6da3d4afccc435b5212ba5c8f0be9773254ad4fe
[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 /**
10  * \brief Proxy settings widget constructor.
11  */
12 ProxySet::ProxySet(QWidget *parent) : QWidget(parent) {
13         QSettings settings("config/global.ini", QSettings::IniFormat);
14         useProxy = settings.value("Network/proxyUsed", 0).toInt();
15         QString addrS = settings.value("Network/proxyAddr", "").toString();
16         QString portS = settings.value("Network/proxyPort", "").toString();
17         QString nameS = settings.value("Network/proxyName", "").toString();
18         QString passS = settings.value("Network/proxyPass", "").toString();
19         
20         mainLayout = new QVBoxLayout;
21         proxy = new QCheckBox(tr("Use proxy server"));
22         proxy->setCheckState((Qt::CheckState) useProxy);
23         connect(proxy, SIGNAL(stateChanged(int)), this, SLOT(checkChange(int)));
24         addr = new QLabel(tr("proxy address:"));
25         port = new QLabel(tr("proxy port:"));
26         name = new QLabel(tr("proxy username:"));
27         pass = new QLabel(tr("proxy password:"));
28         addrP = new QLineEdit(addrS);
29         portP = new QLineEdit(portS);
30         nameP = new QLineEdit(nameS);
31         passP = new QLineEdit(passS);
32         passP->setEchoMode(QLineEdit::Password);
33         saveButt = new QPushButton(tr("Save changes"));
34         connect(saveButt, SIGNAL(clicked()), this, SLOT(save()));
35         mainLayout->addWidget(proxy);
36         mainLayout->addWidget(addr);
37         mainLayout->addWidget(addrP);
38         mainLayout->addWidget(port);
39         mainLayout->addWidget(portP);
40         mainLayout->addWidget(name);
41         mainLayout->addWidget(nameP);
42         mainLayout->addWidget(pass);
43         mainLayout->addWidget(passP);
44         mainLayout->addWidget(saveButt);
45         setLayout(mainLayout);
46         this->show();
47 }
48
49 /**
50  * \brief Proxy settings destructor.
51  */
52 ProxySet::~ProxySet() {
53         delete addrP;
54         delete portP;
55         delete nameP;
56         delete passP;
57         delete proxy;
58         delete addr;
59         delete port;
60         delete name;
61         delete pass;
62         delete saveButt;
63         delete mainLayout;
64 }
65
66 /**
67  * \brief Slot assigned to save button click.
68  */
69 void ProxySet::save() {
70         QSettings settings("config/global.ini", QSettings::IniFormat);
71         settings.setValue("Network/proxyUsed", useProxy);
72         settings.setValue("Network/proxyAddr", addrP->text());
73         settings.setValue("Network/proxyPort", portP->text());
74         settings.setValue("Network/proxyName", nameP->text());
75         settings.setValue("Network/proxyPass", passP->text());
76         settings.sync();
77 }
78
79 /**
80  * \brief Slot assigned to check box changes.
81  */
82 void ProxySet::checkChange(int state) {
83         useProxy = state;
84 }