comparison ui/createinstallerdialog.cpp @ 516:3332db04c77d

Call makensis in create installer dialog
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 28 Apr 2014 17:15:31 +0000
parents 9d3880db6ba7
children 31e0a86f5a35
comparison
equal deleted inserted replaced
515:9d3880db6ba7 516:3332db04c77d
16 #include <QFileDialog> 16 #include <QFileDialog>
17 #include <QSettings> 17 #include <QSettings>
18 #include <QMessageBox> 18 #include <QMessageBox>
19 19
20 CreateInstallerDialog::CreateInstallerDialog(QMainWindow *parent) : 20 CreateInstallerDialog::CreateInstallerDialog(QMainWindow *parent) :
21 QDialog(parent) 21 QDialog(parent),
22 mProgress(this)
22 { 23 {
23 QSettings settings; 24 QSettings settings;
24 setWindowTitle(tr("Create binary installer")); 25 setWindowTitle(tr("Create binary installer"));
25 setupGUI(); 26 setupGUI();
26 resize(500, 250); 27 resize(500, 250);
27 mCertFile->setText(settings.value("CodeSignCert", QString()).toString()); 28 mCertFile->setText(settings.value("CodeSignCert", QString()).toString());
28 mBinaryFolder->setText(settings.value("LastBinaryFolder", QString()).toString()); 29 mBinaryFolder->setText(settings.value("LastBinaryFolder", QString()).toString());
29 mSaveFile->setText(settings.value("LastBinOutputFolder", 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)));
30 } 36 }
31 37
32 void CreateInstallerDialog::setupGUI() 38 void CreateInstallerDialog::setupGUI()
33 { 39 {
34 /* Top level layout / widgets */ 40 /* Top level layout / widgets */
104 topLayout->addWidget(bottomSeparator); 110 topLayout->addWidget(bottomSeparator);
105 topLayout->addLayout(bottomLayout); 111 topLayout->addLayout(bottomLayout);
106 112
107 setLayout(topLayout); 113 setLayout(topLayout);
108 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
109 return; 121 return;
110 } 122 }
111 123
112 void CreateInstallerDialog::openCertificateSelect() 124 void CreateInstallerDialog::openCertificateSelect()
113 { 125 {
143 void CreateInstallerDialog::showErrorMessage(const QString &msg) 155 void CreateInstallerDialog::showErrorMessage(const QString &msg)
144 { 156 {
145 QMessageBox::warning(this, tr("Error!"), msg); 157 QMessageBox::warning(this, tr("Error!"), msg);
146 } 158 }
147 159
160 void CreateInstallerDialog::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
161 {
162 mProgress.cancel();
163 }
164
165 void CreateInstallerDialog::processError(QProcess::ProcessError error)
166 {
167 mProgress.cancel();
168 }
169
148 void CreateInstallerDialog::createInstaller() 170 void CreateInstallerDialog::createInstaller()
149 { 171 {
150 QDir binDir(mBinaryFolder->text()); 172 QDir binDir(mBinaryFolder->text());
151 if (mBinaryFolder->text().isEmpty() && binDir.exists()) { 173 QDir outDir(mSaveFile->text());
174 if (mBinaryFolder->text().isEmpty() || !binDir.exists()) {
152 showErrorMessage(tr("Please select an existing input folder.")); 175 showErrorMessage(tr("Please select an existing input folder."));
153 } 176 return;
154 qDebug() << "and now create the installer using:"; 177 }
155 qDebug() << "source archive: " << mBinaryFolder->text(); 178 if (mCertFile->text().isEmpty()) {
156 qDebug() << "certificate: " << mCertFile->text(); 179 showErrorMessage(tr("Please select a codesigning certificate."));
157 qDebug() << "target" << mSaveFile->text(); 180 return;
158 } 181 }
182 if (mSaveFile->text().isEmpty() || !outDir.exists()) {
183 showErrorMessage(tr("Please select a output folder."));
184 return;
185 }
186 QSettings options(binDir.filePath("meta.ini"), QSettings::IniFormat);
187 options.sync();
188 QStringList keys = options.allKeys();
189 if (options.status() != QSettings::NoError || keys.size() < 1) {
190 showErrorMessage(tr("Folder %1 does not appear to contain a meta.ini")
191 .arg(binDir.path()));
192 return;
193 }
194
195 /* Copy windows directory contents to tmpdir */
196 QStringList arguments;
197 mNSISProc.setProgram("makensis");
198 mNSISProc.setWorkingDirectory(outDir.path());
199 arguments << QString::fromLatin1("-Dfiles_dir=") + binDir.path() + "/windows";
200
201 foreach (const QString &key, keys) {
202 arguments << QString::fromLatin1("-D%1=\"%2\"").arg(key,
203 options.value(key, QString()).toString());
204 }
205
206 arguments << binDir.path() + "/trustbridge.nsi";
207
208 mNSISProc.start();
209 mProgress.show();
210
211 if (!mNSISProc.waitForStarted() ||
212 mNSISProc.state() == QProcess::NotRunning) {
213 showErrorMessage(tr("Failed to start makensis.\n"
214 "Please ensure that makensis is installed and in your PATH variable."));
215 }
216
217
218
219
220 }

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