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 static QString shortenPath(const QString &path);
45 void deleteFiles(const QFileInfoList &files);
46 void copyFiles(const QFileInfoList &files, QDir &destination);
47 void moveFiles(const QFileInfoList &files, QDir &destination);
50 void showErrorPrompt(FileManipulatorThread* manipulator,
51 const QString &message,
52 const QString &fileName,
54 void showOverwritePrompt(FileManipulatorThread* manipulator,
55 const QString &fileName,
56 const bool dirOverDir);
58 void remove(FileManipulatorThread* manipulator);
59 void setBarSize(FileManipulatorThread* manipulator, unsigned int size);
60 void updateProgress(FileManipulatorThread* manipulator, int value);
63 void caterNewThread(FileManipulatorThread *thread);
65 QList<FileManipulatorThread*> manipulatorList;
69 class FileManipulatorThread : public QThread {
73 explicit FileManipulatorThread(const QFileInfoList files, QDir dest = QDir());
74 ~FileManipulatorThread();
75 void setResponse(const FileOperator::Response response, const bool appyToAll = false, const int err = 0);
77 void setText(int value);
79 QProgressBar *progressBar;
84 void processFiles(const QFileInfoList &files);
85 virtual void perform(const QFileInfo &file) = 0;
87 bool remove(QString &fileName, const bool doUpdates = false);
88 bool remove(const QFileInfoList &files, const bool doUpdates = false);
89 bool remove(const QFileInfo &file, const bool doUpdates = false);
91 void copy(const QFileInfo &file);
93 unsigned int calculateFileSize(const QFileInfoList &files,
94 const bool count = false,
95 const bool addSize = false);
97 QFileInfoList listDirFiles(const QString &dirPath);
99 void setBarSize(unsigned int size);
100 void updateProgress(int value);
101 void updateFile(const QString &name);
103 const QFileInfoList files;
106 FileOperator::Response response;
107 FileOperator::Response overwriteAll;
111 QMap<QString, qint64> fileSizeMap;
114 QWaitCondition waitCond;
116 QString fileName, barText;
117 time_t lastTimeUpdate;
119 unsigned int barSize, barValue, fileSize, fileValue;
122 void showErrorPrompt(FileManipulatorThread*, const QString&, const QString&, const int);
123 void showOverwritePrompt(FileManipulatorThread*, const QString&, const bool);
124 void finished(FileManipulatorThread*);
125 void setBarSize(FileManipulatorThread*, unsigned int);
126 void updateProgress(FileManipulatorThread*, int);
130 class DeleteThread : public FileManipulatorThread {
134 explicit DeleteThread(const QFileInfoList &files);
138 virtual void perform(const QFileInfo &file);
142 class CopyThread : public FileManipulatorThread {
146 explicit CopyThread(const QFileInfoList &files, QDir &dest);
150 virtual void perform(const QFileInfo &file);
154 class MoveThread : public FileManipulatorThread {
158 explicit MoveThread(const QFileInfoList &files, QDir &dest);
162 virtual void perform(const QFileInfo &file);
163 void rename(const QFileInfoList &files, const QDir &dest);
167 #endif // FILEOPERATOR_H