2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
12 #include "FileItemList.h"
13 #include "filesystem/IFileTypes.h"
14 #include "utils/ProgressJob.h"
19 class CFileOperationJob
: public CProgressJob
27 ActionReplace
, ///< Copy, emptying any existing destination directories first
33 CFileOperationJob(FileAction action
, CFileItemList
& items
,
34 const std::string
& strDestFile
,
35 bool displayProgress
= false,
36 int errorHeading
= 0, int errorLine
= 0);
38 static std::string
GetActionString(FileAction action
);
40 // implementations of CJob
41 bool DoWork() override
;
42 const char* GetType() const override
{ return m_displayProgress
? "filemanager" : ""; }
43 bool operator==(const CJob
*job
) const override
;
45 void SetFileOperation(FileAction action
,
46 const CFileItemList
& items
,
47 const std::string
& strDestFile
);
49 const std::string
&GetAverageSpeed() const { return m_avgSpeed
; }
50 const std::string
&GetCurrentOperation() const { return m_currentOperation
; }
51 const std::string
&GetCurrentFile() const { return m_currentFile
; }
52 const CFileItemList
&GetItems() const { return m_items
; }
53 FileAction
GetAction() const { return m_action
; }
54 int GetHeading() const { return m_heading
; }
55 int GetLine() const { return m_line
; }
58 class CFileOperation
: public XFILE::IFileCallback
61 CFileOperation(FileAction action
, const std::string
&strFileA
, const std::string
&strFileB
, int64_t time
);
63 bool OnFileCallback(void* pContext
, int ipercent
, float avgSpeed
) override
;
65 bool ExecuteOperation(CFileOperationJob
*base
, double ¤t
, double opWeight
);
69 std::string m_strFileA
, m_strFileB
;
72 friend class CFileOperation
;
74 typedef std::vector
<CFileOperation
> FileOperationList
;
75 bool DoProcess(FileAction action
,
76 const CFileItemList
& items
,
77 const std::string
& strDestFile
,
78 FileOperationList
& fileOperations
,
80 bool DoProcessFolder(FileAction action
, const std::string
& strPath
, const std::string
& strDestFile
, FileOperationList
&fileOperations
, double &totalTime
);
81 bool DoProcessFile(FileAction action
, const std::string
& strFileA
, const std::string
& strFileB
, FileOperationList
&fileOperations
, double &totalTime
);
83 static inline bool CanBeRenamed(const std::string
&strFileA
, const std::string
&strFileB
);
85 FileAction m_action
= ActionCopy
;
86 CFileItemList m_items
;
87 std::string m_strDestFile
;
88 std::string m_avgSpeed
, m_currentOperation
, m_currentFile
;
89 bool m_displayProgress
= false;