From 0fa003ad691b60fbcca85726f1f3651a89347044 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Mon, 10 Sep 2012 15:41:05 -0500 Subject: [PATCH] Fix VPN settings dialog --- .../src/configwidgets/CMakeLists.txt | 4 +- ...denetman-connection_setting_vpn_widget.cpp | 24 ++--- .../tdenetman-connection_setting_vpn_widget.h | 6 +- .../tdenetman-connection_settings_dialog.cpp | 11 +-- .../src/tdenetman-vpnmanager.cpp | 89 ++++++++++++------- 5 files changed, 78 insertions(+), 56 deletions(-) diff --git a/tdenetworkmanager/src/configwidgets/CMakeLists.txt b/tdenetworkmanager/src/configwidgets/CMakeLists.txt index 6233f98..8c9c32e 100644 --- a/tdenetworkmanager/src/configwidgets/CMakeLists.txt +++ b/tdenetworkmanager/src/configwidgets/CMakeLists.txt @@ -44,7 +44,7 @@ set( ${target}_SRCS connection_setting_wireless_security_wepencryption.ui connection_settings.ui connection_setting_wireless_security_auth.ui -# connection_setting_vpn.ui + connection_setting_vpn.ui tdenetman-connection_setting_cdma_widget.cpp tdenetman-connection_setting_gsm_widget.cpp tdenetman-connection_setting_info_widget.cpp @@ -53,7 +53,7 @@ set( ${target}_SRCS tdenetman-connection_setting_serial_widget.cpp tdenetman-connection_setting_wireless_security_widget.cpp tdenetman-connection_setting_wireless_widget.cpp -# tdenetman-connection_setting_vpn_widget.cpp + tdenetman-connection_setting_vpn_widget.cpp tdenetman-connection_setting_widget_interface.cpp tdenetman-connection_settings_dialog.cpp ) diff --git a/tdenetworkmanager/src/configwidgets/tdenetman-connection_setting_vpn_widget.cpp b/tdenetworkmanager/src/configwidgets/tdenetman-connection_setting_vpn_widget.cpp index 06509ec..c4f488b 100644 --- a/tdenetworkmanager/src/configwidgets/tdenetman-connection_setting_vpn_widget.cpp +++ b/tdenetworkmanager/src/configwidgets/tdenetman-connection_setting_vpn_widget.cpp @@ -35,20 +35,17 @@ #include // tdenm headers -#include "tdenetman-connection.h" -#include "tdenetman-connection_setting_vpn.h" #include "tdenetman-connection_setting_vpn_widget.h" -#include "tdenetman-device.h" #include "tdenetman-vpnmanager.h" #include "tdenetman-vpnservice.h" using namespace ConnectionSettings; -VPNWidgetImpl::VPNWidgetImpl(Connection* conn, bool new_conn, TQWidget* parent, const char* name, WFlags fl) +VPNWidgetImpl::VPNWidgetImpl(TDENetworkConnection* conn, bool new_conn, TQWidget* parent, const char* name, WFlags fl) : WidgetInterface(parent, name, fl) , _new_conn(new_conn) { - _vpnsetting = dynamic_cast (conn->getSetting(NM_SETTING_VPN_SETTING_NAME)); + _vpnsetting = dynamic_cast(conn); TQVBoxLayout* layout = new TQVBoxLayout(this, 1, 1); _mainWid = new ConnectionSettingVPNWidget(this); @@ -96,9 +93,10 @@ VPNWidgetImpl::Init() disp_name = "StrongSwan VPN"; } - // the service should not get changed when editing a connection - if (service->getService() != _vpnsetting->getServiceType() && !_new_conn) + // the service should not be changed when editing a connection + if (service->getService() != _vpnsetting->vpnPluginID && !_new_conn) { continue; + } // no special icon for this service, use default if (icon.isEmpty()) @@ -107,7 +105,7 @@ VPNWidgetImpl::Init() _mainWid->cboServices->insertItem(SmallIcon(icon, TQIconSet::Automatic), disp_name, index); _mapServiceCombo.insert(index++, *it); - if (service->getService() == _vpnsetting->getServiceType()) + if (service->getService() == _vpnsetting->vpnPluginID) { // preselect the correct service _mainWid->cboServices->setCurrentItem(index - 1); @@ -128,7 +126,7 @@ VPNWidgetImpl::Init() // update the username to the current one KUser user; - _vpnsetting->setUserName(user.loginName()); + _vpnsetting->lockedUserName = user.loginName(); // notification if VPN service is selected connect(_mainWid->cboServices, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotServiceComboActivated(int))); @@ -169,7 +167,7 @@ VPNWidgetImpl::slotServiceComboActivated(int index) VPNConfigWidget* config = getVPNConfigWidget(service); _mainWid->widgetStack->raiseWidget(config); - config->setVPNData(_vpnsetting->getRoutes(), _vpnsetting->getData()); + config->setVPNData(_vpnsetting->ipConfig.routeConfigurations, _vpnsetting->pluginData, _vpnsetting->pluginSecrets); } } else @@ -186,13 +184,15 @@ VPNWidgetImpl::Deactivate() if (service) { // set the correct service type - _vpnsetting->setServiceType(service->getService()); + _vpnsetting->vpnPluginID = service->getService(); VPNConfigWidget* config = *_mapServiceWidget.find(service); if (config) { // update the vpn properties - _vpnsetting->setData(config->getVPNProperties()); + _vpnsetting->pluginData = config->getVPNProperties(); + // update the vpn secrets + _vpnsetting->pluginSecrets = config->getVPNSecrets(); } } } diff --git a/tdenetworkmanager/src/configwidgets/tdenetman-connection_setting_vpn_widget.h b/tdenetworkmanager/src/configwidgets/tdenetman-connection_setting_vpn_widget.h index ad9cfde..09efd05 100644 --- a/tdenetworkmanager/src/configwidgets/tdenetman-connection_setting_vpn_widget.h +++ b/tdenetworkmanager/src/configwidgets/tdenetman-connection_setting_vpn_widget.h @@ -41,14 +41,12 @@ class VPNConfigWidget; namespace ConnectionSettings { -class Connection; - class VPNWidgetImpl : public WidgetInterface { Q_OBJECT public: - VPNWidgetImpl(Connection* conn, bool new_conn, TQWidget* parent = NULL, const char* name = NULL, WFlags fl = 0); + VPNWidgetImpl(TDENetworkConnection* conn, bool new_conn, TQWidget* parent = NULL, const char* name = NULL, WFlags fl = 0); void Activate(); void Deactivate(); public slots: @@ -59,7 +57,7 @@ class VPNWidgetImpl : public WidgetInterface VPNConfigWidget* getVPNConfigWidget(VPNService* service); bool _new_conn; - VPN* _vpnsetting; + TDEVPNConnection* _vpnsetting; ConnectionSettingVPNWidget* _mainWid; TQMap _mapServiceCombo; TQMap _mapServiceWidget; diff --git a/tdenetworkmanager/src/configwidgets/tdenetman-connection_settings_dialog.cpp b/tdenetworkmanager/src/configwidgets/tdenetman-connection_settings_dialog.cpp index 7b98819..50ac293 100644 --- a/tdenetworkmanager/src/configwidgets/tdenetman-connection_settings_dialog.cpp +++ b/tdenetworkmanager/src/configwidgets/tdenetman-connection_settings_dialog.cpp @@ -50,6 +50,7 @@ #include "tdenetman-connection_setting_wireless_security_widget.h" #include "tdenetman-connection_setting_ipv4_widget.h" #include "tdenetman-connection_setting_info_widget.h" +#include "tdenetman-connection_setting_vpn_widget.h" #include "tdenetman-wireless_network.h" #include "tdenetman-wireless_manager.h" @@ -143,8 +144,8 @@ ConnectionSettingsDialogImpl::createWidgetsForVPN(TDENetworkConnection* conn, bo { TQValueList ret; - // widgetlist for wired connection -// ret.append(new ConnectionSettings::VPNWidgetImpl(conn, new_conn, this)); + // widgetlist for virtual private connection + ret.append(new ConnectionSettings::VPNWidgetImpl(conn, new_conn, this)); ret.append(new ConnectionSettings::InfoWidgetImpl(conn, this)); return ret; @@ -221,9 +222,9 @@ ConnectionSettingsDialogImpl::createWidgetsForConnection(TDENetworkConnection* c } } } -// else if (conn->getType() == NM_SETTING_VPN_SETTING_NAME) { -// widgets = createWidgetsForVPN(conn, new_conn); -// } + else if (conn->type() == TDENetworkConnectionType::VPN) { + widgets = createWidgetsForVPN(conn, new_conn); + } else { kdWarning() << k_funcinfo << "Not handled yet" << endl; } diff --git a/tdenetworkmanager/src/tdenetman-vpnmanager.cpp b/tdenetworkmanager/src/tdenetman-vpnmanager.cpp index 1113562..aa777f1 100644 --- a/tdenetworkmanager/src/tdenetman-vpnmanager.cpp +++ b/tdenetworkmanager/src/tdenetman-vpnmanager.cpp @@ -23,8 +23,6 @@ * **************************************************************************/ -#define SERVICE_DIR "/etc/NetworkManager/VPN" - #include #include #include @@ -42,27 +40,40 @@ VPNServiceList VPNManager::getVPNServices () { VPNServiceList list; - - TQDir serviceDir(SERVICE_DIR, TQString(), TQDir::Name|TQDir::IgnoreCase, TQDir::Files); - TQStringList services = serviceDir.entryList ().grep (".name", true); - if (services.count () > 0) - { - // read in all available Services - for (TQStringList::Iterator i = services.begin (); i != services.end (); ++i) { - TQString service = SERVICE_DIR + TQString ("/") + *i; - KConfig* kconfig = new KConfig (service, true, true, "config"); - kconfig->setGroup ("VPN Connection"); + TDEGlobalNetworkManager* nm = KGlobal::networkManager(); + TDENetworkVPNTypeList availablePlugins = nm->availableVPNTypes(); - kdDebug() << "VPN Service " << kconfig->readEntry ("name", TQString()).ascii() << endl; + if (availablePlugins.count() > 0) { + // find all available services + for (TDENetworkVPNTypeList::Iterator it = availablePlugins.begin (); it != availablePlugins.end (); ++it) { + TQString serviceString; + if ((*it) == TDENetworkVPNType::OpenVPN) { + serviceString = "openvpn"; + } + else if ((*it) == TDENetworkVPNType::PPTP) { + serviceString = "pptp"; + } + else if ((*it) == TDENetworkVPNType::StrongSwan) { + serviceString = "strongswan"; + } + else if ((*it) == TDENetworkVPNType::VPNC) { + serviceString = "vpnc"; + } + if (serviceString == "") { + continue; + } + + kdDebug() << "VPN Service " << serviceString.ascii() << endl; // create new VPNService Object - VPNService* vpnservice = new VPNService(kconfig->readEntry ("name", TQString()), kconfig->readEntry ("service", TQString()), TQT_TQOBJECT(TDENetworkManager::getInstance())); - if (!vpnservice->getVPNPlugin()) + VPNService* vpnservice = new VPNService(serviceString, serviceString, TQT_TQOBJECT(TDENetworkManager::getInstance())); + if (!vpnservice->getVPNPlugin()) { delete vpnservice; - else + } + else { list.push_back(vpnservice); - delete kconfig; + } } } @@ -73,31 +84,43 @@ VPNService* VPNManager::getVPNService(TQString service_type) { VPNServiceList list; - - TQDir serviceDir(SERVICE_DIR, TQString(), TQDir::Name|TQDir::IgnoreCase, TQDir::Files); - TQStringList services = serviceDir.entryList ().grep (".name", true); - if (services.count () > 0) - { - // read in all available Services - for (TQStringList::Iterator i = services.begin (); i != services.end (); ++i) { - TQString service = SERVICE_DIR + TQString ("/") + *i; - KConfig* kconfig = new KConfig (service, true, true, "config"); - kconfig->setGroup ("VPN Connection"); + TDEGlobalNetworkManager* nm = KGlobal::networkManager(); + TDENetworkVPNTypeList availablePlugins = nm->availableVPNTypes(); - if (kconfig->readEntry ("service", TQString()) == service_type) - { + if (availablePlugins.count() > 0) { + for (TDENetworkVPNTypeList::Iterator it = availablePlugins.begin (); it != availablePlugins.end (); ++it) { + TQString serviceString; + if ((*it) == TDENetworkVPNType::OpenVPN) { + serviceString = "openvpn"; + } + else if ((*it) == TDENetworkVPNType::PPTP) { + serviceString = "pptp"; + } + else if ((*it) == TDENetworkVPNType::StrongSwan) { + serviceString = "strongswan"; + } + else if ((*it) == TDENetworkVPNType::VPNC) { + serviceString = "vpnc"; + } + if (serviceString == "") { + continue; + } + + if (serviceString == service_type) { // create new VPNService Object - VPNService* vpnservice = new VPNService(kconfig->readEntry ("name", TQString()), kconfig->readEntry ("service", TQString()), TQT_TQOBJECT(TDENetworkManager::getInstance())); - if (!vpnservice->getVPNPlugin()) + VPNService* vpnservice = new VPNService(service_type, service_type, TQT_TQOBJECT(TDENetworkManager::getInstance())); + if (!vpnservice->getVPNPlugin()) { delete vpnservice; - else + } + else { return vpnservice; + } } } } - return NULL; + return NULL; } #include "tdenetman-vpnmanager.moc"