@@ -76,44 +76,8 @@ UDisks2::Block::Block(const QString &path, const UDisks2::InterfacePropertyMap &
76
76
});
77
77
}
78
78
79
- // Use when morphing a block e.g. updating encrypted block to crypto backing block device (e.i. to a block that implements file system).
80
- UDisks2::Block &UDisks2::Block::operator =(const UDisks2::Block &other)
79
+ UDisks2::Block &UDisks2::Block::operator =(const UDisks2::Block &)
81
80
{
82
- if (&other == this )
83
- return *this ;
84
-
85
- if (!this ->m_connection .disconnect (
86
- UDISKS2_SERVICE,
87
- m_path,
88
- DBUS_OBJECT_PROPERTIES_INTERFACE,
89
- UDisks2::propertiesChangedSignal,
90
- this ,
91
- SLOT (updateProperties (QDBusMessage)))) {
92
- qCWarning (lcMemoryCardLog) << " Failed to disconnect to Block properties change interface" << m_path << m_connection.lastError ().message ();
93
- }
94
-
95
- this ->m_path = other.m_path ;
96
-
97
- if (!this ->m_connection .connect (
98
- UDISKS2_SERVICE,
99
- this ->m_path ,
100
- DBUS_OBJECT_PROPERTIES_INTERFACE,
101
- UDisks2::propertiesChangedSignal,
102
- this ,
103
- SLOT (updateProperties (QDBusMessage)))) {
104
- qCWarning (lcMemoryCardLog) << " Failed to connect to Block properties change interface" << m_path << m_connection.lastError ().message ();
105
- }
106
-
107
- m_interfacePropertyMap = other.m_interfacePropertyMap ;
108
- m_data = other.m_data ;
109
- m_drive = other.m_drive ;
110
- m_mountable = other.m_mountable ;
111
- m_mountPath = other.m_mountPath ;
112
- m_encrypted = other.m_encrypted ;
113
- m_formatting = other.m_formatting ;
114
- m_locking = other.m_locking ;
115
-
116
- return *this ;
117
81
}
118
82
119
83
UDisks2::Block::~Block ()
@@ -184,7 +148,7 @@ bool UDisks2::Block::isCryptoBlock() const
184
148
bool UDisks2::Block::hasCryptoBackingDevice () const
185
149
{
186
150
const QString cryptoBackingDev = cryptoBackingDeviceObjectPath ();
187
- return cryptoBackingDev != QLatin1String (" /" );
151
+ return !cryptoBackingDev. isEmpty () && cryptoBackingDev != QLatin1String (" /" );
188
152
}
189
153
190
154
QString UDisks2::Block::cryptoBackingDevicePath () const
@@ -264,6 +228,11 @@ bool UDisks2::Block::isExternal() const
264
228
return prefDevice != QStringLiteral (" /dev/sailfish/home" ) && prefDevice != QStringLiteral (" /dev/sailfish/root" );
265
229
}
266
230
231
+ bool UDisks2::Block::isValid () const
232
+ {
233
+ return m_interfacePropertyMap.contains (UDISKS2_BLOCK_INTERFACE);
234
+ }
235
+
267
236
QString UDisks2::Block::idType () const
268
237
{
269
238
return value (QStringLiteral (" IdType" )).toString ();
@@ -321,6 +290,72 @@ QString UDisks2::Block::cryptoBackingDevicePath(const QString &objectPath)
321
290
}
322
291
}
323
292
293
+ void UDisks2::Block::addInterface (const QString &interface, QVariantMap propertyMap)
294
+ {
295
+ m_interfacePropertyMap.insert (interface, propertyMap);
296
+ if (interface == UDISKS2_FILESYSTEM_INTERFACE) {
297
+ setMountable (true );
298
+ } else if (interface == UDISKS2_ENCRYPTED_INTERFACE) {
299
+ setEncrypted (true );
300
+ }
301
+ }
302
+
303
+ void UDisks2::Block::removeInterface (const QString &interface)
304
+ {
305
+ m_interfacePropertyMap.remove (interface);
306
+ if (interface == UDISKS2_BLOCK_INTERFACE) {
307
+ m_data.clear ();
308
+ } else if (interface == UDISKS2_DRIVE_INTERFACE) {
309
+ m_drive.clear ();
310
+ } else if (interface == UDISKS2_FILESYSTEM_INTERFACE) {
311
+ setMountable (false );
312
+ }else if (interface == UDISKS2_ENCRYPTED_INTERFACE) {
313
+ setEncrypted (false );
314
+ }
315
+ }
316
+
317
+ void UDisks2::Block::morph (const UDisks2::Block &other)
318
+ {
319
+ if (&other == this )
320
+ return ;
321
+
322
+ if (!this ->m_connection .disconnect (
323
+ UDISKS2_SERVICE,
324
+ m_path,
325
+ DBUS_OBJECT_PROPERTIES_INTERFACE,
326
+ UDisks2::propertiesChangedSignal,
327
+ this ,
328
+ SLOT (updateProperties (QDBusMessage)))) {
329
+ qCWarning (lcMemoryCardLog) << " Failed to disconnect to Block properties change interface" << m_path << m_connection.lastError ().message ();
330
+ }
331
+
332
+ this ->m_path = other.m_path ;
333
+
334
+ if (!this ->m_connection .connect (
335
+ UDISKS2_SERVICE,
336
+ this ->m_path ,
337
+ DBUS_OBJECT_PROPERTIES_INTERFACE,
338
+ UDisks2::propertiesChangedSignal,
339
+ this ,
340
+ SLOT (updateProperties (QDBusMessage)))) {
341
+ qCWarning (lcMemoryCardLog) << " Failed to connect to Block properties change interface" << m_path << m_connection.lastError ().message ();
342
+ }
343
+
344
+ m_interfacePropertyMap = other.m_interfacePropertyMap ;
345
+ m_data = other.m_data ;
346
+ m_drive = other.m_drive ;
347
+ m_mountPath = other.m_mountPath ;
348
+ m_mountable = other.m_mountable ;
349
+ m_encrypted = other.m_encrypted ;
350
+ bool wasFormatting = m_formatting;
351
+ m_formatting = other.m_formatting ;
352
+ m_locking = other.m_locking ;
353
+
354
+ if (wasFormatting && hasCryptoBackingDevice ()) {
355
+ rescan (cryptoBackingDeviceObjectPath ());
356
+ }
357
+ }
358
+
324
359
void UDisks2::Block::updateProperties (const QDBusMessage &message)
325
360
{
326
361
QList<QVariant> arguments = message.arguments ();
@@ -458,3 +493,26 @@ void UDisks2::Block::getDriveProperties()
458
493
complete ();
459
494
});
460
495
}
496
+
497
+ void UDisks2::Block::rescan (const QString &dbusObjectPath)
498
+ {
499
+ QVariantList arguments;
500
+ QVariantMap options;
501
+ arguments << options;
502
+
503
+ QDBusInterface blockDeviceInterface (UDISKS2_SERVICE,
504
+ dbusObjectPath,
505
+ UDISKS2_BLOCK_INTERFACE,
506
+ m_connection);
507
+
508
+ QDBusPendingCall pendingCall = blockDeviceInterface.asyncCallWithArgumentList (UDISKS2_BLOCK_RESCAN, arguments);
509
+ QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher (pendingCall, this );
510
+ connect (watcher, &QDBusPendingCallWatcher::finished,
511
+ this , [dbusObjectPath](QDBusPendingCallWatcher *watcher) {
512
+ if (watcher->isError ()) {
513
+ QDBusError error = watcher->error ();
514
+ qCDebug (lcMemoryCardLog) << " UDisks failed to rescan object path" << dbusObjectPath << " , error type:" << error.type () << " ,name:" << error.name () << " , message:" << error.message ();
515
+ }
516
+ watcher->deleteLater ();
517
+ });
518
+ }
0 commit comments