PageRenderTime 23ms CodeModel.GetById 11ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/xbmc/utils/FileOperationJob.h

http://github.com/xbmc/xbmc
C Header | 85 lines | 61 code | 16 blank | 8 comment | 0 complexity | 38beecf4551f364409af70c8103ec9a0 MD5 | raw file
 1/*
 2 *  Copyright (C) 2005-2018 Team Kodi
 3 *  This file is part of Kodi - https://kodi.tv
 4 *
 5 *  SPDX-License-Identifier: GPL-2.0-or-later
 6 *  See LICENSES/README.md for more information.
 7 */
 8
 9#pragma once
10
11#include "FileItem.h"
12#include "filesystem/File.h"
13#include "utils/ProgressJob.h"
14
15#include <string>
16#include <vector>
17
18class CFileOperationJob : public CProgressJob
19{
20public:
21  enum FileAction
22  {
23    ActionCopy = 1,
24    ActionMove,
25    ActionDelete,
26    ActionReplace, ///< Copy, emptying any existing destination directories first
27    ActionCreateFolder,
28    ActionDeleteFolder,
29  };
30
31  CFileOperationJob();
32  CFileOperationJob(FileAction action, CFileItemList & items,
33                    const std::string& strDestFile,
34                    bool displayProgress = false,
35                    int errorHeading = 0, int errorLine = 0);
36
37  static std::string GetActionString(FileAction action);
38
39  // implementations of CJob
40  bool DoWork() override;
41  const char* GetType() const override { return m_displayProgress ? "filemanager" : ""; }
42  bool operator==(const CJob *job) const override;
43
44  void SetFileOperation(FileAction action, CFileItemList &items, const std::string &strDestFile);
45
46  const std::string &GetAverageSpeed() const { return m_avgSpeed; }
47  const std::string &GetCurrentOperation() const { return m_currentOperation; }
48  const std::string &GetCurrentFile() const { return m_currentFile; }
49  const CFileItemList &GetItems() const { return m_items; }
50  FileAction GetAction() const { return m_action; }
51  int GetHeading() const { return m_heading; }
52  int GetLine() const { return m_line; }
53
54private:
55  class CFileOperation : public XFILE::IFileCallback
56  {
57  public:
58    CFileOperation(FileAction action, const std::string &strFileA, const std::string &strFileB, int64_t time);
59
60    bool OnFileCallback(void* pContext, int ipercent, float avgSpeed) override;
61
62    bool ExecuteOperation(CFileOperationJob *base, double &current, double opWeight);
63
64  private:
65    FileAction m_action;
66    std::string m_strFileA, m_strFileB;
67    int64_t m_time;
68  };
69  friend class CFileOperation;
70
71  typedef std::vector<CFileOperation> FileOperationList;
72  bool DoProcess(FileAction action, CFileItemList & items, const std::string& strDestFile, FileOperationList &fileOperations, double &totalTime);
73  bool DoProcessFolder(FileAction action, const std::string& strPath, const std::string& strDestFile, FileOperationList &fileOperations, double &totalTime);
74  bool DoProcessFile(FileAction action, const std::string& strFileA, const std::string& strFileB, FileOperationList &fileOperations, double &totalTime);
75
76  static inline bool CanBeRenamed(const std::string &strFileA, const std::string &strFileB);
77
78  FileAction m_action = ActionCopy;
79  CFileItemList m_items;
80  std::string m_strDestFile;
81  std::string m_avgSpeed, m_currentOperation, m_currentFile;
82  bool m_displayProgress = false;
83  int m_heading = 0;
84  int m_line = 0;
85};