uisupport: Provide helpers for dealing with widget changes
[quassel.git] / src / qtui / settingspages / networkssettingspage.cpp
index 478acd1..a886d92 100644 (file)
@@ -21,6 +21,7 @@
 #include <QHeaderView>
 #include <QMessageBox>
 #include <QTextCodec>
+#include <utility>
 
 #include "networkssettingspage.h"
 
@@ -31,6 +32,7 @@
 #include "presetnetworks.h"
 #include "settingspagedlg.h"
 #include "util.h"
+#include "widgethelpers.h"
 
 // IRCv3 capabilities
 #include "irccap.h"
@@ -39,9 +41,6 @@
 
 NetworksSettingsPage::NetworksSettingsPage(QWidget *parent)
     : SettingsPage(tr("IRC"), tr("Networks"), parent)
-#ifdef HAVE_SSL
-      , _cid(nullptr)
-#endif
 {
     ui.setupUi(this);
 
@@ -65,8 +64,6 @@ NetworksSettingsPage::NetworksSettingsPage(QWidget *parent)
     ui.downServer->setIcon(icon::get("go-down"));
     ui.editIdentities->setIcon(icon::get("configure"));
 
-    _ignoreWidgetChanges = false;
-
     connectedIcon = icon::get("network-connect");
     connectingIcon = icon::get("network-wired"); // FIXME network-connecting
     disconnectedIcon = icon::get("network-disconnect");
@@ -87,41 +84,36 @@ NetworksSettingsPage::NetworksSettingsPage(QWidget *parent)
     currentId = 0;
     setEnabled(Client::isConnected()); // need a core connection!
     setWidgetStates();
-    connect(Client::instance(), SIGNAL(coreConnectionStateChanged(bool)), this, SLOT(coreConnectionStateChanged(bool)));
-    connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(clientNetworkAdded(NetworkId)));
-    connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), this, SLOT(clientNetworkRemoved(NetworkId)));
-    connect(Client::instance(), SIGNAL(identityCreated(IdentityId)), this, SLOT(clientIdentityAdded(IdentityId)));
-    connect(Client::instance(), SIGNAL(identityRemoved(IdentityId)), this, SLOT(clientIdentityRemoved(IdentityId)));
-
-    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.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()));
-    connect(ui.serverEncoding, SIGNAL(currentIndexChanged(int)), this, SLOT(widgetHasChanged()));
-    connect(ui.autoReconnect, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
-    connect(ui.reconnectInterval, SIGNAL(valueChanged(int)), this, SLOT(widgetHasChanged()));
-    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()));
+
+    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);
+    connect(Client::instance(), &Client::networkRemoved, this, &NetworksSettingsPage::clientNetworkRemoved);
+    connect(Client::instance(), &Client::identityCreated, this, &NetworksSettingsPage::clientIdentityAdded);
+    connect(Client::instance(), &Client::identityRemoved, this, &NetworksSettingsPage::clientIdentityRemoved);
 
     foreach(IdentityId id, Client::identityIds()) {
         clientIdentityAdded(id);
@@ -416,7 +408,7 @@ void NetworksSettingsPage::coreConnectionStateChanged(bool state)
 void NetworksSettingsPage::clientIdentityAdded(IdentityId id)
 {
     const Identity *identity = Client::identity(id);
-    connect(identity, SIGNAL(updatedRemotely()), this, SLOT(clientIdentityUpdated()));
+    connect(identity, &SyncableObject::updatedRemotely, this, &NetworksSettingsPage::clientIdentityUpdated);
 
     QString name = identity->identityName();
     for (int j = 0; j < ui.identityList->count(); j++) {
@@ -434,7 +426,7 @@ void NetworksSettingsPage::clientIdentityAdded(IdentityId id)
 
 void NetworksSettingsPage::clientIdentityUpdated()
 {
-    const Identity *identity = qobject_cast<const Identity *>(sender());
+    const auto *identity = qobject_cast<const Identity *>(sender());
     if (!identity) {
         qWarning() << "NetworksSettingsPage: Invalid identity to update!";
         return;
@@ -481,21 +473,21 @@ QListWidgetItem *NetworksSettingsPage::networkItem(NetworkId id) const
 void NetworksSettingsPage::clientNetworkAdded(NetworkId id)
 {
     insertNetwork(id);
-    //connect(Client::network(id), SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
-    connect(Client::network(id), SIGNAL(configChanged()), this, SLOT(clientNetworkUpdated()));
+    //connect(Client::network(id), &Network::updatedRemotely, this, &NetworksSettingsPage::clientNetworkUpdated);
+    connect(Client::network(id), &Network::configChanged, this, &NetworksSettingsPage::clientNetworkUpdated);
 
-    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 &)));
+    connect(Client::network(id), &Network::connectionStateSet, this, &NetworksSettingsPage::networkConnectionStateChanged);
+    connect(Client::network(id), &Network::connectionError, this, &NetworksSettingsPage::networkConnectionError);
 
     // 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()));
+    connect(Client::network(id), &Network::capAdded, this, &NetworksSettingsPage::clientNetworkCapsUpdated);
+    connect(Client::network(id), &Network::capRemoved, this, &NetworksSettingsPage::clientNetworkCapsUpdated);
 }
 
 
 void NetworksSettingsPage::clientNetworkUpdated()
 {
-    const Network *net = qobject_cast<const Network *>(sender());
+    const auto *net = qobject_cast<const Network *>(sender());
     if (!net) {
         qWarning() << "Update request for unknown network received!";
         return;
@@ -526,7 +518,7 @@ void NetworksSettingsPage::clientNetworkRemoved(NetworkId id)
 void NetworksSettingsPage::networkConnectionStateChanged(Network::ConnectionState state)
 {
     Q_UNUSED(state);
-    const Network *net = qobject_cast<const Network *>(sender());
+    const auto *net = qobject_cast<const Network *>(sender());
     if (!net) return;
     /*
     if(net->networkId() == currentId) {
@@ -595,12 +587,12 @@ void NetworksSettingsPage::displayNetwork(NetworkId id)
         // this is only needed when the core supports SASL EXTERNAL
         if (Client::isCoreFeatureEnabled(Quassel::Feature::SaslExternal)) {
             if (_cid) {
-                disconnect(_cid, SIGNAL(sslSettingsUpdated()), this, SLOT(sslUpdated()));
+                disconnect(_cid, &CertIdentity::sslSettingsUpdated, this, &NetworksSettingsPage::sslUpdated);
                 delete _cid;
             }
             _cid = new CertIdentity(*Client::identity(info.identity), this);
             _cid->enableEditSsl(true);
-            connect(_cid, SIGNAL(sslSettingsUpdated()), this, SLOT(sslUpdated()));
+            connect(_cid, &CertIdentity::sslSettingsUpdated, this, &NetworksSettingsPage::sslUpdated);
         }
 #endif
 
@@ -653,7 +645,7 @@ void NetworksSettingsPage::displayNetwork(NetworkId id)
         // just clear widgets
 #ifdef HAVE_SSL
         if (_cid) {
-            disconnect(_cid, SIGNAL(sslSettingsUpdated()), this, SLOT(sslUpdated()));
+            disconnect(_cid, &CertIdentity::sslSettingsUpdated, this, &NetworksSettingsPage::sslUpdated);
             delete _cid;
         }
 #endif
@@ -709,7 +701,7 @@ void NetworksSettingsPage::saveToNetworkInfo(NetworkInfo &info)
 void NetworksSettingsPage::clientNetworkCapsUpdated()
 {
     // Grab the updated network
-    const Network *net = qobject_cast<const Network *>(sender());
+    const auto *net = qobject_cast<const Network *>(sender());
     if (!net) {
         qWarning() << "Update request for unknown network received!";
         return;
@@ -1029,20 +1021,20 @@ IdentityId NetworksSettingsPage::defaultIdentity() const
 * NetworkAddDlg
 *************************************************************************/
 
-NetworkAddDlg::NetworkAddDlg(const QStringList &exist, QWidget *parent) : QDialog(parent), existing(exist)
+NetworkAddDlg::NetworkAddDlg(QStringList exist, QWidget *parent) : QDialog(parent), existing(std::move(exist))
 {
     ui.setupUi(this);
     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)));
+    connect(ui.useSSL, &QAbstractButton::toggled, this, &NetworkAddDlg::updateSslPort);
     // 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)));
+        connect(ui.useSSL, &QAbstractButton::toggled, ui.sslVerify, &QWidget::setEnabled);
     } else {
         // Core isn't new enough to allow requiring SSL; disable checkbox and uncheck
         ui.sslVerify->setEnabled(false);
@@ -1068,10 +1060,10 @@ NetworkAddDlg::NetworkAddDlg(const QStringList &exist, QWidget *parent) : QDialo
         ui.useManual->setChecked(true);
         ui.usePreset->setEnabled(false);
     }
-    connect(ui.networkName, SIGNAL(textChanged(const QString &)), SLOT(setButtonStates()));
-    connect(ui.serverAddress, SIGNAL(textChanged(const QString &)), SLOT(setButtonStates()));
-    connect(ui.usePreset, SIGNAL(toggled(bool)), SLOT(setButtonStates()));
-    connect(ui.useManual, SIGNAL(toggled(bool)), SLOT(setButtonStates()));
+    connect(ui.networkName, &QLineEdit::textChanged, this, &NetworkAddDlg::setButtonStates);
+    connect(ui.serverAddress, &QLineEdit::textChanged, this, &NetworkAddDlg::setButtonStates);
+    connect(ui.usePreset, &QRadioButton::toggled, this, &NetworkAddDlg::setButtonStates);
+    connect(ui.useManual, &QRadioButton::toggled, this, &NetworkAddDlg::setButtonStates);
     setButtonStates();
 }
 
@@ -1121,7 +1113,7 @@ void NetworkAddDlg::updateSslPort(bool isChecked)
  * NetworkEditDlg
  *************************************************************************/
 
-NetworkEditDlg::NetworkEditDlg(const QString &old, const QStringList &exist, QWidget *parent) : QDialog(parent), existing(exist)
+NetworkEditDlg::NetworkEditDlg(const QString &old, QStringList exist, QWidget *parent) : QDialog(parent), existing(std::move(exist))
 {
     ui.setupUi(this);
 
@@ -1184,14 +1176,14 @@ ServerEditDlg::ServerEditDlg(const Network::Server &server, QWidget *parent) : Q
     }
 
     // Whenever useSSL is toggled, update the port number if not changed from the default
-    connect(ui.useSSL, SIGNAL(toggled(bool)), SLOT(updateSslPort(bool)));
+    connect(ui.useSSL, &QAbstractButton::toggled, this, &ServerEditDlg::updateSslPort);
     // 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)));
+        connect(ui.useSSL, &QAbstractButton::toggled, ui.sslVerify, &QWidget::setEnabled);
     } else {
         // Core isn't new enough to allow requiring SSL; disable checkbox and uncheck
         ui.sslVerify->setEnabled(false);
@@ -1259,8 +1251,8 @@ SaveNetworksDlg::SaveNetworksDlg(const QList<NetworkInfo> &toCreate, const QList
         ui.progressBar->setMaximum(numevents);
         ui.progressBar->setValue(0);
 
-        connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(clientEvent()));
-        connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), this, SLOT(clientEvent()));
+        connect(Client::instance(), &Client::networkCreated, this, &SaveNetworksDlg::clientEvent);
+        connect(Client::instance(), &Client::networkRemoved, this, &SaveNetworksDlg::clientEvent);
 
         foreach(NetworkId id, toRemove) {
             Client::removeNetwork(id);
@@ -1276,7 +1268,7 @@ SaveNetworksDlg::SaveNetworksDlg(const QList<NetworkInfo> &toCreate, const QList
                 continue;
             }
             // FIXME this only checks for one changed item rather than all!
-            connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientEvent()));
+            connect(net, &SyncableObject::updatedRemotely, this, &SaveNetworksDlg::clientEvent);
             Client::updateNetwork(info);
         }
     }