Sync default port with Use encrypted connection
[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     void clientNetworkAdded(NetworkId);
62     void clientNetworkRemoved(NetworkId);
63     void clientNetworkUpdated();
64
65     void clientIdentityAdded(IdentityId);
66     void clientIdentityRemoved(IdentityId);
67     void clientIdentityUpdated();
68
69 #ifdef HAVE_SSL
70     void sslUpdated();
71 #endif
72
73     void on_networkList_itemSelectionChanged();
74     void on_addNetwork_clicked();
75     void on_deleteNetwork_clicked();
76     void on_renameNetwork_clicked();
77     void on_editIdentities_clicked();
78
79     // void on_connectNow_clicked();
80
81     void on_serverList_itemSelectionChanged();
82     void on_addServer_clicked();
83     void on_deleteServer_clicked();
84     void on_editServer_clicked();
85     void on_upServer_clicked();
86     void on_downServer_clicked();
87
88 private:
89     Ui::NetworksSettingsPage ui;
90
91     NetworkId currentId;
92     QHash<NetworkId, NetworkInfo> networkInfos;
93     bool _ignoreWidgetChanges;
94 #ifdef HAVE_SSL
95     CertIdentity *_cid;
96 #endif
97
98     QIcon connectedIcon, connectingIcon, disconnectedIcon;
99
100     void reset();
101     bool testHasChanged();
102     QListWidgetItem *insertNetwork(NetworkId);
103     QListWidgetItem *insertNetwork(const NetworkInfo &info);
104     QListWidgetItem *networkItem(NetworkId) const;
105     void saveToNetworkInfo(NetworkInfo &);
106     IdentityId defaultIdentity() const;
107 };
108
109
110 class NetworkAddDlg : public QDialog
111 {
112     Q_OBJECT
113
114 public:
115     NetworkAddDlg(const QStringList &existing = QStringList(), QWidget *parent = 0);
116
117     NetworkInfo networkInfo() const;
118
119 private slots:
120     void setButtonStates();
121
122     /**
123      * Update the default server port according to isChecked
124      *
125      * Connect with useSSL->toggled() in order to keep the port number in sync.  This only modifies
126      * the port if it's not been changed from defaults.
127      *
128      * @param isChecked If true and port unchanged, set port to 6697, else set port to 6667.
129      */
130     void updateSslPort(bool isChecked);
131
132 private:
133     Ui::NetworkAddDlg ui;
134
135     QStringList existing;
136 };
137
138
139 class NetworkEditDlg : public QDialog
140 {
141     Q_OBJECT
142
143 public:
144     NetworkEditDlg(const QString &old, const QStringList &existing = QStringList(), QWidget *parent = 0);
145
146     QString networkName() const;
147
148 private slots:
149     void on_networkEdit_textChanged(const QString &);
150
151 private:
152     Ui::NetworkEditDlg ui;
153
154     QStringList existing;
155 };
156
157
158 class ServerEditDlg : public QDialog
159 {
160     Q_OBJECT
161
162 public:
163     ServerEditDlg(const Network::Server &server = Network::Server(), QWidget *parent = 0);
164
165     Network::Server serverData() const;
166
167 private slots:
168     void on_host_textChanged();
169
170     /**
171      * Update the default server port according to isChecked
172      *
173      * Connect with useSSL->toggled() in order to keep the port number in sync.  This only modifies
174      * the port if it's not been changed from defaults.
175      *
176      * @param isChecked If true and port unchanged, set port to 6697, else set port to 6667.
177      */
178     void updateSslPort(bool isChecked);
179
180 private:
181     Ui::ServerEditDlg ui;
182 };
183
184
185 class SaveNetworksDlg : public QDialog
186 {
187     Q_OBJECT
188
189 public:
190     SaveNetworksDlg(const QList<NetworkInfo> &toCreate, const QList<NetworkInfo> &toUpdate, const QList<NetworkId> &toRemove, QWidget *parent = 0);
191
192 private slots:
193     void clientEvent();
194
195 private:
196     Ui::SaveIdentitiesDlg ui;
197
198     int numevents, rcvevents;
199 };
200
201
202 #endif