1 /***************************************************************************
2 * Copyright (C) 2005-2020 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
21 #ifndef NETWORKSSETTINGSPAGE_H
22 #define NETWORKSSETTINGSPAGE_H
26 #include "clientidentity.h"
28 #include "settingspage.h"
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"
37 class NetworksSettingsPage : public SettingsPage
42 NetworksSettingsPage(QWidget* parent = nullptr);
44 inline bool needsCoreConnection() const override { return true; }
46 bool aboutToSave() override;
51 void bufferList_Open(NetworkId);
54 void widgetHasChanged();
55 void setWidgetStates();
56 void coreConnectionStateChanged(bool);
57 void networkConnectionStateChanged(Network::ConnectionState state);
58 void networkConnectionError(const QString& msg);
60 void displayNetwork(NetworkId);
61 void setItemState(NetworkId, QListWidgetItem* item = nullptr);
64 * Reset the capability-dependent settings to the default unknown states
66 * For example, this updates the SASL text to indicate the status is unknown. Any actual
67 * information should be set by setNetworkCapStates()
69 * @see NetworksSettingsPage::setNetworkCapStates()
71 void resetNetworkCapStates();
74 * Update the capability-dependent settings according to what the server supports
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.
79 * @param[in] id NetworkId referencing network used to update settings user interface.
81 void setNetworkCapStates(NetworkId id);
83 void clientNetworkAdded(NetworkId);
84 void clientNetworkRemoved(NetworkId);
85 void clientNetworkUpdated();
87 void clientIdentityAdded(IdentityId);
88 void clientIdentityRemoved(IdentityId);
89 void clientIdentityUpdated();
92 * Update the settings user interface according to capabilities advertised by the IRC server
94 void clientNetworkCapsUpdated();
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();
104 // void on_connectNow_clicked();
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();
114 * Event handler for SASL status Details button
116 void on_saslStatusDetails_clicked();
119 * Event handler for Features status Details button
121 void on_enableCapsStatusDetails_clicked();
124 * Event handler for Features Advanced edit button
126 void on_enableCapsAdvanced_clicked();
130 * Status of capability support
132 enum CapSupportStatus
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
139 // Keep in mind networks can add, change, and remove capabilities at any time.
141 Ui::NetworksSettingsPage ui;
144 QHash<NetworkId, NetworkInfo> networkInfos;
145 bool _ignoreWidgetChanges{false};
146 CertIdentity* _cid{nullptr};
148 QIcon connectedIcon, connectingIcon, disconnectedIcon;
151 QIcon infoIcon, successIcon, unavailableIcon, questionIcon;
153 CapSupportStatus _capSaslStatusSelected; ///< Status of SASL support for selected network
154 bool _capSaslStatusUsingExternal{false}; ///< Whether SASL support status is for SASL EXTERNAL
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;
165 * Get whether or not the displayed network's identity has SSL certs associated with it
167 * @return True if the currently displayed network has SSL certs set, otherwise false
169 bool displayedNetworkHasCertId() const;
172 * Update the SASL settings interface according to the given SASL state
174 * @param saslStatus Current status of SASL support.
175 * @param usingSASLExternal If true, SASL support status is for SASL EXTERNAL, else SASL PLAIN
177 void setCapSASLStatus(const CapSupportStatus saslStatus, bool usingSASLExternal = false);
180 class NetworkAddDlg : public QDialog
185 NetworkAddDlg(QStringList existing = QStringList(), QWidget* parent = nullptr);
187 NetworkInfo networkInfo() const;
190 void setButtonStates();
193 * Update the default server port according to isChecked
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.
198 * @param isChecked If true and port unchanged, set port to 6697, else set port to 6667.
200 void updateSslPort(bool isChecked);
203 Ui::NetworkAddDlg ui;
205 QStringList existing;
208 class NetworkEditDlg : public QDialog
213 NetworkEditDlg(const QString& old, QStringList existing = QStringList(), QWidget* parent = nullptr);
215 QString networkName() const;
218 void on_networkEdit_textChanged(const QString&);
221 Ui::NetworkEditDlg ui;
223 QStringList existing;
226 class ServerEditDlg : public QDialog
231 ServerEditDlg(const Network::Server& server = Network::Server(), QWidget* parent = nullptr);
233 Network::Server serverData() const;
236 void on_host_textChanged();
239 * Update the default server port according to isChecked
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.
244 * @param isChecked If true and port unchanged, set port to 6697, else set port to 6667.
246 void updateSslPort(bool isChecked);
249 Ui::ServerEditDlg ui;
252 class CapsEditDlg : public QDialog
257 CapsEditDlg(const QString& oldSkipCapsString, QWidget* parent = nullptr);
259 QString skipCapsString() const;
262 void defaultSkipCaps();
263 void on_skipCapsEdit_textChanged(const QString&);
268 QString oldSkipCapsString;
271 class SaveNetworksDlg : public QDialog
276 SaveNetworksDlg(const QList<NetworkInfo>& toCreate,
277 const QList<NetworkInfo>& toUpdate,
278 const QList<NetworkId>& toRemove,
279 QWidget* parent = nullptr);
285 Ui::SaveIdentitiesDlg ui;
287 int numevents, rcvevents;