2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "threads/SystemClock.h"
22 #include "AsyncFileCopy.h"
23 #include "dialogs/GUIDialogProgress.h"
24 #include "guilib/GUIWindowManager.h"
26 #include "utils/TimeUtils.h"
27 #include "utils/StringUtils.h"
30 CAsyncFileCopy::CAsyncFileCopy() : CThread("AsyncFileCopy")
39 CAsyncFileCopy::~CAsyncFileCopy()
44 bool CAsyncFileCopy::Copy(const CStdString &from, const CStdString &to, const CStdString &heading)
46 // reset the variables to their appropriate states
57 // create our thread, which starts the file copy operation
59 CGUIDialogProgress *dlg = (CGUIDialogProgress *)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
60 unsigned int time = XbmcThreads::SystemClockMillis();
63 m_event.WaitMSec(1000 / 30);
66 // start the dialog up as needed
67 if (dlg && !dlg->IsDialogRunning() && (XbmcThreads::SystemClockMillis() - time) > 500) // wait 0.5 seconds before starting dialog
69 dlg->SetHeading(heading);
70 dlg->SetLine(0, url1.GetWithoutUserDetails());
71 dlg->SetLine(1, url2.GetWithoutUserDetails());
72 dlg->SetPercentage(0);
75 // and update the dialog as we go
76 if (dlg && dlg->IsDialogRunning())
78 CStdString speedString = StringUtils::Format("%2.2f KB/s", m_speed / 1024);
79 dlg->SetHeading(heading);
80 dlg->SetLine(0, url1.Get());
81 dlg->SetLine(1, url2.Get());
82 dlg->SetLine(2, speedString);
83 dlg->SetPercentage(m_percent);
85 m_cancelled = dlg->IsCanceled();
90 return !m_cancelled && m_succeeded;
93 bool CAsyncFileCopy::OnFileCallback(void *pContext, int ipercent, float avgSpeed)
101 void CAsyncFileCopy::Process()
105 m_succeeded = XFILE::CFile::Cache(m_from, m_to, this);
110 CLog::Log(LOGERROR, "%s: unhandled exception copying file", __FUNCTION__);