+ return insertNetwork(info);
+}
+
+
+QListWidgetItem *NetworksSettingsPage::insertNetwork(const NetworkInfo &info)
+{
+ QListWidgetItem *item = 0;
+ QList<QListWidgetItem *> 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) {
+ NetworkId id = i->data(Qt::UserRole).value<NetworkId>();
+ if (id < 0) { item = i; break; }
+ }
+ if (!item) item = new QListWidgetItem(disconnectedIcon, info.networkName, ui.networkList);
+ }
+ item->setData(Qt::UserRole, QVariant::fromValue<NetworkId>(info.networkId));
+ setItemState(info.networkId, item);
+ widgetHasChanged();
+ return item;
+}
+
+
+void NetworksSettingsPage::displayNetwork(NetworkId id)
+{
+ _ignoreWidgetChanges = true;
+ if (id != 0) {
+ NetworkInfo info = networkInfos[id];
+
+#ifdef HAVE_SSL
+ // this is only needed when the core supports SASL EXTERNAL
+ if (Client::coreFeatures() & Quassel::SaslExternal) {
+ if (_cid) {
+ disconnect(_cid, SIGNAL(sslSettingsUpdated()), this, SLOT(sslUpdated()));
+ delete _cid;
+ }
+ _cid = new CertIdentity(*Client::identity(info.identity), this);
+ _cid->enableEditSsl(true);
+ connect(_cid, SIGNAL(sslSettingsUpdated()), this, SLOT(sslUpdated()));
+ }
+#endif
+
+ 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));
+ if (server.useSsl)
+ item->setIcon(SmallIcon("document-encrypt"));
+ ui.serverList->addItem(item);
+ }
+ //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);
+ ui.sasl->setChecked(info.useSasl);
+ ui.saslAccount->setText(info.saslAccount);
+ ui.saslPassword->setText(info.saslPassword);
+ if (info.codecForEncoding.isEmpty()) {
+ ui.sendEncoding->setCurrentIndex(ui.sendEncoding->findText(Network::defaultCodecForEncoding()));
+ ui.recvEncoding->setCurrentIndex(ui.recvEncoding->findText(Network::defaultCodecForDecoding()));
+ ui.serverEncoding->setCurrentIndex(ui.serverEncoding->findText(Network::defaultCodecForServer()));
+ ui.useCustomEncodings->setChecked(false);
+ }
+ else {
+ ui.sendEncoding->setCurrentIndex(ui.sendEncoding->findText(info.codecForEncoding));
+ ui.recvEncoding->setCurrentIndex(ui.recvEncoding->findText(info.codecForDecoding));
+ ui.serverEncoding->setCurrentIndex(ui.serverEncoding->findText(info.codecForServer));
+ ui.useCustomEncodings->setChecked(true);
+ }
+ ui.autoReconnect->setChecked(info.useAutoReconnect);
+ ui.reconnectInterval->setValue(info.autoReconnectInterval);
+ ui.reconnectRetries->setValue(info.autoReconnectRetries);
+ ui.unlimitedRetries->setChecked(info.unlimitedReconnectRetries);
+ ui.rejoinOnReconnect->setChecked(info.rejoinChannels);
+ }
+ else {
+ // just clear widgets
+#ifdef HAVE_SSL
+ if (_cid) {
+ disconnect(_cid, SIGNAL(sslSettingsUpdated()), this, SLOT(sslUpdated()));
+ delete _cid;
+ }
+#endif
+ ui.identityList->setCurrentIndex(-1);
+ ui.serverList->clear();
+ ui.performEdit->clear();
+ ui.autoIdentifyService->clear();
+ ui.autoIdentifyPassword->clear();
+ ui.saslAccount->clear();
+ ui.saslPassword->clear();
+ setWidgetStates();
+ }
+ _ignoreWidgetChanges = false;
+ currentId = 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();
+ info.useSasl = ui.sasl->isChecked();
+ info.saslAccount = ui.saslAccount->text();
+ info.saslPassword = ui.saslPassword->text();
+ if (!ui.useCustomEncodings->isChecked()) {
+ info.codecForEncoding.clear();
+ info.codecForDecoding.clear();
+ info.codecForServer.clear();
+ }
+ else {
+ info.codecForEncoding = ui.sendEncoding->currentText().toLatin1();
+ info.codecForDecoding = ui.recvEncoding->currentText().toLatin1();
+ info.codecForServer = ui.serverEncoding->currentText().toLatin1();
+ }
+ info.useAutoReconnect = ui.autoReconnect->isChecked();
+ info.autoReconnectInterval = ui.reconnectInterval->value();
+ info.autoReconnectRetries = ui.reconnectRetries->value();
+ info.unlimitedReconnectRetries = ui.unlimitedRetries->isChecked();
+ info.rejoinChannels = ui.rejoinOnReconnect->isChecked();
+}
+
+
+#ifdef HAVE_SSL
+void NetworksSettingsPage::sslUpdated()
+{
+ if (_cid && !_cid->sslKey().isNull()) {
+ ui.saslAccount->setDisabled(true);
+ ui.saslAccountLabel->setDisabled(true);
+ ui.saslPassword->setDisabled(true);
+ ui.saslPasswordLabel->setDisabled(true);
+ ui.saslExtInfo->setHidden(false);
+ } else {
+ ui.saslAccount->setDisabled(false);
+ ui.saslAccountLabel->setDisabled(false);
+ ui.saslPassword->setDisabled(false);
+ ui.saslPasswordLabel->setDisabled(false);
+ ui.saslExtInfo->setHidden(true);
+ }
+}
+#endif
+
+
+/*** Network list ***/
+
+void NetworksSettingsPage::on_networkList_itemSelectionChanged()
+{
+ if (currentId != 0) {
+ saveToNetworkInfo(networkInfos[currentId]);
+ }
+ if (ui.networkList->selectedItems().count()) {
+ NetworkId id = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
+ currentId = id;
+ displayNetwork(id);
+ ui.serverList->setCurrentRow(0);
+ }
+ else {
+ currentId = 0;
+ }