20 #if defined(WITH_UDISKS) || defined(WITH_UDISKS2)
21 #include <tqdbusdata.h>
22 #include <tqdbusmessage.h>
23 #include <tqdbusproxy.h>
24 #include <tqdbusvariant.h>
25 #include <tqdbusconnection.h>
26 #include <tqdbuserror.h>
27 #include <tqdbusdatamap.h>
28 #include <tqdbusobjectpath.h>
29 #include "tqdbusdatalist.h"
33 #include "tdestoragedevice.h"
34 #include "disksHelper.h"
42 TQStringVariantMap udisksEjectDrive(TDEStorageDevice *sdevice) {
43 TQStringVariantMap result;
44 result[
"result"] =
false;
46 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
47 if (dbusConn.isConnected()) {
48 TQString blockDeviceString = sdevice->deviceNode();
49 blockDeviceString.replace(
"/dev/",
"");
50 blockDeviceString.replace(
"-",
"_2d");
51 blockDeviceString =
"/org/freedesktop/UDisks/devices/" + blockDeviceString;
55 TQT_DBusProxy driveControl(
"org.freedesktop.UDisks", blockDeviceString,
"org.freedesktop.UDisks.Device", dbusConn);
56 if (driveControl.canSend()) {
57 TQValueList<TQT_DBusData> params;
58 TQT_DBusDataList options;
59 params << TQT_DBusData::fromList(options);
60 TQT_DBusMessage reply = driveControl.sendWithReply(
"DriveEject", params, &error);
61 if (error.isValid()) {
63 result[
"errStr"] = error.name() +
": " + error.message();
68 TQT_DBusProxy driveInformation(
"org.freedesktop.UDisks", blockDeviceString,
69 "org.freedesktop.DBus.Properties", dbusConn);
71 params << TQT_DBusData::fromString(
"org.freedesktop.UDisks.Drive") << TQT_DBusData::fromString(
"DriveCanDetach");
72 TQT_DBusMessage reply = driveInformation.sendWithReply(
"Get", params, &error);
73 if (error.isValid()) {
75 result[
"errStr"] = error.name() +
": " + error.message();
79 if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
80 bool canPowerOff = reply[0].toVariant().value.toBool();
83 result[
"result"] =
true;
89 TQT_DBusDataMap<TQString> options(TQT_DBusData::Variant);
90 params << TQT_DBusData::fromStringKeyMap(options);
91 TQT_DBusMessage reply = driveControl.sendWithReply(
"DriveDetach", params, &error);
92 if (error.isValid()) {
94 result[
"errStr"] = error.name() +
": " + error.message();
98 result[
"result"] =
true;
108 TQStringVariantMap udisksMountDrive(
const TQString &deviceNode,
const TQString &fileSystemType, TQStringList mountOptions) {
109 TQStringVariantMap result;
110 result[
"result"] =
false;
111 result[
"retcode"] = -2;
113 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
114 if (dbusConn.isConnected()) {
115 TQString blockDeviceString = deviceNode;
116 blockDeviceString.replace(
"/dev/",
"");
117 blockDeviceString.replace(
"-",
"_2d");
118 blockDeviceString =
"/org/freedesktop/UDisks/devices/" + blockDeviceString;
122 TQT_DBusProxy driveControl(
"org.freedesktop.UDisks", blockDeviceString,
"org.freedesktop.UDisks.Device", dbusConn);
123 if (driveControl.canSend()) {
124 TQValueList<TQT_DBusData> params;
125 params << TQT_DBusData::fromString(fileSystemType);
126 params << TQT_DBusData::fromList(TQT_DBusDataList(mountOptions));
127 TQT_DBusMessage reply = driveControl.sendWithReply(
"FilesystemMount", params, &error);
128 if (!error.isValid()) {
130 result[
"retcode"] = 0;
131 result[
"result"] =
true;
136 if (error.name() ==
"org.freedesktop.DBus.Error.ServiceUnknown") {
140 result[
"errStr"] = error.name() +
": " + error.message();
141 result[
"retcode"] = -1;
150 TQStringVariantMap udisksUnmountDrive(
const TQString &deviceNode, TQStringList unmountOptions) {
151 TQStringVariantMap result;
152 result[
"result"] =
false;
153 result[
"retcode"] = -2;
155 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
156 if (dbusConn.isConnected()) {
157 TQString blockDeviceString = deviceNode;
158 blockDeviceString.replace(
"/dev/",
"");
159 blockDeviceString.replace(
"-",
"_2d");
160 blockDeviceString =
"/org/freedesktop/UDisks/devices/" + blockDeviceString;
164 TQT_DBusProxy driveControl(
"org.freedesktop.UDisks", blockDeviceString,
"org.freedesktop.UDisks.Device", dbusConn);
165 if (driveControl.canSend()) {
166 TQValueList<TQT_DBusData> params;
167 params << TQT_DBusData::fromList(TQT_DBusDataList(unmountOptions));
168 TQT_DBusMessage reply = driveControl.sendWithReply(
"FilesystemUnmount", params, &error);
169 if (!error.isValid()) {
171 result[
"retcode"] = 0;
172 result[
"result"] =
true;
177 if (error.name() ==
"org.freedesktop.DBus.Error.ServiceUnknown") {
181 result[
"errStr"] = error.name() +
": " + error.message();
182 result[
"retcode"] = -1;
197 TQStringVariantMap udisks2EjectDrive(TDEStorageDevice *sdevice) {
198 TQStringVariantMap result;
199 result[
"result"] =
false;
201 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
202 if (dbusConn.isConnected()) {
203 TQString blockDeviceString = sdevice->deviceNode();
204 blockDeviceString.replace(
"/dev/",
"");
205 blockDeviceString.replace(
"-",
"_2d");
206 blockDeviceString =
"/org/freedesktop/UDisks2/block_devices/" + blockDeviceString;
207 TQT_DBusProxy hardwareControl(
"org.freedesktop.UDisks2", blockDeviceString,
"org.freedesktop.DBus.Properties", dbusConn);
208 if (hardwareControl.canSend()) {
211 TQValueList<TQT_DBusData> params;
212 params << TQT_DBusData::fromString(
"org.freedesktop.UDisks2.Block") << TQT_DBusData::fromString(
"Drive");
213 TQT_DBusMessage reply = hardwareControl.sendWithReply(
"Get", params, &error);
214 if (error.isValid()) {
216 result[
"errStr"] = error.name() +
": " + error.message();
220 if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
221 TQT_DBusObjectPath driveObjectPath = reply[0].toVariant().value.toObjectPath();
222 if (!driveObjectPath.isValid()) {
225 error = TQT_DBusError();
226 TQT_DBusProxy driveInformation(
"org.freedesktop.UDisks2", driveObjectPath,
227 "org.freedesktop.DBus.Properties", dbusConn);
230 params << TQT_DBusData::fromString(
"org.freedesktop.UDisks2.Drive") << TQT_DBusData::fromString(
"Ejectable");
231 TQT_DBusMessage reply = driveInformation.sendWithReply(
"Get", params, &error);
232 if (error.isValid()) {
234 result[
"errStr"] = error.name() +
": " + error.message();
238 if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
239 bool ejectable = reply[0].toVariant().value.toBool();
241 result[
"errStr"] =
i18n(
"Media not ejectable");
246 TQT_DBusProxy driveControl(
"org.freedesktop.UDisks2", driveObjectPath,
"org.freedesktop.UDisks2.Drive", dbusConn);
248 TQT_DBusDataMap<TQString> options(TQT_DBusData::Variant);
249 params << TQT_DBusData::fromStringKeyMap(options);
250 TQT_DBusMessage reply = driveControl.sendWithReply(
"Eject", params, &error);
251 if (error.isValid()) {
253 result[
"errStr"] = error.name() +
": " + error.message();
259 params << TQT_DBusData::fromString(
"org.freedesktop.UDisks2.Drive") << TQT_DBusData::fromString(
"CanPowerOff");
260 TQT_DBusMessage reply = driveInformation.sendWithReply(
"Get", params, &error);
261 if (error.isValid()) {
263 result[
"errStr"] = error.name() +
": " + error.message();
267 if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
268 bool canPowerOff = reply[0].toVariant().value.toBool();
271 result[
"result"] =
true;
277 TQT_DBusDataMap<TQString> options(TQT_DBusData::Variant);
278 params << TQT_DBusData::fromStringKeyMap(options);
279 TQT_DBusMessage reply = driveControl.sendWithReply(
"PowerOff", params, &error);
280 if (error.isValid()) {
282 result[
"errStr"] = error.name() +
": " + error.message();
286 result[
"result"] =
true;
298 TQStringVariantMap udisks2MountDrive(
const TQString &deviceNode,
const TQString &fileSystemType,
const TQString &mountOptions) {
299 TQStringVariantMap result;
300 result[
"result"] =
false;
301 result[
"retcode"] = -2;
303 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
304 if (dbusConn.isConnected()) {
305 TQString blockDeviceString = deviceNode;
306 blockDeviceString.replace(
"/dev/",
"");
307 blockDeviceString.replace(
"-",
"_2d");
308 blockDeviceString =
"/org/freedesktop/UDisks2/block_devices/" + blockDeviceString;
312 TQT_DBusProxy driveControl(
"org.freedesktop.UDisks2", blockDeviceString,
"org.freedesktop.UDisks2.Filesystem", dbusConn);
313 if (driveControl.canSend()) {
314 TQValueList<TQT_DBusData> params;
315 TQMap<TQString, TQT_DBusData> optionsMap;
316 if (fileSystemType !=
"") {
317 optionsMap[
"fstype"] = (TQT_DBusData::fromString(fileSystemType)).getAsVariantData();
319 optionsMap[
"options"] = (TQT_DBusData::fromString(mountOptions)).getAsVariantData();
320 params << TQT_DBusData::fromStringKeyMap(TQT_DBusDataMap<TQString>(optionsMap));
321 TQT_DBusMessage reply = driveControl.sendWithReply(
"Mount", params, &error);
322 if (!error.isValid()) {
324 result[
"retcode"] = 0;
325 result[
"result"] =
true;
330 if (error.name() ==
"org.freedesktop.DBus.Error.ServiceUnknown") {
334 result[
"errStr"] = error.name() +
": " + error.message();
335 result[
"retcode"] = -1;
344 TQStringVariantMap udisks2UnmountDrive(
const TQString &deviceNode,
const TQString &unmountOptions) {
345 TQStringVariantMap result;
346 result[
"result"] =
false;
347 result[
"retcode"] = -2;
349 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
350 if (dbusConn.isConnected()) {
351 TQString blockDeviceString = deviceNode;
352 blockDeviceString.replace(
"/dev/",
"");
353 blockDeviceString.replace(
"-",
"_2d");
354 blockDeviceString =
"/org/freedesktop/UDisks2/block_devices/" + blockDeviceString;
358 TQT_DBusProxy driveControl(
"org.freedesktop.UDisks2", blockDeviceString,
"org.freedesktop.UDisks2.Filesystem", dbusConn);
359 if (driveControl.canSend()) {
360 TQValueList<TQT_DBusData> params;
361 TQMap<TQString, TQT_DBusData> optionsMap;
362 optionsMap[
"options"] = (TQT_DBusData::fromString(unmountOptions)).getAsVariantData();
363 params << TQT_DBusData::fromStringKeyMap(TQT_DBusDataMap<TQString>(optionsMap));
364 TQT_DBusMessage reply = driveControl.sendWithReply(
"Unmount", params, &error);
365 if (!error.isValid()) {
367 result[
"retcode"] = 0;
368 result[
"result"] =
true;
373 if (error.name() ==
"org.freedesktop.DBus.Error.ServiceUnknown") {
377 result[
"errStr"] = error.name() +
": " + error.message();
378 result[
"retcode"] = -1;
387 TQStringVariantMap udisks2UnlockDrive(
const TQString &deviceNode,
const TQString &passphrase) {
388 TQStringVariantMap result;
389 result[
"result"] =
false;
390 result[
"retcode"] = -2;
392 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
393 if (dbusConn.isConnected()) {
394 TQString blockDeviceString = deviceNode;
395 blockDeviceString.replace(
"/dev/",
"");
396 blockDeviceString.replace(
"-",
"_2d");
397 blockDeviceString =
"/org/freedesktop/UDisks2/block_devices/" + blockDeviceString;
401 TQT_DBusProxy driveControl(
"org.freedesktop.UDisks2", blockDeviceString,
"org.freedesktop.UDisks2.Encrypted", dbusConn);
402 if (driveControl.canSend()) {
403 TQValueList<TQT_DBusData> params;
404 params << TQT_DBusData::fromString(passphrase);
405 TQMap<TQString, TQT_DBusVariant> optionsMap;
406 params << TQT_DBusData::fromStringKeyMap(TQT_DBusDataMap<TQString>(optionsMap));
407 TQT_DBusMessage reply = driveControl.sendWithReply(
"Unlock", params, &error);
408 if (!error.isValid()) {
409 if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
410 TQT_DBusObjectPath deviceObjectPath = reply[0].toObjectPath();
411 if (deviceObjectPath.isValid()) {
413 result[
"unlockedDevice"] = deviceObjectPath;
414 result[
"retcode"] = 0;
415 result[
"result"] =
true;
419 result[
"errStr"] =
i18n(
"Unknown error during unlocking operation.");
420 result[
"retcode"] = -1;
425 if (error.name() ==
"org.freedesktop.DBus.Error.ServiceUnknown") {
429 result[
"errStr"] = error.name() +
": " + error.message();
430 result[
"retcode"] = -1;
439 TQStringVariantMap udisks2LockDrive(
const TQString &deviceNode) {
440 TQStringVariantMap result;
441 result[
"result"] =
false;
442 result[
"retcode"] = -2;
444 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
445 if (dbusConn.isConnected()) {
446 TQString blockDeviceString = deviceNode;
447 blockDeviceString.replace(
"/dev/",
"");
448 blockDeviceString.replace(
"-",
"_2d");
449 blockDeviceString =
"/org/freedesktop/UDisks2/block_devices/" + blockDeviceString;
453 TQT_DBusProxy driveControl(
"org.freedesktop.UDisks2", blockDeviceString,
"org.freedesktop.UDisks2.Encrypted", dbusConn);
454 if (driveControl.canSend()) {
455 TQValueList<TQT_DBusData> params;
456 TQMap<TQString, TQT_DBusVariant> optionsMap;
457 params << TQT_DBusData::fromStringKeyMap(TQT_DBusDataMap<TQString>(optionsMap));
458 TQT_DBusMessage reply = driveControl.sendWithReply(
"Lock", params, &error);
459 if (!error.isValid()) {
461 result[
"retcode"] = 0;
462 result[
"result"] =
true;
467 if (error.name() ==
"org.freedesktop.DBus.Error.ServiceUnknown") {
471 result[
"errStr"] = error.name() +
": " + error.message();
472 result[
"retcode"] = -1;
TQString i18n(const char *text)
i18n is the function that does everything you need to translate a string.