#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");
void FileOperator::deleteFiles(const QFileInfoList &files) {
+ if (checkMaxOpsNumber()) return;
+
QString title, desc;
if (files.size() == 1) {
title = tr("Delete file");
void FileOperator::copyFiles(const QFileInfoList &files, QDir &destination) {
+ if (checkMaxOpsNumber()) return;
+
QString title, desc;
if (files.size() == 1) {
title = tr("Copy file");
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;
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;
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)),
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);
}
}
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;
+}
#define FILEOPERATOR_H
#include <QWidget>
+#include <QHBoxLayout>
#include "progressbar.h"
#include "operationthread.h"
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