diff ui/createinstallerdialog.cpp @ 524:a097dd86cb4d

merged.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 29 Apr 2014 15:26:43 +0200
parents 31e0a86f5a35
children f6371e9c959a
line wrap: on
line diff
--- a/ui/createinstallerdialog.cpp	Tue Apr 29 15:26:02 2014 +0200
+++ b/ui/createinstallerdialog.cpp	Tue Apr 29 15:26:43 2014 +0200
@@ -14,13 +14,25 @@
 #include <QVBoxLayout>
 #include <QLabel>
 #include <QFileDialog>
+#include <QSettings>
+#include <QMessageBox>
 
 CreateInstallerDialog::CreateInstallerDialog(QMainWindow *parent) :
-    QDialog(parent)
+    QDialog(parent),
+    mProgress(this)
 {
+    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());
+
+    connect(&mNSISProc, SIGNAL(finished(int, QProcess::ExitStatus)),
+            this, SLOT(processFinished(int, QProcess::ExitStatus)));
+    connect(&mNSISProc, SIGNAL(error(QProcess::ProcessError)),
+            this, SLOT(processError(QProcess::ProcessError)));
 }
 
 void CreateInstallerDialog::setupGUI()
@@ -37,7 +49,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 +60,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()));
@@ -100,35 +112,109 @@
 
     setLayout(topLayout);
 
+    mProgress.setWindowModality(Qt::WindowModal);
+    mProgress.setLabelText(tr("Creating installer package..."));
+    mProgress.setCancelButton(0);
+    mProgress.setRange(0,0);
+    mProgress.setMinimumDuration(0);
+
     return;
 }
 
 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::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
+{
+    qDebug() << "Finished: " << mNSISProc.readAll();
+    mProgress.cancel();
+}
+
+void CreateInstallerDialog::processError(QProcess::ProcessError error)
+{
+    qDebug() << "Error: " << mNSISProc.readAll();
+    mProgress.cancel();
 }
 
 void CreateInstallerDialog::createInstaller()
 {
-    qDebug() << "and now create the installer using:";
-    qDebug() << "source archive: " << mArchiveFile->text();
-    qDebug() << "certificate: " << mCertFile->text();
-    qDebug() << "target" << mSaveFile->text();
-    // TODO
+    QDir binDir(mBinaryFolder->text());
+    QDir outDir(mSaveFile->text());
+    if (mBinaryFolder->text().isEmpty() || !binDir.exists()) {
+        showErrorMessage(tr("Please select an existing input folder."));
+        return;
+    }
+    if (mCertFile->text().isEmpty()) {
+        showErrorMessage(tr("Please select a codesigning certificate."));
+        return;
+    }
+    if (mSaveFile->text().isEmpty() || !outDir.exists()) {
+        showErrorMessage(tr("Please select a output folder."));
+        return;
+    }
+    QSettings options(binDir.filePath("meta.ini"), QSettings::IniFormat);
+    options.sync();
+    QStringList keys = options.allKeys();
+    if (options.status() != QSettings::NoError || keys.size() < 1) {
+        showErrorMessage(tr("Folder %1 does not appear to contain a meta.ini")
+                .arg(binDir.path()));
+        return;
+    }
+
+    /* Copy windows directory contents to tmpdir */
+    QStringList arguments;
+    mNSISProc.setProgram("makensis");
+    mNSISProc.setProcessChannelMode(QProcess::MergedChannels);
+    mNSISProc.setWorkingDirectory(outDir.path());
+    arguments << QString::fromLatin1("-Dfiles_dir=") + binDir.path() + "/windows";
+    foreach (const QString &key, keys) {
+        arguments << QString::fromLatin1("-D%1=%2").arg(key,
+                options.value(key, QString()).toString());
+    }
+
+    arguments << binDir.path() + "/trustbridge.nsi";
+
+    qDebug() << "Starting makensis with arguments: " << arguments;
+    mNSISProc.setArguments(arguments);
+    mNSISProc.start();
+    mProgress.show();
+
+    if (!mNSISProc.waitForStarted() ||
+        mNSISProc.state() == QProcess::NotRunning) {
+        showErrorMessage(tr("Failed to start makensis.\n"
+            "Please ensure that makensis is installed and in your PATH variable."));
+    }
 }

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