diff ui/createinstallerdialog.cpp @ 515:9d3880db6ba7

Improve error handlig and persist user decisions
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 28 Apr 2014 14:02:40 +0000
parents d1819cd56dee
children 3332db04c77d
line wrap: on
line diff
--- a/ui/createinstallerdialog.cpp	Mon Apr 28 13:59:55 2014 +0000
+++ b/ui/createinstallerdialog.cpp	Mon Apr 28 14:02:40 2014 +0000
@@ -14,13 +14,19 @@
 #include <QVBoxLayout>
 #include <QLabel>
 #include <QFileDialog>
+#include <QSettings>
+#include <QMessageBox>
 
 CreateInstallerDialog::CreateInstallerDialog(QMainWindow *parent) :
     QDialog(parent)
 {
+    QSettings settings;
     setWindowTitle(tr("Create binary installer"));
     setupGUI();
     resize(500, 250);
+    mCertFile->setText(settings.value("CodeSignCert", QString()).toString());
+    mBinaryFolder->setText(settings.value("LastBinaryFolder", QString()).toString());
+    mSaveFile->setText(settings.value("LastBinOutputFolder", QString()).toString());
 }
 
 void CreateInstallerDialog::setupGUI()
@@ -37,7 +43,7 @@
 
     QLabel *header = new QLabel("<h3>" + tr("Create binary installer") + "</h3>");
     QLabel *description = new QLabel(
-        tr("Create and sign a TrustBridge binary installer from source."));
+        tr("Create and sign a TrustBridge binary installer."));
     headerSubLayout->insertSpacing(0, 40);
     headerSubLayout->addWidget(description);
     QFrame *headerSeparator = new QFrame();
@@ -48,22 +54,22 @@
     headerLayout->addWidget(headerSeparator);
     headerLayout->insertSpacing(4, 10);
 
-    QLabel *archiveLabel = new QLabel(tr("Select source archive:"));
-    QLabel *certLabel = new QLabel(tr("Select code signing certificate (secret key):"));
+    QLabel *archiveLabel = new QLabel(tr("Select binary folder:"));
+    QLabel *certLabel = new QLabel(tr("Select code signing certificate:"));
     QLabel *saveLabel = new QLabel(tr("Select output folder:"));
     labelLayout->addWidget(archiveLabel);
     labelLayout->addWidget(certLabel);
     labelLayout->addWidget(saveLabel);
 
-    mArchiveFile = new QLineEdit();
+    mBinaryFolder = new QLineEdit();
     mCertFile = new QLineEdit();
     mSaveFile = new QLineEdit();
-    fieldLayout->addWidget(mArchiveFile);
+    fieldLayout->addWidget(mBinaryFolder);
     fieldLayout->addWidget(mCertFile);
     fieldLayout->addWidget(mSaveFile);
 
     QPushButton *archiveSelect = new QPushButton("...");
-    connect(archiveSelect, SIGNAL(clicked()), this, SLOT(openArchiveSelect()));
+    connect(archiveSelect, SIGNAL(clicked()), this, SLOT(openFolderSelect()));
     archiveSelect->setFixedWidth(30);
     QPushButton *certSelect = new QPushButton("...");
     connect(certSelect, SIGNAL(clicked()), this, SLOT(openCertificateSelect()));
@@ -105,30 +111,48 @@
 
 void CreateInstallerDialog::openCertificateSelect()
 {
+    QSettings settings;
     QString certFile = QFileDialog::getOpenFileName(
-        this, tr("Select certificate"), QDir::homePath(), "*.pem *.der *.crt");
+        this, tr("Select certificate"),
+        mCertFile->text().isEmpty() ? QDir::homePath() : mCertFile->text(),
+        "*.pem *.der *.crt");
+    settings.setValue("CodeSignCert", certFile);
     mCertFile->setText(certFile);
 }
 
-void CreateInstallerDialog::openArchiveSelect()
+void CreateInstallerDialog::openFolderSelect()
 {
-    QString archiveFile = QFileDialog::getOpenFileName(
-        this, tr("Select source archive"), QDir::homePath(), "*.zip *.tar.gz");
-    mArchiveFile->setText(archiveFile);
+    QSettings settings;
+    QString archiveFolder = QFileDialog::getExistingDirectory(
+        this, tr("Select binary folder"),
+        mBinaryFolder->text().isEmpty() ? QDir::homePath() : mBinaryFolder->text());
+    mBinaryFolder->setText(archiveFolder);
+    settings.setValue("LastBinaryFolder", archiveFolder);
 }
 
 void CreateInstallerDialog::openSaveLocation()
 {
+    QSettings settings;
     QString saveFile = QFileDialog::getExistingDirectory(
-        this, tr("Select target location"), QDir::homePath());
+        this, tr("Select target location"),
+        mSaveFile->text().isEmpty() ? QDir::homePath() : mSaveFile->text());
     mSaveFile->setText(saveFile);
+    settings.setValue("LastBinOutputFolder", saveFile);
+}
+
+void CreateInstallerDialog::showErrorMessage(const QString &msg)
+{
+    QMessageBox::warning(this, tr("Error!"), msg);
 }
 
 void CreateInstallerDialog::createInstaller()
 {
+    QDir binDir(mBinaryFolder->text());
+    if (mBinaryFolder->text().isEmpty() && binDir.exists()) {
+        showErrorMessage(tr("Please select an existing input folder."));
+    }
     qDebug() << "and now create the installer using:";
-    qDebug() << "source archive: " << mArchiveFile->text();
+    qDebug() << "source archive: " << mBinaryFolder->text();
     qDebug() << "certificate: " << mCertFile->text();
     qDebug() << "target" << mSaveFile->text();
-    // TODO
 }

http://wald.intevation.org/projects/trustbridge/