1 /***************************************************************************
2 * Copyright (C) 2005-2020 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 "networkssettingspage.h"
25 #include <QHeaderView>
26 #include <QMessageBox>
33 #include "presetnetworks.h"
34 #include "settingspagedlg.h"
36 #include "widgethelpers.h"
41 #include "settingspages/identitiessettingspage.h"
43 NetworksSettingsPage::NetworksSettingsPage(QWidget* parent)
44 : SettingsPage(tr("IRC"), tr("Networks"), parent)
48 // hide SASL options for older cores
49 if (!Client::isCoreFeatureEnabled(Quassel::Feature::SaslAuthentication))
51 if (!Client::isCoreFeatureEnabled(Quassel::Feature::SaslExternal))
52 ui.saslExtInfo->hide();
55 ui.renameNetwork->setIcon(icon::get("edit-rename"));
56 ui.addNetwork->setIcon(icon::get("list-add"));
57 ui.deleteNetwork->setIcon(icon::get("edit-delete"));
58 ui.addServer->setIcon(icon::get("list-add"));
59 ui.deleteServer->setIcon(icon::get("edit-delete"));
60 ui.editServer->setIcon(icon::get("configure"));
61 ui.upServer->setIcon(icon::get("go-up"));
62 ui.downServer->setIcon(icon::get("go-down"));
63 ui.editIdentities->setIcon(icon::get("configure"));
65 connectedIcon = icon::get("network-connect");
66 connectingIcon = icon::get("network-wired"); // FIXME network-connecting
67 disconnectedIcon = icon::get("network-disconnect");
70 infoIcon = icon::get({"emblem-information", "dialog-information"});
71 successIcon = icon::get({"emblem-success", "dialog-information"});
72 unavailableIcon = icon::get({"emblem-unavailable", "dialog-warning"});
73 questionIcon = icon::get({"emblem-question", "dialog-question", "dialog-information"});
75 foreach (int mib, QTextCodec::availableMibs()) {
76 QByteArray codec = QTextCodec::codecForMib(mib)->name();
77 ui.sendEncoding->addItem(codec);
78 ui.recvEncoding->addItem(codec);
79 ui.serverEncoding->addItem(codec);
81 ui.sendEncoding->model()->sort(0);
82 ui.recvEncoding->model()->sort(0);
83 ui.serverEncoding->model()->sort(0);
85 setEnabled(Client::isConnected()); // need a core connection!
88 connectToWidgetsChangedSignals({ui.identityList, ui.performEdit, ui.sasl,
89 ui.saslAccount, ui.saslPassword, ui.autoIdentify,
90 ui.autoIdentifyService, ui.autoIdentifyPassword, ui.useCustomEncodings,
91 ui.sendEncoding, ui.recvEncoding, ui.serverEncoding,
92 ui.autoReconnect, ui.reconnectInterval, ui.reconnectRetries,
93 ui.unlimitedRetries, ui.rejoinOnReconnect, ui.useCustomMessageRate,
94 ui.messageRateBurstSize, ui.messageRateDelay, ui.unlimitedMessageRate,
95 ui.enableCapServerTime},
97 &NetworksSettingsPage::widgetHasChanged);
99 connect(Client::instance(), &Client::coreConnectionStateChanged, this, &NetworksSettingsPage::coreConnectionStateChanged);
100 connect(Client::instance(), &Client::networkCreated, this, &NetworksSettingsPage::clientNetworkAdded);
101 connect(Client::instance(), &Client::networkRemoved, this, &NetworksSettingsPage::clientNetworkRemoved);
102 connect(Client::instance(), &Client::identityCreated, this, &NetworksSettingsPage::clientIdentityAdded);
103 connect(Client::instance(), &Client::identityRemoved, this, &NetworksSettingsPage::clientIdentityRemoved);
105 foreach (IdentityId id, Client::identityIds()) {
106 clientIdentityAdded(id);
110 void NetworksSettingsPage::save()
114 saveToNetworkInfo(networkInfos[currentId]);
116 QList<NetworkInfo> toCreate, toUpdate;
117 QList<NetworkId> toRemove;
118 QHash<NetworkId, NetworkInfo>::iterator i = networkInfos.begin();
119 while (i != networkInfos.end()) {
120 NetworkId id = (*i).networkId;
123 // if(id == currentId) currentId = 0;
124 // QList<QListWidgetItem *> items = ui.networkList->findItems((*i).networkName, Qt::MatchExactly);
125 // if(items.count()) {
126 // Q_ASSERT(items[0]->data(Qt::UserRole).value<NetworkId>() == id);
129 // i = networkInfos.erase(i);
133 if ((*i) != Client::network((*i).networkId)->networkInfo()) {
139 foreach (NetworkId id, Client::networkIds()) {
140 if (!networkInfos.contains(id))
143 SaveNetworksDlg dlg(toCreate, toUpdate, toRemove, this);
144 int ret = dlg.exec();
145 if (ret == QDialog::Rejected) {
146 // canceled -> reload everything to be safe
149 setChangedState(false);
153 void NetworksSettingsPage::load()
157 // Handle UI dependent on core feature flags here
158 if (Client::isCoreFeatureEnabled(Quassel::Feature::CustomRateLimits)) {
159 // Custom rate limiting supported, allow toggling
160 ui.useCustomMessageRate->setEnabled(true);
161 // Reset tooltip to default.
162 ui.useCustomMessageRate->setToolTip(QString("%1").arg(tr("<p>Override default message rate limiting.</p>"
163 "<p><b>Setting limits too low may get you disconnected"
164 " from the server!</b></p>")));
165 // If changed, update the message below!
168 // Custom rate limiting not supported, disallow toggling
169 ui.useCustomMessageRate->setEnabled(false);
170 // Split up the message to allow re-using translations:
171 // [Original tool-tip]
172 // [Bold 'does not support feature' message]
173 // [Specific version needed and feature details]
174 ui.useCustomMessageRate->setToolTip(QString("%1<br/><b>%2</b><br/>%3")
175 .arg(tr("<p>Override default message rate limiting.</p>"
176 "<p><b>Setting limits too low may get you disconnected"
177 " from the server!</b></p>"),
178 tr("Your Quassel core does not support this feature"),
179 tr("You need a Quassel core v0.13.0 or newer in order to "
180 "modify message rate limits.")));
183 if (!Client::isConnected() || Client::isCoreFeatureEnabled(Quassel::Feature::SkipIrcCaps)) {
184 // Either disconnected or IRCv3 capability skippping supported, enable configuration and
185 // hide warning. Don't show the warning needlessly when disconnected.
186 ui.enableCapsConfigWidget->setEnabled(true);
187 ui.enableCapsStatusLabel->setText(tr("These features require support from the network"));
188 ui.enableCapsStatusIcon->setPixmap(infoIcon.pixmap(16));
191 // Core does not IRCv3 capability skipping, show warning and disable configuration
192 ui.enableCapsConfigWidget->setEnabled(false);
193 ui.enableCapsStatusLabel->setText(tr("Your Quassel core is too old to configure IRCv3 features"));
194 ui.enableCapsStatusIcon->setPixmap(unavailableIcon.pixmap(16));
197 // Hide the SASL EXTERNAL notice until a network's shown. Stops it from showing while loading
198 // backlog from the core.
201 // Reset network capability status in case no valid networks get selected (a rare situation)
202 resetNetworkCapStates();
204 foreach (NetworkId netid, Client::networkIds()) {
205 clientNetworkAdded(netid);
207 ui.networkList->setCurrentRow(0);
209 setChangedState(false);
212 void NetworksSettingsPage::reset()
215 ui.networkList->clear();
216 networkInfos.clear();
219 bool NetworksSettingsPage::aboutToSave()
222 saveToNetworkInfo(networkInfos[currentId]);
224 foreach (NetworkInfo info, networkInfos.values()) {
225 if (!info.serverList.count())
230 QString error(tr("<b>The following problems need to be corrected before your changes can be applied:</b><ul>"));
231 if (errors.contains(1))
232 error += tr("<li>All networks need at least one server defined</li>");
233 error += tr("</ul>");
234 QMessageBox::warning(this, tr("Invalid Network Settings"), error);
238 void NetworksSettingsPage::widgetHasChanged()
240 if (_ignoreWidgetChanges)
242 bool changed = testHasChanged();
243 if (changed != hasChanged())
244 setChangedState(changed);
247 bool NetworksSettingsPage::testHasChanged()
249 if (currentId != 0) {
250 saveToNetworkInfo(networkInfos[currentId]);
252 if (Client::networkIds().count() != networkInfos.count())
254 foreach (NetworkId id, networkInfos.keys()) {
257 if (Client::network(id)->networkInfo() != networkInfos[id])
263 void NetworksSettingsPage::setWidgetStates()
266 if (ui.networkList->selectedItems().count()) {
267 ui.detailsBox->setEnabled(true);
268 ui.renameNetwork->setEnabled(true);
269 ui.deleteNetwork->setEnabled(true);
271 /* button disabled for now
272 NetworkId id = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
273 const Network *net = id > 0 ? Client::network(id) : 0;
274 ui.connectNow->setEnabled(net);
275 // && (Client::network(id)->connectionState() == Network::Initialized
276 // || Client::network(id)->connectionState() == Network::Disconnected));
278 if(net->connectionState() == Network::Disconnected) {
279 ui.connectNow->setIcon(connectedIcon);
280 ui.connectNow->setText(tr("Connect"));
282 ui.connectNow->setIcon(disconnectedIcon);
283 ui.connectNow->setText(tr("Disconnect"));
286 ui.connectNow->setIcon(QIcon());
287 ui.connectNow->setText(tr("Apply first!"));
291 ui.renameNetwork->setEnabled(false);
292 ui.deleteNetwork->setEnabled(false);
293 // ui.connectNow->setEnabled(false);
294 ui.detailsBox->setEnabled(false);
297 if (ui.serverList->selectedItems().count()) {
298 ui.editServer->setEnabled(true);
299 ui.deleteServer->setEnabled(true);
300 ui.upServer->setEnabled(ui.serverList->currentRow() > 0);
301 ui.downServer->setEnabled(ui.serverList->currentRow() < ui.serverList->count() - 1);
304 ui.editServer->setEnabled(false);
305 ui.deleteServer->setEnabled(false);
306 ui.upServer->setEnabled(false);
307 ui.downServer->setEnabled(false);
311 void NetworksSettingsPage::setItemState(NetworkId id, QListWidgetItem* item)
313 if (!item && !(item = networkItem(id)))
315 const Network* net = Client::network(id);
316 if (!net || net->isInitialized())
317 item->setFlags(item->flags() | Qt::ItemIsEnabled);
319 item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
320 if (net && net->connectionState() == Network::Initialized) {
321 item->setIcon(connectedIcon);
323 else if (net && net->connectionState() != Network::Disconnected) {
324 item->setIcon(connectingIcon);
327 item->setIcon(disconnectedIcon);
331 // check if we already have another net of this name in the list, and replace it
332 QList<QListWidgetItem*> items = ui.networkList->findItems(net->networkName(), Qt::MatchExactly);
334 foreach (QListWidgetItem* i, items) {
335 NetworkId oldid = i->data(Qt::UserRole).value<NetworkId>();
337 continue; // only locally created nets should be replaced
338 if (oldid == currentId) {
341 ui.networkList->clearSelection();
343 int row = ui.networkList->row(i);
345 QListWidgetItem* olditem = ui.networkList->takeItem(row);
349 networkInfos.remove(oldid);
353 item->setText(net->networkName());
355 item->setSelected(true);
359 void NetworksSettingsPage::resetNetworkCapStates()
361 // Set the status to a blank (invalid) network ID, reseting all UI
362 setNetworkCapStates(NetworkId());
365 void NetworksSettingsPage::setNetworkCapStates(NetworkId id)
367 const Network* net = Client::network(id);
368 if (net && Client::isCoreFeatureEnabled(Quassel::Feature::CapNegotiation)) {
369 // Capability negotiation is supported, network exists.
370 // Check if the network is connected. Don't use net->isConnected() as that won't be true
371 // during capability negotiation when capabilities are added and removed.
372 if (net->connectionState() != Network::Disconnected) {
373 // Network exists and is connected, check available capabilities...
375 // Quassel switches between SASL PLAIN and SASL EXTERNAL based on the existence of an
376 // SSL certificate on the identity - check EXTERNAL if CertID exists, PLAIN if not
377 bool usingSASLExternal = displayedNetworkHasCertId();
378 if ((usingSASLExternal && net->saslMaybeSupports(IrcCap::SaslMech::EXTERNAL))
379 || (!usingSASLExternal && net->saslMaybeSupports(IrcCap::SaslMech::PLAIN))) {
380 setCapSASLStatus(CapSupportStatus::MaybeSupported, usingSASLExternal);
383 setCapSASLStatus(CapSupportStatus::MaybeUnsupported, usingSASLExternal);
386 // Add additional capability-dependent interface updates here
389 // Network is disconnected
391 setCapSASLStatus(CapSupportStatus::Disconnected);
393 // Add additional capability-dependent interface updates here
397 // Capability negotiation is not supported and/or network doesn't exist.
398 // Don't assume anything and reset all capability-dependent interface elements to neutral.
400 setCapSASLStatus(CapSupportStatus::Unknown);
402 // Add additional capability-dependent interface updates here
406 void NetworksSettingsPage::coreConnectionStateChanged(bool state)
408 this->setEnabled(state);
418 void NetworksSettingsPage::clientIdentityAdded(IdentityId id)
420 const Identity* identity = Client::identity(id);
421 connect(identity, &SyncableObject::updatedRemotely, this, &NetworksSettingsPage::clientIdentityUpdated);
423 QString name = identity->identityName();
424 for (int j = 0; j < ui.identityList->count(); j++) {
425 if ((j > 0 || ui.identityList->itemData(0).toInt() != 1) && name.localeAwareCompare(ui.identityList->itemText(j)) < 0) {
426 ui.identityList->insertItem(j, name, id.toInt());
432 ui.identityList->insertItem(ui.identityList->count(), name, id.toInt());
436 void NetworksSettingsPage::clientIdentityUpdated()
438 const auto* identity = qobject_cast<const Identity*>(sender());
440 qWarning() << "NetworksSettingsPage: Invalid identity to update!";
443 int row = ui.identityList->findData(identity->id().toInt());
445 qWarning() << "NetworksSettingsPage: Invalid identity to update!";
448 if (ui.identityList->itemText(row) != identity->identityName()) {
449 ui.identityList->setItemText(row, identity->identityName());
453 void NetworksSettingsPage::clientIdentityRemoved(IdentityId id)
455 IdentityId defaultId = defaultIdentity();
457 saveToNetworkInfo(networkInfos[currentId]);
458 foreach (NetworkInfo info, networkInfos.values()) {
459 if (info.identity == id) {
460 if (info.networkId == currentId)
461 ui.identityList->setCurrentIndex(0);
462 info.identity = defaultId;
463 networkInfos[info.networkId] = info;
464 if (info.networkId > 0)
465 Client::updateNetwork(info);
468 ui.identityList->removeItem(ui.identityList->findData(id.toInt()));
472 QListWidgetItem* NetworksSettingsPage::networkItem(NetworkId id) const
474 for (int i = 0; i < ui.networkList->count(); i++) {
475 QListWidgetItem* item = ui.networkList->item(i);
476 if (item->data(Qt::UserRole).value<NetworkId>() == id)
482 void NetworksSettingsPage::clientNetworkAdded(NetworkId id)
485 // connect(Client::network(id), &Network::updatedRemotely, this, &NetworksSettingsPage::clientNetworkUpdated);
486 connect(Client::network(id), &Network::configChanged, this, &NetworksSettingsPage::clientNetworkUpdated);
488 connect(Client::network(id), &Network::connectionStateSet, this, &NetworksSettingsPage::networkConnectionStateChanged);
489 connect(Client::network(id), &Network::connectionError, this, &NetworksSettingsPage::networkConnectionError);
491 // Handle capability changes in case a server dis/connects with the settings window open.
492 connect(Client::network(id), &Network::capAdded, this, &NetworksSettingsPage::clientNetworkCapsUpdated);
493 connect(Client::network(id), &Network::capRemoved, this, &NetworksSettingsPage::clientNetworkCapsUpdated);
496 void NetworksSettingsPage::clientNetworkUpdated()
498 const auto* net = qobject_cast<const Network*>(sender());
500 qWarning() << "Update request for unknown network received!";
503 networkInfos[net->networkId()] = net->networkInfo();
504 setItemState(net->networkId());
505 if (net->networkId() == currentId)
506 displayNetwork(net->networkId());
511 void NetworksSettingsPage::clientNetworkRemoved(NetworkId id)
513 if (!networkInfos.contains(id))
517 NetworkInfo info = networkInfos.take(id);
518 QList<QListWidgetItem*> items = ui.networkList->findItems(info.networkName, Qt::MatchExactly);
519 foreach (QListWidgetItem* item, items) {
520 if (item->data(Qt::UserRole).value<NetworkId>() == id)
521 delete ui.networkList->takeItem(ui.networkList->row(item));
527 void NetworksSettingsPage::networkConnectionStateChanged(Network::ConnectionState state)
530 const auto* net = qobject_cast<const Network*>(sender());
534 if(net->networkId() == currentId) {
535 ui.connectNow->setEnabled(state == Network::Initialized || state == Network::Disconnected);
538 setItemState(net->networkId());
539 if (net->networkId() == currentId) {
540 // Network is currently shown. Update the capability-dependent UI in case capabilities have
542 setNetworkCapStates(currentId);
547 void NetworksSettingsPage::networkConnectionError(const QString&) {}
549 QListWidgetItem* NetworksSettingsPage::insertNetwork(NetworkId id)
551 NetworkInfo info = Client::network(id)->networkInfo();
552 networkInfos[id] = info;
553 return insertNetwork(info);
556 QListWidgetItem* NetworksSettingsPage::insertNetwork(const NetworkInfo& info)
558 QListWidgetItem* item = nullptr;
559 QList<QListWidgetItem*> items = ui.networkList->findItems(info.networkName, Qt::MatchExactly);
561 item = new QListWidgetItem(disconnectedIcon, info.networkName, ui.networkList);
563 // we overwrite an existing net if it a) has the same name and b) has a negative ID meaning we created it locally before
564 // -> then we can be sure that this is the core-side replacement for the net we created
565 foreach (QListWidgetItem* i, items) {
566 NetworkId id = i->data(Qt::UserRole).value<NetworkId>();
573 item = new QListWidgetItem(disconnectedIcon, info.networkName, ui.networkList);
575 item->setData(Qt::UserRole, QVariant::fromValue(info.networkId));
576 setItemState(info.networkId, item);
581 // Called when selecting 'Configure' from the buffer list
582 void NetworksSettingsPage::bufferList_Open(NetworkId netId)
584 QListWidgetItem* item = networkItem(netId);
585 ui.networkList->setCurrentItem(item, QItemSelectionModel::SelectCurrent);
588 void NetworksSettingsPage::displayNetwork(NetworkId id)
590 _ignoreWidgetChanges = true;
592 NetworkInfo info = networkInfos[id];
594 // this is only needed when the core supports SASL EXTERNAL
595 if (Client::isCoreFeatureEnabled(Quassel::Feature::SaslExternal)) {
597 // Clean up existing CertIdentity
598 disconnect(_cid, &CertIdentity::sslSettingsUpdated, this, &NetworksSettingsPage::sslUpdated);
602 auto *identity = Client::identity(info.identity);
604 // Connect new CertIdentity
605 _cid = new CertIdentity(*identity, this);
606 _cid->enableEditSsl(true);
607 connect(_cid, &CertIdentity::sslSettingsUpdated, this, &NetworksSettingsPage::sslUpdated);
610 qWarning() << "NetworksSettingsPage::displayNetwork can't find Identity for IdentityId:" << info.identity;
614 ui.identityList->setCurrentIndex(ui.identityList->findData(info.identity.toInt()));
615 ui.serverList->clear();
616 foreach (Network::Server server, info.serverList) {
617 QListWidgetItem* item = new QListWidgetItem(QString("%1:%2").arg(server.host).arg(server.port));
619 item->setIcon(icon::get("document-encrypt"));
620 ui.serverList->addItem(item);
623 // ui.randomServer->setChecked(info.useRandomServer);
624 // Update the capability-dependent UI in case capabilities have changed.
625 setNetworkCapStates(id);
626 ui.performEdit->setPlainText(info.perform.join("\n"));
627 ui.autoIdentify->setChecked(info.useAutoIdentify);
628 ui.autoIdentifyService->setText(info.autoIdentifyService);
629 ui.autoIdentifyPassword->setText(info.autoIdentifyPassword);
630 ui.sasl->setChecked(info.useSasl);
631 ui.saslAccount->setText(info.saslAccount);
632 ui.saslPassword->setText(info.saslPassword);
633 if (info.codecForEncoding.isEmpty()) {
634 ui.sendEncoding->setCurrentIndex(ui.sendEncoding->findText(Network::defaultCodecForEncoding()));
635 ui.recvEncoding->setCurrentIndex(ui.recvEncoding->findText(Network::defaultCodecForDecoding()));
636 ui.serverEncoding->setCurrentIndex(ui.serverEncoding->findText(Network::defaultCodecForServer()));
637 ui.useCustomEncodings->setChecked(false);
640 ui.sendEncoding->setCurrentIndex(ui.sendEncoding->findText(info.codecForEncoding));
641 ui.recvEncoding->setCurrentIndex(ui.recvEncoding->findText(info.codecForDecoding));
642 ui.serverEncoding->setCurrentIndex(ui.serverEncoding->findText(info.codecForServer));
643 ui.useCustomEncodings->setChecked(true);
645 ui.autoReconnect->setChecked(info.useAutoReconnect);
646 ui.reconnectInterval->setValue(info.autoReconnectInterval);
647 ui.reconnectRetries->setValue(info.autoReconnectRetries);
648 ui.unlimitedRetries->setChecked(info.unlimitedReconnectRetries);
649 ui.rejoinOnReconnect->setChecked(info.rejoinChannels);
650 // Custom rate limiting
651 ui.unlimitedMessageRate->setChecked(info.unlimitedMessageRate);
652 // Set 'ui.useCustomMessageRate' after 'ui.unlimitedMessageRate' so if the latter is
653 // disabled, 'ui.messageRateDelayFrame' will remain disabled.
654 ui.useCustomMessageRate->setChecked(info.useCustomMessageRate);
655 ui.messageRateBurstSize->setValue(info.messageRateBurstSize);
656 // Convert milliseconds (integer) into seconds (double)
657 ui.messageRateDelay->setValue(info.messageRateDelay / 1000.0f);
658 // Skipped IRCv3 capabilities
659 ui.enableCapServerTime->setChecked(!info.skipCaps.contains(IrcCap::SERVER_TIME));
662 // just clear widgets
664 disconnect(_cid, &CertIdentity::sslSettingsUpdated, this, &NetworksSettingsPage::sslUpdated);
667 ui.identityList->setCurrentIndex(-1);
668 ui.serverList->clear();
669 ui.performEdit->clear();
670 ui.autoIdentifyService->clear();
671 ui.autoIdentifyPassword->clear();
672 ui.saslAccount->clear();
673 ui.saslPassword->clear();
676 _ignoreWidgetChanges = false;
680 void NetworksSettingsPage::saveToNetworkInfo(NetworkInfo& info)
682 info.identity = ui.identityList->itemData(ui.identityList->currentIndex()).toInt();
683 // info.useRandomServer = ui.randomServer->isChecked();
684 info.perform = ui.performEdit->toPlainText().split("\n");
685 info.useAutoIdentify = ui.autoIdentify->isChecked();
686 info.autoIdentifyService = ui.autoIdentifyService->text();
687 info.autoIdentifyPassword = ui.autoIdentifyPassword->text();
688 info.useSasl = ui.sasl->isChecked();
689 info.saslAccount = ui.saslAccount->text();
690 info.saslPassword = ui.saslPassword->text();
691 if (!ui.useCustomEncodings->isChecked()) {
692 info.codecForEncoding.clear();
693 info.codecForDecoding.clear();
694 info.codecForServer.clear();
697 info.codecForEncoding = ui.sendEncoding->currentText().toLatin1();
698 info.codecForDecoding = ui.recvEncoding->currentText().toLatin1();
699 info.codecForServer = ui.serverEncoding->currentText().toLatin1();
701 info.useAutoReconnect = ui.autoReconnect->isChecked();
702 info.autoReconnectInterval = ui.reconnectInterval->value();
703 info.autoReconnectRetries = ui.reconnectRetries->value();
704 info.unlimitedReconnectRetries = ui.unlimitedRetries->isChecked();
705 info.rejoinChannels = ui.rejoinOnReconnect->isChecked();
706 // Custom rate limiting
707 info.useCustomMessageRate = ui.useCustomMessageRate->isChecked();
708 info.messageRateBurstSize = ui.messageRateBurstSize->value();
709 // Convert seconds (double) into milliseconds (integer)
710 info.messageRateDelay = static_cast<quint32>((ui.messageRateDelay->value() * 1000));
711 info.unlimitedMessageRate = ui.unlimitedMessageRate->isChecked();
712 // Skipped IRCv3 capabilities
713 if (ui.enableCapServerTime->isChecked()) {
714 // Capability enabled, remove it from the skip list
715 info.skipCaps.removeAll(IrcCap::SERVER_TIME);
716 } else if (!info.skipCaps.contains(IrcCap::SERVER_TIME)) {
717 // Capability disabled and not in the skip list, add it
718 info.skipCaps.append(IrcCap::SERVER_TIME);
722 void NetworksSettingsPage::clientNetworkCapsUpdated()
724 // Grab the updated network
725 const auto* net = qobject_cast<const Network*>(sender());
727 qWarning() << "Update request for unknown network received!";
730 if (net->networkId() == currentId) {
731 // Network is currently shown. Update the capability-dependent UI in case capabilities have
733 setNetworkCapStates(currentId);
737 void NetworksSettingsPage::setCapSASLStatus(const CapSupportStatus saslStatus, bool usingSASLExternal)
739 if (_capSaslStatusSelected != saslStatus || _capSaslStatusUsingExternal != usingSASLExternal) {
740 // Update the cached copy of SASL status used with the Details dialog
741 _capSaslStatusSelected = saslStatus;
742 _capSaslStatusUsingExternal = usingSASLExternal;
744 // Update the user interface
745 switch (saslStatus) {
746 case CapSupportStatus::Unknown:
747 // There's no capability negotiation or network doesn't exist. Don't assume
749 ui.saslStatusLabel->setText(QString("<i>%1</i>").arg(tr("Could not check if supported by network")));
750 ui.saslStatusIcon->setPixmap(questionIcon.pixmap(16));
752 case CapSupportStatus::Disconnected:
753 // Disconnected from network, no way to check.
754 ui.saslStatusLabel->setText(QString("<i>%1</i>").arg(tr("Cannot check if supported when disconnected")));
755 ui.saslStatusIcon->setPixmap(questionIcon.pixmap(16));
757 case CapSupportStatus::MaybeUnsupported:
758 // The network doesn't advertise support for SASL PLAIN/EXTERNAL. Here be dragons.
759 ui.saslStatusLabel->setText(QString("<i>%1</i>").arg(tr("Not currently supported by network")));
760 ui.saslStatusIcon->setPixmap(unavailableIcon.pixmap(16));
762 case CapSupportStatus::MaybeSupported:
763 // The network advertises support for SASL PLAIN/EXTERNAL. Encourage using it!
764 // Unfortunately we don't know for sure if it's desired or functional.
765 if (usingSASLExternal) {
766 // SASL EXTERNAL is used
767 // With SASL v3.1, it's not possible to reliably tell if SASL EXTERNAL is supported,
768 // or just SASL PLAIN. Use less assertive phrasing.
769 ui.saslStatusLabel->setText(QString("<i>%1</i>").arg(tr("May be supported by network")));
772 // SASL PLAIN is used
773 ui.saslStatusLabel->setText(QString("<i>%1</i>").arg(tr("Supported by network")));
775 ui.saslStatusIcon->setPixmap(successIcon.pixmap(16));
781 void NetworksSettingsPage::sslUpdated()
783 if (displayedNetworkHasCertId()) {
784 ui.saslPlainContents->setDisabled(true);
785 ui.saslExtInfo->setHidden(false);
788 ui.saslPlainContents->setDisabled(false);
789 // Directly re-enabling causes the widgets to ignore the parent "Use SASL Authentication"
790 // state to indicate whether or not it's disabled. To workaround this, keep track of
791 // whether or not "Use SASL Authentication" is enabled, then quickly uncheck/recheck the
793 if (!ui.sasl->isChecked()) {
794 // SASL is not enabled, uncheck/recheck the group box to re-disable saslPlainContents.
795 // Leaving saslPlainContents disabled doesn't work as that prevents it from re-enabling if
796 // sasl is later checked.
797 ui.sasl->setChecked(true);
798 ui.sasl->setChecked(false);
800 ui.saslExtInfo->setHidden(true);
802 // Update whether SASL PLAIN or SASL EXTERNAL is used to detect SASL status
803 if (currentId != 0) {
804 setNetworkCapStates(currentId);
808 /*** Network list ***/
810 void NetworksSettingsPage::on_networkList_itemSelectionChanged()
812 if (currentId != 0) {
813 saveToNetworkInfo(networkInfos[currentId]);
815 if (ui.networkList->selectedItems().count()) {
816 NetworkId id = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
819 ui.serverList->setCurrentRow(0);
827 void NetworksSettingsPage::on_addNetwork_clicked()
829 QStringList existing;
830 for (int i = 0; i < ui.networkList->count(); i++)
831 existing << ui.networkList->item(i)->text();
832 NetworkAddDlg dlg(existing, this);
833 if (dlg.exec() == QDialog::Accepted) {
834 NetworkInfo info = dlg.networkInfo();
835 if (info.networkName.isEmpty())
836 return; // sanity check
839 for (id = 1; id <= networkInfos.count(); id++) {
841 if (!networkInfos.keys().contains(-id.toInt()))
846 info.identity = defaultIdentity();
847 networkInfos[id] = info;
848 QListWidgetItem* item = insertNetwork(info);
849 ui.networkList->setCurrentItem(item);
854 void NetworksSettingsPage::on_deleteNetwork_clicked()
856 if (ui.networkList->selectedItems().count()) {
857 NetworkId netid = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
859 = QMessageBox::question(this,
860 tr("Delete Network?"),
861 tr("Do you really want to delete the network \"%1\" and all related settings, including the backlog?")
862 .arg(networkInfos[netid].networkName),
863 QMessageBox::Yes | QMessageBox::No,
865 if (ret == QMessageBox::Yes) {
867 networkInfos.remove(netid);
868 delete ui.networkList->takeItem(ui.networkList->row(ui.networkList->selectedItems()[0]));
869 ui.networkList->setCurrentRow(qMin(ui.networkList->currentRow() + 1, ui.networkList->count() - 1));
876 void NetworksSettingsPage::on_renameNetwork_clicked()
878 if (!ui.networkList->selectedItems().count())
880 QString old = ui.networkList->selectedItems()[0]->text();
881 QStringList existing;
882 for (int i = 0; i < ui.networkList->count(); i++)
883 existing << ui.networkList->item(i)->text();
884 NetworkEditDlg dlg(old, existing, this);
885 if (dlg.exec() == QDialog::Accepted) {
886 ui.networkList->selectedItems()[0]->setText(dlg.networkName());
887 NetworkId netid = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
888 networkInfos[netid].networkName = dlg.networkName();
894 void NetworksSettingsPage::on_connectNow_clicked() {
895 if(!ui.networkList->selectedItems().count()) return;
896 NetworkId id = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
897 const Network *net = Client::network(id);
899 if(net->connectionState() == Network::Disconnected) net->requestConnect();
900 else net->requestDisconnect();
904 /*** Server list ***/
906 void NetworksSettingsPage::on_serverList_itemSelectionChanged()
911 void NetworksSettingsPage::on_addServer_clicked()
915 ServerEditDlg dlg(Network::Server(), this);
916 if (dlg.exec() == QDialog::Accepted) {
917 networkInfos[currentId].serverList.append(dlg.serverData());
918 displayNetwork(currentId);
919 ui.serverList->setCurrentRow(ui.serverList->count() - 1);
924 void NetworksSettingsPage::on_editServer_clicked()
928 int cur = ui.serverList->currentRow();
929 ServerEditDlg dlg(networkInfos[currentId].serverList[cur], this);
930 if (dlg.exec() == QDialog::Accepted) {
931 networkInfos[currentId].serverList[cur] = dlg.serverData();
932 displayNetwork(currentId);
933 ui.serverList->setCurrentRow(cur);
938 void NetworksSettingsPage::on_deleteServer_clicked()
942 int cur = ui.serverList->currentRow();
943 networkInfos[currentId].serverList.removeAt(cur);
944 displayNetwork(currentId);
945 ui.serverList->setCurrentRow(qMin(cur, ui.serverList->count() - 1));
949 void NetworksSettingsPage::on_upServer_clicked()
951 int cur = ui.serverList->currentRow();
952 Network::Server server = networkInfos[currentId].serverList.takeAt(cur);
953 networkInfos[currentId].serverList.insert(cur - 1, server);
954 displayNetwork(currentId);
955 ui.serverList->setCurrentRow(cur - 1);
959 void NetworksSettingsPage::on_downServer_clicked()
961 int cur = ui.serverList->currentRow();
962 Network::Server server = networkInfos[currentId].serverList.takeAt(cur);
963 networkInfos[currentId].serverList.insert(cur + 1, server);
964 displayNetwork(currentId);
965 ui.serverList->setCurrentRow(cur + 1);
969 void NetworksSettingsPage::on_editIdentities_clicked()
971 SettingsPageDlg dlg(new IdentitiesSettingsPage(this), this);
975 void NetworksSettingsPage::on_saslStatusDetails_clicked()
977 if (ui.networkList->selectedItems().count()) {
978 NetworkId netid = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
979 QString& netName = networkInfos[netid].networkName;
981 // If these strings are visible, one of the status messages wasn't detected below.
982 QString saslStatusHeader = "[header unintentionally left blank]";
983 QString saslStatusExplanation = "[explanation unintentionally left blank]";
985 // If true, show a warning icon instead of an information icon
986 bool useWarningIcon = false;
988 // Determine which explanation to show
989 switch (_capSaslStatusSelected) {
990 case CapSupportStatus::Unknown:
991 saslStatusHeader = tr("Could not check if SASL supported by network");
992 saslStatusExplanation = tr("Quassel could not check if \"%1\" supports SASL. This may "
993 "be due to unsaved changes or an older Quassel core. You "
994 "can still try using SASL.")
997 case CapSupportStatus::Disconnected:
998 saslStatusHeader = tr("Cannot check if SASL supported when disconnected");
999 saslStatusExplanation = tr("Quassel cannot check if \"%1\" supports SASL when "
1000 "disconnected. Connect to the network, or try using SASL "
1004 case CapSupportStatus::MaybeUnsupported:
1005 if (displayedNetworkHasCertId()) {
1006 // SASL EXTERNAL is used
1007 saslStatusHeader = tr("SASL EXTERNAL not currently supported by network");
1008 saslStatusExplanation = tr("The network \"%1\" does not currently support SASL "
1009 "EXTERNAL for SSL certificate authentication. However, "
1010 "support might be added later on.")
1014 // SASL PLAIN is used
1015 saslStatusHeader = tr("SASL not currently supported by network");
1016 saslStatusExplanation = tr("The network \"%1\" does not currently support SASL. "
1017 "However, support might be added later on.")
1020 useWarningIcon = true;
1022 case CapSupportStatus::MaybeSupported:
1023 if (displayedNetworkHasCertId()) {
1024 // SASL EXTERNAL is used
1025 // With SASL v3.1, it's not possible to reliably tell if SASL EXTERNAL is supported,
1026 // or just SASL PLAIN. Caution about this in the details dialog.
1027 saslStatusHeader = tr("SASL EXTERNAL may be supported by network");
1028 saslStatusExplanation = tr("The network \"%1\" may support SASL EXTERNAL for SSL "
1029 "certificate authentication. In most cases, you should "
1030 "use SASL instead of NickServ identification.")
1034 // SASL PLAIN is used
1035 saslStatusHeader = tr("SASL supported by network");
1036 saslStatusExplanation = tr("The network \"%1\" supports SASL. In most cases, you "
1037 "should use SASL instead of NickServ identification.")
1043 // Process this in advance for reusability below
1044 const QString saslStatusMsgTitle = tr("SASL support for \"%1\"").arg(netName);
1045 const QString saslStatusMsgText = QString("<p><b>%1</b></p></br><p>%2</p></br><p><i>%3</i></p>")
1046 .arg(saslStatusHeader,
1047 saslStatusExplanation,
1048 tr("SASL is a standardized way to log in and identify yourself to "
1051 if (useWarningIcon) {
1052 // Show as a warning dialog box
1053 QMessageBox::warning(this, saslStatusMsgTitle, saslStatusMsgText);
1056 // Show as an information dialog box
1057 QMessageBox::information(this, saslStatusMsgTitle, saslStatusMsgText);
1062 void NetworksSettingsPage::on_enableCapsStatusDetails_clicked()
1064 if (!Client::isConnected() || Client::isCoreFeatureEnabled(Quassel::Feature::SkipIrcCaps)) {
1065 // Either disconnected or IRCv3 capability skippping supported
1067 // Try to get a list of currently enabled features
1068 QStringList sortedCapsEnabled;
1069 // Check if a network is selected
1070 if (ui.networkList->selectedItems().count()) {
1071 // Get the underlying Network from the selected network
1072 NetworkId netid = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
1073 const Network* net = Client::network(netid);
1074 if (net && Client::isCoreFeatureEnabled(Quassel::Feature::CapNegotiation)) {
1075 // Capability negotiation is supported, network exists.
1076 // If the network is disconnected, the list of enabled capabilities will be empty,
1077 // no need to check for that specifically.
1078 // Sorting isn't required, but it looks nicer.
1079 sortedCapsEnabled = net->capsEnabled();
1080 sortedCapsEnabled.sort();
1084 // Try to explain IRCv3 network features in a friendly way, including showing the currently
1085 // enabled features if available
1086 auto messageText = QString("<p>%1</p></br><p>%2</p>")
1087 .arg(tr("Quassel makes use of newer IRC features when supported by the IRC network."
1088 " If desired, you can disable unwanted or problematic features here."),
1089 tr("The <a href=\"https://ircv3.net/irc/\">IRCv3 website</a> provides more "
1090 "technical details on the IRCv3 capabilities powering these features."));
1092 if (!sortedCapsEnabled.isEmpty()) {
1093 // Format the capabilities within <code></code> blocks
1094 auto formattedCaps = QString("<code>%1</code>")
1095 .arg(sortedCapsEnabled.join("</code>, <code>"));
1097 // Add the currently enabled capabilities to the list
1098 // This creates a new QString, but this code is not performance-critical.
1099 messageText = messageText.append(QString("<p><i>%1</i></p>").arg(
1100 tr("Currently enabled IRCv3 capabilities for this "
1101 "network: %1").arg(formattedCaps)));
1104 QMessageBox::information(this, tr("Configuring network features"), messageText);
1107 // Core does not IRCv3 capability skipping, show warning
1108 QMessageBox::warning(this, tr("Configuring network features unsupported"),
1109 QString("<p><b>%1</b></p></br><p>%2</p>")
1110 .arg(tr("Your Quassel core is too old to configure IRCv3 network features"),
1111 tr("You need a Quassel core v0.14.0 or newer to control what network "
1112 "features Quassel will use.")));
1116 void NetworksSettingsPage::on_enableCapsAdvanced_clicked()
1121 CapsEditDlg dlg(networkInfos[currentId].skipCapsToString(), this);
1122 if (dlg.exec() == QDialog::Accepted) {
1123 networkInfos[currentId].skipCapsFromString(dlg.skipCapsString());
1124 displayNetwork(currentId);
1129 IdentityId NetworksSettingsPage::defaultIdentity() const
1131 IdentityId defaultId = 0;
1132 QList<IdentityId> ids = Client::identityIds();
1133 foreach (IdentityId id, ids) {
1134 if (defaultId == 0 || id < defaultId)
1140 bool NetworksSettingsPage::displayedNetworkHasCertId() const
1142 // Check if the CertIdentity exists and that it has a non-null SSL key set
1143 return (_cid && !_cid->sslKey().isNull());
1146 /**************************************************************************
1148 *************************************************************************/
1150 NetworkAddDlg::NetworkAddDlg(QStringList exist, QWidget* parent)
1152 , existing(std::move(exist))
1155 ui.useSSL->setIcon(icon::get("document-encrypt"));
1157 // Whenever useSSL is toggled, update the port number if not changed from the default
1158 connect(ui.useSSL, &QAbstractButton::toggled, this, &NetworkAddDlg::updateSslPort);
1159 // Do NOT call updateSslPort when loading settings, otherwise port settings may be overriden.
1160 // If useSSL is later changed to be checked by default, change port's default value, too.
1162 if (Client::isCoreFeatureEnabled(Quassel::Feature::VerifyServerSSL)) {
1163 // Synchronize requiring SSL with the use SSL checkbox
1164 ui.sslVerify->setEnabled(ui.useSSL->isChecked());
1165 connect(ui.useSSL, &QAbstractButton::toggled, ui.sslVerify, &QWidget::setEnabled);
1168 // Core isn't new enough to allow requiring SSL; disable checkbox and uncheck
1169 ui.sslVerify->setEnabled(false);
1170 ui.sslVerify->setChecked(false);
1171 // Split up the message to allow re-using translations:
1172 // [Original tool-tip]
1173 // [Bold 'does not support feature' message]
1174 // [Specific version needed and feature details]
1175 ui.sslVerify->setToolTip(QString("%1<br/><b>%2</b><br/>%3")
1176 .arg(ui.sslVerify->toolTip(),
1177 tr("Your Quassel core does not support this feature"),
1178 tr("You need a Quassel core v0.13.0 or newer in order to "
1179 "verify connection security.")));
1182 // read preset networks
1183 QStringList networks = PresetNetworks::names();
1184 foreach (QString s, existing)
1185 networks.removeAll(s);
1186 if (networks.count())
1187 ui.presetList->addItems(networks);
1189 ui.useManual->setChecked(true);
1190 ui.usePreset->setEnabled(false);
1192 connect(ui.networkName, &QLineEdit::textChanged, this, &NetworkAddDlg::setButtonStates);
1193 connect(ui.serverAddress, &QLineEdit::textChanged, this, &NetworkAddDlg::setButtonStates);
1194 connect(ui.usePreset, &QRadioButton::toggled, this, &NetworkAddDlg::setButtonStates);
1195 connect(ui.useManual, &QRadioButton::toggled, this, &NetworkAddDlg::setButtonStates);
1199 NetworkInfo NetworkAddDlg::networkInfo() const
1201 if (ui.useManual->isChecked()) {
1203 info.networkName = ui.networkName->text().trimmed();
1204 info.serverList << Network::Server(ui.serverAddress->text().trimmed(),
1206 ui.serverPassword->text(),
1207 ui.useSSL->isChecked(),
1208 ui.sslVerify->isChecked());
1212 return PresetNetworks::networkInfo(ui.presetList->currentText());
1215 void NetworkAddDlg::setButtonStates()
1218 if (ui.usePreset->isChecked() && ui.presetList->count())
1220 else if (ui.useManual->isChecked()) {
1221 ok = !ui.networkName->text().trimmed().isEmpty() && !existing.contains(ui.networkName->text().trimmed())
1222 && !ui.serverAddress->text().isEmpty();
1224 ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ok);
1227 void NetworkAddDlg::updateSslPort(bool isChecked)
1229 // "Use encrypted connection" was toggled, check the state...
1230 if (isChecked && ui.port->value() == Network::PORT_PLAINTEXT) {
1231 // Had been using the plain-text port, use the SSL default
1232 ui.port->setValue(Network::PORT_SSL);
1234 else if (!isChecked && ui.port->value() == Network::PORT_SSL) {
1235 // Had been using the SSL port, use the plain-text default
1236 ui.port->setValue(Network::PORT_PLAINTEXT);
1240 /**************************************************************************
1242 *************************************************************************/
1244 NetworkEditDlg::NetworkEditDlg(const QString& old, QStringList exist, QWidget* parent)
1246 , existing(std::move(exist))
1250 if (old.isEmpty()) {
1252 setWindowTitle(tr("Add Network"));
1253 on_networkEdit_textChanged(""); // disable ok button
1256 ui.networkEdit->setText(old);
1259 QString NetworkEditDlg::networkName() const
1261 return ui.networkEdit->text().trimmed();
1264 void NetworkEditDlg::on_networkEdit_textChanged(const QString& text)
1266 ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(text.isEmpty() || existing.contains(text.trimmed()));
1269 /**************************************************************************
1271 *************************************************************************/
1272 ServerEditDlg::ServerEditDlg(const Network::Server& server, QWidget* parent)
1276 ui.useSSL->setIcon(icon::get("document-encrypt"));
1277 ui.host->setText(server.host);
1278 ui.host->setFocus();
1279 ui.port->setValue(server.port);
1280 ui.password->setText(server.password);
1281 ui.useSSL->setChecked(server.useSsl);
1282 ui.sslVerify->setChecked(server.sslVerify);
1283 ui.sslVersion->setCurrentIndex(server.sslVersion);
1284 ui.useProxy->setChecked(server.useProxy);
1285 ui.proxyType->setCurrentIndex(server.proxyType == QNetworkProxy::Socks5Proxy ? 0 : 1);
1286 ui.proxyHost->setText(server.proxyHost);
1287 ui.proxyPort->setValue(server.proxyPort);
1288 ui.proxyUsername->setText(server.proxyUser);
1289 ui.proxyPassword->setText(server.proxyPass);
1291 // This is a dirty hack to display the core->IRC SSL protocol dropdown
1292 // only if the core won't use autonegotiation to determine the best
1293 // protocol. When autonegotiation was introduced, it would have been
1294 // a good idea to use the CoreFeatures enum to accomplish this.
1295 // However, since multiple versions have been released since then, that
1296 // is no longer possible. Instead, we rely on the fact that the
1297 // Datastream protocol was introduced in the same version (0.10) as SSL
1298 // autonegotiation. Because of that, we can display the dropdown only
1299 // if the Legacy protocol is in use. If any other RemotePeer protocol
1300 // is in use, that means a newer protocol is in use and therefore the
1301 // core will use autonegotiation.
1302 if (Client::coreConnection()->peer()->protocol() != Protocol::LegacyProtocol) {
1304 ui.sslVersion->hide();
1307 // Whenever useSSL is toggled, update the port number if not changed from the default
1308 connect(ui.useSSL, &QAbstractButton::toggled, this, &ServerEditDlg::updateSslPort);
1309 // Do NOT call updateSslPort when loading settings, otherwise port settings may be overriden.
1310 // If useSSL is later changed to be checked by default, change port's default value, too.
1312 if (Client::isCoreFeatureEnabled(Quassel::Feature::VerifyServerSSL)) {
1313 // Synchronize requiring SSL with the use SSL checkbox
1314 ui.sslVerify->setEnabled(ui.useSSL->isChecked());
1315 connect(ui.useSSL, &QAbstractButton::toggled, ui.sslVerify, &QWidget::setEnabled);
1318 // Core isn't new enough to allow requiring SSL; disable checkbox and uncheck
1319 ui.sslVerify->setEnabled(false);
1320 ui.sslVerify->setChecked(false);
1321 // Split up the message to allow re-using translations:
1322 // [Original tool-tip]
1323 // [Bold 'does not support feature' message]
1324 // [Specific version needed and feature details]
1325 ui.sslVerify->setToolTip(QString("%1<br/><b>%2</b><br/>%3")
1326 .arg(ui.sslVerify->toolTip(),
1327 tr("Your Quassel core does not support this feature"),
1328 tr("You need a Quassel core v0.13.0 or newer in order to "
1329 "verify connection security.")));
1332 on_host_textChanged();
1335 Network::Server ServerEditDlg::serverData() const
1337 Network::Server server(ui.host->text().trimmed(), ui.port->value(), ui.password->text(), ui.useSSL->isChecked(), ui.sslVerify->isChecked());
1338 server.sslVersion = ui.sslVersion->currentIndex();
1339 server.useProxy = ui.useProxy->isChecked();
1340 server.proxyType = ui.proxyType->currentIndex() == 0 ? QNetworkProxy::Socks5Proxy : QNetworkProxy::HttpProxy;
1341 server.proxyHost = ui.proxyHost->text();
1342 server.proxyPort = ui.proxyPort->value();
1343 server.proxyUser = ui.proxyUsername->text();
1344 server.proxyPass = ui.proxyPassword->text();
1348 void ServerEditDlg::on_host_textChanged()
1350 ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(ui.host->text().trimmed().isEmpty());
1353 void ServerEditDlg::updateSslPort(bool isChecked)
1355 // "Use encrypted connection" was toggled, check the state...
1356 if (isChecked && ui.port->value() == Network::PORT_PLAINTEXT) {
1357 // Had been using the plain-text port, use the SSL default
1358 ui.port->setValue(Network::PORT_SSL);
1360 else if (!isChecked && ui.port->value() == Network::PORT_SSL) {
1361 // Had been using the SSL port, use the plain-text default
1362 ui.port->setValue(Network::PORT_PLAINTEXT);
1366 /**************************************************************************
1368 *************************************************************************/
1370 CapsEditDlg::CapsEditDlg(const QString& oldSkipCapsString, QWidget* parent)
1372 , oldSkipCapsString(oldSkipCapsString)
1376 // Connect to the reset button to reset the text
1377 // This provides an explicit way to "get back to defaults" in case someone changes settings to
1379 QPushButton* defaultsButton = ui.buttonBox->button(QDialogButtonBox::RestoreDefaults);
1380 connect(defaultsButton, &QPushButton::clicked, this, &CapsEditDlg::defaultSkipCaps);
1382 if (oldSkipCapsString.isEmpty()) {
1383 // Disable Reset button
1384 on_skipCapsEdit_textChanged("");
1387 ui.skipCapsEdit->setText(oldSkipCapsString);
1392 QString CapsEditDlg::skipCapsString() const
1394 return ui.skipCapsEdit->text();
1397 void CapsEditDlg::defaultSkipCaps()
1399 ui.skipCapsEdit->setText("");
1402 void CapsEditDlg::on_skipCapsEdit_textChanged(const QString& text)
1404 ui.buttonBox->button(QDialogButtonBox::RestoreDefaults)->setDisabled(text.isEmpty());
1407 /**************************************************************************
1409 *************************************************************************/
1411 SaveNetworksDlg::SaveNetworksDlg(const QList<NetworkInfo>& toCreate,
1412 const QList<NetworkInfo>& toUpdate,
1413 const QList<NetworkId>& toRemove,
1419 numevents = toCreate.count() + toUpdate.count() + toRemove.count();
1422 ui.progressBar->setMaximum(numevents);
1423 ui.progressBar->setValue(0);
1425 connect(Client::instance(), &Client::networkCreated, this, &SaveNetworksDlg::clientEvent);
1426 connect(Client::instance(), &Client::networkRemoved, this, &SaveNetworksDlg::clientEvent);
1428 foreach (NetworkId id, toRemove) {
1429 Client::removeNetwork(id);
1431 foreach (NetworkInfo info, toCreate) {
1432 Client::createNetwork(info);
1434 foreach (NetworkInfo info, toUpdate) {
1435 const Network* net = Client::network(info.networkId);
1437 qWarning() << "Invalid client network!";
1441 // FIXME this only checks for one changed item rather than all!
1442 connect(net, &SyncableObject::updatedRemotely, this, &SaveNetworksDlg::clientEvent);
1443 Client::updateNetwork(info);
1447 qWarning() << "Sync dialog called without stuff to change!";
1452 void SaveNetworksDlg::clientEvent()
1454 ui.progressBar->setValue(++rcvevents);
1455 if (rcvevents >= numevents)