Mercurial > trustbridge
comparison 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 |
comparison
equal
deleted
inserted
replaced
523:ca583ffe728a | 524:a097dd86cb4d |
---|---|
12 #include <QGroupBox> | 12 #include <QGroupBox> |
13 #include <QHBoxLayout> | 13 #include <QHBoxLayout> |
14 #include <QVBoxLayout> | 14 #include <QVBoxLayout> |
15 #include <QLabel> | 15 #include <QLabel> |
16 #include <QFileDialog> | 16 #include <QFileDialog> |
17 #include <QSettings> | |
18 #include <QMessageBox> | |
17 | 19 |
18 CreateInstallerDialog::CreateInstallerDialog(QMainWindow *parent) : | 20 CreateInstallerDialog::CreateInstallerDialog(QMainWindow *parent) : |
19 QDialog(parent) | 21 QDialog(parent), |
20 { | 22 mProgress(this) |
23 { | |
24 QSettings settings; | |
21 setWindowTitle(tr("Create binary installer")); | 25 setWindowTitle(tr("Create binary installer")); |
22 setupGUI(); | 26 setupGUI(); |
23 resize(500, 250); | 27 resize(500, 250); |
28 mCertFile->setText(settings.value("CodeSignCert", QString()).toString()); | |
29 mBinaryFolder->setText(settings.value("LastBinaryFolder", QString()).toString()); | |
30 mSaveFile->setText(settings.value("LastBinOutputFolder", QString()).toString()); | |
31 | |
32 connect(&mNSISProc, SIGNAL(finished(int, QProcess::ExitStatus)), | |
33 this, SLOT(processFinished(int, QProcess::ExitStatus))); | |
34 connect(&mNSISProc, SIGNAL(error(QProcess::ProcessError)), | |
35 this, SLOT(processError(QProcess::ProcessError))); | |
24 } | 36 } |
25 | 37 |
26 void CreateInstallerDialog::setupGUI() | 38 void CreateInstallerDialog::setupGUI() |
27 { | 39 { |
28 /* Top level layout / widgets */ | 40 /* Top level layout / widgets */ |
35 QVBoxLayout *fieldLayout = new QVBoxLayout; | 47 QVBoxLayout *fieldLayout = new QVBoxLayout; |
36 QVBoxLayout *buttonLayout = new QVBoxLayout; | 48 QVBoxLayout *buttonLayout = new QVBoxLayout; |
37 | 49 |
38 QLabel *header = new QLabel("<h3>" + tr("Create binary installer") + "</h3>"); | 50 QLabel *header = new QLabel("<h3>" + tr("Create binary installer") + "</h3>"); |
39 QLabel *description = new QLabel( | 51 QLabel *description = new QLabel( |
40 tr("Create and sign a TrustBridge binary installer from source.")); | 52 tr("Create and sign a TrustBridge binary installer.")); |
41 headerSubLayout->insertSpacing(0, 40); | 53 headerSubLayout->insertSpacing(0, 40); |
42 headerSubLayout->addWidget(description); | 54 headerSubLayout->addWidget(description); |
43 QFrame *headerSeparator = new QFrame(); | 55 QFrame *headerSeparator = new QFrame(); |
44 headerSeparator->setFrameShape(QFrame::HLine); | 56 headerSeparator->setFrameShape(QFrame::HLine); |
45 headerSeparator->setFrameShadow(QFrame::Sunken); | 57 headerSeparator->setFrameShadow(QFrame::Sunken); |
46 headerLayout->addWidget(header); | 58 headerLayout->addWidget(header); |
47 headerLayout->addLayout(headerSubLayout); | 59 headerLayout->addLayout(headerSubLayout); |
48 headerLayout->addWidget(headerSeparator); | 60 headerLayout->addWidget(headerSeparator); |
49 headerLayout->insertSpacing(4, 10); | 61 headerLayout->insertSpacing(4, 10); |
50 | 62 |
51 QLabel *archiveLabel = new QLabel(tr("Select source archive:")); | 63 QLabel *archiveLabel = new QLabel(tr("Select binary folder:")); |
52 QLabel *certLabel = new QLabel(tr("Select code signing certificate (secret key):")); | 64 QLabel *certLabel = new QLabel(tr("Select code signing certificate:")); |
53 QLabel *saveLabel = new QLabel(tr("Select output folder:")); | 65 QLabel *saveLabel = new QLabel(tr("Select output folder:")); |
54 labelLayout->addWidget(archiveLabel); | 66 labelLayout->addWidget(archiveLabel); |
55 labelLayout->addWidget(certLabel); | 67 labelLayout->addWidget(certLabel); |
56 labelLayout->addWidget(saveLabel); | 68 labelLayout->addWidget(saveLabel); |
57 | 69 |
58 mArchiveFile = new QLineEdit(); | 70 mBinaryFolder = new QLineEdit(); |
59 mCertFile = new QLineEdit(); | 71 mCertFile = new QLineEdit(); |
60 mSaveFile = new QLineEdit(); | 72 mSaveFile = new QLineEdit(); |
61 fieldLayout->addWidget(mArchiveFile); | 73 fieldLayout->addWidget(mBinaryFolder); |
62 fieldLayout->addWidget(mCertFile); | 74 fieldLayout->addWidget(mCertFile); |
63 fieldLayout->addWidget(mSaveFile); | 75 fieldLayout->addWidget(mSaveFile); |
64 | 76 |
65 QPushButton *archiveSelect = new QPushButton("..."); | 77 QPushButton *archiveSelect = new QPushButton("..."); |
66 connect(archiveSelect, SIGNAL(clicked()), this, SLOT(openArchiveSelect())); | 78 connect(archiveSelect, SIGNAL(clicked()), this, SLOT(openFolderSelect())); |
67 archiveSelect->setFixedWidth(30); | 79 archiveSelect->setFixedWidth(30); |
68 QPushButton *certSelect = new QPushButton("..."); | 80 QPushButton *certSelect = new QPushButton("..."); |
69 connect(certSelect, SIGNAL(clicked()), this, SLOT(openCertificateSelect())); | 81 connect(certSelect, SIGNAL(clicked()), this, SLOT(openCertificateSelect())); |
70 certSelect->setFixedWidth(30); | 82 certSelect->setFixedWidth(30); |
71 QPushButton *saveSelect = new QPushButton("..."); | 83 QPushButton *saveSelect = new QPushButton("..."); |
98 topLayout->addWidget(bottomSeparator); | 110 topLayout->addWidget(bottomSeparator); |
99 topLayout->addLayout(bottomLayout); | 111 topLayout->addLayout(bottomLayout); |
100 | 112 |
101 setLayout(topLayout); | 113 setLayout(topLayout); |
102 | 114 |
115 mProgress.setWindowModality(Qt::WindowModal); | |
116 mProgress.setLabelText(tr("Creating installer package...")); | |
117 mProgress.setCancelButton(0); | |
118 mProgress.setRange(0,0); | |
119 mProgress.setMinimumDuration(0); | |
120 | |
103 return; | 121 return; |
104 } | 122 } |
105 | 123 |
106 void CreateInstallerDialog::openCertificateSelect() | 124 void CreateInstallerDialog::openCertificateSelect() |
107 { | 125 { |
126 QSettings settings; | |
108 QString certFile = QFileDialog::getOpenFileName( | 127 QString certFile = QFileDialog::getOpenFileName( |
109 this, tr("Select certificate"), QDir::homePath(), "*.pem *.der *.crt"); | 128 this, tr("Select certificate"), |
129 mCertFile->text().isEmpty() ? QDir::homePath() : mCertFile->text(), | |
130 "*.pem *.der *.crt"); | |
131 settings.setValue("CodeSignCert", certFile); | |
110 mCertFile->setText(certFile); | 132 mCertFile->setText(certFile); |
111 } | 133 } |
112 | 134 |
113 void CreateInstallerDialog::openArchiveSelect() | 135 void CreateInstallerDialog::openFolderSelect() |
114 { | 136 { |
115 QString archiveFile = QFileDialog::getOpenFileName( | 137 QSettings settings; |
116 this, tr("Select source archive"), QDir::homePath(), "*.zip *.tar.gz"); | 138 QString archiveFolder = QFileDialog::getExistingDirectory( |
117 mArchiveFile->setText(archiveFile); | 139 this, tr("Select binary folder"), |
140 mBinaryFolder->text().isEmpty() ? QDir::homePath() : mBinaryFolder->text()); | |
141 mBinaryFolder->setText(archiveFolder); | |
142 settings.setValue("LastBinaryFolder", archiveFolder); | |
118 } | 143 } |
119 | 144 |
120 void CreateInstallerDialog::openSaveLocation() | 145 void CreateInstallerDialog::openSaveLocation() |
121 { | 146 { |
147 QSettings settings; | |
122 QString saveFile = QFileDialog::getExistingDirectory( | 148 QString saveFile = QFileDialog::getExistingDirectory( |
123 this, tr("Select target location"), QDir::homePath()); | 149 this, tr("Select target location"), |
150 mSaveFile->text().isEmpty() ? QDir::homePath() : mSaveFile->text()); | |
124 mSaveFile->setText(saveFile); | 151 mSaveFile->setText(saveFile); |
152 settings.setValue("LastBinOutputFolder", saveFile); | |
153 } | |
154 | |
155 void CreateInstallerDialog::showErrorMessage(const QString &msg) | |
156 { | |
157 QMessageBox::warning(this, tr("Error!"), msg); | |
158 } | |
159 | |
160 void CreateInstallerDialog::processFinished(int exitCode, QProcess::ExitStatus exitStatus) | |
161 { | |
162 qDebug() << "Finished: " << mNSISProc.readAll(); | |
163 mProgress.cancel(); | |
164 } | |
165 | |
166 void CreateInstallerDialog::processError(QProcess::ProcessError error) | |
167 { | |
168 qDebug() << "Error: " << mNSISProc.readAll(); | |
169 mProgress.cancel(); | |
125 } | 170 } |
126 | 171 |
127 void CreateInstallerDialog::createInstaller() | 172 void CreateInstallerDialog::createInstaller() |
128 { | 173 { |
129 qDebug() << "and now create the installer using:"; | 174 QDir binDir(mBinaryFolder->text()); |
130 qDebug() << "source archive: " << mArchiveFile->text(); | 175 QDir outDir(mSaveFile->text()); |
131 qDebug() << "certificate: " << mCertFile->text(); | 176 if (mBinaryFolder->text().isEmpty() || !binDir.exists()) { |
132 qDebug() << "target" << mSaveFile->text(); | 177 showErrorMessage(tr("Please select an existing input folder.")); |
133 // TODO | 178 return; |
134 } | 179 } |
180 if (mCertFile->text().isEmpty()) { | |
181 showErrorMessage(tr("Please select a codesigning certificate.")); | |
182 return; | |
183 } | |
184 if (mSaveFile->text().isEmpty() || !outDir.exists()) { | |
185 showErrorMessage(tr("Please select a output folder.")); | |
186 return; | |
187 } | |
188 QSettings options(binDir.filePath("meta.ini"), QSettings::IniFormat); | |
189 options.sync(); | |
190 QStringList keys = options.allKeys(); | |
191 if (options.status() != QSettings::NoError || keys.size() < 1) { | |
192 showErrorMessage(tr("Folder %1 does not appear to contain a meta.ini") | |
193 .arg(binDir.path())); | |
194 return; | |
195 } | |
196 | |
197 /* Copy windows directory contents to tmpdir */ | |
198 QStringList arguments; | |
199 mNSISProc.setProgram("makensis"); | |
200 mNSISProc.setProcessChannelMode(QProcess::MergedChannels); | |
201 mNSISProc.setWorkingDirectory(outDir.path()); | |
202 arguments << QString::fromLatin1("-Dfiles_dir=") + binDir.path() + "/windows"; | |
203 foreach (const QString &key, keys) { | |
204 arguments << QString::fromLatin1("-D%1=%2").arg(key, | |
205 options.value(key, QString()).toString()); | |
206 } | |
207 | |
208 arguments << binDir.path() + "/trustbridge.nsi"; | |
209 | |
210 qDebug() << "Starting makensis with arguments: " << arguments; | |
211 mNSISProc.setArguments(arguments); | |
212 mNSISProc.start(); | |
213 mProgress.show(); | |
214 | |
215 if (!mNSISProc.waitForStarted() || | |
216 mNSISProc.state() == QProcess::NotRunning) { | |
217 showErrorMessage(tr("Failed to start makensis.\n" | |
218 "Please ensure that makensis is installed and in your PATH variable.")); | |
219 } | |
220 } |