1
/* This file is part of Clementine.
2
Copyright 2010, David Sansome <me@davidsansome.com>
4
Clementine 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
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
18
#include "iconloader.h"
19
#include "networkproxysettingspage.h"
20
#include "ui_networkproxysettingspage.h"
21
#include "core/networkproxyfactory.h"
26
NetworkProxySettingsPage::NetworkProxySettingsPage(SettingsDialog* dialog)
27
: SettingsPage(dialog),
28
ui_(new Ui_NetworkProxySettingsPage)
31
setWindowIcon(IconLoader::Load("applications-internet"));
34
NetworkProxySettingsPage::~NetworkProxySettingsPage() {
38
void NetworkProxySettingsPage::Load() {
41
s.beginGroup(NetworkProxyFactory::kSettingsGroup);
42
NetworkProxyFactory::Mode mode = NetworkProxyFactory::Mode(
43
s.value("mode", NetworkProxyFactory::Mode_System).toInt());
45
case NetworkProxyFactory::Mode_Manual:
46
ui_->proxy_manual->setChecked(true);
49
case NetworkProxyFactory::Mode_Direct:
50
ui_->proxy_direct->setChecked(true);
53
case NetworkProxyFactory::Mode_System:
55
ui_->proxy_system->setChecked(true);
59
ui_->proxy_type->setCurrentIndex(s.value("type", QNetworkProxy::HttpProxy)
60
.toInt() == QNetworkProxy::HttpProxy ? 0 : 1);
61
ui_->proxy_hostname->setText(s.value("hostname").toString());
62
ui_->proxy_port->setValue(s.value("port").toInt());
63
ui_->proxy_auth->setChecked(s.value("use_authentication", false).toBool());
64
ui_->proxy_username->setText(s.value("username").toString());
65
ui_->proxy_password->setText(s.value("password").toString());
69
void NetworkProxySettingsPage::Save() {
72
NetworkProxyFactory::Mode mode = NetworkProxyFactory::Mode_System;
73
if (ui_->proxy_direct->isChecked()) mode = NetworkProxyFactory::Mode_Direct;
74
else if (ui_->proxy_system->isChecked()) mode = NetworkProxyFactory::Mode_System;
75
else if (ui_->proxy_manual->isChecked()) mode = NetworkProxyFactory::Mode_Manual;
77
s.beginGroup(NetworkProxyFactory::kSettingsGroup);
78
s.setValue("mode", mode);
79
s.setValue("type", ui_->proxy_type->currentIndex() == 0 ?
80
QNetworkProxy::HttpProxy : QNetworkProxy::Socks5Proxy);
81
s.setValue("hostname", ui_->proxy_hostname->text());
82
s.setValue("port", ui_->proxy_port->value());
83
s.setValue("use_authentication", ui_->proxy_auth->isChecked());
84
s.setValue("username", ui_->proxy_username->text());
85
s.setValue("password", ui_->proxy_password->text());
88
NetworkProxyFactory::Instance()->ReloadSettings();