Branch: master

bf683427 2019-07-07 14:44:28 Michele Calgaro
Reworked code for eject/mount/unmount operations to support new TDEStorageOpResult return type.

Signed-off-by: Michele Calgaro <michele.calgaro@...>
M tdecore/tdehw/disksHelper.cpp
M tdecore/tdehw/disksHelper.h
M tdecore/tdehw/tdestoragedevice.cpp
M tdecore/tdehw/tdestoragedevice.h

tdecore/tdehw/disksHelper.cpp

diff --git a/tdecore/tdehw/disksHelper.cpp b/tdecore/tdehw/disksHelper.cpp
index e8e164b..37efa25 100644
--- a/tdecore/tdehw/disksHelper.cpp
+++ b/tdecore/tdehw/disksHelper.cpp
@@ -18,8 +18,9 @@
 */
 
 #include "disksHelper.h"
+#include "tdelocale.h"
 #include "tdestoragedevice.h"
-
+#include <tqvariant.h>
 #include <tqdbusdata.h>
 #include <tqdbusmessage.h>
 #include <tqdbusproxy.h>
@@ -33,7 +34,10 @@
 //-------------------------------
 //  UDisks
 //-------------------------------
-bool ejectDriveUDisks(TDEStorageDevice* sdevice) {
+TDEStorageOpResult UDisksEjectDrive(TDEStorageDevice *sdevice) {
+	TDEStorageOpResult result;
+	result["result"] = false;
+
 	TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
 	if (dbusConn.isConnected()) {
 		TQString blockDeviceString = sdevice->deviceNode();
@@ -51,18 +55,23 @@
 			TQT_DBusMessage reply = driveControl.sendWithReply("DriveEject", params, &error);
 			if (error.isValid()) {
 				// Error!
-				printf("[ERROR][tdehwlib] ejectDriveUDisks: %s\n", error.name().ascii()); fflush(stdout);
-				return false;
+				result["errStr"] = error.name() + ": " + error.message();
+				return result;
 			}
 			else {
-				return true;
+				result["result"] = true;
+				return result;
 			}
 		}
 	}
-	return false;
+	return result;
 }
 
-int mountDriveUDisks(TQString deviceNode, TQString fileSystemType, TQStringList mountOptions, TQString* errStr) {
+TDEStorageOpResult UDisksMountDrive(TQString deviceNode, TQString fileSystemType, TQStringList mountOptions) {
+	TDEStorageOpResult result;
+	result["result"] = false;
+	result["retcode"] = -2;
+
 	TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
 	if (dbusConn.isConnected()) {
 		TQString blockDeviceString = deviceNode;
@@ -78,32 +87,33 @@
 			params << TQT_DBusData::fromString(fileSystemType);
 			params << TQT_DBusData::fromList(TQT_DBusDataList(mountOptions));
 			TQT_DBusMessage reply = driveControl.sendWithReply("FilesystemMount", params, &error);
-			if (error.isValid()) {
-				// Error!
-				if (error.name() == "org.freedesktop.DBus.Error.ServiceUnknown") {
-					// Service not installed or unavailable
-					return -2;
-				}
-				if (errStr) {
-					*errStr = error.name() + ": " + error.message();
-				}
-				else {
-					printf("[ERROR][tdehwlib] mountDriveUDisks: %s\n", error.name().ascii()); fflush(stdout);
-				}
-				return -1;
+			if (!error.isValid()) {
+				// Success
+				result["retcode"] = 0;
+				result["result"] = true;
+				return result;
 			}
 			else {
-				return 0;
+				// Error!
+				if (error.name() == "org.freedesktop.DBus.Error.ServiceUnknown") {
+					return result;  // Service not installed or unavailable
+				}
+				else {
+					result["errStr"] = error.name() + ": " + error.message();
+					result["retcode"] = -1;
+					return result;
+				}
 			}
 		}
-		else {
-			return -2;
-		}
 	}
-	return -2;
+	return result;
 }
 
-int unMountDriveUDisks(TQString deviceNode, TQStringList unMountOptions, TQString* errStr) {
+TDEStorageOpResult UDisksUnmountDrive(TQString deviceNode, TQStringList unmountOptions) {
+	TDEStorageOpResult result;
+	result["result"] = false;
+	result["retcode"] = -2;
+
 	TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
 	if (dbusConn.isConnected()) {
 		TQString blockDeviceString = deviceNode;
@@ -116,37 +126,37 @@
 		TQT_DBusProxy driveControl("org.freedesktop.UDisks", blockDeviceString, "org.freedesktop.UDisks.Device", dbusConn);
 		if (driveControl.canSend()) {
 			TQValueList<TQT_DBusData> params;
-			params << TQT_DBusData::fromList(TQT_DBusDataList(unMountOptions));
+			params << TQT_DBusData::fromList(TQT_DBusDataList(unmountOptions));
 			TQT_DBusMessage reply = driveControl.sendWithReply("FilesystemUnmount", params, &error);
-			if (error.isValid()) {
-				// Error!
-				if (error.name() == "org.freedesktop.DBus.Error.ServiceUnknown") {
-					// Service not installed or unavailable
-					return -2;
-				}
-				if (errStr) {
-					*errStr = error.name() + ": " + error.message();
-				}
-				else {
-					printf("[ERROR][tdehwlib] unMountDriveUDisks: %s\n", error.name().ascii()); fflush(stdout);
-				}
-				return -1;
+			if (!error.isValid()) {
+				// Success
+				result["retcode"] = 0;
+				result["result"] = true;
+				return result;
 			}
 			else {
-				return 0;
+				// Error!
+				if (error.name() == "org.freedesktop.DBus.Error.ServiceUnknown") {
+					return result;  // Service not installed or unavailable
+				}
+				else {
+					result["errStr"] = error.name() + ": " + error.message();
+					result["retcode"] = -1;
+					return result;
+				}
 			}
 		}
-		else {
-			return -2;
-		}
 	}
-	return -2;
+	return result;
 }
 
 //-------------------------------
 //  UDisks2
 //-------------------------------
-bool ejectDriveUDisks2(TDEStorageDevice* sdevice) {
+TDEStorageOpResult UDisks2EjectDrive(TDEStorageDevice *sdevice) {
+	TDEStorageOpResult result;
+	result["result"] = false;
+
 	TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
 	if (dbusConn.isConnected()) {
 		TQString blockDeviceString = sdevice->deviceNode();
@@ -162,56 +172,62 @@
 			TQT_DBusMessage reply = hardwareControl.sendWithReply("Get", params, &error);
 			if (error.isValid()) {
 				// Error!
-				printf("[ERROR][tdehwlib] ejectDriveUDisks2: %s\n", error.name().ascii()); fflush(stdout);
-				return false;
+				result["errStr"] = error.name() + ": " + error.message();
+				return result;
 			}
-			else {
+
+			if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
+				TQT_DBusObjectPath driveObjectPath = reply[0].toVariant().value.toObjectPath();
+				if (!driveObjectPath.isValid()) {
+					return result;
+				}
+				error = TQT_DBusError();
+				TQT_DBusProxy driveInformation("org.freedesktop.UDisks2", driveObjectPath,
+								"org.freedesktop.DBus.Properties", dbusConn);
+				// can eject?
+				TQValueList<TQT_DBusData> params;
+				params << TQT_DBusData::fromString("org.freedesktop.UDisks2.Drive") << TQT_DBusData::fromString("Ejectable");
+				TQT_DBusMessage reply = driveInformation.sendWithReply("Get", params, &error);
+				if (error.isValid()) {
+					// Error!
+					result["errStr"] = error.name() + ": " + error.message();
+					return result;
+				}
+
 				if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
-					TQT_DBusObjectPath driveObjectPath = reply[0].toVariant().value.toObjectPath();
-					if (!driveObjectPath.isValid()) {
-						return false;
+					bool ejectable = reply[0].toVariant().value.toBool();
+					if (!ejectable) {
+						result["errStr"] = i18n("Media not ejectable");
+						return result;
 					}
 
-					error = TQT_DBusError();
-					TQT_DBusProxy driveInformation("org.freedesktop.UDisks2", driveObjectPath, "org.freedesktop.DBus.Properties", dbusConn);
-					// can eject?
+					// Eject the drive!
+					TQT_DBusProxy driveControl("org.freedesktop.UDisks2", driveObjectPath, "org.freedesktop.UDisks2.Drive", dbusConn);
 					TQValueList<TQT_DBusData> params;
-					params << TQT_DBusData::fromString("org.freedesktop.UDisks2.Drive") << TQT_DBusData::fromString("Ejectable");
-					TQT_DBusMessage reply = driveInformation.sendWithReply("Get", params, &error);
+					TQT_DBusDataMap<TQString> options(TQT_DBusData::Variant);
+					params << TQT_DBusData::fromStringKeyMap(options);
+					TQT_DBusMessage reply = driveControl.sendWithReply("Eject", params, &error);
 					if (error.isValid()) {
 						// Error!
-						printf("[ERROR][tdehwlib] ejectDriveUDisks2: %s\n", error.name().ascii()); fflush(stdout);
-						return false;
+						result["errStr"] = error.name() + ": " + error.message();
+						return result;
 					}
-					if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
-						bool ejectable = reply[0].toVariant().value.toBool();
-						if (!ejectable) {
-							return false;
-						}
-
-						// Eject the drive!
-						TQT_DBusProxy driveControl("org.freedesktop.UDisks2", driveObjectPath, "org.freedesktop.UDisks2.Drive", dbusConn);
-						TQValueList<TQT_DBusData> params;
-						TQT_DBusDataMap<TQString> options(TQT_DBusData::Variant);
-						params << TQT_DBusData::fromStringKeyMap(options);
-						TQT_DBusMessage reply = driveControl.sendWithReply("Eject", params, &error);
-						if (error.isValid()) {
-							// Error!
-							printf("[ERROR][tdehwlib] ejectDriveUDisks2: %s\n", error.name().ascii()); fflush(stdout);
-							return false;
-						}
-						else {
-							return true;
-						}
+					else {
+						result["result"] = true;
+						return result;
 					}
 				}
 			}
** Diff limit reached (max: 250 lines) **
aaaf3780 2019-07-07 14:44:40 Michele Calgaro
Adjusted to use new TQStringVariantMap type.

Signed-off-by: Michele Calgaro <michele.calgaro@...>
M tdecore/kdcoppropertyproxy.cpp
M tdecore/tdehw/disksHelper.cpp
M tdecore/tdehw/disksHelper.h
M tdecore/tdehw/tdestoragedevice.cpp
M tdecore/tdehw/tdestoragedevice.h
M tdeio/tdeio/kservice.cpp
M tdeio/tdeio/kservice.h
M tdeio/tdeio/kservicetype.cpp
M tdeio/tdeio/kservicetype.h
M tdeprint/foomatic2loader.cpp
M tdeprint/foomatic2loader.h
M tdeprint/fooparser.cpp
M tdeprint/fooparser.y
M tdeprint/lpr/matichandler.cpp
M tdeprint/ppdloader.cpp
** Diff limit reached (max: 250 lines) **
2cc91245 2019-07-07 14:44:43 Michele Calgaro
Added TQStringVariantMap to dcop known types.

Signed-off-by: Michele Calgaro <michele.calgaro@...>
M dcop/dcoptypes.h
** Diff limit reached (max: 250 lines) **
95ee524a 2019-07-07 14:44:45 Michele Calgaro
Updated to latest mediamanager dcop interface.

Signed-off-by: Michele Calgaro <michele.calgaro@...>
M tdeioslave/file/file.cc
** Diff limit reached (max: 250 lines) **