X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fqtui%2Fsettingspages%2Fnetworkssettingspage.cpp;h=c1ee10a861dedf3a364ae2e7107f06a147e7ae70;hb=b40672ab5c48b577b31371c159e60d330fdd7ce5;hp=142f3d0c2314e96101df5441594ebe1e23ec5a93;hpb=9d54503555534a2c554f09a33df6afa33d6308ec;p=quassel.git diff --git a/src/qtui/settingspages/networkssettingspage.cpp b/src/qtui/settingspages/networkssettingspage.cpp index 142f3d0c..c1ee10a8 100644 --- a/src/qtui/settingspages/networkssettingspage.cpp +++ b/src/qtui/settingspages/networkssettingspage.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2014 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -25,12 +25,16 @@ #include "networkssettingspage.h" #include "client.h" -#include "iconloader.h" +#include "icon.h" #include "identity.h" #include "network.h" +#include "presetnetworks.h" #include "settingspagedlg.h" #include "util.h" +// IRCv3 capabilities +#include "irccap.h" + #include "settingspages/identitiessettingspage.h" NetworksSettingsPage::NetworksSettingsPage(QWidget *parent) @@ -42,30 +46,34 @@ NetworksSettingsPage::NetworksSettingsPage(QWidget *parent) ui.setupUi(this); // hide SASL options for older cores - if (!(Client::coreFeatures() & Quassel::SaslAuthentication)) + if (!Client::isCoreFeatureEnabled(Quassel::Feature::SaslAuthentication)) ui.sasl->hide(); - if (!(Client::coreFeatures() & Quassel::SaslExternal)) + if (!Client::isCoreFeatureEnabled(Quassel::Feature::SaslExternal)) ui.saslExtInfo->hide(); #ifndef HAVE_SSL ui.saslExtInfo->hide(); #endif // set up icons - ui.renameNetwork->setIcon(SmallIcon("edit-rename")); - ui.addNetwork->setIcon(SmallIcon("list-add")); - ui.deleteNetwork->setIcon(SmallIcon("edit-delete")); - ui.addServer->setIcon(SmallIcon("list-add")); - ui.deleteServer->setIcon(SmallIcon("edit-delete")); - ui.editServer->setIcon(SmallIcon("configure")); - ui.upServer->setIcon(SmallIcon("go-up")); - ui.downServer->setIcon(SmallIcon("go-down")); - ui.editIdentities->setIcon(SmallIcon("configure")); + ui.renameNetwork->setIcon(icon::get("edit-rename")); + ui.addNetwork->setIcon(icon::get("list-add")); + ui.deleteNetwork->setIcon(icon::get("edit-delete")); + ui.addServer->setIcon(icon::get("list-add")); + ui.deleteServer->setIcon(icon::get("edit-delete")); + ui.editServer->setIcon(icon::get("configure")); + ui.upServer->setIcon(icon::get("go-up")); + ui.downServer->setIcon(icon::get("go-down")); + ui.editIdentities->setIcon(icon::get("configure")); _ignoreWidgetChanges = false; - connectedIcon = SmallIcon("network-connect"); - connectingIcon = SmallIcon("network-wired"); // FIXME network-connecting - disconnectedIcon = SmallIcon("network-disconnect"); + connectedIcon = icon::get("network-connect"); + 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()) { QByteArray codec = QTextCodec::codecForMib(mib)->name(); @@ -88,12 +96,12 @@ NetworksSettingsPage::NetworksSettingsPage(QWidget *parent) connect(ui.identityList, SIGNAL(currentIndexChanged(int)), this, SLOT(widgetHasChanged())); //connect(ui.randomServer, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); connect(ui.performEdit, SIGNAL(textChanged()), this, SLOT(widgetHasChanged())); - connect(ui.autoIdentify, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); - connect(ui.autoIdentifyService, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged())); - connect(ui.autoIdentifyPassword, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged())); connect(ui.sasl, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); connect(ui.saslAccount, SIGNAL(textEdited(QString)), this, SLOT(widgetHasChanged())); connect(ui.saslPassword, SIGNAL(textEdited(QString)), this, SLOT(widgetHasChanged())); + connect(ui.autoIdentify, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); + connect(ui.autoIdentifyService, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged())); + connect(ui.autoIdentifyPassword, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged())); connect(ui.useCustomEncodings, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); connect(ui.sendEncoding, SIGNAL(currentIndexChanged(int)), this, SLOT(widgetHasChanged())); connect(ui.recvEncoding, SIGNAL(currentIndexChanged(int)), this, SLOT(widgetHasChanged())); @@ -103,6 +111,15 @@ NetworksSettingsPage::NetworksSettingsPage(QWidget *parent) connect(ui.reconnectRetries, SIGNAL(valueChanged(int)), this, SLOT(widgetHasChanged())); connect(ui.unlimitedRetries, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); connect(ui.rejoinOnReconnect, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); + + // Core features can change during a reconnect. Always connect these here, delaying testing for + // the core feature flag in load(). + connect(ui.useCustomMessageRate, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); + connect(ui.messageRateBurstSize, SIGNAL(valueChanged(int)), this, SLOT(widgetHasChanged())); + connect(ui.messageRateDelay, SIGNAL(valueChanged(double)), this, SLOT(widgetHasChanged())); + connect(ui.unlimitedMessageRate, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); + + // Add additional widgets here //connect(ui., SIGNAL(), this, SLOT(widgetHasChanged())); //connect(ui., SIGNAL(), this, SLOT(widgetHasChanged())); @@ -157,10 +174,47 @@ void NetworksSettingsPage::save() void NetworksSettingsPage::load() { reset(); + + // Handle UI dependent on core feature flags here + if (Client::isCoreFeatureEnabled(Quassel::Feature::CustomRateLimits)) { + // 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!
"))); + // If changed, update the message below! + } 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("%1Override 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 + // Hide the SASL EXTERNAL notice until a network's shown. Stops it from showing while loading + // backlog from the core. + sslUpdated(); +#endif + + // Reset network capability status in case no valid networks get selected (a rare situation) + resetNetworkCapStates(); + foreach(NetworkId netid, Client::networkIds()) { clientNetworkAdded(netid); } ui.networkList->setCurrentRow(0); + setChangedState(false); } @@ -304,6 +358,48 @@ void NetworksSettingsPage::setItemState(NetworkId id, QListWidgetItem *item) } +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); + 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 + // during capability negotiation when capabilities are added and removed. + if (net->connectionState() != Network::Disconnected) { + // Network exists and is connected, check available capabilities... + // [SASL] + if (net->saslMaybeSupports(IrcCap::SaslMech::PLAIN)) { + setSASLStatus(CapSupportStatus::MaybeSupported); + } else { + setSASLStatus(CapSupportStatus::MaybeUnsupported); + } + + // Add additional capability-dependent interface updates here + } else { + // Network is disconnected + // [SASL] + setSASLStatus(CapSupportStatus::Disconnected); + + // Add additional capability-dependent interface updates here + } + } 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] + setSASLStatus(CapSupportStatus::Unknown); + + // Add additional capability-dependent interface updates here + } +} + + void NetworksSettingsPage::coreConnectionStateChanged(bool state) { this->setEnabled(state); @@ -390,6 +486,10 @@ void NetworksSettingsPage::clientNetworkAdded(NetworkId id) connect(Client::network(id), SIGNAL(connectionStateSet(Network::ConnectionState)), this, SLOT(networkConnectionStateChanged(Network::ConnectionState))); connect(Client::network(id), SIGNAL(connectionError(const QString &)), this, SLOT(networkConnectionError(const QString &))); + + // Handle capability changes in case a server dis/connects with the settings window open. + connect(Client::network(id), SIGNAL(capAdded(const QString &)), this, SLOT(clientNetworkCapsUpdated())); + connect(Client::network(id), SIGNAL(capRemoved(const QString &)), this, SLOT(clientNetworkCapsUpdated())); } @@ -434,6 +534,11 @@ void NetworksSettingsPage::networkConnectionStateChanged(Network::ConnectionStat } */ setItemState(net->networkId()); + if (net->networkId() == currentId) { + // Network is currently shown. Update the capability-dependent UI in case capabilities have + // changed. + setNetworkCapStates(currentId); + } setWidgetStates(); } @@ -472,6 +577,14 @@ QListWidgetItem *NetworksSettingsPage::insertNetwork(const NetworkInfo &info) } +// Called when selecting 'Configure' from the buffer list +void NetworksSettingsPage::bufferList_Open(NetworkId netId) +{ + QListWidgetItem *item = networkItem(netId); + ui.networkList->setCurrentItem(item, QItemSelectionModel::SelectCurrent); +} + + void NetworksSettingsPage::displayNetwork(NetworkId id) { _ignoreWidgetChanges = true; @@ -480,7 +593,7 @@ void NetworksSettingsPage::displayNetwork(NetworkId id) #ifdef HAVE_SSL // this is only needed when the core supports SASL EXTERNAL - if (Client::coreFeatures() & Quassel::SaslExternal) { + if (Client::isCoreFeatureEnabled(Quassel::Feature::SaslExternal)) { if (_cid) { disconnect(_cid, SIGNAL(sslSettingsUpdated()), this, SLOT(sslUpdated())); delete _cid; @@ -496,11 +609,13 @@ void NetworksSettingsPage::displayNetwork(NetworkId id) foreach(Network::Server server, info.serverList) { QListWidgetItem *item = new QListWidgetItem(QString("%1:%2").arg(server.host).arg(server.port)); if (server.useSsl) - item->setIcon(SmallIcon("document-encrypt")); + item->setIcon(icon::get("document-encrypt")); ui.serverList->addItem(item); } //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")); ui.autoIdentify->setChecked(info.useAutoIdentify); ui.autoIdentifyService->setText(info.autoIdentifyService); @@ -525,6 +640,14 @@ void NetworksSettingsPage::displayNetwork(NetworkId id) ui.reconnectRetries->setValue(info.autoReconnectRetries); ui.unlimitedRetries->setChecked(info.unlimitedReconnectRetries); ui.rejoinOnReconnect->setChecked(info.rejoinChannels); + // Custom rate limiting + ui.unlimitedMessageRate->setChecked(info.unlimitedMessageRate); + // Set 'ui.useCustomMessageRate' after 'ui.unlimitedMessageRate' so if the latter is + // disabled, 'ui.messageRateDelayFrame' will remain disabled. + ui.useCustomMessageRate->setChecked(info.useCustomMessageRate); + ui.messageRateBurstSize->setValue(info.messageRateBurstSize); + // Convert milliseconds (integer) into seconds (double) + ui.messageRateDelay->setValue(info.messageRateDelay / 1000.0f); } else { // just clear widgets @@ -574,6 +697,66 @@ void NetworksSettingsPage::saveToNetworkInfo(NetworkInfo &info) info.autoReconnectRetries = ui.reconnectRetries->value(); info.unlimitedReconnectRetries = ui.unlimitedRetries->isChecked(); info.rejoinChannels = ui.rejoinOnReconnect->isChecked(); + // Custom rate limiting + info.useCustomMessageRate = ui.useCustomMessageRate->isChecked(); + info.messageRateBurstSize = ui.messageRateBurstSize->value(); + // Convert seconds (double) into milliseconds (integer) + info.messageRateDelay = static_cast%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 { + // Show as an information dialog box + QMessageBox::information(this, saslStatusMsgTitle, saslStatusMsgText); + } + } +} + + IdentityId NetworksSettingsPage::defaultIdentity() const { IdentityId defaultId = 0; @@ -783,10 +1032,34 @@ IdentityId NetworksSettingsPage::defaultIdentity() const NetworkAddDlg::NetworkAddDlg(const QStringList &exist, QWidget *parent) : QDialog(parent), existing(exist) { ui.setupUi(this); - ui.useSSL->setIcon(SmallIcon("document-encrypt")); + ui.useSSL->setIcon(icon::get("document-encrypt")); + + // Whenever useSSL is toggled, update the port number if not changed from the default + connect(ui.useSSL, SIGNAL(toggled(bool)), SLOT(updateSslPort(bool))); + // Do NOT call updateSslPort when loading settings, otherwise port settings may be overriden. + // If useSSL is later changed to be checked by default, change port's default value, too. + + if (Client::isCoreFeatureEnabled(Quassel::Feature::VerifyServerSSL)) { + // Synchronize requiring SSL with the use SSL checkbox + ui.sslVerify->setEnabled(ui.useSSL->isChecked()); + connect(ui.useSSL, SIGNAL(toggled(bool)), ui.sslVerify, SLOT(setEnabled(bool))); + } else { + // Core isn't new enough to allow requiring SSL; disable checkbox and uncheck + ui.sslVerify->setEnabled(false); + ui.sslVerify->setChecked(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.sslVerify->setToolTip(QString("%1