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