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