X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fsettingspages%2Fnetworkssettingspage.cpp;fp=src%2Fqtui%2Fsettingspages%2Fnetworkssettingspage.cpp;h=f540bc8480f34e6d5d3f4c297f8708774348b6ab;hp=a886d92ef4a9353ff640611a40a57e3acda2f0c5;hb=c1cf157116de7fc3da96203aa6f03c38c7ebb650;hpb=30b159cb876a9495de42e9a3e70ca050516f0805 diff --git a/src/qtui/settingspages/networkssettingspage.cpp b/src/qtui/settingspages/networkssettingspage.cpp index a886d92e..f540bc84 100644 --- a/src/qtui/settingspages/networkssettingspage.cpp +++ b/src/qtui/settingspages/networkssettingspage.cpp @@ -18,12 +18,13 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ +#include "networkssettingspage.h" + +#include + #include #include #include -#include - -#include "networkssettingspage.h" #include "client.h" #include "icon.h" @@ -39,7 +40,7 @@ #include "settingspages/identitiessettingspage.h" -NetworksSettingsPage::NetworksSettingsPage(QWidget *parent) +NetworksSettingsPage::NetworksSettingsPage(QWidget* parent) : SettingsPage(tr("IRC"), tr("Networks"), parent) { ui.setupUi(this); @@ -65,14 +66,14 @@ NetworksSettingsPage::NetworksSettingsPage(QWidget *parent) ui.editIdentities->setIcon(icon::get("configure")); connectedIcon = icon::get("network-connect"); - connectingIcon = icon::get("network-wired"); // FIXME network-connecting + connectingIcon = icon::get("network-wired"); // FIXME network-connecting disconnectedIcon = icon::get("network-disconnect"); // Status icons infoIcon = icon::get("dialog-information"); warningIcon = icon::get("dialog-warning"); - foreach(int mib, QTextCodec::availableMibs()) { + foreach (int mib, QTextCodec::availableMibs()) { QByteArray codec = QTextCodec::codecForMib(mib)->name(); ui.sendEncoding->addItem(codec); ui.recvEncoding->addItem(codec); @@ -82,32 +83,18 @@ NetworksSettingsPage::NetworksSettingsPage(QWidget *parent) ui.recvEncoding->model()->sort(0); ui.serverEncoding->model()->sort(0); currentId = 0; - setEnabled(Client::isConnected()); // need a core connection! + setEnabled(Client::isConnected()); // need a core connection! setWidgetStates(); - connectToWidgetsChangedSignals({ - ui.identityList, - ui.performEdit, - ui.sasl, - ui.saslAccount, - ui.saslPassword, - ui.autoIdentify, - ui.autoIdentifyService, - ui.autoIdentifyPassword, - ui.useCustomEncodings, - ui.sendEncoding, - ui.recvEncoding, - ui.serverEncoding, - ui.autoReconnect, - ui.reconnectInterval, - ui.reconnectRetries, - ui.unlimitedRetries, - ui.rejoinOnReconnect, - ui.useCustomMessageRate, - ui.messageRateBurstSize, - ui.messageRateDelay, - ui.unlimitedMessageRate - }, this, &NetworksSettingsPage::widgetHasChanged); + connectToWidgetsChangedSignals({ui.identityList, ui.performEdit, ui.sasl, + ui.saslAccount, ui.saslPassword, ui.autoIdentify, + ui.autoIdentifyService, ui.autoIdentifyPassword, ui.useCustomEncodings, + ui.sendEncoding, ui.recvEncoding, ui.serverEncoding, + ui.autoReconnect, ui.reconnectInterval, ui.reconnectRetries, + ui.unlimitedRetries, ui.rejoinOnReconnect, ui.useCustomMessageRate, + ui.messageRateBurstSize, ui.messageRateDelay, ui.unlimitedMessageRate}, + this, + &NetworksSettingsPage::widgetHasChanged); connect(Client::instance(), &Client::coreConnectionStateChanged, this, &NetworksSettingsPage::coreConnectionStateChanged); connect(Client::instance(), &Client::networkCreated, this, &NetworksSettingsPage::clientNetworkAdded); @@ -115,16 +102,16 @@ NetworksSettingsPage::NetworksSettingsPage(QWidget *parent) connect(Client::instance(), &Client::identityCreated, this, &NetworksSettingsPage::clientIdentityAdded); connect(Client::instance(), &Client::identityRemoved, this, &NetworksSettingsPage::clientIdentityRemoved); - foreach(IdentityId id, Client::identityIds()) { + foreach (IdentityId id, Client::identityIds()) { clientIdentityAdded(id); } } - void NetworksSettingsPage::save() { setEnabled(false); - if (currentId != 0) saveToNetworkInfo(networkInfos[currentId]); + if (currentId != 0) + saveToNetworkInfo(networkInfos[currentId]); QList toCreate, toUpdate; QList toRemove; @@ -133,13 +120,13 @@ void NetworksSettingsPage::save() NetworkId id = (*i).networkId; if (id < 0) { toCreate.append(*i); - //if(id == currentId) currentId = 0; - //QList items = ui.networkList->findItems((*i).networkName, Qt::MatchExactly); - //if(items.count()) { + // if(id == currentId) currentId = 0; + // QList items = ui.networkList->findItems((*i).networkName, Qt::MatchExactly); + // if(items.count()) { // Q_ASSERT(items[0]->data(Qt::UserRole).value() == id); // delete items[0]; //} - //i = networkInfos.erase(i); + // i = networkInfos.erase(i); ++i; } else { @@ -149,8 +136,9 @@ void NetworksSettingsPage::save() ++i; } } - foreach(NetworkId id, Client::networkIds()) { - if (!networkInfos.contains(id)) toRemove.append(id); + foreach (NetworkId id, Client::networkIds()) { + if (!networkInfos.contains(id)) + toRemove.append(id); } SaveNetworksDlg dlg(toCreate, toUpdate, toRemove, this); int ret = dlg.exec(); @@ -162,7 +150,6 @@ void NetworksSettingsPage::save() setEnabled(true); } - void NetworksSettingsPage::load() { reset(); @@ -172,25 +159,25 @@ void NetworksSettingsPage::load() // Custom rate limiting supported, allow toggling ui.useCustomMessageRate->setEnabled(true); // Reset tooltip to default. - ui.useCustomMessageRate->setToolTip(QString("%1").arg( - tr("

Override default message rate limiting.

" - "

Setting limits too low may get you disconnected" - " from the server!

"))); + ui.useCustomMessageRate->setToolTip(QString("%1").arg(tr("

Override default message rate limiting.

" + "

Setting limits too low may get you disconnected" + " from the server!

"))); // If changed, update the message below! - } else { + } + else { // Custom rate limiting not supported, disallow toggling ui.useCustomMessageRate->setEnabled(false); // Split up the message to allow re-using translations: // [Original tool-tip] // [Bold 'does not support feature' message] // [Specific version needed and feature details] - ui.useCustomMessageRate->setToolTip(QString("%1
%2
%3").arg( - tr("

Override default message rate limiting.

" - "

Setting limits too low may get you disconnected" - " from the server!

"), - tr("Your Quassel core does not support this feature"), - tr("You need a Quassel core v0.13.0 or newer in order to " - "modify message rate limits."))); + ui.useCustomMessageRate->setToolTip(QString("%1
%2
%3") + .arg(tr("

Override default message rate limiting.

" + "

Setting limits too low may get you disconnected" + " from the server!

"), + tr("Your Quassel core does not support this feature"), + tr("You need a Quassel core v0.13.0 or newer in order to " + "modify message rate limits."))); } #ifdef HAVE_SSL @@ -202,7 +189,7 @@ void NetworksSettingsPage::load() // Reset network capability status in case no valid networks get selected (a rare situation) resetNetworkCapStates(); - foreach(NetworkId netid, Client::networkIds()) { + foreach (NetworkId netid, Client::networkIds()) { clientNetworkAdded(netid); } ui.networkList->setCurrentRow(0); @@ -210,7 +197,6 @@ void NetworksSettingsPage::load() setChangedState(false); } - void NetworksSettingsPage::reset() { currentId = 0; @@ -218,45 +204,50 @@ void NetworksSettingsPage::reset() networkInfos.clear(); } - bool NetworksSettingsPage::aboutToSave() { - if (currentId != 0) saveToNetworkInfo(networkInfos[currentId]); + if (currentId != 0) + saveToNetworkInfo(networkInfos[currentId]); QList errors; - foreach(NetworkInfo info, networkInfos.values()) { - if (!info.serverList.count()) errors.append(1); + foreach (NetworkInfo info, networkInfos.values()) { + if (!info.serverList.count()) + errors.append(1); } - if (!errors.count()) return true; + if (!errors.count()) + return true; QString error(tr("The following problems need to be corrected before your changes can be applied:
    ")); - if (errors.contains(1)) error += tr("
  • All networks need at least one server defined
  • "); + if (errors.contains(1)) + error += tr("
  • All networks need at least one server defined
  • "); error += tr("
"); QMessageBox::warning(this, tr("Invalid Network Settings"), error); return false; } - void NetworksSettingsPage::widgetHasChanged() { - if (_ignoreWidgetChanges) return; + if (_ignoreWidgetChanges) + return; bool changed = testHasChanged(); - if (changed != hasChanged()) setChangedState(changed); + if (changed != hasChanged()) + setChangedState(changed); } - bool NetworksSettingsPage::testHasChanged() { if (currentId != 0) { saveToNetworkInfo(networkInfos[currentId]); } - if (Client::networkIds().count() != networkInfos.count()) return true; - foreach(NetworkId id, networkInfos.keys()) { - if (id < 0) return true; - if (Client::network(id)->networkInfo() != networkInfos[id]) return true; + if (Client::networkIds().count() != networkInfos.count()) + return true; + foreach (NetworkId id, networkInfos.keys()) { + if (id < 0) + return true; + if (Client::network(id)->networkInfo() != networkInfos[id]) + return true; } return false; } - void NetworksSettingsPage::setWidgetStates() { // network list @@ -287,7 +278,7 @@ void NetworksSettingsPage::setWidgetStates() else { ui.renameNetwork->setEnabled(false); ui.deleteNetwork->setEnabled(false); - //ui.connectNow->setEnabled(false); + // ui.connectNow->setEnabled(false); ui.detailsBox->setEnabled(false); } // network details @@ -305,13 +296,15 @@ void NetworksSettingsPage::setWidgetStates() } } - -void NetworksSettingsPage::setItemState(NetworkId id, QListWidgetItem *item) +void NetworksSettingsPage::setItemState(NetworkId id, QListWidgetItem* item) { - if (!item && !(item = networkItem(id))) return; - const Network *net = Client::network(id); - if (!net || net->isInitialized()) item->setFlags(item->flags() | Qt::ItemIsEnabled); - else item->setFlags(item->flags() & ~Qt::ItemIsEnabled); + if (!item && !(item = networkItem(id))) + return; + const Network* net = Client::network(id); + if (!net || net->isInitialized()) + item->setFlags(item->flags() | Qt::ItemIsEnabled); + else + item->setFlags(item->flags() & ~Qt::ItemIsEnabled); if (net && net->connectionState() == Network::Initialized) { item->setIcon(connectedIcon); } @@ -324,11 +317,12 @@ void NetworksSettingsPage::setItemState(NetworkId id, QListWidgetItem *item) if (net) { bool select = false; // check if we already have another net of this name in the list, and replace it - QList items = ui.networkList->findItems(net->networkName(), Qt::MatchExactly); + QList items = ui.networkList->findItems(net->networkName(), Qt::MatchExactly); if (items.count()) { - foreach(QListWidgetItem *i, items) { + foreach (QListWidgetItem* i, items) { NetworkId oldid = i->data(Qt::UserRole).value(); - if (oldid > 0) continue; // only locally created nets should be replaced + if (oldid > 0) + continue; // only locally created nets should be replaced if (oldid == currentId) { select = true; currentId = 0; @@ -336,7 +330,7 @@ void NetworksSettingsPage::setItemState(NetworkId id, QListWidgetItem *item) } int row = ui.networkList->row(i); if (row >= 0) { - QListWidgetItem *olditem = ui.networkList->takeItem(row); + QListWidgetItem* olditem = ui.networkList->takeItem(row); Q_ASSERT(olditem); delete olditem; } @@ -345,21 +339,20 @@ void NetworksSettingsPage::setItemState(NetworkId id, QListWidgetItem *item) } } item->setText(net->networkName()); - if (select) item->setSelected(true); + if (select) + item->setSelected(true); } } - void NetworksSettingsPage::resetNetworkCapStates() { // Set the status to a blank (invalid) network ID, reseting all UI setNetworkCapStates(NetworkId()); } - void NetworksSettingsPage::setNetworkCapStates(NetworkId id) { - const Network *net = Client::network(id); + const Network* net = Client::network(id); if (net && Client::isCoreFeatureEnabled(Quassel::Feature::CapNegotiation)) { // Capability negotiation is supported, network exists. // Check if the network is connected. Don't use net->isConnected() as that won't be true @@ -369,19 +362,22 @@ void NetworksSettingsPage::setNetworkCapStates(NetworkId id) // [SASL] if (net->saslMaybeSupports(IrcCap::SaslMech::PLAIN)) { setSASLStatus(CapSupportStatus::MaybeSupported); - } else { + } + else { setSASLStatus(CapSupportStatus::MaybeUnsupported); } // Add additional capability-dependent interface updates here - } else { + } + else { // Network is disconnected // [SASL] setSASLStatus(CapSupportStatus::Disconnected); // Add additional capability-dependent interface updates here } - } else { + } + else { // Capability negotiation is not supported and/or network doesn't exist. // Don't assume anything and reset all capability-dependent interface elements to neutral. // [SASL] @@ -391,7 +387,6 @@ void NetworksSettingsPage::setNetworkCapStates(NetworkId id) } } - void NetworksSettingsPage::coreConnectionStateChanged(bool state) { this->setEnabled(state); @@ -400,14 +395,13 @@ void NetworksSettingsPage::coreConnectionStateChanged(bool state) } else { // reset - //currentId = 0; + // currentId = 0; } } - void NetworksSettingsPage::clientIdentityAdded(IdentityId id) { - const Identity *identity = Client::identity(id); + const Identity* identity = Client::identity(id); connect(identity, &SyncableObject::updatedRemotely, this, &NetworksSettingsPage::clientIdentityUpdated); QString name = identity->identityName(); @@ -423,10 +417,9 @@ void NetworksSettingsPage::clientIdentityAdded(IdentityId id) widgetHasChanged(); } - void NetworksSettingsPage::clientIdentityUpdated() { - const auto *identity = qobject_cast(sender()); + const auto* identity = qobject_cast(sender()); if (!identity) { qWarning() << "NetworksSettingsPage: Invalid identity to update!"; return; @@ -441,39 +434,39 @@ void NetworksSettingsPage::clientIdentityUpdated() } } - void NetworksSettingsPage::clientIdentityRemoved(IdentityId id) { IdentityId defaultId = defaultIdentity(); - if (currentId != 0) saveToNetworkInfo(networkInfos[currentId]); - foreach(NetworkInfo info, networkInfos.values()) { + if (currentId != 0) + saveToNetworkInfo(networkInfos[currentId]); + foreach (NetworkInfo info, networkInfos.values()) { if (info.identity == id) { if (info.networkId == currentId) ui.identityList->setCurrentIndex(0); info.identity = defaultId; networkInfos[info.networkId] = info; - if (info.networkId > 0) Client::updateNetwork(info); + if (info.networkId > 0) + Client::updateNetwork(info); } } ui.identityList->removeItem(ui.identityList->findData(id.toInt())); widgetHasChanged(); } - -QListWidgetItem *NetworksSettingsPage::networkItem(NetworkId id) const +QListWidgetItem* NetworksSettingsPage::networkItem(NetworkId id) const { for (int i = 0; i < ui.networkList->count(); i++) { - QListWidgetItem *item = ui.networkList->item(i); - if (item->data(Qt::UserRole).value() == id) return item; + QListWidgetItem* item = ui.networkList->item(i); + if (item->data(Qt::UserRole).value() == id) + return item; } return nullptr; } - void NetworksSettingsPage::clientNetworkAdded(NetworkId id) { insertNetwork(id); - //connect(Client::network(id), &Network::updatedRemotely, this, &NetworksSettingsPage::clientNetworkUpdated); + // connect(Client::network(id), &Network::updatedRemotely, this, &NetworksSettingsPage::clientNetworkUpdated); connect(Client::network(id), &Network::configChanged, this, &NetworksSettingsPage::clientNetworkUpdated); connect(Client::network(id), &Network::connectionStateSet, this, &NetworksSettingsPage::networkConnectionStateChanged); @@ -484,29 +477,30 @@ void NetworksSettingsPage::clientNetworkAdded(NetworkId id) connect(Client::network(id), &Network::capRemoved, this, &NetworksSettingsPage::clientNetworkCapsUpdated); } - void NetworksSettingsPage::clientNetworkUpdated() { - const auto *net = qobject_cast(sender()); + const auto* net = qobject_cast(sender()); if (!net) { qWarning() << "Update request for unknown network received!"; return; } networkInfos[net->networkId()] = net->networkInfo(); setItemState(net->networkId()); - if (net->networkId() == currentId) displayNetwork(net->networkId()); + if (net->networkId() == currentId) + displayNetwork(net->networkId()); setWidgetStates(); widgetHasChanged(); } - void NetworksSettingsPage::clientNetworkRemoved(NetworkId id) { - if (!networkInfos.contains(id)) return; - if (id == currentId) displayNetwork(0); + if (!networkInfos.contains(id)) + return; + if (id == currentId) + displayNetwork(0); NetworkInfo info = networkInfos.take(id); - QList items = ui.networkList->findItems(info.networkName, Qt::MatchExactly); - foreach(QListWidgetItem *item, items) { + QList items = ui.networkList->findItems(info.networkName, Qt::MatchExactly); + foreach (QListWidgetItem* item, items) { if (item->data(Qt::UserRole).value() == id) delete ui.networkList->takeItem(ui.networkList->row(item)); } @@ -514,12 +508,12 @@ void NetworksSettingsPage::clientNetworkRemoved(NetworkId id) widgetHasChanged(); } - void NetworksSettingsPage::networkConnectionStateChanged(Network::ConnectionState state) { Q_UNUSED(state); - const auto *net = qobject_cast(sender()); - if (!net) return; + const auto* net = qobject_cast(sender()); + if (!net) + return; /* if(net->networkId() == currentId) { ui.connectNow->setEnabled(state == Network::Initialized || state == Network::Disconnected); @@ -534,33 +528,33 @@ void NetworksSettingsPage::networkConnectionStateChanged(Network::ConnectionStat setWidgetStates(); } +void NetworksSettingsPage::networkConnectionError(const QString&) {} -void NetworksSettingsPage::networkConnectionError(const QString &) -{ -} - - -QListWidgetItem *NetworksSettingsPage::insertNetwork(NetworkId id) +QListWidgetItem* NetworksSettingsPage::insertNetwork(NetworkId id) { NetworkInfo info = Client::network(id)->networkInfo(); networkInfos[id] = info; return insertNetwork(info); } - -QListWidgetItem *NetworksSettingsPage::insertNetwork(const NetworkInfo &info) +QListWidgetItem* NetworksSettingsPage::insertNetwork(const NetworkInfo& info) { - QListWidgetItem *item = nullptr; - QList items = ui.networkList->findItems(info.networkName, Qt::MatchExactly); - if (!items.count()) item = new QListWidgetItem(disconnectedIcon, info.networkName, ui.networkList); + QListWidgetItem* item = nullptr; + QList items = ui.networkList->findItems(info.networkName, Qt::MatchExactly); + if (!items.count()) + item = new QListWidgetItem(disconnectedIcon, info.networkName, ui.networkList); else { // we overwrite an existing net if it a) has the same name and b) has a negative ID meaning we created it locally before // -> then we can be sure that this is the core-side replacement for the net we created - foreach(QListWidgetItem *i, items) { + foreach (QListWidgetItem* i, items) { NetworkId id = i->data(Qt::UserRole).value(); - if (id < 0) { item = i; break; } + if (id < 0) { + item = i; + break; + } } - if (!item) item = new QListWidgetItem(disconnectedIcon, info.networkName, ui.networkList); + if (!item) + item = new QListWidgetItem(disconnectedIcon, info.networkName, ui.networkList); } item->setData(Qt::UserRole, QVariant::fromValue(info.networkId)); setItemState(info.networkId, item); @@ -568,15 +562,13 @@ QListWidgetItem *NetworksSettingsPage::insertNetwork(const NetworkInfo &info) return item; } - // Called when selecting 'Configure' from the buffer list void NetworksSettingsPage::bufferList_Open(NetworkId netId) { - QListWidgetItem *item = networkItem(netId); + QListWidgetItem* item = networkItem(netId); ui.networkList->setCurrentItem(item, QItemSelectionModel::SelectCurrent); } - void NetworksSettingsPage::displayNetwork(NetworkId id) { _ignoreWidgetChanges = true; @@ -598,14 +590,14 @@ void NetworksSettingsPage::displayNetwork(NetworkId id) ui.identityList->setCurrentIndex(ui.identityList->findData(info.identity.toInt())); ui.serverList->clear(); - foreach(Network::Server server, info.serverList) { - QListWidgetItem *item = new QListWidgetItem(QString("%1:%2").arg(server.host).arg(server.port)); + foreach (Network::Server server, info.serverList) { + QListWidgetItem* item = new QListWidgetItem(QString("%1:%2").arg(server.host).arg(server.port)); if (server.useSsl) item->setIcon(icon::get("document-encrypt")); ui.serverList->addItem(item); } - //setItemState(id); - //ui.randomServer->setChecked(info.useRandomServer); + // setItemState(id); + // ui.randomServer->setChecked(info.useRandomServer); // Update the capability-dependent UI in case capabilities have changed. setNetworkCapStates(id); ui.performEdit->setPlainText(info.perform.join("\n")); @@ -662,11 +654,10 @@ void NetworksSettingsPage::displayNetwork(NetworkId id) currentId = id; } - -void NetworksSettingsPage::saveToNetworkInfo(NetworkInfo &info) +void NetworksSettingsPage::saveToNetworkInfo(NetworkInfo& info) { info.identity = ui.identityList->itemData(ui.identityList->currentIndex()).toInt(); - //info.useRandomServer = ui.randomServer->isChecked(); + // info.useRandomServer = ui.randomServer->isChecked(); info.perform = ui.performEdit->toPlainText().split("\n"); info.useAutoIdentify = ui.autoIdentify->isChecked(); info.autoIdentifyService = ui.autoIdentifyService->text(); @@ -697,11 +688,10 @@ void NetworksSettingsPage::saveToNetworkInfo(NetworkInfo &info) info.unlimitedMessageRate = ui.unlimitedMessageRate->isChecked(); } - void NetworksSettingsPage::clientNetworkCapsUpdated() { // Grab the updated network - const auto *net = qobject_cast(sender()); + const auto* net = qobject_cast(sender()); if (!net) { qWarning() << "Update request for unknown network received!"; return; @@ -713,7 +703,6 @@ void NetworksSettingsPage::clientNetworkCapsUpdated() } } - void NetworksSettingsPage::setSASLStatus(const CapSupportStatus saslStatus) { if (_saslStatusSelected != saslStatus) { @@ -722,43 +711,40 @@ void NetworksSettingsPage::setSASLStatus(const CapSupportStatus saslStatus) // Update the user interface switch (saslStatus) { - case CapSupportStatus::Unknown: - // There's no capability negotiation or network doesn't exist. Don't assume - // anything. - ui.saslStatusLabel->setText(QString("%1").arg( - tr("Could not check if supported by network"))); - ui.saslStatusIcon->setPixmap(infoIcon.pixmap(16)); - break; - case CapSupportStatus::Disconnected: - // Disconnected from network, no way to check. - ui.saslStatusLabel->setText(QString("%1").arg( - tr("Cannot check if supported when disconnected"))); - ui.saslStatusIcon->setPixmap(infoIcon.pixmap(16)); - break; - case CapSupportStatus::MaybeUnsupported: - // The network doesn't advertise support for SASL PLAIN. Here be dragons. - ui.saslStatusLabel->setText(QString("%1").arg( - tr("Not currently supported by network"))); - ui.saslStatusIcon->setPixmap(warningIcon.pixmap(16)); - break; - case CapSupportStatus::MaybeSupported: - // The network advertises support for SASL PLAIN. Encourage using it! - // Unfortunately we don't know for sure if it's desired or functional. - ui.saslStatusLabel->setText(QString("%1").arg(tr("Supported by network"))); - ui.saslStatusIcon->setPixmap(infoIcon.pixmap(16)); - break; + case CapSupportStatus::Unknown: + // There's no capability negotiation or network doesn't exist. Don't assume + // anything. + ui.saslStatusLabel->setText(QString("%1").arg(tr("Could not check if supported by network"))); + ui.saslStatusIcon->setPixmap(infoIcon.pixmap(16)); + break; + case CapSupportStatus::Disconnected: + // Disconnected from network, no way to check. + ui.saslStatusLabel->setText(QString("%1").arg(tr("Cannot check if supported when disconnected"))); + ui.saslStatusIcon->setPixmap(infoIcon.pixmap(16)); + break; + case CapSupportStatus::MaybeUnsupported: + // The network doesn't advertise support for SASL PLAIN. Here be dragons. + ui.saslStatusLabel->setText(QString("%1").arg(tr("Not currently supported by network"))); + ui.saslStatusIcon->setPixmap(warningIcon.pixmap(16)); + break; + case CapSupportStatus::MaybeSupported: + // The network advertises support for SASL PLAIN. Encourage using it! + // Unfortunately we don't know for sure if it's desired or functional. + ui.saslStatusLabel->setText(QString("%1").arg(tr("Supported by network"))); + ui.saslStatusIcon->setPixmap(infoIcon.pixmap(16)); + break; } } } - #ifdef HAVE_SSL void NetworksSettingsPage::sslUpdated() { if (_cid && !_cid->sslKey().isNull()) { ui.saslContents->setDisabled(true); ui.saslExtInfo->setHidden(false); - } else { + } + else { ui.saslContents->setDisabled(false); // Directly re-enabling causes the widgets to ignore the parent "Use SASL Authentication" // state to indicate whether or not it's disabled. To workaround this, keep track of @@ -776,7 +762,6 @@ void NetworksSettingsPage::sslUpdated() } #endif - /*** Network list ***/ void NetworksSettingsPage::on_networkList_itemSelectionChanged() @@ -796,11 +781,11 @@ void NetworksSettingsPage::on_networkList_itemSelectionChanged() setWidgetStates(); } - void NetworksSettingsPage::on_addNetwork_clicked() { QStringList existing; - for (int i = 0; i < ui.networkList->count(); i++) existing << ui.networkList->item(i)->text(); + for (int i = 0; i < ui.networkList->count(); i++) + existing << ui.networkList->item(i)->text(); NetworkAddDlg dlg(existing, this); if (dlg.exec() == QDialog::Accepted) { NetworkInfo info = dlg.networkInfo(); @@ -810,44 +795,49 @@ void NetworksSettingsPage::on_addNetwork_clicked() NetworkId id; for (id = 1; id <= networkInfos.count(); id++) { widgetHasChanged(); - if (!networkInfos.keys().contains(-id.toInt())) break; + if (!networkInfos.keys().contains(-id.toInt())) + break; } id = -id.toInt(); info.networkId = id; info.identity = defaultIdentity(); networkInfos[id] = info; - QListWidgetItem *item = insertNetwork(info); + QListWidgetItem* item = insertNetwork(info); ui.networkList->setCurrentItem(item); setWidgetStates(); } } - void NetworksSettingsPage::on_deleteNetwork_clicked() { if (ui.networkList->selectedItems().count()) { NetworkId netid = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value(); - int ret = QMessageBox::question(this, tr("Delete Network?"), - tr("Do you really want to delete the network \"%1\" and all related settings, including the backlog?").arg(networkInfos[netid].networkName), - QMessageBox::Yes|QMessageBox::No, QMessageBox::No); + int ret + = QMessageBox::question(this, + tr("Delete Network?"), + tr("Do you really want to delete the network \"%1\" and all related settings, including the backlog?") + .arg(networkInfos[netid].networkName), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::No); if (ret == QMessageBox::Yes) { currentId = 0; networkInfos.remove(netid); delete ui.networkList->takeItem(ui.networkList->row(ui.networkList->selectedItems()[0])); - ui.networkList->setCurrentRow(qMin(ui.networkList->currentRow()+1, ui.networkList->count()-1)); + ui.networkList->setCurrentRow(qMin(ui.networkList->currentRow() + 1, ui.networkList->count() - 1)); setWidgetStates(); widgetHasChanged(); } } } - void NetworksSettingsPage::on_renameNetwork_clicked() { - if (!ui.networkList->selectedItems().count()) return; + if (!ui.networkList->selectedItems().count()) + return; QString old = ui.networkList->selectedItems()[0]->text(); QStringList existing; - for (int i = 0; i < ui.networkList->count(); i++) existing << ui.networkList->item(i)->text(); + for (int i = 0; i < ui.networkList->count(); i++) + existing << ui.networkList->item(i)->text(); NetworkEditDlg dlg(old, existing, this); if (dlg.exec() == QDialog::Accepted) { ui.networkList->selectedItems()[0]->setText(dlg.networkName()); @@ -857,7 +847,6 @@ void NetworksSettingsPage::on_renameNetwork_clicked() } } - /* void NetworksSettingsPage::on_connectNow_clicked() { if(!ui.networkList->selectedItems().count()) return; @@ -876,23 +865,23 @@ void NetworksSettingsPage::on_serverList_itemSelectionChanged() setWidgetStates(); } - void NetworksSettingsPage::on_addServer_clicked() { - if (currentId == 0) return; + if (currentId == 0) + return; ServerEditDlg dlg(Network::Server(), this); if (dlg.exec() == QDialog::Accepted) { networkInfos[currentId].serverList.append(dlg.serverData()); displayNetwork(currentId); - ui.serverList->setCurrentRow(ui.serverList->count()-1); + ui.serverList->setCurrentRow(ui.serverList->count() - 1); widgetHasChanged(); } } - void NetworksSettingsPage::on_editServer_clicked() { - if (currentId == 0) return; + if (currentId == 0) + return; int cur = ui.serverList->currentRow(); ServerEditDlg dlg(networkInfos[currentId].serverList[cur], this); if (dlg.exec() == QDialog::Accepted) { @@ -903,52 +892,48 @@ void NetworksSettingsPage::on_editServer_clicked() } } - void NetworksSettingsPage::on_deleteServer_clicked() { - if (currentId == 0) return; + if (currentId == 0) + return; int cur = ui.serverList->currentRow(); networkInfos[currentId].serverList.removeAt(cur); displayNetwork(currentId); - ui.serverList->setCurrentRow(qMin(cur, ui.serverList->count()-1)); + ui.serverList->setCurrentRow(qMin(cur, ui.serverList->count() - 1)); widgetHasChanged(); } - void NetworksSettingsPage::on_upServer_clicked() { int cur = ui.serverList->currentRow(); Network::Server server = networkInfos[currentId].serverList.takeAt(cur); - networkInfos[currentId].serverList.insert(cur-1, server); + networkInfos[currentId].serverList.insert(cur - 1, server); displayNetwork(currentId); - ui.serverList->setCurrentRow(cur-1); + ui.serverList->setCurrentRow(cur - 1); widgetHasChanged(); } - void NetworksSettingsPage::on_downServer_clicked() { int cur = ui.serverList->currentRow(); Network::Server server = networkInfos[currentId].serverList.takeAt(cur); - networkInfos[currentId].serverList.insert(cur+1, server); + networkInfos[currentId].serverList.insert(cur + 1, server); displayNetwork(currentId); - ui.serverList->setCurrentRow(cur+1); + ui.serverList->setCurrentRow(cur + 1); widgetHasChanged(); } - void NetworksSettingsPage::on_editIdentities_clicked() { SettingsPageDlg dlg(new IdentitiesSettingsPage(this), this); dlg.exec(); } - void NetworksSettingsPage::on_saslStatusDetails_clicked() { if (ui.networkList->selectedItems().count()) { NetworkId netid = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value(); - QString &netName = networkInfos[netid].networkName; + QString& netName = networkInfos[netid].networkName; // If these strings are visible, one of the status messages wasn't detected below. QString saslStatusHeader = "[header unintentionally left blank]"; @@ -963,65 +948,68 @@ void NetworksSettingsPage::on_saslStatusDetails_clicked() saslStatusHeader = tr("Could not check if SASL supported by network"); saslStatusExplanation = tr("Quassel could not check if \"%1\" supports SASL. This may " "be due to unsaved changes or an older Quassel core. You " - "can still try using SASL.").arg(netName); + "can still try using SASL.") + .arg(netName); break; case CapSupportStatus::Disconnected: saslStatusHeader = tr("Cannot check if SASL supported when disconnected"); saslStatusExplanation = tr("Quassel cannot check if \"%1\" supports SASL when " "disconnected. Connect to the network, or try using SASL " - "anyways.").arg(netName); + "anyways.") + .arg(netName); break; case CapSupportStatus::MaybeUnsupported: saslStatusHeader = tr("SASL not currently supported by network"); saslStatusExplanation = tr("The network \"%1\" does not currently support SASL. " - "However, support might be added later on.").arg(netName); + "However, support might be added later on.") + .arg(netName); useWarningIcon = true; break; case CapSupportStatus::MaybeSupported: saslStatusHeader = tr("SASL supported by network"); saslStatusExplanation = tr("The network \"%1\" supports SASL. In most cases, you " - "should use SASL instead of NickServ identification." - ).arg(netName); + "should use SASL instead of NickServ identification.") + .arg(netName); break; } // Process this in advance for reusability below const QString saslStatusMsgTitle = tr("SASL support for \"%1\"").arg(netName); - const QString saslStatusMsgText = - QString("

%1


%2


%3

" - ).arg(saslStatusHeader, - saslStatusExplanation, - tr("SASL is a standardized way to log in and identify yourself to " - "IRC servers.")); + const QString saslStatusMsgText = QString("

%1


%2


%3

") + .arg(saslStatusHeader, + saslStatusExplanation, + tr("SASL is a standardized way to log in and identify yourself to " + "IRC servers.")); if (useWarningIcon) { // Show as a warning dialog box QMessageBox::warning(this, saslStatusMsgTitle, saslStatusMsgText); - } else { + } + else { // Show as an information dialog box QMessageBox::information(this, saslStatusMsgTitle, saslStatusMsgText); } } } - IdentityId NetworksSettingsPage::defaultIdentity() const { IdentityId defaultId = 0; QList ids = Client::identityIds(); - foreach(IdentityId id, ids) { + foreach (IdentityId id, ids) { if (defaultId == 0 || id < defaultId) defaultId = id; } return defaultId; } - /************************************************************************** -* NetworkAddDlg -*************************************************************************/ + * NetworkAddDlg + *************************************************************************/ -NetworkAddDlg::NetworkAddDlg(QStringList exist, QWidget *parent) : QDialog(parent), existing(std::move(exist)) +NetworkAddDlg::NetworkAddDlg(QStringList exist, QWidget* parent) + : QDialog(parent) + , existing(std::move(exist)) { ui.setupUi(this); ui.useSSL->setIcon(icon::get("document-encrypt")); @@ -1035,7 +1023,8 @@ NetworkAddDlg::NetworkAddDlg(QStringList exist, QWidget *parent) : QDialog(paren // Synchronize requiring SSL with the use SSL checkbox ui.sslVerify->setEnabled(ui.useSSL->isChecked()); connect(ui.useSSL, &QAbstractButton::toggled, ui.sslVerify, &QWidget::setEnabled); - } else { + } + else { // Core isn't new enough to allow requiring SSL; disable checkbox and uncheck ui.sslVerify->setEnabled(false); ui.sslVerify->setChecked(false); @@ -1043,17 +1032,17 @@ NetworkAddDlg::NetworkAddDlg(QStringList exist, QWidget *parent) : QDialog(paren // [Original tool-tip] // [Bold 'does not support feature' message] // [Specific version needed and feature details] - ui.sslVerify->setToolTip(QString("%1
%2
%3").arg( - ui.sslVerify->toolTip(), - tr("Your Quassel core does not support this feature"), - tr("You need a Quassel core v0.13.0 or newer in order to " - "verify connection security."))); + ui.sslVerify->setToolTip(QString("%1
%2
%3") + .arg(ui.sslVerify->toolTip(), + tr("Your Quassel core does not support this feature"), + tr("You need a Quassel core v0.13.0 or newer in order to " + "verify connection security."))); } // read preset networks QStringList networks = PresetNetworks::names(); - foreach(QString s, existing) - networks.removeAll(s); + foreach (QString s, existing) + networks.removeAll(s); if (networks.count()) ui.presetList->addItems(networks); else { @@ -1067,14 +1056,15 @@ NetworkAddDlg::NetworkAddDlg(QStringList exist, QWidget *parent) : QDialog(paren setButtonStates(); } - NetworkInfo NetworkAddDlg::networkInfo() const { if (ui.useManual->isChecked()) { NetworkInfo info; info.networkName = ui.networkName->text().trimmed(); - info.serverList << Network::Server(ui.serverAddress->text().trimmed(), ui.port->value(), - ui.serverPassword->text(), ui.useSSL->isChecked(), + info.serverList << Network::Server(ui.serverAddress->text().trimmed(), + ui.port->value(), + ui.serverPassword->text(), + ui.useSSL->isChecked(), ui.sslVerify->isChecked()); return info; } @@ -1082,7 +1072,6 @@ NetworkInfo NetworkAddDlg::networkInfo() const return PresetNetworks::networkInfo(ui.presetList->currentText()); } - void NetworkAddDlg::setButtonStates() { bool ok = false; @@ -1095,53 +1084,53 @@ void NetworkAddDlg::setButtonStates() ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ok); } - void NetworkAddDlg::updateSslPort(bool isChecked) { // "Use encrypted connection" was toggled, check the state... if (isChecked && ui.port->value() == Network::PORT_PLAINTEXT) { // Had been using the plain-text port, use the SSL default ui.port->setValue(Network::PORT_SSL); - } else if (!isChecked && ui.port->value() == Network::PORT_SSL) { + } + else if (!isChecked && ui.port->value() == Network::PORT_SSL) { // Had been using the SSL port, use the plain-text default ui.port->setValue(Network::PORT_PLAINTEXT); } } - /************************************************************************** * NetworkEditDlg *************************************************************************/ -NetworkEditDlg::NetworkEditDlg(const QString &old, QStringList exist, QWidget *parent) : QDialog(parent), existing(std::move(exist)) +NetworkEditDlg::NetworkEditDlg(const QString& old, QStringList exist, QWidget* parent) + : QDialog(parent) + , existing(std::move(exist)) { ui.setupUi(this); if (old.isEmpty()) { // new network setWindowTitle(tr("Add Network")); - on_networkEdit_textChanged(""); // disable ok button + on_networkEdit_textChanged(""); // disable ok button } - else ui.networkEdit->setText(old); + else + ui.networkEdit->setText(old); } - QString NetworkEditDlg::networkName() const { return ui.networkEdit->text().trimmed(); } - -void NetworkEditDlg::on_networkEdit_textChanged(const QString &text) +void NetworkEditDlg::on_networkEdit_textChanged(const QString& text) { ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(text.isEmpty() || existing.contains(text.trimmed())); } - /************************************************************************** * ServerEditDlg *************************************************************************/ -ServerEditDlg::ServerEditDlg(const Network::Server &server, QWidget *parent) : QDialog(parent) +ServerEditDlg::ServerEditDlg(const Network::Server& server, QWidget* parent) + : QDialog(parent) { ui.setupUi(this); ui.useSSL->setIcon(icon::get("document-encrypt")); @@ -1184,7 +1173,8 @@ ServerEditDlg::ServerEditDlg(const Network::Server &server, QWidget *parent) : Q // Synchronize requiring SSL with the use SSL checkbox ui.sslVerify->setEnabled(ui.useSSL->isChecked()); connect(ui.useSSL, &QAbstractButton::toggled, ui.sslVerify, &QWidget::setEnabled); - } else { + } + else { // Core isn't new enough to allow requiring SSL; disable checkbox and uncheck ui.sslVerify->setEnabled(false); ui.sslVerify->setChecked(false); @@ -1192,21 +1182,19 @@ ServerEditDlg::ServerEditDlg(const Network::Server &server, QWidget *parent) : Q // [Original tool-tip] // [Bold 'does not support feature' message] // [Specific version needed and feature details] - ui.sslVerify->setToolTip(QString("%1
%2
%3").arg( - ui.sslVerify->toolTip(), - tr("Your Quassel core does not support this feature"), - tr("You need a Quassel core v0.13.0 or newer in order to " - "verify connection security."))); + ui.sslVerify->setToolTip(QString("%1
%2
%3") + .arg(ui.sslVerify->toolTip(), + tr("Your Quassel core does not support this feature"), + tr("You need a Quassel core v0.13.0 or newer in order to " + "verify connection security."))); } on_host_textChanged(); } - Network::Server ServerEditDlg::serverData() const { - Network::Server server(ui.host->text().trimmed(), ui.port->value(), ui.password->text(), - ui.useSSL->isChecked(), ui.sslVerify->isChecked()); + Network::Server server(ui.host->text().trimmed(), ui.port->value(), ui.password->text(), ui.useSSL->isChecked(), ui.sslVerify->isChecked()); server.sslVersion = ui.sslVersion->currentIndex(); server.useProxy = ui.useProxy->isChecked(); server.proxyType = ui.proxyType->currentIndex() == 0 ? QNetworkProxy::Socks5Proxy : QNetworkProxy::HttpProxy; @@ -1217,31 +1205,33 @@ Network::Server ServerEditDlg::serverData() const return server; } - void ServerEditDlg::on_host_textChanged() { ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(ui.host->text().trimmed().isEmpty()); } - void ServerEditDlg::updateSslPort(bool isChecked) { // "Use encrypted connection" was toggled, check the state... if (isChecked && ui.port->value() == Network::PORT_PLAINTEXT) { // Had been using the plain-text port, use the SSL default ui.port->setValue(Network::PORT_SSL); - } else if (!isChecked && ui.port->value() == Network::PORT_SSL) { + } + else if (!isChecked && ui.port->value() == Network::PORT_SSL) { // Had been using the SSL port, use the plain-text default ui.port->setValue(Network::PORT_PLAINTEXT); } } - /************************************************************************** * SaveNetworksDlg *************************************************************************/ -SaveNetworksDlg::SaveNetworksDlg(const QList &toCreate, const QList &toUpdate, const QList &toRemove, QWidget *parent) : QDialog(parent) +SaveNetworksDlg::SaveNetworksDlg(const QList& toCreate, + const QList& toUpdate, + const QList& toRemove, + QWidget* parent) + : QDialog(parent) { ui.setupUi(this); @@ -1254,14 +1244,14 @@ SaveNetworksDlg::SaveNetworksDlg(const QList &toCreate, const QList connect(Client::instance(), &Client::networkCreated, this, &SaveNetworksDlg::clientEvent); connect(Client::instance(), &Client::networkRemoved, this, &SaveNetworksDlg::clientEvent); - foreach(NetworkId id, toRemove) { + foreach (NetworkId id, toRemove) { Client::removeNetwork(id); } - foreach(NetworkInfo info, toCreate) { + foreach (NetworkInfo info, toCreate) { Client::createNetwork(info); } - foreach(NetworkInfo info, toUpdate) { - const Network *net = Client::network(info.networkId); + foreach (NetworkInfo info, toUpdate) { + const Network* net = Client::network(info.networkId); if (!net) { qWarning() << "Invalid client network!"; numevents--; @@ -1278,9 +1268,9 @@ SaveNetworksDlg::SaveNetworksDlg(const QList &toCreate, const QList } } - void SaveNetworksDlg::clientEvent() { ui.progressBar->setValue(++rcvevents); - if (rcvevents >= numevents) accept(); + if (rcvevents >= numevents) + accept(); }