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 FILEOPERATOR_H
19 #define FILEOPERATOR_H
22 #include <QProgressBar>
26 #include <QWaitCondition>
32 class FileManipulatorThread;
35 class FileOperator : public QWidget {
39 // DONT_ASK_ONCE is a hackish way to avoid asking twice to overwrite the same directory when moving
40 enum Response{NONE, ABORT, RETRY, IGNORE, KEEP, OVERWRITE, SKIP_DIR, DONT_ASK_ONCE};
42 FileOperator(QWidget *parent = 0);
44 static QString shortenPath(const QString &path);
46 void deleteFiles(const QFileInfoList &files);
47 void copyFiles(const QFileInfoList &files, QDir &destination);
48 void moveFiles(const QFileInfoList &files, QDir &destination);
51 void showErrorPrompt(FileManipulatorThread* manipulator,
52 const QString &message,
53 const QString &fileName,
55 void showOverwritePrompt(FileManipulatorThread* manipulator,
56 const QString &fileName,
57 const bool dirOverDir);
59 void remove(FileManipulatorThread* manipulator);
60 void setBarSize(FileManipulatorThread* manipulator, unsigned int size);
61 void updateProgress(FileManipulatorThread* manipulator, int value);
64 void caterNewThread(FileManipulatorThread *thread);
66 QList<FileManipulatorThread*> manipulatorList;
70 class FileManipulatorThread : public QThread {
74 explicit FileManipulatorThread(const QFileInfoList files, QDir dest = QDir());
75 ~FileManipulatorThread();
76 void setResponse(const FileOperator::Response response, const bool appyToAll = false, const int err = 0);
78 void setText(int value);
80 QProgressBar *progressBar;
85 void processFiles(const QFileInfoList &files);
86 virtual void perform(const QFileInfo &file) = 0;
88 bool remove(QString &fileName, const bool doUpdates = false);
89 bool remove(const QFileInfoList &files, const bool doUpdates = false);
90 bool remove(const QFileInfo &file, const bool doUpdates = false);
92 void copy(const QFileInfo &file);
94 unsigned int calculateFileSize(const QFileInfoList &files,
95 const bool count = false,
96 const bool addSize = false);
98 QFileInfoList listDirFiles(const QString &dirPath);
100 void setBarSize(unsigned int size);
101 void updateProgress(int value);
102 void updateFile(const QString &name);
104 const QFileInfoList files;
107 FileOperator::Response response;
108 FileOperator::Response overwriteAll;
112 // set of files that won't be deleted by the remove(...) functions
113 // used when move(...) would not overwrite target file to ensure the source file doesn't get deleted
114 QSet<QString> removeExcludeFiles;
116 QMap<QString, qint64> fileSizeMap;
119 QWaitCondition waitCond;
121 QString fileName, barText;
122 time_t lastTimeUpdate;
124 unsigned int barSize, barValue, fileSize, fileValue;
127 void showErrorPrompt(FileManipulatorThread*, const QString&, const QString&, const int);
128 void showOverwritePrompt(FileManipulatorThread*, const QString&, const bool);
129 void finished(FileManipulatorThread*);
130 void setBarSize(FileManipulatorThread*, unsigned int);
131 void updateProgress(FileManipulatorThread*, int);
135 class DeleteThread : public FileManipulatorThread {
139 explicit DeleteThread(const QFileInfoList &files);
143 virtual void perform(const QFileInfo &file);
147 class CopyThread : public FileManipulatorThread {
151 explicit CopyThread(const QFileInfoList &files, QDir &dest);
155 virtual void perform(const QFileInfo &file);
159 class MoveThread : public FileManipulatorThread {
163 explicit MoveThread(const QFileInfoList &files, QDir &dest);
167 virtual void perform(const QFileInfo &file);
168 void rename(const QFileInfoList &files, const QDir &dest);
172 #endif // FILEOPERATOR_H