added possibility to pause/abort the operations
[case] / src / fileoperator.h
index 76f5535..b73e45a 100644 (file)
@@ -19,7 +19,6 @@
 #define FILEOPERATOR_H
 
 #include <QWidget>
-#include <QProgressBar>
 #include <QFileInfo>
 #include <QThread>
 #include <QMutex>
@@ -28,6 +27,8 @@
 #include <QMap>
 #include <QSet>
 
+#include "progressbar.h"
+
 
 class FileManipulatorThread;
 
@@ -63,6 +64,10 @@ public slots:
     void remove(FileManipulatorThread* manipulator);
     void setBarSize(FileManipulatorThread* manipulator, unsigned int size);
     void updateProgress(FileManipulatorThread* manipulator, int value);
+    void showPaused(FileManipulatorThread* manipulator);
+
+    void togglePauseOperation(FileManipulatorThread* manipulator);
+    void abortOperation(FileManipulatorThread* manipulator);
 
 protected:
     void caterNewThread(FileManipulatorThread *thread);
@@ -81,13 +86,15 @@ public:
 
     void setText(int value);
 
-    QProgressBar *progressBar;
+    void wake();
+
+    ProgressBar *progressBar;
 
-    time_t startTime;
     QMutex mutex;
-    QWaitCondition waitCond;
     // 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);
@@ -109,6 +116,10 @@ protected:
     void updateProgress(int value);
     void updateFile(const QString &name);
 
+    void waitOnCond();
+
+    QWaitCondition waitCond;
+
     // files to process by the operation
     const QFileInfoList files;
     // destination for files - changes as the operation recurses into directories
@@ -117,8 +128,6 @@ protected:
     // responses from the dialog prompts (error and overwrite)
     FileOperator::Response response;
     FileOperator::Response overwriteAll;
-    // a flag to abort the operation
-    bool abort;
     // an array indicating whether to always ignore the error of index errno
     bool ignoreAll[256];
 
@@ -135,6 +144,7 @@ protected:
     QString fileName, 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;
@@ -146,6 +156,7 @@ signals:
     void finished(FileManipulatorThread*);
     void setBarSize(FileManipulatorThread*, unsigned int);
     void updateProgress(FileManipulatorThread*, int);
+    void operationPaused(FileManipulatorThread*);
 };