#define FILEOPERATOR_H
#include <QWidget>
-#include <QProgressBar>
#include <QFileInfo>
#include <QThread>
#include <QMutex>
#include <QWaitCondition>
#include <QDir>
+#include <QFSFileEngine>
#include <QMap>
#include <QSet>
+#include "progressbar.h"
+
class FileManipulatorThread;
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};
+ enum Response{NONE, ABORT, RETRY, IGNORE, KEEP, OVERWRITE, SKIP_DIR, ASK, DONT_ASK_ONCE};
FileOperator(QWidget *parent = 0);
static QString shortenPath(const QString &path);
+ static QString unwindPath(const QString &path);
void deleteFiles(const QFileInfoList &files);
void copyFiles(const QFileInfoList &files, QDir &destination);
void showOverwritePrompt(FileManipulatorThread* manipulator,
const QString &fileName,
const bool dirOverDir);
+ void showInputFilenamePrompt(FileManipulatorThread* manipulator,
+ const QFileInfo &fileName,
+ const bool dirOverDir);
void remove(FileManipulatorThread* manipulator);
void setBarSize(FileManipulatorThread* manipulator, unsigned int size);
void updateProgress(FileManipulatorThread* manipulator, int value);
+ void updateMainText(FileManipulatorThread* manipulator, const QString &text);
+ void showPaused(FileManipulatorThread* manipulator);
+
+ void togglePauseOperation(FileManipulatorThread* manipulator);
+ void abortOperation(FileManipulatorThread* manipulator);
protected:
void caterNewThread(FileManipulatorThread *thread);
QList<FileManipulatorThread*> manipulatorList;
+ QPixmap deleteIcon, inverseDeleteIcon, copyIcon, inverseCopyIcon, moveIcon, inverseMoveIcon;
};
void setText(int value);
- QProgressBar *progressBar;
+ void wake();
- time_t startTime;
+ ProgressBar *progressBar;
+
+ QMutex mutex;
+ // the new name entered from the overwrite dialog
+ QString newNameFromDialog;
+ // flags to abort/pause the operation
+ bool abort, pause;
protected:
void processFiles(const QFileInfoList &files);
void updateProgress(int value);
void updateFile(const QString &name);
+ void waitOnCond();
+
+ bool checkSequentialFile(const QFSFileEngine &engine);
+
+ QWaitCondition waitCond;
+
+ // files to process by the operation
const QFileInfoList files;
+ // destination for files - changes as the operation recurses into directories
QDir dest;
+ // responses from the dialog prompts (error and overwrite)
FileOperator::Response response;
FileOperator::Response overwriteAll;
- bool abort;
+ // an array indicating whether to always ignore the error of index errno
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;
+ // A map of file paths to their size. Not the actual size, but what is calculated for the
+ // purpose of the progressbar for the given operation. So either fileSize/BLOCK_SIZE or simply
+ // 1 for a file and file count for dirs (or both for copy&delete)
QMap<QString, qint64> fileSizeMap;
- QMutex mutex;
- QWaitCondition waitCond;
-
- QString fileName, barText;
+ // the text of the progressBar (the format)
+ QString barText;
+ // stamp of the last ETA recalculation - done every second
time_t lastTimeUpdate;
+ time_t startTime, waitTime;
char timeBuf[10];
+ // progress information of the bar and for the current file
unsigned int barSize, barValue, fileSize, fileValue;
signals:
void showErrorPrompt(FileManipulatorThread*, const QString&, const QString&, const int);
void showOverwritePrompt(FileManipulatorThread*, const QString&, const bool);
+ void showInputFilenamePrompt(FileManipulatorThread*, const QFileInfo&, const bool);
void finished(FileManipulatorThread*);
void setBarSize(FileManipulatorThread*, unsigned int);
void updateProgress(FileManipulatorThread*, int);
+ void updateFileName(FileManipulatorThread*, QString);
+ void operationPaused(FileManipulatorThread*);
};