1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel IRC Team *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
22 #include <QAbstractButton>
24 #include "coreconfigwizard.h"
27 //#include "identitiessettingspage.h"
29 CoreConfigWizard::CoreConfigWizard(const QList<QVariant> &backends, QWidget *parent) : QWizard(parent) {
30 foreach(QVariant v, backends) _backends[v.toMap()["DisplayName"].toString()] = v;
31 setPage(IntroPage, new CoreConfigWizardPages::IntroPage(this));
32 setPage(AdminUserPage, new CoreConfigWizardPages::AdminUserPage(this));
33 setPage(StorageSelectionPage, new CoreConfigWizardPages::StorageSelectionPage(_backends, this));
34 syncPage = new CoreConfigWizardPages::SyncPage(this);
35 connect(syncPage, SIGNAL(setupCore(const QString &)), this, SLOT(prepareCoreSetup(const QString &)));
36 setPage(SyncPage, syncPage);
37 syncRelayPage = new CoreConfigWizardPages::SyncRelayPage(this);
38 connect(syncRelayPage, SIGNAL(startOver()), this, SLOT(startOver()));
39 setPage(SyncRelayPage, syncRelayPage);
40 //setPage(Page_StorageDetails, new StorageDetailsPage());
41 //setPage(Page_Conclusion, new ConclusionPage(storageProviders));
43 setStartId(IntroPage);
44 //setStartId(StorageSelectionPage);
47 setWizardStyle(ModernStyle);
50 setOption(HaveHelpButton, false);
51 setOption(NoBackButtonOnStartPage, true);
52 setOption(HaveNextButtonOnLastPage, false);
53 setOption(HaveFinishButtonOnEarlyPages, false);
54 setOption(NoCancelButton, true);
55 setOption(IndependentPages, true);
56 //setOption(ExtendedWatermarkPixmap, true);
60 setWindowTitle(tr("Core Configuration Wizard"));
61 setPixmap(QWizard::LogoPixmap, QPixmap(":icons/quassel-icon.png"));
64 QHash<QString, QVariant> CoreConfigWizard::backends() const {
68 void CoreConfigWizard::prepareCoreSetup(const QString &backend) {
69 // Prevent the user from changing any settings he already specified...
70 foreach(int idx, visitedPages()) page(idx)->setEnabled(false);
72 foo["AdminUser"] = field("adminUser.user").toString();
73 foo["AdminPasswd"] = field("adminUser.password").toString();
74 foo["Backend"] = backend;
78 void CoreConfigWizard::coreSetupSuccess() {
79 syncPage->setStatus(tr("Your core has been successfully configured. Logging you in..."));
80 syncPage->setError(false);
81 syncRelayPage->setMode(CoreConfigWizardPages::SyncRelayPage::Error);
82 QVariantMap loginData;
83 loginData["User"] = field("adminUser.user");
84 loginData["Password"] = field("adminUser.password");
85 loginData["RememberPasswd"] = field("adminUser.rememberPasswd");
86 emit loginToCore(loginData);
89 void CoreConfigWizard::coreSetupFailed(const QString &error) {
90 syncPage->setStatus(tr("Core configuration failed:<br><b>%1</b><br>Press <em>Next</em> to start over.").arg(error));
91 syncPage->setError(true);
92 syncRelayPage->setMode(CoreConfigWizardPages::SyncRelayPage::Error);
93 //foreach(int idx, visitedPages()) page(idx)->setEnabled(true);
94 //setStartId(SyncPage);
99 void CoreConfigWizard::startOver() {
100 foreach(int idx, visitedPages()) page(idx)->setEnabled(true);
101 setStartId(CoreConfigWizard::AdminUserPage);
105 void CoreConfigWizard::loginSuccess() {
106 syncPage->setStatus(tr("Your are now logged into your freshly configured Quassel Core!<br>"
107 "Please remember to configure your identities and networks now."));
108 syncPage->setComplete(true);
109 syncPage->setFinalPage(true);
112 void CoreConfigWizard::syncFinished() {
113 // TODO: display identities and networks settings if appropriate!
117 namespace CoreConfigWizardPages {
121 IntroPage::IntroPage(QWidget *parent) : QWizardPage(parent) {
123 setTitle(tr("Introduction"));
124 //setSubTitle(tr("foobar"));
125 //setPixmap(QWizard::WatermarkPixmap, QPixmap(":icons/quassel-icon.png"));
129 int IntroPage::nextId() const {
130 return CoreConfigWizard::AdminUserPage;
134 /*** Admin User Page ***/
136 AdminUserPage::AdminUserPage(QWidget *parent) : QWizardPage(parent) {
138 setTitle(tr("Create User Account"));
139 setSubTitle(tr("First, we will create a user account on the core. This first user will have administrator privileges."));
141 registerField("adminUser.user*", ui.user);
142 registerField("adminUser.password*", ui.password);
143 registerField("adminUser.password2*", ui.password2);
144 registerField("adminUser.rememberPasswd", ui.rememberPasswd);
146 //ui.user->setText("foo");
147 //ui.password->setText("foo");
148 //ui.password2->setText("foo");
151 int AdminUserPage::nextId() const {
152 return CoreConfigWizard::StorageSelectionPage;
156 bool AdminUserPage::isComplete() const {
157 bool ok = !ui.user->text().isEmpty() && !ui.password->text().isEmpty() && ui.password->text() == ui.password2->text();
161 /*** Storage Selection Page ***/
163 StorageSelectionPage::StorageSelectionPage(const QHash<QString, QVariant> &backends, QWidget *parent) : QWizardPage(parent) {
165 _backends = backends;
167 setTitle(tr("Select Storage Backend"));
168 setSubTitle(tr("Please select a database backend for the Quassel Core storage to store the backlog and other data in."));
171 registerField("storage.backend", ui.backendList);
173 foreach(QString key, _backends.keys()) {
174 ui.backendList->addItem(_backends[key].toMap()["DisplayName"].toString(), key);
177 on_backendList_currentIndexChanged();
180 int StorageSelectionPage::nextId() const {
181 return CoreConfigWizard::SyncPage;
184 QString StorageSelectionPage::selectedBackend() const {
185 return ui.backendList->currentText();
188 void StorageSelectionPage::on_backendList_currentIndexChanged() {
189 QString backend = ui.backendList->itemData(ui.backendList->currentIndex()).toString();
190 ui.description->setText(_backends[backend].toMap()["Description"].toString());
195 SyncPage::SyncPage(QWidget *parent) : QWizardPage(parent) {
197 setTitle(tr("Storing Your Settings"));
198 setSubTitle(tr("Your settings are now stored in the core, and you will be logged in automatically."));
201 void SyncPage::initializePage() {
204 QString backend = qobject_cast<StorageSelectionPage *>(wizard()->page(CoreConfigWizard::StorageSelectionPage))->selectedBackend();
205 Q_ASSERT(!backend.isEmpty());
206 ui.user->setText(wizard()->field("adminUser.user").toString());
207 ui.backend->setText(backend);
208 emit setupCore(backend);
211 int SyncPage::nextId() const {
212 if(!hasError) return -1;
213 return CoreConfigWizard::SyncRelayPage;
216 bool SyncPage::isComplete() const {
220 void SyncPage::setStatus(const QString &status) {
221 ui.status->setText(status);
224 void SyncPage::setError(bool e) {
228 void SyncPage::setComplete(bool c) {
233 /*** Sync Relay Page ***/
235 SyncRelayPage::SyncRelayPage(QWidget *parent) : QWizardPage(parent) {
239 void SyncRelayPage::setMode(Mode m) {
244 void SyncRelayPage::initializePage() {
246 if(mode == Success) {
254 int SyncRelayPage::nextId() const {
259 }; /* namespace CoreConfigWizardPages */