client: Switch infobar dialog-* icons to emblem-*
[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_networkadddlg.h"
31 #include "ui_networkeditdlg.h"
32 #include "ui_networkssettingspage.h"
33 #include "ui_saveidentitiesdlg.h"
34 #include "ui_servereditdlg.h"
35
36 class NetworksSettingsPage : public SettingsPage
37 {
38     Q_OBJECT
39
40 public:
41     NetworksSettingsPage(QWidget* parent = nullptr);
42
43     inline bool needsCoreConnection() const override { return true; }
44
45     bool aboutToSave() override;
46
47 public slots:
48     void save() override;
49     void load() override;
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 = nullptr);
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     void sslUpdated();
96
97     void on_networkList_itemSelectionChanged();
98     void on_addNetwork_clicked();
99     void on_deleteNetwork_clicked();
100     void on_renameNetwork_clicked();
101     void on_editIdentities_clicked();
102
103     // void on_connectNow_clicked();
104
105     void on_serverList_itemSelectionChanged();
106     void on_addServer_clicked();
107     void on_deleteServer_clicked();
108     void on_editServer_clicked();
109     void on_upServer_clicked();
110     void on_downServer_clicked();
111
112     /**
113      * Event handler for SASL status Details button
114      */
115     void on_saslStatusDetails_clicked();
116
117 private:
118     /**
119      * Status of capability support
120      */
121     enum CapSupportStatus
122     {
123         Unknown,           ///< Old core, or otherwise unknown, can't make assumptions
124         Disconnected,      ///< Disconnected from network, can't determine
125         MaybeUnsupported,  ///< Server does not advertise support at this moment
126         MaybeSupported     ///< Server advertises support at this moment
127     };
128     // Keep in mind networks can add, change, and remove capabilities at any time.
129
130     Ui::NetworksSettingsPage ui;
131
132     NetworkId currentId;
133     QHash<NetworkId, NetworkInfo> networkInfos;
134     bool _ignoreWidgetChanges{false};
135     CertIdentity* _cid{nullptr};
136
137     QIcon connectedIcon, connectingIcon, disconnectedIcon;
138
139     // Status icons
140     QIcon successIcon, unavailableIcon, questionIcon;
141
142     CapSupportStatus _saslStatusSelected;  /// Status of SASL support for currently-selected network
143
144     void reset();
145     bool testHasChanged();
146     QListWidgetItem* insertNetwork(NetworkId);
147     QListWidgetItem* insertNetwork(const NetworkInfo& info);
148     QListWidgetItem* networkItem(NetworkId) const;
149     void saveToNetworkInfo(NetworkInfo&);
150     IdentityId defaultIdentity() const;
151
152     /**
153      * Update the SASL settings interface according to the given SASL state
154      *
155      * @param[in] saslStatus Current status of SASL support.
156      */
157     void setSASLStatus(const CapSupportStatus saslStatus);
158 };
159
160 class NetworkAddDlg : public QDialog
161 {
162     Q_OBJECT
163
164 public:
165     NetworkAddDlg(QStringList existing = QStringList(), QWidget* parent = nullptr);
166
167     NetworkInfo networkInfo() const;
168
169 private slots:
170     void setButtonStates();
171
172     /**
173      * Update the default server port according to isChecked
174      *
175      * Connect with useSSL->toggled() in order to keep the port number in sync.  This only modifies
176      * the port if it's not been changed from defaults.
177      *
178      * @param isChecked If true and port unchanged, set port to 6697, else set port to 6667.
179      */
180     void updateSslPort(bool isChecked);
181
182 private:
183     Ui::NetworkAddDlg ui;
184
185     QStringList existing;
186 };
187
188 class NetworkEditDlg : public QDialog
189 {
190     Q_OBJECT
191
192 public:
193     NetworkEditDlg(const QString& old, QStringList existing = QStringList(), QWidget* parent = nullptr);
194
195     QString networkName() const;
196
197 private slots:
198     void on_networkEdit_textChanged(const QString&);
199
200 private:
201     Ui::NetworkEditDlg ui;
202
203     QStringList existing;
204 };
205
206 class ServerEditDlg : public QDialog
207 {
208     Q_OBJECT
209
210 public:
211     ServerEditDlg(const Network::Server& server = Network::Server(), QWidget* parent = nullptr);
212
213     Network::Server serverData() const;
214
215 private slots:
216     void on_host_textChanged();
217
218     /**
219      * Update the default server port according to isChecked
220      *
221      * Connect with useSSL->toggled() in order to keep the port number in sync.  This only modifies
222      * the port if it's not been changed from defaults.
223      *
224      * @param isChecked If true and port unchanged, set port to 6697, else set port to 6667.
225      */
226     void updateSslPort(bool isChecked);
227
228 private:
229     Ui::ServerEditDlg ui;
230 };
231
232 class SaveNetworksDlg : public QDialog
233 {
234     Q_OBJECT
235
236 public:
237     SaveNetworksDlg(const QList<NetworkInfo>& toCreate,
238                     const QList<NetworkInfo>& toUpdate,
239                     const QList<NetworkId>& toRemove,
240                     QWidget* parent = nullptr);
241
242 private slots:
243     void clientEvent();
244
245 private:
246     Ui::SaveIdentitiesDlg ui;
247
248     int numevents, rcvevents;
249 };
250
251 #endif