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(identitySet(IdentityId)), this, SLOT(clientNetworkUpdated()));
326 connect(Client::network(id), SIGNAL(networkNameSet(const QString &)), this, SLOT(clientNetworkUpdated()));
327 connect(Client::network(id), SIGNAL(serverListSet(QVariantList)), this, SLOT(clientNetworkUpdated()));
328 connect(Client::network(id), SIGNAL(useRandomServerSet(bool)), this, SLOT(clientNetworkUpdated()));
329 connect(Client::network(id), SIGNAL(performSet(const QStringList &)), this, SLOT(clientNetworkUpdated()));
330 connect(Client::network(id), SIGNAL(useAutoIdentifySet(bool)), this, SLOT(clientNetworkUpdated()));
331 connect(Client::network(id), SIGNAL(autoIdentifyServiceSet(const QString &)), this, SLOT(clientNetworkUpdated()));
332 connect(Client::network(id), SIGNAL(autoIdentifyPasswordSet(const QString &)), this, SLOT(clientNetworkUpdated()));
333 connect(Client::network(id), SIGNAL(useAutoReconnectSet(bool)), this, SLOT(clientNetworkUpdated()));
334 connect(Client::network(id), SIGNAL(autoReconnectIntervalSet(quint32)), this, SLOT(clientNetworkUpdated()));
335 connect(Client::network(id), SIGNAL(autoReconnectRetriesSet(quint16)), this, SLOT(clientNetworkUpdated()));
336 connect(Client::network(id), SIGNAL(unlimitedReconnectRetriesSet(bool)), this, SLOT(clientNetworkUpdated()));
337 connect(Client::network(id), SIGNAL(rejoinChannelsSet(bool)), this, SLOT(clientNetworkUpdated()));
338 connect(Client::network(id), SIGNAL(codecForServerSet(const QByteArray &)), this, SLOT(clientNetworkUpdated()));
339 connect(Client::network(id), SIGNAL(codecForEncodingSet(const QByteArray &)), this, SLOT(clientNetworkUpdated()));
340 connect(Client::network(id), SIGNAL(codecForDecodingSet(const QByteArray &)), this, SLOT(clientNetworkUpdated()));
342 connect(Client::network(id), SIGNAL(connectionStateSet(Network::ConnectionState)), this, SLOT(networkConnectionStateChanged(Network::ConnectionState)));
343 connect(Client::network(id), SIGNAL(connectionError(const QString &)), this, SLOT(networkConnectionError(const QString &)));
346 void NetworksSettingsPage::clientNetworkUpdated() {
347 const Network *net = qobject_cast<const Network *>(sender());
349 qWarning() << "Update request for unknown network received!";
352 networkInfos[net->networkId()] = net->networkInfo();
353 setItemState(net->networkId());
354 if(net->networkId() == currentId) displayNetwork(net->networkId());
359 void NetworksSettingsPage::clientNetworkRemoved(NetworkId id) {
360 if(!networkInfos.contains(id)) return;
361 if(id == currentId) displayNetwork(0);
362 NetworkInfo info = networkInfos.take(id);
363 QList<QListWidgetItem *> items = ui.networkList->findItems(info.networkName, Qt::MatchExactly);
364 foreach(QListWidgetItem *item, items) {
365 if(item->data(Qt::UserRole).value<NetworkId>() == id)
366 delete ui.networkList->takeItem(ui.networkList->row(item));
372 void NetworksSettingsPage::networkConnectionStateChanged(Network::ConnectionState state) {
373 const Network *net = qobject_cast<const Network *>(sender());
375 if(net->networkId() == currentId) {
376 ui.connectNow->setEnabled(state == Network::Initialized || state == Network::Disconnected);
378 setItemState(net->networkId());
381 void NetworksSettingsPage::networkConnectionError(const QString &) {
385 QListWidgetItem *NetworksSettingsPage::insertNetwork(NetworkId id) {
386 NetworkInfo info = Client::network(id)->networkInfo();
387 networkInfos[id] = info;
388 return insertNetwork(info);
391 QListWidgetItem *NetworksSettingsPage::insertNetwork(const NetworkInfo &info) {
392 QListWidgetItem *item = 0;
393 QList<QListWidgetItem *> items = ui.networkList->findItems(info.networkName, Qt::MatchExactly);
394 if(!items.count()) item = new QListWidgetItem(disconnectedIcon, info.networkName, ui.networkList);
396 // we overwrite an existing net if it a) has the same name and b) has a negative ID meaning we created it locally before
397 // -> then we can be sure that this is the core-side replacement for the net we created
398 foreach(QListWidgetItem *i, items) {
399 NetworkId id = i->data(Qt::UserRole).value<NetworkId>();
400 if(id < 0) { item = i; break; }
402 if(!item) item = new QListWidgetItem(disconnectedIcon, info.networkName, ui.networkList);
404 item->setData(Qt::UserRole, QVariant::fromValue<NetworkId>(info.networkId));
405 setItemState(info.networkId, item);
410 void NetworksSettingsPage::displayNetwork(NetworkId id) {
411 _ignoreWidgetChanges = true;
413 NetworkInfo info = networkInfos[id];
414 ui.identityList->setCurrentIndex(ui.identityList->findData(info.identity.toInt()));
415 ui.serverList->clear();
416 foreach(QVariant v, info.serverList) {
417 ui.serverList->addItem(QString("%1:%2").arg(v.toMap()["Host"].toString()).arg(v.toMap()["Port"].toUInt()));
420 ui.randomServer->setChecked(info.useRandomServer);
421 ui.performEdit->setPlainText(info.perform.join("\n"));
422 ui.autoIdentify->setChecked(info.useAutoIdentify);
423 ui.autoIdentifyService->setText(info.autoIdentifyService);
424 ui.autoIdentifyPassword->setText(info.autoIdentifyPassword);
425 if(info.codecForEncoding.isEmpty()) {
426 ui.sendEncoding->setCurrentIndex(ui.sendEncoding->findText(Network::defaultCodecForEncoding()));
427 ui.recvEncoding->setCurrentIndex(ui.recvEncoding->findText(Network::defaultCodecForDecoding()));
428 ui.useDefaultEncodings->setChecked(true);
430 ui.sendEncoding->setCurrentIndex(ui.sendEncoding->findText(info.codecForEncoding));
431 ui.recvEncoding->setCurrentIndex(ui.recvEncoding->findText(info.codecForDecoding));
432 ui.useDefaultEncodings->setChecked(false);
434 ui.autoReconnect->setChecked(info.useAutoReconnect);
435 ui.reconnectInterval->setValue(info.autoReconnectInterval);
436 ui.reconnectRetries->setValue(info.autoReconnectRetries);
437 ui.unlimitedRetries->setChecked(info.unlimitedReconnectRetries);
438 ui.rejoinOnReconnect->setChecked(info.rejoinChannels);
440 // just clear widgets
441 ui.identityList->setCurrentIndex(-1);
442 ui.serverList->clear();
443 ui.performEdit->clear();
444 ui.autoIdentifyService->clear();
445 ui.autoIdentifyPassword->clear();
448 _ignoreWidgetChanges = false;
452 void NetworksSettingsPage::saveToNetworkInfo(NetworkInfo &info) {
453 info.identity = ui.identityList->itemData(ui.identityList->currentIndex()).toInt();
454 info.useRandomServer = ui.randomServer->isChecked();
455 info.perform = ui.performEdit->toPlainText().split("\n");
456 info.useAutoIdentify = ui.autoIdentify->isChecked();
457 info.autoIdentifyService = ui.autoIdentifyService->text();
458 info.autoIdentifyPassword = ui.autoIdentifyPassword->text();
459 if(ui.useDefaultEncodings->isChecked()) {
460 info.codecForEncoding.clear();
461 info.codecForDecoding.clear();
463 info.codecForEncoding = ui.sendEncoding->currentText().toLatin1();
464 info.codecForDecoding = ui.recvEncoding->currentText().toLatin1();
466 info.useAutoReconnect = ui.autoReconnect->isChecked();
467 info.autoReconnectInterval = ui.reconnectInterval->value();
468 info.autoReconnectRetries = ui.reconnectRetries->value();
469 info.unlimitedReconnectRetries = ui.unlimitedRetries->isChecked();
470 info.rejoinChannels = ui.rejoinOnReconnect->isChecked();
472 /*** Network list ***/
474 void NetworksSettingsPage::on_networkList_itemSelectionChanged() {
476 saveToNetworkInfo(networkInfos[currentId]);
478 if(ui.networkList->selectedItems().count()) {
479 NetworkId id = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
482 ui.serverList->setCurrentRow(0);
489 void NetworksSettingsPage::on_addNetwork_clicked() {
490 QStringList existing;
491 for(int i = 0; i < ui.networkList->count(); i++) existing << ui.networkList->item(i)->text();
492 NetworkEditDlg dlg(QString(), existing, this);
493 if(dlg.exec() == QDialog::Accepted) {
495 for(id = 1; id <= networkInfos.count(); id++) {
497 if(!networkInfos.keys().contains(-id.toInt())) break;
502 info.networkName = dlg.networkName();
506 info.useRandomServer = false;
507 info.useAutoReconnect = true;
508 info.autoReconnectInterval = 60;
509 info.autoReconnectRetries = 20;
510 info.unlimitedReconnectRetries = false;
511 info.useAutoIdentify = false;
512 info.autoIdentifyService = "NickServ";
513 info.rejoinChannels = true;
515 networkInfos[id] = info;
516 QListWidgetItem *item = insertNetwork(info);
517 ui.networkList->setCurrentItem(item);
522 void NetworksSettingsPage::on_deleteNetwork_clicked() {
523 if(ui.networkList->selectedItems().count()) {
524 NetworkId netid = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
525 int ret = QMessageBox::question(this, tr("Delete Network?"),
526 tr("Do you really want to delete the network \"%1\" and all related settings, including the backlog?").arg(networkInfos[netid].networkName),
527 QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
528 if(ret == QMessageBox::Yes) {
530 networkInfos.remove(netid);
531 delete ui.networkList->takeItem(ui.networkList->row(ui.networkList->selectedItems()[0]));
532 ui.networkList->setCurrentRow(qMin(ui.networkList->currentRow()+1, ui.networkList->count()-1));
539 void NetworksSettingsPage::on_renameNetwork_clicked() {
540 if(!ui.networkList->selectedItems().count()) return;
541 QString old = ui.networkList->selectedItems()[0]->text();
542 QStringList existing;
543 for(int i = 0; i < ui.networkList->count(); i++) existing << ui.networkList->item(i)->text();
544 NetworkEditDlg dlg(old, existing, this);
545 if(dlg.exec() == QDialog::Accepted) {
546 ui.networkList->selectedItems()[0]->setText(dlg.networkName());
547 NetworkId netid = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
548 networkInfos[netid].networkName = dlg.networkName();
553 void NetworksSettingsPage::on_connectNow_clicked() {
554 if(!ui.networkList->selectedItems().count()) return;
555 NetworkId id = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
556 const Network *net = Client::network(id);
558 if(net->connectionState() == Network::Disconnected) net->requestConnect();
559 else net->requestDisconnect();
562 /*** Server list ***/
564 void NetworksSettingsPage::on_serverList_itemSelectionChanged() {
568 void NetworksSettingsPage::on_addServer_clicked() {
569 if(currentId == 0) return;
570 ServerEditDlg dlg(QVariantMap(), this);
571 if(dlg.exec() == QDialog::Accepted) {
572 networkInfos[currentId].serverList.append(dlg.serverData());
573 displayNetwork(currentId);
574 ui.serverList->setCurrentRow(ui.serverList->count()-1);
580 void NetworksSettingsPage::on_editServer_clicked() {
581 if(currentId == 0) return;
582 int cur = ui.serverList->currentRow();
583 ServerEditDlg dlg(networkInfos[currentId].serverList[cur], this);
584 if(dlg.exec() == QDialog::Accepted) {
585 networkInfos[currentId].serverList[cur] = dlg.serverData();
586 displayNetwork(currentId);
587 ui.serverList->setCurrentRow(cur);
592 void NetworksSettingsPage::on_deleteServer_clicked() {
593 if(currentId == 0) return;
594 int cur = ui.serverList->currentRow();
595 networkInfos[currentId].serverList.removeAt(cur);
596 displayNetwork(currentId);
597 ui.serverList->setCurrentRow(qMin(cur, ui.serverList->count()-1));
601 void NetworksSettingsPage::on_upServer_clicked() {
602 int cur = ui.serverList->currentRow();
603 QVariant foo = networkInfos[currentId].serverList.takeAt(cur);
604 networkInfos[currentId].serverList.insert(cur-1, foo);
605 displayNetwork(currentId);
606 ui.serverList->setCurrentRow(cur-1);
610 void NetworksSettingsPage::on_downServer_clicked() {
611 int cur = ui.serverList->currentRow();
612 QVariant foo = networkInfos[currentId].serverList.takeAt(cur);
613 networkInfos[currentId].serverList.insert(cur+1, foo);
614 displayNetwork(currentId);
615 ui.serverList->setCurrentRow(cur+1);
619 /**************************************************************************
621 *************************************************************************/
623 NetworkEditDlg::NetworkEditDlg(const QString &old, const QStringList &exist, QWidget *parent) : QDialog(parent), existing(exist) {
628 setWindowTitle(tr("Add Network"));
629 on_networkEdit_textChanged(""); // disable ok button
630 } else ui.networkEdit->setText(old);
633 QString NetworkEditDlg::networkName() const {
634 return ui.networkEdit->text();
638 void NetworkEditDlg::on_networkEdit_textChanged(const QString &text) {
639 ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(text.isEmpty() || existing.contains(text));
643 /**************************************************************************
645 *************************************************************************/
647 ServerEditDlg::ServerEditDlg(const QVariant &_serverData, QWidget *parent) : QDialog(parent) {
649 QVariantMap serverData = _serverData.toMap();
650 if(serverData.count()) {
651 ui.host->setText(serverData["Host"].toString());
652 ui.port->setValue(serverData["Port"].toUInt());
653 ui.password->setText(serverData["Password"].toString());
654 ui.useSSL->setChecked(serverData["UseSSL"].toBool());
656 ui.port->setValue(6667);
658 on_host_textChanged();
661 QVariant ServerEditDlg::serverData() const {
662 QVariantMap _serverData;
663 _serverData["Host"] = ui.host->text().trimmed();
664 _serverData["Port"] = ui.port->value();
665 _serverData["Password"] = ui.password->text();
666 _serverData["UseSSL"] = ui.useSSL->isChecked();
670 void ServerEditDlg::on_host_textChanged() {
671 ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(ui.host->text().trimmed().isEmpty());
674 /**************************************************************************
676 *************************************************************************/
678 SaveNetworksDlg::SaveNetworksDlg(const QList<NetworkInfo> &toCreate, const QList<NetworkInfo> &toUpdate, const QList<NetworkId> &toRemove, QWidget *parent) : QDialog(parent)
682 numevents = toCreate.count() + toUpdate.count() + toRemove.count();
685 ui.progressBar->setMaximum(numevents);
686 ui.progressBar->setValue(0);
688 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(clientEvent()));
689 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), this, SLOT(clientEvent()));
691 foreach(NetworkInfo info, toCreate) {
692 Client::createNetwork(info);
694 foreach(NetworkInfo info, toUpdate) {
695 const Network *net = Client::network(info.networkId);
697 qWarning() << "Invalid client network!";
701 // FIXME this only checks for one changed item rather than all!
702 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientEvent()));
703 Client::updateNetwork(info);
705 foreach(NetworkId id, toRemove) {
706 Client::removeNetwork(id);
709 qWarning() << "Sync dialog called without stuff to change!";
714 void SaveNetworksDlg::clientEvent() {
715 ui.progressBar->setValue(++rcvevents);
716 if(rcvevents >= numevents) accept();