+
+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();
+ }
+}
+
+
+void SaveNetworksDlg::clientEvent()
+{
+ ui.progressBar->setValue(++rcvevents);
+ if (rcvevents >= numevents) accept();
+}