3 * Copyright (C) 2005-2013 Team XBMC
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with XBMC; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
25 #include "filesystem/File.h"
27 class CGUIDialogProgressBarHandle;
29 class CFileOperationJob : public CJob
37 ActionReplace, ///< Copy, emptying any existing destination directories first
43 CFileOperationJob(FileAction action, CFileItemList & items,
44 const CStdString& strDestFile,
45 bool displayProgress=false,
46 int errorHeading=0, int errorLine=0);
48 void SetFileOperation(FileAction action, CFileItemList &items, const CStdString &strDestFile);
50 virtual bool operator==(const CJob *job) const;
52 static CStdString GetActionString(FileAction action);
54 const char* GetType() const { return m_displayProgress?"filemanager":""; }
56 virtual bool DoWork();
57 const CStdString &GetAverageSpeed() { return m_avgSpeed; }
58 const CStdString &GetCurrentOperation() { return m_currentOperation; }
59 const CStdString &GetCurrentFile() { return m_currentFile; }
60 const CFileItemList &GetItems() { return m_items; }
61 FileAction GetAction() const { return m_action; }
62 int GetHeading() const { return m_heading; }
63 int GetLine() const { return m_line; }
65 class CFileOperation : public XFILE::IFileCallback
68 CFileOperation(FileAction action, const CStdString &strFileA, const CStdString &strFileB, int64_t time);
69 bool ExecuteOperation(CFileOperationJob *base, double ¤t, double opWeight);
71 virtual bool OnFileCallback(void* pContext, int ipercent, float avgSpeed);
74 CStdString m_strFileA, m_strFileB;
77 friend class CFileOperation;
78 typedef std::vector<CFileOperation> FileOperationList;
79 bool DoProcess(FileAction action, CFileItemList & items, const CStdString& strDestFile, FileOperationList &fileOperations, double &totalTime);
80 bool DoProcessFolder(FileAction action, const CStdString& strPath, const CStdString& strDestFile, FileOperationList &fileOperations, double &totalTime);
81 bool DoProcessFile(FileAction action, const CStdString& strFileA, const CStdString& strFileB, FileOperationList &fileOperations, double &totalTime);
83 static inline bool CanBeRenamed(const CStdString &strFileA, const CStdString &strFileB);
86 CFileItemList m_items;
87 CStdString m_strDestFile;
88 CStdString m_avgSpeed, m_currentOperation, m_currentFile;
89 CGUIDialogProgressBarHandle* m_handle;
90 bool m_displayProgress;