forked from saa7go/qDebDownloader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxydialog.cpp
More file actions
134 lines (114 loc) · 4.03 KB
/
proxydialog.cpp
File metadata and controls
134 lines (114 loc) · 4.03 KB
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
/* This file is part of qDebDownloader.
*
* Copyright (c) 2011 - Christian Kurniawan Ginting S. <saa7_go@terralinux.org>
*
* qDebDownloader is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* qDebDownloader is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with qDebDownloader. If not, see <http://www.gnu.org/licenses/>. */
#include "proxydialog.h"
#include "ui_proxydialog.h"
#include <QSettings>
#include <QValidator>
ProxyDialog::ProxyDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ProxyDialog)
{
ui->setupUi(this);
ui->proxyListComboBox->clear();
ui->proxyListComboBox->addItem(tr("No Proxy"));
ui->proxyListComboBox->addItem(tr("Default Proxy"));
ui->proxyListComboBox->addItem(tr("Http Proxy"));
ui->proxyListComboBox->addItem(tr("Socks5 Proxy"));
ui->portEdit->setValidator(new QIntValidator(0, 65535, this));
connect(ui->okButton, SIGNAL(clicked()), SLOT(acceptProxy()));
connect(ui->okButton, SIGNAL(clicked()), SLOT(accept()));
connect(ui->cancelButton, SIGNAL(clicked()), SLOT(reject()));
connect(ui->proxyListComboBox, SIGNAL(currentIndexChanged(int)), SLOT(proxyIndexListChanged(int)));
ui->frame->setVisible(false);
readSetting();
}
ProxyDialog::~ProxyDialog()
{
delete ui;
}
void ProxyDialog::acceptProxy()
{
m_proxy = QNetworkProxy(); // reset
int index = ui->proxyListComboBox->currentIndex();
if(index == 0)
m_proxy.setType(QNetworkProxy::NoProxy);
else if(index == 1)
m_proxy.setType(QNetworkProxy::DefaultProxy);
else {
if(index == 2)
m_proxy.setType(QNetworkProxy::HttpProxy);
else if(index == 3)
m_proxy.setType(QNetworkProxy::Socks5Proxy);
else
return;
m_proxy.setHostName(ui->hostnameEdit->text());
m_proxy.setPort(ui->portEdit->text().toInt());
m_proxy.setUser(ui->usernameEdit->text());
m_proxy.setPassword(ui->passwordEdit->text());
}
writeSetting();
}
void ProxyDialog::proxyIndexListChanged(int index)
{
switch(index)
{
case 0:
case 1:
ui->frame->setVisible(false);
break;
case 2:
case 3:
ui->frame->setVisible(true);
break;
}
}
void ProxyDialog::readSetting()
{
QSettings setting("./apt-web.ini", QSettings::IniFormat);
int type = setting.value("Proxy/Type", 0).toInt();
if(type < 0 || type > 3)
type = 0;
ui->proxyListComboBox->setCurrentIndex(type);
if(type == 2 || type == 3){
QString host = setting.value("Proxy/Hostname", "").toString();
int port = setting.value("Proxy/Port", 0).toInt();
QString username = setting.value("Proxy/Username", "").toString();
QString password = setting.value("Proxy/Password", "").toString();
ui->hostnameEdit->setText(host);
ui->portEdit->setText(port == 0 ? "" : QString::number(port));
ui->usernameEdit->setText(username);
ui->passwordEdit->setText(password);
}
}
void ProxyDialog::writeSetting()
{
QSettings setting("./apt-web.ini", QSettings::IniFormat);
int index = ui->proxyListComboBox->currentIndex();
setting.setValue("Proxy/Type", index);
int port = 0;
QString host = "", username = "", password = "";
if(index == 2 || index == 3){
host = ui->hostnameEdit->text();
port = ui->portEdit->text().toInt();
username = ui->usernameEdit->text();
password = ui->passwordEdit->text();
}
setting.setValue("Proxy/Hostname", host);
setting.setValue("Proxy/Port", port);
setting.setValue("Proxy/Username", username);
setting.setValue("Proxy/Password", password);
}