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) {
36 connectedIcon = QIcon(":/22x22/actions/network-connect");
37 connectingIcon = QIcon(":/22x22/actions/gear");
38 disconnectedIcon = QIcon(":/22x22/actions/network-disconnect");
40 foreach(int mib, QTextCodec::availableMibs()) {
41 QByteArray codec = QTextCodec::codecForMib(mib)->name();
42 ui.sendEncoding->addItem(codec);
43 ui.recvEncoding->addItem(codec);
45 ui.sendEncoding->model()->sort(0);
46 ui.recvEncoding->model()->sort(0);
48 setEnabled(Client::isConnected()); // need a core connection!
50 connect(Client::instance(), SIGNAL(coreConnectionStateChanged(bool)), this, SLOT(coreConnectionStateChanged(bool)));
51 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(clientNetworkAdded(NetworkId)));
52 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), this, SLOT(clientNetworkRemoved(NetworkId)));
53 connect(Client::instance(), SIGNAL(identityCreated(IdentityId)), this, SLOT(clientIdentityAdded(IdentityId)));
54 connect(Client::instance(), SIGNAL(identityRemoved(IdentityId)), this, SLOT(clientIdentityRemoved(IdentityId)));
56 connect(ui.identityList, SIGNAL(currentIndexChanged(int)), this, SLOT(widgetHasChanged()));
57 connect(ui.randomServer, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
58 connect(ui.performEdit, SIGNAL(textChanged()), this, SLOT(widgetHasChanged()));
59 connect(ui.autoIdentify, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
60 connect(ui.autoIdentifyService, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged()));
61 connect(ui.autoIdentifyPassword, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged()));
62 connect(ui.useDefaultEncodings, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
63 connect(ui.sendEncoding, SIGNAL(currentIndexChanged(int)), this, SLOT(widgetHasChanged()));
64 connect(ui.recvEncoding, SIGNAL(currentIndexChanged(int)), this, SLOT(widgetHasChanged()));
65 connect(ui.autoReconnect, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
66 connect(ui.reconnectInterval, SIGNAL(valueChanged(int)), this, SLOT(widgetHasChanged()));
67 connect(ui.reconnectRetries, SIGNAL(valueChanged(int)), this, SLOT(widgetHasChanged()));
68 connect(ui.unlimitedRetries, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
69 connect(ui.rejoinOnReconnect, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
70 //connect(ui., SIGNAL(), this, SLOT(widgetHasChanged()));
71 //connect(ui., SIGNAL(), this, SLOT(widgetHasChanged()));
73 foreach(IdentityId id, Client::identityIds()) {
74 clientIdentityAdded(id);
78 void NetworksSettingsPage::save() {
80 if(currentId != 0) saveToNetworkInfo(networkInfos[currentId]);
82 QList<NetworkInfo> toCreate, toUpdate;
83 QList<NetworkId> toRemove;
84 QHash<NetworkId, NetworkInfo>::iterator i = networkInfos.begin();
85 while(i != networkInfos.end()) {
86 NetworkId id = (*i).networkId;
89 //if(id == currentId) currentId = 0;
90 //QList<QListWidgetItem *> items = ui.networkList->findItems((*i).networkName, Qt::MatchExactly);
92 // Q_ASSERT(items[0]->data(Qt::UserRole).value<NetworkId>() == id);
95 //i = networkInfos.erase(i);
98 if((*i) != Client::network((*i).networkId)->networkInfo()) {
104 foreach(NetworkId id, Client::networkIds()) {
105 if(!networkInfos.contains(id)) toRemove.append(id);
107 SaveNetworksDlg dlg(toCreate, toUpdate, toRemove, this);
108 int ret = dlg.exec();
109 if(ret == QDialog::Rejected) {
110 // canceled -> reload everything to be safe
113 setChangedState(false);
117 void NetworksSettingsPage::load() {
119 foreach(NetworkId netid, Client::networkIds()) {
120 clientNetworkAdded(netid);
122 ui.networkList->setCurrentRow(0);
123 setChangedState(false);
126 void NetworksSettingsPage::reset() {
128 ui.networkList->clear();
129 networkInfos.clear();
133 bool NetworksSettingsPage::aboutToSave() {
134 if(currentId != 0) saveToNetworkInfo(networkInfos[currentId]);
136 foreach(NetworkInfo info, networkInfos.values()) {
137 if(!info.serverList.count()) errors.append(1);
139 if(!errors.count()) return true;
140 QString error(tr("<b>The following problems need to be corrected before your changes can be applied:</b><ul>"));
141 if(errors.contains(1)) error += tr("<li>All networks need at least one server defined</li>");
142 error += tr("</ul>");
143 QMessageBox::warning(this, tr("Invalid Network Settings"), error);
147 void NetworksSettingsPage::widgetHasChanged() {
148 bool changed = testHasChanged();
149 if(changed != hasChanged()) setChangedState(changed);
152 bool NetworksSettingsPage::testHasChanged() {
154 saveToNetworkInfo(networkInfos[currentId]);
156 if(Client::networkIds().count() != networkInfos.count()) return true;
157 foreach(NetworkId id, networkInfos.keys()) {
158 if(id < 0) return true;
159 if(Client::network(id)->networkInfo() != networkInfos[id]) return true;
164 void NetworksSettingsPage::setWidgetStates() {
166 if(ui.networkList->selectedItems().count()) {
167 NetworkId id = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
168 ui.detailsBox->setEnabled(true);
169 ui.renameNetwork->setEnabled(true);
170 ui.deleteNetwork->setEnabled(true);
171 ui.connectNow->setEnabled(id > 0
172 && (Client::network(id)->connectionState() == Network::Initialized
173 || Client::network(id)->connectionState() == Network::Disconnected));
174 if(Client::network(id) && Client::network(id)->isConnected()) {
175 ui.connectNow->setIcon(disconnectedIcon);
176 ui.connectNow->setText(tr("Disconnect"));
178 ui.connectNow->setIcon(connectedIcon);
179 ui.connectNow->setText(tr("Connect"));
182 ui.renameNetwork->setEnabled(false);
183 ui.deleteNetwork->setEnabled(false);
184 ui.connectNow->setEnabled(false);
185 ui.detailsBox->setEnabled(false);
188 if(ui.serverList->selectedItems().count()) {
189 ui.editServer->setEnabled(true);
190 ui.deleteServer->setEnabled(true);
191 ui.upServer->setEnabled(ui.serverList->currentRow() > 0);
192 ui.downServer->setEnabled(ui.serverList->currentRow() < ui.serverList->count() - 1);
194 ui.editServer->setEnabled(false);
195 ui.deleteServer->setEnabled(false);
196 ui.upServer->setEnabled(false);
197 ui.downServer->setEnabled(false);
201 void NetworksSettingsPage::setItemState(NetworkId id, QListWidgetItem *item) {
202 if(!item && !(item = networkItem(id))) return;
203 const Network *net = Client::network(id);
204 if(!net || net->isInitialized()) item->setFlags(item->flags() | Qt::ItemIsEnabled);
205 else item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
206 if(net && net->connectionState() == Network::Initialized) {
207 item->setIcon(connectedIcon);
208 } else if(net && net->connectionState() != Network::Disconnected) {
209 item->setIcon(connectingIcon);
211 item->setIcon(disconnectedIcon);
215 // check if we already have another net of this name in the list, and replace it
216 QList<QListWidgetItem *> items = ui.networkList->findItems(net->networkName(), Qt::MatchExactly);
218 foreach(QListWidgetItem *i, items) {
219 NetworkId oldid = i->data(Qt::UserRole).value<NetworkId>();
220 if(oldid > 0) continue; // only locally created nets should be replaced
221 if(oldid == currentId) {
225 int row = ui.networkList->row(i);
227 qDebug() << "ABOUT TO REMOVE: id=" << oldid << "from row" << row;
228 QListWidgetItem *olditem = ui.networkList->takeItem(row);
229 qDebug() << "Successfully removed item from list.";
231 qWarning() << "NetworksSettingsPage::setItemState(): Why the heck don't we have an itempointer here?";
232 Q_ASSERT(olditem); // abort non-gracefully, I need to figure out what's causing this
236 networkInfos.remove(oldid);
240 item->setText(net->networkName());
241 if(select) item->setSelected(true);
245 void NetworksSettingsPage::coreConnectionStateChanged(bool state) {
246 this->setEnabled(state);
255 void NetworksSettingsPage::clientIdentityAdded(IdentityId id) {
256 const Identity * identity = Client::identity(id);
257 connect(identity, SIGNAL(updatedRemotely()), this, SLOT(clientIdentityUpdated()));
260 // default identity is always the first one!
261 ui.identityList->insertItem(0, identity->identityName(), id.toInt());
263 QString name = identity->identityName();
264 for(int j = 0; j < ui.identityList->count(); j++) {
265 if((j>0 || ui.identityList->itemData(0).toInt() != 1) && name.localeAwareCompare(ui.identityList->itemText(j)) < 0) {
266 ui.identityList->insertItem(j, name, id.toInt());
272 ui.identityList->insertItem(ui.identityList->count(), name, id.toInt());
277 void NetworksSettingsPage::clientIdentityUpdated() {
278 const Identity *identity = qobject_cast<const Identity *>(sender());
280 qWarning() << "NetworksSettingsPage: Invalid identity to update!";
283 int row = ui.identityList->findData(identity->id().toInt());
285 qWarning() << "NetworksSettingsPage: Invalid identity to update!";
288 if(ui.identityList->itemText(row) != identity->identityName()) {
289 ui.identityList->setItemText(row, identity->identityName());
293 void NetworksSettingsPage::clientIdentityRemoved(IdentityId id) {
294 if(currentId != 0) saveToNetworkInfo(networkInfos[currentId]);
295 //ui.identityList->removeItem(ui.identityList->findData(id.toInt()));
296 foreach(NetworkInfo info, networkInfos.values()) {
297 //qDebug() << info.networkName << info.networkId << info.identity;
298 if(info.identity == id) {
299 if(info.networkId == currentId) ui.identityList->setCurrentIndex(0);
300 info.identity = 1; // set to default
301 networkInfos[info.networkId] = info;
302 if(info.networkId > 0) Client::updateNetwork(info);
305 ui.identityList->removeItem(ui.identityList->findData(id.toInt()));
309 QListWidgetItem *NetworksSettingsPage::networkItem(NetworkId id) const {
310 for(int i = 0; i < ui.networkList->count(); i++) {
311 QListWidgetItem *item = ui.networkList->item(i);
312 if(item->data(Qt::UserRole).value<NetworkId>() == id) return item;
317 void NetworksSettingsPage::clientNetworkAdded(NetworkId id) {
319 connect(Client::network(id), SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
320 connect(Client::network(id), SIGNAL(connectionStateSet(Network::ConnectionState)), this, SLOT(networkConnectionStateChanged(Network::ConnectionState)));
321 connect(Client::network(id), SIGNAL(connectionError(const QString &)), this, SLOT(networkConnectionError(const QString &)));
324 void NetworksSettingsPage::clientNetworkUpdated() {
325 const Network *net = qobject_cast<const Network *>(sender());
327 qWarning() << "Update request for unknown network received!";
330 networkInfos[net->networkId()] = net->networkInfo();
331 setItemState(net->networkId());
332 if(net->networkId() == currentId) displayNetwork(net->networkId());
337 void NetworksSettingsPage::clientNetworkRemoved(NetworkId id) {
338 if(!networkInfos.contains(id)) return;
339 if(id == currentId) displayNetwork(0);
340 NetworkInfo info = networkInfos.take(id);
341 QList<QListWidgetItem *> items = ui.networkList->findItems(info.networkName, Qt::MatchExactly);
342 foreach(QListWidgetItem *item, items) {
343 if(item->data(Qt::UserRole).value<NetworkId>() == id)
344 delete ui.networkList->takeItem(ui.networkList->row(item));
350 void NetworksSettingsPage::networkConnectionStateChanged(Network::ConnectionState state) {
351 const Network *net = qobject_cast<const Network *>(sender());
353 if(net->networkId() == currentId) {
354 ui.connectNow->setEnabled(state == Network::Initialized || state == Network::Disconnected);
356 setItemState(net->networkId());
359 void NetworksSettingsPage::networkConnectionError(const QString &) {
363 QListWidgetItem *NetworksSettingsPage::insertNetwork(NetworkId id) {
364 NetworkInfo info = Client::network(id)->networkInfo();
365 networkInfos[id] = info;
366 return insertNetwork(info);
369 QListWidgetItem *NetworksSettingsPage::insertNetwork(const NetworkInfo &info) {
370 QListWidgetItem *item = 0;
371 QList<QListWidgetItem *> items = ui.networkList->findItems(info.networkName, Qt::MatchExactly);
372 if(!items.count()) item = new QListWidgetItem(disconnectedIcon, info.networkName, ui.networkList);
374 // we overwrite an existing net if it a) has the same name and b) has a negative ID meaning we created it locally before
375 // -> then we can be sure that this is the core-side replacement for the net we created
376 foreach(QListWidgetItem *i, items) {
377 NetworkId id = i->data(Qt::UserRole).value<NetworkId>();
378 if(id < 0) { item = i; break; }
380 if(!item) item = new QListWidgetItem(disconnectedIcon, info.networkName, ui.networkList);
382 item->setData(Qt::UserRole, QVariant::fromValue<NetworkId>(info.networkId));
383 setItemState(info.networkId, item);
388 void NetworksSettingsPage::displayNetwork(NetworkId id) {
390 NetworkInfo info = networkInfos[id];
391 ui.identityList->setCurrentIndex(ui.identityList->findData(info.identity.toInt()));
392 ui.serverList->clear();
393 foreach(QVariant v, info.serverList) {
394 ui.serverList->addItem(QString("%1:%2").arg(v.toMap()["Host"].toString()).arg(v.toMap()["Port"].toUInt()));
397 ui.randomServer->setChecked(info.useRandomServer);
398 ui.performEdit->setPlainText(info.perform.join("\n"));
399 ui.autoIdentify->setChecked(info.useAutoIdentify);
400 ui.autoIdentifyService->setText(info.autoIdentifyService);
401 ui.autoIdentifyPassword->setText(info.autoIdentifyPassword);
402 if(info.codecForEncoding.isEmpty()) {
403 ui.sendEncoding->setCurrentIndex(ui.sendEncoding->findText(Network::defaultCodecForEncoding()));
404 ui.recvEncoding->setCurrentIndex(ui.recvEncoding->findText(Network::defaultCodecForDecoding()));
405 ui.useDefaultEncodings->setChecked(true);
407 ui.sendEncoding->setCurrentIndex(ui.sendEncoding->findText(info.codecForEncoding));
408 ui.recvEncoding->setCurrentIndex(ui.recvEncoding->findText(info.codecForDecoding));
409 ui.useDefaultEncodings->setChecked(false);
411 ui.autoReconnect->setChecked(info.useAutoReconnect);
412 ui.reconnectInterval->setValue(info.autoReconnectInterval);
413 ui.reconnectRetries->setValue(info.autoReconnectRetries);
414 ui.unlimitedRetries->setChecked(info.unlimitedReconnectRetries);
415 ui.rejoinOnReconnect->setChecked(info.rejoinChannels);
417 // just clear widgets
418 ui.identityList->setCurrentIndex(-1);
419 ui.serverList->clear();
420 ui.performEdit->clear();
426 void NetworksSettingsPage::saveToNetworkInfo(NetworkInfo &info) {
427 info.identity = ui.identityList->itemData(ui.identityList->currentIndex()).toInt();
428 info.useRandomServer = ui.randomServer->isChecked();
429 info.perform = ui.performEdit->toPlainText().split("\n");
430 info.useAutoIdentify = ui.autoIdentify->isChecked();
431 info.autoIdentifyService = ui.autoIdentifyService->text();
432 info.autoIdentifyPassword = ui.autoIdentifyPassword->text();
433 if(ui.useDefaultEncodings->isChecked()) {
434 info.codecForEncoding.clear();
435 info.codecForDecoding.clear();
437 info.codecForEncoding = ui.sendEncoding->currentText().toLatin1();
438 info.codecForDecoding = ui.recvEncoding->currentText().toLatin1();
440 info.useAutoReconnect = ui.autoReconnect->isChecked();
441 info.autoReconnectInterval = ui.reconnectInterval->value();
442 info.autoReconnectRetries = ui.reconnectRetries->value();
443 info.unlimitedReconnectRetries = ui.unlimitedRetries->isChecked();
444 info.rejoinChannels = ui.rejoinOnReconnect->isChecked();
446 /*** Network list ***/
448 void NetworksSettingsPage::on_networkList_itemSelectionChanged() {
450 saveToNetworkInfo(networkInfos[currentId]);
452 if(ui.networkList->selectedItems().count()) {
453 NetworkId id = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
456 ui.serverList->setCurrentRow(0);
463 void NetworksSettingsPage::on_addNetwork_clicked() {
464 QStringList existing;
465 for(int i = 0; i < ui.networkList->count(); i++) existing << ui.networkList->item(i)->text();
466 NetworkEditDlg dlg(QString(), existing, this);
467 if(dlg.exec() == QDialog::Accepted) {
469 for(id = 1; id <= networkInfos.count(); id++) {
471 if(!networkInfos.keys().contains(-id.toInt())) break;
476 info.networkName = dlg.networkName();
480 info.useRandomServer = false;
481 info.useAutoReconnect = true;
482 info.autoReconnectInterval = 60;
483 info.autoReconnectRetries = 20;
484 info.unlimitedReconnectRetries = false;
485 info.useAutoIdentify = false;
486 info.autoIdentifyService = "NickServ";
487 info.rejoinChannels = true;
489 networkInfos[id] = info;
490 QListWidgetItem *item = insertNetwork(info);
491 ui.networkList->setCurrentItem(item);
496 void NetworksSettingsPage::on_deleteNetwork_clicked() {
497 if(ui.networkList->selectedItems().count()) {
498 NetworkId netid = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
499 int ret = QMessageBox::question(this, tr("Delete Network?"),
500 tr("Do you really want to delete the network \"%1\" and all related settings, including the backlog?").arg(networkInfos[netid].networkName),
501 QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
502 if(ret == QMessageBox::Yes) {
504 networkInfos.remove(netid);
505 delete ui.networkList->takeItem(ui.networkList->row(ui.networkList->selectedItems()[0]));
506 ui.networkList->setCurrentRow(qMin(ui.networkList->currentRow()+1, ui.networkList->count()-1));
513 void NetworksSettingsPage::on_renameNetwork_clicked() {
514 if(!ui.networkList->selectedItems().count()) return;
515 QString old = ui.networkList->selectedItems()[0]->text();
516 QStringList existing;
517 for(int i = 0; i < ui.networkList->count(); i++) existing << ui.networkList->item(i)->text();
518 NetworkEditDlg dlg(old, existing, this);
519 if(dlg.exec() == QDialog::Accepted) {
520 ui.networkList->selectedItems()[0]->setText(dlg.networkName());
521 NetworkId netid = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
522 networkInfos[netid].networkName = dlg.networkName();
527 void NetworksSettingsPage::on_connectNow_clicked() {
528 if(!ui.networkList->selectedItems().count()) return;
529 NetworkId id = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
530 const Network *net = Client::network(id);
532 if(!net->isConnected()) net->requestConnect();
533 else net->requestDisconnect();
536 /*** Server list ***/
538 void NetworksSettingsPage::on_serverList_itemSelectionChanged() {
542 void NetworksSettingsPage::on_addServer_clicked() {
543 if(currentId == 0) return;
544 ServerEditDlg dlg(QVariantMap(), this);
545 if(dlg.exec() == QDialog::Accepted) {
546 networkInfos[currentId].serverList.append(dlg.serverData());
547 displayNetwork(currentId);
548 ui.serverList->setCurrentRow(ui.serverList->count()-1);
554 void NetworksSettingsPage::on_editServer_clicked() {
555 if(currentId == 0) return;
556 int cur = ui.serverList->currentRow();
557 ServerEditDlg dlg(networkInfos[currentId].serverList[cur], this);
558 if(dlg.exec() == QDialog::Accepted) {
559 networkInfos[currentId].serverList[cur] = dlg.serverData();
560 displayNetwork(currentId);
561 ui.serverList->setCurrentRow(cur);
566 void NetworksSettingsPage::on_deleteServer_clicked() {
567 if(currentId == 0) return;
568 int cur = ui.serverList->currentRow();
569 networkInfos[currentId].serverList.removeAt(cur);
570 displayNetwork(currentId);
571 ui.serverList->setCurrentRow(qMin(cur, ui.serverList->count()-1));
575 void NetworksSettingsPage::on_upServer_clicked() {
576 int cur = ui.serverList->currentRow();
577 QVariant foo = networkInfos[currentId].serverList.takeAt(cur);
578 networkInfos[currentId].serverList.insert(cur-1, foo);
579 displayNetwork(currentId);
580 ui.serverList->setCurrentRow(cur-1);
584 void NetworksSettingsPage::on_downServer_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 /**************************************************************************
595 *************************************************************************/
597 NetworkEditDlg::NetworkEditDlg(const QString &old, const QStringList &exist, QWidget *parent) : QDialog(parent), existing(exist) {
602 setWindowTitle(tr("Add Network"));
603 on_networkEdit_textChanged(""); // disable ok button
604 } else ui.networkEdit->setText(old);
607 QString NetworkEditDlg::networkName() const {
608 return ui.networkEdit->text();
612 void NetworkEditDlg::on_networkEdit_textChanged(const QString &text) {
613 ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(text.isEmpty() || existing.contains(text));
617 /**************************************************************************
619 *************************************************************************/
621 ServerEditDlg::ServerEditDlg(const QVariant &_serverData, QWidget *parent) : QDialog(parent) {
623 QVariantMap serverData = _serverData.toMap();
624 if(serverData.count()) {
625 ui.host->setText(serverData["Host"].toString());
626 ui.port->setValue(serverData["Port"].toUInt());
627 ui.password->setText(serverData["Password"].toString());
628 ui.useSSL->setChecked(serverData["UseSSL"].toBool());
630 ui.port->setValue(6667);
632 on_host_textChanged();
635 QVariant ServerEditDlg::serverData() const {
636 QVariantMap _serverData;
637 _serverData["Host"] = ui.host->text();
638 _serverData["Port"] = ui.port->value();
639 _serverData["Password"] = ui.password->text();
640 _serverData["UseSSL"] = ui.useSSL->isChecked();
644 void ServerEditDlg::on_host_textChanged() {
645 ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(ui.host->text().isEmpty());
648 /**************************************************************************
650 *************************************************************************/
652 SaveNetworksDlg::SaveNetworksDlg(const QList<NetworkInfo> &toCreate, const QList<NetworkInfo> &toUpdate, const QList<NetworkId> &toRemove, QWidget *parent) : QDialog(parent)
656 numevents = toCreate.count() + toUpdate.count() + toRemove.count();
659 ui.progressBar->setMaximum(numevents);
660 ui.progressBar->setValue(0);
662 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(clientEvent()));
663 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), this, SLOT(clientEvent()));
665 foreach(NetworkInfo info, toCreate) {
666 Client::createNetwork(info);
668 foreach(NetworkInfo info, toUpdate) {
669 const Network *net = Client::network(info.networkId);
671 qWarning() << "Invalid client network!";
675 // FIXME this only checks for one changed item rather than all!
676 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientEvent()));
677 Client::updateNetwork(info);
679 foreach(NetworkId id, toRemove) {
680 Client::removeNetwork(id);
683 qWarning() << "Sync dialog called without stuff to change!";
688 void SaveNetworksDlg::clientEvent() {
689 ui.progressBar->setValue(++rcvevents);
690 if(rcvevents >= numevents) accept();