From 72c587990ced37e1ab120eaf2e788c9f26f0b98d Mon Sep 17 00:00:00 2001 From: Lukas Hrazky Date: Sun, 22 Aug 2010 14:28:43 +0200 Subject: [PATCH] made progressbar layout 2 rows, max 6 bars total Signed-off-by: Lukas Hrazky --- case.pro | 1 + src/fileoperator.cpp | 75 +++++++++++++++++++++++++++++++++++++++++++++++--- src/fileoperator.h | 6 ++++ 3 files changed, 78 insertions(+), 4 deletions(-) diff --git a/case.pro b/case.pro index 5655ede..8ede4b5 100644 --- 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 \ diff --git a/src/fileoperator.cpp b/src/fileoperator.cpp index b25ab3b..639fd5d 100644 --- a/src/fileoperator.cpp +++ b/src/fileoperator.cpp @@ -19,16 +19,25 @@ #include #include -#include +#include +#include #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"); @@ -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; +} diff --git a/src/fileoperator.h b/src/fileoperator.h index c0a47ee..ab62839 100644 --- a/src/fileoperator.h +++ b/src/fileoperator.h @@ -19,6 +19,7 @@ #define FILEOPERATOR_H #include +#include #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 -- 1.7.9.5