1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel IRC Team *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include <QHeaderView>
22 #include <QMessageBox>
25 #include "networkssettingspage.h"
33 NetworksSettingsPage::NetworksSettingsPage(QWidget *parent) : SettingsPage(tr("General"), tr("Networks"), parent) {
35 _ignoreWidgetChanges = false;
37 connectedIcon = QIcon(":/22x22/actions/network-connect");
38 connectingIcon = QIcon(":/22x22/actions/gear");
39 disconnectedIcon = QIcon(":/22x22/actions/network-disconnect");
41 foreach(int mib, QTextCodec::availableMibs()) {
42 QByteArray codec = QTextCodec::codecForMib(mib)->name();
43 ui.sendEncoding->addItem(codec);
44 ui.recvEncoding->addItem(codec);
46 ui.sendEncoding->model()->sort(0);
47 ui.recvEncoding->model()->sort(0);
49 setEnabled(Client::isConnected()); // need a core connection!
51 connect(Client::instance(), SIGNAL(coreConnectionStateChanged(bool)), this, SLOT(coreConnectionStateChanged(bool)));
52 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(clientNetworkAdded(NetworkId)));
53 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), this, SLOT(clientNetworkRemoved(NetworkId)));
54 connect(Client::instance(), SIGNAL(identityCreated(IdentityId)), this, SLOT(clientIdentityAdded(IdentityId)));
55 connect(Client::instance(), SIGNAL(identityRemoved(IdentityId)), this, SLOT(clientIdentityRemoved(IdentityId)));
57 connect(ui.identityList, SIGNAL(currentIndexChanged(int)), this, SLOT(widgetHasChanged()));
58 connect(ui.randomServer, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
59 connect(ui.performEdit, SIGNAL(textChanged()), this, SLOT(widgetHasChanged()));
60 connect(ui.autoIdentify, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
61 connect(ui.autoIdentifyService, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged()));
62 connect(ui.autoIdentifyPassword, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged()));
63 connect(ui.useDefaultEncodings, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
64 connect(ui.sendEncoding, SIGNAL(currentIndexChanged(int)), this, SLOT(widgetHasChanged()));
65 connect(ui.recvEncoding, SIGNAL(currentIndexChanged(int)), this, SLOT(widgetHasChanged()));
66 connect(ui.autoReconnect, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
67 connect(ui.reconnectInterval, SIGNAL(valueChanged(int)), this, SLOT(widgetHasChanged()));
68 connect(ui.reconnectRetries, SIGNAL(valueChanged(int)), this, SLOT(widgetHasChanged()));
69 connect(ui.unlimitedRetries, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
70 connect(ui.rejoinOnReconnect, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
71 //connect(ui., SIGNAL(), this, SLOT(widgetHasChanged()));
72 //connect(ui., SIGNAL(), this, SLOT(widgetHasChanged()));
74 foreach(IdentityId id, Client::identityIds()) {
75 clientIdentityAdded(id);
79 void NetworksSettingsPage::save() {
81 if(currentId != 0) saveToNetworkInfo(networkInfos[currentId]);
83 QList<NetworkInfo> toCreate, toUpdate;
84 QList<NetworkId> toRemove;
85 QHash<NetworkId, NetworkInfo>::iterator i = networkInfos.begin();
86 while(i != networkInfos.end()) {
87 NetworkId id = (*i).networkId;
90 //if(id == currentId) currentId = 0;
91 //QList<QListWidgetItem *> items = ui.networkList->findItems((*i).networkName, Qt::MatchExactly);
93 // Q_ASSERT(items[0]->data(Qt::UserRole).value<NetworkId>() == id);
96 //i = networkInfos.erase(i);
99 if((*i) != Client::network((*i).networkId)->networkInfo()) {
105 foreach(NetworkId id, Client::networkIds()) {
106 if(!networkInfos.contains(id)) toRemove.append(id);
108 SaveNetworksDlg dlg(toCreate, toUpdate, toRemove, this);
109 int ret = dlg.exec();
110 if(ret == QDialog::Rejected) {
111 // canceled -> reload everything to be safe
114 setChangedState(false);
118 void NetworksSettingsPage::load() {
120 foreach(NetworkId netid, Client::networkIds()) {
121 clientNetworkAdded(netid);
123 ui.networkList->setCurrentRow(0);
124 setChangedState(false);
127 void NetworksSettingsPage::reset() {
129 ui.networkList->clear();
130 networkInfos.clear();
134 bool NetworksSettingsPage::aboutToSave() {
135 if(currentId != 0) saveToNetworkInfo(networkInfos[currentId]);
137 foreach(NetworkInfo info, networkInfos.values()) {
138 if(!info.serverList.count()) errors.append(1);
140 if(!errors.count()) return true;
141 QString error(tr("<b>The following problems need to be corrected before your changes can be applied:</b><ul>"));
142 if(errors.contains(1)) error += tr("<li>All networks need at least one server defined</li>");
143 error += tr("</ul>");
144 QMessageBox::warning(this, tr("Invalid Network Settings"), error);
148 void NetworksSettingsPage::widgetHasChanged() {
149 if(_ignoreWidgetChanges) return;
150 bool changed = testHasChanged();
151 if(changed != hasChanged()) setChangedState(changed);
154 bool NetworksSettingsPage::testHasChanged() {
156 saveToNetworkInfo(networkInfos[currentId]);
158 if(Client::networkIds().count() != networkInfos.count()) return true;
159 foreach(NetworkId id, networkInfos.keys()) {
160 if(id < 0) return true;
161 if(Client::network(id)->networkInfo() != networkInfos[id]) return true;
166 void NetworksSettingsPage::setWidgetStates() {
168 if(ui.networkList->selectedItems().count()) {
169 NetworkId id = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
170 const Network *net = 0;
171 if(id > 0) net = Client::network(id);
172 ui.detailsBox->setEnabled(true);
173 ui.renameNetwork->setEnabled(true);
174 ui.deleteNetwork->setEnabled(true);
175 ui.connectNow->setEnabled(net);
176 // && (Client::network(id)->connectionState() == Network::Initialized
177 // || Client::network(id)->connectionState() == Network::Disconnected));
179 if(net->connectionState() == Network::Disconnected) {
180 ui.connectNow->setIcon(connectedIcon);
181 ui.connectNow->setText(tr("Connect"));
183 ui.connectNow->setIcon(disconnectedIcon);
184 ui.connectNow->setText(tr("Disconnect"));
187 ui.connectNow->setIcon(QIcon());
188 ui.connectNow->setText(tr("Apply first!"));
191 ui.renameNetwork->setEnabled(false);
192 ui.deleteNetwork->setEnabled(false);
193 ui.connectNow->setEnabled(false);
194 ui.detailsBox->setEnabled(false);
197 if(ui.serverList->selectedItems().count()) {
198 ui.editServer->setEnabled(true);
199 ui.deleteServer->setEnabled(true);
200 ui.upServer->setEnabled(ui.serverList->currentRow() > 0);
201 ui.downServer->setEnabled(ui.serverList->currentRow() < ui.serverList->count() - 1);
203 ui.editServer->setEnabled(false);
204 ui.deleteServer->setEnabled(false);
205 ui.upServer->setEnabled(false);
206 ui.downServer->setEnabled(false);
210 void NetworksSettingsPage::setItemState(NetworkId id, QListWidgetItem *item) {
211 if(!item && !(item = networkItem(id))) return;
212 const Network *net = Client::network(id);
213 if(!net || net->isInitialized()) item->setFlags(item->flags() | Qt::ItemIsEnabled);
214 else item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
215 if(net && net->connectionState() == Network::Initialized) {
216 item->setIcon(connectedIcon);
217 } else if(net && net->connectionState() != Network::Disconnected) {
218 item->setIcon(connectingIcon);
220 item->setIcon(disconnectedIcon);
224 // check if we already have another net of this name in the list, and replace it
225 QList<QListWidgetItem *> items = ui.networkList->findItems(net->networkName(), Qt::MatchExactly);
227 foreach(QListWidgetItem *i, items) {
228 NetworkId oldid = i->data(Qt::UserRole).value<NetworkId>();
229 if(oldid > 0) continue; // only locally created nets should be replaced
230 if(oldid == currentId) {
233 ui.networkList->clearSelection();
235 int row = ui.networkList->row(i);
237 QListWidgetItem *olditem = ui.networkList->takeItem(row);
241 networkInfos.remove(oldid);
245 item->setText(net->networkName());
246 if(select) item->setSelected(true);
250 void NetworksSettingsPage::coreConnectionStateChanged(bool state) {
251 this->setEnabled(state);
260 void NetworksSettingsPage::clientIdentityAdded(IdentityId id) {
261 const Identity * identity = Client::identity(id);
262 connect(identity, SIGNAL(updatedRemotely()), this, SLOT(clientIdentityUpdated()));
265 // default identity is always the first one!
266 ui.identityList->insertItem(0, identity->identityName(), id.toInt());
268 QString name = identity->identityName();
269 for(int j = 0; j < ui.identityList->count(); j++) {
270 if((j>0 || ui.identityList->itemData(0).toInt() != 1) && name.localeAwareCompare(ui.identityList->itemText(j)) < 0) {
271 ui.identityList->insertItem(j, name, id.toInt());
277 ui.identityList->insertItem(ui.identityList->count(), name, id.toInt());
282 void NetworksSettingsPage::clientIdentityUpdated() {
283 const Identity *identity = qobject_cast<const Identity *>(sender());
285 qWarning() << "NetworksSettingsPage: Invalid identity to update!";
288 int row = ui.identityList->findData(identity->id().toInt());
290 qWarning() << "NetworksSettingsPage: Invalid identity to update!";
293 if(ui.identityList->itemText(row) != identity->identityName()) {
294 ui.identityList->setItemText(row, identity->identityName());
298 void NetworksSettingsPage::clientIdentityRemoved(IdentityId id) {
299 if(currentId != 0) saveToNetworkInfo(networkInfos[currentId]);
300 //ui.identityList->removeItem(ui.identityList->findData(id.toInt()));
301 foreach(NetworkInfo info, networkInfos.values()) {
302 //qDebug() << info.networkName << info.networkId << info.identity;
303 if(info.identity == id) {
304 if(info.networkId == currentId) ui.identityList->setCurrentIndex(0);
305 info.identity = 1; // set to default
306 networkInfos[info.networkId] = info;
307 if(info.networkId > 0) Client::updateNetwork(info);
310 ui.identityList->removeItem(ui.identityList->findData(id.toInt()));
314 QListWidgetItem *NetworksSettingsPage::networkItem(NetworkId id) const {
315 for(int i = 0; i < ui.networkList->count(); i++) {
316 QListWidgetItem *item = ui.networkList->item(i);
317 if(item->data(Qt::UserRole).value<NetworkId>() == id) return item;
322 void NetworksSettingsPage::clientNetworkAdded(NetworkId id) {
324 connect(Client::network(id), SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
325 connect(Client::network(id), SIGNAL(connectionStateSet(Network::ConnectionState)), this, SLOT(networkConnectionStateChanged(Network::ConnectionState)));
326 connect(Client::network(id), SIGNAL(connectionError(const QString &)), this, SLOT(networkConnectionError(const QString &)));
329 void NetworksSettingsPage::clientNetworkUpdated() {
330 const Network *net = qobject_cast<const Network *>(sender());
332 qWarning() << "Update request for unknown network received!";
335 networkInfos[net->networkId()] = net->networkInfo();
336 setItemState(net->networkId());
337 if(net->networkId() == currentId) displayNetwork(net->networkId());
342 void NetworksSettingsPage::clientNetworkRemoved(NetworkId id) {
343 if(!networkInfos.contains(id)) return;
344 if(id == currentId) displayNetwork(0);
345 NetworkInfo info = networkInfos.take(id);
346 QList<QListWidgetItem *> items = ui.networkList->findItems(info.networkName, Qt::MatchExactly);
347 foreach(QListWidgetItem *item, items) {
348 if(item->data(Qt::UserRole).value<NetworkId>() == id)
349 delete ui.networkList->takeItem(ui.networkList->row(item));
355 void NetworksSettingsPage::networkConnectionStateChanged(Network::ConnectionState state) {
356 const Network *net = qobject_cast<const Network *>(sender());
358 if(net->networkId() == currentId) {
359 ui.connectNow->setEnabled(state == Network::Initialized || state == Network::Disconnected);
361 setItemState(net->networkId());
364 void NetworksSettingsPage::networkConnectionError(const QString &) {
368 QListWidgetItem *NetworksSettingsPage::insertNetwork(NetworkId id) {
369 NetworkInfo info = Client::network(id)->networkInfo();
370 networkInfos[id] = info;
371 return insertNetwork(info);
374 QListWidgetItem *NetworksSettingsPage::insertNetwork(const NetworkInfo &info) {
375 QListWidgetItem *item = 0;
376 QList<QListWidgetItem *> items = ui.networkList->findItems(info.networkName, Qt::MatchExactly);
377 if(!items.count()) item = new QListWidgetItem(disconnectedIcon, info.networkName, ui.networkList);
379 // we overwrite an existing net if it a) has the same name and b) has a negative ID meaning we created it locally before
380 // -> then we can be sure that this is the core-side replacement for the net we created
381 foreach(QListWidgetItem *i, items) {
382 NetworkId id = i->data(Qt::UserRole).value<NetworkId>();
383 if(id < 0) { item = i; break; }
385 if(!item) item = new QListWidgetItem(disconnectedIcon, info.networkName, ui.networkList);
387 item->setData(Qt::UserRole, QVariant::fromValue<NetworkId>(info.networkId));
388 setItemState(info.networkId, item);
393 void NetworksSettingsPage::displayNetwork(NetworkId id) {
394 _ignoreWidgetChanges = true;
396 NetworkInfo info = networkInfos[id];
397 ui.identityList->setCurrentIndex(ui.identityList->findData(info.identity.toInt()));
398 ui.serverList->clear();
399 foreach(QVariant v, info.serverList) {
400 ui.serverList->addItem(QString("%1:%2").arg(v.toMap()["Host"].toString()).arg(v.toMap()["Port"].toUInt()));
403 ui.randomServer->setChecked(info.useRandomServer);
404 ui.performEdit->setPlainText(info.perform.join("\n"));
405 ui.autoIdentify->setChecked(info.useAutoIdentify);
406 ui.autoIdentifyService->setText(info.autoIdentifyService);
407 ui.autoIdentifyPassword->setText(info.autoIdentifyPassword);
408 if(info.codecForEncoding.isEmpty()) {
409 ui.sendEncoding->setCurrentIndex(ui.sendEncoding->findText(Network::defaultCodecForEncoding()));
410 ui.recvEncoding->setCurrentIndex(ui.recvEncoding->findText(Network::defaultCodecForDecoding()));
411 ui.useDefaultEncodings->setChecked(true);
413 ui.sendEncoding->setCurrentIndex(ui.sendEncoding->findText(info.codecForEncoding));
414 ui.recvEncoding->setCurrentIndex(ui.recvEncoding->findText(info.codecForDecoding));
415 ui.useDefaultEncodings->setChecked(false);
417 ui.autoReconnect->setChecked(info.useAutoReconnect);
418 ui.reconnectInterval->setValue(info.autoReconnectInterval);
419 ui.reconnectRetries->setValue(info.autoReconnectRetries);
420 ui.unlimitedRetries->setChecked(info.unlimitedReconnectRetries);
421 ui.rejoinOnReconnect->setChecked(info.rejoinChannels);
423 // just clear widgets
424 ui.identityList->setCurrentIndex(-1);
425 ui.serverList->clear();
426 ui.performEdit->clear();
427 ui.autoIdentifyService->clear();
428 ui.autoIdentifyPassword->clear();
431 _ignoreWidgetChanges = false;
435 void NetworksSettingsPage::saveToNetworkInfo(NetworkInfo &info) {
436 info.identity = ui.identityList->itemData(ui.identityList->currentIndex()).toInt();
437 info.useRandomServer = ui.randomServer->isChecked();
438 info.perform = ui.performEdit->toPlainText().split("\n");
439 info.useAutoIdentify = ui.autoIdentify->isChecked();
440 info.autoIdentifyService = ui.autoIdentifyService->text();
441 info.autoIdentifyPassword = ui.autoIdentifyPassword->text();
442 if(ui.useDefaultEncodings->isChecked()) {
443 info.codecForEncoding.clear();
444 info.codecForDecoding.clear();
446 info.codecForEncoding = ui.sendEncoding->currentText().toLatin1();
447 info.codecForDecoding = ui.recvEncoding->currentText().toLatin1();
449 info.useAutoReconnect = ui.autoReconnect->isChecked();
450 info.autoReconnectInterval = ui.reconnectInterval->value();
451 info.autoReconnectRetries = ui.reconnectRetries->value();
452 info.unlimitedReconnectRetries = ui.unlimitedRetries->isChecked();
453 info.rejoinChannels = ui.rejoinOnReconnect->isChecked();
455 /*** Network list ***/
457 void NetworksSettingsPage::on_networkList_itemSelectionChanged() {
459 saveToNetworkInfo(networkInfos[currentId]);
461 if(ui.networkList->selectedItems().count()) {
462 NetworkId id = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
465 ui.serverList->setCurrentRow(0);
472 void NetworksSettingsPage::on_addNetwork_clicked() {
473 QStringList existing;
474 for(int i = 0; i < ui.networkList->count(); i++) existing << ui.networkList->item(i)->text();
475 NetworkEditDlg dlg(QString(), existing, this);
476 if(dlg.exec() == QDialog::Accepted) {
478 for(id = 1; id <= networkInfos.count(); id++) {
480 if(!networkInfos.keys().contains(-id.toInt())) break;
485 info.networkName = dlg.networkName();
489 info.useRandomServer = false;
490 info.useAutoReconnect = true;
491 info.autoReconnectInterval = 60;
492 info.autoReconnectRetries = 20;
493 info.unlimitedReconnectRetries = false;
494 info.useAutoIdentify = false;
495 info.autoIdentifyService = "NickServ";
496 info.rejoinChannels = true;
498 networkInfos[id] = info;
499 QListWidgetItem *item = insertNetwork(info);
500 ui.networkList->setCurrentItem(item);
505 void NetworksSettingsPage::on_deleteNetwork_clicked() {
506 if(ui.networkList->selectedItems().count()) {
507 NetworkId netid = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
508 int ret = QMessageBox::question(this, tr("Delete Network?"),
509 tr("Do you really want to delete the network \"%1\" and all related settings, including the backlog?").arg(networkInfos[netid].networkName),
510 QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
511 if(ret == QMessageBox::Yes) {
513 networkInfos.remove(netid);
514 delete ui.networkList->takeItem(ui.networkList->row(ui.networkList->selectedItems()[0]));
515 ui.networkList->setCurrentRow(qMin(ui.networkList->currentRow()+1, ui.networkList->count()-1));
522 void NetworksSettingsPage::on_renameNetwork_clicked() {
523 if(!ui.networkList->selectedItems().count()) return;
524 QString old = ui.networkList->selectedItems()[0]->text();
525 QStringList existing;
526 for(int i = 0; i < ui.networkList->count(); i++) existing << ui.networkList->item(i)->text();
527 NetworkEditDlg dlg(old, existing, this);
528 if(dlg.exec() == QDialog::Accepted) {
529 ui.networkList->selectedItems()[0]->setText(dlg.networkName());
530 NetworkId netid = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
531 networkInfos[netid].networkName = dlg.networkName();
536 void NetworksSettingsPage::on_connectNow_clicked() {
537 if(!ui.networkList->selectedItems().count()) return;
538 NetworkId id = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
539 const Network *net = Client::network(id);
541 if(net->connectionState() == Network::Disconnected) net->requestConnect();
542 else net->requestDisconnect();
545 /*** Server list ***/
547 void NetworksSettingsPage::on_serverList_itemSelectionChanged() {
551 void NetworksSettingsPage::on_addServer_clicked() {
552 if(currentId == 0) return;
553 ServerEditDlg dlg(QVariantMap(), this);
554 if(dlg.exec() == QDialog::Accepted) {
555 networkInfos[currentId].serverList.append(dlg.serverData());
556 displayNetwork(currentId);
557 ui.serverList->setCurrentRow(ui.serverList->count()-1);
563 void NetworksSettingsPage::on_editServer_clicked() {
564 if(currentId == 0) return;
565 int cur = ui.serverList->currentRow();
566 ServerEditDlg dlg(networkInfos[currentId].serverList[cur], this);
567 if(dlg.exec() == QDialog::Accepted) {
568 networkInfos[currentId].serverList[cur] = dlg.serverData();
569 displayNetwork(currentId);
570 ui.serverList->setCurrentRow(cur);
575 void NetworksSettingsPage::on_deleteServer_clicked() {
576 if(currentId == 0) return;
577 int cur = ui.serverList->currentRow();
578 networkInfos[currentId].serverList.removeAt(cur);
579 displayNetwork(currentId);
580 ui.serverList->setCurrentRow(qMin(cur, ui.serverList->count()-1));
584 void NetworksSettingsPage::on_upServer_clicked() {
585 int cur = ui.serverList->currentRow();
586 QVariant foo = networkInfos[currentId].serverList.takeAt(cur);
587 networkInfos[currentId].serverList.insert(cur-1, foo);
588 displayNetwork(currentId);
589 ui.serverList->setCurrentRow(cur-1);
593 void NetworksSettingsPage::on_downServer_clicked() {
594 int cur = ui.serverList->currentRow();
595 QVariant foo = networkInfos[currentId].serverList.takeAt(cur);
596 networkInfos[currentId].serverList.insert(cur+1, foo);
597 displayNetwork(currentId);
598 ui.serverList->setCurrentRow(cur+1);
602 /**************************************************************************
604 *************************************************************************/
606 NetworkEditDlg::NetworkEditDlg(const QString &old, const QStringList &exist, QWidget *parent) : QDialog(parent), existing(exist) {
611 setWindowTitle(tr("Add Network"));
612 on_networkEdit_textChanged(""); // disable ok button
613 } else ui.networkEdit->setText(old);
616 QString NetworkEditDlg::networkName() const {
617 return ui.networkEdit->text();
621 void NetworkEditDlg::on_networkEdit_textChanged(const QString &text) {
622 ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(text.isEmpty() || existing.contains(text));
626 /**************************************************************************
628 *************************************************************************/
630 ServerEditDlg::ServerEditDlg(const QVariant &_serverData, QWidget *parent) : QDialog(parent) {
632 QVariantMap serverData = _serverData.toMap();
633 if(serverData.count()) {
634 ui.host->setText(serverData["Host"].toString());
635 ui.port->setValue(serverData["Port"].toUInt());
636 ui.password->setText(serverData["Password"].toString());
637 ui.useSSL->setChecked(serverData["UseSSL"].toBool());
639 ui.port->setValue(6667);
641 on_host_textChanged();
644 QVariant ServerEditDlg::serverData() const {
645 QVariantMap _serverData;
646 _serverData["Host"] = ui.host->text().trimmed();
647 _serverData["Port"] = ui.port->value();
648 _serverData["Password"] = ui.password->text();
649 _serverData["UseSSL"] = ui.useSSL->isChecked();
653 void ServerEditDlg::on_host_textChanged() {
654 ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(ui.host->text().trimmed().isEmpty());
657 /**************************************************************************
659 *************************************************************************/
661 SaveNetworksDlg::SaveNetworksDlg(const QList<NetworkInfo> &toCreate, const QList<NetworkInfo> &toUpdate, const QList<NetworkId> &toRemove, QWidget *parent) : QDialog(parent)
665 numevents = toCreate.count() + toUpdate.count() + toRemove.count();
668 ui.progressBar->setMaximum(numevents);
669 ui.progressBar->setValue(0);
671 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(clientEvent()));
672 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), this, SLOT(clientEvent()));
674 foreach(NetworkInfo info, toCreate) {
675 Client::createNetwork(info);
677 foreach(NetworkInfo info, toUpdate) {
678 const Network *net = Client::network(info.networkId);
680 qWarning() << "Invalid client network!";
684 // FIXME this only checks for one changed item rather than all!
685 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientEvent()));
686 Client::updateNetwork(info);
688 foreach(NetworkId id, toRemove) {
689 Client::removeNetwork(id);
692 qWarning() << "Sync dialog called without stuff to change!";
697 void SaveNetworksDlg::clientEvent() {
698 ui.progressBar->setValue(++rcvevents);
699 if(rcvevents >= numevents) accept();