+
+void NetworksSettingsPage::on_editServer_clicked()
+{
+ if (currentId == 0) return;
+ int cur = ui.serverList->currentRow();
+ ServerEditDlg dlg(networkInfos[currentId].serverList[cur], this);
+ if (dlg.exec() == QDialog::Accepted) {
+ networkInfos[currentId].serverList[cur] = dlg.serverData();
+ displayNetwork(currentId);
+ ui.serverList->setCurrentRow(cur);
+ widgetHasChanged();
+ }
+}
+
+
+void NetworksSettingsPage::on_deleteServer_clicked()
+{
+ if (currentId == 0) return;
+ int cur = ui.serverList->currentRow();
+ networkInfos[currentId].serverList.removeAt(cur);
+ displayNetwork(currentId);
+ ui.serverList->setCurrentRow(qMin(cur, ui.serverList->count()-1));
+ widgetHasChanged();
+}
+
+
+void NetworksSettingsPage::on_upServer_clicked()
+{
+ int cur = ui.serverList->currentRow();
+ Network::Server server = networkInfos[currentId].serverList.takeAt(cur);
+ networkInfos[currentId].serverList.insert(cur-1, server);
+ displayNetwork(currentId);
+ ui.serverList->setCurrentRow(cur-1);
+ widgetHasChanged();
+}
+
+
+void NetworksSettingsPage::on_downServer_clicked()
+{
+ int cur = ui.serverList->currentRow();
+ Network::Server server = networkInfos[currentId].serverList.takeAt(cur);
+ networkInfos[currentId].serverList.insert(cur+1, server);
+ displayNetwork(currentId);
+ ui.serverList->setCurrentRow(cur+1);
+ widgetHasChanged();
+}
+
+
+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(QIcon::fromTheme("document-encrypt"));
+
+ // read preset networks
+ QStringList networks = PresetNetworks::names();
+ 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 PresetNetworks::networkInfo(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);
+}
+
+
+/**************************************************************************
+ * NetworkEditDlg
+ *************************************************************************/
+
+NetworkEditDlg::NetworkEditDlg(const QString &old, const QStringList &exist, QWidget *parent) : QDialog(parent), existing(exist)
+{
+ ui.setupUi(this);
+
+ if (old.isEmpty()) {
+ // new network
+ setWindowTitle(tr("Add Network"));
+ on_networkEdit_textChanged(""); // disable ok button
+ }
+ else ui.networkEdit->setText(old);
+}
+
+
+QString NetworkEditDlg::networkName() const
+{
+ return ui.networkEdit->text().trimmed();
+}
+
+
+void NetworkEditDlg::on_networkEdit_textChanged(const QString &text)
+{
+ ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(text.isEmpty() || existing.contains(text.trimmed()));
+}
+
+
+/**************************************************************************
+ * ServerEditDlg
+ *************************************************************************/
+ServerEditDlg::ServerEditDlg(const Network::Server &server, QWidget *parent) : QDialog(parent)
+{
+ ui.setupUi(this);
+ ui.useSSL->setIcon(QIcon::fromTheme("document-encrypt"));
+ ui.host->setText(server.host);
+ ui.host->setFocus();
+ ui.port->setValue(server.port);
+ ui.password->setText(server.password);
+ ui.useSSL->setChecked(server.useSsl);
+ ui.sslVersion->setCurrentIndex(server.sslVersion);
+ ui.useProxy->setChecked(server.useProxy);
+ ui.proxyType->setCurrentIndex(server.proxyType == QNetworkProxy::Socks5Proxy ? 0 : 1);
+ ui.proxyHost->setText(server.proxyHost);
+ ui.proxyPort->setValue(server.proxyPort);
+ ui.proxyUsername->setText(server.proxyUser);
+ ui.proxyPassword->setText(server.proxyPass);
+
+ // This is a dirty hack to display the core->IRC SSL protocol dropdown
+ // only if the core won't use autonegotiation to determine the best
+ // protocol. When autonegotiation was introduced, it would have been
+ // a good idea to use the CoreFeatures enum to accomplish this.
+ // However, since multiple versions have been released since then, that
+ // is no longer possible. Instead, we rely on the fact that the
+ // Datastream protocol was introduced in the same version (0.10) as SSL
+ // autonegotiation. Because of that, we can display the dropdown only
+ // if the Legacy protocol is in use. If any other RemotePeer protocol
+ // is in use, that means a newer protocol is in use and therefore the
+ // core will use autonegotiation.
+ if (Client::coreConnection()->peer()->protocol() != Protocol::LegacyProtocol) {
+ ui.label_3->hide();
+ ui.sslVersion->hide();
+ }
+
+ on_host_textChanged();
+}
+
+
+Network::Server ServerEditDlg::serverData() const
+{
+ Network::Server server(ui.host->text().trimmed(), ui.port->value(), ui.password->text(), ui.useSSL->isChecked());
+ server.sslVersion = ui.sslVersion->currentIndex();
+ server.useProxy = ui.useProxy->isChecked();
+ server.proxyType = ui.proxyType->currentIndex() == 0 ? QNetworkProxy::Socks5Proxy : QNetworkProxy::HttpProxy;
+ server.proxyHost = ui.proxyHost->text();
+ server.proxyPort = ui.proxyPort->value();
+ server.proxyUser = ui.proxyUsername->text();
+ server.proxyPass = ui.proxyPassword->text();
+ return server;
+}
+
+
+void ServerEditDlg::on_host_textChanged()
+{
+ ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(ui.host->text().trimmed().isEmpty());
+}
+
+
+/**************************************************************************
+ * SaveNetworksDlg
+ *************************************************************************/
+
+SaveNetworksDlg::SaveNetworksDlg(const QList<NetworkInfo> &toCreate, const QList<NetworkInfo> &toUpdate, const QList<NetworkId> &toRemove, QWidget *parent) : QDialog(parent)
+{
+ ui.setupUi(this);
+
+ numevents = toCreate.count() + toUpdate.count() + toRemove.count();
+ rcvevents = 0;
+ if (numevents) {
+ 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()));
+
+ foreach(NetworkId id, toRemove) {
+ Client::removeNetwork(id);
+ }
+ foreach(NetworkInfo info, toCreate) {
+ Client::createNetwork(info);
+ }
+ foreach(NetworkInfo info, toUpdate) {
+ const Network *net = Client::network(info.networkId);
+ if (!net) {
+ qWarning() << "Invalid client network!";
+ numevents--;
+ continue;
+ }
+ // FIXME this only checks for one changed item rather than all!
+ connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientEvent()));
+ Client::updateNetwork(info);
+ }
+ }
+ else {
+ qWarning() << "Sync dialog called without stuff to change!";
+ accept();
+ }
+}
+
+
+void SaveNetworksDlg::clientEvent()
+{
+ ui.progressBar->setValue(++rcvevents);
+ if (rcvevents >= numevents) accept();
+}