summaryrefslogtreecommitdiffstats
path: root/tdecore/tdehw/disksHelper.cpp
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2019-05-30 23:28:23 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2019-07-07 23:44:28 +0900
commitbf683427937ea0cfd90749b833456377de6ffa10 (patch)
tree6b911cc13766cfb54dc6e8b0211e7138e64cba7b /tdecore/tdehw/disksHelper.cpp
parent7214a7b6b590d62aac622dbf2de31b1ca1ba78d5 (diff)
downloadtdelibs-bf683427937ea0cfd90749b833456377de6ffa10.tar.gz
tdelibs-bf683427937ea0cfd90749b833456377de6ffa10.zip
Reworked code for eject/mount/unmount operations to support new TDEStorageOpResult return type.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'tdecore/tdehw/disksHelper.cpp')
-rw-r--r--tdecore/tdehw/disksHelper.cpp228
1 files changed, 121 insertions, 107 deletions
diff --git a/tdecore/tdehw/disksHelper.cpp b/tdecore/tdehw/disksHelper.cpp
index e8e164b56..37efa25ac 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 @@ bool ejectDriveUDisks(TDEStorageDevice* sdevice) {
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 @@ int mountDriveUDisks(TQString deviceNode, TQString fileSystemType, TQStringList
params << TQT_DBusData::fromString(fileSystemType);
params << TQT_DBusData::fromList(TQT_DBusDataList(mountOptions));
TQT_DBusMessage reply = driveControl.sendWithReply("FilesystemMount", params, &error);
- if (error.isValid()) {
+ if (!error.isValid()) {
+ // Success
+ result["retcode"] = 0;
+ result["result"] = true;
+ return result;
+ }
+ else {
// Error!
if (error.name() == "org.freedesktop.DBus.Error.ServiceUnknown") {
- // Service not installed or unavailable
- return -2;
- }
- if (errStr) {
- *errStr = error.name() + ": " + error.message();
+ return result; // Service not installed or unavailable
}
else {
- printf("[ERROR][tdehwlib] mountDriveUDisks: %s\n", error.name().ascii()); fflush(stdout);
+ result["errStr"] = error.name() + ": " + error.message();
+ result["retcode"] = -1;
+ return result;
}
- return -1;
- }
- else {
- return 0;
}
}
- 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 @@ int unMountDriveUDisks(TQString deviceNode, TQStringList unMountOptions, TQStrin
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()) {
+ if (!error.isValid()) {
+ // Success
+ result["retcode"] = 0;
+ result["result"] = true;
+ return result;
+ }
+ else {
// Error!
if (error.name() == "org.freedesktop.DBus.Error.ServiceUnknown") {
- // Service not installed or unavailable
- return -2;
- }
- if (errStr) {
- *errStr = error.name() + ": " + error.message();
+ return result; // Service not installed or unavailable
}
else {
- printf("[ERROR][tdehwlib] unMountDriveUDisks: %s\n", error.name().ascii()); fflush(stdout);
+ result["errStr"] = error.name() + ": " + error.message();
+ result["retcode"] = -1;
+ return result;
}
- return -1;
- }
- else {
- return 0;
}
}
- 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 @@ bool ejectDriveUDisks2(TDEStorageDevice* sdevice) {
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;
}
}
}
}
}
- return false;
+ return result;
}
-int mountDriveUDisks2(TQString deviceNode, TQString fileSystemType, TQString mountOptions, TQString* errStr) {
+TDEStorageOpResult UDisks2MountDrive(TQString deviceNode, TQString fileSystemType, TQString mountOptions) {
+ TDEStorageOpResult result;
+ result["result"] = false;
+ result["retcode"] = -2;
+
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if (dbusConn.isConnected()) {
TQString blockDeviceString = deviceNode;
@@ -231,32 +247,33 @@ int mountDriveUDisks2(TQString deviceNode, TQString fileSystemType, TQString mou
optionsMap["options"] = (TQT_DBusData::fromString(mountOptions)).getAsVariantData();
params << TQT_DBusData::fromStringKeyMap(TQT_DBusDataMap<TQString>(optionsMap));
TQT_DBusMessage reply = driveControl.sendWithReply("Mount", params, &error);
- if (error.isValid()) {
+ if (!error.isValid()) {
+ // Success
+ result["retcode"] = 0;
+ result["result"] = true;
+ return result;
+ }
+ else {
// Error!
if (error.name() == "org.freedesktop.DBus.Error.ServiceUnknown") {
- // Service not installed or unavailable
- return -2;
- }
- if (errStr) {
- *errStr = error.name() + ": " + error.message();
+ return result; // Service not installed or unavailable
}
else {
- printf("[ERROR][tdehwlib] mountDriveUDisks2: %s\n", error.name().ascii()); fflush(stdout);
+ result["errStr"] = error.name() + ": " + error.message();
+ result["retcode"] = -1;
+ return result;
}
- return -1;
- }
- else {
- return 0;
}
}
- else {
- return -2;
- }
}
- return -2;
+ return result;
}
-int unMountDriveUDisks2(TQString deviceNode, TQString unMountOptions, TQString* errStr) {
+TDEStorageOpResult UDisks2UnmountDrive(TQString deviceNode, TQString unmountOptions) {
+ TDEStorageOpResult result;
+ result["result"] = false;
+ result["retcode"] = -2;
+
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if (dbusConn.isConnected()) {
TQString blockDeviceString = deviceNode;
@@ -270,32 +287,29 @@ int unMountDriveUDisks2(TQString deviceNode, TQString unMountOptions, TQString*
if (driveControl.canSend()) {
TQValueList<TQT_DBusData> params;
TQMap<TQString, TQT_DBusData> optionsMap;
- optionsMap["options"] = (TQT_DBusData::fromString(unMountOptions)).getAsVariantData();
+ optionsMap["options"] = (TQT_DBusData::fromString(unmountOptions)).getAsVariantData();
params << TQT_DBusData::fromStringKeyMap(TQT_DBusDataMap<TQString>(optionsMap));
TQT_DBusMessage reply = driveControl.sendWithReply("Unmount", params, &error);
- if (error.isValid()) {
+ if (!error.isValid()) {
+ // Success
+ result["retcode"] = 0;
+ result["result"] = true;
+ return result;
+ }
+ else {
// Error!
if (error.name() == "org.freedesktop.DBus.Error.ServiceUnknown") {
- // Service not installed or unavailable
- return -2;
- }
- if (errStr) {
- *errStr = error.name() + ": " + error.message();
+ return result; // Service not installed or unavailable
}
else {
- printf("[ERROR][tdehwlib] unMountDriveUDisks2: %s\n", error.name().ascii()); fflush(stdout);
+ result["errStr"] = error.name() + ": " + error.message();
+ result["retcode"] = -1;
+ return result;
}
- return -1;
}
- else {
- return 0;
- }
- }
- else {
- return -2;
}
}
- return -2;
+ return result;
}