Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add addInterface and removeInterface methods to the Block
  • Loading branch information
rainemak committed Nov 22, 2018
1 parent 12bb39b commit c0ab8b7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
24 changes: 24 additions & 0 deletions src/udisks2block.cpp
Expand Up @@ -321,6 +321,30 @@ QString UDisks2::Block::cryptoBackingDevicePath(const QString &objectPath)
}
}

void UDisks2::Block::addInterface(const QString &interface, QVariantMap propertyMap)
{
m_interfacePropertyMap.insert(interface, propertyMap);
if (interface == UDISKS2_FILESYSTEM_INTERFACE) {
setMountable(true);
} else if (interface == UDISKS2_ENCRYPTED_INTERFACE) {
setEncrypted(true);
}
}

void UDisks2::Block::removeInterface(const QString &interface)
{
m_interfacePropertyMap.remove(interface);
if (interface == UDISKS2_BLOCK_INTERFACE) {
m_data.clear();
} else if (interface == UDISKS2_DRIVE_INTERFACE) {
m_drive.clear();
} else if (interface == UDISKS2_FILESYSTEM_INTERFACE) {
setMountable(false);
}else if (interface == UDISKS2_ENCRYPTED_INTERFACE) {
setEncrypted(false);
}
}

void UDisks2::Block::updateProperties(const QDBusMessage &message)
{
QList<QVariant> arguments = message.arguments();
Expand Down
13 changes: 9 additions & 4 deletions src/udisks2block_p.h
Expand Up @@ -51,7 +51,7 @@ class Block : public QObject
Block(const QString &path, const UDisks2::InterfacePropertyMap &interfacePropertyMap, QObject *parent = nullptr);
Block& operator=(const Block& other);

~Block();
virtual ~Block();

QString path() const;

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

bool isEncrypted() const;
bool setEncrypted(bool encrypted);

bool isMountable() const;
bool setMountable(bool mountable);

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

static QString cryptoBackingDevicePath(const QString &objectPath);

void addInterface(const QString &interface, QVariantMap propertyMap);
void removeInterface(const QString &interface);

signals:
void completed();
void updated();
Expand All @@ -111,6 +111,9 @@ private slots:
void updateProperties(const QDBusMessage &message);

private:
bool setEncrypted(bool encrypted);
bool setMountable(bool mountable);

bool isCompleted() const;
void updateMountPoint(const QVariant &mountPoints);
void complete();
Expand All @@ -120,6 +123,8 @@ private slots:
void getEncryptedInterface();
void getDriveProperties();

void rescan(const QString &dbusObjectPath);

QString m_path;
UDisks2::InterfacePropertyMap m_interfacePropertyMap;
QVariantMap m_data;
Expand Down
8 changes: 4 additions & 4 deletions src/udisks2monitor.cpp
Expand Up @@ -232,10 +232,10 @@ void UDisks2::Monitor::interfacesAdded(const QDBusObjectPath &objectPath, const
if (m_blockDevices.contains(path)) {
UDisks2::Block *block = m_blockDevices.value(path);
if (interfaces.contains(UDISKS2_FILESYSTEM_INTERFACE)) {
block->setMountable(true);
block->addInterface(UDISKS2_FILESYSTEM_INTERFACE, interfaces.value(UDISKS2_FILESYSTEM_INTERFACE));
}
if (interfaces.contains(UDISKS2_ENCRYPTED_INTERFACE)) {
block->setEncrypted(true);
block->addInterface(UDISKS2_ENCRYPTED_INTERFACE, interfaces.value(UDISKS2_ENCRYPTED_INTERFACE));
}
} else {
QVariantMap dict = interfaces.value(UDISKS2_BLOCK_INTERFACE);
Expand Down Expand Up @@ -296,10 +296,10 @@ void UDisks2::Monitor::interfacesRemoved(const QDBusObjectPath &objectPath, cons
} else if (m_blockDevices.contains(path)) {
UDisks2::Block *block = m_blockDevices.value(path);
if (interfaces.contains(UDISKS2_FILESYSTEM_INTERFACE)) {
block->setMountable(false);
block->removeInterface(UDISKS2_FILESYSTEM_INTERFACE);
}
if (interfaces.contains(UDISKS2_ENCRYPTED_INTERFACE)) {
block->setEncrypted(false);
block->removeInterface(UDISKS2_ENCRYPTED_INTERFACE);
}
}
}
Expand Down

0 comments on commit c0ab8b7

Please sign in to comment.