display buttons in overwrite dialog in 2 columns
authorLukas Hrazky <lukkash@email.cz>
Sun, 25 Jul 2010 12:55:49 +0000 (14:55 +0200)
committerLukas Hrazky <lukkash@email.cz>
Sun, 25 Jul 2010 12:55:49 +0000 (14:55 +0200)
By implementing a custom dialog class.

Signed-off-by: Lukas Hrazky <lukkash@email.cz>

case.pro
src/dialog.cpp [new file with mode: 0644]
src/dialog.h [new file with mode: 0644]
src/fileoperator.cpp

index 26bd047..2a3833a 100644 (file)
--- a/case.pro
+++ b/case.pro
@@ -20,11 +20,13 @@ HEADERS += src/addressbar.h \
            src/case.h \
            src/filelist.h \
            src/fileoperator.h \
-           src/pane.h
+           src/pane.h \
+           src/dialog.h
 SOURCES += src/addressbar.cpp \
            src/button.cpp \
            src/case.cpp \
            src/filelist.cpp \
            src/fileoperator.cpp \
            src/main.cpp \
-           src/pane.cpp
+           src/pane.cpp \
+           src/dialog.cpp
diff --git a/src/dialog.cpp b/src/dialog.cpp
new file mode 100644 (file)
index 0000000..8af4fba
--- /dev/null
@@ -0,0 +1,81 @@
+// case - file manager for N900
+// Copyright (C) 2010 Lukas Hrazky <lukkash@email.cz>
+// 
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+// 
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "dialog.h"
+
+#include <QHBoxLayout>
+
+
+Dialog::Dialog(QWidget *parent) :
+    QDialog(parent),
+    text(new QLabel()),
+    buttons1(new QDialogButtonBox(Qt::Vertical)),
+    buttons2(new QDialogButtonBox(Qt::Vertical))
+{
+    text->setWordWrap(true);
+    text->setAlignment(Qt::AlignTop | Qt::AlignLeft);
+
+    QHBoxLayout *layout = new QHBoxLayout();
+    setLayout(layout);
+    layout->addWidget(text);
+
+    connect(buttons1, SIGNAL(clicked(QAbstractButton*)), this, SLOT(finishUp(QAbstractButton*)));
+    connect(buttons2, SIGNAL(clicked(QAbstractButton*)), this, SLOT(finishUp(QAbstractButton*)));
+}
+
+
+QPushButton *Dialog::addButtonFirst(const QString &text, QDialogButtonBox::ButtonRole role) {
+    return buttons1->addButton(text, role);
+}
+
+
+QPushButton *Dialog::addButtonFirst(const QDialogButtonBox::StandardButton button) {
+    return buttons1->addButton(button);
+}
+
+
+QPushButton *Dialog::addButtonSecond(const QString &text, QDialogButtonBox::ButtonRole role) {
+    return buttons2->addButton(text, role);
+}
+
+
+QPushButton *Dialog::addButtonSecond(const QDialogButtonBox::StandardButton button) {
+    return buttons2->addButton(button);
+}
+
+
+void Dialog::setText(const QString &t) {
+    text->setText(t);
+}
+
+
+void Dialog::finishUp(QAbstractButton *button) {
+    clickedButton = button;
+    done(0);
+}
+
+
+int Dialog::exec() {
+    QHBoxLayout *l = qobject_cast<QHBoxLayout*>(layout());
+    if (buttons1->buttons().size()) {
+        l->addWidget(buttons1, 0, Qt::AlignTop);
+    }
+    if (buttons2->buttons().size()) {
+        l->addWidget(buttons2, 0, Qt::AlignTop);
+    }
+    return QDialog::exec();
+}
diff --git a/src/dialog.h b/src/dialog.h
new file mode 100644 (file)
index 0000000..bc383d6
--- /dev/null
@@ -0,0 +1,48 @@
+// case - file manager for N900
+// Copyright (C) 2010 Lukas Hrazky <lukkash@email.cz>
+// 
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+// 
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef DIALOG_H
+#define DIALOG_H
+
+#include <QDialog>
+#include <QDialogButtonBox>
+#include <QLabel>
+
+
+class Dialog : public QDialog {
+    Q_OBJECT
+
+public:
+    explicit Dialog(QWidget *parent = 0);
+    QPushButton *addButtonFirst(const QString &text, QDialogButtonBox::ButtonRole role);
+    QPushButton *addButtonFirst(const QDialogButtonBox::StandardButton button);
+    QPushButton *addButtonSecond(const QString &text, QDialogButtonBox::ButtonRole role);
+    QPushButton *addButtonSecond(const QDialogButtonBox::StandardButton button);
+
+    QAbstractButton *clickedButton;
+
+public slots:
+    void finishUp(QAbstractButton *button);
+    void setText(const QString &t);
+    int exec();
+
+protected:
+    QLabel *text;
+    QDialogButtonBox *buttons1, *buttons2;
+};
+
+#endif // DIALOG_H
index 67c5204..fc826b9 100644 (file)
@@ -23,6 +23,8 @@
 #include <QHBoxLayout>
 #include <QChar>
 
+#include "dialog.h"
+
 #include <math.h>
 #include <errno.h>
 #include <iostream>
@@ -218,40 +220,40 @@ void FileOperator::showOverwritePrompt(
     const QString &fileName,
     const bool dirOverDir)
 {
-    QMessageBox msgBox;
-    msgBox.addButton(QMessageBox::Cancel);
-    QAbstractButton *yesButton = msgBox.addButton(QMessageBox::Yes);
-    QAbstractButton *yesToAllButton = msgBox.addButton(QMessageBox::YesToAll);
-    QAbstractButton *noButton = msgBox.addButton(QMessageBox::No);
-    QAbstractButton *noToAllButton = msgBox.addButton(QMessageBox::NoToAll);
-    QAbstractButton *abortButton = msgBox.addButton(tr("Abort"), QMessageBox::DestructiveRole);
+    Dialog msgBox;
+    msgBox.addButtonFirst(QDialogButtonBox::Cancel);
+    QAbstractButton *yesButton = msgBox.addButtonFirst(QDialogButtonBox::Yes);
+    QAbstractButton *yesToAllButton = msgBox.addButtonFirst(QDialogButtonBox::YesToAll);
+    QAbstractButton *noButton = msgBox.addButtonSecond(QDialogButtonBox::No);
+    QAbstractButton *noToAllButton = msgBox.addButtonSecond(QDialogButtonBox::NoToAll);
+    QAbstractButton *abortButton = msgBox.addButtonSecond(tr("Abort"), QDialogButtonBox::DestructiveRole);
     QAbstractButton *askButton = 0;
     QAbstractButton *skipDirButton = 0;
 
     if (dirOverDir) {
         msgBox.setText(tr("Directory %1 already exists. Overwrite the files inside?")
             .arg(FileOperator::shortenPath(fileName)));
-        askButton = msgBox.addButton(tr("Ask"), QMessageBox::AcceptRole);
-        skipDirButton = msgBox.addButton(tr("Skip"), QMessageBox::NoRole);
+        askButton = msgBox.addButtonFirst(tr("Ask"), QDialogButtonBox::AcceptRole);
+        skipDirButton = msgBox.addButtonSecond(tr("Skip"), QDialogButtonBox::NoRole);
     } else {
         msgBox.setText(tr("File %1 already exists. Overwrite?").arg(FileOperator::shortenPath(fileName)));
     }
 
     msgBox.exec();
 
-    if (msgBox.clickedButton() == abortButton) {
+    if (msgBox.clickedButton == abortButton) {
         manipulator->setResponse(ABORT);
-    } else if (msgBox.clickedButton() == yesButton) {
+    } else if (msgBox.clickedButton == yesButton) {
         manipulator->setResponse(OVERWRITE);
-    } else if (msgBox.clickedButton() == yesToAllButton) {
+    } else if (msgBox.clickedButton == yesToAllButton) {
         manipulator->setResponse(OVERWRITE, true);
-    } else if (msgBox.clickedButton() == noButton) {
+    } else if (msgBox.clickedButton == noButton) {
         manipulator->setResponse(KEEP);
-    } else if (msgBox.clickedButton() == noToAllButton) {
+    } else if (msgBox.clickedButton == noToAllButton) {
         manipulator->setResponse(KEEP, true);
-    } else if (msgBox.clickedButton() == askButton) {
+    } else if (msgBox.clickedButton == askButton) {
         manipulator->setResponse(NONE, true);
-    } else if (msgBox.clickedButton() == skipDirButton) {
+    } else if (msgBox.clickedButton == skipDirButton) {
         manipulator->setResponse(SKIP_DIR);
     }
 }
@@ -327,7 +329,7 @@ FileManipulatorThread::FileManipulatorThread(const QFileInfoList files, QDir des
 
 
 FileManipulatorThread::~FileManipulatorThread() {
-    if (progressBar->value() < progressBar->maximum()) {
+    if (!abort && progressBar->value() < progressBar->maximum()) {
         std::cout << "WARNING: deleting a progressbar which's value " << progressBar->value() <<
             " has not reached maximum of " << progressBar->maximum() << std::endl;
     }