Commit 01f8a746 authored by Gleb Popov's avatar Gleb Popov

Rename ObjectManager::addInterface to addInterfaces() and make it signal all

added interfaces at once.

Reported by: tijl
parent a32bcc3d2fe0
......@@ -274,16 +274,19 @@ bool ObjectManager::registerBlock(Block* b, bool tryPostponed)
qDebug() << "Registering " + devPath;
QDBusConnection::systemBus().registerObject(devPath, b);
addInterface(b->dbusPath, QStringLiteral("org.freedesktop.UDisks2.Block"), new BlockAdaptor(b));
QList<std::pair<QString, QDBusAbstractAdaptor*>> interfaces;
interfaces << std::make_pair(QStringLiteral("org.freedesktop.UDisks2.Block"), new BlockAdaptor(b));
if(b->bFilesystem)
addInterface(b->dbusPath, QStringLiteral("org.freedesktop.UDisks2.Filesystem"), new FilesystemAdaptor(b));
interfaces << std::make_pair(QStringLiteral("org.freedesktop.UDisks2.Filesystem"), new FilesystemAdaptor(b));
if(b->bPartTable)
addInterface(b->dbusPath, QStringLiteral("org.freedesktop.UDisks2.PartitionTable"), new PartitionTableAdaptor(b));
interfaces << std::make_pair(QStringLiteral("org.freedesktop.UDisks2.PartitionTable"), new PartitionTableAdaptor(b));
if(b->bPartition)
addInterface(b->dbusPath, "org.freedesktop.UDisks2.Partition", new PartitionAdaptor(b));
interfaces << std::make_pair(QStringLiteral("org.freedesktop.UDisks2.Partition"), new PartitionAdaptor(b));
addInterfaces(b->dbusPath, interfaces);
}
else {} // we were updating things after updateBlock()
......@@ -301,7 +304,7 @@ void ObjectManager::registerDrive(Drive* d)
qDebug() << "Registering " + dbusPath;
QDBusConnection::systemBus().registerObject(dbusPath, d);
addInterface(d->dbusPath, "org.freedesktop.UDisks2.Drive", new DriveAdaptor(d));
addInterfaces(d->dbusPath, {std::make_pair("org.freedesktop.UDisks2.Drive", new DriveAdaptor(d))});
tryRegisterPostponed();
}
......@@ -433,18 +436,24 @@ void ObjectManager::addPartition(Block* b, const QString& tableBlockName, const
}
void ObjectManager::addInterface(QDBusObjectPath path, QString iface, QDBusAbstractAdaptor* adaptor)
void ObjectManager::addInterfaces(QDBusObjectPath path, QList<std::pair<QString, QDBusAbstractAdaptor*>> newInterfaces)
{
QVariantMapMap& interfaces = m_managedObjects[path];
QVariantMap properties;
for (int i = adaptor->metaObject()->propertyOffset();
i < adaptor->metaObject()->propertyCount(); ++i) {
auto propertyName = adaptor->metaObject()->property(i).name();
properties.insert(QString::fromLatin1(propertyName), adaptor->property(propertyName));
}
for (auto pair : newInterfaces)
{
const QString& iface = pair.first;
QDBusAbstractAdaptor* adaptor = pair.second;
QVariantMap properties;
for (int i = adaptor->metaObject()->propertyOffset();
i < adaptor->metaObject()->propertyCount(); ++i) {
auto propertyName = adaptor->metaObject()->property(i).name();
properties.insert(QString::fromLatin1(propertyName), adaptor->property(propertyName));
}
interfaces[iface] = properties;
interfaces[iface] = properties;
}
emit InterfacesAdded(path, interfaces);
}
......
......@@ -68,7 +68,7 @@ private:
void addPartition(Block* b, const QString& tableBlockName, const Part& partInfo);
void addInterface(QDBusObjectPath path, QString iface, QDBusAbstractAdaptor* adaptor);
void addInterfaces(QDBusObjectPath path, QList<std::pair<QString, QDBusAbstractAdaptor*>> newInterfaces);
void removeInterfaces(QDBusObjectPath path, QStringList ifaces);
DBUSManagerStruct m_managedObjects;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment