+
+#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;
+ }
+ setWidgetStates();
+}
+
+
+void NetworksSettingsPage::on_addNetwork_clicked()
+{
+ QStringList existing;
+ for (int i = 0; i < ui.networkList->count(); i++) existing << ui.networkList->item(i)->text();
+ NetworkAddDlg dlg(existing, this);
+ if (dlg.exec() == QDialog::Accepted) {
+ NetworkInfo info = dlg.networkInfo();
+ if (info.networkName.isEmpty())
+ return; // sanity check
+
+ NetworkId id;
+ for (id = 1; id <= networkInfos.count(); id++) {
+ widgetHasChanged();
+ if (!networkInfos.keys().contains(-id.toInt())) break;
+ }
+ id = -id.toInt();
+ info.networkId = id;
+ info.identity = defaultIdentity();
+ networkInfos[id] = info;
+ QListWidgetItem *item = insertNetwork(info);
+ ui.networkList->setCurrentItem(item);
+ setWidgetStates();
+ }
+}
+
+
+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?").arg(networkInfos[netid].networkName),
+ QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
+ if (ret == QMessageBox::Yes) {
+ currentId = 0;
+ networkInfos.remove(netid);
+ delete ui.networkList->takeItem(ui.networkList->row(ui.networkList->selectedItems()[0]));
+ ui.networkList->setCurrentRow(qMin(ui.networkList->currentRow()+1, ui.networkList->count()-1));
+ setWidgetStates();
+ widgetHasChanged();
+ }
+ }
+}
+
+
+void NetworksSettingsPage::on_renameNetwork_clicked()
+{
+ if (!ui.networkList->selectedItems().count()) return;
+ QString old = ui.networkList->selectedItems()[0]->text();
+ QStringList existing;
+ for (int i = 0; i < ui.networkList->count(); i++) existing << ui.networkList->item(i)->text();
+ NetworkEditDlg dlg(old, existing, this);
+ if (dlg.exec() == QDialog::Accepted) {
+ ui.networkList->selectedItems()[0]->setText(dlg.networkName());
+ NetworkId netid = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
+ networkInfos[netid].networkName = dlg.networkName();
+ widgetHasChanged();
+ }
+}
+
+
+/*
+void NetworksSettingsPage::on_connectNow_clicked() {
+ if(!ui.networkList->selectedItems().count()) return;
+ NetworkId id = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
+ const Network *net = Client::network(id);
+ if(!net) return;
+ if(net->connectionState() == Network::Disconnected) net->requestConnect();
+ else net->requestDisconnect();
+}
+*/
+
+/*** Server list ***/
+
+void NetworksSettingsPage::on_serverList_itemSelectionChanged()
+{
+ setWidgetStates();
+}
+
+
+void NetworksSettingsPage::on_addServer_clicked()
+{
+ if (currentId == 0) return;
+ ServerEditDlg dlg(Network::Server(), this);
+ if (dlg.exec() == QDialog::Accepted) {
+ networkInfos[currentId].serverList.append(dlg.serverData());
+ displayNetwork(currentId);
+ ui.serverList->setCurrentRow(ui.serverList->count()-1);
+ widgetHasChanged();
+ }
+}
+
+
+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"));
+
+ // Whenever useSSL is toggled, update the port number if not changed from the default
+ connect(ui.useSSL, SIGNAL(toggled(bool)), SLOT(updateSslPort(bool)));
+ // Do NOT call updateSslPort when loading settings, otherwise port settings may be overriden.
+ // If useSSL is later changed to be checked by default, change port's default value, too.
+
+ if (Client::coreFeatures() & Quassel::VerifyServerSSL) {
+ // Synchronize requiring SSL with the use SSL checkbox
+ ui.sslVerify->setEnabled(ui.useSSL->isChecked());
+ connect(ui.useSSL, SIGNAL(toggled(bool)), ui.sslVerify, SLOT(setEnabled(bool)));
+ } else {
+ // Core isn't new enough to allow requiring SSL; disable checkbox and uncheck
+ ui.sslVerify->setEnabled(false);
+ ui.sslVerify->setChecked(false);
+ // Split up the message to allow re-using translations:
+ // [Original tool-tip]
+ // [Bold 'does not support feature' message]
+ // [Specific version needed and feature details]
+ ui.sslVerify->setToolTip(QString("%1<br/><b>%2</b><br/>%3").arg(
+ ui.sslVerify->toolTip(),
+ tr("Your Quassel core does not support this feature"),
+ tr("You need a Quassel core v0.13.0 or newer in order to "
+ "verify connection security.")));
+ }
+
+ // 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(),
+ ui.sslVerify->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);
+}
+
+
+void NetworkAddDlg::updateSslPort(bool isChecked)
+{
+ // "Use encrypted connection" was toggled, check the state...
+ if (isChecked && ui.port->value() == Network::PORT_PLAINTEXT) {
+ // Had been using the plain-text port, use the SSL default
+ ui.port->setValue(Network::PORT_SSL);
+ } else if (!isChecked && ui.port->value() == Network::PORT_SSL) {
+ // Had been using the SSL port, use the plain-text default
+ ui.port->setValue(Network::PORT_PLAINTEXT);
+ }
+}
+
+
+/**************************************************************************
+ * 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.sslVerify->setChecked(server.sslVerify);
+ 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();
+ }
+
+ // Whenever useSSL is toggled, update the port number if not changed from the default
+ connect(ui.useSSL, SIGNAL(toggled(bool)), SLOT(updateSslPort(bool)));
+ // Do NOT call updateSslPort when loading settings, otherwise port settings may be overriden.
+ // If useSSL is later changed to be checked by default, change port's default value, too.
+
+ if (Client::coreFeatures() & Quassel::VerifyServerSSL) {
+ // Synchronize requiring SSL with the use SSL checkbox
+ ui.sslVerify->setEnabled(ui.useSSL->isChecked());
+ connect(ui.useSSL, SIGNAL(toggled(bool)), ui.sslVerify, SLOT(setEnabled(bool)));
+ } else {
+ // Core isn't new enough to allow requiring SSL; disable checkbox and uncheck
+ ui.sslVerify->setEnabled(false);
+ ui.sslVerify->setChecked(false);
+ // Split up the message to allow re-using translations:
+ // [Original tool-tip]
+ // [Bold 'does not support feature' message]
+ // [Specific version needed and feature details]
+ ui.sslVerify->setToolTip(QString("%1<br/><b>%2</b><br/>%3").arg(
+ ui.sslVerify->toolTip(),
+ tr("Your Quassel core does not support this feature"),
+ tr("You need a Quassel core v0.13.0 or newer in order to "
+ "verify connection security.")));
+ }
+
+ on_host_textChanged();
+}
+
+
+Network::Server ServerEditDlg::serverData() const
+{
+ Network::Server server(ui.host->text().trimmed(), ui.port->value(), ui.password->text(),
+ ui.useSSL->isChecked(), ui.sslVerify->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());
+}
+
+
+void ServerEditDlg::updateSslPort(bool isChecked)
+{
+ // "Use encrypted connection" was toggled, check the state...
+ if (isChecked && ui.port->value() == Network::PORT_PLAINTEXT) {
+ // Had been using the plain-text port, use the SSL default
+ ui.port->setValue(Network::PORT_SSL);
+ } else if (!isChecked && ui.port->value() == Network::PORT_SSL) {
+ // Had been using the SSL port, use the plain-text default
+ ui.port->setValue(Network::PORT_PLAINTEXT);
+ }
+}
+
+
+/**************************************************************************
+ * 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();
+ }
+}