#define FILEOPERATOR_H
#include <QWidget>
-#include <QProgressBar>
-#include <QFileInfo>
-#include <QThread>
-#include <QMutex>
-#include <QWaitCondition>
-#include <QDir>
-#include <QMap>
-#include <QSet>
+#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, SKIP_DIR, DONT_ASK_ONCE};
-
FileOperator(QWidget *parent = 0);
- static QString shortenPath(const QString &path);
-
void deleteFiles(const QFileInfoList &files);
void copyFiles(const QFileInfoList &files, QDir &destination);
void moveFiles(const QFileInfoList &files, QDir &destination);
public slots:
- void showErrorPrompt(FileManipulatorThread* manipulator,
+ void showErrorPrompt(OperationThread* op,
const QString &message,
const QString &fileName,
const int err);
- void showOverwritePrompt(FileManipulatorThread* manipulator,
+ void showOverwritePrompt(OperationThread* op,
const QString &fileName,
const bool dirOverDir);
+ void showInputFilenamePrompt(OperationThread* op,
+ const QFileInfo &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());
- ~FileManipulatorThread();
- void setResponse(const FileOperator::Response response, const bool appyToAll = false, const int err = 0);
-
- void setText(int value);
-
- QProgressBar *progressBar;
-
- time_t startTime;
-
-protected:
- void processFiles(const QFileInfoList &files);
- virtual void perform(const QFileInfo &file) = 0;
-
- bool remove(QString &fileName, const bool doUpdates = false);
- bool remove(const QFileInfoList &files, const bool doUpdates = false);
- bool remove(const QFileInfo &file, const bool doUpdates = false);
-
- void copy(const QFileInfo &file);
-
- unsigned int calculateFileSize(const QFileInfoList &files,
- const bool count = false,
- const bool addSize = false);
-
- QFileInfoList listDirFiles(const QString &dirPath);
-
- void setBarSize(unsigned int size);
- void updateProgress(int value);
- void updateFile(const QString &name);
-
- const QFileInfoList files;
- QDir dest;
-
- FileOperator::Response response;
- FileOperator::Response overwriteAll;
- bool abort;
- bool ignoreAll[256];
-
- // set of files that won't be deleted by the remove(...) functions
- // used when move(...) would not overwrite target file to ensure the source file doesn't get deleted
- QSet<QString> removeExcludeFiles;
-
- QMap<QString, qint64> fileSizeMap;
-
- QMutex mutex;
- QWaitCondition waitCond;
-
- QString fileName, barText;
- time_t lastTimeUpdate;
- char timeBuf[10];
- unsigned int barSize, barValue, fileSize, fileValue;
-
-signals:
- void showErrorPrompt(FileManipulatorThread*, const QString&, const QString&, const int);
- void showOverwritePrompt(FileManipulatorThread*, const QString&, const bool);
- void finished(FileManipulatorThread*);
- void setBarSize(FileManipulatorThread*, unsigned int);
- void updateProgress(FileManipulatorThread*, int);
-};
-
-
-class DeleteThread : public FileManipulatorThread {
- Q_OBJECT
-
-public:
- explicit DeleteThread(const QFileInfoList &files);
-
-protected:
- void run();
- virtual void perform(const QFileInfo &file);
-};
-
-
-class CopyThread : public FileManipulatorThread {
- Q_OBJECT
+ void remove(OperationThread* op);
-public:
- explicit CopyThread(const QFileInfoList &files, QDir &dest);
+ 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 MoveThread : public FileManipulatorThread {
- Q_OBJECT
-
-public:
- explicit MoveThread(const QFileInfoList &files, QDir &dest);
-
-protected:
- void run();
- virtual void perform(const QFileInfo &file);
- void rename(const QFileInfoList &files, const QDir &dest);
+ OperationList opList;
+ QPixmap deleteIcon, inverseDeleteIcon, copyIcon, inverseCopyIcon, moveIcon, inverseMoveIcon;
};
-
#endif // FILEOPERATOR_H