summaryrefslogtreecommitdiffstats
path: root/tdecore/tdehw
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2019-07-07 22:21:21 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2019-07-07 22:40:46 +0900
commit7214a7b6b590d62aac622dbf2de31b1ca1ba78d5 (patch)
treee63d5e40e1a2d4d4a8efb0990ebff10dcf163617 /tdecore/tdehw
parentc76553c4fb3ee8f839c17b4dc3c3beb3c4338eb3 (diff)
downloadtdelibs-7214a7b6b590d62aac622dbf2de31b1ca1ba78d5.tar.gz
tdelibs-7214a7b6b590d62aac622dbf2de31b1ca1ba78d5.zip
tdehw: code restructuring for tdestoragedevice.
1. added disk helper source files 2. removed WITH_UDISKS2, WITH_UDISK, WITH_UDEVIL defines. The respective code is always included 3. order of execution for mount/umount activities: udisks2, udisk, udevil, pmount. Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'tdecore/tdehw')
-rw-r--r--tdecore/tdehw/CMakeLists.txt25
-rw-r--r--tdecore/tdehw/disksHelper.cpp301
-rw-r--r--tdecore/tdehw/disksHelper.h36
-rw-r--r--tdecore/tdehw/tdestoragedevice.cpp563
4 files changed, 442 insertions, 483 deletions
diff --git a/tdecore/tdehw/CMakeLists.txt b/tdecore/tdehw/CMakeLists.txt
index 02b775931..9495b3717 100644
--- a/tdecore/tdehw/CMakeLists.txt
+++ b/tdecore/tdehw/CMakeLists.txt
@@ -17,13 +17,6 @@ if( NOT DBUS_SYSTEM_BUS )
set( DBUS_SYSTEM_BUS "unix:path=/var/run/dbus/system_bus_socket" CACHE INTERNAL "" FORCE )
endif()
-if( WITH_TDEHWLIB_DAEMONS OR WITH_HAL OR WITH_DEVKITPOWER OR WITH_UPOWER OR WITH_UDISKS OR WITH_UDISKS2 OR
- WITH_NETWORK_MANAGER_BACKEND OR WITH_CONSOLEKIT )
- list( APPEND TDEHW_CUSTOM_INCLUDE_DIRS ${DBUS_TQT_INCLUDE_DIRS} )
- list( APPEND TDEHW_CUSTOM_LIBRARY_DIRS ${DBUS_TQT_LIBRARY_DIRS} )
- list( APPEND TDEHW_CUSTOM_LIBRARIES ${DBUS_TQT_LIBRARIES} )
-endif( )
-
if( WITH_TDEHWLIB_DAEMONS )
add_definitions( -DWITH_TDEHWLIB_DAEMONS )
endif( )
@@ -44,18 +37,6 @@ if( WITH_UPOWER )
add_definitions( -DWITH_UPOWER )
endif( )
-if( WITH_UDISKS )
- add_definitions( -DWITH_UDISKS )
-endif( )
-
-if( WITH_UDISKS2 )
- add_definitions( -DWITH_UDISKS2 )
-endif( )
-
-if( WITH_UDEVIL )
- add_definitions( -DWITH_UDEVIL )
-endif( )
-
if( WITH_CONSOLEKIT )
add_definitions( -DWITH_CONSOLEKIT )
endif( )
@@ -92,14 +73,17 @@ include_directories(
${CMAKE_SOURCE_DIR}/tdecore
${CMAKE_SOURCE_DIR}/dcop
${CMAKE_BINARY_DIR}/tdeio/kssl
+ ${DBUS_TQT_INCLUDE_DIRS}
${TDEHW_CUSTOM_INCLUDE_DIRS}
)
link_directories(
${TQT_LIBRARY_DIRS}
+ ${DBUS_TQT_LIBRARY_DIRS}
${TDEHW_CUSTOM_LIBRARY_DIRS}
)
+
##### headers ###################################
install( FILES tdehardwaredevices.h tdenetworkconnections.h tdegenericdevice.h
@@ -120,10 +104,11 @@ set( ${target}_SRCS
tdemainspowerdevice.cpp tdenetworkdevice.cpp tdebacklightdevice.cpp
tdemonitordevice.cpp tdesensordevice.cpp tderootsystemdevice.cpp
tdeeventdevice.cpp tdeinputdevice.cpp tdecryptographiccarddevice.cpp
+ disksHelper.cpp
)
tde_add_library( ${target} STATIC_PIC AUTOMOC
SOURCES ${${target}_SRCS}
- LINK udev ${TDENM_LIBRARIES} ${TDEUPOWER_LIBRARIES}
+ LINK udev ${TDENM_LIBRARIES} ${TDEUPOWER_LIBRARIES} ${DBUS_TQT_LIBRARIES}
${TDEHW_CUSTOM_LIBRARIES}
)
diff --git a/tdecore/tdehw/disksHelper.cpp b/tdecore/tdehw/disksHelper.cpp
new file mode 100644
index 000000000..e8e164b56
--- /dev/null
+++ b/tdecore/tdehw/disksHelper.cpp
@@ -0,0 +1,301 @@
+/* This file is part of the TDE libraries
+ Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
+ (C) 2013 Golubev Alexander <fatzer2@gmail.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "disksHelper.h"
+#include "tdestoragedevice.h"
+
+#include <tqdbusdata.h>
+#include <tqdbusmessage.h>
+#include <tqdbusproxy.h>
+#include <tqdbusvariant.h>
+#include <tqdbusconnection.h>
+#include <tqdbuserror.h>
+#include <tqdbusdatamap.h>
+#include <tqdbusobjectpath.h>
+#include "tqdbusdatalist.h"
+
+//-------------------------------
+// UDisks
+//-------------------------------
+bool ejectDriveUDisks(TDEStorageDevice* sdevice) {
+ TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
+ if (dbusConn.isConnected()) {
+ TQString blockDeviceString = sdevice->deviceNode();
+ blockDeviceString.replace("/dev/", "");
+ blockDeviceString.replace("-", "_2d");
+ blockDeviceString = "/org/freedesktop/UDisks/devices/" + blockDeviceString;
+
+ // Eject the drive!
+ TQT_DBusError error;
+ TQT_DBusProxy driveControl("org.freedesktop.UDisks", blockDeviceString, "org.freedesktop.UDisks.Device", dbusConn);
+ if (driveControl.canSend()) {
+ TQValueList<TQT_DBusData> params;
+ TQT_DBusDataList options;
+ params << TQT_DBusData::fromList(options);
+ 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;
+ }
+ else {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+int mountDriveUDisks(TQString deviceNode, TQString fileSystemType, TQStringList mountOptions, TQString* errStr) {
+ TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
+ if (dbusConn.isConnected()) {
+ TQString blockDeviceString = deviceNode;
+ blockDeviceString.replace("/dev/", "");
+ blockDeviceString.replace("-", "_2d");
+ blockDeviceString = "/org/freedesktop/UDisks/devices/" + blockDeviceString;
+
+ // Mount the drive!
+ TQT_DBusError error;
+ TQT_DBusProxy driveControl("org.freedesktop.UDisks", blockDeviceString, "org.freedesktop.UDisks.Device", dbusConn);
+ if (driveControl.canSend()) {
+ TQValueList<TQT_DBusData> params;
+ 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;
+ }
+ else {
+ return 0;
+ }
+ }
+ else {
+ return -2;
+ }
+ }
+ return -2;
+}
+
+int unMountDriveUDisks(TQString deviceNode, TQStringList unMountOptions, TQString* errStr) {
+ TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
+ if (dbusConn.isConnected()) {
+ TQString blockDeviceString = deviceNode;
+ blockDeviceString.replace("/dev/", "");
+ blockDeviceString.replace("-", "_2d");
+ blockDeviceString = "/org/freedesktop/UDisks/devices/" + blockDeviceString;
+
+ // Mount the drive!
+ TQT_DBusError error;
+ 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));
+ 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;
+ }
+ else {
+ return 0;
+ }
+ }
+ else {
+ return -2;
+ }
+ }
+ return -2;
+}
+
+//-------------------------------
+// UDisks2
+//-------------------------------
+bool ejectDriveUDisks2(TDEStorageDevice* sdevice) {
+ TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
+ if (dbusConn.isConnected()) {
+ TQString blockDeviceString = sdevice->deviceNode();
+ blockDeviceString.replace("/dev/", "");
+ blockDeviceString.replace("-", "_2d");
+ blockDeviceString = "/org/freedesktop/UDisks2/block_devices/" + blockDeviceString;
+ TQT_DBusProxy hardwareControl("org.freedesktop.UDisks2", blockDeviceString, "org.freedesktop.DBus.Properties", dbusConn);
+ if (hardwareControl.canSend()) {
+ // get associated udisks2 drive path
+ TQT_DBusError error;
+ TQValueList<TQT_DBusData> params;
+ params << TQT_DBusData::fromString("org.freedesktop.UDisks2.Block") << TQT_DBusData::fromString("Drive");
+ 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;
+ }
+ else {
+ if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
+ TQT_DBusObjectPath driveObjectPath = reply[0].toVariant().value.toObjectPath();
+ if (!driveObjectPath.isValid()) {
+ return false;
+ }
+
+ 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!
+ printf("[ERROR][tdehwlib] ejectDriveUDisks2: %s\n", error.name().ascii()); fflush(stdout);
+ return false;
+ }
+ 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;
+ }
+ }
+ }
+ }
+ }
+ }
+ return false;
+}
+
+int mountDriveUDisks2(TQString deviceNode, TQString fileSystemType, TQString mountOptions, TQString* errStr) {
+ TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
+ if (dbusConn.isConnected()) {
+ TQString blockDeviceString = deviceNode;
+ blockDeviceString.replace("/dev/", "");
+ blockDeviceString.replace("-", "_2d");
+ 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"] = (TQT_DBusData::fromString(fileSystemType)).getAsVariantData();
+ }
+ 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()) {
+ // 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;
+ }
+ }
+ return -2;
+}
+
+int unMountDriveUDisks2(TQString deviceNode, TQString unMountOptions, TQString* errStr) {
+ TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
+ if (dbusConn.isConnected()) {
+ TQString blockDeviceString = deviceNode;
+ blockDeviceString.replace("/dev/", "");
+ blockDeviceString.replace("-", "_2d");
+ 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"] = (TQT_DBusData::fromString(unMountOptions)).getAsVariantData();
+ 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;
+ }
+ }
+ return -2;
+}
+
+
diff --git a/tdecore/tdehw/disksHelper.h b/tdecore/tdehw/disksHelper.h
new file mode 100644
index 000000000..def540f34
--- /dev/null
+++ b/tdecore/tdehw/disksHelper.h
@@ -0,0 +1,36 @@
+/* This file is part of the TDE libraries
+ Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
+ (C) 2013 Golubev Alexander <fatzer2@gmail.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef _DISKS_HELPER_H
+#define _DISKS_HELPER_H
+
+#include <stdlib.h>
+
+class TDEStorageDevice;
+class TQString;
+class TQStringList;
+
+bool ejectDriveUDisks(TDEStorageDevice* sdevice);
+bool ejectDriveUDisks2(TDEStorageDevice* sdevice);
+int mountDriveUDisks(TQString deviceNode, TQString fileSystemType, TQStringList mountOptions, TQString* errStr = NULL);
+int mountDriveUDisks2(TQString deviceNode, TQString fileSystemType, TQString mountOptions, TQString* errStr = NULL);
+int unMountDriveUDisks(TQString deviceNode, TQStringList unMountOptions, TQString* errStr = NULL);
+int unMountDriveUDisks2(TQString deviceNode, TQString unMountOptions, TQString* errStr = NULL);
+
+#endif
diff --git a/tdecore/tdehw/tdestoragedevice.cpp b/tdecore/tdehw/tdestoragedevice.cpp
index 71f852e0b..bf2ca2fd4 100644
--- a/tdecore/tdehw/tdestoragedevice.cpp
+++ b/tdecore/tdehw/tdestoragedevice.cpp
@@ -35,8 +35,8 @@
#include "kiconloader.h"
#include "tdetempfile.h"
#include "kstandarddirs.h"
-
#include "tdehardwaredevices.h"
+#include "disksHelper.h"
#include "config.h"
@@ -55,21 +55,6 @@
#endif
#endif
-// uDisks2 integration
-#if defined(WITH_UDISKS) || defined(WITH_UDISKS2)
- #include <tqdbusdata.h>
- #include <tqdbusmessage.h>
- #include <tqdbusproxy.h>
- #include <tqdbusvariant.h>
- #include <tqdbusconnection.h>
- #include <tqdbuserror.h>
- #include <tqdbusdatamap.h>
- #include <tqdbusobjectpath.h>
-#endif // defined(WITH_UDISKS) || defined(WITH_UDISKS2)
-#if defined(WITH_UDISKS)
- #include "tqdbusdatalist.h"
-#endif // ddefined(WITH_UDISKS)
-
TDEStorageDevice::TDEStorageDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn), m_mediaInserted(true), m_cryptDevice(NULL) {
m_diskType = TDEDiskDeviceType::Null;
m_diskStatus = TDEDiskDeviceStatus::Null;
@@ -322,282 +307,7 @@ bool TDEStorageDevice::lockDriveMedia(bool lock) {
}
}
-bool ejectDriveUDisks(TDEStorageDevice* sdevice) {
-#ifdef WITH_UDISKS
- TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
- if (dbusConn.isConnected()) {
- TQString blockDeviceString = sdevice->deviceNode();
- blockDeviceString.replace("/dev/", "");
- blockDeviceString.replace("-", "_2d");
- blockDeviceString = "/org/freedesktop/UDisks/devices/" + blockDeviceString;
-
- // Eject the drive!
- TQT_DBusError error;
- TQT_DBusProxy driveControl("org.freedesktop.UDisks", blockDeviceString, "org.freedesktop.UDisks.Device", dbusConn);
- if (driveControl.canSend()) {
- TQValueList<TQT_DBusData> params;
- TQT_DBusDataList options;
- params << TQT_DBusData::fromList(options);
- 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;
- }
- else {
- return true;
- }
- }
- }
-#endif // WITH_UDISKS
- return false;
-}
-
-bool ejectDriveUDisks2(TDEStorageDevice* sdevice) {
-#ifdef WITH_UDISKS2
- TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
- if (dbusConn.isConnected()) {
- TQString blockDeviceString = sdevice->deviceNode();
- blockDeviceString.replace("/dev/", "");
- blockDeviceString.replace("-", "_2d");
- blockDeviceString = "/org/freedesktop/UDisks2/block_devices/" + blockDeviceString;
- TQT_DBusProxy hardwareControl("org.freedesktop.UDisks2", blockDeviceString, "org.freedesktop.DBus.Properties", dbusConn);
- if (hardwareControl.canSend()) {
- // get associated udisks2 drive path
- TQT_DBusError error;
- TQValueList<TQT_DBusData> params;
- params << TQT_DBusData::fromString("org.freedesktop.UDisks2.Block") << TQT_DBusData::fromString("Drive");
- 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;
- }
- else {
- if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
- TQT_DBusObjectPath driveObjectPath = reply[0].toVariant().value.toObjectPath();
- if (!driveObjectPath.isValid()) {
- return false;
- }
-
- 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!
- printf("[ERROR][tdehwlib] ejectDriveUDisks2: %s\n", error.name().ascii()); fflush(stdout);
- return false;
- }
- 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;
- }
- }
- }
- }
- }
- }
-#endif // WITH_UDISKS2
- return false;
-}
-
-int mountDriveUDisks(TQString deviceNode, TQString fileSystemType, TQStringList mountOptions, TQString* errStr = NULL) {
-#ifdef WITH_UDISKS
- TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
- if (dbusConn.isConnected()) {
- TQString blockDeviceString = deviceNode;
- blockDeviceString.replace("/dev/", "");
- blockDeviceString.replace("-", "_2d");
- blockDeviceString = "/org/freedesktop/UDisks/devices/" + blockDeviceString;
-
- // Mount the drive!
- TQT_DBusError error;
- TQT_DBusProxy driveControl("org.freedesktop.UDisks", blockDeviceString, "org.freedesktop.UDisks.Device", dbusConn);
- if (driveControl.canSend()) {
- TQValueList<TQT_DBusData> params;
- 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;
- }
- else {
- return 0;
- }
- }
- else {
- return -2;
- }
- }
-#endif // WITH_UDISKS
- 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.replace("-", "_2d");
- 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"] = (TQT_DBusData::fromString(fileSystemType)).getAsVariantData();
- }
- 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()) {
- // 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);
- if (dbusConn.isConnected()) {
- TQString blockDeviceString = deviceNode;
- blockDeviceString.replace("/dev/", "");
- blockDeviceString.replace("-", "_2d");
- blockDeviceString = "/org/freedesktop/UDisks/devices/" + blockDeviceString;
-
- // Mount the drive!
- TQT_DBusError error;
- 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));
- 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;
- }
- else {
- return 0;
- }
- }
- else {
- return -2;
- }
- }
-#endif // WITH_UDISKS
- 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.replace("-", "_2d");
- 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"] = (TQT_DBusData::fromString(unMountOptions)).getAsVariantData();
- 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())) {
if (ejectDriveUDisks2(this)) {
return true;
@@ -607,9 +317,6 @@ bool TDEStorageDevice::ejectDrive() {
fflush(stdout);
}
}
-#endif // WITH_UDISKS2
-
-#ifdef WITH_UDISKS
if (!(TDEGlobal::dirs()->findExe("udisks").isEmpty())) {
if (ejectDriveUDisks(this)) {
return true;
@@ -619,7 +326,6 @@ bool TDEStorageDevice::ejectDrive() {
fflush(stdout);
}
}
-#endif // WITH_UDISKS
if (!(TDEGlobal::dirs()->findExe("eject").isEmpty())) {
TQString command = TQString("eject -v '%1' 2>&1").arg(deviceNode());
@@ -994,24 +700,20 @@ TQString TDEStorageDevice::mountPath() {
}
TQString TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageMountOptions mountOptions, TQString* errRet, int* retcode) {
+ // Device is already mounted
+ if (!mountPath().isNull()) {
+ return mountPath();
+ }
+
int internal_retcode;
if (!retcode) {
retcode = &internal_retcode;
}
- TQString ret = mountPath();
-
- // Device is already mounted
- if (!ret.isNull()) {
- return ret;
- }
-
- TQString command;
TQString devNode = deviceNode();
devNode.replace("'", "'\\''");
mediaName.replace("'", "'\\''");
-#if defined(WITH_UDEVIL) || defined(WITH_UDISKS2) || defined(WITH_UDISKS)
// Prepare filesystem options for mount
TQStringList udisksOptions;
TQString optionString;
@@ -1068,109 +770,70 @@ TQString TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageMountOption
if (!optionString.isEmpty()) {
optionString.remove(0, 1);
}
-#endif // defined(WITH_UDEVIL) || defined(WITH_UDISKS2) || defined(WITH_UDISKS)
-
-#ifdef WITH_UDEVIL
- if(command.isEmpty()) {
- // Use 'udevil' command, if available
- TQString udevilProg = TDEGlobal::dirs()->findExe("udevil");
- if (!udevilProg.isEmpty()) {
-
- TQString fileSystemType;
- if (mountOptions.contains("filesystem") && !mountOptions["filesystem"].isEmpty()) {
- fileSystemType = TQString("-t %1").arg(mountOptions["filesystem"]);
- }
- TQString mountpoint;
- if (mountOptions.contains("mountpoint")
- && !mountOptions["mountpoint"].isEmpty()
- && (mountOptions["mountpoint"] != "/media/")) {
- mountpoint = mountOptions["mountpoint"];
- mountpoint.replace("'", "'\\''");
- }
- else {
- mountpoint = TQString("/media/%1").arg(mediaName);
- }
+ // Try to use UDISKS v2 via DBUS, if available
+ TQString errorString;
+ TQString fileSystemType;
- command = TQString("udevil mount %1 -o '%2' '%3' '%4' 2>&1").arg(fileSystemType).arg(optionString).arg(devNode).arg(mountpoint);
- }
+ if (mountOptions.contains("filesystem") && !mountOptions["filesystem"].isEmpty()) {
+ fileSystemType = mountOptions["filesystem"];
}
-#endif // WITH_UDEVIL
-
-#ifdef WITH_UDISKS2
- if(command.isEmpty()) {
- // Try to use UDISKS v2 via DBUS, if available
- TQString errorString;
- TQString fileSystemType;
- 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;
+ int uDisks2Ret = mountDriveUDisks2(devNode, fileSystemType, optionString, &errorString);
+ if (uDisks2Ret == 0) {
+ // Update internal mount data
+ TDEGlobal::hardwareDevices()->processModifiedMounts();
+ return mountPath();
+ }
+ else if (uDisks2Ret == -1) {
+ if (errRet) {
+ *errRet = errorString;
}
- else if (uDisks2Ret == -1) {
- if (errRet) {
- *errRet = errorString;
- }
-
- // Update internal mount data
- TDEGlobal::hardwareDevices()->processModifiedMounts();
+ // Update internal mount data
+ TDEGlobal::hardwareDevices()->processModifiedMounts();
+ return mountPath();
+ }
- ret = mountPath();
- return ret;
- }
- else {
- // The UDISKS v2 DBUS service was either not available or was unusable; try another method...
- command = TQString::null;
+ // The UDISKS v2 DBUS service was either not available or was unusable
+ // Try to use UDISKS v1 via DBUS, if available
+ int uDisksRet = mountDriveUDisks(devNode, fileSystemType, udisksOptions, &errorString);
+ if (uDisksRet == 0) {
+ // Update internal mount data
+ TDEGlobal::hardwareDevices()->processModifiedMounts();
+ return mountPath();
+ }
+ else if (uDisksRet == -1) {
+ if (errRet) {
+ *errRet = errorString;
}
+ // Update internal mount data
+ TDEGlobal::hardwareDevices()->processModifiedMounts();
+ return mountPath();
}
-#endif // WITH_UDISKS2
-
-#ifdef WITH_UDISKS
- if(command.isEmpty()) {
- // Try to use UDISKS v1 via DBUS, if available
- TQString errorString;
- TQString fileSystemType;
+ // The UDISKS v1 DBUS service was either not available or was unusable
+ // Use 'udevil' command, if available
+ TQString command = TQString::null;
+ TQString udevilProg = TDEGlobal::dirs()->findExe("udevil");
+ if (!udevilProg.isEmpty()) {
if (mountOptions.contains("filesystem") && !mountOptions["filesystem"].isEmpty()) {
- fileSystemType = mountOptions["filesystem"];
+ fileSystemType = TQString("-t %1").arg(mountOptions["filesystem"]);
}
-
- int uDisksRet = mountDriveUDisks(devNode, fileSystemType, udisksOptions, &errorString);
- if (uDisksRet == 0) {
- // Update internal mount data
- TDEGlobal::hardwareDevices()->processModifiedMounts();
-
- ret = mountPath();
- return ret;
- }
- else if (uDisksRet == -1) {
- if (errRet) {
- *errRet = errorString;
- }
-
- // Update internal mount data
- TDEGlobal::hardwareDevices()->processModifiedMounts();
-
- ret = mountPath();
- return ret;
+ TQString mountpoint;
+ if (mountOptions.contains("mountpoint") && !mountOptions["mountpoint"].isEmpty() &&
+ (mountOptions["mountpoint"] != "/media/")) {
+ mountpoint = mountOptions["mountpoint"];
+ mountpoint.replace("'", "'\\''");
}
else {
- // The UDISKS v1 DBUS service was either not available or was unusable; try another method...
- command = TQString::null;
+ mountpoint = TQString("/media/%1").arg(mediaName);
}
+ command = TQString("udevil mount %1 -o '%2' '%3' '%4' 2>&1")
+ .arg(fileSystemType).arg(optionString).arg(devNode).arg(mountpoint);
}
-#endif // WITH_UDISKS
+ // If 'udevil' was not found, use 'pmount' command if available
if(command.isEmpty()) {
- // Use 'pmount' command, if available
TQString pmountProg = TDEGlobal::dirs()->findExe("pmount");
if (!pmountProg.isEmpty()) {
// Create dummy password file
@@ -1203,9 +866,8 @@ TQString TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageMountOption
}
TQString mountpoint;
- if (mountOptions.contains("mountpoint")
- && !mountOptions["mountpoint"].isEmpty()
- && (mountOptions["mountpoint"] != "/media/")) {
+ if (mountOptions.contains("mountpoint") && !mountOptions["mountpoint"].isEmpty() &&
+ (mountOptions["mountpoint"] != "/media/")) {
mountpoint = mountOptions["mountpoint"];
mountpoint.replace("'", "'\\''");
}
@@ -1216,7 +878,8 @@ TQString TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageMountOption
TQString passFileName = passwordFile.name();
passFileName.replace("'", "'\\''");
- command = TQString("pmount -p '%1' %2 '%3' '%4' 2>&1").arg(passFileName).arg(optionString).arg(devNode).arg(mountpoint);
+ command = TQString("pmount -p '%1' %2 '%3' '%4' 2>&1")
+ .arg(passFileName).arg(optionString).arg(devNode).arg(mountpoint);
}
}
@@ -1224,7 +887,7 @@ TQString TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageMountOption
if (errRet) {
*errRet = i18n("No supported mounting methods were detected on your system");
}
- return ret;
+ return mountPath();
}
FILE *exepipe = popen(command.local8Bit(), "r");
@@ -1241,10 +904,7 @@ TQString TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageMountOption
// Update internal mount data
TDEGlobal::hardwareDevices()->processModifiedMounts();
-
- ret = mountPath();
-
- return ret;
+ return mountPath();
}
TQString TDEStorageDevice::mountEncryptedDevice(TQString passphrase, TQString mediaName, TDEStorageMountOptions mountOptions, TQString* errRet, int* retcode) {
@@ -1274,15 +934,15 @@ TQString TDEStorageDevice::mountEncryptedDevice(TQString passphrase, TQString me
if (mountOptions["ro"] == "true") {
optionString.append(" -r");
}
-
+
if (mountOptions["atime"] != "true") {
optionString.append(" -A");
}
-
+
if (mountOptions["utf8"] == "true") {
optionString.append(" -c utf8");
}
-
+
if (mountOptions["sync"] == "true") {
optionString.append(" -s");
}
@@ -1323,6 +983,10 @@ TQString TDEStorageDevice::mountEncryptedDevice(TQString passphrase, TQString me
}
bool TDEStorageDevice::unmountDevice(TQString* errRet, int* retcode) {
+ if (mountPath().isNull()) {
+ return true;
+ }
+
int internal_retcode;
if (!retcode) {
retcode = &internal_retcode;
@@ -1331,77 +995,50 @@ bool TDEStorageDevice::unmountDevice(TQString* errRet, int* retcode) {
TQString mountpoint = mountPath();
TQString devNode = deviceNode();
- if (mountpoint.isNull()) {
- return true;
- }
-
mountpoint.replace("'", "'\\''");
- TQString command;
-
-#ifdef WITH_UDEVIL
- if(command.isEmpty() &&
- !(TDEGlobal::dirs()->findExe("udevil").isEmpty())) {
- command = TQString("udevil umount '%1' 2>&1").arg(mountpoint);
+ // 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;
}
-#endif // WITH_UDEVIL
-
-#ifdef WITH_UDISKS2
- 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;
+ else if (unMountUDisks2Ret == -1) {
+ if (errRet) {
+ *errRet = errorString;
}
+ // Update internal mount data
+ TDEGlobal::hardwareDevices()->processModifiedMounts();
+ return false;
}
-#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) {
- // Update internal mount data
- TDEGlobal::hardwareDevices()->processModifiedMounts();
- return true;
+ // The UDISKS v2 DBUS service was either not available or was unusable
+ // Try to use UDISKS v1 via DBUS, if available
+ int unMountUDisksRet = unMountDriveUDisks(devNode, TQStringList(), &errorString);
+ if (unMountUDisksRet == 0) {
+ // Update internal mount data
+ TDEGlobal::hardwareDevices()->processModifiedMounts();
+ return true;
+ }
+ else if (unMountUDisksRet == -1) {
+ if (errRet) {
+ *errRet = errorString;
}
- else if (unMountUDisksRet == -1) {
- if (errRet) {
- *errRet = errorString;
- }
-
- // Update internal mount data
- TDEGlobal::hardwareDevices()->processModifiedMounts();
+ // Update internal mount data
+ TDEGlobal::hardwareDevices()->processModifiedMounts();
+ return false;
+ }
- return false;
- }
- else {
- // The UDISKS v1 DBUS service was either not available or was unusable; try another method...
- command = TQString::null;
- }
+ // The UDISKS v1 DBUS service was either not available or was unusable
+ // Try to use udevil, if available
+ TQString command;
+ if(!(TDEGlobal::dirs()->findExe("udevil").isEmpty())) {
+ command = TQString("udevil umount '%1' 2>&1").arg(mountpoint);
}
-#endif // WITH_UDISKS
+ // If 'udevil' was not found, use 'pmount' command if available
if(command.isEmpty() &&
!(TDEGlobal::dirs()->findExe("pumount").isEmpty())) {
command = TQString("pumount '%1' 2>&1").arg(mountpoint);