+void NetworksSettingsPage::on_editIdentities_clicked() {
+ SettingsPageDlg dlg(new IdentitiesSettingsPage(this), this);
+ dlg.exec();
+}
+
+IdentityId NetworksSettingsPage::defaultIdentity() const {
+ IdentityId defaultId = 0;
+ QList<IdentityId> ids = Client::identityIds();
+ foreach(IdentityId id, ids) {
+ if(defaultId == 0 || id < defaultId)
+ defaultId = id;
+ }
+ return defaultId;
+}
+
+/**************************************************************************
+* NetworkAddDlg
+*************************************************************************/
+
+NetworkAddDlg::NetworkAddDlg(const QStringList &exist, QWidget *parent) : QDialog(parent), existing(exist) {
+ ui.setupUi(this);
+ ui.useSSL->setIcon(SmallIcon("document-encrypt"));
+
+ // read preset networks
+ QStringList networks = Network::presetNetworks();
+ foreach(QString s, existing)
+ networks.removeAll(s);
+ if(networks.count())
+ ui.presetList->addItems(networks);
+ else {
+ 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()));
+ setButtonStates();
+}
+
+NetworkInfo NetworkAddDlg::networkInfo() const {
+ if(ui.useManual->isChecked()) {
+ NetworkInfo info;
+ info.networkName = ui.networkName->text().trimmed();
+ info.serverList << Network::Server(ui.serverAddress->text().trimmed(), ui.port->value(), ui.serverPassword->text(), ui.useSSL->isChecked());
+ return info;
+ } else
+ return Network::networkInfoFromPreset(ui.presetList->currentText());
+}
+
+void NetworkAddDlg::setButtonStates() {
+ bool ok = false;
+ if(ui.usePreset->isChecked() && ui.presetList->count())
+ ok = true;
+ else if(ui.useManual->isChecked()) {
+ ok = !ui.networkName->text().trimmed().isEmpty() && !existing.contains(ui.networkName->text().trimmed())
+ && !ui.serverAddress->text().isEmpty();
+ }
+ ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ok);
+}
+