+/**************************************************************************
+* 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);
+}
+
+/**************************************************************************
+ * 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(SmallIcon("document-encrypt"));
+ ui.host->setText(server.host);
+ 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);
+ 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();
+}