[PATCH 5 of 7] Improve error handlig and persist user decisions
Wald Commits
scm-commit at wald.intevation.org
Mon Apr 28 19:15:57 CEST 2014
# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1398693760 0
# Node ID 9d3880db6ba7b233c66164e7726d0027f6ed0857
# Parent ce8325686b09815bc893342b9421b47d9123b964
Improve error handlig and persist user decisions
diff -r ce8325686b09 -r 9d3880db6ba7 ui/administratorwindow.cpp
--- a/ui/administratorwindow.cpp Mon Apr 28 13:59:55 2014 +0000
+++ b/ui/administratorwindow.cpp Mon Apr 28 14:02:40 2014 +0000
@@ -138,14 +138,16 @@
void AdministratorWindow::loadCertificateFile()
{
+ QString lastCertFile = mSettings.value("LastCertList", QDir::homePath()).toString();
QString certFile = QFileDialog::getOpenFileName(
- this, tr("Select certificate list file"), QDir::homePath(), "*.txt");
+ this, tr("Select certificate list file"), lastCertFile, "*.txt");
mCertList.readList(certFile.toLocal8Bit().constData());
if (!mCertList.isValid()) {
- qDebug() << "Not a valid list.";
+ QMessageBox::warning(this, tr("Error!"), tr("Failed to load the certificate list."));
} else {
certificateModel->removeAll();
loadCertificateTable();
+ mSettings.setValue("LastCertList", certFile);
}
}
diff -r ce8325686b09 -r 9d3880db6ba7 ui/createcertlistdialog.cpp
--- a/ui/createcertlistdialog.cpp Mon Apr 28 13:59:55 2014 +0000
+++ b/ui/createcertlistdialog.cpp Mon Apr 28 14:02:40 2014 +0000
@@ -258,7 +258,16 @@
return;
}
- if (!outputFile.copy(archiveDir.filePath("current_certificates.txt"))) {
+ QString curCerts = archiveDir.filePath("current_certificates.txt");
+
+ if (QFile::exists(curCerts)) {
+ if (!QFile::remove(curCerts)) {
+ showErrorMessage(tr("Failed to update current_certificates.txt"));
+ return;
+ }
+ }
+
+ if (!outputFile.copy(curCerts)) {
showErrorMessage(tr("Failed to write current_certificates file."));
return;
}
diff -r ce8325686b09 -r 9d3880db6ba7 ui/createinstallerdialog.cpp
--- 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
}
diff -r ce8325686b09 -r 9d3880db6ba7 ui/createinstallerdialog.h
--- a/ui/createinstallerdialog.h Mon Apr 28 13:59:55 2014 +0000
+++ b/ui/createinstallerdialog.h Mon Apr 28 14:02:40 2014 +0000
@@ -31,12 +31,18 @@
void setupGUI();
QLineEdit *mCertFile;
- QLineEdit *mArchiveFile;
+ QLineEdit *mBinaryFolder;
QLineEdit *mSaveFile;
+ /** @brief show an error message with QMessageBox
+ *
+ * @param [in] msg The message to show
+ */
+ void showErrorMessage(const QString &msg);
+
private slots:
void openCertificateSelect();
- void openArchiveSelect();
+ void openFolderSelect();
void openSaveLocation();
void createInstaller();
};
More information about the Trustbridge-commits
mailing list