From 475d08942faffe521f631e149b05e39825736cb6 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Mon, 10 Sep 2012 13:36:13 -0500 Subject: [PATCH] Reactivate basic VPN support --- tdenetworkmanager/src/CMakeLists.txt | 11 +- tdenetworkmanager/src/tdenetman-tray.cpp | 172 +++++++++++++++--- tdenetworkmanager/src/tdenetman-tray.h | 4 + .../src/tdenetman-vpn_plugin.cpp | 132 -------------- tdenetworkmanager/src/tdenetman-vpn_plugin.h | 62 ------- .../src/tdenetman-vpnauthenticationdialog.cpp | 51 +----- .../src/tdenetman-vpnauthenticationdialog.h | 12 +- .../src/tdenetman-vpnmanager.cpp | 10 +- tdenetworkmanager/src/tdenetman-vpnmanager.h | 3 - tdenetworkmanager/src/tdenetman-vpnplugin.cpp | 4 +- tdenetworkmanager/src/tdenetman-vpnplugin.h | 10 +- tdenetworkmanager/src/tdenetman-vpnservice.h | 3 - tdenetworkmanager/src/vpn_tray_component.cpp | 120 ++++++------ 13 files changed, 243 insertions(+), 351 deletions(-) delete mode 100644 tdenetworkmanager/src/tdenetman-vpn_plugin.cpp delete mode 100644 tdenetworkmanager/src/tdenetman-vpn_plugin.h diff --git a/tdenetworkmanager/src/CMakeLists.txt b/tdenetworkmanager/src/CMakeLists.txt index 3d82ad4..10dd396 100644 --- a/tdenetworkmanager/src/CMakeLists.txt +++ b/tdenetworkmanager/src/CMakeLists.txt @@ -50,8 +50,7 @@ tde_add_tdeinit_executable( tdenetworkmanager AUTOMOC SOURCES connection_editor.ui vpnauthentication.ui main.cpp tdenetman.cpp tdenetman-tray.cpp - #tdenetman-vpn_plugin.cpp - tdenetman-cellular_device_tray.cpp #tdenetman-device_tray.cpp + tdenetman-cellular_device_tray.cpp tdenetman-wired_device_tray.cpp tdenetman-wireless_device_tray.cpp tdenetman-wireless_menuitem.cpp tdenetman-menuitem.cpp tdenetman-menu_subhead.cpp @@ -59,10 +58,10 @@ tde_add_tdeinit_executable( tdenetworkmanager AUTOMOC tdenetman-wireless_network.cpp tdenetman-wireless_manager.cpp tdenetman-connection_editor.cpp devicetraycomponent.cpp traycomponent.cpp - #tdenetman-plugin.cpp tdenetman-vpnplugin.cpp - #tdenetman-pluginmanager.cpp tdenetman-vpnservice.cpp tdenetman-vpnmanager.cpp - #tdenetman-vpnauthenticationdialog.cpp - #vpn_tray_component.cpp + tdenetman-plugin.cpp tdenetman-vpnplugin.cpp + tdenetman-pluginmanager.cpp tdenetman-vpnservice.cpp tdenetman-vpnmanager.cpp + tdenetman-vpnauthenticationdialog.cpp + vpn_tray_component.cpp EMBED tdenetwork-connection-configwidgets-static #tdenetwork-connection-settings-static LINK tdecore-shared tdeui-shared kutils-shared ${DBUS_TQT_LIBRARIES} ) diff --git a/tdenetworkmanager/src/tdenetman-tray.cpp b/tdenetworkmanager/src/tdenetman-tray.cpp index 371260c..f6b4d9e 100644 --- a/tdenetworkmanager/src/tdenetman-tray.cpp +++ b/tdenetworkmanager/src/tdenetman-tray.cpp @@ -66,10 +66,12 @@ #include "tdenetman-wired_device_tray.h" #include "tdenetman-wireless_device_tray.h" #include "tdenetman-cellular_device_tray.h" +#include "vpn_tray_component.h" #include -TDENetworkConnectionStatus::TDENetworkConnectionStatus nm_device_state_global; +TDENetworkConnectionStatus::TDENetworkConnectionStatus nm_device_state_global = TDENetworkConnectionStatus::Invalid; +TDENetworkConnectionStatus::TDENetworkConnectionStatus current_vpn_state = TDENetworkConnectionStatus::Invalid; NewSecretsDialog::NewSecretsDialog(TDENetworkConnection *connection, TQWidget * parent, const char * name, bool modal, TQt::WFlags f) : TQDialog(parent, name, modal, f) @@ -189,6 +191,23 @@ void Tray::slotOnlineMode() nm->enableNetworking(true); } +void Tray::slotNewVPNConnection() +{ + printf("Creating new VPN connection\n\r"); + // create a new VPN connection + TDEVPNConnection* conn = new TDEVPNConnection(); + + // edit the new connection + ConnectionSettingsDialogImpl* dlg = new ConnectionSettingsDialogImpl(conn, true, TQByteArray(), this, "connect_something", false, TQt::WDestructiveClose); + dlg->show(); +} + +void Tray::slotVPNBannerShow(const TQString& vpnbanner) +{ + printf("VPN banner: %s\n\r", vpnbanner.ascii()); + KNotifyClient::event(winId(), "knm-nm-vpn-banner", vpnbanner); +} + void Tray::contextMenuAboutToShow (KPopupMenu* menu) { TDEGlobalNetworkManager* nm = KGlobal::networkManager(); @@ -243,6 +262,13 @@ void Tray::contextMenuAboutToShow (KPopupMenu* menu) newConnActionMenu->insert(deviceNewConnAction); } } + // New VPN connection option + ++it; + KAction * deviceNewConnAction = 0; + TQString menuCaption = "VPN Connection"; + TQString actionName = TQString("new_connection_%1").arg("vpn"); + deviceNewConnAction = new KAction (menuCaption, 0, TQT_TQOBJECT(this), TQT_SLOT(slotNewVPNConnection()), actionCollection(), actionName); + newConnActionMenu->insert(deviceNewConnAction); } else if ( devices == 1 ) { newConnAction = actionCollection ()->action ("new_connection"); @@ -470,6 +496,33 @@ void Tray::createDeviceTrayComponent(TQString dev) } } +void Tray::createVPNTrayComponent() +{ + bool trayExists = false; + + // check if we have already a trayicon for this device + for (TQValueList::Iterator it = d->trayComponents.begin(); it != d->trayComponents.end(); ++it) + { + VPNTrayComponent* vpn_comp = dynamic_cast (*it); + if (vpn_comp) + { + trayExists = true; + break; + } + } + + // create the appropriate device tray icon + if (!trayExists) + { + TrayComponent* devTray = new VPNTrayComponent(this, "vpn_device_tray"); + if(devTray) + { + d->trayComponents.append(devTray); + //WILLTODO: sort + } + } +} + void Tray::updateDeviceTrays() { // create one tray-icon for each device @@ -486,6 +539,9 @@ void Tray::updateDeviceTrays() kdWarning() << k_funcinfo << "got a NULL-Device" << endl; } } + + // add the VPN componenet as it is not associated with a device + createVPNTrayComponent(); } void Tray::mousePressEvent( TQMouseEvent *e ) @@ -618,13 +674,37 @@ void Tray::trayUiChanged() void Tray::updateTrayIcon(TDENetworkConnectionStatus::TDENetworkConnectionStatus state) { // Get all active connections + char active_vpn=0; char found_any_active_connection=0; TDEGlobalNetworkManager* nm = KGlobal::networkManager(); + TDENetworkConnectionList* allconmap; + + // get all available VPN Connections + active_vpn = 0; + allconmap = nm->connections(); + for (TDENetworkConnectionList::Iterator it = allconmap->begin(); it != allconmap->end(); ++it) { + TDEVPNConnection* conn = dynamic_cast(*it); + if (!conn) { + continue; + } + + TDENetworkConnectionStatus::TDENetworkConnectionStatus connStatus = nm->checkConnectionStatus(conn->UUID); + if ((connStatus & TDENetworkConnectionStatus::Connected) + || (connStatus & TDENetworkConnectionStatus::EstablishingLink) + || (connStatus & TDENetworkConnectionStatus::ConfiguringProtocols) + || (connStatus & TDENetworkConnectionStatus::Reconnecting) + || (connStatus & TDENetworkConnectionStatus::VerifyingProtocols) + || (connStatus & TDENetworkConnectionStatus::NeedAuthorization) + || (connStatus & TDENetworkConnectionStatus::DependencyWait)) { + // This VPN connection is active! + active_vpn = 1; + } + } found_any_active_connection = 0; // Get all active connections - TDENetworkConnectionList* allconmap = nm->connections(); + allconmap = nm->connections(); for (TDENetworkConnectionList::Iterator it = allconmap->begin(); it != allconmap->end(); ++it) { TDENetworkConnection* conn = (*it); @@ -645,6 +725,10 @@ void Tray::updateTrayIcon(TDENetworkConnectionStatus::TDENetworkConnectionStatus // printf("Active connection found\n\r"); // } + if ((current_vpn_state & TDENetworkConnectionStatus::Failed) || (current_vpn_state & TDENetworkConnectionStatus::Disconnected)) { + active_vpn = 0; + } + // stop the old movie to avoid unnecessary wakups DeviceTrayComponent * dtc = d->foregroundTrayComponent; @@ -652,35 +736,77 @@ void Tray::updateTrayIcon(TDENetworkConnectionStatus::TDENetworkConnectionStatus movie()->pause(); } - if ((dtc) && (found_any_active_connection == 1)) { - if (!dtc->movieForState(state).isNull()) - { - // animation desired - int frame = -1; - if (movie()) { - frame = movie()->frameNumber(); + if (active_vpn == 0) { + if ((dtc) && (found_any_active_connection == 1)) { + if (!dtc->movieForState(state).isNull()) + { + // animation desired + int frame = -1; + if (movie()) { + frame = movie()->frameNumber(); + } + + // set the movie + setMovie(dtc->movieForState(state)); + + // start at the same frame as the movie before + if (frame > 0) { + movie()->step(frame); + } + + // start the animation + movie()->unpause(); } - - // set the movie - setMovie(dtc->movieForState(state)); - - // start at the same frame as the movie before - if (frame > 0) { - movie()->step(frame); + else if (!dtc->pixmapForState(state).isNull()) { + setPixmap(dtc->pixmapForState(state)); + } + else { + setPixmap(loadIcon("tdenetworkmanager")); } - - // start the animation - movie()->unpause(); - } - else if (!dtc->pixmapForState(state).isNull()) { - setPixmap(dtc->pixmapForState(state)); } else { setPixmap(loadIcon("tdenetworkmanager")); } } else { - setPixmap(loadIcon("tdenetworkmanager")); + printf("VPN state: %d\n\r", current_vpn_state); + //printf("Activated is: %d\n\r", TDENetworkConnectionStatus::Connected); + // stop the old movie to avoid unnecessary wakups + DeviceTrayComponent * dtc = d->foregroundTrayComponent; + + if (movie()) + movie()->pause(); + + if (dtc) { + if (current_vpn_state & TDENetworkConnectionStatus::Connected) { + setPixmap(loadIcon("nm_device_vpn")); + } + if ((current_vpn_state & TDENetworkConnectionStatus::EstablishingLink) + || (current_vpn_state & TDENetworkConnectionStatus::NeedAuthorization) + || (current_vpn_state & TDENetworkConnectionStatus::ConfiguringProtocols) + || (current_vpn_state & TDENetworkConnectionStatus::VerifyingProtocols)) { + int frame = -1; + if (movie()) + frame = movie()->frameNumber(); + + // set the movie + if ((current_vpn_state & TDENetworkConnectionStatus::EstablishingLink) + || (current_vpn_state & TDENetworkConnectionStatus::NeedAuthorization)) { + setMovie(TQMovie(KGlobal::iconLoader()->moviePath("nm_stage02_connecting_vpn", KIcon::Panel))); + } + if ((current_vpn_state & TDENetworkConnectionStatus::ConfiguringProtocols) + || (current_vpn_state & TDENetworkConnectionStatus::VerifyingProtocols)) { + setMovie(TQMovie(KGlobal::iconLoader()->moviePath("nm_stage03_connecting_vpn", KIcon::Panel))); + } + + // start at the same frame as the movie before + if (frame > 0) + movie()->step(frame); + + // start the animation + movie()->unpause(); + } + } } nm_device_state_global = state; diff --git a/tdenetworkmanager/src/tdenetman-tray.h b/tdenetworkmanager/src/tdenetman-tray.h index 75075a8..1daf455 100644 --- a/tdenetworkmanager/src/tdenetman-tray.h +++ b/tdenetworkmanager/src/tdenetman-tray.h @@ -94,6 +94,9 @@ class Tray : public KSystemTray void slotUpdateDeviceState(); void slotUpdateDeviceState(TDENetworkConnectionStatus::TDENetworkConnectionStatus newState, TDENetworkConnectionStatus::TDENetworkConnectionStatus prevState, TQString hwAddress); + void slotNewVPNConnection(); + void slotVPNBannerShow(const TQString& vpnbanner); + protected slots: void updateDeviceTrays(); void slotAddDeviceTrayComponent(TQString); @@ -112,6 +115,7 @@ class Tray : public KSystemTray void updateTrayIcon(TDENetworkConnectionStatus::TDENetworkConnectionStatus); void updateActiveConnection(TDENetworkConnectionStatus::TDENetworkConnectionStatus); void mousePressEvent(TQMouseEvent *e); + void createVPNTrayComponent(); void createDeviceTrayComponent(TQString); void enterEvent(TQEvent*); void connectTrayDeviceManager(); diff --git a/tdenetworkmanager/src/tdenetman-vpn_plugin.cpp b/tdenetworkmanager/src/tdenetman-vpn_plugin.cpp deleted file mode 100644 index 94f20b4..0000000 --- a/tdenetworkmanager/src/tdenetman-vpn_plugin.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/*************************************************************************** - * - * tdenetman-vpn_plugin.cpp - A NetworkManager frontend for TDE - * - * Copyright (C) 2005, 2006 Novell, Inc. - * - * Author: Helmut Schaa , - * Author: Timothy Pearson - * - * 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) any later version. - * - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - **************************************************************************/ - -// TDE includes -#include - -// TQt includes -#include - -// TQT_DBus includes -#include -#include -#include - -// NM includes -#include -#include - -// TDENM includes -#include "tdenetman.h" -#include "tdenetman-tray.h" -#include "tdenetman-vpn_plugin.h" -#include "dbus/vpnpluginproxy.h" -#include "tdenetman-hal_device_proxy.h" -#include "tdenetman-nm_proxy.h" - -#if !defined(NM_CHECK_VERSION) -#define NM_CHECK_VERSION(x,y,z) 0 -#endif - -unsigned int current_vpn_state = 0; -extern NMDeviceState nm_device_state_global; -extern TQT_DBusObjectPath vpn_attempt_this_conn; -unsigned char vpn_new_credentials_needed = 0; - -class VPNDBUSPluginPrivate -{ -public: - VPNDBUSPluginPrivate(TQString service, TQString obj_path) - : nmVPNDBUS(service, obj_path) - {} - ~VPNDBUSPluginPrivate() {} - - DBus::VPNPluginProxy nmVPNDBUS; -}; - -TQ_UINT32 VPNDBUSPlugin::getState() -{ - TQT_DBusError err; - return d->nmVPNDBUS.getState(err); -} - -void VPNDBUSPlugin::slotStateChanged(TQ_UINT32 state) -{ - current_vpn_state = state+1; - Tray* tray = Tray::getInstance(); - tray->slotUpdateDeviceState(nm_device_state_global); - //emit StateChanged((NMDeviceState)state); -} - -void VPNDBUSPlugin::slotLoginBanner(const TQString& banner) -{ - Tray* tray = Tray::getInstance(); - tray->slotVPNBannerShow(banner); -} - -void VPNDBUSPlugin::slotFailure(TQ_UINT32 failure_reason) -{ - printf("VPN failure code %d\n\r", failure_reason); - - if ((failure_reason == 0) || (failure_reason == 1) || (failure_reason == 2)) { - // Try to connect again using cached information; request new login though - printf("Reactivate VPN connection on default device\n\r"); - vpn_new_credentials_needed = 1; - int id; - TQT_DBusError err; - NMProxy* nm = NMProxy::getInstance(); - TQT_DBusObjectPath act_conn = nm->getDefaultActiveConnection(); - TQT_DBusObjectPath device = nm->getDeviceForActiveConnection(act_conn); -#if NM_CHECK_VERSION(0,8,992) - nm->ActivateConnectionAsync(id,"org.freedesktop.NetworkManagerUserSettings", vpn_attempt_this_conn, device, act_conn, err); -#else - nm->ActivateConnectionAsync(id,NM_DBUS_SERVICE_USER_SETTINGS, vpn_attempt_this_conn, device, act_conn, err); -#endif - } -} - -VPNDBUSPlugin::VPNDBUSPlugin () - : TQObject() -{ - d = new VPNDBUSPluginPrivate(NM_VPN_DBUS_PLUGIN_INTERFACE, NM_VPN_DBUS_PLUGIN_PATH); - d->nmVPNDBUS.setConnection(TQT_DBusConnection::systemBus()); - - // Connect the state changed signal to the handler - connect(&(d->nmVPNDBUS), TQT_SIGNAL(StateChanged(TQ_UINT32)), this, TQT_SLOT(slotStateChanged(TQ_UINT32))); - - // Connect the failure signal to the handler - connect(&(d->nmVPNDBUS), TQT_SIGNAL(Failure(TQ_UINT32)), this, TQT_SLOT(slotFailure(TQ_UINT32))); - - // And the banner signal - connect(&(d->nmVPNDBUS), TQT_SIGNAL(LoginBanner(const TQString&)), this, TQT_SLOT(slotLoginBanner(const TQString&))); -} - -VPNDBUSPlugin::~VPNDBUSPlugin () -{ - delete d; -} - - -#include "tdenetman-vpn_plugin.moc" diff --git a/tdenetworkmanager/src/tdenetman-vpn_plugin.h b/tdenetworkmanager/src/tdenetman-vpn_plugin.h deleted file mode 100644 index 674a402..0000000 --- a/tdenetworkmanager/src/tdenetman-vpn_plugin.h +++ /dev/null @@ -1,62 +0,0 @@ -/*************************************************************************** - * - * tdenetman-wired_device.h - A NetworkManager frontend for TDE - * - * Copyright (C) 2005, 2006 Novell, Inc. - * - * Author: Helmut Schaa , - * Author: Timothy Pearson - * - * 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) any later version. - * - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - **************************************************************************/ - -#ifndef KNETWORKMANAGER_VPNDBUSPLUGIN_H -#define KNETWORKMANAGER_VPNDBUSPLUGIN_H - -// std includes -#include - -// TDENM includes -#include "tdenetman.h" - -class TDENetworkManager; - -class VPNDBUSPluginPrivate; - -class VPNDBUSPlugin : public TQObject -{ - Q_OBJECT - - public: - VPNDBUSPlugin (); - ~VPNDBUSPlugin (); - - TQ_UINT32 getState(); - - private: - VPNDBUSPluginPrivate * d; - -// signals: -// void StateChanged(NMDeviceState); - - public slots: - void slotFailure(TQ_UINT32); - void slotStateChanged(TQ_UINT32); - void slotLoginBanner(const TQString&); -// void slotDeactivate(); -}; - -#endif /* KNETWORKMANAGER_VPNDBUSPLUGIN_H */ diff --git a/tdenetworkmanager/src/tdenetman-vpnauthenticationdialog.cpp b/tdenetworkmanager/src/tdenetman-vpnauthenticationdialog.cpp index ae4c047..db078df 100644 --- a/tdenetworkmanager/src/tdenetman-vpnauthenticationdialog.cpp +++ b/tdenetworkmanager/src/tdenetman-vpnauthenticationdialog.cpp @@ -38,32 +38,20 @@ #include #include -#include -#include - #include "tdenetman-vpnservice.h" #include "tdenetman-vpnmanager.h" #include "tdenetman-vpnauthenticationdialog.h" -#include "tdenetman-vpn_connection.h" -#include "tdenetman-nm_proxy.h" -#include "tdenetman-connection_setting_vpn.h" -#include "tdenetman-connection_setting_info.h" - -extern TQT_DBusObjectPath vpn_attempt_this_conn; - -using namespace ConnectionSettings; - /* * class VPNAuthenticationDialog * */ -VPNAuthenticationDialog::VPNAuthenticationDialog(VPNConnection* conn, TQWidget* parent, const char* name, bool modal, WFlags fl) +VPNAuthenticationDialog::VPNAuthenticationDialog(TDEVPNConnection* conn, TQWidget* parent, const char* name, bool modal, WFlags fl) : AuthenticationDialog(parent, name, modal, fl) , _conn(conn) { this->setIcon(SmallIcon("encrypted", TQIconSet::Automatic)); - this->setCaption(i18n("VPN Authentication for %1").arg(conn->getInfoSetting()->getName())); + this->setCaption(i18n("VPN Authentication for %1").arg(conn->friendlyName)); labelPixmap->setPixmap(KGlobal::instance()->iconLoader()->loadIcon("encrypted", KIcon::Small, 32)); // nice icons @@ -74,8 +62,8 @@ VPNAuthenticationDialog::VPNAuthenticationDialog(VPNConnection* conn, TQWidget* TQFocusData* foc = focusData(); TQWidget* lastFocusWidget = foc->last(); - VPN* vpn = conn->getVPNSetting(); - VPNService* vpnservice = VPNManager::getVPNService(vpn->getServiceType()); + TDEVPNConnection* vpn = conn; + VPNService* vpnservice = VPNManager::getVPNService(vpn->vpnPluginID); // get the appropriate plugin and create the authentication widget VPNPlugin* vpnPlugin = vpnservice->getVPNPlugin(); @@ -84,7 +72,7 @@ VPNAuthenticationDialog::VPNAuthenticationDialog(VPNConnection* conn, TQWidget* _vpnAuthWidget = vpnPlugin->CreateAuthenticationWidget(widgetStack); if (_vpnAuthWidget) { - _vpnAuthWidget->setVPNData(conn->getVPNSetting()->getRoutes(), conn->getVPNSetting()->getData()); + _vpnAuthWidget->setVPNData(conn->ipConfig.routeConfigurations, conn->pluginData, conn->pluginSecrets); widgetStack->raiseWidget(_vpnAuthWidget); } } @@ -119,37 +107,11 @@ VPNAuthenticationDialog::~VPNAuthenticationDialog() bool VPNAuthenticationDialog::close(bool alsoDelete) { - // no secrets provided, tell NM - _conn->slotSecretsError(); return AuthenticationDialog::close(alsoDelete); } void VPNAuthenticationDialog::ok() { - // Good, we have new secrets now, update the settings - TQMap mypwds; - - mypwds = _vpnAuthWidget->getPasswords(); - ConnectionSetting* propcore = _conn->getVPNSettingConnectionCore(); - SettingsMap othersettingsmap = propcore->toMap(); - - // Pull the username and gateway out of mypwds to stuff in the NM standard settings matrix - othersettingsmap.insert("user", TQT_DBusData::fromString(mypwds["user"])); - mypwds.erase("user"); - othersettingsmap.insert("domain", TQT_DBusData::fromString(mypwds["domain"])); - mypwds.erase("domain"); -// othersettingsmap.erase("Commit to disk"); -// if (chkStorePasswordsPermanent->isChecked() == true) { -// othersettingsmap.insert("Commit to disk", TQT_DBusData::fromString("true")); -// } -// else { -// othersettingsmap.insert("Commit to disk", TQT_DBusData::fromString("false")); -// } - - propcore->fromMap(othersettingsmap); - VPN* prop = dynamic_cast(propcore); - prop->setSecrets(mypwds); - _conn->slotSecretsProvided(prop); TQDialog::done(0); } @@ -169,9 +131,6 @@ void VPNAuthenticationDialog::cancel() printf("Attempting to deactivate VPN connection...\n\r"); - // Disconnect the attempted connection - _conn->slotSecretsError(); - // Quit the dialog TQDialog::done(1); } diff --git a/tdenetworkmanager/src/tdenetman-vpnauthenticationdialog.h b/tdenetworkmanager/src/tdenetman-vpnauthenticationdialog.h index 5602518..af50908 100644 --- a/tdenetworkmanager/src/tdenetman-vpnauthenticationdialog.h +++ b/tdenetworkmanager/src/tdenetman-vpnauthenticationdialog.h @@ -30,6 +30,9 @@ #include #include +#include +#include + #include "tdenetman.h" #include "vpnauthentication.h" #include "tdenetman-vpnplugin.h" @@ -39,17 +42,12 @@ class TDENetworkManager; class ManageConnectionsDialog; class VPNService; -namespace ConnectionSettings -{ - class VPNConnection; -} - class VPNAuthenticationDialog : public AuthenticationDialog { Q_OBJECT public: - VPNAuthenticationDialog(ConnectionSettings::VPNConnection* conn = NULL, TQWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0); + VPNAuthenticationDialog(TDEVPNConnection* conn = NULL, TQWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0); ~VPNAuthenticationDialog(); void setPasswords(TQString name, TQString value); virtual bool close(bool); @@ -60,7 +58,7 @@ class VPNAuthenticationDialog : public AuthenticationDialog private: VPNAuthenticationWidget* _vpnAuthWidget; - ConnectionSettings::VPNConnection* _conn; + TDEVPNConnection* _conn; signals: void done(bool, TQStringList &, bool, bool); diff --git a/tdenetworkmanager/src/tdenetman-vpnmanager.cpp b/tdenetworkmanager/src/tdenetman-vpnmanager.cpp index d3472c3..1113562 100644 --- a/tdenetworkmanager/src/tdenetman-vpnmanager.cpp +++ b/tdenetworkmanager/src/tdenetman-vpnmanager.cpp @@ -41,22 +41,20 @@ VPNServiceList VPNManager::getVPNServices () { - bool status = false; VPNServiceList list; TQDir serviceDir(SERVICE_DIR, TQString(), TQDir::Name|TQDir::IgnoreCase, TQDir::Files); TQStringList services = serviceDir.entryList ().grep (".name", true); if (services.count () > 0) - { - status = true; + { // 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"); -kdDebug() << "VPN Service " << kconfig->readEntry ("name", TQString()).ascii() << endl; + kdDebug() << "VPN Service " << kconfig->readEntry ("name", TQString()).ascii() << endl; // create new VPNService Object VPNService* vpnservice = new VPNService(kconfig->readEntry ("name", TQString()), kconfig->readEntry ("service", TQString()), TQT_TQOBJECT(TDENetworkManager::getInstance())); @@ -74,15 +72,13 @@ kdDebug() << "VPN Service " << kconfig->readEntry ("name", TQString()).ascii() < VPNService* VPNManager::getVPNService(TQString service_type) { - bool status = false; VPNServiceList list; TQDir serviceDir(SERVICE_DIR, TQString(), TQDir::Name|TQDir::IgnoreCase, TQDir::Files); TQStringList services = serviceDir.entryList ().grep (".name", true); if (services.count () > 0) - { - status = true; + { // read in all available Services for (TQStringList::Iterator i = services.begin (); i != services.end (); ++i) { TQString service = SERVICE_DIR + TQString ("/") + *i; diff --git a/tdenetworkmanager/src/tdenetman-vpnmanager.h b/tdenetworkmanager/src/tdenetman-vpnmanager.h index d6e6002..d80e7c5 100644 --- a/tdenetworkmanager/src/tdenetman-vpnmanager.h +++ b/tdenetworkmanager/src/tdenetman-vpnmanager.h @@ -26,9 +26,6 @@ #ifndef KNETWORKMANAGER_VPNMANAGER_H #define KNETWORKMANAGER_VPNMANAGER_H -#include -#include - #include #include diff --git a/tdenetworkmanager/src/tdenetman-vpnplugin.cpp b/tdenetworkmanager/src/tdenetman-vpnplugin.cpp index e06ea39..f21fa6b 100644 --- a/tdenetworkmanager/src/tdenetman-vpnplugin.cpp +++ b/tdenetworkmanager/src/tdenetman-vpnplugin.cpp @@ -41,7 +41,7 @@ VPNConfigWidget::VPNConfigWidget(TQWidget* parent, const char* name) } -void VPNConfigWidget::setVPNData(const TQStringList& /*routes*/, const TQMap& /*properties*/) +void VPNConfigWidget::setVPNData(TDENetworkSingleRouteConfigurationList& /*routes*/, TDENetworkSettingsMap& /*properties*/, TDENetworkSettingsMap& /*secrets*/) { } @@ -91,7 +91,7 @@ void VPNAuthenticationWidget::setPasswords(TQString name, TQString value) } -void VPNAuthenticationWidget::setVPNData(const TQStringList& /*routes*/, const TQMap& /*properties*/) +void VPNAuthenticationWidget::setVPNData(TDENetworkSingleRouteConfigurationList& /*routes*/, TDENetworkSettingsMap& /*properties*/, TDENetworkSettingsMap& /*secrets*/) { } diff --git a/tdenetworkmanager/src/tdenetman-vpnplugin.h b/tdenetworkmanager/src/tdenetman-vpnplugin.h index d98db7e..a24749a 100644 --- a/tdenetworkmanager/src/tdenetman-vpnplugin.h +++ b/tdenetworkmanager/src/tdenetman-vpnplugin.h @@ -27,8 +27,10 @@ #include #include -#include -#include + +#include +#include + #include "tdenetman-plugin.h" #define KNETWORKMANAGER_VPNPLUGIN "TDENetworkManager/VPNPlugin" @@ -41,7 +43,7 @@ class VPNConfigWidget : public TQWidget virtual ~VPNConfigWidget(); VPNConfigWidget(TQWidget* parent = NULL, const char* name = NULL); - virtual void setVPNData(const TQStringList&, const TQMap&); + virtual void setVPNData(TDENetworkSingleRouteConfigurationList&, TDENetworkSettingsMap&, TDENetworkSettingsMap&); virtual TQMap getVPNProperties(); virtual TQStringList getVPNRoutes(); virtual bool hasChanged(); @@ -56,7 +58,7 @@ class VPNAuthenticationWidget : public TQWidget virtual ~VPNAuthenticationWidget(); VPNAuthenticationWidget(TQWidget* parent = NULL, const char* name = NULL); - virtual void setVPNData(const TQStringList&, const TQMap&); + virtual void setVPNData(TDENetworkSingleRouteConfigurationList&, TDENetworkSettingsMap&, TDENetworkSettingsMap&); virtual TQMap getPasswords(); virtual void setPasswords(TQString value, TQString data); virtual bool needsUserInteraction(); diff --git a/tdenetworkmanager/src/tdenetman-vpnservice.h b/tdenetworkmanager/src/tdenetman-vpnservice.h index d95fafa..ed6004f 100644 --- a/tdenetworkmanager/src/tdenetman-vpnservice.h +++ b/tdenetworkmanager/src/tdenetman-vpnservice.h @@ -26,9 +26,6 @@ #ifndef KNETWORKMANAGER_VPN_SERVICE_H #define KNETWORKMANAGER_VPN_SERVICE_H -#include -#include - #include #include diff --git a/tdenetworkmanager/src/vpn_tray_component.cpp b/tdenetworkmanager/src/vpn_tray_component.cpp index 49474b2..019e6c3 100644 --- a/tdenetworkmanager/src/vpn_tray_component.cpp +++ b/tdenetworkmanager/src/vpn_tray_component.cpp @@ -35,12 +35,7 @@ #include "vpn_tray_component.h" #include "tdenetman-menuitem.h" #include "tdenetman-menu_subhead.h" -#include "tdenetman-connection_store.h" -#include "tdenetman-vpn_connection.h" -#include "tdenetman-nm_proxy.h" -#include "tdenetman-connection_setting_info.h" -#include "tdenetman-connection_setting_vpn.h" #include "tdenetman-connection_settings_dialog.h" #include @@ -48,11 +43,14 @@ using namespace ConnectionSettings; void VPNTrayComponent::slotShowNewConnectionDialog() { + TDEGlobalNetworkManager* nm = KGlobal::networkManager(); + // create a new VPN connection - Connection* conn = new VPNConnection(); + TDEVPNConnection* conn = new TDEVPNConnection(); + nm->loadConnectionAllowedValues(conn); // edit the new connection - ConnectionSettingsDialogImpl* dlg = new ConnectionSettingsDialogImpl(conn, true, NULL, tray(), "connect_something", false, TQt::WDestructiveClose); + ConnectionSettingsDialogImpl* dlg = new ConnectionSettingsDialogImpl(conn, true, TQByteArray(), tray(), "connect_something", false, TQt::WDestructiveClose); dlg->show(); } @@ -60,70 +58,80 @@ void VPNTrayComponent::slotShowNewConnectionDialog() void VPNTrayComponent::addMenuItems(KPopupMenu* menu) { int inactive_vpn_connections = 0; - char vpn_found; + char vpn_found = 0; char any_vpn_found = 0; - ConnectionStore* connectionStore = ConnectionStore::getInstance(); // Get all active connections - NMProxy* nm = NMProxy::getInstance(); - TQValueList > map = nm->getActiveConnectionsMap(); + TDEGlobalNetworkManager* nm = KGlobal::networkManager(); // get all available VPN Connections - TQValueList connections = connectionStore->getConnections(NM_SETTING_VPN_SETTING_NAME); - if (!connections.empty()) - { - TQPopupMenu* popup = new TQPopupMenu(menu); - for (TQValueList::iterator it = connections.begin(); it != connections.end(); ++it) - { - VPNConnection* vpnconn = dynamic_cast(*it); - if (vpnconn) - { - // VPN connection found :) - Info* info = vpnconn->getInfoSetting(); - - // lets create a nice name for this connection - if (info) - { - TQString title = info->getName(); + TQPopupMenu* popup = NULL; + TDENetworkConnectionList* allconmap = nm->connections(); + for (TDENetworkConnectionList::Iterator it = allconmap->begin(); it != allconmap->end(); ++it) { + TDEVPNConnection* conn = dynamic_cast(*it); + if (!conn) { + continue; + } + + if (!popup) { + popup = new TQPopupMenu(menu); + } + + TQString title = conn->friendlyName; - NetworkMenuItem* item = new NetworkMenuItem(NULL, vpnconn, TQT_TQOBJECT(menu)); - - vpn_found = 0; - for (TQValueList >::Iterator it = map.begin(); it != map.end(); ++it) - { - ConnectionSettings::GenericConnection* conn = dynamic_cast((*it).first); - - if (conn) { - if (strcmp(info->getName(), conn->getInfoSetting()->getName()) == 0) { - vpn_found = 1; - any_vpn_found = 1; - } - } - } - - if (vpn_found == 1) { - printf("Active VPN connection found\n\r"); - } - else { - int id = popup->insertItem(SmallIcon ("encrypted", TQIconSet::Automatic), title, item, TQT_SLOT(slotActivate())); - inactive_vpn_connections++; - } - - //menu->setItemChecked(id, ((*it) == active_conn)); - } - } + NetworkMenuItem* item = new NetworkMenuItem(NULL, conn->UUID, TQT_TQOBJECT(menu)); + + vpn_found = 0; + TDENetworkConnectionStatus::TDENetworkConnectionStatus connStatus = nm->checkConnectionStatus(conn->UUID); + if ((connStatus & TDENetworkConnectionStatus::Connected) + || (connStatus & TDENetworkConnectionStatus::EstablishingLink) + || (connStatus & TDENetworkConnectionStatus::ConfiguringProtocols) + || (connStatus & TDENetworkConnectionStatus::Reconnecting) + || (connStatus & TDENetworkConnectionStatus::VerifyingProtocols) + || (connStatus & TDENetworkConnectionStatus::NeedAuthorization) + || (connStatus & TDENetworkConnectionStatus::DependencyWait)) { + // This VPN connection is active! + vpn_found = 1; + any_vpn_found = 1; + } + + if (vpn_found == 1) { + printf("Active VPN connection found\n\r"); + } + else { + popup->insertItem(SmallIcon ("encrypted", TQIconSet::Automatic), title, item, TQT_SLOT(slotActivate())); + inactive_vpn_connections++; } - TQT_DBusObjectPath act_conn = nm->getDefaultActiveConnection(); - TQT_DBusObjectPath device = nm->getDeviceForActiveConnection(act_conn); + //menu->setItemChecked(id, ((*it) == active_conn)); + } + if (popup) { + // At least one VPN connection is defined on this system if (any_vpn_found == 1) { inactive_vpn_connections = 0; } - if (device.isNull()) { +#if 0 + // FIXME + // NetworkManager is rather stupid and won't let us activate a VPN connection if it doesn't manage the backend connection (!?!?!?) + // When/if this limitation is removed, uncomment the following code block! + TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags backendStatus = nm->backendStatus(); + if ((backendStatus & TDENetworkGlobalManagerFlags::Connected) + || (backendStatus & TDENetworkGlobalManagerFlags::LinkLocalAccess) + || (backendStatus & TDENetworkGlobalManagerFlags::SiteLocalAccess) + || (backendStatus & TDENetworkGlobalManagerFlags::GlobalAccess)) { + // We have network access of some kind + } + else { + inactive_vpn_connections = 0; + } +#else + TQStringList defaultNetworkDevices = nm->defaultNetworkDevices(); + if (defaultNetworkDevices.count() <= 0) { inactive_vpn_connections = 0; } +#endif if (inactive_vpn_connections > 0) { menu->insertItem(SmallIcon ("encrypted", TQIconSet::Automatic), i18n("Start VPN connection"), popup);