Use only available mechanisms to eject in the tdehw storage backend

pull/16/head
Slávek Banko 12 years ago
parent 990c3797c4
commit 8054860ca3

@ -118,23 +118,16 @@ bool ejectDriveUDisks(TDEStorageDevice* sdevice) {
TQT_DBusMessage reply = driveControl.sendWithReply("DriveEject", params, &error); TQT_DBusMessage reply = driveControl.sendWithReply("DriveEject", params, &error);
if (error.isValid()) { if (error.isValid()) {
// Error! // Error!
printf("[ERROR] %s\n", error.name().ascii()); fflush(stdout); printf("[ERROR][tdehwlib] ejectDriveUDisks: %s\n", error.name().ascii()); fflush(stdout);
return FALSE; return FALSE;
} }
else { else {
return TRUE; return TRUE;
} }
} }
else {
return FALSE;
}
}
else {
return FALSE;
} }
#else // WITH_UDISKS
return FALSE;
#endif // WITH_UDISKS #endif // WITH_UDISKS
return FALSE;
} }
bool ejectDriveUDisks2(TDEStorageDevice* sdevice) { bool ejectDriveUDisks2(TDEStorageDevice* sdevice) {
@ -153,7 +146,7 @@ bool ejectDriveUDisks2(TDEStorageDevice* sdevice) {
TQT_DBusMessage reply = hardwareControl.sendWithReply("Get", params, &error); TQT_DBusMessage reply = hardwareControl.sendWithReply("Get", params, &error);
if (error.isValid()) { if (error.isValid()) {
// Error! // Error!
printf("[ERROR] %s\n", error.name().ascii()); fflush(stdout); printf("[ERROR][tdehwlib] ejectDriveUDisks2: %s\n", error.name().ascii()); fflush(stdout);
return FALSE; return FALSE;
} }
else { else {
@ -162,7 +155,7 @@ bool ejectDriveUDisks2(TDEStorageDevice* sdevice) {
if (!driveObjectPath.isValid()) { if (!driveObjectPath.isValid()) {
return FALSE; return FALSE;
} }
error = TQT_DBusError(); error = TQT_DBusError();
TQT_DBusProxy driveInformation("org.freedesktop.UDisks2", driveObjectPath, "org.freedesktop.DBus.Properties", dbusConn); TQT_DBusProxy driveInformation("org.freedesktop.UDisks2", driveObjectPath, "org.freedesktop.DBus.Properties", dbusConn);
// can eject? // can eject?
@ -171,7 +164,7 @@ bool ejectDriveUDisks2(TDEStorageDevice* sdevice) {
TQT_DBusMessage reply = driveInformation.sendWithReply("Get", params, &error); TQT_DBusMessage reply = driveInformation.sendWithReply("Get", params, &error);
if (error.isValid()) { if (error.isValid()) {
// Error! // Error!
printf("[ERROR] %s\n", error.name().ascii()); fflush(stdout); printf("[ERROR][tdehwlib] ejectDriveUDisks2: %s\n", error.name().ascii()); fflush(stdout);
return FALSE; return FALSE;
} }
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) { if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
@ -179,7 +172,7 @@ bool ejectDriveUDisks2(TDEStorageDevice* sdevice) {
if (!ejectable) { if (!ejectable) {
return FALSE; return FALSE;
} }
// Eject the drive! // Eject the drive!
TQT_DBusProxy driveControl("org.freedesktop.UDisks2", driveObjectPath, "org.freedesktop.UDisks2.Drive", dbusConn); TQT_DBusProxy driveControl("org.freedesktop.UDisks2", driveObjectPath, "org.freedesktop.UDisks2.Drive", dbusConn);
TQValueList<TQT_DBusData> params; TQValueList<TQT_DBusData> params;
@ -188,71 +181,64 @@ bool ejectDriveUDisks2(TDEStorageDevice* sdevice) {
TQT_DBusMessage reply = driveControl.sendWithReply("Eject", params, &error); TQT_DBusMessage reply = driveControl.sendWithReply("Eject", params, &error);
if (error.isValid()) { if (error.isValid()) {
// Error! // Error!
printf("[ERROR] %s\n", error.name().ascii()); fflush(stdout); printf("[ERROR][tdehwlib] ejectDriveUDisks2: %s\n", error.name().ascii()); fflush(stdout);
return FALSE; return FALSE;
} }
else { else {
return TRUE; return TRUE;
} }
} }
else {
return FALSE;
}
}
else {
return FALSE;
} }
} }
} }
else {
return FALSE;
}
}
else {
return FALSE;
} }
#else // WITH_UDISKS2
return FALSE;
#endif // WITH_UDISKS2 #endif // WITH_UDISKS2
return FALSE;
} }
bool TDEStorageDevice::ejectDrive() { bool TDEStorageDevice::ejectDrive() {
if (ejectDriveUDisks2(this)) {
return TRUE;
}
else {
#ifdef WITH_UDISKS2 #ifdef WITH_UDISKS2
printf("[tdehwlib] Failed to eject drive '%s' via udisks2, falling back to alternate mechanism\n", deviceNode().ascii()); if (!(TDEGlobal::dirs()->findExe("udisksctl").isEmpty())) {
if (ejectDriveUDisks2(this)) {
return TRUE;
}
else {
printf("[tdehwlib] Failed to eject drive '%s' via udisks2, falling back to alternate mechanism\n", deviceNode().ascii());
fflush(stdout);
}
}
#endif // WITH_UDISKS2 #endif // WITH_UDISKS2
#ifdef WITH_UDISKS
if (!(TDEGlobal::dirs()->findExe("udisks").isEmpty())) {
if (ejectDriveUDisks(this)) { if (ejectDriveUDisks(this)) {
return TRUE; return TRUE;
} }
else { else {
#ifdef WITH_UDISKS
printf("[tdehwlib] Failed to eject drive '%s' via udisks, falling back to alternate mechanism\n", deviceNode().ascii()); printf("[tdehwlib] Failed to eject drive '%s' via udisks, falling back to alternate mechanism\n", deviceNode().ascii());
fflush(stdout);
}
}
#endif // WITH_UDISKS #endif // WITH_UDISKS
TQString command = TQString("eject -v '%1' 2>&1").arg(deviceNode());
if (!(TDEGlobal::dirs()->findExe("eject").isEmpty())) {
FILE *exepipe = popen(command.ascii(), "r"); TQString command = TQString("eject -v '%1' 2>&1").arg(deviceNode());
if (exepipe) {
TQString pmount_output; FILE *exepipe = popen(command.ascii(), "r");
char buffer[8092]; if (exepipe) {
pmount_output = fgets(buffer, sizeof(buffer), exepipe); TQString pmount_output;
int retcode = pclose(exepipe); char buffer[8092];
if (retcode == 0) { pmount_output = fgets(buffer, sizeof(buffer), exepipe);
return TRUE; int retcode = pclose(exepipe);
} if (retcode == 0) {
else { return TRUE;
printf("[tdehwlib] Failed to eject drive '%s' via 'eject' command\n", deviceNode().ascii());
return FALSE;
}
}
else {
printf("[tdehwlib] Failed to eject drive '%s' via 'eject' command\n", deviceNode().ascii());
return FALSE;
} }
} }
printf("[tdehwlib] Failed to eject drive '%s' via 'eject' command\n", deviceNode().ascii());
fflush(stdout);
} }
return FALSE;
} }
bool TDEStorageDevice::ejectDriveMedia() { bool TDEStorageDevice::ejectDriveMedia() {

Loading…
Cancel
Save