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 ***************************************************************************/
21 #include "ircconnectionwizard.h"
24 #include "identityeditwidget.h"
25 #include "simplenetworkeditor.h"
27 #include <QVBoxLayout>
29 IrcConnectionWizard::IrcConnectionWizard(QWidget *parent, Qt::WindowFlags flags)
30 : QWizard(parent, flags),
36 _introductionPage = createIntroductionPage(this);
37 _identityPage = new IdentityPage(this);
38 _networkPage = new NetworkPage(this);
41 addPage(_introductionPage);
42 addPage(_identityPage);
43 addPage(_networkPage);
45 setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
47 setOptions(options() | (QWizard::WizardOptions)(QWizard::NoDefaultButton | QWizard::CancelButtonOnLeft));
48 setOption(QWizard::NoCancelButton, false);
50 connect(button(QWizard::FinishButton), SIGNAL(clicked()), this, SLOT(finishClicked()));
51 setButtonText(QWizard::FinishButton, tr("Save && Connect"));
54 QWizardPage *IrcConnectionWizard::createIntroductionPage(QWidget *parent) {
55 QWizardPage *page = new QWizardPage(parent);
56 page->setTitle(QObject::tr("Welcome to Quassel IRC"));
58 QLabel *label = new QLabel(QObject::tr("This wizard will help you setting up your default identity and your IRC network connection. "
59 "You can abort this wizard in any step, if you want to setup your identity and IRC connection in more detail. "
60 "This can be done in the settings."), page);
61 label->setWordWrap(true);
63 QVBoxLayout *layout = new QVBoxLayout;
64 layout->addWidget(label);
65 page->setLayout(layout);
69 void IrcConnectionWizard::finishClicked() {
70 CertIdentity *identity = static_cast<IdentityPage *>(_identityPage)->identity();
71 if(identity->id().isValid()) {
72 Client::updateIdentity(identity->id(), identity->toVariantMap());
73 identityReady(identity->id());
75 connect(Client::instance(), SIGNAL(identityCreated(IdentityId)), this, SLOT(identityReady(IdentityId)));
76 Client::createIdentity(*identity);
80 void IrcConnectionWizard::identityReady(IdentityId id) {
81 disconnect(Client::instance(), SIGNAL(identityCreated(IdentityId)), this, SLOT(identityReady(IdentityId)));
82 NetworkPage *networkPage = static_cast<NetworkPage *>(_networkPage);
83 NetworkInfo networkInfo = networkPage->networkInfo();
84 QStringList channels = networkPage->channelList();
85 networkInfo.identity = id;
86 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(networkReady(NetworkId)));
87 Client::createNetwork(networkInfo, channels);
90 void IrcConnectionWizard::networkReady(NetworkId id) {
91 disconnect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(networkReady(NetworkId)));
92 const Network *net = Client::network(id);
94 net->requestConnect();
98 // ==============================
100 // ==============================
103 IdentityPage::IdentityPage(QWidget *parent)
104 : QWizardPage(parent),
105 _identityEditWidget(new IdentityEditWidget(this)),
108 setTitle(tr("Setup Identity"));
110 if(Client::identityIds().isEmpty()) {
111 _identity = new CertIdentity(-1, this);
112 _identity->setToDefaults();
113 _identity->setIdentityName(tr("Default Identity"));
115 _identity = new CertIdentity(*Client::identity(Client::identityIds().first()), this);
118 _identityEditWidget->displayIdentity(_identity);
119 _identityEditWidget->showAdvanced(false);
120 QVBoxLayout *layout = new QVBoxLayout;
121 layout->addWidget(_identityEditWidget);
125 CertIdentity *IdentityPage::identity() {
126 _identityEditWidget->saveToIdentity(_identity);
132 NetworkPage::NetworkPage(QWidget *parent)
133 : QWizardPage(parent),
134 _networkEditor(new SimpleNetworkEditor(this))
137 QStringList defaultNets = Network::presetNetworks(true);
138 if(!defaultNets.isEmpty()) {
139 NetworkInfo info = Network::networkInfoFromPreset(defaultNets[0]);
140 if(!info.networkName.isEmpty()) {
142 _channelList = Network::presetDefaultChannels(defaultNets[0]);
146 _networkEditor->displayNetworkInfo(_networkInfo);
147 _networkEditor->setDefaultChannels(_channelList);
149 setTitle(tr("Setup Network Connection"));
151 QVBoxLayout *layout = new QVBoxLayout;
152 layout->addWidget(_networkEditor);
156 NetworkInfo NetworkPage::networkInfo() {
157 _networkEditor->saveToNetworkInfo(_networkInfo);
161 QStringList NetworkPage::channelList() {
162 _channelList = _networkEditor->defaultChannels();