Mercurial > trustbridge
comparison 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 |
comparison
equal
deleted
inserted
replaced
514:ce8325686b09 | 515:9d3880db6ba7 |
---|---|
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 { |
23 QSettings settings; | |
21 setWindowTitle(tr("Create binary installer")); | 24 setWindowTitle(tr("Create binary installer")); |
22 setupGUI(); | 25 setupGUI(); |
23 resize(500, 250); | 26 resize(500, 250); |
27 mCertFile->setText(settings.value("CodeSignCert", QString()).toString()); | |
28 mBinaryFolder->setText(settings.value("LastBinaryFolder", QString()).toString()); | |
29 mSaveFile->setText(settings.value("LastBinOutputFolder", QString()).toString()); | |
24 } | 30 } |
25 | 31 |
26 void CreateInstallerDialog::setupGUI() | 32 void CreateInstallerDialog::setupGUI() |
27 { | 33 { |
28 /* Top level layout / widgets */ | 34 /* Top level layout / widgets */ |
35 QVBoxLayout *fieldLayout = new QVBoxLayout; | 41 QVBoxLayout *fieldLayout = new QVBoxLayout; |
36 QVBoxLayout *buttonLayout = new QVBoxLayout; | 42 QVBoxLayout *buttonLayout = new QVBoxLayout; |
37 | 43 |
38 QLabel *header = new QLabel("<h3>" + tr("Create binary installer") + "</h3>"); | 44 QLabel *header = new QLabel("<h3>" + tr("Create binary installer") + "</h3>"); |
39 QLabel *description = new QLabel( | 45 QLabel *description = new QLabel( |
40 tr("Create and sign a TrustBridge binary installer from source.")); | 46 tr("Create and sign a TrustBridge binary installer.")); |
41 headerSubLayout->insertSpacing(0, 40); | 47 headerSubLayout->insertSpacing(0, 40); |
42 headerSubLayout->addWidget(description); | 48 headerSubLayout->addWidget(description); |
43 QFrame *headerSeparator = new QFrame(); | 49 QFrame *headerSeparator = new QFrame(); |
44 headerSeparator->setFrameShape(QFrame::HLine); | 50 headerSeparator->setFrameShape(QFrame::HLine); |
45 headerSeparator->setFrameShadow(QFrame::Sunken); | 51 headerSeparator->setFrameShadow(QFrame::Sunken); |
46 headerLayout->addWidget(header); | 52 headerLayout->addWidget(header); |
47 headerLayout->addLayout(headerSubLayout); | 53 headerLayout->addLayout(headerSubLayout); |
48 headerLayout->addWidget(headerSeparator); | 54 headerLayout->addWidget(headerSeparator); |
49 headerLayout->insertSpacing(4, 10); | 55 headerLayout->insertSpacing(4, 10); |
50 | 56 |
51 QLabel *archiveLabel = new QLabel(tr("Select source archive:")); | 57 QLabel *archiveLabel = new QLabel(tr("Select binary folder:")); |
52 QLabel *certLabel = new QLabel(tr("Select code signing certificate (secret key):")); | 58 QLabel *certLabel = new QLabel(tr("Select code signing certificate:")); |
53 QLabel *saveLabel = new QLabel(tr("Select output folder:")); | 59 QLabel *saveLabel = new QLabel(tr("Select output folder:")); |
54 labelLayout->addWidget(archiveLabel); | 60 labelLayout->addWidget(archiveLabel); |
55 labelLayout->addWidget(certLabel); | 61 labelLayout->addWidget(certLabel); |
56 labelLayout->addWidget(saveLabel); | 62 labelLayout->addWidget(saveLabel); |
57 | 63 |
58 mArchiveFile = new QLineEdit(); | 64 mBinaryFolder = new QLineEdit(); |
59 mCertFile = new QLineEdit(); | 65 mCertFile = new QLineEdit(); |
60 mSaveFile = new QLineEdit(); | 66 mSaveFile = new QLineEdit(); |
61 fieldLayout->addWidget(mArchiveFile); | 67 fieldLayout->addWidget(mBinaryFolder); |
62 fieldLayout->addWidget(mCertFile); | 68 fieldLayout->addWidget(mCertFile); |
63 fieldLayout->addWidget(mSaveFile); | 69 fieldLayout->addWidget(mSaveFile); |
64 | 70 |
65 QPushButton *archiveSelect = new QPushButton("..."); | 71 QPushButton *archiveSelect = new QPushButton("..."); |
66 connect(archiveSelect, SIGNAL(clicked()), this, SLOT(openArchiveSelect())); | 72 connect(archiveSelect, SIGNAL(clicked()), this, SLOT(openFolderSelect())); |
67 archiveSelect->setFixedWidth(30); | 73 archiveSelect->setFixedWidth(30); |
68 QPushButton *certSelect = new QPushButton("..."); | 74 QPushButton *certSelect = new QPushButton("..."); |
69 connect(certSelect, SIGNAL(clicked()), this, SLOT(openCertificateSelect())); | 75 connect(certSelect, SIGNAL(clicked()), this, SLOT(openCertificateSelect())); |
70 certSelect->setFixedWidth(30); | 76 certSelect->setFixedWidth(30); |
71 QPushButton *saveSelect = new QPushButton("..."); | 77 QPushButton *saveSelect = new QPushButton("..."); |
103 return; | 109 return; |
104 } | 110 } |
105 | 111 |
106 void CreateInstallerDialog::openCertificateSelect() | 112 void CreateInstallerDialog::openCertificateSelect() |
107 { | 113 { |
114 QSettings settings; | |
108 QString certFile = QFileDialog::getOpenFileName( | 115 QString certFile = QFileDialog::getOpenFileName( |
109 this, tr("Select certificate"), QDir::homePath(), "*.pem *.der *.crt"); | 116 this, tr("Select certificate"), |
117 mCertFile->text().isEmpty() ? QDir::homePath() : mCertFile->text(), | |
118 "*.pem *.der *.crt"); | |
119 settings.setValue("CodeSignCert", certFile); | |
110 mCertFile->setText(certFile); | 120 mCertFile->setText(certFile); |
111 } | 121 } |
112 | 122 |
113 void CreateInstallerDialog::openArchiveSelect() | 123 void CreateInstallerDialog::openFolderSelect() |
114 { | 124 { |
115 QString archiveFile = QFileDialog::getOpenFileName( | 125 QSettings settings; |
116 this, tr("Select source archive"), QDir::homePath(), "*.zip *.tar.gz"); | 126 QString archiveFolder = QFileDialog::getExistingDirectory( |
117 mArchiveFile->setText(archiveFile); | 127 this, tr("Select binary folder"), |
128 mBinaryFolder->text().isEmpty() ? QDir::homePath() : mBinaryFolder->text()); | |
129 mBinaryFolder->setText(archiveFolder); | |
130 settings.setValue("LastBinaryFolder", archiveFolder); | |
118 } | 131 } |
119 | 132 |
120 void CreateInstallerDialog::openSaveLocation() | 133 void CreateInstallerDialog::openSaveLocation() |
121 { | 134 { |
135 QSettings settings; | |
122 QString saveFile = QFileDialog::getExistingDirectory( | 136 QString saveFile = QFileDialog::getExistingDirectory( |
123 this, tr("Select target location"), QDir::homePath()); | 137 this, tr("Select target location"), |
138 mSaveFile->text().isEmpty() ? QDir::homePath() : mSaveFile->text()); | |
124 mSaveFile->setText(saveFile); | 139 mSaveFile->setText(saveFile); |
140 settings.setValue("LastBinOutputFolder", saveFile); | |
141 } | |
142 | |
143 void CreateInstallerDialog::showErrorMessage(const QString &msg) | |
144 { | |
145 QMessageBox::warning(this, tr("Error!"), msg); | |
125 } | 146 } |
126 | 147 |
127 void CreateInstallerDialog::createInstaller() | 148 void CreateInstallerDialog::createInstaller() |
128 { | 149 { |
150 QDir binDir(mBinaryFolder->text()); | |
151 if (mBinaryFolder->text().isEmpty() && binDir.exists()) { | |
152 showErrorMessage(tr("Please select an existing input folder.")); | |
153 } | |
129 qDebug() << "and now create the installer using:"; | 154 qDebug() << "and now create the installer using:"; |
130 qDebug() << "source archive: " << mArchiveFile->text(); | 155 qDebug() << "source archive: " << mBinaryFolder->text(); |
131 qDebug() << "certificate: " << mCertFile->text(); | 156 qDebug() << "certificate: " << mCertFile->text(); |
132 qDebug() << "target" << mSaveFile->text(); | 157 qDebug() << "target" << mSaveFile->text(); |
133 // TODO | |
134 } | 158 } |