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

« back to all changes in this revision

Viewing changes to vpn/openswan/openswanauth.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 Jan Grulich <jgrulich@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 "openswanauth.h"
 
22
#include "ui_openswanauth.h"
 
23
#include "nm-openswan-service.h"
 
24
 
 
25
#include <QString>
 
26
 
 
27
class OpenswanAuthDialogPrivate
 
28
{
 
29
public:
 
30
    Ui_OpenswanAuth ui;
 
31
    NetworkManager::VpnSetting::Ptr setting;
 
32
};
 
33
 
 
34
OpenswanAuthDialog::OpenswanAuthDialog(const NetworkManager::VpnSetting::Ptr &setting, QWidget * parent)
 
35
    : SettingWidget(setting, parent), d_ptr(new OpenswanAuthDialogPrivate)
 
36
{
 
37
    Q_D(OpenswanAuthDialog);
 
38
    d->ui.setupUi(this);
 
39
    d->setting = setting;
 
40
    connect(d->ui.cbShowPasswords, SIGNAL(toggled(bool)), this, SLOT(showPasswordsChanged(bool)));
 
41
 
 
42
    readSecrets();
 
43
 
 
44
    KAcceleratorManager::manage(this);
 
45
}
 
46
 
 
47
OpenswanAuthDialog::~OpenswanAuthDialog()
 
48
{
 
49
    delete d_ptr;
 
50
}
 
51
 
 
52
void OpenswanAuthDialog::readSecrets()
 
53
{
 
54
    Q_D(OpenswanAuthDialog);
 
55
    const NMStringMap data = d->setting->data();
 
56
    const NMStringMap secrets = d->setting->secrets();
 
57
 
 
58
    const QString groupName = data.value(NM_OPENSWAN_LEFTID);
 
59
    if (!groupName.isEmpty()) {
 
60
        d->ui.leGroupName->setText(groupName);
 
61
    }
 
62
 
 
63
    bool haveUserPassword = true;
 
64
    if (data.value(NM_OPENSWAN_XAUTH_PASSWORD_INPUT_MODES) != NM_OPENSWAN_PW_TYPE_UNUSED) {
 
65
        d->ui.leUserPassword->setText(secrets.value(NM_OPENSWAN_XAUTH_PASSWORD));
 
66
    } else {
 
67
        d->ui.leUserPassword->setVisible(false);
 
68
        d->ui.userPasswordLabel->setVisible(false);
 
69
        haveUserPassword = false;
 
70
    }
 
71
 
 
72
    bool haveGroupPassword = true;
 
73
    if (data.value(NM_OPENSWAN_PSK_INPUT_MODES) != NM_OPENSWAN_PW_TYPE_UNUSED) {
 
74
        d->ui.leGroupPassword->setText(secrets.value(NM_OPENSWAN_PSK_VALUE));
 
75
    } else {
 
76
        d->ui.leGroupPassword->setVisible(false);
 
77
        d->ui.groupPasswordLabel->setVisible(false);
 
78
        haveGroupPassword = false;
 
79
    }
 
80
 
 
81
    if (haveUserPassword && d->ui.leUserPassword->text().isEmpty()) {
 
82
        d->ui.leUserPassword->setFocus(Qt::OtherFocusReason);
 
83
    } else if (haveGroupPassword && d->ui.leGroupPassword->text().isEmpty()) {
 
84
        d->ui.leGroupPassword->setFocus(Qt::OtherFocusReason);
 
85
    }
 
86
}
 
87
 
 
88
QVariantMap OpenswanAuthDialog::setting(bool agentOwned) const
 
89
{
 
90
    Q_D(const OpenswanAuthDialog);
 
91
    Q_UNUSED(agentOwned)
 
92
 
 
93
    NMStringMap secrets;
 
94
    QVariantMap result;
 
95
 
 
96
    if (!d->ui.leUserPassword->text().isEmpty()) {
 
97
        secrets.insert(NM_OPENSWAN_XAUTH_PASSWORD, d->ui.leUserPassword->text());
 
98
    }
 
99
 
 
100
    if (!d->ui.leGroupPassword->text().isEmpty()) {
 
101
        secrets.insert(NM_OPENSWAN_PSK_VALUE, d->ui.leGroupPassword->text());
 
102
    }
 
103
 
 
104
    result.insert("secrets", QVariant::fromValue<NMStringMap>(secrets));
 
105
 
 
106
    return result;
 
107
}
 
108
 
 
109
void OpenswanAuthDialog::showPasswordsChanged(bool show)
 
110
{
 
111
    Q_D(OpenswanAuthDialog);
 
112
    d->ui.leUserPassword->setPasswordMode(!show);
 
113
    d->ui.leGroupPassword->setPasswordMode(!show);
 
114
}