Encourage SASL over NickServ when server supports
[quassel.git] / src / qtui / settingspages / networkssettingspage.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2016 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
51 private slots:
52     void widgetHasChanged();
53     void setWidgetStates();
54     void coreConnectionStateChanged(bool);
55     void networkConnectionStateChanged(Network::ConnectionState state);
56     void networkConnectionError(const QString &msg);
57
58     void displayNetwork(NetworkId);
59     void setItemState(NetworkId, QListWidgetItem *item = 0);
60
61     /**
62      * Update the capability-dependent settings according to what the server supports
63      *
64      * For example, this updates the SASL text for when the server advertises support.  This should
65      * only be called on the currently displayed network.
66      *
67      * @param[in] id  NetworkId referencing network used to update settings user interface.
68      */
69     void setNetworkCapStates(NetworkId id);
70
71     void clientNetworkAdded(NetworkId);
72     void clientNetworkRemoved(NetworkId);
73     void clientNetworkUpdated();
74
75     void clientIdentityAdded(IdentityId);
76     void clientIdentityRemoved(IdentityId);
77     void clientIdentityUpdated();
78
79     /**
80      * Update the settings user interface according to capabilities advertised by the IRC server
81      */
82     void clientNetworkCapsUpdated();
83
84 #ifdef HAVE_SSL
85     void sslUpdated();
86 #endif
87
88     void on_networkList_itemSelectionChanged();
89     void on_addNetwork_clicked();
90     void on_deleteNetwork_clicked();
91     void on_renameNetwork_clicked();
92     void on_editIdentities_clicked();
93
94     // void on_connectNow_clicked();
95
96     void on_serverList_itemSelectionChanged();
97     void on_addServer_clicked();
98     void on_deleteServer_clicked();
99     void on_editServer_clicked();
100     void on_upServer_clicked();
101     void on_downServer_clicked();
102
103 private:
104     Ui::NetworksSettingsPage ui;
105
106     NetworkId currentId;
107     QHash<NetworkId, NetworkInfo> networkInfos;
108     bool _ignoreWidgetChanges;
109 #ifdef HAVE_SSL
110     CertIdentity *_cid;
111 #endif
112
113     QIcon connectedIcon, connectingIcon, disconnectedIcon;
114
115     void reset();
116     bool testHasChanged();
117     QListWidgetItem *insertNetwork(NetworkId);
118     QListWidgetItem *insertNetwork(const NetworkInfo &info);
119     QListWidgetItem *networkItem(NetworkId) const;
120     void saveToNetworkInfo(NetworkInfo &);
121     IdentityId defaultIdentity() const;
122 };
123
124
125 class NetworkAddDlg : public QDialog
126 {
127     Q_OBJECT
128
129 public:
130     NetworkAddDlg(const QStringList &existing = QStringList(), QWidget *parent = 0);
131
132     NetworkInfo networkInfo() const;
133
134 private slots:
135     void setButtonStates();
136
137     /**
138      * Update the default server port according to isChecked
139      *
140      * Connect with useSSL->toggled() in order to keep the port number in sync.  This only modifies
141      * the port if it's not been changed from defaults.
142      *
143      * @param isChecked If true and port unchanged, set port to 6697, else set port to 6667.
144      */
145     void updateSslPort(bool isChecked);
146
147 private:
148     Ui::NetworkAddDlg ui;
149
150     QStringList existing;
151 };
152
153
154 class NetworkEditDlg : public QDialog
155 {
156     Q_OBJECT
157
158 public:
159     NetworkEditDlg(const QString &old, const QStringList &existing = QStringList(), QWidget *parent = 0);
160
161     QString networkName() const;
162
163 private slots:
164     void on_networkEdit_textChanged(const QString &);
165
166 private:
167     Ui::NetworkEditDlg ui;
168
169     QStringList existing;
170 };
171
172
173 class ServerEditDlg : public QDialog
174 {
175     Q_OBJECT
176
177 public:
178     ServerEditDlg(const Network::Server &server = Network::Server(), QWidget *parent = 0);
179
180     Network::Server serverData() const;
181
182 private slots:
183     void on_host_textChanged();
184
185     /**
186      * Update the default server port according to isChecked
187      *
188      * Connect with useSSL->toggled() in order to keep the port number in sync.  This only modifies
189      * the port if it's not been changed from defaults.
190      *
191      * @param isChecked If true and port unchanged, set port to 6697, else set port to 6667.
192      */
193     void updateSslPort(bool isChecked);
194
195 private:
196     Ui::ServerEditDlg ui;
197 };
198
199
200 class SaveNetworksDlg : public QDialog
201 {
202     Q_OBJECT
203
204 public:
205     SaveNetworksDlg(const QList<NetworkInfo> &toCreate, const QList<NetworkInfo> &toUpdate, const QList<NetworkId> &toRemove, QWidget *parent = 0);
206
207 private slots:
208     void clientEvent();
209
210 private:
211     Ui::SaveIdentitiesDlg ui;
212
213     int numevents, rcvevents;
214 };
215
216
217 #endif