1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
/***************************************************************************
* Copyright (C) 2005-09 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) version 3. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <QDebug>
#include <QAbstractButton>
#include <QFormLayout>
#include <QSpinBox>
#include "coreconfigwizard.h"
#include "iconloader.h"
CoreConfigWizard::CoreConfigWizard(const QList<QVariant> &backends, QWidget *parent) : QWizard(parent) {
foreach(QVariant v, backends) _backends[v.toMap()["DisplayName"].toString()] = v;
setPage(IntroPage, new CoreConfigWizardPages::IntroPage(this));
setPage(AdminUserPage, new CoreConfigWizardPages::AdminUserPage(this));
setPage(StorageSelectionPage, new CoreConfigWizardPages::StorageSelectionPage(_backends, this));
syncPage = new CoreConfigWizardPages::SyncPage(this);
connect(syncPage, SIGNAL(setupCore(const QString &, const QVariantMap &)), this, SLOT(prepareCoreSetup(const QString &, const QVariantMap &)));
setPage(SyncPage, syncPage);
syncRelayPage = new CoreConfigWizardPages::SyncRelayPage(this);
connect(syncRelayPage, SIGNAL(startOver()), this, SLOT(startOver()));
setPage(SyncRelayPage, syncRelayPage);
//setPage(Page_StorageDetails, new StorageDetailsPage());
//setPage(Page_Conclusion, new ConclusionPage(storageProviders));
setStartId(IntroPage);
//setStartId(StorageSelectionPage);
#ifndef Q_WS_MAC
setWizardStyle(ModernStyle);
#endif
setOption(HaveHelpButton, false);
setOption(NoBackButtonOnStartPage, true);
setOption(HaveNextButtonOnLastPage, false);
setOption(HaveFinishButtonOnEarlyPages, false);
setOption(NoCancelButton, true);
setOption(IndependentPages, true);
//setOption(ExtendedWatermarkPixmap, true);
setModal(true);
setWindowTitle(tr("Core Configuration Wizard"));
setPixmap(QWizard::LogoPixmap, DesktopIcon("quassel"));
}
QHash<QString, QVariant> CoreConfigWizard::backends() const {
return _backends;
}
void CoreConfigWizard::prepareCoreSetup(const QString &backend, const QVariantMap &properties) {
// Prevent the user from changing any settings he already specified...
foreach(int idx, visitedPages())
page(idx)->setEnabled(false);
QVariantMap foo;
foo["AdminUser"] = field("adminUser.user").toString();
foo["AdminPasswd"] = field("adminUser.password").toString();
foo["Backend"] = backend;
foo["ConnectionProperties"] = properties;
emit setupCore(foo);
}
void CoreConfigWizard::coreSetupSuccess() {
syncPage->setStatus(tr("Your core has been successfully configured. Logging you in..."));
syncPage->setError(false);
syncRelayPage->setMode(CoreConfigWizardPages::SyncRelayPage::Error);
QVariantMap loginData;
loginData["User"] = field("adminUser.user");
loginData["Password"] = field("adminUser.password");
loginData["RememberPasswd"] = field("adminUser.rememberPasswd");
emit loginToCore(loginData);
}
void CoreConfigWizard::coreSetupFailed(const QString &error) {
syncPage->setStatus(tr("Core configuration failed:<br><b>%1</b><br>Press <em>Next</em> to start over.").arg(error));
syncPage->setError(true);
syncRelayPage->setMode(CoreConfigWizardPages::SyncRelayPage::Error);
//foreach(int idx, visitedPages()) page(idx)->setEnabled(true);
//setStartId(SyncPage);
//restart();
}
void CoreConfigWizard::startOver() {
foreach(int idx, visitedPages()) page(idx)->setEnabled(true);
setStartId(CoreConfigWizard::AdminUserPage);
restart();
}
void CoreConfigWizard::loginSuccess() {
syncPage->setStatus(tr("Your are now logged into your freshly configured Quassel Core!<br>"
"Please remember to configure your identities and networks now."));
syncPage->setComplete(true);
syncPage->setFinalPage(true);
}
void CoreConfigWizard::syncFinished() {
// TODO: display identities and networks settings if appropriate!
// accept();
}
namespace CoreConfigWizardPages {
/*** Intro Page ***/
IntroPage::IntroPage(QWidget *parent) : QWizardPage(parent) {
ui.setupUi(this);
setTitle(tr("Introduction"));
//setSubTitle(tr("foobar"));
//setPixmap(QWizard::WatermarkPixmap, QPixmap(":icons/quassel-icon.png"));
}
int IntroPage::nextId() const {
return CoreConfigWizard::AdminUserPage;
}
/*** Admin User Page ***/
AdminUserPage::AdminUserPage(QWidget *parent) : QWizardPage(parent) {
ui.setupUi(this);
setTitle(tr("Create Admin User"));
setSubTitle(tr("First, we will create a user on the core. This first user will have administrator privileges."));
registerField("adminUser.user*", ui.user);
registerField("adminUser.password*", ui.password);
registerField("adminUser.password2*", ui.password2);
registerField("adminUser.rememberPasswd", ui.rememberPasswd);
//ui.user->setText("foo");
//ui.password->setText("foo");
//ui.password2->setText("foo");
}
int AdminUserPage::nextId() const {
return CoreConfigWizard::StorageSelectionPage;
}
bool AdminUserPage::isComplete() const {
bool ok = !ui.user->text().isEmpty() && !ui.password->text().isEmpty() && ui.password->text() == ui.password2->text();
return ok;
}
/*** Storage Selection Page ***/
StorageSelectionPage::StorageSelectionPage(const QHash<QString, QVariant> &backends, QWidget *parent)
: QWizardPage(parent),
_connectionBox(0),
_backends(backends)
{
ui.setupUi(this);
setTitle(tr("Select Storage Backend"));
setSubTitle(tr("Please select a database backend for the Quassel Core storage to store the backlog and other data in."));
setCommitPage(true);
registerField("storage.backend", ui.backendList);
foreach(QString key, _backends.keys()) {
ui.backendList->addItem(_backends[key].toMap()["DisplayName"].toString(), key);
}
on_backendList_currentIndexChanged();
}
int StorageSelectionPage::nextId() const {
return CoreConfigWizard::SyncPage;
}
QString StorageSelectionPage::selectedBackend() const {
return ui.backendList->currentText();
}
QVariantMap StorageSelectionPage::connectionProperties() const {
QString backend = ui.backendList->itemData(ui.backendList->currentIndex()).toString();
QVariantMap properties;
QStringList setupKeys = _backends[backend].toMap()["SetupKeys"].toStringList();
if(!setupKeys.isEmpty()) {
QVariantMap defaults = _backends[backend].toMap()["SetupDefaults"].toMap();
foreach(QString key, setupKeys) {
QWidget *widget = _connectionBox->findChild<QWidget *>(key);
QVariant def;
if(defaults.contains(key)) {
def = defaults[key];
}
switch(def.type()) {
case QVariant::Int:
{
QSpinBox *spinbox = qobject_cast<QSpinBox *>(widget);
Q_ASSERT(spinbox);
def = QVariant(spinbox->value());
}
break;
default:
{
QLineEdit *lineEdit = qobject_cast<QLineEdit *>(widget);
Q_ASSERT(lineEdit);
def = QVariant(lineEdit->text());
}
}
properties[key] = def;
}
}
qDebug() << properties;
// QVariantMap properties = _backends[backend].toMap()["ConnectionProperties"].toMap();
// if(!properties.isEmpty() && _connectionBox) {
// QVariantMap::iterator propertyIter = properties.begin();
// while(propertyIter != properties.constEnd()) {
// QWidget *widget = _connectionBox->findChild<QWidget *>(propertyIter.key());
// switch(propertyIter.value().type()) {
// case QVariant::Int:
// {
// QSpinBox *spinbox = qobject_cast<QSpinBox *>(widget);
// Q_ASSERT(spinbox);
// propertyIter.value() = QVariant(spinbox->value());
// }
// break;
// default:
// {
// QLineEdit *lineEdit = qobject_cast<QLineEdit *>(widget);
// Q_ASSERT(lineEdit);
// propertyIter.value() = QVariant(lineEdit->text());
// }
// }
// propertyIter++;
// }
// }
return properties;
}
void StorageSelectionPage::on_backendList_currentIndexChanged() {
QString backend = ui.backendList->itemData(ui.backendList->currentIndex()).toString();
ui.description->setText(_backends[backend].toMap()["Description"].toString());
if(_connectionBox) {
layout()->removeWidget(_connectionBox);
_connectionBox->deleteLater();
_connectionBox = 0;
}
QStringList setupKeys = _backends[backend].toMap()["SetupKeys"].toStringList();
if(!setupKeys.isEmpty()) {
QVariantMap defaults = _backends[backend].toMap()["SetupDefaults"].toMap();
QGroupBox *propertyBox = new QGroupBox(this);
propertyBox->setTitle(tr("Connection Properties"));
QFormLayout *formlayout = new QFormLayout;
foreach(QString key, setupKeys) {
QWidget *widget = 0;
QVariant def;
if(defaults.contains(key)) {
def = defaults[key];
}
switch(def.type()) {
case QVariant::Int:
{
QSpinBox *spinbox = new QSpinBox(propertyBox);
spinbox->setMaximum(64000);
spinbox->setValue(def.toInt());
widget = spinbox;
}
break;
default:
{
QLineEdit *lineEdit = new QLineEdit(def.toString(), propertyBox);
if(key.toLower().contains("password")) {
lineEdit->setEchoMode(QLineEdit::Password);
}
widget = lineEdit;
}
}
widget->setObjectName(key);
formlayout->addRow(key + ":", widget);
}
propertyBox->setLayout(formlayout);
static_cast<QVBoxLayout *>(layout())->insertWidget(layout()->indexOf(ui.descriptionBox) + 1, propertyBox);
_connectionBox = propertyBox;
}
}
/*** Sync Page ***/
SyncPage::SyncPage(QWidget *parent) : QWizardPage(parent) {
ui.setupUi(this);
setTitle(tr("Storing Your Settings"));
setSubTitle(tr("Your settings are now stored in the core, and you will be logged in automatically."));
}
void SyncPage::initializePage() {
complete = false;
hasError = false;
StorageSelectionPage *storagePage = qobject_cast<StorageSelectionPage *>(wizard()->page(CoreConfigWizard::StorageSelectionPage));
QString backend = storagePage->selectedBackend();
QVariantMap properties = storagePage->connectionProperties();
Q_ASSERT(!backend.isEmpty());
ui.user->setText(wizard()->field("adminUser.user").toString());
ui.backend->setText(backend);
emit setupCore(backend, properties);
}
int SyncPage::nextId() const {
if(!hasError) return -1;
return CoreConfigWizard::SyncRelayPage;
}
bool SyncPage::isComplete() const {
return complete;
}
void SyncPage::setStatus(const QString &status) {
ui.status->setText(status);
}
void SyncPage::setError(bool e) {
hasError = e;
}
void SyncPage::setComplete(bool c) {
complete = c;
completeChanged();
}
/*** Sync Relay Page ***/
SyncRelayPage::SyncRelayPage(QWidget *parent) : QWizardPage(parent) {
mode = Success;
}
void SyncRelayPage::setMode(Mode m) {
mode = m;
}
/*
void SyncRelayPage::initializePage() {
return;
if(mode == Success) {
wizard()->accept();
} else {
emit startOver();
}
}
*/
int SyncRelayPage::nextId() const {
emit startOver();
return 0;
}
}; /* namespace CoreConfigWizardPages */
|