#define FILEOPERATOR_H
#include <QWidget>
-#include <QProgressBar>
-#include <QFileInfo>
-#include <QThread>
-#include <QMutex>
-#include <QWaitCondition>
-#include <QDir>
-#include <QMap>
+#include "progressbar.h"
+#include "operationthread.h"
-class FileManipulatorThread;
+typedef QList<QPair<OperationThread*, ProgressBar*> > OperationList;
class FileOperator : public QWidget {
Q_OBJECT
public:
- // DONT_ASK_ONCE is a hackish way to avoid asking twice to overwrite the same directory when moving
- enum Response{NONE, ABORT, RETRY, IGNORE, KEEP, OVERWRITE, DONT_ASK_ONCE};
-
FileOperator(QWidget *parent = 0);
void deleteFiles(const QFileInfoList &files);
void moveFiles(const QFileInfoList &files, QDir &destination);
public slots:
- void showErrorPrompt(FileManipulatorThread* manipulator, const QString &message, const int err);
- void showOverwritePrompt(FileManipulatorThread* manipulator, const QString &fileName, const bool dirOverDir);
- void remove(FileManipulatorThread* manipulator);
- void setBarSize(FileManipulatorThread* manipulator, unsigned int size);
- void updateProgress(FileManipulatorThread* manipulator, int value);
-
-protected:
- void caterNewThread(FileManipulatorThread *thread);
-
- QList<FileManipulatorThread*> manipulatorList;
-};
-
-
-class FileManipulatorThread : public QThread {
- Q_OBJECT
-
-public:
- explicit FileManipulatorThread(const QFileInfoList files, QDir dest = QDir());
- void setResponse(const FileOperator::Response response, const bool appyToAll = false, const int err = 0);
-
- QProgressBar *widget;
-
-protected:
- void processFiles(const QFileInfoList &files);
- virtual void perform(const QFileInfo &file) = 0;
-
- bool remove(QString &filename, const bool ignoreDirNotEmpty = false);
- bool remove(const QFileInfoList &files, const bool ignoreDirNotEmpty = false);
- bool remove(const QFileInfo &file, const bool ignoreDirNotEmpty = false);
-
- void copy(const QFileInfo &file, const bool removeAfterCopy);
-
- unsigned int countFiles(const QFileInfoList &files);
- unsigned int calculateFileSize(const QFileInfoList &files);
-
- QFileInfoList listDirFiles(const QString &dirPath);
-
- void setBarSize(unsigned int size);
- void updateProgress(int value);
- void updateFile(const QString &fileName);
-
- const QFileInfoList files;
- QDir dest;
-
- FileOperator::Response response;
- FileOperator::Response overwriteAll;
- bool abort;
- bool ignoreAll[256];
-
- QMap<QString, qint64> fileSizeMap;
-
- QMutex mutex;
- QWaitCondition waitCond;
-
- unsigned int barSize, barValue, fileSize, fileValue;
-
-signals:
- void showErrorPrompt(FileManipulatorThread*, const QString&, const int);
- void showOverwritePrompt(FileManipulatorThread*, const QString&, const bool);
- void finished(FileManipulatorThread*);
- void setBarSize(FileManipulatorThread*, unsigned int);
- void updateProgress(FileManipulatorThread*, int);
- void updateFile(FileManipulatorThread*, const QString&);
-};
-
-
-class DeleteThread : public FileManipulatorThread {
- Q_OBJECT
-
-public:
- explicit DeleteThread(const QFileInfoList &files) : FileManipulatorThread(files) {}
+ void showErrorPrompt(OperationThread* op,
+ const QString &message,
+ const QString &fileName,
+ const int err);
+ void showOverwritePrompt(OperationThread* op,
+ const QString &fileName,
+ const bool dirOverDir);
+ void showInputFilenamePrompt(OperationThread* op,
+ const QFileInfo &fileName,
+ const bool dirOverDir);
+
+ void remove(OperationThread* op);
+
+ void togglePauseOperation(ProgressBar* bar);
+ void abortOperation(ProgressBar* bar);
protected:
- void run();
- virtual void perform(const QFileInfo &file);
-};
-
+ void initOperation(OperationThread *thread, ProgressBar *bar);
+ ProgressBar *get(OperationThread *op) const;
+ OperationThread *get(ProgressBar *bar) const;
-class CopyThread : public FileManipulatorThread {
- Q_OBJECT
-
-public:
- explicit CopyThread(const QFileInfoList &files, QDir &dest) : FileManipulatorThread(files, dest) {}
-
-protected:
- void run();
- virtual void perform(const QFileInfo &file);
+ OperationList opList;
+ QPixmap deleteIcon, inverseDeleteIcon, copyIcon, inverseCopyIcon, moveIcon, inverseMoveIcon;
};
-
-class MoveThread : public FileManipulatorThread {
- Q_OBJECT
-
-public:
- explicit MoveThread(const QFileInfoList &files, QDir &dest) : FileManipulatorThread(files, dest) {}
-
-protected:
- void run();
- virtual void perform(const QFileInfo &file);
- void rename(const QFileInfoList &files, const QDir &dest);
-};
-
-
#endif // FILEOPERATOR_H