modernize: Use auto where the type is clear from context
[quassel.git] / src / qtui / settingspages / networkssettingspage.cpp
index d8309ad..b8b8474 100644 (file)
@@ -21,6 +21,7 @@
 #include <QHeaderView>
 #include <QMessageBox>
 #include <QTextCodec>
+#include <utility>
 
 #include "networkssettingspage.h"
 
@@ -39,9 +40,6 @@
 
 NetworksSettingsPage::NetworksSettingsPage(QWidget *parent)
     : SettingsPage(tr("IRC"), tr("Networks"), parent)
-#ifdef HAVE_SSL
-      , _cid(0)
-#endif
 {
     ui.setupUi(this);
 
@@ -207,6 +205,9 @@ void NetworksSettingsPage::load()
     sslUpdated();
 #endif
 
+    // Reset network capability status in case no valid networks get selected (a rare situation)
+    resetNetworkCapStates();
+
     foreach(NetworkId netid, Client::networkIds()) {
         clientNetworkAdded(netid);
     }
@@ -355,10 +356,17 @@ 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 (Client::isCoreFeatureEnabled(Quassel::Feature::CapNegotiation) && net) {
+    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.
@@ -424,7 +432,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;
@@ -464,7 +472,7 @@ QListWidgetItem *NetworksSettingsPage::networkItem(NetworkId id) const
         QListWidgetItem *item = ui.networkList->item(i);
         if (item->data(Qt::UserRole).value<NetworkId>() == id) return item;
     }
-    return 0;
+    return nullptr;
 }
 
 
@@ -485,7 +493,7 @@ void NetworksSettingsPage::clientNetworkAdded(NetworkId id)
 
 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;
@@ -516,7 +524,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) {
@@ -548,7 +556,7 @@ QListWidgetItem *NetworksSettingsPage::insertNetwork(NetworkId id)
 
 QListWidgetItem *NetworksSettingsPage::insertNetwork(const NetworkInfo &info)
 {
-    QListWidgetItem *item = 0;
+    QListWidgetItem *item = nullptr;
     QList<QListWidgetItem *> items = ui.networkList->findItems(info.networkName, Qt::MatchExactly);
     if (!items.count()) item = new QListWidgetItem(disconnectedIcon, info.networkName, ui.networkList);
     else {
@@ -699,7 +707,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;
@@ -1019,7 +1027,7 @@ 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"));
@@ -1060,6 +1068,8 @@ NetworkAddDlg::NetworkAddDlg(const QStringList &exist, QWidget *parent) : QDialo
     }
     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()));
     setButtonStates();
 }
 
@@ -1109,7 +1119,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);