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 _saslStatusSelected; /// Status of SASL support for currently-selected network
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;
164 * Update the SASL settings interface according to the given SASL state
166 * @param[in] saslStatus Current status of SASL support.
168 void setSASLStatus(const CapSupportStatus saslStatus);
171 class NetworkAddDlg : public QDialog
176 NetworkAddDlg(QStringList existing = QStringList(), QWidget* parent = nullptr);
178 NetworkInfo networkInfo() const;
181 void setButtonStates();
184 * Update the default server port according to isChecked
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.
189 * @param isChecked If true and port unchanged, set port to 6697, else set port to 6667.
191 void updateSslPort(bool isChecked);
194 Ui::NetworkAddDlg ui;
196 QStringList existing;
199 class NetworkEditDlg : public QDialog
204 NetworkEditDlg(const QString& old, QStringList existing = QStringList(), QWidget* parent = nullptr);
206 QString networkName() const;
209 void on_networkEdit_textChanged(const QString&);
212 Ui::NetworkEditDlg ui;
214 QStringList existing;
217 class ServerEditDlg : public QDialog
222 ServerEditDlg(const Network::Server& server = Network::Server(), QWidget* parent = nullptr);
224 Network::Server serverData() const;
227 void on_host_textChanged();
230 * Update the default server port according to isChecked
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.
235 * @param isChecked If true and port unchanged, set port to 6697, else set port to 6667.
237 void updateSslPort(bool isChecked);
240 Ui::ServerEditDlg ui;
243 class CapsEditDlg : public QDialog
248 CapsEditDlg(const QString& oldSkipCapsString, QWidget* parent = nullptr);
250 QString skipCapsString() const;
253 void defaultSkipCaps();
254 void on_skipCapsEdit_textChanged(const QString&);
259 QString oldSkipCapsString;
262 class SaveNetworksDlg : public QDialog
267 SaveNetworksDlg(const QList<NetworkInfo>& toCreate,
268 const QList<NetworkInfo>& toUpdate,
269 const QList<NetworkId>& toRemove,
270 QWidget* parent = nullptr);
276 Ui::SaveIdentitiesDlg ui;
278 int numevents, rcvevents;