1 /***************************************************************************
2 * Copyright (C) 2005-2016 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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include "ircconnectionwizard.h"
24 #include "identityeditwidget.h"
25 #include "simplenetworkeditor.h"
26 #include "presetnetworks.h"
28 #include <QVBoxLayout>
30 IrcConnectionWizard::IrcConnectionWizard(QWidget *parent, Qt::WindowFlags flags)
31 : QWizard(parent, flags),
36 _introductionPage = createIntroductionPage(this);
37 _identityPage = new IdentityPage(this);
38 _networkPage = new NetworkPage(this);
40 addPage(_introductionPage);
41 addPage(_identityPage);
42 addPage(_networkPage);
44 setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
46 setOptions(options() | (QWizard::WizardOptions)(QWizard::NoDefaultButton | QWizard::CancelButtonOnLeft));
47 setOption(QWizard::NoCancelButton, false);
49 connect(button(QWizard::FinishButton), SIGNAL(clicked()), this, SLOT(finishClicked()));
50 setButtonText(QWizard::FinishButton, tr("Save && Connect"));
54 QWizardPage *IrcConnectionWizard::createIntroductionPage(QWidget *parent)
56 QWizardPage *page = new QWizardPage(parent);
57 page->setTitle(QObject::tr("Welcome to Quassel IRC"));
59 QLabel *label = new QLabel(QObject::tr("This wizard will help you to set up your default identity and your IRC network connection.<br>"
60 "This only covers basic settings. You can cancel this wizard any time and use the settings dialog for more detailed changes."), page);
61 label->setWordWrap(true);
63 QVBoxLayout *layout = new QVBoxLayout;
64 layout->addWidget(label);
65 page->setLayout(layout);
70 void IrcConnectionWizard::finishClicked()
72 CertIdentity *identity = static_cast<IdentityPage *>(_identityPage)->identity();
73 if (identity->id().isValid()) {
74 Client::updateIdentity(identity->id(), identity->toVariantMap());
75 identityReady(identity->id());
78 connect(Client::instance(), SIGNAL(identityCreated(IdentityId)), this, SLOT(identityReady(IdentityId)));
79 Client::createIdentity(*identity);
84 void IrcConnectionWizard::identityReady(IdentityId id)
86 disconnect(Client::instance(), SIGNAL(identityCreated(IdentityId)), this, SLOT(identityReady(IdentityId)));
87 NetworkPage *networkPage = static_cast<NetworkPage *>(_networkPage);
88 NetworkInfo networkInfo = networkPage->networkInfo();
89 QStringList channels = networkPage->channelList();
90 networkInfo.identity = id;
91 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(networkReady(NetworkId)));
92 Client::createNetwork(networkInfo, channels);
96 void IrcConnectionWizard::networkReady(NetworkId id)
98 disconnect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(networkReady(NetworkId)));
99 const Network *net = Client::network(id);
101 net->requestConnect();
106 // ==============================
108 // ==============================
111 IdentityPage::IdentityPage(QWidget *parent)
112 : QWizardPage(parent),
113 _identityEditWidget(new IdentityEditWidget(this)),
116 setTitle(tr("Setup Identity"));
118 if (Client::identityIds().isEmpty()) {
119 _identity = new CertIdentity(-1, this);
120 _identity->setToDefaults();
121 _identity->setIdentityName(tr("Default Identity"));
124 _identity = new CertIdentity(*Client::identity(Client::identityIds().first()), this);
127 _identityEditWidget->displayIdentity(_identity);
128 _identityEditWidget->showAdvanced(false);
129 QVBoxLayout *layout = new QVBoxLayout;
130 layout->addWidget(_identityEditWidget);
135 CertIdentity *IdentityPage::identity()
137 _identityEditWidget->saveToIdentity(_identity);
143 NetworkPage::NetworkPage(QWidget *parent)
144 : QWizardPage(parent),
145 _networkEditor(new SimpleNetworkEditor(this))
147 QStringList defaultNets = PresetNetworks::names(true);
148 if (!defaultNets.isEmpty()) {
149 NetworkInfo info = PresetNetworks::networkInfo(defaultNets[0]);
150 if (!info.networkName.isEmpty()) {
152 _channelList = PresetNetworks::defaultChannels(defaultNets[0]);
156 _networkEditor->displayNetworkInfo(_networkInfo);
157 _networkEditor->setDefaultChannels(_channelList);
159 setTitle(tr("Setup Network Connection"));
161 QVBoxLayout *layout = new QVBoxLayout;
162 layout->addWidget(_networkEditor);
167 NetworkInfo NetworkPage::networkInfo()
169 _networkEditor->saveToNetworkInfo(_networkInfo);
174 QStringList NetworkPage::channelList()
176 _channelList = _networkEditor->defaultChannels();