~ubuntu-branches/ubuntu/saucy/plasma-nm/saucy-proposed

« back to all changes in this revision

Viewing changes to vpn/vpnc/vpncadvancedwidget.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-08-16 19:07:09 UTC
  • Revision ID: package-import@ubuntu.com-20130816190709-ef9ydm9skigmg15l
Tags: upstream-0.0~git20130816
ImportĀ upstreamĀ versionĀ 0.0~git20130816

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright 2013 Lukas Tinkl <ltinkl@redhat.com>
 
3
 
 
4
    This library is free software; you can redistribute it and/or
 
5
    modify it under the terms of the GNU Lesser General Public
 
6
    License as published by the Free Software Foundation; either
 
7
    version 2.1 of the License, or (at your option) version 3, or any
 
8
    later version accepted by the membership of KDE e.V. (or its
 
9
    successor approved by the membership of KDE e.V.), which shall
 
10
    act as a proxy defined in Section 6 of version 3 of the license.
 
11
 
 
12
    This library is distributed in the hope that it will be useful,
 
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
    Lesser General Public License for more details.
 
16
 
 
17
    You should have received a copy of the GNU Lesser General Public
 
18
    License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 
19
*/
 
20
 
 
21
#include "vpncadvancedwidget.h"
 
22
#include "ui_vpncadvanced.h"
 
23
#include "nm-vpnc-service.h"
 
24
 
 
25
#include <KLocalizedString>
 
26
#include <KAcceleratorManager>
 
27
 
 
28
VpncAdvancedWidget::VpncAdvancedWidget(const NetworkManager::VpnSetting::Ptr &setting, QWidget *parent) :
 
29
    QDialog(parent),
 
30
    m_ui(new Ui::VpncAdvancedWidget)
 
31
{
 
32
    m_ui->setupUi(this);
 
33
 
 
34
    setWindowTitle(i18n("Advanced VPNC properties"));
 
35
 
 
36
    // vendor
 
37
    m_ui->vendor->addItem(i18nc("VPNC vendor name", "Cisco"), NM_VPNC_VENDOR_CISCO);
 
38
    m_ui->vendor->addItem(i18nc("VPNC vendor name", "Netscreen"), NM_VPNC_VENDOR_NETSCREEN);
 
39
 
 
40
    // encryption
 
41
    m_ui->encryption->addItem(i18nc("VPNC encryption method", "Secure (default)"));
 
42
    m_ui->encryption->addItem(i18nc("VPNC encryption method", "Weak (use with caution)"), NM_VPNC_KEY_SINGLE_DES);
 
43
    m_ui->encryption->addItem(i18nc("VPNC encryption method", "None (completely insecure)"), NM_VPNC_KEY_NO_ENCRYPTION);
 
44
 
 
45
    // NAT traversal
 
46
    m_ui->nat->addItem(i18nc("NAT traversal method", "NAT-T when available (default)"), NM_VPNC_NATT_MODE_NATT);
 
47
    m_ui->nat->addItem(i18nc("NAT traversal method", "NAT-T always"), NM_VPNC_NATT_MODE_NATT_ALWAYS);
 
48
    m_ui->nat->addItem(i18nc("NAT traversal method", "Cisco UDP"), NM_VPNC_NATT_MODE_CISCO);
 
49
    m_ui->nat->addItem(i18nc("NAT traversal method", "Disabled"), NM_VPNC_NATT_MODE_NONE);
 
50
 
 
51
    // IKE DH group
 
52
    m_ui->dhGroup->addItem(i18nc("IKE DH group", "DH Group 1"), NM_VPNC_DHGROUP_DH1);
 
53
    m_ui->dhGroup->addItem(i18nc("IKE DH group", "DH Group 2 (default)"), NM_VPNC_DHGROUP_DH2);
 
54
    m_ui->dhGroup->addItem(i18nc("IKE DH group", "DH Group 5"), NM_VPNC_DHGROUP_DH5);
 
55
 
 
56
    // PFS
 
57
    m_ui->pfs->addItem(i18nc("Perfect Forward Secrecy", "Server (default)"), NM_VPNC_PFS_SERVER);
 
58
    m_ui->pfs->addItem(i18nc("Perfect Forward Secrecy", "None"), NM_VPNC_PFS_NOPFS);
 
59
    m_ui->pfs->addItem(i18nc("Perfect Forward Secrecy", "DH Group 1"), NM_VPNC_PFS_DH1);
 
60
    m_ui->pfs->addItem(i18nc("Perfect Forward Secrecy", "DH Group 2"), NM_VPNC_PFS_DH2);
 
61
    m_ui->pfs->addItem(i18nc("Perfect Forward Secrecy", "DH Group 5"), NM_VPNC_PFS_DH5);
 
62
 
 
63
    loadConfig(setting);
 
64
 
 
65
    KAcceleratorManager::manage(this);
 
66
}
 
67
 
 
68
VpncAdvancedWidget::~VpncAdvancedWidget()
 
69
{
 
70
    delete m_ui;
 
71
}
 
72
 
 
73
void VpncAdvancedWidget::loadConfig(const NetworkManager::VpnSetting::Ptr &setting)
 
74
{
 
75
    m_ui->domain->setText(setting->data().value(NM_VPNC_KEY_DOMAIN));
 
76
 
 
77
    const QString vendor = setting->data().value(NM_VPNC_KEY_VENDOR);
 
78
    if (!vendor.isEmpty())
 
79
        m_ui->vendor->setCurrentIndex(m_ui->vendor->findData(vendor));
 
80
 
 
81
    if (setting->data().value(NM_VPNC_KEY_SINGLE_DES) == "yes")
 
82
        m_ui->encryption->setCurrentIndex(m_ui->encryption->findData(NM_VPNC_KEY_SINGLE_DES));
 
83
    else if (setting->data().value(NM_VPNC_KEY_NO_ENCRYPTION) == "yes")
 
84
        m_ui->encryption->setCurrentIndex(m_ui->encryption->findData(NM_VPNC_KEY_NO_ENCRYPTION));
 
85
 
 
86
    const QString nat = setting->data().value(NM_VPNC_KEY_NAT_TRAVERSAL_MODE);
 
87
    if (!nat.isEmpty())
 
88
        m_ui->nat->setCurrentIndex(m_ui->nat->findData(nat));
 
89
 
 
90
    const QString dhGroup = setting->data().value(NM_VPNC_KEY_DHGROUP);
 
91
    if (!dhGroup.isEmpty())
 
92
        m_ui->dhGroup->setCurrentIndex(m_ui->dhGroup->findData(dhGroup));
 
93
    else
 
94
        m_ui->dhGroup->setCurrentIndex(m_ui->dhGroup->findData(NM_VPNC_DHGROUP_DH2));  // default
 
95
 
 
96
    const QString pfs = setting->data().value(NM_VPNC_KEY_PERFECT_FORWARD);
 
97
    if (!pfs.isEmpty())
 
98
        m_ui->pfs->setCurrentIndex(m_ui->pfs->findData(pfs));
 
99
 
 
100
    bool ok = false;
 
101
    const uint dpd = setting->data().value(NM_VPNC_KEY_DPD_IDLE_TIMEOUT).toUInt(&ok);
 
102
    m_ui->deadPeer->setChecked(ok && dpd == 0);
 
103
}
 
104
 
 
105
NMStringMap VpncAdvancedWidget::setting() const
 
106
{
 
107
    NMStringMap result;
 
108
    if (!m_ui->domain->text().isEmpty())
 
109
        result.insert(NM_VPNC_KEY_DOMAIN, m_ui->domain->text());
 
110
 
 
111
    result.insert(NM_VPNC_KEY_VENDOR, m_ui->vendor->itemData(m_ui->vendor->currentIndex()).toString());
 
112
 
 
113
    const QString encData = m_ui->encryption->itemData(m_ui->encryption->currentIndex()).toString();
 
114
    if (!encData.isEmpty()) {
 
115
        if (encData == NM_VPNC_KEY_SINGLE_DES)
 
116
            result.insert(NM_VPNC_KEY_SINGLE_DES, "yes");
 
117
        else if (encData == NM_VPNC_KEY_NO_ENCRYPTION)
 
118
            result.insert(NM_VPNC_KEY_NO_ENCRYPTION, "yes");
 
119
    }
 
120
 
 
121
    result.insert(NM_VPNC_KEY_NAT_TRAVERSAL_MODE, m_ui->nat->itemData(m_ui->nat->currentIndex()).toString());
 
122
 
 
123
    result.insert(NM_VPNC_KEY_DHGROUP, m_ui->dhGroup->itemData(m_ui->dhGroup->currentIndex()).toString());
 
124
 
 
125
    result.insert(NM_VPNC_KEY_PERFECT_FORWARD, m_ui->pfs->itemData(m_ui->pfs->currentIndex()).toString());
 
126
 
 
127
    if (m_ui->deadPeer->isChecked())
 
128
        result.insert(NM_VPNC_KEY_DPD_IDLE_TIMEOUT, "0");
 
129
 
 
130
    return result;
 
131
}