summaryrefslogtreecommitdiffstats
path: root/tdecore
diff options
context:
space:
mode:
Diffstat (limited to 'tdecore')
-rw-r--r--tdecore/tdehw/networkbackends/network-manager/network-manager.cpp10
-rw-r--r--tdecore/tdehw/tdehardwaredevices.cpp14
-rw-r--r--tdecore/tdehw/tdestoragedevice.cpp166
3 files changed, 171 insertions, 19 deletions
diff --git a/tdecore/tdehw/networkbackends/network-manager/network-manager.cpp b/tdecore/tdehw/networkbackends/network-manager/network-manager.cpp
index af056de4b..2a0354105 100644
--- a/tdecore/tdehw/networkbackends/network-manager/network-manager.cpp
+++ b/tdecore/tdehw/networkbackends/network-manager/network-manager.cpp
@@ -47,6 +47,9 @@
// #define WAIT_FOR_OPERATION_BEFORE_RETURNING 1
#define USE_ASYNC_DBUS_CONNECTION_COMMAND_CALLS 1
+// Defined in tdehardwaredevices.cpp
+TQT_DBusData convertDBUSDataToVariantData(TQT_DBusData);
+
TQ_UINT32 reverseIPV4ByteOrder(TQ_UINT32 address) {
TQ_UINT32 ret;
unsigned char valuearray[4];
@@ -62,13 +65,6 @@ TQ_UINT32 reverseIPV4ByteOrder(TQ_UINT32 address) {
return ret;
}
-TQT_DBusData convertDBUSDataToVariantData(TQT_DBusData object) {
- TQT_DBusVariant variant;
- variant.value = object;
- variant.signature = variant.value.buildDBusSignature();
- return TQT_DBusData::fromVariant(variant);
-}
-
void printDBUSObjectStructure(TQT_DBusData object, int level=0, TQString mapKey=TQString::null) {
int i;
TQString levelIndent = "";
diff --git a/tdecore/tdehw/tdehardwaredevices.cpp b/tdecore/tdehw/tdehardwaredevices.cpp
index 7be686722..8038a3380 100644
--- a/tdecore/tdehw/tdehardwaredevices.cpp
+++ b/tdecore/tdehw/tdehardwaredevices.cpp
@@ -99,6 +99,20 @@ unsigned int reverse_bits(register unsigned int x)
#define BIT_IS_SET(bits, n) (bits[n >> 3] & (1 << (n & 0x7)))
+#if defined(WITH_UDISKS) || defined(WITH_UDISKS2) || defined(WITH_NETWORK_MANAGER_BACKEND)
+#include <tqdbusvariant.h>
+#include <tqdbusdata.h>
+// Convenience method for tdehwlib DBUS calls
+// FIXME
+// Should probably be part of dbus-1-tqt
+TQT_DBusData convertDBUSDataToVariantData(TQT_DBusData object) {
+ TQT_DBusVariant variant;
+ variant.value = object;
+ variant.signature = variant.value.buildDBusSignature();
+ return TQT_DBusData::fromVariant(variant);
+}
+#endif // defined(WITH_UDISKS) || defined(WITH_UDISKS2) || defined(WITH_NETWORK_MANAGER_BACKEND)
+
TDEHardwareDevices::TDEHardwareDevices() {
// Initialize members
pci_id_map = 0;
diff --git a/tdecore/tdehw/tdestoragedevice.cpp b/tdecore/tdehw/tdestoragedevice.cpp
index 8a0ae3f67..9a3897133 100644
--- a/tdecore/tdehw/tdestoragedevice.cpp
+++ b/tdecore/tdehw/tdestoragedevice.cpp
@@ -53,6 +53,11 @@
#include "tqdbusdatalist.h"
#endif // ddefined(WITH_UDISKS)
+#if defined(WITH_UDISKS) || defined(WITH_UDISKS2)
+ // Defined in tdehardwaredevices.cpp
+ TQT_DBusData convertDBUSDataToVariantData(TQT_DBusData);
+#endif // defined(WITH_UDISKS) || defined(WITH_UDISKS2)
+
TDEStorageDevice::TDEStorageDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn), m_mediaInserted(true) {
m_diskType = TDEDiskDeviceType::Null;
m_diskStatus = TDEDiskDeviceStatus::Null;
@@ -214,6 +219,10 @@ int mountDriveUDisks(TQString deviceNode, TQString fileSystemType, TQStringList
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();
}
@@ -234,6 +243,52 @@ int mountDriveUDisks(TQString deviceNode, TQString fileSystemType, TQStringList
return -2;
}
+int mountDriveUDisks2(TQString deviceNode, TQString fileSystemType, TQString mountOptions, TQString* errStr = NULL) {
+#ifdef WITH_UDISKS2
+ TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
+ if (dbusConn.isConnected()) {
+ TQString blockDeviceString = deviceNode;
+ blockDeviceString.replace("/dev/", "");
+ blockDeviceString = "/org/freedesktop/UDisks2/block_devices/" + blockDeviceString;
+
+ // Mount the drive!
+ TQT_DBusError error;
+ TQT_DBusProxy driveControl("org.freedesktop.UDisks2", blockDeviceString, "org.freedesktop.UDisks2.Filesystem", dbusConn);
+ if (driveControl.canSend()) {
+ TQValueList<TQT_DBusData> params;
+ TQMap<TQString, TQT_DBusData> optionsMap;
+ if (fileSystemType != "") {
+ optionsMap["fstype"] = convertDBUSDataToVariantData(TQT_DBusData::fromString(fileSystemType));
+ }
+ optionsMap["options"] = convertDBUSDataToVariantData(TQT_DBusData::fromString(mountOptions));
+ params << TQT_DBusData::fromStringKeyMap(TQT_DBusDataMap<TQString>(optionsMap));
+ TQT_DBusMessage reply = driveControl.sendWithReply("Mount", 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] mountDriveUDisks2: %s\n", error.name().ascii()); fflush(stdout);
+ }
+ return -1;
+ }
+ else {
+ return 0;
+ }
+ }
+ else {
+ return -2;
+ }
+ }
+#endif // WITH_UDISKS2
+ return -2;
+}
+
int unMountDriveUDisks(TQString deviceNode, TQStringList unMountOptions, TQString* errStr = NULL) {
#ifdef WITH_UDISKS
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
@@ -251,6 +306,10 @@ int unMountDriveUDisks(TQString deviceNode, TQStringList unMountOptions, TQStrin
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();
}
@@ -271,6 +330,49 @@ int unMountDriveUDisks(TQString deviceNode, TQStringList unMountOptions, TQStrin
return -2;
}
+int unMountDriveUDisks2(TQString deviceNode, TQString unMountOptions, TQString* errStr = NULL) {
+#ifdef WITH_UDISKS2
+ TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
+ if (dbusConn.isConnected()) {
+ TQString blockDeviceString = deviceNode;
+ blockDeviceString.replace("/dev/", "");
+ blockDeviceString = "/org/freedesktop/UDisks2/block_devices/" + blockDeviceString;
+
+ // Mount the drive!
+ TQT_DBusError error;
+ TQT_DBusProxy driveControl("org.freedesktop.UDisks2", blockDeviceString, "org.freedesktop.UDisks2.Filesystem", dbusConn);
+ if (driveControl.canSend()) {
+ TQValueList<TQT_DBusData> params;
+ TQMap<TQString, TQT_DBusData> optionsMap;
+ optionsMap["options"] = convertDBUSDataToVariantData(TQT_DBusData::fromString(unMountOptions));
+ params << TQT_DBusData::fromStringKeyMap(TQT_DBusDataMap<TQString>(optionsMap));
+ TQT_DBusMessage reply = driveControl.sendWithReply("Unmount", 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] unMountDriveUDisks2: %s\n", error.name().ascii()); fflush(stdout);
+ }
+ return -1;
+ }
+ else {
+ return 0;
+ }
+ }
+ else {
+ return -2;
+ }
+ }
+#endif // WITH_UDISKS2
+ return -2;
+}
+
bool TDEStorageDevice::ejectDrive() {
#ifdef WITH_UDISKS2
if (!(TDEGlobal::dirs()->findExe("udisksctl").isEmpty())) {
@@ -734,18 +836,36 @@ TQString TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageMountOption
#ifdef WITH_UDISKS2
if(command.isEmpty()) {
- // Use 'udisksctl' command (from UDISKS2), if available
- TQString udisksctlProg = TDEGlobal::dirs()->findExe("udisksctl");
- if (!udisksctlProg.isEmpty()) {
- if(!optionString.isEmpty()) {
- optionString.insert(0, "-o ");
- }
+ // Try to use UDISKS v2 via DBUS, if available
+ TQString errorString;
+ TQString fileSystemType;
- if (mountOptions.contains("filesystem") && !mountOptions["filesystem"].isEmpty()) {
- optionString.append(TQString(" -t %1").arg(mountOptions["filesystem"]));
+ if (mountOptions.contains("filesystem") && !mountOptions["filesystem"].isEmpty()) {
+ fileSystemType = mountOptions["filesystem"];
+ }
+
+ int uDisks2Ret = mountDriveUDisks2(devNode, fileSystemType, optionString, &errorString);
+ if (uDisks2Ret == 0) {
+ // Update internal mount data
+ TDEGlobal::hardwareDevices()->processModifiedMounts();
+
+ ret = mountPath();
+ return ret;
+ }
+ else if (uDisks2Ret == -1) {
+ if (errRet) {
+ *errRet = errorString;
}
- command = TQString("udisksctl mount -b '%1' %2 2>&1").arg(devNode).arg(optionString);
+ // Update internal mount data
+ TDEGlobal::hardwareDevices()->processModifiedMounts();
+
+ ret = mountPath();
+ return ret;
+ }
+ else {
+ // The UDISKS v2 DBUS service was either not available or was unusable; try another method...
+ command = TQString::null;
}
}
#endif // WITH_UDISKS2
@@ -944,13 +1064,35 @@ bool TDEStorageDevice::unmountDevice(TQString* errRet, int* retcode) {
TQString command;
#ifdef WITH_UDISKS2
- if(command.isEmpty() &&
- !(TDEGlobal::dirs()->findExe("udisksctl").isEmpty())) {
- command = TQString("udisksctl unmount -b '%1' 2>&1").arg(devNode);
+ if(command.isEmpty()) {
+ // Try to use UDISKS v2 via DBUS, if available
+ TQString errorString;
+ int unMountUDisks2Ret = unMountDriveUDisks2(devNode, TQString::null, &errorString);
+ if (unMountUDisks2Ret == 0) {
+ // Update internal mount data
+ TDEGlobal::hardwareDevices()->processModifiedMounts();
+
+ return true;
+ }
+ else if (unMountUDisks2Ret == -1) {
+ if (errRet) {
+ *errRet = errorString;
+ }
+
+ // Update internal mount data
+ TDEGlobal::hardwareDevices()->processModifiedMounts();
+
+ return false;
+ }
+ else {
+ // The UDISKS v2 DBUS service was either not available or was unusable; try another method...
+ command = TQString::null;
+ }
}
#endif // WITH_UDISKS2
#ifdef WITH_UDISKS
if(command.isEmpty()) {
+ // Try to use UDISKS v1 via DBUS, if available
TQString errorString;
int unMountUDisksRet = unMountDriveUDisks(devNode, TQStringList(), &errorString);
if (unMountUDisksRet == 0) {