1 // case - file manager for N900
2 // Copyright (C) 2010 Lukas Hrazky <lukkash@email.cz>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef OPERATIONTHREAD_H
19 #define OPERATIONTHREAD_H
25 #include <QFSFileEngine>
28 #include <QWaitCondition>
31 class OperationThread : public QThread {
35 // DONT_ASK_ONCE is a hackish way to avoid asking twice to overwrite the same directory when moving
36 enum Response{NONE, ABORT, RETRY, IGNORE, KEEP, OVERWRITE, SKIP_DIR, ASK, DONT_ASK_ONCE};
38 explicit OperationThread(const QFileInfoList files, QDir dest = QDir());
39 void setResponse(const Response response, const bool appyToAll = false, const int err = 0);
43 // the new name entered from the overwrite dialog
44 QString newNameFromDialog;
45 // flags to abort/pause the operation
49 void processFiles(const QFileInfoList &files);
50 virtual void perform(const QFileInfo &file) = 0;
52 bool remove(QString &fileName, const bool doUpdates = false);
53 bool remove(const QFileInfoList &files, const bool doUpdates = false);
54 bool remove(const QFileInfo &file, const bool doUpdates = false);
56 void copy(const QFileInfo &file);
58 unsigned int calculateFileSize(const QFileInfoList &files,
59 const bool count = false,
60 const bool addSize = false);
62 QFileInfoList listDirFiles(const QString &dirPath);
64 void setTotalSize(unsigned int size);
65 void updateProgress(int value);
66 void updateFile(const QString &name);
70 bool checkSequentialFile(const QFSFileEngine &engine);
73 QWaitCondition waitCond;
75 // files to process by the operation
76 const QFileInfoList files;
77 // destination for files - changes as the operation recurses into directories
80 // responses from the dialog prompts (error and overwrite)
82 Response overwriteAll;
83 // an array indicating whether to always ignore the error of index errno
86 // set of files that won't be deleted by the remove(...) functions
87 // used when move(...) would not overwrite target file to ensure the source file doesn't get deleted
88 QSet<QString> removeExcludeFiles;
90 // A map of file paths to their size. Not the actual size, but what is calculated for the
91 // purpose of the progressbar for the given operation. So either fileSize/BLOCK_SIZE or simply
92 // 1 for a file and file count for dirs (or both for copy&delete)
93 QMap<QString, qint64> fileSizeMap;
95 // progress information of the bar and for the current file
96 unsigned int totalSize, totalValue, fileValue;
99 void showErrorPrompt(OperationThread*, const QString&, const QString&, const int);
100 void showOverwritePrompt(OperationThread*, const QString&, const bool);
101 void showInputFilenamePrompt(OperationThread*, const QFileInfo&, const bool);
102 void finished(OperationThread*);
104 void totalSizeChanged(int);
105 void progressUpdate(int);
106 void fileNameUpdated(QString);
107 void operationStarted(time_t);
108 void operationPaused();
109 void operationResumed(time_t);
110 // special signal emitted when operation has to copy files between partitions
111 // to notify the user it is deleting files after succesful copy (which can take some time)
112 void removeAfterCopy();
116 class DeleteThread : public OperationThread {
120 explicit DeleteThread(const QFileInfoList &files) : OperationThread(files) {}
124 virtual void perform(const QFileInfo &file);
128 class CopyThread : public OperationThread {
132 explicit CopyThread(const QFileInfoList &files, QDir &dest) : OperationThread(files, dest) {}
136 virtual void perform(const QFileInfo &file);
140 class MoveThread : public OperationThread {
144 explicit MoveThread(const QFileInfoList &files, QDir &dest) : OperationThread(files, dest) {}
148 virtual void perform(const QFileInfo &file);
149 void rename(const QFileInfoList &files, const QDir &dest);
152 #endif // OPERATIONTHREAD_H