1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel Project *
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 ***************************************************************************/
23 #include "configwizard.h"
25 ConfigWizard::ConfigWizard(const QStringList &storageProviders, QWidget *parent) : QWizard(parent) {
26 setPage(Page_Intro, new IntroPage());
27 setPage(Page_AdminUser, new AdminUserPage());
28 setPage(Page_StorageSelection, new StorageSelectionPage(storageProviders));
29 setPage(Page_StorageDetails, new StorageDetailsPage());
30 setPage(Page_Conclusion, new ConclusionPage(storageProviders));
32 setStartId(Page_Intro);
35 setWizardStyle(ModernStyle);
38 setOption(HaveHelpButton, false);
39 setOption(NoBackButtonOnStartPage, true);
40 setOption(HaveNextButtonOnLastPage, false);
41 setOption(HaveFinishButtonOnEarlyPages, false);
42 setOption(NoCancelButton, true);
44 setWindowTitle(tr("Core Configuration Wizard"));
48 IntroPage::IntroPage(QWidget *parent) : QWizardPage(parent) {
49 setTitle(tr("Introduction"));
51 label = new QLabel(tr("This wizard will guide you through the setup process for your shiny new Quassel IRC Client."));
52 label->setWordWrap(true);
54 QVBoxLayout *layout = new QVBoxLayout();
55 layout->addWidget(label);
59 int IntroPage::nextId() const {
60 return ConfigWizard::Page_AdminUser;
64 AdminUserPage::AdminUserPage(QWidget *parent) : QWizardPage(parent) {
65 setTitle(tr("Setup Admin User"));
66 setSubTitle(tr("Please enter credentials for the admin user."));
68 nameLabel = new QLabel(tr("Name:"));
69 nameEdit = new QLineEdit();
70 nameLabel->setBuddy(nameEdit);
72 passwordLabel = new QLabel(tr("Password:"));
73 passwordEdit = new QLineEdit();
74 passwordEdit->setEchoMode(QLineEdit::Password);
75 passwordLabel->setBuddy(passwordLabel);
77 registerField("adminuser.name*", nameEdit);
78 registerField("adminuser.password*", passwordEdit);
80 QGridLayout *layout = new QGridLayout();
81 layout->addWidget(nameLabel, 0, 0);
82 layout->addWidget(nameEdit, 0, 1);
83 layout->addWidget(passwordLabel, 1, 0);
84 layout->addWidget(passwordEdit, 1, 1);
88 int AdminUserPage::nextId() const {
89 return ConfigWizard::Page_StorageSelection;
93 StorageSelectionPage::StorageSelectionPage(const QStringList &storageProviders, QWidget *parent) : QWizardPage(parent) {
94 setTitle(tr("Select Storage Provider"));
95 setSubTitle(tr("Please select the storage provider you want to use."));
97 storageSelection = new QComboBox();
98 storageSelection->addItems(storageProviders);
100 registerField("storage.provider", storageSelection);
102 QVBoxLayout *layout = new QVBoxLayout();
103 layout->addWidget(storageSelection);
107 int StorageSelectionPage::nextId() const {
108 QString selection = storageSelection->currentText();
109 if (!selection.compare("Sqlite", Qt::CaseInsensitive)) {
110 return ConfigWizard::Page_Conclusion;
112 return ConfigWizard::Page_StorageDetails;
117 StorageDetailsPage::StorageDetailsPage(QWidget *parent) : QWizardPage(parent) {
118 setTitle(tr("Setup Storage Provider"));
119 setSubTitle(tr("Please enter credentials for the selected storage provider."));
121 hostLabel = new QLabel(tr("Host:"));
122 hostEdit = new QLineEdit();
123 hostLabel->setBuddy(hostEdit);
125 portLabel = new QLabel(tr("Port:"));
126 portEdit = new QLineEdit();
127 QIntValidator *portValidator = new QIntValidator(0, 65535, this);
128 portEdit->setValidator(portValidator);
129 portLabel->setBuddy(portEdit);
131 databaseLabel = new QLabel(tr("Database:"));
132 databaseEdit = new QLineEdit();
133 databaseLabel->setBuddy(databaseEdit);
135 userLabel = new QLabel(tr("User:"));
136 userEdit = new QLineEdit();
137 userLabel->setBuddy(userEdit);
139 passwordLabel = new QLabel(tr("Password:"));
140 passwordEdit = new QLineEdit();
141 passwordEdit->setEchoMode(QLineEdit::Password);
142 passwordLabel->setBuddy(passwordLabel);
144 registerField("storage.host*", hostEdit);
145 registerField("storage.port*", portEdit);
146 registerField("storage.database*", databaseEdit);
147 registerField("storage.user*", userEdit);
148 registerField("storage.password*", passwordEdit);
150 QGridLayout *layout = new QGridLayout();
151 layout->addWidget(hostLabel, 0, 0);
152 layout->addWidget(hostEdit, 0, 1);
153 layout->addWidget(portLabel, 1, 0);
154 layout->addWidget(portEdit, 1, 1);
155 layout->addWidget(databaseLabel, 2, 0);
156 layout->addWidget(databaseEdit, 2, 1);
157 layout->addWidget(userLabel, 3, 0);
158 layout->addWidget(userEdit, 3, 1);
159 layout->addWidget(passwordLabel, 4, 0);
160 layout->addWidget(passwordEdit, 4, 1);
164 int StorageDetailsPage::nextId() const {
165 return ConfigWizard::Page_Conclusion;
169 ConclusionPage::ConclusionPage(const QStringList &storageProviders, QWidget *parent) : QWizardPage(parent) {
170 setTitle(tr("Conclusion"));
171 setSubTitle(tr("You chose the following configuration:"));
173 this->storageProviders = storageProviders;
175 adminuser = new QLabel();
176 storage = new QLabel();
177 storage->setWordWrap(true);
179 QVBoxLayout *layout = new QVBoxLayout();
180 layout->addWidget(adminuser);
181 layout->addWidget(storage);
185 int ConclusionPage::nextId() const {
189 void ConclusionPage::initializePage() {
190 QString adminuserText = "Admin User: " + field("adminuser.name").toString();
191 adminuser->setText(adminuserText);
193 QString storageText = "Selected Storage Provider: ";
194 QString sp = storageProviders.value(field("storage.provider").toInt());
195 if (!sp.compare("Sqlite", Qt::CaseInsensitive)) {
196 storageText.append(sp);
198 storageText += sp + "\nHost: " + field("storage.host").toString() + "\nPort: " + field("storage.port").toString() + "\nDatabase: " + field("storage.database").toString() + "\nUser: " + field("storage.user").toString();
200 storage->setText(storageText);