2
Copyright 2013 Lukas Tinkl <ltinkl@redhat.com>
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.
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.
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/>.
21
#include "vpncwidget.h"
22
#include "vpncadvancedwidget.h"
24
#include "nm-vpnc-service.h"
26
#include <QDBusMetaType>
29
VpncWidget::VpncWidget(const NetworkManager::VpnSetting::Ptr &setting, QWidget* parent, Qt::WindowFlags f):
30
SettingWidget(setting, parent, f),
31
m_ui(new Ui::VpncWidget),
34
qDBusRegisterMetaType<NMStringMap>();
38
connect(m_ui->cboUserPasswordType, SIGNAL(currentIndexChanged(int)), SLOT(userPasswordTypeChanged(int)));
39
connect(m_ui->cboGroupPasswordType, SIGNAL(currentIndexChanged(int)), SLOT(groupPasswordTypeChanged(int)));
40
connect(m_ui->cbShowPasswords, SIGNAL(toggled(bool)), SLOT(showPasswords(bool)));
41
connect(m_ui->btnAdvanced, SIGNAL(clicked()), SLOT(showAdvanced()));
43
connect(m_ui->gateway, SIGNAL(textChanged(QString)), SLOT(slotWidgetChanged()));
45
KAcceleratorManager::manage(this);
51
VpncWidget::~VpncWidget()
57
void VpncWidget::loadConfig(const NetworkManager::Setting::Ptr &setting)
61
const NMStringMap data = m_setting->data();
62
const NMStringMap secrets = m_setting->secrets();
64
const QString gateway = data.value(NM_VPNC_KEY_GATEWAY);
65
if (!gateway.isEmpty())
66
m_ui->gateway->setText(gateway);
68
const QString user = data.value(NM_VPNC_KEY_XAUTH_USER);
70
m_ui->user->setText(user);
72
const QString userPassword = secrets.value(NM_VPNC_KEY_XAUTH_PASSWORD);
73
if (!userPassword.isEmpty())
74
m_ui->userPassword->setText(userPassword);
76
const NetworkManager::Setting::SecretFlags userPassType =
77
static_cast<NetworkManager::Setting::SecretFlags>(data.value(NM_VPNC_KEY_XAUTH_PASSWORD"-flags").toInt());
78
if (userPassType.testFlag(NetworkManager::Setting::NotSaved))
79
m_ui->cboUserPasswordType->setCurrentIndex(SettingWidget::EnumPasswordStorageType::AlwaysAsk);
80
else if (userPassType.testFlag(NetworkManager::Setting::NotRequired))
81
m_ui->cboUserPasswordType->setCurrentIndex(SettingWidget::EnumPasswordStorageType::NotRequired);
83
m_ui->cboUserPasswordType->setCurrentIndex(SettingWidget::EnumPasswordStorageType::Store);
85
const QString groupName = data.value(NM_VPNC_KEY_ID);
86
if (!groupName.isEmpty())
87
m_ui->group->setText(groupName);
89
const QString groupPassword = secrets.value(NM_VPNC_KEY_SECRET);
90
if (!groupPassword.isEmpty())
91
m_ui->groupPassword->setText(groupPassword);
93
const NetworkManager::Setting::SecretFlags groupPassType =
94
static_cast<NetworkManager::Setting::SecretFlags>(data.value(NM_VPNC_KEY_SECRET"-flags").toInt());
95
if (groupPassType.testFlag(NetworkManager::Setting::NotSaved))
96
m_ui->cboGroupPasswordType->setCurrentIndex(SettingWidget::EnumPasswordStorageType::AlwaysAsk);
97
else if (groupPassType.testFlag(NetworkManager::Setting::NotRequired))
98
m_ui->cboGroupPasswordType->setCurrentIndex(SettingWidget::EnumPasswordStorageType::NotRequired);
100
m_ui->cboGroupPasswordType->setCurrentIndex(SettingWidget::EnumPasswordStorageType::Store);
102
if (data.value(NM_VPNC_KEY_AUTHMODE) == QLatin1String("hybrid")) {
103
m_ui->useHybridAuth->setChecked(true);
104
m_ui->caFile->setUrl(KUrl(data.value(NM_VPNC_KEY_CA_FILE)));
108
QVariantMap VpncWidget::setting(bool agentOwned) const
110
NetworkManager::VpnSetting setting;
111
setting.setServiceType(QLatin1String(NM_DBUS_SERVICE_VPNC));
113
if (!m_tmpSetting.isNull()) {
114
data = m_tmpSetting->data();
118
if (!m_ui->gateway->text().isEmpty())
119
data.insert(NM_VPNC_KEY_GATEWAY, m_ui->gateway->text());
121
if (!m_ui->user->text().isEmpty())
122
data.insert(NM_VPNC_KEY_XAUTH_USER, m_ui->user->text());
124
if (m_ui->userPassword->isEnabled() && !m_ui->userPassword->text().isEmpty())
125
secrets.insert(NM_VPNC_KEY_XAUTH_PASSWORD, m_ui->userPassword->text());
127
const int userPasswordTypeIndex = m_ui->cboUserPasswordType->currentIndex();
128
if (userPasswordTypeIndex == SettingWidget::EnumPasswordStorageType::AlwaysAsk) {
129
data.insert(NM_VPNC_KEY_XAUTH_PASSWORD"-flags", QString::number(NetworkManager::Setting::NotSaved));
130
} else if (userPasswordTypeIndex == SettingWidget::EnumPasswordStorageType::NotRequired) {
131
data.insert(NM_VPNC_KEY_XAUTH_PASSWORD"-flags", QString::number(NetworkManager::Setting::NotRequired));
134
data.insert(NM_VPNC_KEY_XAUTH_PASSWORD"-flags", QString::number(NetworkManager::Setting::AgentOwned));
136
data.insert(NM_VPNC_KEY_XAUTH_PASSWORD"-flags", QString::number(NetworkManager::Setting::None));
140
if (!m_ui->group->text().isEmpty())
141
data.insert(NM_VPNC_KEY_ID, m_ui->group->text());
143
if (m_ui->groupPassword->isEnabled() && !m_ui->groupPassword->text().isEmpty())
144
secrets.insert(NM_VPNC_KEY_SECRET, m_ui->groupPassword->text());
146
const int groupPasswordTypeIndex = m_ui->cboGroupPasswordType->currentIndex();
147
if (groupPasswordTypeIndex == SettingWidget::EnumPasswordStorageType::AlwaysAsk) {
148
data.insert(NM_VPNC_KEY_SECRET"-flags", QString::number(NetworkManager::Setting::NotSaved));
149
} else if (groupPasswordTypeIndex == SettingWidget::EnumPasswordStorageType::NotRequired) {
150
data.insert(NM_VPNC_KEY_SECRET"-flags", QString::number(NetworkManager::Setting::NotRequired));
153
data.insert(NM_VPNC_KEY_SECRET"-flags", QString::number(NetworkManager::Setting::AgentOwned));
155
data.insert(NM_VPNC_KEY_SECRET"-flags", QString::number(NetworkManager::Setting::None));
159
if (m_ui->useHybridAuth->isChecked() && !m_ui->caFile->url().isEmpty()) {
160
data.insert(NM_VPNC_KEY_AUTHMODE, "hybrid");
161
data.insert(NM_VPNC_KEY_CA_FILE, m_ui->caFile->url().url());
164
setting.setData(data);
165
setting.setSecrets(secrets);
166
return setting.toMap();
169
void VpncWidget::userPasswordTypeChanged(int index)
171
m_ui->userPassword->setEnabled(index == SettingWidget::EnumPasswordStorageType::Store);
174
void VpncWidget::groupPasswordTypeChanged(int index)
176
m_ui->groupPassword->setEnabled(index == SettingWidget::EnumPasswordStorageType::Store);
179
void VpncWidget::showPasswords(bool show)
181
m_ui->userPassword->setPasswordMode(!show);
182
m_ui->groupPassword->setPasswordMode(!show);
185
void VpncWidget::showAdvanced()
187
QPointer<VpncAdvancedWidget> adv;
188
if (m_tmpSetting.isNull()) {
189
adv = new VpncAdvancedWidget(m_setting, this);
191
adv = new VpncAdvancedWidget(m_tmpSetting, this);
193
if (adv->exec() == QDialog::Accepted) {
194
NMStringMap advData = adv->setting();
195
if (!advData.isEmpty()) {
196
if (m_tmpSetting.isNull()) {
197
m_tmpSetting = NetworkManager::VpnSetting::Ptr(new NetworkManager::VpnSetting);
199
m_tmpSetting->setData(advData);
208
bool VpncWidget::isValid() const
210
return !m_ui->gateway->text().isEmpty();