1 /***************************************************************************
2 * Copyright (C) 2005-2019 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"
24 #include "networkssettingspage.h"
26 SimpleNetworkEditor::SimpleNetworkEditor(QWidget* parent)
31 ui.addServer->setIcon(icon::get("list-add"));
32 ui.deleteServer->setIcon(icon::get("edit-delete"));
33 ui.editServer->setIcon(icon::get("configure"));
34 ui.upServer->setIcon(icon::get("go-up"));
35 ui.downServer->setIcon(icon::get("go-down"));
37 connect(ui.networkNameEdit, &QLineEdit::textEdited, this, &SimpleNetworkEditor::widgetHasChanged);
38 connect(ui.channelList, &QTextEdit::textChanged, this, &SimpleNetworkEditor::widgetHasChanged);
41 void SimpleNetworkEditor::setWidgetStates()
43 if (ui.serverList->selectedItems().count()) {
44 ui.editServer->setEnabled(true);
45 ui.deleteServer->setEnabled(true);
46 ui.upServer->setEnabled(ui.serverList->currentRow() > 0);
47 ui.downServer->setEnabled(ui.serverList->currentRow() < ui.serverList->count() - 1);
50 ui.editServer->setEnabled(false);
51 ui.deleteServer->setEnabled(false);
52 ui.upServer->setEnabled(false);
53 ui.downServer->setEnabled(false);
57 void SimpleNetworkEditor::displayNetworkInfo(const NetworkInfo& networkInfo)
59 _networkInfo = networkInfo;
61 ui.serverList->clear();
62 foreach (Network::Server server, _networkInfo.serverList) {
63 QListWidgetItem* item = new QListWidgetItem(QString("%1:%2").arg(server.host).arg(server.port));
65 item->setIcon(icon::get("document-encrypt"));
66 ui.serverList->addItem(item);
69 ui.networkNameEdit->setText(_networkInfo.networkName);
73 void SimpleNetworkEditor::saveToNetworkInfo(NetworkInfo& networkInfo)
75 _networkInfo.networkName = ui.networkNameEdit->text();
76 networkInfo = _networkInfo;
79 QStringList SimpleNetworkEditor::defaultChannels() const
81 return ui.channelList->toPlainText().split("\n", QString::SkipEmptyParts);
84 void SimpleNetworkEditor::setDefaultChannels(const QStringList& channels)
86 ui.channelList->setPlainText(channels.join("\n"));
89 void SimpleNetworkEditor::on_serverList_itemSelectionChanged()
94 void SimpleNetworkEditor::on_addServer_clicked()
96 ServerEditDlg dlg(Network::Server(), this);
97 if (dlg.exec() == QDialog::Accepted) {
98 _networkInfo.serverList.append(dlg.serverData());
99 displayNetworkInfo(_networkInfo);
100 ui.serverList->setCurrentRow(ui.serverList->count() - 1);
101 emit widgetHasChanged();
105 void SimpleNetworkEditor::on_editServer_clicked()
107 int cur = ui.serverList->currentRow();
108 ServerEditDlg dlg(_networkInfo.serverList[cur], this);
109 if (dlg.exec() == QDialog::Accepted) {
110 _networkInfo.serverList[cur] = dlg.serverData();
111 displayNetworkInfo(_networkInfo);
112 ui.serverList->setCurrentRow(cur);
113 emit widgetHasChanged();
117 void SimpleNetworkEditor::on_deleteServer_clicked()
119 int cur = ui.serverList->currentRow();
120 _networkInfo.serverList.removeAt(cur);
121 displayNetworkInfo(_networkInfo);
122 ui.serverList->setCurrentRow(qMin(cur, ui.serverList->count() - 1));
123 emit widgetHasChanged();
126 void SimpleNetworkEditor::on_upServer_clicked()
128 int cur = ui.serverList->currentRow();
129 Network::Server server = _networkInfo.serverList.takeAt(cur);
130 _networkInfo.serverList.insert(cur - 1, server);
131 displayNetworkInfo(_networkInfo);
132 ui.serverList->setCurrentRow(cur - 1);
133 emit widgetHasChanged();
136 void SimpleNetworkEditor::on_downServer_clicked()
138 int cur = ui.serverList->currentRow();
139 Network::Server server = _networkInfo.serverList.takeAt(cur);
140 _networkInfo.serverList.insert(cur + 1, server);
141 displayNetworkInfo(_networkInfo);
142 ui.serverList->setCurrentRow(cur + 1);
143 emit widgetHasChanged();