Update Finnish translation
[nomnom.git] / src / settings / nsettingsdialog_proxy.cpp
blob043a9b9a6ad9bbfd113c214dfd2b26bbbac3f143
1 /* NomNom
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/>.
18 #include "config.h"
20 #include <QButtonGroup>
21 #include <QRadioButton>
22 #include <QVBoxLayout>
23 #include <QLineEdit>
24 #include <QGroupBox>
25 #include <QSpinBox>
26 #include <QLabel>
28 #include <NSettingsMutator>
29 #include <NSettingsDialog>
31 extern nn::NSettingsMutator settings; // main.cpp
33 namespace nn
36 NSettingsProxy::NSettingsProxy(QWidget *parent/*=NULL*/)
37 : NSettingsWidget(parent)
40 // Widgets
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"));
48 // Button group
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)));
57 // Address
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);
78 // Layout
80 QVBoxLayout *box = new QVBoxLayout;
81 box->addWidget(autodetect);
82 box->addWidget(no_proxy);
83 box->addWidget(manual);
84 box->addWidget(addressGroup);
85 box->addStretch(0);
86 setLayout(box);
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);
129 } // namespace nn
131 /* vim: set ts=2 sw=2 tw=72 expandtab: */