@@ -17,10 +17,6 @@ UDisks2::Block::Block(const QString &path, const UDisks2::InterfacePropertyMap &
17
17
, m_encrypted(interfacePropertyMap.contains(UDISKS2_ENCRYPTED_INTERFACE))
18
18
, m_formatting(false )
19
19
, m_locking(false )
20
- , m_pendingFileSystem(nullptr )
21
- , m_pendingBlock(nullptr )
22
- , m_pendingEncrypted(nullptr )
23
- , m_pendingDrive(nullptr )
24
20
{
25
21
if (!m_connection.connect (
26
22
UDISKS2_SERVICE,
@@ -39,35 +35,61 @@ UDisks2::Block::Block(const QString &path, const UDisks2::InterfacePropertyMap &
39
35
40
36
qCInfo (lcMemoryCardLog) << " Creating a new block. Mountable:" << m_mountable << " , encrypted:" << m_encrypted << " object path:" << m_path << " data is empty:" << m_data.isEmpty ();
41
37
42
- if (m_data .isEmpty ()) {
43
- getFileSystemInterface ();
44
- getEncryptedInterface ();
45
- QDBusPendingCall pendingCall = dbusPropertyInterface. asyncCall (DBUS_GET_ALL, UDISKS2_BLOCK_INTERFACE) ;
46
- m_pendingBlock = new QDBusPendingCallWatcher (pendingCall, this );
47
- connect (m_pendingBlock, &QDBusPendingCallWatcher::finished, this , [ this , path](QDBusPendingCallWatcher *watcher) {
48
- if (watcher-> isValid () && watcher-> isFinished ()) {
49
- QDBusPendingReply<> reply = *watcher;
50
- QDBusMessage message = reply. reply ();
51
- QVariantMap blockProperties = NemoDBus::demarshallArgument<QVariantMap>(message. arguments (). at ( 0 ) );
52
- qCInfo (lcMemoryCardLog) << " Block properties: " << blockProperties ;
53
- m_data = blockProperties;
54
- getDriveProperties ();
55
- } else {
56
- QDBusError error = watcher-> error ( );
57
- qCWarning (lcMemoryCardLog) << " Error reading block properties: " << error. name () << error. message ( );
58
- }
59
- m_pendingBlock-> deleteLater ();
60
- m_pendingBlock = nullptr ;
61
- complete ( );
38
+ if (m_interfacePropertyMap .isEmpty ()) {
39
+ // Encrypted interface
40
+ getProperties (m_path, UDISKS2_ENCRYPTED_INTERFACE, m_pendingEncrypted, [ this ]( const QVariantMap &encryptedProperties) {
41
+ m_encrypted = true ;
42
+ m_interfacePropertyMap. insert (UDISKS2_ENCRYPTED_INTERFACE, encryptedProperties );
43
+ });
44
+
45
+ // File system interface
46
+ getProperties (m_path, UDISKS2_FILESYSTEM_INTERFACE, m_pendingFileSystem, [ this ]( const QVariantMap &filesystemProperties) {
47
+ updateFileSystemInterface (filesystemProperties );
48
+ }) ;
49
+
50
+ // Partition table interface
51
+ getProperties (m_path, UDISKS2_PARTITION_TABLE_INTERFACE, m_pendingPartitionTable, [ this ]( const QVariantMap &partitionTableProperties) {
52
+ m_interfacePropertyMap. insert (UDISKS2_PARTITION_TABLE_INTERFACE, partitionTableProperties );
53
+ } );
54
+
55
+ // Partition interface
56
+ getProperties (m_path, UDISKS2_PARTITION_INTERFACE, m_pendingPartition, [ this ]( const QVariantMap &partitionProperties) {
57
+ m_interfacePropertyMap. insert (UDISKS2_PARTITION_INTERFACE, partitionProperties );
62
58
});
59
+
60
+ // Block interface
61
+ getProperties (m_path, UDISKS2_BLOCK_INTERFACE, m_pendingBlock, [this ](const QVariantMap &blockProperties) {
62
+ qCInfo (lcMemoryCardLog) << " Block properties:" << blockProperties;
63
+ m_data = blockProperties;
64
+ m_interfacePropertyMap.insert (UDISKS2_BLOCK_INTERFACE, blockProperties);
65
+
66
+ // Drive path is blocks property => doing it the callback.
67
+ getProperties (drive (), UDISKS2_DRIVE_INTERFACE, m_pendingDrive, [this ](const QVariantMap &driveProperties) {
68
+ qCInfo (lcMemoryCardLog) << " Drive properties:" << driveProperties;
69
+ m_drive = driveProperties;
70
+ });
71
+
72
+ connect (m_pendingDrive.data (), &QObject::destroyed, this , &Block::complete);
73
+ });
74
+
75
+ connect (m_pendingEncrypted.data (), &QObject::destroyed, this , &Block::complete);
76
+ connect (m_pendingFileSystem.data (), &QObject::destroyed, this , &Block::complete);
77
+ connect (m_pendingPartitionTable.data (), &QObject::destroyed, this , &Block::complete);
78
+ connect (m_pendingPartition.data (), &QObject::destroyed, this , &Block::complete);
79
+ connect (m_pendingBlock.data (), &QObject::destroyed, this , &Block::complete);
63
80
} else {
64
81
if (m_mountable) {
65
82
QVariantMap map = interfacePropertyMap.value (UDISKS2_FILESYSTEM_INTERFACE);
66
- updateMountPoint (map);
83
+ updateFileSystemInterface (map);
67
84
}
68
- getDriveProperties ();
69
85
70
- // We have either org.freedesktop.UDisks2.Filesystem or org.freedesktop.UDisks2.Encrypted interface.
86
+ getProperties (drive (), UDISKS2_DRIVE_INTERFACE, m_pendingDrive, [this ](const QVariantMap &driveProperties) {
87
+ qCInfo (lcMemoryCardLog) << " Drive properties:" << driveProperties;
88
+ m_drive = driveProperties;
89
+ });
90
+
91
+ if (m_pendingDrive)
92
+ connect (m_pendingDrive.data (), &QObject::destroyed, this , &Block::complete);
71
93
complete ();
72
94
}
73
95
@@ -78,6 +100,7 @@ UDisks2::Block::Block(const QString &path, const UDisks2::InterfacePropertyMap &
78
100
79
101
UDisks2::Block &UDisks2::Block::operator =(const UDisks2::Block &)
80
102
{
103
+ return *this ;
81
104
}
82
105
83
106
UDisks2::Block::~Block ()
@@ -125,6 +148,22 @@ QString UDisks2::Block::connectionBus() const
125
148
return bus;
126
149
}
127
150
151
+ QString UDisks2::Block::partitionTable () const
152
+ {
153
+ // Partion table that this partition belongs to.
154
+ return NemoDBus::demarshallDBusArgument (m_interfacePropertyMap.value (UDISKS2_PARTITION_INTERFACE).value (QStringLiteral (" Table" ))).toString ();
155
+ }
156
+
157
+ bool UDisks2::Block::isPartition () const
158
+ {
159
+ return !m_interfacePropertyMap.value (UDISKS2_PARTITION_INTERFACE).isEmpty ();
160
+ }
161
+
162
+ bool UDisks2::Block::isPartitionTable () const
163
+ {
164
+ return !m_interfacePropertyMap.value (UDISKS2_PARTITION_TABLE_INTERFACE).isEmpty ();
165
+ }
166
+
128
167
qint64 UDisks2::Block::deviceNumber () const
129
168
{
130
169
return value (QStringLiteral (" DeviceNumber" )).toLongLong ();
@@ -277,7 +316,9 @@ void UDisks2::Block::dumpInfo() const
277
316
qCInfo (lcMemoryCardLog) << " - idversion:" << idVersion () << " idlabel:" << idLabel ();
278
317
qCInfo (lcMemoryCardLog) << " - iduuid:" << idUUID ();
279
318
qCInfo (lcMemoryCardLog) << " - ismountable:" << isMountable () << " mount path:" << mountPath ();
280
- qCInfo (lcMemoryCardLog) << " - isencrypted:" << isEncrypted () << " crypto backing device:" << cryptoBackingDevicePath ();
319
+ qCInfo (lcMemoryCardLog) << " - isencrypted:" << isEncrypted () << " crypto backing device:" << cryptoBackingDevicePath () << " crypto backing object path:" << cryptoBackingDeviceObjectPath ();
320
+ qCInfo (lcMemoryCardLog) << " - isformatting:" << isFormatting ();
321
+ qCInfo (lcMemoryCardLog) << " - ispartiontable:" << isPartitionTable () << " ispartition:" << isPartition ();
281
322
}
282
323
283
324
QString UDisks2::Block::cryptoBackingDevicePath (const QString &objectPath)
@@ -309,11 +350,21 @@ void UDisks2::Block::removeInterface(const QString &interface)
309
350
m_drive.clear ();
310
351
} else if (interface == UDISKS2_FILESYSTEM_INTERFACE) {
311
352
setMountable (false );
312
- }else if (interface == UDISKS2_ENCRYPTED_INTERFACE) {
353
+ } else if (interface == UDISKS2_ENCRYPTED_INTERFACE) {
313
354
setEncrypted (false );
314
355
}
315
356
}
316
357
358
+ int UDisks2::Block::interfaceCount () const
359
+ {
360
+ return m_interfacePropertyMap.keys ().count ();
361
+ }
362
+
363
+ bool UDisks2::Block::hasInterface (const QString &interface) const
364
+ {
365
+ return m_interfacePropertyMap.contains (interface);
366
+ }
367
+
317
368
void UDisks2::Block::morph (const UDisks2::Block &other)
318
369
{
319
370
if (&other == this )
@@ -341,6 +392,12 @@ void UDisks2::Block::morph(const UDisks2::Block &other)
341
392
qCWarning (lcMemoryCardLog) << " Failed to connect to Block properties change interface" << m_path << m_connection.lastError ().message ();
342
393
}
343
394
395
+ qCInfo (lcMemoryCardLog) << " Morphing" << qPrintable (device ()) << " that was" << (m_formatting ? " formatting" : " not formatting" ) << " to" << qPrintable (other.device ());
396
+ qCInfo (lcMemoryCardLog) << " Old block:" ;
397
+ dumpInfo ();
398
+ qCInfo (lcMemoryCardLog) << " New block:" ;
399
+ other.dumpInfo ();
400
+
344
401
m_interfacePropertyMap = other.m_interfacePropertyMap ;
345
402
m_data = other.m_data ;
346
403
m_drive = other.m_drive ;
@@ -351,6 +408,7 @@ void UDisks2::Block::morph(const UDisks2::Block &other)
351
408
m_formatting = other.m_formatting ;
352
409
m_locking = other.m_locking ;
353
410
411
+
354
412
if (wasFormatting && hasCryptoBackingDevice ()) {
355
413
rescan (cryptoBackingDeviceObjectPath ());
356
414
}
@@ -370,19 +428,21 @@ void UDisks2::Block::updateProperties(const QDBusMessage &message)
370
428
emit updated ();
371
429
}
372
430
} else if (interface == UDISKS2_FILESYSTEM_INTERFACE) {
373
- updateMountPoint (arguments.value (1 ));
431
+ updateFileSystemInterface (arguments.value (1 ));
374
432
}
375
433
}
376
434
377
435
bool UDisks2::Block::isCompleted () const
378
436
{
379
- return !m_pendingFileSystem && !m_pendingBlock && !m_pendingEncrypted && !m_pendingDrive;
437
+ return !m_pendingFileSystem && !m_pendingBlock && !m_pendingEncrypted && !m_pendingDrive
438
+ && !m_pendingPartition && !m_pendingPartitionTable;
380
439
}
381
440
382
- void UDisks2::Block::updateMountPoint (const QVariant &mountPoints )
441
+ void UDisks2::Block::updateFileSystemInterface (const QVariant &filesystemInterface )
383
442
{
384
- QVariantMap mountPointsMap = NemoDBus::demarshallArgument<QVariantMap>(mountPoints);
385
- QList<QByteArray> mountPointList = NemoDBus::demarshallArgument<QList<QByteArray> >(mountPointsMap.value (QStringLiteral (" MountPoints" )));
443
+ QVariantMap filesystem = NemoDBus::demarshallArgument<QVariantMap>(filesystemInterface);
444
+ m_interfacePropertyMap.insert (UDISKS2_FILESYSTEM_INTERFACE, filesystem);
445
+ QList<QByteArray> mountPointList = NemoDBus::demarshallArgument<QList<QByteArray> >(filesystem.value (QStringLiteral (" MountPoints" )));
386
446
m_mountPath.clear ();
387
447
388
448
for (const QByteArray &bytes : mountPointList) {
@@ -402,7 +462,7 @@ void UDisks2::Block::updateMountPoint(const QVariant &mountPoints)
402
462
emit updated ();
403
463
}
404
464
405
- qCInfo (lcMemoryCardLog) << " New file system mount points:" << mountPoints << " resolved mount path: " << m_mountPath << " trigger update:" << triggerUpdate;
465
+ qCInfo (lcMemoryCardLog) << " New file system mount points:" << filesystemInterface << " resolved mount path: " << m_mountPath << " trigger update:" << triggerUpdate;
406
466
emit mountPathChanged ();
407
467
}
408
468
@@ -421,79 +481,6 @@ bool UDisks2::Block::clearFormattingState()
421
481
return false ;
422
482
}
423
483
424
- void UDisks2::Block::getFileSystemInterface ()
425
- {
426
- QDBusInterface dbusPropertyInterface (UDISKS2_SERVICE,
427
- m_path,
428
- DBUS_OBJECT_PROPERTIES_INTERFACE,
429
- m_connection);
430
- QDBusPendingCall pendingCall = dbusPropertyInterface.asyncCall (DBUS_GET_ALL, UDISKS2_FILESYSTEM_INTERFACE);
431
- m_pendingFileSystem = new QDBusPendingCallWatcher (pendingCall, this );
432
- connect (m_pendingFileSystem, &QDBusPendingCallWatcher::finished, this , [this ](QDBusPendingCallWatcher *watcher) {
433
- if (watcher->isValid () && watcher->isFinished ()) {
434
- QDBusPendingReply<> reply = *watcher;
435
- QDBusMessage message = reply.reply ();
436
- updateMountPoint (message.arguments ().at (0 ));
437
- } else {
438
- QDBusError error = watcher->error ();
439
- qCWarning (lcMemoryCardLog) << " Error reading filesystem properties:" << error.name () << error.message () << m_path;
440
- m_mountable = false ;
441
- }
442
- m_pendingFileSystem->deleteLater ();
443
- m_pendingFileSystem = nullptr ;
444
- complete ();
445
- });
446
- }
447
-
448
- void UDisks2::Block::getEncryptedInterface ()
449
- {
450
- QDBusInterface dbusPropertyInterface (UDISKS2_SERVICE,
451
- m_path,
452
- DBUS_OBJECT_PROPERTIES_INTERFACE,
453
- m_connection);
454
- QDBusPendingCall pendingCall = dbusPropertyInterface.asyncCall (DBUS_GET_ALL, UDISKS2_ENCRYPTED_INTERFACE);
455
- m_pendingEncrypted = new QDBusPendingCallWatcher (pendingCall, this );
456
- connect (m_pendingEncrypted, &QDBusPendingCallWatcher::finished, this , [this ](QDBusPendingCallWatcher *watcher) {
457
- if (watcher->isValid () && watcher->isFinished ()) {
458
- m_encrypted = true ;
459
- } else {
460
- QDBusError error = watcher->error ();
461
- qCWarning (lcMemoryCardLog) << " Error reading encrypted properties:" << error.name () << error.message () << m_path;
462
- m_encrypted = false ;
463
- }
464
- m_pendingEncrypted->deleteLater ();
465
- m_pendingEncrypted = nullptr ;
466
- complete ();
467
- });
468
- }
469
-
470
- void UDisks2::Block::getDriveProperties ()
471
- {
472
- QDBusInterface drivePropertyInterface (UDISKS2_SERVICE,
473
- drive (),
474
- DBUS_OBJECT_PROPERTIES_INTERFACE,
475
- m_connection);
476
- QDBusPendingCall pendingCall = drivePropertyInterface.asyncCall (DBUS_GET_ALL, UDISKS2_DRIVE_INTERFACE);
477
- m_pendingDrive = new QDBusPendingCallWatcher (pendingCall, this );
478
- connect (m_pendingDrive, &QDBusPendingCallWatcher::finished, this , [this ](QDBusPendingCallWatcher *watcher) {
479
- if (watcher->isValid () && watcher->isFinished ()) {
480
- QDBusPendingReply<> reply = *watcher;
481
- QDBusMessage message = reply.reply ();
482
- QVariantMap driveProperties = NemoDBus::demarshallArgument<QVariantMap>(message.arguments ().at (0 ));
483
- qCInfo (lcMemoryCardLog) << " Drive properties:" << driveProperties;
484
- m_drive = driveProperties;
485
- } else {
486
- QDBusError error = watcher->error ();
487
- qCWarning (lcMemoryCardLog) << " Error reading drive properties:" << error.name () << error.message ();
488
- m_drive.clear ();
489
- }
490
-
491
- m_pendingDrive->deleteLater ();
492
- m_pendingDrive = nullptr ;
493
- complete ();
494
- });
495
- }
496
-
497
484
void UDisks2::Block::rescan (const QString &dbusObjectPath)
498
485
{
499
486
QVariantList arguments;
@@ -516,3 +503,35 @@ void UDisks2::Block::rescan(const QString &dbusObjectPath)
516
503
watcher->deleteLater ();
517
504
});
518
505
}
506
+
507
+ void UDisks2::Block::getProperties (const QString &path, const QString &interface,
508
+ QPointer<QDBusPendingCallWatcher> &watcherPointer,
509
+ std::function<void (const QVariantMap &)> success)
510
+ {
511
+ if (path.isEmpty () || path == QLatin1String (" /" )) {
512
+ qCInfo (lcMemoryCardLog) << " Ignoring get properties from path:" << path << " interface:" << interface;
513
+ return ;
514
+ }
515
+
516
+ QDBusInterface dbusPropertyInterface (UDISKS2_SERVICE,
517
+ path,
518
+ DBUS_OBJECT_PROPERTIES_INTERFACE,
519
+ m_connection);
520
+ QDBusPendingCall pendingCall = dbusPropertyInterface.asyncCall (DBUS_GET_ALL, interface);
521
+ watcherPointer = new QDBusPendingCallWatcher (pendingCall, this );
522
+ connect (watcherPointer.data (), &QDBusPendingCallWatcher::finished, this , [success, path, interface](QDBusPendingCallWatcher *watcher) {
523
+ if (watcher->isValid () && watcher->isFinished ()) {
524
+ QDBusPendingReply<> reply = *watcher;
525
+ QDBusMessage message = reply.reply ();
526
+ success (NemoDBus::demarshallArgument<QVariantMap>(message.arguments ().at (0 )));
527
+ } else {
528
+ qCDebug (lcMemoryCardLog) << " Get properties failed" << path << " interface:" << interface << watcher->isValid () << watcher->isFinished () << watcher->isError ();
529
+ QDBusPendingReply<> reply = *watcher;
530
+ QDBusMessage message = reply.reply ();
531
+ QDBusError error = watcher->error ();
532
+ qCDebug (lcMemoryCardLog) << " Error reading" << message.interface () << " properties:" << error.name () << error.message ();
533
+ }
534
+
535
+ watcher->deleteLater ();
536
+ });
537
+ }
0 commit comments