Skip to content
This repository was archived by the owner on Apr 28, 2022. It is now read-only.

Commit c0ab8b7

Browse files
committed
Add addInterface and removeInterface methods to the Block
1 parent 12bb39b commit c0ab8b7

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

src/udisks2block.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,30 @@ QString UDisks2::Block::cryptoBackingDevicePath(const QString &objectPath)
321321
}
322322
}
323323

324+
void UDisks2::Block::addInterface(const QString &interface, QVariantMap propertyMap)
325+
{
326+
m_interfacePropertyMap.insert(interface, propertyMap);
327+
if (interface == UDISKS2_FILESYSTEM_INTERFACE) {
328+
setMountable(true);
329+
} else if (interface == UDISKS2_ENCRYPTED_INTERFACE) {
330+
setEncrypted(true);
331+
}
332+
}
333+
334+
void UDisks2::Block::removeInterface(const QString &interface)
335+
{
336+
m_interfacePropertyMap.remove(interface);
337+
if (interface == UDISKS2_BLOCK_INTERFACE) {
338+
m_data.clear();
339+
} else if (interface == UDISKS2_DRIVE_INTERFACE) {
340+
m_drive.clear();
341+
} else if (interface == UDISKS2_FILESYSTEM_INTERFACE) {
342+
setMountable(false);
343+
}else if (interface == UDISKS2_ENCRYPTED_INTERFACE) {
344+
setEncrypted(false);
345+
}
346+
}
347+
324348
void UDisks2::Block::updateProperties(const QDBusMessage &message)
325349
{
326350
QList<QVariant> arguments = message.arguments();

src/udisks2block_p.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Block : public QObject
5151
Block(const QString &path, const UDisks2::InterfacePropertyMap &interfacePropertyMap, QObject *parent = nullptr);
5252
Block& operator=(const Block& other);
5353

54-
~Block();
54+
virtual ~Block();
5555

5656
QString path() const;
5757

@@ -72,10 +72,7 @@ class Block : public QObject
7272
QString cryptoBackingDeviceObjectPath() const;
7373

7474
bool isEncrypted() const;
75-
bool setEncrypted(bool encrypted);
76-
7775
bool isMountable() const;
78-
bool setMountable(bool mountable);
7976

8077
bool isFormatting() const;
8178
bool setFormatting(bool formatting);
@@ -101,6 +98,9 @@ class Block : public QObject
10198

10299
static QString cryptoBackingDevicePath(const QString &objectPath);
103100

101+
void addInterface(const QString &interface, QVariantMap propertyMap);
102+
void removeInterface(const QString &interface);
103+
104104
signals:
105105
void completed();
106106
void updated();
@@ -111,6 +111,9 @@ private slots:
111111
void updateProperties(const QDBusMessage &message);
112112

113113
private:
114+
bool setEncrypted(bool encrypted);
115+
bool setMountable(bool mountable);
116+
114117
bool isCompleted() const;
115118
void updateMountPoint(const QVariant &mountPoints);
116119
void complete();
@@ -120,6 +123,8 @@ private slots:
120123
void getEncryptedInterface();
121124
void getDriveProperties();
122125

126+
void rescan(const QString &dbusObjectPath);
127+
123128
QString m_path;
124129
UDisks2::InterfacePropertyMap m_interfacePropertyMap;
125130
QVariantMap m_data;

src/udisks2monitor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,10 @@ void UDisks2::Monitor::interfacesAdded(const QDBusObjectPath &objectPath, const
232232
if (m_blockDevices.contains(path)) {
233233
UDisks2::Block *block = m_blockDevices.value(path);
234234
if (interfaces.contains(UDISKS2_FILESYSTEM_INTERFACE)) {
235-
block->setMountable(true);
235+
block->addInterface(UDISKS2_FILESYSTEM_INTERFACE, interfaces.value(UDISKS2_FILESYSTEM_INTERFACE));
236236
}
237237
if (interfaces.contains(UDISKS2_ENCRYPTED_INTERFACE)) {
238-
block->setEncrypted(true);
238+
block->addInterface(UDISKS2_ENCRYPTED_INTERFACE, interfaces.value(UDISKS2_ENCRYPTED_INTERFACE));
239239
}
240240
} else {
241241
QVariantMap dict = interfaces.value(UDISKS2_BLOCK_INTERFACE);
@@ -296,10 +296,10 @@ void UDisks2::Monitor::interfacesRemoved(const QDBusObjectPath &objectPath, cons
296296
} else if (m_blockDevices.contains(path)) {
297297
UDisks2::Block *block = m_blockDevices.value(path);
298298
if (interfaces.contains(UDISKS2_FILESYSTEM_INTERFACE)) {
299-
block->setMountable(false);
299+
block->removeInterface(UDISKS2_FILESYSTEM_INTERFACE);
300300
}
301301
if (interfaces.contains(UDISKS2_ENCRYPTED_INTERFACE)) {
302-
block->setEncrypted(false);
302+
block->removeInterface(UDISKS2_ENCRYPTED_INTERFACE);
303303
}
304304
}
305305
}

0 commit comments

Comments
 (0)