From 7d8a74d0f9922463f3c6e12d8ea46762f5c8bb10 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sat, 8 Sep 2012 21:10:55 -0500 Subject: Automatically generate UUID when needed --- .../network-manager/network-manager.cpp | 60 +++++++++++++++++++--- .../network-manager/network-manager_p.h | 1 + tdecore/tdenetworkconnections.cpp | 7 --- 3 files changed, 53 insertions(+), 15 deletions(-) (limited to 'tdecore') diff --git a/tdecore/networkbackends/network-manager/network-manager.cpp b/tdecore/networkbackends/network-manager/network-manager.cpp index 105c8e332..a46144ea2 100644 --- a/tdecore/networkbackends/network-manager/network-manager.cpp +++ b/tdecore/networkbackends/network-manager/network-manager.cpp @@ -56,14 +56,44 @@ TQT_DBusData convertDBUSDataToVariantData(TQT_DBusData object) { return TQT_DBusData::fromVariant(variant); } -void printDBUSObjectStructure(TQT_DBusData object, int level=0) { +void printDBUSObjectStructure(TQT_DBusData object, int level=0, TQString mapKey=TQString::null) { int i; TQString levelIndent = ""; for (i=0; i outerMap = object.toStringKeyMap().toTQMap(); TQMap::const_iterator it; for (it = outerMap.begin(); it != outerMap.end(); ++it) { - printDBUSObjectStructure(*it, level+1); + printDBUSObjectStructure(*it, level+1, it.key()); } } - if (object.type() == TQT_DBusData::List) { + else if (object.type() == TQT_DBusData::List) { TQT_DBusDataValueList valueList = object.toTQValueList(); TQT_DBusDataValueList::const_iterator it; for (it = valueList.begin(); it != valueList.end(); ++it) { @@ -84,7 +114,7 @@ void printDBUSObjectStructure(TQT_DBusData object, int level=0) { else if (object.type() == TQT_DBusData::Variant) { TQT_DBusVariant dataValueVariant = object.toVariant(); TQT_DBusData dataValue = dataValueVariant.value; - printDBUSObjectStructure(dataValue, level+1); + printDBUSObjectStructure(dataValue, level+1, mapKey); } } @@ -2749,12 +2779,26 @@ bool TDENetworkConnectionManager_BackendNM::loadConnectionSecretsForGroup(TQStri } bool TDENetworkConnectionManager_BackendNM::saveConnection(TDENetworkConnection* connection) { - // Find path for connection with specified UUID, if it exists - // This is so that any settings that we are not aware of can be loaded now and preserved through the update operation if (!connection) { PRINT_ERROR(TQString("connection cannot be NULL!")); return FALSE; } + + // If the UUID is blank, generate a new UUID for this connection and also guarantee that it it truly unique + if (connection->UUID == "") { + bool unique = false; + while (!unique) { + connection->UUID = TQUuid::createUuid().toString(); + connection->UUID.replace("{", ""); + connection->UUID.replace("}", ""); + if (!findConnectionByUUID(connection->UUID)) { + unique = true; + } + } + } + + // Find path for connection with specified UUID, if it exists + // This is so that any settings that we are not aware of can be loaded now and preserved through the update operation TDEWiredEthernetConnection* ethernetConnection = dynamic_cast(connection); TDEWiredInfinibandConnection* infinibandConnection = dynamic_cast(connection); TDEWiFiConnection* wiFiConnection = dynamic_cast(connection); @@ -2848,7 +2892,7 @@ bool TDENetworkConnectionManager_BackendNM::saveConnection(TDENetworkConnection* } settingsMap["autoconnect"] = convertDBUSDataToVariantData(TQT_DBusData::fromBool(connection->autoConnect)); settingsMap["read-only"] = convertDBUSDataToVariantData(TQT_DBusData::fromBool(connection->readOnly)); - settingsMap["master"] = convertDBUSDataToVariantData(TQT_DBusData::fromString(connection->masterConnectionUUID)); + UPDATE_STRING_SETTING_IF_VALID(connection->masterConnectionUUID, "master", settingsMap) { TQString slaveType = tdeSlaveTypeToNMSlaveType(connection->slaveType); if (slaveType != "") settingsMap["slave-type"] = convertDBUSDataToVariantData(TQT_DBusData::fromString(slaveType)); diff --git a/tdecore/networkbackends/network-manager/network-manager_p.h b/tdecore/networkbackends/network-manager/network-manager_p.h index 728b1ac52..758e7fe77 100644 --- a/tdecore/networkbackends/network-manager/network-manager_p.h +++ b/tdecore/networkbackends/network-manager/network-manager_p.h @@ -23,6 +23,7 @@ #include #include #include +#include /* TDE headers */ #include diff --git a/tdecore/tdenetworkconnections.cpp b/tdecore/tdenetworkconnections.cpp index 3891f1ff7..6139bd49f 100644 --- a/tdecore/tdenetworkconnections.cpp +++ b/tdecore/tdenetworkconnections.cpp @@ -21,8 +21,6 @@ #include "config.h" -#include - #include #ifdef WITH_NETWORK_MANAGER_BACKEND @@ -501,11 +499,6 @@ TDENetworkConnection::TDENetworkConnection() { requireIPV4 = false; requireIPV6 = false; mtu = 0; - - // Create a UUID for the new connection - // This may be overridden later on if connection information - // is loaded into this object from another source - UUID = TQUuid::createUuid().toString(); } TDENetworkConnection::~TDENetworkConnection() { -- cgit v1.2.1