All network settings can now be edited/stored properly. Most of the new options are not
[quassel.git] / src / qtui / settingspages / networkssettingspage.cpp
index 1e0cefa..16aa61b 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <QHeaderView>
 #include <QMessageBox>
+#include <QTextCodec>
 
 #include "networkssettingspage.h"
 
@@ -36,8 +37,15 @@ NetworksSettingsPage::NetworksSettingsPage(QWidget *parent) : SettingsPage(tr("G
   connectingIcon = QIcon(":/22x22/actions/gear");
   disconnectedIcon = QIcon(":/22x22/actions/network-disconnect");
 
+  foreach(int mib, QTextCodec::availableMibs()) {
+    QByteArray codec = QTextCodec::codecForMib(mib)->name();
+    ui.sendEncoding->addItem(codec);
+    ui.recvEncoding->addItem(codec);
+  }
+  ui.sendEncoding->model()->sort(0);
+  ui.recvEncoding->model()->sort(0);
   currentId = 0;
-  setEnabled(false);  // need a core connection!
+  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)));
@@ -46,6 +54,19 @@ NetworksSettingsPage::NetworksSettingsPage(QWidget *parent) : SettingsPage(tr("G
   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.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.useDefaultEncodings, 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.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()));
   //connect(ui., SIGNAL(), this, SLOT(widgetHasChanged()));
   //connect(ui., SIGNAL(), this, SLOT(widgetHasChanged()));
 
@@ -175,14 +196,10 @@ void NetworksSettingsPage::setWidgetStates() {
     ui.upServer->setEnabled(false);
     ui.downServer->setEnabled(false);
   }
-
-  // FIXME disable network creation/deletion because of the storage issue
-  ui.addNetwork->setEnabled(false);
-  ui.deleteNetwork->setEnabled(false);
 }
 
 void NetworksSettingsPage::setItemState(NetworkId id, QListWidgetItem *item) {
-  if(!item) item = networkItem(id);
+  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);
@@ -194,19 +211,22 @@ void NetworksSettingsPage::setItemState(NetworkId id, QListWidgetItem *item) {
     item->setIcon(disconnectedIcon);
   }
   if(net) {
+    bool select = false;
     // check if we already have another net of this name in the list, and replace it
     QList<QListWidgetItem *> items = ui.networkList->findItems(net->networkName(), Qt::MatchExactly);
     if(items.count()) {
       foreach(QListWidgetItem *i, items) {
         NetworkId oldid = i->data(Qt::UserRole).value<NetworkId>();
         if(oldid > 0) continue;  // only locally created nets should be replaced
-        if(oldid == currentId) item->setSelected(true);
-        delete ui.networkList->takeItem(ui.networkList->row(i));
+        if(oldid == currentId) select = true;
+        int row = ui.networkList->row(i);
+        if(row >= 0) delete ui.networkList->takeItem(row);
         networkInfos.remove(oldid);
         break;
       }
     }
     item->setText(net->networkName());
+    if(select) item->setSelected(true);
   }
 }
 
@@ -362,6 +382,30 @@ void NetworksSettingsPage::displayNetwork(NetworkId id) {
       ui.serverList->addItem(QString("%1:%2").arg(v.toMap()["Host"].toString()).arg(v.toMap()["Port"].toUInt()));
     }
     setItemState(id);
+    ui.randomServer->setChecked(info.useRandomServer);
+    ui.performEdit->setPlainText(info.perform.join("\n"));
+    ui.autoIdentify->setChecked(info.useAutoIdentify);
+    ui.autoIdentifyService->setText(info.autoIdentifyService);
+    ui.autoIdentifyPassword->setText(info.autoIdentifyPassword);
+    if(info.codecForEncoding.isEmpty()) {
+      ui.sendEncoding->setCurrentIndex(ui.sendEncoding->findText(Network::defaultCodecForEncoding()));
+      ui.recvEncoding->setCurrentIndex(ui.recvEncoding->findText(Network::defaultCodecForDecoding()));
+      ui.useDefaultEncodings->setChecked(true);
+    } else {
+      ui.sendEncoding->setCurrentIndex(ui.sendEncoding->findText(info.codecForEncoding));
+      ui.recvEncoding->setCurrentIndex(ui.recvEncoding->findText(info.codecForDecoding));
+      ui.useDefaultEncodings->setChecked(false);
+    }
+    ui.autoReconnect->setChecked(info.useAutoReconnect);
+    ui.reconnectInterval->setValue(info.autoReconnectInterval);
+    if(info.autoReconnectRetries >= 0) {
+      ui.reconnectRetries->setValue(info.autoReconnectRetries);
+      ui.unlimitedRetries->setChecked(false);
+    } else {
+      ui.reconnectRetries->setValue(1);
+      ui.unlimitedRetries->setChecked(true);
+    }
+    ui.rejoinOnReconnect->setChecked(info.rejoinChannels);
   } else {
     // just clear widgets
     ui.identityList->setCurrentIndex(-1);
@@ -374,6 +418,23 @@ void NetworksSettingsPage::displayNetwork(NetworkId id) {
 
 void NetworksSettingsPage::saveToNetworkInfo(NetworkInfo &info) {
   info.identity = ui.identityList->itemData(ui.identityList->currentIndex()).toInt();
+  info.useRandomServer = ui.randomServer->isChecked();
+  info.perform = ui.performEdit->toPlainText().split("\n");
+  info.useAutoIdentify = ui.autoIdentify->isChecked();
+  info.autoIdentifyService = ui.autoIdentifyService->text();
+  info.autoIdentifyPassword = ui.autoIdentifyPassword->text();
+  if(ui.useDefaultEncodings->isChecked()) {
+    info.codecForEncoding.clear();
+    info.codecForDecoding.clear();
+  } else {
+    info.codecForEncoding = ui.sendEncoding->currentText().toLatin1();
+    info.codecForDecoding = ui.recvEncoding->currentText().toLatin1();
+  }
+  info.useAutoReconnect = ui.autoReconnect->isChecked();
+  info.autoReconnectInterval = ui.reconnectInterval->value();
+  if(ui.unlimitedRetries->isChecked()) info.autoReconnectRetries = -1;
+  else info.autoReconnectRetries = ui.reconnectRetries->value();
+  info.rejoinChannels = ui.rejoinOnReconnect->isChecked();
 }
 /*** Network list ***/
 
@@ -418,8 +479,7 @@ void NetworksSettingsPage::on_deleteNetwork_clicked() {
   if(ui.networkList->selectedItems().count()) {
     NetworkId netid = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
     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?"
-                                       "<br><br><em>NOTE: Backlog deletion hasn't actually been implemented yet.</em>").arg(networkInfos[netid].networkName),
+                                    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;
@@ -549,7 +609,7 @@ ServerEditDlg::ServerEditDlg(const QVariant &_serverData, QWidget *parent) : QDi
     ui.password->setText(serverData["Password"].toString());
     ui.useSSL->setChecked(serverData["UseSSL"].toBool());
   } else {
-    ui.port->setValue(Global::defaultPort);
+    ui.port->setValue(6667);
   }
   on_host_textChanged();
 }