1 /**
2  * KDiff3 - Text Diff And Merge Tool
3  *
4  * SPDX-FileCopyrightText: 2021 Michael Reeves <reeves.87@gmail.com>
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  *
7  */
8 
9 #ifndef FILEACCESSJOBHANDLER_H
10 #define FILEACCESSJOBHANDLER_H
11 
12 #include "fileaccess.h"
13 
14 #include <QObject>
15 #include <QString>
16 
17 #ifndef AUTOTEST
18 #include <KIO/UDSEntry>
19 #endif
20 
21 namespace KIO {
22 class Job;
23 }
24 
25 class KJob;
26 
27 class FileAccess;
28 class t_DirectoryList;
29 
30 class FileAccessJobHandler: public QObject
31 {
32   public:
FileAccessJobHandler(FileAccess * pFileAccess)33     FileAccessJobHandler(FileAccess* pFileAccess)
34     {
35         mFileAccess = pFileAccess;
36     }
37 
38     virtual FileAccessJobHandler* copy(FileAccess* fileAccess) = 0;
39     //This exists soley to allow FileAccess to be no-except movable
setFileAccess(FileAccess * pFileAccess)40     void setFileAccess(FileAccess* pFileAccess) {  mFileAccess = pFileAccess; }
41     virtual bool get(void* pDestBuffer, long maxLength) = 0;
42     virtual bool put(const void* pSrcBuffer, long maxLength, bool bOverwrite, bool bResume = false, int permissions = -1) = 0;
43     virtual bool stat(short detailLevel = 2, bool bWantToWrite = false) = 0;
44     virtual bool copyFile(const QString& dest) = 0;
45     virtual bool rename(const FileAccess& dest) = 0;
46     virtual bool listDir(t_DirectoryList* pDirList, bool bRecursive, bool bFindHidden,
47                  const QString& filePattern, const QString& fileAntiPattern,
48                  const QString& dirAntiPattern, bool bFollowDirLinks, bool bUseCvsIgnore) = 0;
49     virtual bool removeFile(const QUrl& fileName) = 0;
50     virtual bool symLink(const QUrl& linkTarget, const QUrl& linkLocation) = 0;
51 
52   protected:
53     FileAccess* mFileAccess = nullptr;
54     bool m_bSuccess = false;
55 
56     // Data needed during Job
57     qint64 m_transferredBytes = 0;
58     char* m_pTransferBuffer = nullptr; // Needed during get or put
59     qint64 m_maxLength = 0;
60 
61     QString m_filePattern;
62     QString m_fileAntiPattern;
63     QString m_dirAntiPattern;
64     t_DirectoryList* m_pDirList = nullptr;
65     bool m_bFindHidden = false;
66     bool m_bRecursive = false;
67     bool m_bFollowDirLinks = false;
68 
69   private:
70     virtual bool mkDirImp(const QString& dirName) = 0;
71     virtual bool rmDirImp(const QString& dirName) = 0;
72 };
73 
74 #endif /* FILEACCESSJOBHANDLER_H */
75