51de32b7d1e97887869a21ac6329a1e64973491e
[aspt.git] / proxyset.cc
1 /*******************************************************************
2 Jan Cermak | johniez | aspt.johniez.com
3 Creative Commons 2.5 Attribution-NonCommercial-NoDerivs 2.5 license
4 http://creativecommons.org/licenses/by-nc-nd/2.5/legalcode
5 *******************************************************************/
6
7 #include "proxyset.h"
8
9 ProxySet::ProxySet(QWidget *parent) : QWidget(parent) {
10         QSettings settings("config/global.ini", QSettings::IniFormat);
11         useProxy = settings.value("Network/proxyUsed", 0).toInt();
12         QString addrS = settings.value("Network/proxyAddr", "").toString();
13         QString portS = settings.value("Network/proxyPort", "").toString();
14         QString nameS = settings.value("Network/proxyName", "").toString();
15         QString passS = settings.value("Network/proxyPass", "").toString();
16         
17         mainLayout = new QVBoxLayout;
18         proxy = new QCheckBox(tr("Use proxy server"));
19         proxy->setCheckState((Qt::CheckState) useProxy);
20         connect(proxy, SIGNAL(stateChanged(int)), this, SLOT(checkChange(int)));
21         addr = new QLabel(tr("proxy address:"));
22         port = new QLabel(tr("proxy port:"));
23         name = new QLabel(tr("proxy username:"));
24         pass = new QLabel(tr("proxy password:"));
25         addrP = new QLineEdit(addrS);
26         portP = new QLineEdit(portS);
27         nameP = new QLineEdit(nameS);
28         passP = new QLineEdit(passS);
29         passP->setEchoMode(QLineEdit::Password);
30         saveButt = new QPushButton(tr("Save changes"));
31         connect(saveButt, SIGNAL(clicked()), this, SLOT(save()));
32         mainLayout->addWidget(proxy);
33         mainLayout->addWidget(addr);
34         mainLayout->addWidget(addrP);
35         mainLayout->addWidget(port);
36         mainLayout->addWidget(portP);
37         mainLayout->addWidget(name);
38         mainLayout->addWidget(nameP);
39         mainLayout->addWidget(pass);
40         mainLayout->addWidget(passP);
41         mainLayout->addWidget(saveButt);
42         setLayout(mainLayout);
43         this->show();
44 }
45
46 ProxySet::~ProxySet() {
47         delete addrP;
48         delete portP;
49         delete nameP;
50         delete passP;
51         delete proxy;
52         delete addr;
53         delete port;
54         delete name;
55         delete pass;
56         delete saveButt;
57         delete mainLayout;
58 }
59
60 void ProxySet::save() {
61         QSettings settings("config/global.ini", QSettings::IniFormat);
62         settings.setValue("Network/proxyUsed", useProxy);
63         settings.setValue("Network/proxyAddr", addrP->text());
64         settings.setValue("Network/proxyPort", portP->text());
65         settings.setValue("Network/proxyName", nameP->text());
66         settings.setValue("Network/proxyPass", passP->text());
67         settings.sync();
68 }
69
70 void ProxySet::checkChange(int state) {
71         useProxy = state;
72 }