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 if (net->saslMaybeSupports(IrcCap::SaslMech::PLAIN)) {
376 setSASLStatus(CapSupportStatus::MaybeSupported);
379 setSASLStatus(CapSupportStatus::MaybeUnsupported);
382 // Add additional capability-dependent interface updates here
385 // Network is disconnected
387 setSASLStatus(CapSupportStatus::Disconnected);
389 // Add additional capability-dependent interface updates here
393 // Capability negotiation is not supported and/or network doesn't exist.
394 // Don't assume anything and reset all capability-dependent interface elements to neutral.
396 setSASLStatus(CapSupportStatus::Unknown);
398 // Add additional capability-dependent interface updates here
402 void NetworksSettingsPage::coreConnectionStateChanged(bool state)
404 this->setEnabled(state);
414 void NetworksSettingsPage::clientIdentityAdded(IdentityId id)
416 const Identity* identity = Client::identity(id);
417 connect(identity, &SyncableObject::updatedRemotely, this, &NetworksSettingsPage::clientIdentityUpdated);
419 QString name = identity->identityName();
420 for (int j = 0; j < ui.identityList->count(); j++) {
421 if ((j > 0 || ui.identityList->itemData(0).toInt() != 1) && name.localeAwareCompare(ui.identityList->itemText(j)) < 0) {
422 ui.identityList->insertItem(j, name, id.toInt());
428 ui.identityList->insertItem(ui.identityList->count(), name, id.toInt());
432 void NetworksSettingsPage::clientIdentityUpdated()
434 const auto* identity = qobject_cast<const Identity*>(sender());
436 qWarning() << "NetworksSettingsPage: Invalid identity to update!";
439 int row = ui.identityList->findData(identity->id().toInt());
441 qWarning() << "NetworksSettingsPage: Invalid identity to update!";
444 if (ui.identityList->itemText(row) != identity->identityName()) {
445 ui.identityList->setItemText(row, identity->identityName());
449 void NetworksSettingsPage::clientIdentityRemoved(IdentityId id)
451 IdentityId defaultId = defaultIdentity();
453 saveToNetworkInfo(networkInfos[currentId]);
454 foreach (NetworkInfo info, networkInfos.values()) {
455 if (info.identity == id) {
456 if (info.networkId == currentId)
457 ui.identityList->setCurrentIndex(0);
458 info.identity = defaultId;
459 networkInfos[info.networkId] = info;
460 if (info.networkId > 0)
461 Client::updateNetwork(info);
464 ui.identityList->removeItem(ui.identityList->findData(id.toInt()));
468 QListWidgetItem* NetworksSettingsPage::networkItem(NetworkId id) const
470 for (int i = 0; i < ui.networkList->count(); i++) {
471 QListWidgetItem* item = ui.networkList->item(i);
472 if (item->data(Qt::UserRole).value<NetworkId>() == id)
478 void NetworksSettingsPage::clientNetworkAdded(NetworkId id)
481 // connect(Client::network(id), &Network::updatedRemotely, this, &NetworksSettingsPage::clientNetworkUpdated);
482 connect(Client::network(id), &Network::configChanged, this, &NetworksSettingsPage::clientNetworkUpdated);
484 connect(Client::network(id), &Network::connectionStateSet, this, &NetworksSettingsPage::networkConnectionStateChanged);
485 connect(Client::network(id), &Network::connectionError, this, &NetworksSettingsPage::networkConnectionError);
487 // Handle capability changes in case a server dis/connects with the settings window open.
488 connect(Client::network(id), &Network::capAdded, this, &NetworksSettingsPage::clientNetworkCapsUpdated);
489 connect(Client::network(id), &Network::capRemoved, this, &NetworksSettingsPage::clientNetworkCapsUpdated);
492 void NetworksSettingsPage::clientNetworkUpdated()
494 const auto* net = qobject_cast<const Network*>(sender());
496 qWarning() << "Update request for unknown network received!";
499 networkInfos[net->networkId()] = net->networkInfo();
500 setItemState(net->networkId());
501 if (net->networkId() == currentId)
502 displayNetwork(net->networkId());
507 void NetworksSettingsPage::clientNetworkRemoved(NetworkId id)
509 if (!networkInfos.contains(id))
513 NetworkInfo info = networkInfos.take(id);
514 QList<QListWidgetItem*> items = ui.networkList->findItems(info.networkName, Qt::MatchExactly);
515 foreach (QListWidgetItem* item, items) {
516 if (item->data(Qt::UserRole).value<NetworkId>() == id)
517 delete ui.networkList->takeItem(ui.networkList->row(item));
523 void NetworksSettingsPage::networkConnectionStateChanged(Network::ConnectionState state)
526 const auto* net = qobject_cast<const Network*>(sender());
530 if(net->networkId() == currentId) {
531 ui.connectNow->setEnabled(state == Network::Initialized || state == Network::Disconnected);
534 setItemState(net->networkId());
535 if (net->networkId() == currentId) {
536 // Network is currently shown. Update the capability-dependent UI in case capabilities have
538 setNetworkCapStates(currentId);
543 void NetworksSettingsPage::networkConnectionError(const QString&) {}
545 QListWidgetItem* NetworksSettingsPage::insertNetwork(NetworkId id)
547 NetworkInfo info = Client::network(id)->networkInfo();
548 networkInfos[id] = info;
549 return insertNetwork(info);
552 QListWidgetItem* NetworksSettingsPage::insertNetwork(const NetworkInfo& info)
554 QListWidgetItem* item = nullptr;
555 QList<QListWidgetItem*> items = ui.networkList->findItems(info.networkName, Qt::MatchExactly);
557 item = new QListWidgetItem(disconnectedIcon, info.networkName, ui.networkList);
559 // we overwrite an existing net if it a) has the same name and b) has a negative ID meaning we created it locally before
560 // -> then we can be sure that this is the core-side replacement for the net we created
561 foreach (QListWidgetItem* i, items) {
562 NetworkId id = i->data(Qt::UserRole).value<NetworkId>();
569 item = new QListWidgetItem(disconnectedIcon, info.networkName, ui.networkList);
571 item->setData(Qt::UserRole, QVariant::fromValue(info.networkId));
572 setItemState(info.networkId, item);
577 // Called when selecting 'Configure' from the buffer list
578 void NetworksSettingsPage::bufferList_Open(NetworkId netId)
580 QListWidgetItem* item = networkItem(netId);
581 ui.networkList->setCurrentItem(item, QItemSelectionModel::SelectCurrent);
584 void NetworksSettingsPage::displayNetwork(NetworkId id)
586 _ignoreWidgetChanges = true;
588 NetworkInfo info = networkInfos[id];
590 // this is only needed when the core supports SASL EXTERNAL
591 if (Client::isCoreFeatureEnabled(Quassel::Feature::SaslExternal)) {
593 // Clean up existing CertIdentity
594 disconnect(_cid, &CertIdentity::sslSettingsUpdated, this, &NetworksSettingsPage::sslUpdated);
598 auto *identity = Client::identity(info.identity);
600 // Connect new CertIdentity
601 _cid = new CertIdentity(*identity, this);
602 _cid->enableEditSsl(true);
603 connect(_cid, &CertIdentity::sslSettingsUpdated, this, &NetworksSettingsPage::sslUpdated);
606 qWarning() << "NetworksSettingsPage::displayNetwork can't find Identity for IdentityId:" << info.identity;
610 ui.identityList->setCurrentIndex(ui.identityList->findData(info.identity.toInt()));
611 ui.serverList->clear();
612 foreach (Network::Server server, info.serverList) {
613 QListWidgetItem* item = new QListWidgetItem(QString("%1:%2").arg(server.host).arg(server.port));
615 item->setIcon(icon::get("document-encrypt"));
616 ui.serverList->addItem(item);
619 // ui.randomServer->setChecked(info.useRandomServer);
620 // Update the capability-dependent UI in case capabilities have changed.
621 setNetworkCapStates(id);
622 ui.performEdit->setPlainText(info.perform.join("\n"));
623 ui.autoIdentify->setChecked(info.useAutoIdentify);
624 ui.autoIdentifyService->setText(info.autoIdentifyService);
625 ui.autoIdentifyPassword->setText(info.autoIdentifyPassword);
626 ui.sasl->setChecked(info.useSasl);
627 ui.saslAccount->setText(info.saslAccount);
628 ui.saslPassword->setText(info.saslPassword);
629 if (info.codecForEncoding.isEmpty()) {
630 ui.sendEncoding->setCurrentIndex(ui.sendEncoding->findText(Network::defaultCodecForEncoding()));
631 ui.recvEncoding->setCurrentIndex(ui.recvEncoding->findText(Network::defaultCodecForDecoding()));
632 ui.serverEncoding->setCurrentIndex(ui.serverEncoding->findText(Network::defaultCodecForServer()));
633 ui.useCustomEncodings->setChecked(false);
636 ui.sendEncoding->setCurrentIndex(ui.sendEncoding->findText(info.codecForEncoding));
637 ui.recvEncoding->setCurrentIndex(ui.recvEncoding->findText(info.codecForDecoding));
638 ui.serverEncoding->setCurrentIndex(ui.serverEncoding->findText(info.codecForServer));
639 ui.useCustomEncodings->setChecked(true);
641 ui.autoReconnect->setChecked(info.useAutoReconnect);
642 ui.reconnectInterval->setValue(info.autoReconnectInterval);
643 ui.reconnectRetries->setValue(info.autoReconnectRetries);
644 ui.unlimitedRetries->setChecked(info.unlimitedReconnectRetries);
645 ui.rejoinOnReconnect->setChecked(info.rejoinChannels);
646 // Custom rate limiting
647 ui.unlimitedMessageRate->setChecked(info.unlimitedMessageRate);
648 // Set 'ui.useCustomMessageRate' after 'ui.unlimitedMessageRate' so if the latter is
649 // disabled, 'ui.messageRateDelayFrame' will remain disabled.
650 ui.useCustomMessageRate->setChecked(info.useCustomMessageRate);
651 ui.messageRateBurstSize->setValue(info.messageRateBurstSize);
652 // Convert milliseconds (integer) into seconds (double)
653 ui.messageRateDelay->setValue(info.messageRateDelay / 1000.0f);
654 // Skipped IRCv3 capabilities
655 ui.enableCapServerTime->setChecked(!info.skipCaps.contains(IrcCap::SERVER_TIME));
658 // just clear widgets
660 disconnect(_cid, &CertIdentity::sslSettingsUpdated, this, &NetworksSettingsPage::sslUpdated);
663 ui.identityList->setCurrentIndex(-1);
664 ui.serverList->clear();
665 ui.performEdit->clear();
666 ui.autoIdentifyService->clear();
667 ui.autoIdentifyPassword->clear();
668 ui.saslAccount->clear();
669 ui.saslPassword->clear();
672 _ignoreWidgetChanges = false;
676 void NetworksSettingsPage::saveToNetworkInfo(NetworkInfo& info)
678 info.identity = ui.identityList->itemData(ui.identityList->currentIndex()).toInt();
679 // info.useRandomServer = ui.randomServer->isChecked();
680 info.perform = ui.performEdit->toPlainText().split("\n");
681 info.useAutoIdentify = ui.autoIdentify->isChecked();
682 info.autoIdentifyService = ui.autoIdentifyService->text();
683 info.autoIdentifyPassword = ui.autoIdentifyPassword->text();
684 info.useSasl = ui.sasl->isChecked();
685 info.saslAccount = ui.saslAccount->text();
686 info.saslPassword = ui.saslPassword->text();
687 if (!ui.useCustomEncodings->isChecked()) {
688 info.codecForEncoding.clear();
689 info.codecForDecoding.clear();
690 info.codecForServer.clear();
693 info.codecForEncoding = ui.sendEncoding->currentText().toLatin1();
694 info.codecForDecoding = ui.recvEncoding->currentText().toLatin1();
695 info.codecForServer = ui.serverEncoding->currentText().toLatin1();
697 info.useAutoReconnect = ui.autoReconnect->isChecked();
698 info.autoReconnectInterval = ui.reconnectInterval->value();
699 info.autoReconnectRetries = ui.reconnectRetries->value();
700 info.unlimitedReconnectRetries = ui.unlimitedRetries->isChecked();
701 info.rejoinChannels = ui.rejoinOnReconnect->isChecked();
702 // Custom rate limiting
703 info.useCustomMessageRate = ui.useCustomMessageRate->isChecked();
704 info.messageRateBurstSize = ui.messageRateBurstSize->value();
705 // Convert seconds (double) into milliseconds (integer)
706 info.messageRateDelay = static_cast<quint32>((ui.messageRateDelay->value() * 1000));
707 info.unlimitedMessageRate = ui.unlimitedMessageRate->isChecked();
708 // Skipped IRCv3 capabilities
709 if (ui.enableCapServerTime->isChecked()) {
710 // Capability enabled, remove it from the skip list
711 info.skipCaps.removeAll(IrcCap::SERVER_TIME);
712 } else if (!info.skipCaps.contains(IrcCap::SERVER_TIME)) {
713 // Capability disabled and not in the skip list, add it
714 info.skipCaps.append(IrcCap::SERVER_TIME);
718 void NetworksSettingsPage::clientNetworkCapsUpdated()
720 // Grab the updated network
721 const auto* net = qobject_cast<const Network*>(sender());
723 qWarning() << "Update request for unknown network received!";
726 if (net->networkId() == currentId) {
727 // Network is currently shown. Update the capability-dependent UI in case capabilities have
729 setNetworkCapStates(currentId);
733 void NetworksSettingsPage::setSASLStatus(const CapSupportStatus saslStatus)
735 if (_saslStatusSelected != saslStatus) {
736 // Update the cached copy of SASL status used with the Details dialog
737 _saslStatusSelected = saslStatus;
739 // Update the user interface
740 switch (saslStatus) {
741 case CapSupportStatus::Unknown:
742 // There's no capability negotiation or network doesn't exist. Don't assume
744 ui.saslStatusLabel->setText(QString("<i>%1</i>").arg(tr("Could not check if supported by network")));
745 ui.saslStatusIcon->setPixmap(questionIcon.pixmap(16));
747 case CapSupportStatus::Disconnected:
748 // Disconnected from network, no way to check.
749 ui.saslStatusLabel->setText(QString("<i>%1</i>").arg(tr("Cannot check if supported when disconnected")));
750 ui.saslStatusIcon->setPixmap(questionIcon.pixmap(16));
752 case CapSupportStatus::MaybeUnsupported:
753 // The network doesn't advertise support for SASL PLAIN. Here be dragons.
754 ui.saslStatusLabel->setText(QString("<i>%1</i>").arg(tr("Not currently supported by network")));
755 ui.saslStatusIcon->setPixmap(unavailableIcon.pixmap(16));
757 case CapSupportStatus::MaybeSupported:
758 // The network advertises support for SASL PLAIN. Encourage using it!
759 // Unfortunately we don't know for sure if it's desired or functional.
760 ui.saslStatusLabel->setText(QString("<i>%1</i>").arg(tr("Supported by network")));
761 ui.saslStatusIcon->setPixmap(successIcon.pixmap(16));
767 void NetworksSettingsPage::sslUpdated()
769 if (_cid && !_cid->sslKey().isNull()) {
770 ui.saslContents->setDisabled(true);
771 ui.saslExtInfo->setHidden(false);
774 ui.saslContents->setDisabled(false);
775 // Directly re-enabling causes the widgets to ignore the parent "Use SASL Authentication"
776 // state to indicate whether or not it's disabled. To workaround this, keep track of
777 // whether or not "Use SASL Authentication" is enabled, then quickly uncheck/recheck the
779 if (!ui.sasl->isChecked()) {
780 // SASL is not enabled, uncheck/recheck the group box to re-disable saslContents.
781 // Leaving saslContents disabled doesn't work as that prevents it from re-enabling if
782 // sasl is later checked.
783 ui.sasl->setChecked(true);
784 ui.sasl->setChecked(false);
786 ui.saslExtInfo->setHidden(true);
790 /*** Network list ***/
792 void NetworksSettingsPage::on_networkList_itemSelectionChanged()
794 if (currentId != 0) {
795 saveToNetworkInfo(networkInfos[currentId]);
797 if (ui.networkList->selectedItems().count()) {
798 NetworkId id = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
801 ui.serverList->setCurrentRow(0);
809 void NetworksSettingsPage::on_addNetwork_clicked()
811 QStringList existing;
812 for (int i = 0; i < ui.networkList->count(); i++)
813 existing << ui.networkList->item(i)->text();
814 NetworkAddDlg dlg(existing, this);
815 if (dlg.exec() == QDialog::Accepted) {
816 NetworkInfo info = dlg.networkInfo();
817 if (info.networkName.isEmpty())
818 return; // sanity check
821 for (id = 1; id <= networkInfos.count(); id++) {
823 if (!networkInfos.keys().contains(-id.toInt()))
828 info.identity = defaultIdentity();
829 networkInfos[id] = info;
830 QListWidgetItem* item = insertNetwork(info);
831 ui.networkList->setCurrentItem(item);
836 void NetworksSettingsPage::on_deleteNetwork_clicked()
838 if (ui.networkList->selectedItems().count()) {
839 NetworkId netid = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
841 = QMessageBox::question(this,
842 tr("Delete Network?"),
843 tr("Do you really want to delete the network \"%1\" and all related settings, including the backlog?")
844 .arg(networkInfos[netid].networkName),
845 QMessageBox::Yes | QMessageBox::No,
847 if (ret == QMessageBox::Yes) {
849 networkInfos.remove(netid);
850 delete ui.networkList->takeItem(ui.networkList->row(ui.networkList->selectedItems()[0]));
851 ui.networkList->setCurrentRow(qMin(ui.networkList->currentRow() + 1, ui.networkList->count() - 1));
858 void NetworksSettingsPage::on_renameNetwork_clicked()
860 if (!ui.networkList->selectedItems().count())
862 QString old = ui.networkList->selectedItems()[0]->text();
863 QStringList existing;
864 for (int i = 0; i < ui.networkList->count(); i++)
865 existing << ui.networkList->item(i)->text();
866 NetworkEditDlg dlg(old, existing, this);
867 if (dlg.exec() == QDialog::Accepted) {
868 ui.networkList->selectedItems()[0]->setText(dlg.networkName());
869 NetworkId netid = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
870 networkInfos[netid].networkName = dlg.networkName();
876 void NetworksSettingsPage::on_connectNow_clicked() {
877 if(!ui.networkList->selectedItems().count()) return;
878 NetworkId id = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
879 const Network *net = Client::network(id);
881 if(net->connectionState() == Network::Disconnected) net->requestConnect();
882 else net->requestDisconnect();
886 /*** Server list ***/
888 void NetworksSettingsPage::on_serverList_itemSelectionChanged()
893 void NetworksSettingsPage::on_addServer_clicked()
897 ServerEditDlg dlg(Network::Server(), this);
898 if (dlg.exec() == QDialog::Accepted) {
899 networkInfos[currentId].serverList.append(dlg.serverData());
900 displayNetwork(currentId);
901 ui.serverList->setCurrentRow(ui.serverList->count() - 1);
906 void NetworksSettingsPage::on_editServer_clicked()
910 int cur = ui.serverList->currentRow();
911 ServerEditDlg dlg(networkInfos[currentId].serverList[cur], this);
912 if (dlg.exec() == QDialog::Accepted) {
913 networkInfos[currentId].serverList[cur] = dlg.serverData();
914 displayNetwork(currentId);
915 ui.serverList->setCurrentRow(cur);
920 void NetworksSettingsPage::on_deleteServer_clicked()
924 int cur = ui.serverList->currentRow();
925 networkInfos[currentId].serverList.removeAt(cur);
926 displayNetwork(currentId);
927 ui.serverList->setCurrentRow(qMin(cur, ui.serverList->count() - 1));
931 void NetworksSettingsPage::on_upServer_clicked()
933 int cur = ui.serverList->currentRow();
934 Network::Server server = networkInfos[currentId].serverList.takeAt(cur);
935 networkInfos[currentId].serverList.insert(cur - 1, server);
936 displayNetwork(currentId);
937 ui.serverList->setCurrentRow(cur - 1);
941 void NetworksSettingsPage::on_downServer_clicked()
943 int cur = ui.serverList->currentRow();
944 Network::Server server = networkInfos[currentId].serverList.takeAt(cur);
945 networkInfos[currentId].serverList.insert(cur + 1, server);
946 displayNetwork(currentId);
947 ui.serverList->setCurrentRow(cur + 1);
951 void NetworksSettingsPage::on_editIdentities_clicked()
953 SettingsPageDlg dlg(new IdentitiesSettingsPage(this), this);
957 void NetworksSettingsPage::on_saslStatusDetails_clicked()
959 if (ui.networkList->selectedItems().count()) {
960 NetworkId netid = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
961 QString& netName = networkInfos[netid].networkName;
963 // If these strings are visible, one of the status messages wasn't detected below.
964 QString saslStatusHeader = "[header unintentionally left blank]";
965 QString saslStatusExplanation = "[explanation unintentionally left blank]";
967 // If true, show a warning icon instead of an information icon
968 bool useWarningIcon = false;
970 // Determine which explanation to show
971 switch (_saslStatusSelected) {
972 case CapSupportStatus::Unknown:
973 saslStatusHeader = tr("Could not check if SASL supported by network");
974 saslStatusExplanation = tr("Quassel could not check if \"%1\" supports SASL. This may "
975 "be due to unsaved changes or an older Quassel core. You "
976 "can still try using SASL.")
979 case CapSupportStatus::Disconnected:
980 saslStatusHeader = tr("Cannot check if SASL supported when disconnected");
981 saslStatusExplanation = tr("Quassel cannot check if \"%1\" supports SASL when "
982 "disconnected. Connect to the network, or try using SASL "
986 case CapSupportStatus::MaybeUnsupported:
987 saslStatusHeader = tr("SASL not currently supported by network");
988 saslStatusExplanation = tr("The network \"%1\" does not currently support SASL. "
989 "However, support might be added later on.")
991 useWarningIcon = true;
993 case CapSupportStatus::MaybeSupported:
994 saslStatusHeader = tr("SASL supported by network");
995 saslStatusExplanation = tr("The network \"%1\" supports SASL. In most cases, you "
996 "should use SASL instead of NickServ identification.")
1001 // Process this in advance for reusability below
1002 const QString saslStatusMsgTitle = tr("SASL support for \"%1\"").arg(netName);
1003 const QString saslStatusMsgText = QString("<p><b>%1</b></p></br><p>%2</p></br><p><i>%3</i></p>")
1004 .arg(saslStatusHeader,
1005 saslStatusExplanation,
1006 tr("SASL is a standardized way to log in and identify yourself to "
1009 if (useWarningIcon) {
1010 // Show as a warning dialog box
1011 QMessageBox::warning(this, saslStatusMsgTitle, saslStatusMsgText);
1014 // Show as an information dialog box
1015 QMessageBox::information(this, saslStatusMsgTitle, saslStatusMsgText);
1020 void NetworksSettingsPage::on_enableCapsStatusDetails_clicked()
1022 if (!Client::isConnected() || Client::isCoreFeatureEnabled(Quassel::Feature::SkipIrcCaps)) {
1023 // Either disconnected or IRCv3 capability skippping supported
1025 // Try to get a list of currently enabled features
1026 QStringList sortedCapsEnabled;
1027 // Check if a network is selected
1028 if (ui.networkList->selectedItems().count()) {
1029 // Get the underlying Network from the selected network
1030 NetworkId netid = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
1031 const Network* net = Client::network(netid);
1032 if (net && Client::isCoreFeatureEnabled(Quassel::Feature::CapNegotiation)) {
1033 // Capability negotiation is supported, network exists.
1034 // If the network is disconnected, the list of enabled capabilities will be empty,
1035 // no need to check for that specifically.
1036 // Sorting isn't required, but it looks nicer.
1037 sortedCapsEnabled = net->capsEnabled();
1038 sortedCapsEnabled.sort();
1042 // Try to explain IRCv3 network features in a friendly way, including showing the currently
1043 // enabled features if available
1044 auto messageText = QString("<p>%1</p></br><p>%2</p>")
1045 .arg(tr("Quassel makes use of newer IRC features when supported by the IRC network."
1046 " If desired, you can disable unwanted or problematic features here."),
1047 tr("The <a href=\"https://ircv3.net/irc/\">IRCv3 website</a> provides more "
1048 "technical details on the IRCv3 capabilities powering these features."));
1050 if (!sortedCapsEnabled.isEmpty()) {
1051 // Format the capabilities within <code></code> blocks
1052 auto formattedCaps = QString("<code>%1</code>")
1053 .arg(sortedCapsEnabled.join("</code>, <code>"));
1055 // Add the currently enabled capabilities to the list
1056 // This creates a new QString, but this code is not performance-critical.
1057 messageText = messageText.append(QString("<p><i>%1</i></p>").arg(
1058 tr("Currently enabled IRCv3 capabilities for this "
1059 "network: %1").arg(formattedCaps)));
1062 QMessageBox::information(this, tr("Configuring network features"), messageText);
1065 // Core does not IRCv3 capability skipping, show warning
1066 QMessageBox::warning(this, tr("Configuring network features unsupported"),
1067 QString("<p><b>%1</b></p></br><p>%2</p>")
1068 .arg(tr("Your Quassel core is too old to configure IRCv3 network features"),
1069 tr("You need a Quassel core v0.14.0 or newer to control what network "
1070 "features Quassel will use.")));
1074 void NetworksSettingsPage::on_enableCapsAdvanced_clicked()
1079 CapsEditDlg dlg(networkInfos[currentId].skipCapsToString(), this);
1080 if (dlg.exec() == QDialog::Accepted) {
1081 networkInfos[currentId].skipCapsFromString(dlg.skipCapsString());
1082 displayNetwork(currentId);
1087 IdentityId NetworksSettingsPage::defaultIdentity() const
1089 IdentityId defaultId = 0;
1090 QList<IdentityId> ids = Client::identityIds();
1091 foreach (IdentityId id, ids) {
1092 if (defaultId == 0 || id < defaultId)
1098 /**************************************************************************
1100 *************************************************************************/
1102 NetworkAddDlg::NetworkAddDlg(QStringList exist, QWidget* parent)
1104 , existing(std::move(exist))
1107 ui.useSSL->setIcon(icon::get("document-encrypt"));
1109 // Whenever useSSL is toggled, update the port number if not changed from the default
1110 connect(ui.useSSL, &QAbstractButton::toggled, this, &NetworkAddDlg::updateSslPort);
1111 // Do NOT call updateSslPort when loading settings, otherwise port settings may be overriden.
1112 // If useSSL is later changed to be checked by default, change port's default value, too.
1114 if (Client::isCoreFeatureEnabled(Quassel::Feature::VerifyServerSSL)) {
1115 // Synchronize requiring SSL with the use SSL checkbox
1116 ui.sslVerify->setEnabled(ui.useSSL->isChecked());
1117 connect(ui.useSSL, &QAbstractButton::toggled, ui.sslVerify, &QWidget::setEnabled);
1120 // Core isn't new enough to allow requiring SSL; disable checkbox and uncheck
1121 ui.sslVerify->setEnabled(false);
1122 ui.sslVerify->setChecked(false);
1123 // Split up the message to allow re-using translations:
1124 // [Original tool-tip]
1125 // [Bold 'does not support feature' message]
1126 // [Specific version needed and feature details]
1127 ui.sslVerify->setToolTip(QString("%1<br/><b>%2</b><br/>%3")
1128 .arg(ui.sslVerify->toolTip(),
1129 tr("Your Quassel core does not support this feature"),
1130 tr("You need a Quassel core v0.13.0 or newer in order to "
1131 "verify connection security.")));
1134 // read preset networks
1135 QStringList networks = PresetNetworks::names();
1136 foreach (QString s, existing)
1137 networks.removeAll(s);
1138 if (networks.count())
1139 ui.presetList->addItems(networks);
1141 ui.useManual->setChecked(true);
1142 ui.usePreset->setEnabled(false);
1144 connect(ui.networkName, &QLineEdit::textChanged, this, &NetworkAddDlg::setButtonStates);
1145 connect(ui.serverAddress, &QLineEdit::textChanged, this, &NetworkAddDlg::setButtonStates);
1146 connect(ui.usePreset, &QRadioButton::toggled, this, &NetworkAddDlg::setButtonStates);
1147 connect(ui.useManual, &QRadioButton::toggled, this, &NetworkAddDlg::setButtonStates);
1151 NetworkInfo NetworkAddDlg::networkInfo() const
1153 if (ui.useManual->isChecked()) {
1155 info.networkName = ui.networkName->text().trimmed();
1156 info.serverList << Network::Server(ui.serverAddress->text().trimmed(),
1158 ui.serverPassword->text(),
1159 ui.useSSL->isChecked(),
1160 ui.sslVerify->isChecked());
1164 return PresetNetworks::networkInfo(ui.presetList->currentText());
1167 void NetworkAddDlg::setButtonStates()
1170 if (ui.usePreset->isChecked() && ui.presetList->count())
1172 else if (ui.useManual->isChecked()) {
1173 ok = !ui.networkName->text().trimmed().isEmpty() && !existing.contains(ui.networkName->text().trimmed())
1174 && !ui.serverAddress->text().isEmpty();
1176 ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ok);
1179 void NetworkAddDlg::updateSslPort(bool isChecked)
1181 // "Use encrypted connection" was toggled, check the state...
1182 if (isChecked && ui.port->value() == Network::PORT_PLAINTEXT) {
1183 // Had been using the plain-text port, use the SSL default
1184 ui.port->setValue(Network::PORT_SSL);
1186 else if (!isChecked && ui.port->value() == Network::PORT_SSL) {
1187 // Had been using the SSL port, use the plain-text default
1188 ui.port->setValue(Network::PORT_PLAINTEXT);
1192 /**************************************************************************
1194 *************************************************************************/
1196 NetworkEditDlg::NetworkEditDlg(const QString& old, QStringList exist, QWidget* parent)
1198 , existing(std::move(exist))
1202 if (old.isEmpty()) {
1204 setWindowTitle(tr("Add Network"));
1205 on_networkEdit_textChanged(""); // disable ok button
1208 ui.networkEdit->setText(old);
1211 QString NetworkEditDlg::networkName() const
1213 return ui.networkEdit->text().trimmed();
1216 void NetworkEditDlg::on_networkEdit_textChanged(const QString& text)
1218 ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(text.isEmpty() || existing.contains(text.trimmed()));
1221 /**************************************************************************
1223 *************************************************************************/
1224 ServerEditDlg::ServerEditDlg(const Network::Server& server, QWidget* parent)
1228 ui.useSSL->setIcon(icon::get("document-encrypt"));
1229 ui.host->setText(server.host);
1230 ui.host->setFocus();
1231 ui.port->setValue(server.port);
1232 ui.password->setText(server.password);
1233 ui.useSSL->setChecked(server.useSsl);
1234 ui.sslVerify->setChecked(server.sslVerify);
1235 ui.sslVersion->setCurrentIndex(server.sslVersion);
1236 ui.useProxy->setChecked(server.useProxy);
1237 ui.proxyType->setCurrentIndex(server.proxyType == QNetworkProxy::Socks5Proxy ? 0 : 1);
1238 ui.proxyHost->setText(server.proxyHost);
1239 ui.proxyPort->setValue(server.proxyPort);
1240 ui.proxyUsername->setText(server.proxyUser);
1241 ui.proxyPassword->setText(server.proxyPass);
1243 // This is a dirty hack to display the core->IRC SSL protocol dropdown
1244 // only if the core won't use autonegotiation to determine the best
1245 // protocol. When autonegotiation was introduced, it would have been
1246 // a good idea to use the CoreFeatures enum to accomplish this.
1247 // However, since multiple versions have been released since then, that
1248 // is no longer possible. Instead, we rely on the fact that the
1249 // Datastream protocol was introduced in the same version (0.10) as SSL
1250 // autonegotiation. Because of that, we can display the dropdown only
1251 // if the Legacy protocol is in use. If any other RemotePeer protocol
1252 // is in use, that means a newer protocol is in use and therefore the
1253 // core will use autonegotiation.
1254 if (Client::coreConnection()->peer()->protocol() != Protocol::LegacyProtocol) {
1256 ui.sslVersion->hide();
1259 // Whenever useSSL is toggled, update the port number if not changed from the default
1260 connect(ui.useSSL, &QAbstractButton::toggled, this, &ServerEditDlg::updateSslPort);
1261 // Do NOT call updateSslPort when loading settings, otherwise port settings may be overriden.
1262 // If useSSL is later changed to be checked by default, change port's default value, too.
1264 if (Client::isCoreFeatureEnabled(Quassel::Feature::VerifyServerSSL)) {
1265 // Synchronize requiring SSL with the use SSL checkbox
1266 ui.sslVerify->setEnabled(ui.useSSL->isChecked());
1267 connect(ui.useSSL, &QAbstractButton::toggled, ui.sslVerify, &QWidget::setEnabled);
1270 // Core isn't new enough to allow requiring SSL; disable checkbox and uncheck
1271 ui.sslVerify->setEnabled(false);
1272 ui.sslVerify->setChecked(false);
1273 // Split up the message to allow re-using translations:
1274 // [Original tool-tip]
1275 // [Bold 'does not support feature' message]
1276 // [Specific version needed and feature details]
1277 ui.sslVerify->setToolTip(QString("%1<br/><b>%2</b><br/>%3")
1278 .arg(ui.sslVerify->toolTip(),
1279 tr("Your Quassel core does not support this feature"),
1280 tr("You need a Quassel core v0.13.0 or newer in order to "
1281 "verify connection security.")));
1284 on_host_textChanged();
1287 Network::Server ServerEditDlg::serverData() const
1289 Network::Server server(ui.host->text().trimmed(), ui.port->value(), ui.password->text(), ui.useSSL->isChecked(), ui.sslVerify->isChecked());
1290 server.sslVersion = ui.sslVersion->currentIndex();
1291 server.useProxy = ui.useProxy->isChecked();
1292 server.proxyType = ui.proxyType->currentIndex() == 0 ? QNetworkProxy::Socks5Proxy : QNetworkProxy::HttpProxy;
1293 server.proxyHost = ui.proxyHost->text();
1294 server.proxyPort = ui.proxyPort->value();
1295 server.proxyUser = ui.proxyUsername->text();
1296 server.proxyPass = ui.proxyPassword->text();
1300 void ServerEditDlg::on_host_textChanged()
1302 ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(ui.host->text().trimmed().isEmpty());
1305 void ServerEditDlg::updateSslPort(bool isChecked)
1307 // "Use encrypted connection" was toggled, check the state...
1308 if (isChecked && ui.port->value() == Network::PORT_PLAINTEXT) {
1309 // Had been using the plain-text port, use the SSL default
1310 ui.port->setValue(Network::PORT_SSL);
1312 else if (!isChecked && ui.port->value() == Network::PORT_SSL) {
1313 // Had been using the SSL port, use the plain-text default
1314 ui.port->setValue(Network::PORT_PLAINTEXT);
1318 /**************************************************************************
1320 *************************************************************************/
1322 CapsEditDlg::CapsEditDlg(const QString& oldSkipCapsString, QWidget* parent)
1324 , oldSkipCapsString(oldSkipCapsString)
1328 // Connect to the reset button to reset the text
1329 // This provides an explicit way to "get back to defaults" in case someone changes settings to
1331 QPushButton* defaultsButton = ui.buttonBox->button(QDialogButtonBox::RestoreDefaults);
1332 connect(defaultsButton, &QPushButton::clicked, this, &CapsEditDlg::defaultSkipCaps);
1334 if (oldSkipCapsString.isEmpty()) {
1335 // Disable Reset button
1336 on_skipCapsEdit_textChanged("");
1339 ui.skipCapsEdit->setText(oldSkipCapsString);
1344 QString CapsEditDlg::skipCapsString() const
1346 return ui.skipCapsEdit->text();
1349 void CapsEditDlg::defaultSkipCaps()
1351 ui.skipCapsEdit->setText("");
1354 void CapsEditDlg::on_skipCapsEdit_textChanged(const QString& text)
1356 ui.buttonBox->button(QDialogButtonBox::RestoreDefaults)->setDisabled(text.isEmpty());
1359 /**************************************************************************
1361 *************************************************************************/
1363 SaveNetworksDlg::SaveNetworksDlg(const QList<NetworkInfo>& toCreate,
1364 const QList<NetworkInfo>& toUpdate,
1365 const QList<NetworkId>& toRemove,
1371 numevents = toCreate.count() + toUpdate.count() + toRemove.count();
1374 ui.progressBar->setMaximum(numevents);
1375 ui.progressBar->setValue(0);
1377 connect(Client::instance(), &Client::networkCreated, this, &SaveNetworksDlg::clientEvent);
1378 connect(Client::instance(), &Client::networkRemoved, this, &SaveNetworksDlg::clientEvent);
1380 foreach (NetworkId id, toRemove) {
1381 Client::removeNetwork(id);
1383 foreach (NetworkInfo info, toCreate) {
1384 Client::createNetwork(info);
1386 foreach (NetworkInfo info, toUpdate) {
1387 const Network* net = Client::network(info.networkId);
1389 qWarning() << "Invalid client network!";
1393 // FIXME this only checks for one changed item rather than all!
1394 connect(net, &SyncableObject::updatedRemotely, this, &SaveNetworksDlg::clientEvent);
1395 Client::updateNetwork(info);
1399 qWarning() << "Sync dialog called without stuff to change!";
1404 void SaveNetworksDlg::clientEvent()
1406 ui.progressBar->setValue(++rcvevents);
1407 if (rcvevents >= numevents)