1 /***************************************************************************
2 * Copyright (C) 2005-2019 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"
23 #include <QVBoxLayout>
26 #include "identityeditwidget.h"
27 #include "presetnetworks.h"
28 #include "simplenetworkeditor.h"
30 IrcConnectionWizard::IrcConnectionWizard(QWidget* parent, Qt::WindowFlags flags)
31 : QWizard(parent, flags)
33 _introductionPage = createIntroductionPage(this);
34 _identityPage = new IdentityPage(this);
35 _networkPage = new NetworkPage(this);
37 addPage(_introductionPage);
38 addPage(_identityPage);
39 addPage(_networkPage);
41 setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
43 setOptions(options() | (QWizard::WizardOptions)(QWizard::NoDefaultButton | QWizard::CancelButtonOnLeft));
44 setOption(QWizard::NoCancelButton, false);
46 connect(button(QWizard::FinishButton), &QAbstractButton::clicked, this, &IrcConnectionWizard::finishClicked);
47 setButtonText(QWizard::FinishButton, tr("Save && Connect"));
50 QWizardPage* IrcConnectionWizard::createIntroductionPage(QWidget* parent)
52 auto* page = new QWizardPage(parent);
53 page->setTitle(QObject::tr("Welcome to Quassel IRC"));
55 QLabel* label = new QLabel(
57 "This wizard will help you to set up your default identity and your IRC network connection.<br>"
58 "This only covers basic settings. You can cancel this wizard any time and use the settings dialog for more detailed changes."),
60 label->setWordWrap(true);
62 auto* layout = new QVBoxLayout;
63 layout->addWidget(label);
64 page->setLayout(layout);
68 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());
76 connect(Client::instance(), &Client::identityCreated, this, &IrcConnectionWizard::identityReady);
77 Client::createIdentity(*identity);
81 void IrcConnectionWizard::identityReady(IdentityId id)
83 disconnect(Client::instance(), &Client::identityCreated, this, &IrcConnectionWizard::identityReady);
84 auto* networkPage = static_cast<NetworkPage*>(_networkPage);
85 NetworkInfo networkInfo = networkPage->networkInfo();
86 QStringList channels = networkPage->channelList();
87 networkInfo.identity = id;
88 connect(Client::instance(), &Client::networkCreated, this, &IrcConnectionWizard::networkReady);
89 Client::createNetwork(networkInfo, channels);
92 void IrcConnectionWizard::networkReady(NetworkId id)
94 disconnect(Client::instance(), &Client::networkCreated, this, &IrcConnectionWizard::networkReady);
95 const Network* net = Client::network(id);
97 net->requestConnect();
101 // ==============================
103 // ==============================
106 IdentityPage::IdentityPage(QWidget* parent)
107 : QWizardPage(parent)
108 , _identityEditWidget(new IdentityEditWidget(this))
110 setTitle(tr("Setup Identity"));
112 if (Client::identityIds().isEmpty()) {
113 _identity = new CertIdentity(-1, this);
114 _identity->setToDefaults();
115 _identity->setIdentityName(tr("Default Identity"));
118 _identity = new CertIdentity(*Client::identity(Client::identityIds().first()), this);
121 _identityEditWidget->displayIdentity(_identity);
122 _identityEditWidget->showAdvanced(false);
123 auto* layout = new QVBoxLayout;
124 layout->addWidget(_identityEditWidget);
128 CertIdentity* IdentityPage::identity()
130 _identityEditWidget->saveToIdentity(_identity);
135 NetworkPage::NetworkPage(QWidget* parent)
136 : QWizardPage(parent)
137 , _networkEditor(new SimpleNetworkEditor(this))
139 QStringList defaultNets = PresetNetworks::names(true);
140 if (!defaultNets.isEmpty()) {
141 NetworkInfo info = PresetNetworks::networkInfo(defaultNets[0]);
142 if (!info.networkName.isEmpty()) {
144 _channelList = PresetNetworks::defaultChannels(defaultNets[0]);
148 _networkEditor->displayNetworkInfo(_networkInfo);
149 _networkEditor->setDefaultChannels(_channelList);
151 setTitle(tr("Setup Network Connection"));
153 auto* layout = new QVBoxLayout;
154 layout->addWidget(_networkEditor);
158 NetworkInfo NetworkPage::networkInfo()
160 _networkEditor->saveToNetworkInfo(_networkInfo);
164 QStringList NetworkPage::channelList()
166 _channelList = _networkEditor->defaultChannels();