1 /***************************************************************************
2 * Copyright (C) 2005-2016 by the Quassel Project *
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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include "simplenetworkeditor.h"
25 #include "networkssettingspage.h"
27 SimpleNetworkEditor::SimpleNetworkEditor(QWidget *parent)
32 ui.addServer->setIcon(QIcon::fromTheme("list-add"));
33 ui.deleteServer->setIcon(QIcon::fromTheme("edit-delete"));
34 ui.editServer->setIcon(QIcon::fromTheme("configure"));
35 ui.upServer->setIcon(QIcon::fromTheme("go-up"));
36 ui.downServer->setIcon(QIcon::fromTheme("go-down"));
38 connect(ui.networkNameEdit, SIGNAL(textEdited(const QString &)), this, SIGNAL(widgetHasChanged()));
39 connect(ui.channelList, SIGNAL(textChanged()), this, SIGNAL(widgetHasChanged()));
43 void SimpleNetworkEditor::setWidgetStates()
45 if (ui.serverList->selectedItems().count()) {
46 ui.editServer->setEnabled(true);
47 ui.deleteServer->setEnabled(true);
48 ui.upServer->setEnabled(ui.serverList->currentRow() > 0);
49 ui.downServer->setEnabled(ui.serverList->currentRow() < ui.serverList->count() - 1);
52 ui.editServer->setEnabled(false);
53 ui.deleteServer->setEnabled(false);
54 ui.upServer->setEnabled(false);
55 ui.downServer->setEnabled(false);
60 void SimpleNetworkEditor::displayNetworkInfo(const NetworkInfo &networkInfo)
62 _networkInfo = networkInfo;
64 ui.serverList->clear();
65 foreach(Network::Server server, _networkInfo.serverList) {
66 QListWidgetItem *item = new QListWidgetItem(QString("%1:%2").arg(server.host).arg(server.port));
68 item->setIcon(QIcon::fromTheme("document-encrypt"));
69 ui.serverList->addItem(item);
72 ui.networkNameEdit->setText(_networkInfo.networkName);
77 void SimpleNetworkEditor::saveToNetworkInfo(NetworkInfo &networkInfo)
79 _networkInfo.networkName = ui.networkNameEdit->text();
80 networkInfo = _networkInfo;
84 QStringList SimpleNetworkEditor::defaultChannels() const
86 return ui.channelList->toPlainText().split("\n", QString::SkipEmptyParts);
90 void SimpleNetworkEditor::setDefaultChannels(const QStringList &channels)
92 ui.channelList->setPlainText(channels.join("\n"));
96 void SimpleNetworkEditor::on_serverList_itemSelectionChanged()
102 void SimpleNetworkEditor::on_addServer_clicked()
104 ServerEditDlg dlg(Network::Server(), this);
105 if (dlg.exec() == QDialog::Accepted) {
106 _networkInfo.serverList.append(dlg.serverData());
107 displayNetworkInfo(_networkInfo);
108 ui.serverList->setCurrentRow(ui.serverList->count() - 1);
109 emit widgetHasChanged();
114 void SimpleNetworkEditor::on_editServer_clicked()
116 int cur = ui.serverList->currentRow();
117 ServerEditDlg dlg(_networkInfo.serverList[cur], this);
118 if (dlg.exec() == QDialog::Accepted) {
119 _networkInfo.serverList[cur] = dlg.serverData();
120 displayNetworkInfo(_networkInfo);
121 ui.serverList->setCurrentRow(cur);
122 emit widgetHasChanged();
127 void SimpleNetworkEditor::on_deleteServer_clicked()
129 int cur = ui.serverList->currentRow();
130 _networkInfo.serverList.removeAt(cur);
131 displayNetworkInfo(_networkInfo);
132 ui.serverList->setCurrentRow(qMin(cur, ui.serverList->count() - 1));
133 emit widgetHasChanged();
137 void SimpleNetworkEditor::on_upServer_clicked()
139 int cur = ui.serverList->currentRow();
140 Network::Server server = _networkInfo.serverList.takeAt(cur);
141 _networkInfo.serverList.insert(cur - 1, server);
142 displayNetworkInfo(_networkInfo);
143 ui.serverList->setCurrentRow(cur - 1);
144 emit widgetHasChanged();
148 void SimpleNetworkEditor::on_downServer_clicked()
150 int cur = ui.serverList->currentRow();
151 Network::Server server = _networkInfo.serverList.takeAt(cur);
152 _networkInfo.serverList.insert(cur + 1, server);
153 displayNetworkInfo(_networkInfo);
154 ui.serverList->setCurrentRow(cur + 1);
155 emit widgetHasChanged();