cmake: avoid de-duplication of user's CXXFLAGS
[quassel.git] / src / qtui / settingspages / networkssettingspage.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2022 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 _capSaslStatusSelected;  ///< Status of SASL support for selected network
154     bool _capSaslStatusUsingExternal{false};  ///< Whether SASL support status is for SASL EXTERNAL
155
156     void reset();
157     bool testHasChanged();
158     QListWidgetItem* insertNetwork(NetworkId);
159     QListWidgetItem* insertNetwork(const NetworkInfo& info);
160     QListWidgetItem* networkItem(NetworkId) const;
161     void saveToNetworkInfo(NetworkInfo&);
162     IdentityId defaultIdentity() const;
163
164     /**
165      * Get whether or not the displayed network's identity has SSL certs associated with it
166      *
167      * @return True if the currently displayed network has SSL certs set, otherwise false
168      */
169     bool displayedNetworkHasCertId() const;
170
171     /**
172      * Update the SASL settings interface according to the given SASL state
173      *
174      * @param saslStatus         Current status of SASL support.
175      * @param usingSASLExternal  If true, SASL support status is for SASL EXTERNAL, else SASL PLAIN
176      */
177     void setCapSASLStatus(const CapSupportStatus saslStatus, bool usingSASLExternal = false);
178 };
179
180 class NetworkAddDlg : public QDialog
181 {
182     Q_OBJECT
183
184 public:
185     NetworkAddDlg(QStringList existing = QStringList(), QWidget* parent = nullptr);
186
187     NetworkInfo networkInfo() const;
188
189 private slots:
190     void setButtonStates();
191
192     /**
193      * Update the default server port according to isChecked
194      *
195      * Connect with useSSL->toggled() in order to keep the port number in sync.  This only modifies
196      * the port if it's not been changed from defaults.
197      *
198      * @param isChecked If true and port unchanged, set port to 6697, else set port to 6667.
199      */
200     void updateSslPort(bool isChecked);
201
202 private:
203     Ui::NetworkAddDlg ui;
204
205     QStringList existing;
206 };
207
208 class NetworkEditDlg : public QDialog
209 {
210     Q_OBJECT
211
212 public:
213     NetworkEditDlg(const QString& old, QStringList existing = QStringList(), QWidget* parent = nullptr);
214
215     QString networkName() const;
216
217 private slots:
218     void on_networkEdit_textChanged(const QString&);
219
220 private:
221     Ui::NetworkEditDlg ui;
222
223     QStringList existing;
224 };
225
226 class ServerEditDlg : public QDialog
227 {
228     Q_OBJECT
229
230 public:
231     ServerEditDlg(const Network::Server& server = Network::Server(), QWidget* parent = nullptr);
232
233     Network::Server serverData() const;
234
235 private slots:
236     void on_host_textChanged();
237
238     /**
239      * Update the default server port according to isChecked
240      *
241      * Connect with useSSL->toggled() in order to keep the port number in sync.  This only modifies
242      * the port if it's not been changed from defaults.
243      *
244      * @param isChecked If true and port unchanged, set port to 6697, else set port to 6667.
245      */
246     void updateSslPort(bool isChecked);
247
248 private:
249     Ui::ServerEditDlg ui;
250 };
251
252 class CapsEditDlg : public QDialog
253 {
254     Q_OBJECT
255
256 public:
257     CapsEditDlg(const QString& oldSkipCapsString, QWidget* parent = nullptr);
258
259     QString skipCapsString() const;
260
261 private slots:
262     void defaultSkipCaps();
263     void on_skipCapsEdit_textChanged(const QString&);
264
265 private:
266     Ui::CapsEditDlg ui;
267
268     QString oldSkipCapsString;
269 };
270
271 class SaveNetworksDlg : public QDialog
272 {
273     Q_OBJECT
274
275 public:
276     SaveNetworksDlg(const QList<NetworkInfo>& toCreate,
277                     const QList<NetworkInfo>& toUpdate,
278                     const QList<NetworkId>& toRemove,
279                     QWidget* parent = nullptr);
280
281 private slots:
282     void clientEvent();
283
284 private:
285     Ui::SaveIdentitiesDlg ui;
286
287     int numevents, rcvevents;
288 };
289
290 #endif