summaryrefslogtreecommitdiffstats
path: root/tdecore/tdehw/tdestoragedevice.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tdecore/tdehw/tdestoragedevice.cpp')
-rw-r--r--tdecore/tdehw/tdestoragedevice.cpp231
1 files changed, 110 insertions, 121 deletions
diff --git a/tdecore/tdehw/tdestoragedevice.cpp b/tdecore/tdehw/tdestoragedevice.cpp
index bf2ca2fd4..c21f54606 100644
--- a/tdecore/tdehw/tdestoragedevice.cpp
+++ b/tdecore/tdehw/tdestoragedevice.cpp
@@ -28,6 +28,7 @@
#include <tqregexp.h>
#include <tqpixmap.h>
#include <tqfile.h>
+#include <tqvariant.h>
#include "kdebug.h"
#include "tdelocale.h"
@@ -309,7 +310,8 @@ bool TDEStorageDevice::lockDriveMedia(bool lock) {
bool TDEStorageDevice::ejectDrive() {
if (!(TDEGlobal::dirs()->findExe("udisksctl").isEmpty())) {
- if (ejectDriveUDisks2(this)) {
+ TDEStorageOpResult ejectResult = UDisks2EjectDrive(this);
+ if (ejectResult["result"].toBool()) {
return true;
}
else {
@@ -318,7 +320,8 @@ bool TDEStorageDevice::ejectDrive() {
}
}
if (!(TDEGlobal::dirs()->findExe("udisks").isEmpty())) {
- if (ejectDriveUDisks(this)) {
+ TDEStorageOpResult ejectResult = UDisksEjectDrive(this);
+ if (ejectResult["result"].toBool()) {
return true;
}
else {
@@ -699,15 +702,15 @@ TQString TDEStorageDevice::mountPath() {
return TQString::null;
}
-TQString TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageMountOptions mountOptions, TQString* errRet, int* retcode) {
- // Device is already mounted
- if (!mountPath().isNull()) {
- return mountPath();
- }
+TDEStorageOpResult TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageMountOptions mountOptions) {
+ TDEStorageOpResult result;
- int internal_retcode;
- if (!retcode) {
- retcode = &internal_retcode;
+ // Check if device is already mounted
+ TQString mountpath = mountPath();
+ if (!mountpath.isEmpty()) {
+ result["mountPath"] = mountpath;
+ result["result"] = true;
+ return result;
}
TQString devNode = deviceNode();
@@ -716,8 +719,6 @@ TQString TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageMountOption
// Prepare filesystem options for mount
TQStringList udisksOptions;
- TQString optionString;
-
if (mountOptions["ro"] == "true") {
udisksOptions.append("ro");
}
@@ -730,38 +731,34 @@ TQString TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageMountOption
udisksOptions.append("sync");
}
- if( (mountOptions["filesystem"] == "fat")
- || (mountOptions["filesystem"] == "vfat")
- || (mountOptions["filesystem"] == "msdos")
- || (mountOptions["filesystem"] == "umsdos")
- ) {
+ if ((mountOptions["filesystem"] == "fat") || (mountOptions["filesystem"] == "vfat") ||
+ (mountOptions["filesystem"] == "msdos") || (mountOptions["filesystem"] == "umsdos")) {
if (mountOptions.contains("shortname")) {
udisksOptions.append(TQString("shortname=%1").arg(mountOptions["shortname"]));
}
}
- if( (mountOptions["filesystem"] == "jfs")) {
+ if ((mountOptions["filesystem"] == "jfs")) {
if (mountOptions["utf8"] == "true") {
// udisks/udisks2 for now does not support option iocharset= for jfs
// udisksOptions.append("iocharset=utf8");
}
}
- if( (mountOptions["filesystem"] == "ntfs-3g") ) {
+ if ((mountOptions["filesystem"] == "ntfs-3g")) {
if (mountOptions.contains("locale")) {
udisksOptions.append(TQString("locale=%1").arg(mountOptions["locale"]));
}
}
- if( (mountOptions["filesystem"] == "ext3")
- || (mountOptions["filesystem"] == "ext4")
- ) {
+ if ((mountOptions["filesystem"] == "ext3") || (mountOptions["filesystem"] == "ext4")) {
if (mountOptions.contains("journaling")) {
// udisks/udisks2 for now does not support option data= for ext3/ext4
// udisksOptions.append(TQString("data=%1").arg(mountOptions["journaling"]));
}
}
+ TQString optionString;
for (TQStringList::Iterator it = udisksOptions.begin(); it != udisksOptions.end(); ++it) {
optionString.append(",");
optionString.append(*it);
@@ -772,50 +769,49 @@ TQString TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageMountOption
}
// 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) {
+ TDEStorageOpResult mountResult = UDisks2MountDrive(devNode, fileSystemType, optionString);
+ if (mountResult["result"].toBool()) {
// Update internal mount data
TDEGlobal::hardwareDevices()->processModifiedMounts();
- return mountPath();
+ result["mountPath"] = mountPath();
+ result["result"] = true;
+ return result;
}
- else if (uDisks2Ret == -1) {
- if (errRet) {
- *errRet = errorString;
- }
+ else if (mountResult["retcode"].toInt() == -1) {
// Update internal mount data
TDEGlobal::hardwareDevices()->processModifiedMounts();
- return mountPath();
+ result["errStr"] = mountResult["errStr"];
+ result["result"] = false;
+ return result;
}
// 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) {
+ mountResult = UDisksMountDrive(devNode, fileSystemType, udisksOptions);
+ if (mountResult["result"].toBool()) {
// Update internal mount data
TDEGlobal::hardwareDevices()->processModifiedMounts();
- return mountPath();
+ result["mountPath"] = mountPath();
+ result["result"] = true;
+ return result;
}
- else if (uDisksRet == -1) {
- if (errRet) {
- *errRet = errorString;
- }
+ else if (mountResult["retcode"].toInt() == -1) {
// Update internal mount data
TDEGlobal::hardwareDevices()->processModifiedMounts();
- return mountPath();
+ result["errStr"] = mountResult["errStr"];
+ result["result"] = false;
+ return result;
}
// 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 (!TDEGlobal::dirs()->findExe("udevil").isEmpty()) {
if (mountOptions.contains("filesystem") && !mountOptions["filesystem"].isEmpty()) {
fileSystemType = TQString("-t %1").arg(mountOptions["filesystem"]);
}
@@ -834,8 +830,7 @@ TQString TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageMountOption
// If 'udevil' was not found, use 'pmount' command if available
if(command.isEmpty()) {
- TQString pmountProg = TDEGlobal::dirs()->findExe("pmount");
- if (!pmountProg.isEmpty()) {
+ if (!TDEGlobal::dirs()->findExe("pmount").isEmpty()) {
// Create dummy password file
KTempFile passwordFile(TQString::null, "tmp", 0600);
passwordFile.setAutoDelete(true);
@@ -884,39 +879,38 @@ TQString TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageMountOption
}
if(command.isEmpty()) {
- if (errRet) {
- *errRet = i18n("No supported mounting methods were detected on your system");
- }
- return mountPath();
+ result["errStr"] = i18n("No supported mounting methods were detected on your system");
+ result["result"] = false;
+ return result;
}
FILE *exepipe = popen(command.local8Bit(), "r");
if (exepipe) {
- TQString mount_output;
TQTextStream* ts = new TQTextStream(exepipe, IO_ReadOnly);
- mount_output = ts->read();
+ TQString mount_output = ts->read();
delete ts;
- *retcode = pclose(exepipe);
- if (errRet) {
- *errRet = mount_output;
- }
+ int retcode = pclose(exepipe);
+ result["errStr"] = mount_output;
+ result["retCode"] = retcode;
}
// Update internal mount data
TDEGlobal::hardwareDevices()->processModifiedMounts();
- return mountPath();
+ result["mountPath"] = mountPath();
+ result["result"] = !mountPath().isEmpty();
+ return result;
}
-TQString TDEStorageDevice::mountEncryptedDevice(TQString passphrase, TQString mediaName, TDEStorageMountOptions mountOptions, TQString* errRet, int* retcode) {
- int internal_retcode;
- if (!retcode) {
- retcode = &internal_retcode;
- }
-
- TQString ret = mountPath();
+TDEStorageOpResult TDEStorageDevice::mountEncryptedDevice(TQString passphrase, TQString mediaName,
+ TDEStorageMountOptions mountOptions) {
+ TDEStorageOpResult result;
- if (!ret.isNull()) {
- return ret;
+ // Check if device is already mounted
+ TQString mountpath = mountPath();
+ if (!mountpath.isEmpty()) {
+ result["mountPath"] = mountpath;
+ result["result"] = true;
+ return result;
}
// Create dummy password file
@@ -924,7 +918,9 @@ TQString TDEStorageDevice::mountEncryptedDevice(TQString passphrase, TQString me
passwordFile.setAutoDelete(true);
TQFile* pwFile = passwordFile.file();
if (!pwFile) {
- return TQString::null;
+ result["errStr"] = i18n("Cannot create temporary password file");
+ result["result"] = false;
+ return result;
}
pwFile->writeBlock(passphrase.ascii(), passphrase.length());
@@ -960,119 +956,112 @@ TQString TDEStorageDevice::mountEncryptedDevice(TQString passphrase, TQString me
passFileName.replace("'", "'\\''");
devNode.replace("'", "'\\''");
mediaName.replace("'", "'\\''");
- TQString command = TQString("pmount -p '%1' %2 '%3' '%4' 2>&1").arg(passFileName).arg(optionString).arg(devNode).arg(mediaName);
+ TQString command = TQString("pmount -p '%1' %2 '%3' '%4' 2>&1")
+ .arg(passFileName).arg(optionString).arg(devNode).arg(mediaName);
FILE *exepipe = popen(command.local8Bit(), "r");
if (exepipe) {
- TQString mount_output;
TQTextStream* ts = new TQTextStream(exepipe, IO_ReadOnly);
- mount_output = ts->read();
+ TQString mount_output = ts->read();
delete ts;
- *retcode = pclose(exepipe);
- if (errRet) {
- *errRet = mount_output;
- }
+ int retcode = pclose(exepipe);
+ result["errStr"] = mount_output;
+ result["retCode"] = retcode;
}
// Update internal mount data
TDEGlobal::hardwareDevices()->processModifiedMounts();
-
- ret = mountPath();
-
- return ret;
+ result["mountPath"] = mountPath();
+ result["result"] = !mountPath().isEmpty();
+ return result;
}
-bool TDEStorageDevice::unmountDevice(TQString* errRet, int* retcode) {
- if (mountPath().isNull()) {
- return true;
- }
-
- int internal_retcode;
- if (!retcode) {
- retcode = &internal_retcode;
- }
+TDEStorageOpResult TDEStorageDevice::unmountDevice() {
+ TDEStorageOpResult result;
+ // Check if device is already unmounted
TQString mountpoint = mountPath();
- TQString devNode = deviceNode();
+ if (mountpoint.isEmpty()) {
+ result["result"] = true;
+ return result;
+ }
mountpoint.replace("'", "'\\''");
+ TQString devNode = deviceNode();
// Try to use UDISKS v2 via DBUS, if available
- TQString errorString;
- int unMountUDisks2Ret = unMountDriveUDisks2(devNode, TQString::null, &errorString);
- if (unMountUDisks2Ret == 0) {
+ TDEStorageOpResult unmountResult = UDisks2UnmountDrive(devNode, TQString::null);
+ if (unmountResult["result"].toBool()) {
// Update internal mount data
TDEGlobal::hardwareDevices()->processModifiedMounts();
- return true;
+ result["result"] = true;
+ return result;
}
- else if (unMountUDisks2Ret == -1) {
- if (errRet) {
- *errRet = errorString;
- }
+ else if (unmountResult["retcode"].toInt() == -1) {
// Update internal mount data
TDEGlobal::hardwareDevices()->processModifiedMounts();
- return false;
+ result["errStr"] = unmountResult["errStr"];
+ result["result"] = false;
+ return result;
}
// 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) {
+ unmountResult = UDisksUnmountDrive(devNode, TQStringList());
+ if (unmountResult["result"].toBool()) {
// Update internal mount data
TDEGlobal::hardwareDevices()->processModifiedMounts();
- return true;
+ result["result"] = true;
+ return result;
}
- else if (unMountUDisksRet == -1) {
- if (errRet) {
- *errRet = errorString;
- }
+ else if (unmountResult["retcode"].toInt() == -1) {
// Update internal mount data
TDEGlobal::hardwareDevices()->processModifiedMounts();
- return false;
+ result["errStr"] = unmountResult["errStr"];
+ result["result"] = false;
+ return result;
}
// 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())) {
+ // Use 'udevil' command, if available
+ TQString command = TQString::null;
+ if (!TDEGlobal::dirs()->findExe("udevil").isEmpty()) {
command = TQString("udevil umount '%1' 2>&1").arg(mountpoint);
}
// If 'udevil' was not found, use 'pmount' command if available
- if(command.isEmpty() &&
- !(TDEGlobal::dirs()->findExe("pumount").isEmpty())) {
+ if(command.isEmpty() && !TDEGlobal::dirs()->findExe("pumount").isEmpty()) {
command = TQString("pumount '%1' 2>&1").arg(mountpoint);
}
if(command.isEmpty()) {
- if (errRet) {
- *errRet = i18n("No supported unmounting methods were detected on your system");
- }
- return false;
+ result["errStr"] = i18n("No supported unmounting methods were detected on your system");
+ result["result"] = false;
+ return result;
}
FILE *exepipe = popen(command.local8Bit(), "r");
if (exepipe) {
- TQString umount_output;
TQTextStream* ts = new TQTextStream(exepipe, IO_ReadOnly);
- umount_output = ts->read();
+ TQString umount_output = ts->read();
delete ts;
- *retcode = pclose(exepipe);
- if (*retcode == 0) {
+ int retcode = pclose(exepipe);
+ if (retcode == 0) {
// Update internal mount data
TDEGlobal::hardwareDevices()->processModifiedMounts();
- return true;
+ result["result"] = true;
+ return result;
}
else {
- if (errRet) {
- *errRet = umount_output;
- }
+ result["errStr"] = umount_output;
+ result["retCode"] = retcode;
}
}
// Update internal mount data
TDEGlobal::hardwareDevices()->processModifiedMounts();
- return false;
+ result["result"] = false;
+ return result;
}
TQString TDEStorageDevice::determineFileSystemType(TQString path) {