Quassel IRC  Pre-Release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
simplenetworkeditor.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2015 by the Quassel Project *
3  * devel@quassel-irc.org *
4  * *
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. *
9  * *
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. *
14  * *
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  ***************************************************************************/
20 
21 #include "simplenetworkeditor.h"
22 
23 #include <QIcon>
24 
25 #include "networkssettingspage.h"
26 
28  : QWidget(parent)
29 {
30  ui.setupUi(this);
31 
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"));
37 
38  connect(ui.networkNameEdit, SIGNAL(textEdited(const QString &)), this, SIGNAL(widgetHasChanged()));
39  connect(ui.channelList, SIGNAL(textChanged()), this, SIGNAL(widgetHasChanged()));
40 }
41 
42 
44 {
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);
50  }
51  else {
52  ui.editServer->setEnabled(false);
53  ui.deleteServer->setEnabled(false);
54  ui.upServer->setEnabled(false);
55  ui.downServer->setEnabled(false);
56  }
57 }
58 
59 
61 {
62  _networkInfo = networkInfo;
63 
64  ui.serverList->clear();
66  QListWidgetItem *item = new QListWidgetItem(QString("%1:%2").arg(server.host).arg(server.port));
67  if (server.useSsl)
68  item->setIcon(QIcon::fromTheme("document-encrypt"));
69  ui.serverList->addItem(item);
70  }
71 
72  ui.networkNameEdit->setText(_networkInfo.networkName);
74 }
75 
76 
78 {
79  _networkInfo.networkName = ui.networkNameEdit->text();
80  networkInfo = _networkInfo;
81 }
82 
83 
85 {
86  return ui.channelList->toPlainText().split("\n", QString::SkipEmptyParts);
87 }
88 
89 
90 void SimpleNetworkEditor::setDefaultChannels(const QStringList &channels)
91 {
92  ui.channelList->setPlainText(channels.join("\n"));
93 }
94 
95 
97 {
99 }
100 
101 
103 {
104  ServerEditDlg dlg(Network::Server(), this);
105  if (dlg.exec() == QDialog::Accepted) {
106  _networkInfo.serverList.append(dlg.serverData());
108  ui.serverList->setCurrentRow(ui.serverList->count() - 1);
109  emit widgetHasChanged();
110  }
111 }
112 
113 
115 {
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();
121  ui.serverList->setCurrentRow(cur);
122  emit widgetHasChanged();
123  }
124 }
125 
126 
128 {
129  int cur = ui.serverList->currentRow();
130  _networkInfo.serverList.removeAt(cur);
132  ui.serverList->setCurrentRow(qMin(cur, ui.serverList->count() - 1));
133  emit widgetHasChanged();
134 }
135 
136 
138 {
139  int cur = ui.serverList->currentRow();
141  _networkInfo.serverList.insert(cur - 1, server);
143  ui.serverList->setCurrentRow(cur - 1);
144  emit widgetHasChanged();
145 }
146 
147 
149 {
150  int cur = ui.serverList->currentRow();
152  _networkInfo.serverList.insert(cur + 1, server);
154  ui.serverList->setCurrentRow(cur + 1);
155  emit widgetHasChanged();
156 }