Integrated file selection dialogue with the main code. Improved the
[openvpnui.git] / src / filebrowse / fileworker.h
1 #ifndef FILEWORKER_H
2 #define FILEWORKER_H
3
4 #include <QThread>
5 #include <QDir>
6
7 /**
8 * @brief FileWorker does delete, copy and move files in the background.
9 */
10 class FileWorker : public QThread
11 {
12 Q_OBJECT
13
14 public:
15 explicit FileWorker(QObject *parent = 0);
16 ~FileWorker();
17
18 // call these to start the thread, returns false if start failed
19 void startDeleteFiles(QStringList filenames);
20 void startCopyFiles(QStringList filenames, QString destDirectory);
21 void startMoveFiles(QStringList filenames, QString destDirectory);
22
23 void cancel();
24
25 signals: // signals, can be connected from a thread to another
26 void progressChanged(int progress, QString filename);
27
28 // one of these is emitted when thread ends
29 void done();
30 void errorOccurred(QString message, QString filename);
31
32 void fileDeleted(QString fullname);
33
34 protected:
35 void run();
36
37 private:
38 enum Mode {
39 DeleteMode, CopyMode, MoveMode
40 };
41 enum CancelStatus {
42 Cancelled = 0, KeepRunning = 1
43 };
44
45 QString deleteFile(QString filenames);
46 void deleteFiles();
47 void copyOrMoveFiles();
48 QString copyDirRecursively(QString srcDirectory, QString destDirectory);
49 QString copyOverwrite(QString src, QString dest);
50
51 FileWorker::Mode m_mode;
52 QStringList m_filenames;
53 QString m_destDirectory;
54 QAtomicInt m_cancelled; // atomic so no locks needed
55 int m_progress;
56 };
57
58 #endif // FILEWORKER_H