Use label and Details button, check if connected
[quassel.git] / src / qtui / settingspages / networkssettingspage.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2016 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 #ifndef NETWORKSSETTINGSPAGE_H
22 #define NETWORKSSETTINGSPAGE_H
23
24 #include <QIcon>
25
26 #include "network.h"
27 #include "settingspage.h"
28 #include "clientidentity.h"
29
30 #include "ui_networkssettingspage.h"
31 #include "ui_networkadddlg.h"
32 #include "ui_networkeditdlg.h"
33 #include "ui_servereditdlg.h"
34 #include "ui_saveidentitiesdlg.h"
35
36 class NetworksSettingsPage : public SettingsPage
37 {
38     Q_OBJECT
39
40 public:
41     NetworksSettingsPage(QWidget *parent = 0);
42
43     virtual inline bool needsCoreConnection() const { return true; }
44
45     bool aboutToSave();
46
47 public slots:
48     void save();
49     void load();
50
51 private slots:
52     void widgetHasChanged();
53     void setWidgetStates();
54     void coreConnectionStateChanged(bool);
55     void networkConnectionStateChanged(Network::ConnectionState state);
56     void networkConnectionError(const QString &msg);
57
58     void displayNetwork(NetworkId);
59     void setItemState(NetworkId, QListWidgetItem *item = 0);
60
61     /**
62      * Update the capability-dependent settings according to what the server supports
63      *
64      * For example, this updates the SASL text for when the server advertises support.  This should
65      * only be called on the currently displayed network.
66      *
67      * @param[in] id  NetworkId referencing network used to update settings user interface.
68      */
69     void setNetworkCapStates(NetworkId id);
70
71     void clientNetworkAdded(NetworkId);
72     void clientNetworkRemoved(NetworkId);
73     void clientNetworkUpdated();
74
75     void clientIdentityAdded(IdentityId);
76     void clientIdentityRemoved(IdentityId);
77     void clientIdentityUpdated();
78
79     /**
80      * Update the settings user interface according to capabilities advertised by the IRC server
81      */
82     void clientNetworkCapsUpdated();
83
84 #ifdef HAVE_SSL
85     void sslUpdated();
86 #endif
87
88     void on_networkList_itemSelectionChanged();
89     void on_addNetwork_clicked();
90     void on_deleteNetwork_clicked();
91     void on_renameNetwork_clicked();
92     void on_editIdentities_clicked();
93
94     // void on_connectNow_clicked();
95
96     void on_serverList_itemSelectionChanged();
97     void on_addServer_clicked();
98     void on_deleteServer_clicked();
99     void on_editServer_clicked();
100     void on_upServer_clicked();
101     void on_downServer_clicked();
102
103     /**
104      * Event handler for SASL status Details button
105      */
106     void on_saslStatusDetails_clicked();
107
108 private:
109     /**
110      * Status of capability support
111      */
112     enum CapSupportStatus {
113         Unknown,           ///< Old core, or otherwise unknown, can't make assumptions
114         Disconnected,      ///< Disconnected from network, can't determine
115         MaybeUnsupported,  ///< Server does not advertise support at this moment
116         MaybeSupported     ///< Server advertises support at this moment
117     };
118     // Keep in mind networks can add, change, and remove capabilities at any time.
119
120     Ui::NetworksSettingsPage ui;
121
122     NetworkId currentId;
123     QHash<NetworkId, NetworkInfo> networkInfos;
124     bool _ignoreWidgetChanges;
125 #ifdef HAVE_SSL
126     CertIdentity *_cid;
127 #endif
128
129     QIcon connectedIcon, connectingIcon, disconnectedIcon;
130
131     // Status icons
132     QIcon infoIcon, warningIcon;
133
134     CapSupportStatus _saslStatusSelected;  /// Status of SASL support for currently-selected network
135
136     void reset();
137     bool testHasChanged();
138     QListWidgetItem *insertNetwork(NetworkId);
139     QListWidgetItem *insertNetwork(const NetworkInfo &info);
140     QListWidgetItem *networkItem(NetworkId) const;
141     void saveToNetworkInfo(NetworkInfo &);
142     IdentityId defaultIdentity() const;
143
144     /**
145      * Update the SASL settings interface according to the given SASL state
146      *
147      * @param[in] saslStatus Current status of SASL support.
148      */
149     void setSASLStatus(const CapSupportStatus saslStatus);
150 };
151
152
153 class NetworkAddDlg : public QDialog
154 {
155     Q_OBJECT
156
157 public:
158     NetworkAddDlg(const QStringList &existing = QStringList(), QWidget *parent = 0);
159
160     NetworkInfo networkInfo() const;
161
162 private slots:
163     void setButtonStates();
164
165     /**
166      * Update the default server port according to isChecked
167      *
168      * Connect with useSSL->toggled() in order to keep the port number in sync.  This only modifies
169      * the port if it's not been changed from defaults.
170      *
171      * @param isChecked If true and port unchanged, set port to 6697, else set port to 6667.
172      */
173     void updateSslPort(bool isChecked);
174
175 private:
176     Ui::NetworkAddDlg ui;
177
178     QStringList existing;
179 };
180
181
182 class NetworkEditDlg : public QDialog
183 {
184     Q_OBJECT
185
186 public:
187     NetworkEditDlg(const QString &old, const QStringList &existing = QStringList(), QWidget *parent = 0);
188
189     QString networkName() const;
190
191 private slots:
192     void on_networkEdit_textChanged(const QString &);
193
194 private:
195     Ui::NetworkEditDlg ui;
196
197     QStringList existing;
198 };
199
200
201 class ServerEditDlg : public QDialog
202 {
203     Q_OBJECT
204
205 public:
206     ServerEditDlg(const Network::Server &server = Network::Server(), QWidget *parent = 0);
207
208     Network::Server serverData() const;
209
210 private slots:
211     void on_host_textChanged();
212
213     /**
214      * Update the default server port according to isChecked
215      *
216      * Connect with useSSL->toggled() in order to keep the port number in sync.  This only modifies
217      * the port if it's not been changed from defaults.
218      *
219      * @param isChecked If true and port unchanged, set port to 6697, else set port to 6667.
220      */
221     void updateSslPort(bool isChecked);
222
223 private:
224     Ui::ServerEditDlg ui;
225 };
226
227
228 class SaveNetworksDlg : public QDialog
229 {
230     Q_OBJECT
231
232 public:
233     SaveNetworksDlg(const QList<NetworkInfo> &toCreate, const QList<NetworkInfo> &toUpdate, const QList<NetworkId> &toRemove, QWidget *parent = 0);
234
235 private slots:
236     void clientEvent();
237
238 private:
239     Ui::SaveIdentitiesDlg ui;
240
241     int numevents, rcvevents;
242 };
243
244
245 #endif