Merge pull request #4676 from jmarshallnz/dont_set_scraper_on_tvshow_on_nfo
[vuplus_xbmc] / xbmc / utils / FileOperationJob.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2013 Team XBMC
4  *      http://xbmc.org
5  *
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)
9  *  any later version.
10  *
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.
15  *
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/>.
19  *
20  */
21
22 #include "system.h"
23 #include "FileItem.h"
24 #include "Job.h"
25 #include "filesystem/File.h"
26
27 class CGUIDialogProgressBarHandle;
28
29 class CFileOperationJob : public CJob
30 {
31 public:
32   enum FileAction
33   {
34     ActionCopy = 1,
35     ActionMove,
36     ActionDelete,
37     ActionReplace, ///< Copy, emptying any existing destination directories first
38     ActionCreateFolder,
39     ActionDeleteFolder,
40   };
41
42   CFileOperationJob();
43   CFileOperationJob(FileAction action, CFileItemList & items,
44                     const CStdString& strDestFile,
45                     bool displayProgress=false,
46                     int errorHeading=0, int errorLine=0);
47
48   void SetFileOperation(FileAction action, CFileItemList &items, const CStdString &strDestFile);
49
50   virtual bool operator==(const CJob *job) const;
51
52   static CStdString GetActionString(FileAction action);
53
54   const char* GetType() const { return m_displayProgress?"filemanager":""; }
55
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; }
64 private:
65   class CFileOperation : public XFILE::IFileCallback
66   {
67   public:
68     CFileOperation(FileAction action, const CStdString &strFileA, const CStdString &strFileB, int64_t time);
69     bool ExecuteOperation(CFileOperationJob *base, double &current, double opWeight);
70     void Debug();
71     virtual bool OnFileCallback(void* pContext, int ipercent, float avgSpeed);
72   private:
73     FileAction m_action;
74     CStdString m_strFileA, m_strFileB;
75     int64_t m_time;
76   };
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);
82
83   static inline bool CanBeRenamed(const CStdString &strFileA, const CStdString &strFileB);
84
85   FileAction m_action;
86   CFileItemList m_items;
87   CStdString m_strDestFile;
88   CStdString m_avgSpeed, m_currentOperation, m_currentFile;
89   CGUIDialogProgressBarHandle* m_handle;
90   bool m_displayProgress;
91   int m_heading;
92   int m_line;
93 };