[PATCH 5/5] vpnc auth ui
Andrey Borzenkov
arvidjaar at gmail.com
Fri Nov 26 18:19:45 CET 2010
From: Andrey Borzenkov <arvidjaar at mail.ru>
Signed-off-by: Andrey Borzenkov <arvidjaar at mail.ru>
---
libs/ui/vpnuiplugin.h | 2 +-
vpnplugins/vpnc/CMakeLists.txt | 3 +-
vpnplugins/vpnc/vpnc.cpp | 6 ++
vpnplugins/vpnc/vpnc.h | 1 +
vpnplugins/vpnc/vpncauth.cpp | 106 +++++++++++++++++++++++
vpnplugins/vpnc/vpncauth.h | 53 ++++++++++++
vpnplugins/vpnc/vpncauth.ui | 183 +++++++++++++++++++--------------------
vpnplugins/vpnc/vpncwidget.h | 1 +
8 files changed, 259 insertions(+), 96 deletions(-)
create mode 100644 vpnplugins/vpnc/vpncauth.cpp
create mode 100644 vpnplugins/vpnc/vpncauth.h
diff --git a/libs/ui/vpnuiplugin.h b/libs/ui/vpnuiplugin.h
index b149c45..7a13027 100644
--- a/libs/ui/vpnuiplugin.h
+++ b/libs/ui/vpnuiplugin.h
@@ -45,7 +45,7 @@ public:
virtual ~VpnUiPlugin();
virtual SettingWidget * widget(Knm::Connection * connection, QWidget * parent = 0) = 0;
- SettingWidget * askUser(Knm::Connection * connection, QWidget * parent = 0){ return widget(connection, parent); };
+ virtual SettingWidget * askUser(Knm::Connection * connection, QWidget * parent = 0){ return widget(connection, parent); };
private:
class Private;
Private * d;
diff --git a/vpnplugins/vpnc/CMakeLists.txt b/vpnplugins/vpnc/CMakeLists.txt
index 5e47c38..5af39b9 100644
--- a/vpnplugins/vpnc/CMakeLists.txt
+++ b/vpnplugins/vpnc/CMakeLists.txt
@@ -4,10 +4,11 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libs/internals)
set(vpnc_SRCS
vpnc.cpp
+ vpncauth.cpp
vpncwidget.cpp
)
-kde4_add_ui_files(vpnc_SRCS vpncprop.ui)
+kde4_add_ui_files(vpnc_SRCS vpncprop.ui vpncauth.ui)
kde4_add_plugin(networkmanagement_vpncui ${vpnc_SRCS})
diff --git a/vpnplugins/vpnc/vpnc.cpp b/vpnplugins/vpnc/vpnc.cpp
index b5f1890..deb9108 100644
--- a/vpnplugins/vpnc/vpnc.cpp
+++ b/vpnplugins/vpnc/vpnc.cpp
@@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KPluginFactory>
#include "vpncwidget.h"
+#include "vpncauth.h"
#include "connection.h"
K_PLUGIN_FACTORY( VpncUiPluginFactory, registerPlugin<VpncUiPlugin>(); )
@@ -43,4 +44,9 @@ SettingWidget * VpncUiPlugin::widget(Knm::Connection * connection, QWidget * par
return new VpncSettingWidget(connection, parent);
}
+SettingWidget * VpncUiPlugin::askUser(Knm::Connection * connection, QWidget * parent)
+{
+ return new VpncAuthWidget(connection, parent);
+}
+
// vim: sw=4 sts=4 et tw=100
diff --git a/vpnplugins/vpnc/vpnc.h b/vpnplugins/vpnc/vpnc.h
index bb0683b..aec2136 100644
--- a/vpnplugins/vpnc/vpnc.h
+++ b/vpnplugins/vpnc/vpnc.h
@@ -37,6 +37,7 @@ public:
VpncUiPlugin(QObject * parent = 0, const QVariantList& = QVariantList());
virtual ~VpncUiPlugin();
SettingWidget * widget(Knm::Connection *, QWidget * parent = 0);
+ SettingWidget * askUser(Knm::Connection *, QWidget * parent = 0);
};
#endif // KNM4_VPNC_H
diff --git a/vpnplugins/vpnc/vpncauth.cpp b/vpnplugins/vpnc/vpncauth.cpp
new file mode 100644
index 0000000..eeeb00d
--- /dev/null
+++ b/vpnplugins/vpnc/vpncauth.cpp
@@ -0,0 +1,106 @@
+/*
+Copyright 2010 Andrey Borzenkov <arvidjaar at gmail.com>
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation; either version 2 of
+the License or (at your option) version 3 or any later version
+accepted by the membership of KDE e.V. (or its successor approved
+by the membership of KDE e.V.), which shall act as a proxy
+defined in Section 14 of version 3 of the license.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "vpncauth.h"
+
+#include <nm-setting-vpn.h>
+
+#include <QString>
+#include "nm-vpnc-service.h"
+
+#include "connection.h"
+
+class VpncAuthWidgetPrivate
+{
+public:
+ Ui_VpncAuth ui;
+ Knm::VpnSetting * setting;
+};
+
+VpncAuthWidget::VpncAuthWidget(Knm::Connection * connection, QWidget * parent)
+: SettingWidget(connection, parent), d_ptr(new VpncAuthWidgetPrivate)
+{
+ Q_D(VpncAuthWidget);
+ d->ui.setupUi(this);
+ d->setting = static_cast<Knm::VpnSetting *>(connection->setting(Knm::Setting::Vpn));
+}
+
+VpncAuthWidget::~VpncAuthWidget()
+{
+
+}
+
+#if 0
+void VpncAuthWidget::readConfig()
+{
+ Q_D(VpncAuthWidget);
+}
+#endif
+
+void VpncAuthWidget::readSecrets()
+{
+ Q_D(VpncAuthWidget);
+ QVariantMap secrets = d->setting->vpnSecrets();
+ QStringMap secretsType = d->setting->secretsStorageType();
+ QString userType;
+ QString groupType;
+
+ /*
+ * First time "old" settings are loaded secretsType map is empty, so
+ * try to read from data as fallback
+ */
+ userType = secretsType.value(NM_VPNC_KEY_XAUTH_PASSWORD_TYPE);
+ if (userType.isNull()) {
+ userType = d->setting->data().value(NM_VPNC_KEY_XAUTH_PASSWORD_TYPE);
+ }
+ if (userType == QLatin1String(NM_VPN_PW_TYPE_SAVE)) {
+ d->ui.leUserPassword->setText(secrets.value(QLatin1String(NM_VPNC_KEY_XAUTH_PASSWORD)).toString());
+ d->ui.leUserPassword->setEnabled(false);
+ }
+
+ groupType = secretsType.value(NM_VPNC_KEY_SECRET_TYPE);
+ if (userType.isNull()) {
+ groupType = d->setting->data().value(NM_VPNC_KEY_SECRET_TYPE);
+ }
+ if (groupType == QLatin1String(NM_VPN_PW_TYPE_SAVE)) {
+ d->ui.leGroupPassword->setText(secrets.value(QLatin1String(NM_VPNC_KEY_SECRET)).toString());
+ d->ui.leGroupPassword->setEnabled(false);
+ }
+}
+
+void VpncAuthWidget::writeConfig()
+{
+ Q_D(VpncAuthWidget);
+
+ QVariantMap secretData;
+
+ // user password
+ if (!d->ui.leUserPassword->text().isEmpty()) {
+ secretData.insert(NM_VPNC_KEY_XAUTH_PASSWORD, d->ui.leUserPassword->text());
+ }
+ // group password
+ if (!d->ui.leGroupPassword->text().isEmpty()) {
+ secretData.insert(NM_VPNC_KEY_SECRET, d->ui.leGroupPassword->text());
+ }
+
+ d->setting->setVpnSecrets(secretData);
+}
+
+// vim: sw=4 sts=4 et tw=100
diff --git a/vpnplugins/vpnc/vpncauth.h b/vpnplugins/vpnc/vpncauth.h
new file mode 100644
index 0000000..389b9c3
--- /dev/null
+++ b/vpnplugins/vpnc/vpncauth.h
@@ -0,0 +1,53 @@
+/*
+Copyright 2008 Will Stephenson <wstephenson at kde.org>
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation; either version 2 of
+the License or (at your option) version 3 or any later version
+accepted by the membership of KDE e.V. (or its successor approved
+by the membership of KDE e.V.), which shall act as a proxy
+defined in Section 14 of version 3 of the license.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef VPNCAUTH_H
+#define VPNCAUTH_H
+
+#include "settingwidget.h"
+
+#include "ui_vpncauth.h"
+#include "settings/vpn.h"
+
+namespace Knm
+{
+ class Connection;
+} // namespace Knm
+
+class VpncAuthWidgetPrivate;
+
+class VpncAuthWidget : public SettingWidget
+{
+Q_OBJECT
+Q_DECLARE_PRIVATE(VpncAuthWidget)
+public:
+ VpncAuthWidget(Knm::Connection *, QWidget * parent = 0);
+ ~VpncAuthWidget();
+ void readConfig() {};
+ void readSecrets();
+ void writeConfig();
+protected Q_SLOTS:
+ void validate() {};
+
+private:
+ VpncAuthWidgetPrivate * d_ptr;
+};
+
+#endif // VPNCAUTH_H
diff --git a/vpnplugins/vpnc/vpncauth.ui b/vpnplugins/vpnc/vpncauth.ui
index 2e89b20..bee07cb 100644
--- a/vpnplugins/vpnc/vpncauth.ui
+++ b/vpnplugins/vpnc/vpncauth.ui
@@ -1,94 +1,89 @@
-<!DOCTYPE UI><UI version="3.2" stdsetdef="1">
-<class>VPNCAuthenticationWidget</class>
-<widget class="QWidget">
- <property name="name">
- <cstring>VPNCAuthenticationWidget</cstring>
- </property>
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>372</width>
- <height>171</height>
- </rect>
- </property>
- <property name="caption">
- <string>VPNCAuthentication</string>
- </property>
- <grid>
- <property name="name">
- <cstring>unnamed</cstring>
- </property>
- <property name="margin">
- <number>0</number>
- </property>
- <widget class="QLabel" row="0" column="0">
- <property name="name">
- <cstring>textLabel1</cstring>
- </property>
- <property name="text">
- <string>Password</string>
- </property>
- </widget>
- <widget class="QLabel" row="1" column="0">
- <property name="name">
- <cstring>textLabel2</cstring>
- </property>
- <property name="text">
- <string>Group Password</string>
- </property>
- </widget>
- <spacer row="0" column="2">
- <property name="name">
- <cstring>spacer2</cstring>
- </property>
- <property name="orientation">
- <enum>Horizontal</enum>
- </property>
- <property name="sizeType">
- <enum>Expanding</enum>
- </property>
- <property name="sizeHint">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- <spacer row="2" column="1">
- <property name="name">
- <cstring>spacer1</cstring>
- </property>
- <property name="orientation">
- <enum>Vertical</enum>
- </property>
- <property name="sizeType">
- <enum>Expanding</enum>
- </property>
- <property name="sizeHint">
- <size>
- <width>20</width>
- <height>40</height>
- </size>
- </property>
- </spacer>
- <widget class="KPasswordEdit" row="0" column="1">
- <property name="name">
- <cstring>editUserPassword</cstring>
- </property>
- </widget>
- <widget class="KPasswordEdit" row="1" column="1">
- <property name="name">
- <cstring>editGroupPassword</cstring>
- </property>
- </widget>
- </grid>
-</widget>
-<customwidgets>
-</customwidgets>
-<layoutdefaults spacing="6" margin="11"/>
-<includehints>
-
-
-</includehints>
-</UI>
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>VpncAuth</class>
+ <widget class="QWidget" name="VpncAuth">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>372</width>
+ <height>171</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>VPNCAuthentication</string>
+ </property>
+ <layout class="QGridLayout">
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item row="0" column="0">
+ <widget class="QLabel" name="textLabel1">
+ <property name="text">
+ <string>User Password</string>
+ </property>
+ <property name="wordWrap">
+ <bool>false</bool>
+ </property>
+ <property name="buddy">
+ <cstring>leUserPassword</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="textLabel2">
+ <property name="text">
+ <string>Group Password</string>
+ </property>
+ <property name="wordWrap">
+ <bool>false</bool>
+ </property>
+ <property name="buddy">
+ <cstring>leGroupPassword</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2">
+ <widget class="KLineEdit" name="leUserPassword">
+ <property name="passwordMode">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <spacer name="spacer1">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Expanding</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="1" column="2">
+ <widget class="KLineEdit" name="leGroupPassword">
+ <property name="passwordMode">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
+ <customwidgets>
+ <customwidget>
+ <class>KLineEdit</class>
+ <extends>QLineEdit</extends>
+ <header>klineedit.h</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/vpnplugins/vpnc/vpncwidget.h b/vpnplugins/vpnc/vpncwidget.h
index 6a8a17b..568ccf5 100644
--- a/vpnplugins/vpnc/vpncwidget.h
+++ b/vpnplugins/vpnc/vpncwidget.h
@@ -24,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "settingwidget.h"
#include "ui_vpncprop.h"
+#include "ui_vpncauth.h"
#include "settings/vpn.h"
namespace Knm
--
1.7.3.2
More information about the kde-networkmanager
mailing list