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 to set up your default identity and your IRC network connection.<br>"
59 "This only covers basic settings. You can cancel this wizard any time and use the settings dialog for more detailed changes."), page);
60 label->setWordWrap(true);
62 QVBoxLayout *layout = new QVBoxLayout;
63 layout->addWidget(label);
64 page->setLayout(layout);
68 void IrcConnectionWizard::finishClicked() {
69 CertIdentity *identity = static_cast<IdentityPage *>(_identityPage)->identity();
70 if(identity->id().isValid()) {
71 Client::updateIdentity(identity->id(), identity->toVariantMap());
72 identityReady(identity->id());
74 connect(Client::instance(), SIGNAL(identityCreated(IdentityId)), this, SLOT(identityReady(IdentityId)));
75 Client::createIdentity(*identity);
79 void IrcConnectionWizard::identityReady(IdentityId id) {
80 disconnect(Client::instance(), SIGNAL(identityCreated(IdentityId)), this, SLOT(identityReady(IdentityId)));
81 NetworkPage *networkPage = static_cast<NetworkPage *>(_networkPage);
82 NetworkInfo networkInfo = networkPage->networkInfo();
83 QStringList channels = networkPage->channelList();
84 networkInfo.identity = id;
85 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(networkReady(NetworkId)));
86 Client::createNetwork(networkInfo, channels);
89 void IrcConnectionWizard::networkReady(NetworkId id) {
90 disconnect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(networkReady(NetworkId)));
91 const Network *net = Client::network(id);
93 net->requestConnect();
97 // ==============================
99 // ==============================
102 IdentityPage::IdentityPage(QWidget *parent)
103 : QWizardPage(parent),
104 _identityEditWidget(new IdentityEditWidget(this)),
107 setTitle(tr("Setup Identity"));
109 if(Client::identityIds().isEmpty()) {
110 _identity = new CertIdentity(-1, this);
111 _identity->setToDefaults();
112 _identity->setIdentityName(tr("Default Identity"));
114 _identity = new CertIdentity(*Client::identity(Client::identityIds().first()), this);
117 _identityEditWidget->displayIdentity(_identity);
118 _identityEditWidget->showAdvanced(false);
119 QVBoxLayout *layout = new QVBoxLayout;
120 layout->addWidget(_identityEditWidget);
124 CertIdentity *IdentityPage::identity() {
125 _identityEditWidget->saveToIdentity(_identity);
131 NetworkPage::NetworkPage(QWidget *parent)
132 : QWizardPage(parent),
133 _networkEditor(new SimpleNetworkEditor(this))
136 QStringList defaultNets = Network::presetNetworks(true);
137 if(!defaultNets.isEmpty()) {
138 NetworkInfo info = Network::networkInfoFromPreset(defaultNets[0]);
139 if(!info.networkName.isEmpty()) {
141 _channelList = Network::presetDefaultChannels(defaultNets[0]);
145 _networkEditor->displayNetworkInfo(_networkInfo);
146 _networkEditor->setDefaultChannels(_channelList);
148 setTitle(tr("Setup Network Connection"));
150 QVBoxLayout *layout = new QVBoxLayout;
151 layout->addWidget(_networkEditor);
155 NetworkInfo NetworkPage::networkInfo() {
156 _networkEditor->saveToNetworkInfo(_networkInfo);
160 QStringList NetworkPage::channelList() {
161 _channelList = _networkEditor->defaultChannels();