Fix VPN editing and connection

pull/1/head
Timothy Pearson 12 years ago
parent cfa58d935e
commit f285871c3c

@ -175,12 +175,14 @@ VPNWidgetImpl::Deactivate()
// set the correct service type // set the correct service type
_vpnsetting->vpnPluginID = service->getService(); _vpnsetting->vpnPluginID = service->getService();
VPNConfigWidget* config = *_mapServiceWidget.find(service); if (_mapServiceWidget.find(service) != _mapServiceWidget.end()) {
if (config) { VPNConfigWidget* config = *_mapServiceWidget.find(service);
// update the vpn properties if (config) {
_vpnsetting->pluginData = config->getVPNProperties(); // update the vpn properties
// update the vpn secrets _vpnsetting->pluginData = config->getVPNProperties();
_vpnsetting->pluginSecrets = config->getVPNSecrets(); // update the vpn secrets
_vpnsetting->pluginSecrets = config->getVPNSecrets();
}
} }
} }
} }

@ -45,6 +45,8 @@
#include "tdenetman-connection_editor.h" #include "tdenetman-connection_editor.h"
#include "tdenetman-connection_settings_dialog.h" #include "tdenetman-connection_settings_dialog.h"
extern unsigned int tdenetworkmanager_editor_dialog_count;
using namespace ConnectionSettings; using namespace ConnectionSettings;
/* /*
@ -54,21 +56,24 @@ class ConnectionListViewItem : public KListViewItem
{ {
public: public:
ConnectionListViewItem(TQListView* parent, TDENetworkConnection* connection) ConnectionListViewItem(TQListView* parent, TQString connection)
: KListViewItem(parent) : KListViewItem(parent)
, _conn(connection) , _conn(connection)
{ {
if (_conn) { TDEGlobalNetworkManager* nm = KGlobal::networkManager();
setText(0, _conn->friendlyName); TDENetworkConnection* conn = (nm)?nm->findConnectionByUUID(connection):NULL;
setText(1, TDENetworkConnectionManager::friendlyConnectionTypeName(_conn->type()));
if (conn) {
setText(0, conn->friendlyName);
setText(1, TDENetworkConnectionManager::friendlyConnectionTypeName(conn->type()));
// TODO: Move to a Factory // TODO: Move to a Factory
if (_conn->type() == TDENetworkConnectionType::WiredEthernet) { if (conn->type() == TDENetworkConnectionType::WiredEthernet) {
setPixmap(0, KGlobal::iconLoader()->loadIcon("wired", KIcon::Small)); setPixmap(0, KGlobal::iconLoader()->loadIcon("wired", KIcon::Small));
} }
else if (_conn->type() == TDENetworkConnectionType::WiFi) { else if (conn->type() == TDENetworkConnectionType::WiFi) {
setPixmap(0, KGlobal::iconLoader()->loadIcon("wireless", KIcon::Small)); setPixmap(0, KGlobal::iconLoader()->loadIcon("wireless", KIcon::Small));
} }
else if (_conn->type() == TDENetworkConnectionType::VPN) { else if (conn->type() == TDENetworkConnectionType::VPN) {
setPixmap(0, KGlobal::iconLoader()->loadIcon("encrypted", KIcon::Small)); setPixmap(0, KGlobal::iconLoader()->loadIcon("encrypted", KIcon::Small));
} }
else { else {
@ -77,7 +82,7 @@ class ConnectionListViewItem : public KListViewItem
} }
} }
TDENetworkConnection* _conn; TQString _conn;
}; };
/* /*
@ -86,6 +91,7 @@ class ConnectionListViewItem : public KListViewItem
ConnectionEditorImpl::ConnectionEditorImpl(TQWidget* parent, const char* name, bool modal, WFlags fl) ConnectionEditorImpl::ConnectionEditorImpl(TQWidget* parent, const char* name, bool modal, WFlags fl)
: ConnectionEditor(parent, name, modal, fl) : ConnectionEditor(parent, name, modal, fl)
{ {
tdenetworkmanager_editor_dialog_count++;
// TODO: enable combobox if implemented // TODO: enable combobox if implemented
cboConnectionType->hide(); cboConnectionType->hide();
@ -126,6 +132,8 @@ ConnectionEditorImpl::~ConnectionEditorImpl()
if (pbNew->popup()) { if (pbNew->popup()) {
delete pbNew->popup(); delete pbNew->popup();
} }
tdenetworkmanager_editor_dialog_count--;
} }
/* /*
@ -184,13 +192,15 @@ void ConnectionEditorImpl::slotEditCurrentConnection()
return; return;
} }
TDENetworkConnection* conn = item->_conn; TDENetworkConnection* conn = nm->findConnectionByUUID(item->_conn);
// we need the secrets for editing if (conn) {
nm->loadConnectionSecrets(conn->UUID); // we need the secrets for editing
nm->loadConnectionSecrets(conn->UUID);
ConnectionSettingsDialogImpl* dlg = new ConnectionSettingsDialogImpl(conn, false, TQByteArray(), this, "connect_something", false, TQt::WDestructiveClose); ConnectionSettingsDialogImpl* dlg = new ConnectionSettingsDialogImpl(conn, false, TQByteArray(), this, "connect_something", false, TQt::WDestructiveClose);
dlg->show(); dlg->show();
}
} }
@ -209,11 +219,11 @@ void ConnectionEditorImpl::slotRemoveCurrentConnection()
return; return;
} }
TDENetworkConnection* conn = item->_conn; TDENetworkConnection* conn = nm->findConnectionByUUID(item->_conn);
lvConnections->takeItem(item); lvConnections->takeItem(item);
delete item; delete item;
nm->deleteConnection(conn->UUID); nm->deleteConnection(conn->UUID);
} }
@ -232,7 +242,7 @@ void ConnectionEditorImpl::fillConnectionList()
TDENetworkConnectionList* allconmap = nm->connections(); TDENetworkConnectionList* allconmap = nm->connections();
for (TDENetworkConnectionList::Iterator it = allconmap->begin(); it != allconmap->end(); ++it) { for (TDENetworkConnectionList::Iterator it = allconmap->begin(); it != allconmap->end(); ++it) {
TDENetworkConnection* conn = *it; TDENetworkConnection* conn = *it;
new ConnectionListViewItem(lvConnections, conn); new ConnectionListViewItem(lvConnections, conn->UUID);
} }
} }

@ -70,6 +70,8 @@
#include <stdio.h> #include <stdio.h>
unsigned int tdenetworkmanager_editor_dialog_count = 0;
TDENetworkConnectionStatus::TDENetworkConnectionStatus nm_device_state_global = TDENetworkConnectionStatus::Invalid; TDENetworkConnectionStatus::TDENetworkConnectionStatus nm_device_state_global = TDENetworkConnectionStatus::Invalid;
NewSecretsDialog::NewSecretsDialog(TDENetworkConnection *connection, TQWidget * parent, const char * name, bool modal, TQt::WFlags f) NewSecretsDialog::NewSecretsDialog(TDENetworkConnection *connection, TQWidget * parent, const char * name, bool modal, TQt::WFlags f)
@ -157,6 +159,10 @@ Tray* Tray::getInstance()
void Tray::slotEditConnections() void Tray::slotEditConnections()
{ {
TDEGlobalNetworkManager* nm = KGlobal::networkManager();
if (!nm) return;
if (tdenetworkmanager_editor_dialog_count == 0) nm->loadConnectionInformation();
ConnectionEditorImpl* dlg = new ConnectionEditorImpl(this); ConnectionEditorImpl* dlg = new ConnectionEditorImpl(this);
dlg->show(); dlg->show();
} }
@ -211,7 +217,7 @@ void Tray::contextMenuAboutToShow (KPopupMenu* menu)
{ {
TDEGlobalNetworkManager* nm = KGlobal::networkManager(); TDEGlobalNetworkManager* nm = KGlobal::networkManager();
nm->loadConnectionInformation(); if (tdenetworkmanager_editor_dialog_count == 0) nm->loadConnectionInformation();
// clear menu // clear menu
menu->clear(); menu->clear();
@ -728,6 +734,8 @@ void Tray::updateTrayIcon(TDENetworkConnectionStatus::TDENetworkConnectionStatus
TDEGlobalNetworkManager* nm = KGlobal::networkManager(); TDEGlobalNetworkManager* nm = KGlobal::networkManager();
TDENetworkConnectionList* allconmap; TDENetworkConnectionList* allconmap;
if (tdenetworkmanager_editor_dialog_count == 0) nm->loadConnectionInformation();
// get all available VPN Connections // get all available VPN Connections
active_vpn = 0; active_vpn = 0;
allconmap = nm->connections(); allconmap = nm->connections();
@ -750,8 +758,6 @@ void Tray::updateTrayIcon(TDENetworkConnectionStatus::TDENetworkConnectionStatus
} }
} }
nm->loadConnectionInformation();
found_any_active_connection = 0; found_any_active_connection = 0;
// Get all active connections // Get all active connections
allconmap = nm->connections(); allconmap = nm->connections();

@ -35,6 +35,8 @@
#include "tdenetman-connection_settings_dialog.h" #include "tdenetman-connection_settings_dialog.h"
#include <stdio.h> #include <stdio.h>
extern unsigned int tdenetworkmanager_editor_dialog_count;
using namespace ConnectionSettings; using namespace ConnectionSettings;
void VPNTrayComponent::slotShowNewConnectionDialog() void VPNTrayComponent::slotShowNewConnectionDialog()
@ -60,6 +62,8 @@ void VPNTrayComponent::addMenuItems(KPopupMenu* menu)
// Get all active connections // Get all active connections
TDEGlobalNetworkManager* nm = KGlobal::networkManager(); TDEGlobalNetworkManager* nm = KGlobal::networkManager();
if (tdenetworkmanager_editor_dialog_count == 0) nm->loadConnectionInformation();
// get all available VPN Connections // get all available VPN Connections
TQPopupMenu* popup = NULL; TQPopupMenu* popup = NULL;
TDENetworkConnectionList* allconmap = nm->connections(); TDENetworkConnectionList* allconmap = nm->connections();
@ -88,8 +92,8 @@ void VPNTrayComponent::addMenuItems(KPopupMenu* menu)
|| (connStatus & TDENetworkConnectionStatus::DependencyWait)) { || (connStatus & TDENetworkConnectionStatus::DependencyWait)) {
// This VPN connection is active! // This VPN connection is active!
vpn_found = 1; vpn_found = 1;
any_vpn_found = 1;
} }
any_vpn_found = 1;
if (vpn_found == 1) { if (vpn_found == 1) {
printf("Active VPN connection found\n\r"); printf("Active VPN connection found\n\r");
@ -103,8 +107,7 @@ void VPNTrayComponent::addMenuItems(KPopupMenu* menu)
} }
if (popup) { if (popup) {
// At least one VPN connection is defined on this system if (!any_vpn_found) {
if (any_vpn_found == 1) {
inactive_vpn_connections = 0; inactive_vpn_connections = 0;
} }
@ -123,12 +126,34 @@ void VPNTrayComponent::addMenuItems(KPopupMenu* menu)
inactive_vpn_connections = 0; inactive_vpn_connections = 0;
} }
#else #else
TQStringList defaultNetworkDevices = nm->defaultNetworkDevices(); // TQStringList defaultNetworkDevices = nm->defaultNetworkDevices();
if (defaultNetworkDevices.count() <= 0) { // if (defaultNetworkDevices.count() <= 0) {
// inactive_vpn_connections = 0;
// }
// See if any connections are active
bool found_any_active_connection = false;
TDENetworkConnectionList* allconmap = nm->connections();
for (TDENetworkConnectionList::Iterator it = allconmap->begin(); it != allconmap->end(); ++it) {
TDENetworkConnection* conn = (*it);
if (!conn) {
continue;
}
if ((nm->checkConnectionStatus(conn->UUID) & TDENetworkConnectionStatus::Disconnected)
|| (nm->checkConnectionStatus(conn->UUID) & TDENetworkConnectionStatus::Invalid)) {
continue;
}
// Found an active connection
found_any_active_connection = true;
}
if (!found_any_active_connection) {
inactive_vpn_connections = 0; inactive_vpn_connections = 0;
} }
#endif #endif
if (inactive_vpn_connections > 0) { if (inactive_vpn_connections > 0) {
menu->insertItem(SmallIcon ("encrypted", TQIconSet::Automatic), i18n("Start VPN connection"), popup); menu->insertItem(SmallIcon ("encrypted", TQIconSet::Automatic), i18n("Start VPN connection"), popup);
menu->insertSeparator(); menu->insertSeparator();

Loading…
Cancel
Save