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"
25 #include "iconloader.h"
27 CoreConfigWizard::CoreConfigWizard(const QList<QVariant> &backends, QWidget *parent) : QWizard(parent) {
28 foreach(QVariant v, backends) _backends[v.toMap()["DisplayName"].toString()] = v;
29 setPage(IntroPage, new CoreConfigWizardPages::IntroPage(this));
30 setPage(AdminUserPage, new CoreConfigWizardPages::AdminUserPage(this));
31 setPage(StorageSelectionPage, new CoreConfigWizardPages::StorageSelectionPage(_backends, this));
32 syncPage = new CoreConfigWizardPages::SyncPage(this);
33 connect(syncPage, SIGNAL(setupCore(const QString &)), this, SLOT(prepareCoreSetup(const QString &)));
34 setPage(SyncPage, syncPage);
35 syncRelayPage = new CoreConfigWizardPages::SyncRelayPage(this);
36 connect(syncRelayPage, SIGNAL(startOver()), this, SLOT(startOver()));
37 setPage(SyncRelayPage, syncRelayPage);
38 //setPage(Page_StorageDetails, new StorageDetailsPage());
39 //setPage(Page_Conclusion, new ConclusionPage(storageProviders));
41 setStartId(IntroPage);
42 //setStartId(StorageSelectionPage);
45 setWizardStyle(ModernStyle);
48 setOption(HaveHelpButton, false);
49 setOption(NoBackButtonOnStartPage, true);
50 setOption(HaveNextButtonOnLastPage, false);
51 setOption(HaveFinishButtonOnEarlyPages, false);
52 setOption(NoCancelButton, true);
53 setOption(IndependentPages, true);
54 //setOption(ExtendedWatermarkPixmap, true);
58 setWindowTitle(tr("Core Configuration Wizard"));
59 setPixmap(QWizard::LogoPixmap, DesktopIcon("quassel"));
62 QHash<QString, QVariant> CoreConfigWizard::backends() const {
66 void CoreConfigWizard::prepareCoreSetup(const QString &backend) {
67 // Prevent the user from changing any settings he already specified...
68 foreach(int idx, visitedPages()) page(idx)->setEnabled(false);
70 foo["AdminUser"] = field("adminUser.user").toString();
71 foo["AdminPasswd"] = field("adminUser.password").toString();
72 foo["Backend"] = backend;
76 void CoreConfigWizard::coreSetupSuccess() {
77 syncPage->setStatus(tr("Your core has been successfully configured. Logging you in..."));
78 syncPage->setError(false);
79 syncRelayPage->setMode(CoreConfigWizardPages::SyncRelayPage::Error);
80 QVariantMap loginData;
81 loginData["User"] = field("adminUser.user");
82 loginData["Password"] = field("adminUser.password");
83 loginData["RememberPasswd"] = field("adminUser.rememberPasswd");
84 emit loginToCore(loginData);
87 void CoreConfigWizard::coreSetupFailed(const QString &error) {
88 syncPage->setStatus(tr("Core configuration failed:<br><b>%1</b><br>Press <em>Next</em> to start over.").arg(error));
89 syncPage->setError(true);
90 syncRelayPage->setMode(CoreConfigWizardPages::SyncRelayPage::Error);
91 //foreach(int idx, visitedPages()) page(idx)->setEnabled(true);
92 //setStartId(SyncPage);
97 void CoreConfigWizard::startOver() {
98 foreach(int idx, visitedPages()) page(idx)->setEnabled(true);
99 setStartId(CoreConfigWizard::AdminUserPage);
103 void CoreConfigWizard::loginSuccess() {
104 syncPage->setStatus(tr("Your are now logged into your freshly configured Quassel Core!<br>"
105 "Please remember to configure your identities and networks now."));
106 syncPage->setComplete(true);
107 syncPage->setFinalPage(true);
110 void CoreConfigWizard::syncFinished() {
111 // TODO: display identities and networks settings if appropriate!
115 namespace CoreConfigWizardPages {
119 IntroPage::IntroPage(QWidget *parent) : QWizardPage(parent) {
121 setTitle(tr("Introduction"));
122 //setSubTitle(tr("foobar"));
123 //setPixmap(QWizard::WatermarkPixmap, QPixmap(":icons/quassel-icon.png"));
127 int IntroPage::nextId() const {
128 return CoreConfigWizard::AdminUserPage;
132 /*** Admin User Page ***/
134 AdminUserPage::AdminUserPage(QWidget *parent) : QWizardPage(parent) {
136 setTitle(tr("Create Admin User"));
137 setSubTitle(tr("First, we will create a user on the core. This first user will have administrator privileges."));
139 registerField("adminUser.user*", ui.user);
140 registerField("adminUser.password*", ui.password);
141 registerField("adminUser.password2*", ui.password2);
142 registerField("adminUser.rememberPasswd", ui.rememberPasswd);
144 //ui.user->setText("foo");
145 //ui.password->setText("foo");
146 //ui.password2->setText("foo");
149 int AdminUserPage::nextId() const {
150 return CoreConfigWizard::StorageSelectionPage;
154 bool AdminUserPage::isComplete() const {
155 bool ok = !ui.user->text().isEmpty() && !ui.password->text().isEmpty() && ui.password->text() == ui.password2->text();
159 /*** Storage Selection Page ***/
161 StorageSelectionPage::StorageSelectionPage(const QHash<QString, QVariant> &backends, QWidget *parent) : QWizardPage(parent) {
163 _backends = backends;
165 setTitle(tr("Select Storage Backend"));
166 setSubTitle(tr("Please select a database backend for the Quassel Core storage to store the backlog and other data in."));
169 registerField("storage.backend", ui.backendList);
171 foreach(QString key, _backends.keys()) {
172 ui.backendList->addItem(_backends[key].toMap()["DisplayName"].toString(), key);
175 on_backendList_currentIndexChanged();
178 int StorageSelectionPage::nextId() const {
179 return CoreConfigWizard::SyncPage;
182 QString StorageSelectionPage::selectedBackend() const {
183 return ui.backendList->currentText();
186 void StorageSelectionPage::on_backendList_currentIndexChanged() {
187 QString backend = ui.backendList->itemData(ui.backendList->currentIndex()).toString();
188 ui.description->setText(_backends[backend].toMap()["Description"].toString());
193 SyncPage::SyncPage(QWidget *parent) : QWizardPage(parent) {
195 setTitle(tr("Storing Your Settings"));
196 setSubTitle(tr("Your settings are now stored in the core, and you will be logged in automatically."));
199 void SyncPage::initializePage() {
202 QString backend = qobject_cast<StorageSelectionPage *>(wizard()->page(CoreConfigWizard::StorageSelectionPage))->selectedBackend();
203 Q_ASSERT(!backend.isEmpty());
204 ui.user->setText(wizard()->field("adminUser.user").toString());
205 ui.backend->setText(backend);
206 emit setupCore(backend);
209 int SyncPage::nextId() const {
210 if(!hasError) return -1;
211 return CoreConfigWizard::SyncRelayPage;
214 bool SyncPage::isComplete() const {
218 void SyncPage::setStatus(const QString &status) {
219 ui.status->setText(status);
222 void SyncPage::setError(bool e) {
226 void SyncPage::setComplete(bool c) {
231 /*** Sync Relay Page ***/
233 SyncRelayPage::SyncRelayPage(QWidget *parent) : QWizardPage(parent) {
237 void SyncRelayPage::setMode(Mode m) {
242 void SyncRelayPage::initializePage() {
244 if(mode == Success) {
252 int SyncRelayPage::nextId() const {
257 }; /* namespace CoreConfigWizardPages */