Add a Configure menu item to Networks in the buffer list
[quassel.git] / src / qtui / settingspages / networkssettingspage.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 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 "network.h"
27 #include "settingspage.h"
28 #include "clientidentity.h"
29
30 #include "ui_networkssettingspage.h"
31 #include "ui_networkadddlg.h"
32 #include "ui_networkeditdlg.h"
33 #include "ui_servereditdlg.h"
34 #include "ui_saveidentitiesdlg.h"
35
36 class NetworksSettingsPage : public SettingsPage
37 {
38     Q_OBJECT
39
40 public:
41     NetworksSettingsPage(QWidget *parent = 0);
42
43     virtual inline bool needsCoreConnection() const { return true; }
44
45     bool aboutToSave();
46
47 public slots:
48     void save();
49     void load();
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 = 0);
61
62     /**
63      * Update the capability-dependent settings according to what the server supports
64      *
65      * For example, this updates the SASL text for when the server advertises support.  This should
66      * only be called on the currently displayed network.
67      *
68      * @param[in] id  NetworkId referencing network used to update settings user interface.
69      */
70     void setNetworkCapStates(NetworkId id);
71
72     void clientNetworkAdded(NetworkId);
73     void clientNetworkRemoved(NetworkId);
74     void clientNetworkUpdated();
75
76     void clientIdentityAdded(IdentityId);
77     void clientIdentityRemoved(IdentityId);
78     void clientIdentityUpdated();
79
80     /**
81      * Update the settings user interface according to capabilities advertised by the IRC server
82      */
83     void clientNetworkCapsUpdated();
84
85 #ifdef HAVE_SSL
86     void sslUpdated();
87 #endif
88
89     void on_networkList_itemSelectionChanged();
90     void on_addNetwork_clicked();
91     void on_deleteNetwork_clicked();
92     void on_renameNetwork_clicked();
93     void on_editIdentities_clicked();
94
95     // void on_connectNow_clicked();
96
97     void on_serverList_itemSelectionChanged();
98     void on_addServer_clicked();
99     void on_deleteServer_clicked();
100     void on_editServer_clicked();
101     void on_upServer_clicked();
102     void on_downServer_clicked();
103
104     /**
105      * Event handler for SASL status Details button
106      */
107     void on_saslStatusDetails_clicked();
108
109 private:
110     /**
111      * Status of capability support
112      */
113     enum CapSupportStatus {
114         Unknown,           ///< Old core, or otherwise unknown, can't make assumptions
115         Disconnected,      ///< Disconnected from network, can't determine
116         MaybeUnsupported,  ///< Server does not advertise support at this moment
117         MaybeSupported     ///< Server advertises support at this moment
118     };
119     // Keep in mind networks can add, change, and remove capabilities at any time.
120
121     Ui::NetworksSettingsPage ui;
122
123     NetworkId currentId;
124     QHash<NetworkId, NetworkInfo> networkInfos;
125     bool _ignoreWidgetChanges;
126 #ifdef HAVE_SSL
127     CertIdentity *_cid;
128 #endif
129
130     QIcon connectedIcon, connectingIcon, disconnectedIcon;
131
132     // Status icons
133     QIcon infoIcon, warningIcon;
134
135     CapSupportStatus _saslStatusSelected;  /// Status of SASL support for currently-selected network
136
137     void reset();
138     bool testHasChanged();
139     QListWidgetItem *insertNetwork(NetworkId);
140     QListWidgetItem *insertNetwork(const NetworkInfo &info);
141     QListWidgetItem *networkItem(NetworkId) const;
142     void saveToNetworkInfo(NetworkInfo &);
143     IdentityId defaultIdentity() const;
144
145     /**
146      * Update the SASL settings interface according to the given SASL state
147      *
148      * @param[in] saslStatus Current status of SASL support.
149      */
150     void setSASLStatus(const CapSupportStatus saslStatus);
151 };
152
153
154 class NetworkAddDlg : public QDialog
155 {
156     Q_OBJECT
157
158 public:
159     NetworkAddDlg(const QStringList &existing = QStringList(), QWidget *parent = 0);
160
161     NetworkInfo networkInfo() const;
162
163 private slots:
164     void setButtonStates();
165
166     /**
167      * Update the default server port according to isChecked
168      *
169      * Connect with useSSL->toggled() in order to keep the port number in sync.  This only modifies
170      * the port if it's not been changed from defaults.
171      *
172      * @param isChecked If true and port unchanged, set port to 6697, else set port to 6667.
173      */
174     void updateSslPort(bool isChecked);
175
176 private:
177     Ui::NetworkAddDlg ui;
178
179     QStringList existing;
180 };
181
182
183 class NetworkEditDlg : public QDialog
184 {
185     Q_OBJECT
186
187 public:
188     NetworkEditDlg(const QString &old, const QStringList &existing = QStringList(), QWidget *parent = 0);
189
190     QString networkName() const;
191
192 private slots:
193     void on_networkEdit_textChanged(const QString &);
194
195 private:
196     Ui::NetworkEditDlg ui;
197
198     QStringList existing;
199 };
200
201
202 class ServerEditDlg : public QDialog
203 {
204     Q_OBJECT
205
206 public:
207     ServerEditDlg(const Network::Server &server = Network::Server(), QWidget *parent = 0);
208
209     Network::Server serverData() const;
210
211 private slots:
212     void on_host_textChanged();
213
214     /**
215      * Update the default server port according to isChecked
216      *
217      * Connect with useSSL->toggled() in order to keep the port number in sync.  This only modifies
218      * the port if it's not been changed from defaults.
219      *
220      * @param isChecked If true and port unchanged, set port to 6697, else set port to 6667.
221      */
222     void updateSslPort(bool isChecked);
223
224 private:
225     Ui::ServerEditDlg ui;
226 };
227
228
229 class SaveNetworksDlg : public QDialog
230 {
231     Q_OBJECT
232
233 public:
234     SaveNetworksDlg(const QList<NetworkInfo> &toCreate, const QList<NetworkInfo> &toUpdate, const QList<NetworkId> &toRemove, QWidget *parent = 0);
235
236 private slots:
237     void clientEvent();
238
239 private:
240     Ui::SaveIdentitiesDlg ui;
241
242     int numevents, rcvevents;
243 };
244
245
246 #endif