~ubuntu-branches/ubuntu/saucy/clementine/saucy

« back to all changes in this revision

Viewing changes to src/ui/networkproxysettingspage.cpp

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of Clementine.
 
2
   Copyright 2010, David Sansome <me@davidsansome.com>
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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/>.
 
16
*/
 
17
 
 
18
#include "iconloader.h"
 
19
#include "networkproxysettingspage.h"
 
20
#include "ui_networkproxysettingspage.h"
 
21
#include "core/networkproxyfactory.h"
 
22
 
 
23
#include <QSettings>
 
24
 
 
25
 
 
26
NetworkProxySettingsPage::NetworkProxySettingsPage(SettingsDialog* dialog)
 
27
  : SettingsPage(dialog),
 
28
    ui_(new Ui_NetworkProxySettingsPage)
 
29
{
 
30
  ui_->setupUi(this);
 
31
  setWindowIcon(IconLoader::Load("applications-internet"));
 
32
}
 
33
 
 
34
NetworkProxySettingsPage::~NetworkProxySettingsPage() {
 
35
  delete ui_;
 
36
}
 
37
 
 
38
void NetworkProxySettingsPage::Load() {
 
39
  QSettings s;
 
40
 
 
41
  s.beginGroup(NetworkProxyFactory::kSettingsGroup);
 
42
  NetworkProxyFactory::Mode mode = NetworkProxyFactory::Mode(
 
43
      s.value("mode", NetworkProxyFactory::Mode_System).toInt());
 
44
  switch (mode) {
 
45
  case NetworkProxyFactory::Mode_Manual:
 
46
    ui_->proxy_manual->setChecked(true);
 
47
    break;
 
48
 
 
49
  case NetworkProxyFactory::Mode_Direct:
 
50
    ui_->proxy_direct->setChecked(true);
 
51
    break;
 
52
 
 
53
  case NetworkProxyFactory::Mode_System:
 
54
  default:
 
55
    ui_->proxy_system->setChecked(true);
 
56
    break;
 
57
  }
 
58
 
 
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());
 
66
  s.endGroup();
 
67
}
 
68
 
 
69
void NetworkProxySettingsPage::Save() {
 
70
  QSettings s;
 
71
 
 
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;
 
76
 
 
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());
 
86
  s.endGroup();
 
87
 
 
88
  NetworkProxyFactory::Instance()->ReloadSettings();
 
89
}