2 * Copyright (C) 2011 Toni Gundogdu <legatvs@gmail.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <QButtonGroup>
21 #include <QRadioButton>
22 #include <QVBoxLayout>
28 #include <NSettingsMutator>
29 #include <NSettingsDialog>
31 extern nn::NSettingsMutator settings
; // main.cpp
36 NSettingsProxy::NSettingsProxy(QWidget
*parent
/*=NULL*/)
37 : NSettingsWidget(parent
)
42 QRadioButton
*autodetect
= new QRadioButton(
43 tr("&Autodetect (environment, e.g. http_proxy)"));
45 QRadioButton
*no_proxy
= new QRadioButton(tr("&No proxy"));
46 QRadioButton
*manual
= new QRadioButton(tr("Man&ual"));
50 bgroup
= new QButtonGroup
;
51 bgroup
->addButton(autodetect
, AutodetectProxy
);
52 bgroup
->addButton(no_proxy
, NoProxy
);
53 bgroup
->addButton(manual
, ManualProxy
);
55 connect(bgroup
, SIGNAL(buttonClicked(int)), this, SLOT(typeChanged(int)));
59 QLabel
*l
= new QLabel(tr("&Host:"));
60 addressEdit
= new QLineEdit
;
61 l
->setBuddy(addressEdit
);
63 QGridLayout
*addrGrid
= new QGridLayout
;
64 addrGrid
->addWidget(l
, 0, 0);
65 addrGrid
->addWidget(addressEdit
, 0, 1);
67 l
= new QLabel(tr("Po&rt:"));
68 portSpin
= new QSpinBox
;
69 portSpin
->setMaximum(99999);
70 l
->setBuddy(portSpin
);
72 addrGrid
->addWidget(l
, 1, 0);
73 addrGrid
->addWidget(portSpin
, 1, 1);
75 addressGroup
= new QGroupBox(tr("Proxy address"));
76 addressGroup
->setLayout(addrGrid
);
80 QVBoxLayout
*box
= new QVBoxLayout
;
81 box
->addWidget(autodetect
);
82 box
->addWidget(no_proxy
);
83 box
->addWidget(manual
);
84 box
->addWidget(addressGroup
);
89 void NSettingsProxy::init()
91 typeChanged(bgroup
->checkedId());
94 bool NSettingsProxy::verify(QString
& msg
)
96 if (bgroup
->checkedId() == ManualProxy
)
98 if (addressEdit
->text().isEmpty())
99 msg
= tr("Please fill the required field");
101 return msg
.isEmpty();
104 void NSettingsProxy::write()
106 settings
.setValue(ProxyType
, bgroup
->checkedId());
107 settings
.setValue(ProxyHost
, addressEdit
->text());
108 settings
.setValue(ProxyPort
, portSpin
->value());
111 void NSettingsProxy::read()
113 const int n
= settings
.value(ProxyType
).toInt();
114 dynamic_cast<QRadioButton
*>(bgroup
->button(n
))->setChecked(true);
115 addressEdit
->setText(settings
.value(ProxyHost
).toString());
116 portSpin
->setValue(settings
.value(ProxyPort
).toInt());
119 void NSettingsProxy::enableAddress(bool state
/*=true*/)
121 addressGroup
->setEnabled(state
);
124 void NSettingsProxy::typeChanged(int n
)
126 enableAddress(n
== ManualProxy
);
131 /* vim: set ts=2 sw=2 tw=72 expandtab: */