This repository was archived by the owner on Sep 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathNetworkSettingsTab.cpp
321 lines (275 loc) · 9.19 KB
/
NetworkSettingsTab.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/***************************************************************************//**
* @brief Thumbnail me 3.0
* Thumbnail me is a user interface for Movie thumbnailer.
* Generate thumbnails from any movie is now easier !
*
* @file NetworkSettingsTab.cpp
* @class NetworkSettingsTab
* Cette classe permet de configurer manuellement un proxy.
* Elle génère un widget disponible dans le widget "Settings".
*
* @author Quentin Rousseau\n
* @note Copyright (C) 2011-2012 Quentin Rousseau\n
* License: GNU General Public License version 2 (GPLv2) - http://www.gnu.org/licenses/gpl-2.0.html\n
* Site web: www.thumbnailme.com\n
* Email: quentin.rousseau@thumbnailme.com
*
* @since 3.0
* @version 3.0
* @date 2011-2012
*******************************************************************************/
#include "NetworkSettingsTab.h"
#include "defines.h"
#include "IniManager.h"
/**
*@brief Constructeur.
*/
NetworkSettingsTab::NetworkSettingsTab()
{
settings = new QSettings(QSettings::IniFormat,DEFAULT_PATH_INI,APPLICATION_NAME,DEFAULT_FILE_INI,this);
QGridLayout *networkLayout = new QGridLayout;
QHBoxLayout *networkHLayout = new QHBoxLayout;
/*Construction du groupBox "Connection"*/
connectionGroupBox = new QGroupBox(this);
directConnectionRadio = new QRadioButton(this);
useProxyRadio = new QRadioButton(this);
QVBoxLayout *networkGroupBoxLayout = new QVBoxLayout;
networkGroupBoxLayout->addWidget(directConnectionRadio);
networkGroupBoxLayout->addWidget(useProxyRadio);
connectionGroupBox->setLayout(networkGroupBoxLayout);
/*Construction du groupBox "Proxy"*/
proxyHostnameLabel = new QLabel(this);
proxyPortLabel = new QLabel(this);
proxyType = new QLabel(this);
proxyAuthenticationCheckbox = new QCheckBox(this);
proxyUsernameLabel = new QLabel(this);
proxyUsernameLineEdit = new QLineEdit(this);
proxyPasswordLabel = new QLabel(this);
proxyPasswordLineEdit = new QLineEdit(this);
proxyPasswordLineEdit->setEchoMode(QLineEdit::Password);
proxyGroupBox = new QGroupBox(this);
QGridLayout *proxyGroupBoxLayout = new QGridLayout;
proxyHostnameLineEdit = new QLineEdit(this);
//Range port 0-65535
proxyPortLineEdit = new QSpinBox(this);
proxyPortLineEdit->setMaximum(65536);
proxyTypeHttpRadio = new QRadioButton(this);
proxyTypeSocks5Radio = new QRadioButton(this);
proxyGroupBoxLayout->addWidget(proxyHostnameLabel,0,0);
proxyGroupBoxLayout->addWidget(proxyHostnameLineEdit,0,1);
proxyGroupBoxLayout->addWidget(proxyPortLabel,1,0);
proxyGroupBoxLayout->addWidget(proxyPortLineEdit,1,1);
QHBoxLayout *typeLayout = new QHBoxLayout;
typeLayout->addWidget(proxyTypeHttpRadio);
typeLayout->addWidget(proxyTypeSocks5Radio);
proxyGroupBoxLayout->addWidget(proxyType,2,0);
proxyGroupBoxLayout->addLayout(typeLayout,2,1);
proxyGroupBoxLayout->addWidget(proxyAuthenticationCheckbox,3,0);
proxyGroupBoxLayout->addWidget(proxyUsernameLabel,4,0);
proxyGroupBoxLayout->addWidget(proxyUsernameLineEdit,4,1,1,2);
proxyGroupBoxLayout->addWidget(proxyPasswordLabel,5,0);
proxyGroupBoxLayout->addWidget(proxyPasswordLineEdit,5,1,1,2);
proxyGroupBox->setLayout(proxyGroupBoxLayout);
/*Layout en haut*/
networkHLayout->addWidget(connectionGroupBox);
/*Layout global*/
networkLayout->addLayout(networkHLayout,0,0);
networkLayout->addWidget(proxyGroupBox);
this->initializeWidget();
this->setLayout(networkLayout);
this->retranslate();
/*Connections*/
connect(useProxyRadio,SIGNAL(toggled(bool)),this,SLOT(setEnabledProxyGroupBox(bool)));
connect(proxyAuthenticationCheckbox,SIGNAL(clicked(bool)),proxyUsernameLineEdit,SLOT(setEnabled(bool)));
connect(proxyAuthenticationCheckbox,SIGNAL(clicked(bool)),proxyPasswordLineEdit,SLOT(setEnabled(bool)));
}
/**
*@brief Destructeur.
*/
NetworkSettingsTab::~NetworkSettingsTab()
{
}
/**
*@brief Initialisation des paramètres du widget.
*/
void NetworkSettingsTab::initializeWidget()
{
/*Initialisation du widget selon les paramètres du fichier de configuration*/
setProxyHostname(settings->value("Proxy/hostname").toString());
if(!settings->value("Proxy/port").isNull())
setProxyPort(settings->value("Proxy/port").toInt());
else
setProxyPort(8080);
setProxyType(settings->value("Proxy/type").toInt());
setProxyUsername(settings->value("Proxy/username").toByteArray());
setProxyPassword(settings->value("Proxy/password").toByteArray());
if (settings->value("Proxy/enabled") == "true")
{
useProxyRadio->setChecked(true);
setEnabledProxyGroupBox(true);
}
else
{
directConnectionRadio->setChecked(true);
proxyGroupBox->setDisabled(true);
}
if (settings->value("Proxy/authenticationEnabled") == "true")
proxyAuthenticationCheckbox->setChecked(true);
else proxyAuthenticationCheckbox->setChecked(false);
}
/**
*@brief Retourne l'adresse hôte du proxy.
*@return QString - Valeur du champ.
*/
QString NetworkSettingsTab::getProxyHostname()
{
return proxyHostnameLineEdit->text();
}
/**
*@brief Retourne le port du proxy.
*@return QString - Valeur du champ.
*/
QString NetworkSettingsTab::getProxyPort()
{
return proxyPortLineEdit->text();
}
/**
*@brief Retourne le nom d'utilisateur codé en base 64 pour une connexion avec authentification.
*@return QByteArray - Valeur du champ.
*/
QByteArray NetworkSettingsTab::getProxyUsername()
{
return proxyUsernameLineEdit->text().toLatin1().toBase64();
}
/**
*@brief Retourne le mot de passe codé en base 64 pour une connection avec authentification.
*@return QByteArray - Valeur du champ.
*/
QByteArray NetworkSettingsTab::getProxyPassword()
{
return proxyPasswordLineEdit->text().toLatin1().toBase64();
}
/**
*@brief Retourne le type de proxy (HTTP ou SOCK5).
*@return int - 1 = HTTP | 2 = SOCK5.
*/
int NetworkSettingsTab::getProxyType()
{
if (proxyTypeHttpRadio->isChecked())
return 0;
else return 1;
}
/**
*@brief Setter de l'adresse hôte du proxy.
*@param hostname Adresse hôte du proxy.
*/
void NetworkSettingsTab::setProxyHostname(QString hostname)
{
proxyHostnameLineEdit->setText(hostname);
}
/**
*@brief Setter du port du proxy
*@param port Port du proxy.
*/
void NetworkSettingsTab::setProxyPort(int port)
{
proxyPortLineEdit->setValue(port);
}
/**
*@brief Setter du nom d'utilisateur pour une connection avec authentification.
*@param username Nom d'utilisateur en base 64.
*/
void NetworkSettingsTab::setProxyUsername(QByteArray username)
{
proxyUsernameLineEdit->setText(QByteArray::fromBase64(username));
}
/**
*@brief Setter du mot de passe pour une connection avec authentification.
*@param password Mot de passe en base 64.
*/
void NetworkSettingsTab::setProxyPassword(QByteArray password)
{
proxyPasswordLineEdit->setText(QByteArray::fromBase64(password));
}
/**
*@brief Setter du type de proxy (HTTP ou SOCK5).
*@param type 1 = HTTP | 2 = SOCK5.
*/
void NetworkSettingsTab::setProxyType(int type)
{
if (type == 0)
proxyTypeHttpRadio->setChecked(true);
else proxyTypeSocks5Radio->setChecked(true);
}
/**
*@brief Retourne vrai si le proxy est activé sinon faux.
*@return bool - Vrai ou faux.
*/
bool NetworkSettingsTab::isProxyChecked()
{
return useProxyRadio->isChecked();
}
/**
*@brief Retourne vrai si l'authenfication est activée sinon faux.
*@return bool - Vrai ou faux.
*/
bool NetworkSettingsTab::isAuthenticationChecked()
{
return proxyAuthenticationCheckbox->isChecked();
}
/**
*@brief Active ou désactive la partie proxy.
*@param checked Vrai ou faux.
*/
void NetworkSettingsTab::setEnabledProxyGroupBox(bool checked)
{
if(checked)
{
proxyGroupBox->setEnabled(true);
if (settings->value("Proxy/authenticationEnabled") != "true")
{
proxyAuthenticationCheckbox->setChecked(false);
proxyUsernameLineEdit->setDisabled(true);
proxyPasswordLineEdit->setDisabled(true);
}
}
else
{
proxyGroupBox->setDisabled(true);
}
}
/**
*@brief Fonction annulation - Réaffecte les paramètres d'origine.
*/
void NetworkSettingsTab::reject()
{
this->initializeWidget();
}
/**
*@brief ChangeEvent.
*@param *event Evenement.
*/
void NetworkSettingsTab::changeEvent(QEvent* event)
{
if (event->type() == QEvent::LanguageChange)
retranslate();
QWidget::changeEvent(event);
}
/**
*@brief Fonction de traduction dynamique.
*/
void NetworkSettingsTab::retranslate()
{
connectionGroupBox->setTitle( tr("Network Connection") );
directConnectionRadio->setText( tr("Direct connection") );
useProxyRadio->setText( tr("Use proxy server") );
proxyHostnameLabel->setText( tr("Hostname") + " : " );
proxyPortLabel->setText( tr("Port") + " : " );
proxyType->setText( tr("Type") + " : " );
proxyAuthenticationCheckbox->setText( tr("Authentication") );
proxyUsernameLabel->setText( tr("Username") + " : " );
proxyPasswordLabel->setText( tr("Password") + " : " );
proxyGroupBox->setTitle( tr("Proxy Settings") );
proxyTypeHttpRadio->setText( "HTTP" );
proxyTypeSocks5Radio->setText( "SOCKS5" );
}