new style for the progressbars, display more info
[case] / src / fileoperator.cpp
index 422f90b..bd4c667 100644 (file)
@@ -24,6 +24,7 @@
 #include <QChar>
 
 #include "dialog.h"
+#include "utils.h"
 
 #include <math.h>
 #include <errno.h>
 FileOperator::FileOperator(QWidget *parent) : QWidget(parent) {
     QHBoxLayout *layout = new QHBoxLayout;
     layout->setContentsMargins(0, 0, 0, 0);
-    layout->setSpacing(0);
+    layout->setSpacing(1);
     setLayout(layout);
     qRegisterMetaType<QFileInfo>("QFileInfo");
+    loadOperationIcons(palette(), "delete_small", deleteIcon, inverseDeleteIcon);
+    loadOperationIcons(palette(), "copy_small", copyIcon, inverseCopyIcon);
+    loadOperationIcons(palette(), "move_small", moveIcon, inverseMoveIcon);
 }
 
 
@@ -167,7 +171,9 @@ void FileOperator::deleteFiles(const QFileInfoList &files) {
     );
 
     if(confirm == QMessageBox::Yes) {
-        caterNewThread(new DeleteThread(files));
+        DeleteThread *t = new DeleteThread(files);
+        t->progressBar->setIcons(deleteIcon, inverseDeleteIcon);
+        caterNewThread(t);
     }
 }
 
@@ -194,7 +200,11 @@ void FileOperator::copyFiles(const QFileInfoList &files, QDir &destination) {
     );
 
     if(confirm == QMessageBox::Yes) {
-        caterNewThread(new CopyThread(files, destination));
+        CopyThread *t = new CopyThread(files, destination);
+        t->progressBar->setIcons(copyIcon, inverseCopyIcon);
+        t->progressBar->fromText = shortenPath(files[0].absolutePath());
+        t->progressBar->toText = FileOperator::shortenPath(destination.absolutePath());
+        caterNewThread(t);
     }
 }
 
@@ -224,7 +234,11 @@ void FileOperator::moveFiles(const QFileInfoList &files, QDir &destination) {
     );
 
     if(confirm == QMessageBox::Yes) {
-        caterNewThread(new MoveThread(files, destination));
+        MoveThread *t = new MoveThread(files, destination);
+        t->progressBar->setIcons(moveIcon, inverseMoveIcon);
+        t->progressBar->fromText = shortenPath(files[0].absolutePath());
+        t->progressBar->toText = shortenPath(destination.absolutePath());
+        caterNewThread(t);
     }
 }
 
@@ -366,14 +380,24 @@ void FileOperator::updateProgress(FileManipulatorThread* manipulator, int value)
 }
 
 
+void FileOperator::updateMainText(FileManipulatorThread* manipulator, const QString &text) {
+    manipulator->progressBar->mainText = text;
+    manipulator->progressBar->mainText.remove(0, manipulator->progressBar->fromText.size() + 1);
+    manipulator->progressBar->repaint();
+}
+
+
 void FileOperator::showPaused(FileManipulatorThread* manipulator) {
-    manipulator->setText(0);
+    manipulator->progressBar->paused = true;
+    manipulator->progressBar->repaint();
 }
 
 
 void FileOperator::togglePauseOperation(FileManipulatorThread* manipulator) {
     if (manipulator->pause) {
         manipulator->pause = false;
+        manipulator->progressBar->paused = false;
+        manipulator->progressBar->repaint();
         manipulator->wake();
     } else {
         manipulator->pause = true;
@@ -393,7 +417,6 @@ void FileOperator::abortOperation(FileManipulatorThread* manipulator) {
     if(confirm == QMessageBox::Yes) {
         manipulator->abort = true;
         manipulator->pause = false;
-        manipulator->setText(0);
         manipulator->wake();
     }
 }
@@ -414,6 +437,8 @@ void FileOperator::caterNewThread(FileManipulatorThread *thread) {
         this, SLOT(setBarSize(FileManipulatorThread*, unsigned int)));
     connect(thread, SIGNAL(updateProgress(FileManipulatorThread*, int)),
         this, SLOT(updateProgress(FileManipulatorThread*, int)));
+    connect(thread, SIGNAL(updateFileName(FileManipulatorThread*, QString)),
+        this, SLOT(updateMainText(FileManipulatorThread*, QString)));
     connect(thread, SIGNAL(operationPaused(FileManipulatorThread*)),
         this, SLOT(showPaused(FileManipulatorThread*)));
 
@@ -422,7 +447,6 @@ void FileOperator::caterNewThread(FileManipulatorThread *thread) {
     connect(thread->progressBar, SIGNAL(abortOperation(FileManipulatorThread*)),
         this, SLOT(abortOperation(FileManipulatorThread*)));
 
-    thread->setText(0);
     layout()->addWidget(thread->progressBar);
     thread->start(QThread::LowestPriority);
 }
@@ -768,8 +792,7 @@ void FileManipulatorThread::updateProgress(int value) {
 
 void FileManipulatorThread::updateFile(const QString &name) {
     fileValue = 0;
-    fileName = FileOperator::shortenPath(name);
-    emit updateProgress(this, 0);
+    emit updateFileName(this, FileOperator::shortenPath(name));
 }
 
 
@@ -802,15 +825,6 @@ void FileManipulatorThread::setText(int value) {
             << ") by " << value << std::endl;
     }
 
-    if (!fileName.size()) {
-        if (pause) {
-            progressBar->setFormat(tr("Gathering information...") + " (" + tr("paused") + ")");
-        } else {
-            progressBar->setFormat(tr("Gathering information..."));
-        }
-        return;
-    }
     time_t now = time(0);
     if (lastTimeUpdate < now) {
         lastTimeUpdate = now;
@@ -828,10 +842,8 @@ void FileManipulatorThread::setText(int value) {
         }
     }
 
-    QString newFormat = barText.arg(fileName) + "\n%p%   ETA " + timeBuf;
-    if (pause) newFormat += " (" + tr("paused") + ")";
 
-    progressBar->setFormat(newFormat);
+    progressBar->setFormat(QString("%p%  ") + timeBuf);
     progressBar->setValue(progressBar->value() + value);
 }