made progressbar layout 2 rows, max 6 bars total
authorLukas Hrazky <lukkash@email.cz>
Sun, 22 Aug 2010 12:28:43 +0000 (14:28 +0200)
committerLukas Hrazky <lukkash@email.cz>
Sun, 22 Aug 2010 13:38:00 +0000 (15:38 +0200)
Signed-off-by: Lukas Hrazky <lukkash@email.cz>

case.pro
src/fileoperator.cpp
src/fileoperator.h

index 5655ede..8ede4b5 100644 (file)
--- a/case.pro
+++ b/case.pro
@@ -13,6 +13,7 @@ PKGCONFIG += dbus-1 gnome-vfs-2.0
 LIBS += -lhildonmime -ldbus-1
 OBJECTS_DIR=.build
 MOC_DIR=.build
+QT += maemo5
 
 # Input
 HEADERS += src/addressbar.h \
index b25ab3b..639fd5d 100644 (file)
 
 #include <QtGui>
 #include <QMessageBox>
-#include <QHBoxLayout>
+#include <QVBoxLayout>
+#include <QMaemo5InformationBox>
 
 #include "dialog.h"
 #include "utils.h"
 
 
 FileOperator::FileOperator(QWidget *parent) : QWidget(parent) {
-    QHBoxLayout *layout = new QHBoxLayout;
+    QVBoxLayout *layout = new QVBoxLayout;
     layout->setContentsMargins(0, 0, 0, 0);
     layout->setSpacing(1);
+    topRow = new QHBoxLayout;
+    topRow->setContentsMargins(0, 0, 0, 0);
+    topRow->setSpacing(1);
+    layout->addLayout(topRow);
+    bottomRow = new QHBoxLayout;
+    bottomRow->setContentsMargins(0, 0, 0, 0);
+    bottomRow->setSpacing(1);
+    layout->addLayout(bottomRow);
     setLayout(layout);
 
     qRegisterMetaType<QFileInfo>("QFileInfo");
@@ -41,6 +50,8 @@ FileOperator::FileOperator(QWidget *parent) : QWidget(parent) {
 
 
 void FileOperator::deleteFiles(const QFileInfoList &files) {
+    if (checkMaxOpsNumber()) return;
+
     QString title, desc;
     if (files.size() == 1) {
         title = tr("Delete file");
@@ -67,6 +78,8 @@ void FileOperator::deleteFiles(const QFileInfoList &files) {
 
 
 void FileOperator::copyFiles(const QFileInfoList &files, QDir &destination) {
+    if (checkMaxOpsNumber()) return;
+
     QString title, desc;
     if (files.size() == 1) {
         title = tr("Copy file");
@@ -96,6 +109,8 @@ void FileOperator::copyFiles(const QFileInfoList &files, QDir &destination) {
 
 
 void FileOperator::moveFiles(const QFileInfoList &files, QDir &destination) {
+    if (checkMaxOpsNumber()) return;
+
     // for move we don't wanna move to the same dir
     if (files[0].absolutePath() == destination.absolutePath()) return;
 
@@ -246,7 +261,7 @@ void FileOperator::showInputFilenamePrompt(OperationThread* op,
 void FileOperator::remove(OperationThread* op) {
     op->wait();
     ProgressBar *bar = get(op);
-    layout()->removeWidget(bar);
+    removeBarFromLayout(bar);
     opList.removeAll(qMakePair(op, bar));
     delete op;
     delete bar;
@@ -284,6 +299,7 @@ void FileOperator::abortOperation(ProgressBar* bar) {
 
 
 void FileOperator::initOperation(OperationThread *thread, ProgressBar *bar) {
+    addBarToLayout(bar);
     opList.append(qMakePair(thread, bar));
 
     connect(thread, SIGNAL(showErrorPrompt(OperationThread*, const QString&, const QString&, const int)),
@@ -306,7 +322,6 @@ void FileOperator::initOperation(OperationThread *thread, ProgressBar *bar) {
     connect(bar, SIGNAL(togglePauseOperation(ProgressBar*)), this, SLOT(togglePauseOperation(ProgressBar*)));
     connect(bar, SIGNAL(abortOperation(ProgressBar*)), this, SLOT(abortOperation(ProgressBar*)));
 
-    layout()->addWidget(bar);
     thread->start(QThread::LowestPriority);
 }
 
@@ -325,3 +340,55 @@ OperationThread *FileOperator::get(ProgressBar *bar) const {
     }
     return 0;
 }
+
+
+void FileOperator::addBarToLayout(ProgressBar *bar) {
+    switch (opList.size()) {
+    case 0:
+    case 1:
+    case 2:
+        topRow->addWidget(bar);
+        break;
+    case 4:
+        topRow->addItem(bottomRow->takeAt(0));
+        bottomRow->addWidget(bar);
+        break;
+    case 3:
+        bottomRow->addItem(topRow->takeAt(2));
+    default:
+        bottomRow->addWidget(bar);
+    }
+}
+
+
+void FileOperator::removeBarFromLayout(ProgressBar *bar) {
+    int index = topRow->indexOf(bar);
+    if (index != -1) {
+        topRow->takeAt(index);
+        switch (opList.size()) {
+        case 4:
+            topRow->addItem(bottomRow->takeAt(0));
+        case 6:
+            topRow->addItem(bottomRow->takeAt(0));
+            break;
+        }
+    } else {
+        bottomRow->removeWidget(bar);
+        switch (opList.size()) {
+        case 4:
+            topRow->addItem(bottomRow->takeAt(0));
+            break;
+        case 5:
+            bottomRow->insertWidget(0, topRow->takeAt(2)->widget());
+        }
+    }
+}
+
+
+bool FileOperator::checkMaxOpsNumber() {
+    if (opList.size() == 6) {
+        QMaemo5InformationBox::information(this, tr("The maximum number of file operations is %1.").arg(6));
+        return true;
+    }
+    return false;
+}
index c0a47ee..ab62839 100644 (file)
@@ -19,6 +19,7 @@
 #define FILEOPERATOR_H
 
 #include <QWidget>
+#include <QHBoxLayout>
 
 #include "progressbar.h"
 #include "operationthread.h"
@@ -57,9 +58,14 @@ protected:
     void initOperation(OperationThread *thread, ProgressBar *bar);
     ProgressBar *get(OperationThread *op) const;
     OperationThread *get(ProgressBar *bar) const;
+    void addBarToLayout(ProgressBar *bar);
+    void removeBarFromLayout(ProgressBar *bar);
+
+    bool checkMaxOpsNumber();
 
     OperationList opList;
     QPixmap deleteIcon, inverseDeleteIcon, copyIcon, inverseCopyIcon, moveIcon, inverseMoveIcon;
+    QHBoxLayout *topRow, *bottomRow;
 };
 
 #endif // FILEOPERATOR_H