1 /***************************************************************************
2 * Copyright (C) 2005-2018 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)
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), SIGNAL(clicked()), this, SLOT(finishClicked()));
47 setButtonText(QWizard::FinishButton, tr("Save && Connect"));
51 QWizardPage *IrcConnectionWizard::createIntroductionPage(QWidget *parent)
53 auto *page = new QWizardPage(parent);
54 page->setTitle(QObject::tr("Welcome to Quassel IRC"));
56 QLabel *label = new QLabel(QObject::tr("This wizard will help you to set up your default identity and your IRC network connection.<br>"
57 "This only covers basic settings. You can cancel this wizard any time and use the settings dialog for more detailed changes."), page);
58 label->setWordWrap(true);
60 auto *layout = new QVBoxLayout;
61 layout->addWidget(label);
62 page->setLayout(layout);
67 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());
75 connect(Client::instance(), SIGNAL(identityCreated(IdentityId)), this, SLOT(identityReady(IdentityId)));
76 Client::createIdentity(*identity);
81 void IrcConnectionWizard::identityReady(IdentityId id)
83 disconnect(Client::instance(), SIGNAL(identityCreated(IdentityId)), this, SLOT(identityReady(IdentityId)));
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(), SIGNAL(networkCreated(NetworkId)), this, SLOT(networkReady(NetworkId)));
89 Client::createNetwork(networkInfo, channels);
93 void IrcConnectionWizard::networkReady(NetworkId id)
95 disconnect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(networkReady(NetworkId)));
96 const Network *net = Client::network(id);
98 net->requestConnect();
103 // ==============================
105 // ==============================
108 IdentityPage::IdentityPage(QWidget *parent)
109 : QWizardPage(parent),
110 _identityEditWidget(new IdentityEditWidget(this))
112 setTitle(tr("Setup Identity"));
114 if (Client::identityIds().isEmpty()) {
115 _identity = new CertIdentity(-1, this);
116 _identity->setToDefaults();
117 _identity->setIdentityName(tr("Default Identity"));
120 _identity = new CertIdentity(*Client::identity(Client::identityIds().first()), this);
123 _identityEditWidget->displayIdentity(_identity);
124 _identityEditWidget->showAdvanced(false);
125 auto *layout = new QVBoxLayout;
126 layout->addWidget(_identityEditWidget);
131 CertIdentity *IdentityPage::identity()
133 _identityEditWidget->saveToIdentity(_identity);
139 NetworkPage::NetworkPage(QWidget *parent)
140 : QWizardPage(parent),
141 _networkEditor(new SimpleNetworkEditor(this))
143 QStringList defaultNets = PresetNetworks::names(true);
144 if (!defaultNets.isEmpty()) {
145 NetworkInfo info = PresetNetworks::networkInfo(defaultNets[0]);
146 if (!info.networkName.isEmpty()) {
148 _channelList = PresetNetworks::defaultChannels(defaultNets[0]);
152 _networkEditor->displayNetworkInfo(_networkInfo);
153 _networkEditor->setDefaultChannels(_channelList);
155 setTitle(tr("Setup Network Connection"));
157 auto *layout = new QVBoxLayout;
158 layout->addWidget(_networkEditor);
163 NetworkInfo NetworkPage::networkInfo()
165 _networkEditor->saveToNetworkInfo(_networkInfo);
170 QStringList NetworkPage::channelList()
172 _channelList = _networkEditor->defaultChannels();