tdehw lib: reworked code for eject operation to support return type TQStringVariantMap.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/113/head
Michele Calgaro 5 years ago
parent b44ff1c0a9
commit 07200a5475
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -327,28 +327,47 @@ bool TDEStorageDevice::lockDriveMedia(bool lock) {
} }
} }
bool TDEStorageDevice::ejectDrive() { TQStringVariantMap TDEStorageDevice::ejectDrive() {
TQStringVariantMap result;
TQStringVariantMap ejectResult;
#ifdef WITH_UDISKS2 #ifdef WITH_UDISKS2
if (!(TDEGlobal::dirs()->findExe("udisksctl").isEmpty())) { if (!(TDEGlobal::dirs()->findExe("udisksctl").isEmpty())) {
TQStringVariantMap ejectResult = udisks2EjectDrive(this); ejectResult = udisks2EjectDrive(this);
if (ejectResult["result"].toBool()) { if (ejectResult["result"].toBool()) {
return true; // Update internal mount data
TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
TDEGlobal::hardwareDevices()->processModifiedMounts();
result["result"] = true;
return result;
} }
else { else {
printf("[tdehwlib] Failed to eject drive '%s' via udisks2, falling back to alternate mechanism\n", deviceNode().ascii()); // Update internal mount data
fflush(stdout); TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
TDEGlobal::hardwareDevices()->processModifiedMounts();
result["errStr"] = ejectResult["errStr"];
result["result"] = false;
return result;
} }
} }
#endif #endif
#ifdef WITH_UDISKS #ifdef WITH_UDISKS
if (!(TDEGlobal::dirs()->findExe("udisks").isEmpty())) { if (!(TDEGlobal::dirs()->findExe("udisks").isEmpty())) {
TQStringVariantMap ejectResult = udisksEjectDrive(this); ejectResult = udisksEjectDrive(this);
if (ejectResult["result"].toBool()) { if (ejectResult["result"].toBool()) {
return true; // Update internal mount data
TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
TDEGlobal::hardwareDevices()->processModifiedMounts();
result["result"] = true;
return result;
} }
else { else {
printf("[tdehwlib] Failed to eject drive '%s' via udisks, falling back to alternate mechanism\n", deviceNode().ascii()); // Update internal mount data
fflush(stdout); TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
TDEGlobal::hardwareDevices()->processModifiedMounts();
result["errStr"] = ejectResult["errStr"];
result["result"] = false;
return result;
} }
} }
#endif #endif
@ -363,14 +382,24 @@ bool TDEStorageDevice::ejectDrive() {
eject_output = ts.read(); eject_output = ts.read();
int retcode = pclose(exepipe); int retcode = pclose(exepipe);
if (retcode == 0) { if (retcode == 0) {
return true; // Update internal mount data
TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
TDEGlobal::hardwareDevices()->processModifiedMounts();
result["result"] = true;
return result;
}
else {
result["errStr"] = eject_output;
result["retCode"] = retcode;
} }
} }
printf("[tdehwlib] Failed to eject drive '%s' via 'eject' command\n", deviceNode().ascii());
fflush(stdout);
} }
return false; // Update internal mount data
TDEGlobal::hardwareDevices()->rescanDeviceInformation(this);
TDEGlobal::hardwareDevices()->processModifiedMounts();
result["result"] = false;
return result;
} }
bool TDEStorageDevice::ejectDriveMedia() { bool TDEStorageDevice::ejectDriveMedia() {

@ -99,17 +99,17 @@ inline TDEDiskDeviceType operator~(TDEDiskDeviceType a)
namespace TDEDiskDeviceStatus { namespace TDEDiskDeviceStatus {
enum TDEDiskDeviceStatus { enum TDEDiskDeviceStatus {
Null = 0x00000000, Null = 0x00000000,
Mountable = 0x00000001, Mountable = 0x00000001,
Removable = 0x00000002, Removable = 0x00000002,
Inserted = 0x00000004, Inserted = 0x00000004,
Blank = 0x00000008, Blank = 0x00000008,
UsedByDevice = 0x00000010, UsedByDevice = 0x00000010,
UsesDevice = 0x00000020, UsesDevice = 0x00000020,
ContainsFilesystem = 0x00000040, ContainsFilesystem = 0x00000040,
Hotpluggable = 0x00000080, Hotpluggable = 0x00000080,
Hidden = 0x00000100, Hidden = 0x00000100,
Other = 0x80000000 Other = 0x80000000
}; };
inline TDEDiskDeviceStatus operator|(TDEDiskDeviceStatus a, TDEDiskDeviceStatus b) inline TDEDiskDeviceStatus operator|(TDEDiskDeviceStatus a, TDEDiskDeviceStatus b)
@ -130,11 +130,11 @@ inline TDEDiskDeviceStatus operator~(TDEDiskDeviceStatus a)
namespace TDELUKSKeySlotStatus { namespace TDELUKSKeySlotStatus {
enum TDELUKSKeySlotStatus { enum TDELUKSKeySlotStatus {
Invalid = 0x00000000, Invalid = 0x00000000,
Inactive = 0x00000001, Inactive = 0x00000001,
Active = 0x00000002, Active = 0x00000002,
Last = 0x00000004, Last = 0x00000004,
Other = 0x80000000 Other = 0x80000000
}; };
inline TDELUKSKeySlotStatus operator|(TDELUKSKeySlotStatus a, TDELUKSKeySlotStatus b) inline TDELUKSKeySlotStatus operator|(TDELUKSKeySlotStatus a, TDELUKSKeySlotStatus b)
@ -157,13 +157,13 @@ typedef TQValueList<TDELUKSKeySlotStatus::TDELUKSKeySlotStatus> TDELUKSKeySlotSt
namespace TDELUKSResult { namespace TDELUKSResult {
enum TDELUKSResult { enum TDELUKSResult {
Invalid = 0x00000000, Invalid = 0x00000000,
Success = 0x00000001, Success = 0x00000001,
LUKSNotSupported = 0x00000002, LUKSNotSupported = 0x00000002,
LUKSNotFound = 0x00000003, LUKSNotFound = 0x00000003,
InvalidKeyslot = 0x00000004, InvalidKeyslot = 0x00000004,
KeyslotOpFailed = 0x00000005, KeyslotOpFailed = 0x00000005,
Other = 0x80000000 Other = 0x80000000
}; };
}; };
@ -347,7 +347,7 @@ class TDECORE_EXPORT TDEStorageDevice : public TDEGenericDevice
* *
* This method currently works on all removable storage devices * This method currently works on all removable storage devices
*/ */
bool ejectDrive(); TQStringVariantMap ejectDrive();
/** /**
* @param path Full path to arbitrary file or directory * @param path Full path to arbitrary file or directory

Loading…
Cancel
Save