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 ignoreDirNotEmpty = false);
88 bool remove(const QFileInfoList &files, const bool ignoreDirNotEmpty = false);
89 bool remove(const QFileInfo &file, const bool ignoreDirNotEmpty = false);
91 void copy(const QFileInfo &file, const bool removeAfterCopy);
93 unsigned int countFiles(const QFileInfoList &files);
94 unsigned int calculateFileSize(const QFileInfoList &files);
96 QFileInfoList listDirFiles(const QString &dirPath);
98 void setBarSize(unsigned int size);
99 void updateProgress(int value);
100 void updateFile(const QString &name);
102 const QFileInfoList files;
105 FileOperator::Response response;
106 FileOperator::Response overwriteAll;
110 QMap<QString, qint64> fileSizeMap;
113 QWaitCondition waitCond;
115 QString fileName, barText;
116 time_t lastTimeUpdate;
118 unsigned int barSize, barValue, fileSize, fileValue;
121 void showErrorPrompt(FileManipulatorThread*, const QString&, const QString&, const int);
122 void showOverwritePrompt(FileManipulatorThread*, const QString&, const bool);
123 void finished(FileManipulatorThread*);
124 void setBarSize(FileManipulatorThread*, unsigned int);
125 void updateProgress(FileManipulatorThread*, int);
129 class DeleteThread : public FileManipulatorThread {
133 explicit DeleteThread(const QFileInfoList &files);
137 virtual void perform(const QFileInfo &file);
141 class CopyThread : public FileManipulatorThread {
145 explicit CopyThread(const QFileInfoList &files, QDir &dest);
149 virtual void perform(const QFileInfo &file);
153 class MoveThread : public FileManipulatorThread {
157 explicit MoveThread(const QFileInfoList &files, QDir &dest);
161 virtual void perform(const QFileInfo &file);
162 void rename(const QFileInfoList &files, const QDir &dest);
166 #endif // FILEOPERATOR_H