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>
31 class FileManipulatorThread;
34 class FileOperator : public QWidget {
38 // DONT_ASK_ONCE is a hackish way to avoid asking twice to overwrite the same directory when moving
39 enum Response{NONE, ABORT, RETRY, IGNORE, KEEP, OVERWRITE, DONT_ASK_ONCE};
41 FileOperator(QWidget *parent = 0);
43 void deleteFiles(const QFileInfoList &files);
44 void copyFiles(const QFileInfoList &files, QDir &destination);
45 void moveFiles(const QFileInfoList &files, QDir &destination);
48 void showErrorPrompt(FileManipulatorThread* manipulator, const QString &message, const int err);
49 void showOverwritePrompt(FileManipulatorThread* manipulator, const QString &fileName, const bool dirOverDir);
50 void remove(FileManipulatorThread* manipulator);
51 void setBarSize(FileManipulatorThread* manipulator, unsigned int size);
52 void updateProgress(FileManipulatorThread* manipulator, int value);
55 void caterNewThread(FileManipulatorThread *thread);
57 QList<FileManipulatorThread*> manipulatorList;
61 class FileManipulatorThread : public QThread {
65 explicit FileManipulatorThread(const QFileInfoList files, QDir dest = QDir());
66 void setResponse(const FileOperator::Response response, const bool appyToAll = false, const int err = 0);
71 void processFiles(const QFileInfoList &files);
72 virtual void perform(const QFileInfo &file) = 0;
74 bool remove(QString &filename, const bool ignoreDirNotEmpty = false);
75 bool remove(const QFileInfoList &files, const bool ignoreDirNotEmpty = false);
76 bool remove(const QFileInfo &file, const bool ignoreDirNotEmpty = false);
78 void copy(const QFileInfo &file, const bool removeAfterCopy);
80 unsigned int countFiles(const QFileInfoList &files);
81 unsigned int calculateFileSize(const QFileInfoList &files);
83 QFileInfoList listDirFiles(const QString &dirPath);
85 void setBarSize(unsigned int size);
86 void updateProgress(int value);
87 void updateFile(const QString &fileName);
89 const QFileInfoList files;
92 FileOperator::Response response;
93 FileOperator::Response overwriteAll;
97 QMap<QString, qint64> fileSizeMap;
100 QWaitCondition waitCond;
102 unsigned int barSize, barValue, fileSize, fileValue;
105 void showErrorPrompt(FileManipulatorThread*, const QString&, const int);
106 void showOverwritePrompt(FileManipulatorThread*, const QString&, const bool);
107 void finished(FileManipulatorThread*);
108 void setBarSize(FileManipulatorThread*, unsigned int);
109 void updateProgress(FileManipulatorThread*, int);
110 void updateFile(FileManipulatorThread*, const QString&);
114 class DeleteThread : public FileManipulatorThread {
118 explicit DeleteThread(const QFileInfoList &files) : FileManipulatorThread(files) {}
122 virtual void perform(const QFileInfo &file);
126 class CopyThread : public FileManipulatorThread {
130 explicit CopyThread(const QFileInfoList &files, QDir &dest) : FileManipulatorThread(files, dest) {}
134 virtual void perform(const QFileInfo &file);
138 class MoveThread : public FileManipulatorThread {
142 explicit MoveThread(const QFileInfoList &files, QDir &dest) : FileManipulatorThread(files, dest) {}
146 virtual void perform(const QFileInfo &file);
147 void rename(const QFileInfoList &files, const QDir &dest);
151 #endif // FILEOPERATOR_H