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_networkadddlg.h"
31 #include "ui_networkeditdlg.h"
32 #include "ui_networkssettingspage.h"
33 #include "ui_saveidentitiesdlg.h"
34 #include "ui_servereditdlg.h"
36 class NetworksSettingsPage : public SettingsPage
41 NetworksSettingsPage(QWidget* parent = nullptr);
43 inline bool needsCoreConnection() const override { return true; }
45 bool aboutToSave() override;
50 void bufferList_Open(NetworkId);
53 void widgetHasChanged();
54 void setWidgetStates();
55 void coreConnectionStateChanged(bool);
56 void networkConnectionStateChanged(Network::ConnectionState state);
57 void networkConnectionError(const QString& msg);
59 void displayNetwork(NetworkId);
60 void setItemState(NetworkId, QListWidgetItem* item = nullptr);
63 * Reset the capability-dependent settings to the default unknown states
65 * For example, this updates the SASL text to indicate the status is unknown. Any actual
66 * information should be set by setNetworkCapStates()
68 * @see NetworksSettingsPage::setNetworkCapStates()
70 void resetNetworkCapStates();
73 * Update the capability-dependent settings according to what the server supports
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.
78 * @param[in] id NetworkId referencing network used to update settings user interface.
80 void setNetworkCapStates(NetworkId id);
82 void clientNetworkAdded(NetworkId);
83 void clientNetworkRemoved(NetworkId);
84 void clientNetworkUpdated();
86 void clientIdentityAdded(IdentityId);
87 void clientIdentityRemoved(IdentityId);
88 void clientIdentityUpdated();
91 * Update the settings user interface according to capabilities advertised by the IRC server
93 void clientNetworkCapsUpdated();
99 void on_networkList_itemSelectionChanged();
100 void on_addNetwork_clicked();
101 void on_deleteNetwork_clicked();
102 void on_renameNetwork_clicked();
103 void on_editIdentities_clicked();
105 // void on_connectNow_clicked();
107 void on_serverList_itemSelectionChanged();
108 void on_addServer_clicked();
109 void on_deleteServer_clicked();
110 void on_editServer_clicked();
111 void on_upServer_clicked();
112 void on_downServer_clicked();
115 * Event handler for SASL status Details button
117 void on_saslStatusDetails_clicked();
121 * Status of capability support
123 enum CapSupportStatus
125 Unknown, ///< Old core, or otherwise unknown, can't make assumptions
126 Disconnected, ///< Disconnected from network, can't determine
127 MaybeUnsupported, ///< Server does not advertise support at this moment
128 MaybeSupported ///< Server advertises support at this moment
130 // Keep in mind networks can add, change, and remove capabilities at any time.
132 Ui::NetworksSettingsPage ui;
135 QHash<NetworkId, NetworkInfo> networkInfos;
136 bool _ignoreWidgetChanges{false};
138 CertIdentity* _cid{nullptr};
141 QIcon connectedIcon, connectingIcon, disconnectedIcon;
144 QIcon infoIcon, warningIcon;
146 CapSupportStatus _saslStatusSelected; /// Status of SASL support for currently-selected network
149 bool testHasChanged();
150 QListWidgetItem* insertNetwork(NetworkId);
151 QListWidgetItem* insertNetwork(const NetworkInfo& info);
152 QListWidgetItem* networkItem(NetworkId) const;
153 void saveToNetworkInfo(NetworkInfo&);
154 IdentityId defaultIdentity() const;
157 * Update the SASL settings interface according to the given SASL state
159 * @param[in] saslStatus Current status of SASL support.
161 void setSASLStatus(const CapSupportStatus saslStatus);
164 class NetworkAddDlg : public QDialog
169 NetworkAddDlg(QStringList existing = QStringList(), QWidget* parent = nullptr);
171 NetworkInfo networkInfo() const;
174 void setButtonStates();
177 * Update the default server port according to isChecked
179 * Connect with useSSL->toggled() in order to keep the port number in sync. This only modifies
180 * the port if it's not been changed from defaults.
182 * @param isChecked If true and port unchanged, set port to 6697, else set port to 6667.
184 void updateSslPort(bool isChecked);
187 Ui::NetworkAddDlg ui;
189 QStringList existing;
192 class NetworkEditDlg : public QDialog
197 NetworkEditDlg(const QString& old, QStringList existing = QStringList(), QWidget* parent = nullptr);
199 QString networkName() const;
202 void on_networkEdit_textChanged(const QString&);
205 Ui::NetworkEditDlg ui;
207 QStringList existing;
210 class ServerEditDlg : public QDialog
215 ServerEditDlg(const Network::Server& server = Network::Server(), QWidget* parent = nullptr);
217 Network::Server serverData() const;
220 void on_host_textChanged();
223 * Update the default server port according to isChecked
225 * Connect with useSSL->toggled() in order to keep the port number in sync. This only modifies
226 * the port if it's not been changed from defaults.
228 * @param isChecked If true and port unchanged, set port to 6697, else set port to 6667.
230 void updateSslPort(bool isChecked);
233 Ui::ServerEditDlg ui;
236 class SaveNetworksDlg : public QDialog
241 SaveNetworksDlg(const QList<NetworkInfo>& toCreate,
242 const QList<NetworkInfo>& toUpdate,
243 const QList<NetworkId>& toRemove,
244 QWidget* parent = nullptr);
250 Ui::SaveIdentitiesDlg ui;
252 int numevents, rcvevents;