+void NetworksSettingsPage::sslUpdated()
+{
+ if (_cid && !_cid->sslKey().isNull()) {
+ ui.saslContents->setDisabled(true);
+ ui.saslExtInfo->setHidden(false);
+ }
+ else {
+ ui.saslContents->setDisabled(false);
+ // Directly re-enabling causes the widgets to ignore the parent "Use SASL Authentication"
+ // state to indicate whether or not it's disabled. To workaround this, keep track of
+ // whether or not "Use SASL Authentication" is enabled, then quickly uncheck/recheck the
+ // group box.
+ if (!ui.sasl->isChecked()) {
+ // SASL is not enabled, uncheck/recheck the group box to re-disable saslContents.
+ // Leaving saslContents disabled doesn't work as that prevents it from re-enabling if
+ // sasl is later checked.
+ ui.sasl->setChecked(true);
+ ui.sasl->setChecked(false);
+ }
+ ui.saslExtInfo->setHidden(true);
+ }
+}
+
+/*** 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();
+}
+
+void NetworksSettingsPage::on_saslStatusDetails_clicked()
+{
+ if (ui.networkList->selectedItems().count()) {
+ NetworkId netid = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
+ QString& netName = networkInfos[netid].networkName;
+
+ // If these strings are visible, one of the status messages wasn't detected below.
+ QString saslStatusHeader = "[header unintentionally left blank]";
+ QString saslStatusExplanation = "[explanation unintentionally left blank]";
+
+ // If true, show a warning icon instead of an information icon
+ bool useWarningIcon = false;
+
+ // Determine which explanation to show
+ switch (_saslStatusSelected) {
+ case CapSupportStatus::Unknown:
+ saslStatusHeader = tr("Could not check if SASL supported by network");
+ saslStatusExplanation = tr("Quassel could not check if \"%1\" supports SASL. This may "
+ "be due to unsaved changes or an older Quassel core. You "
+ "can still try using SASL.")
+ .arg(netName);
+ break;
+ case CapSupportStatus::Disconnected:
+ saslStatusHeader = tr("Cannot check if SASL supported when disconnected");
+ saslStatusExplanation = tr("Quassel cannot check if \"%1\" supports SASL when "
+ "disconnected. Connect to the network, or try using SASL "
+ "anyways.")
+ .arg(netName);
+ break;
+ case CapSupportStatus::MaybeUnsupported:
+ saslStatusHeader = tr("SASL not currently supported by network");
+ saslStatusExplanation = tr("The network \"%1\" does not currently support SASL. "
+ "However, support might be added later on.")
+ .arg(netName);
+ useWarningIcon = true;
+ break;
+ case CapSupportStatus::MaybeSupported:
+ saslStatusHeader = tr("SASL supported by network");
+ saslStatusExplanation = tr("The network \"%1\" supports SASL. In most cases, you "
+ "should use SASL instead of NickServ identification.")
+ .arg(netName);
+ break;
+ }
+
+ // Process this in advance for reusability below
+ const QString saslStatusMsgTitle = tr("SASL support for \"%1\"").arg(netName);
+ const QString saslStatusMsgText = QString("<p><b>%1</b></p></br><p>%2</p></br><p><i>%3</i></p>")
+ .arg(saslStatusHeader,
+ saslStatusExplanation,
+ tr("SASL is a standardized way to log in and identify yourself to "
+ "IRC servers."));
+
+ if (useWarningIcon) {
+ // Show as a warning dialog box
+ QMessageBox::warning(this, saslStatusMsgTitle, saslStatusMsgText);
+ }
+ else {
+ // Show as an information dialog box
+ QMessageBox::information(this, saslStatusMsgTitle, saslStatusMsgText);
+ }
+ }
+}
+
+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(QStringList exist, QWidget* parent)
+ : QDialog(parent)
+ , existing(std::move(exist))
+{
+ ui.setupUi(this);
+ ui.useSSL->setIcon(icon::get("document-encrypt"));
+
+ // Whenever useSSL is toggled, update the port number if not changed from the default
+ connect(ui.useSSL, &QAbstractButton::toggled, this, &NetworkAddDlg::updateSslPort);
+ // 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::isCoreFeatureEnabled(Quassel::Feature::VerifyServerSSL)) {
+ // Synchronize requiring SSL with the use SSL checkbox
+ ui.sslVerify->setEnabled(ui.useSSL->isChecked());
+ connect(ui.useSSL, &QAbstractButton::toggled, ui.sslVerify, &QWidget::setEnabled);
+ }
+ 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, &QLineEdit::textChanged, this, &NetworkAddDlg::setButtonStates);
+ connect(ui.serverAddress, &QLineEdit::textChanged, this, &NetworkAddDlg::setButtonStates);
+ connect(ui.usePreset, &QRadioButton::toggled, this, &NetworkAddDlg::setButtonStates);
+ connect(ui.useManual, &QRadioButton::toggled, this, &NetworkAddDlg::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, QStringList exist, QWidget* parent)
+ : QDialog(parent)
+ , existing(std::move(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(icon::get("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, &QAbstractButton::toggled, this, &ServerEditDlg::updateSslPort);
+ // 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::isCoreFeatureEnabled(Quassel::Feature::VerifyServerSSL)) {
+ // Synchronize requiring SSL with the use SSL checkbox
+ ui.sslVerify->setEnabled(ui.useSSL->isChecked());
+ connect(ui.useSSL, &QAbstractButton::toggled, ui.sslVerify, &QWidget::setEnabled);
+ }
+ 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(), &Client::networkCreated, this, &SaveNetworksDlg::clientEvent);
+ connect(Client::instance(), &Client::networkRemoved, this, &SaveNetworksDlg::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, &SyncableObject::updatedRemotely, this, &SaveNetworksDlg::clientEvent);
+ Client::updateNetwork(info);
+ }
+ }
+ else {
+ qWarning() << "Sync dialog called without stuff to change!";
+ accept();
+ }
+}