feat: add objectManager interface

refact the way to get DBus interface from Qt Meta System

Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
ComixHe
2023-08-18 10:01:52 +08:00
committed by Comix
parent bb83716d27
commit d49a99d252
12 changed files with 165 additions and 71 deletions

View File

@ -23,6 +23,7 @@
#include "config.h"
using IconMap = QMap<QString, QMap<uint, QMap<QString, QDBusUnixFileDescriptor>>>;
using ObjectMap = QMap<QDBusObjectPath, QStringList>;
inline QString getApplicationLauncherBinary()
{
@ -185,11 +186,9 @@ private:
bool registerObjectToDBus(QObject *o, const QString &path, const QString &interface);
void unregisterObjectFromDBus(const QString &path);
template <typename T>
QString getDBusInterface()
inline QString getDBusInterface(const QMetaType &meta)
{
auto meta = QMetaType::fromType<T>();
auto infoObject = meta.metaObject();
const auto *infoObject = meta.metaObject();
if (auto infoIndex = infoObject->indexOfClassInfo("D-Bus Interface"); infoIndex != -1) {
return infoObject->classInfo(infoIndex).value();
}
@ -197,6 +196,19 @@ QString getDBusInterface()
return {};
}
inline QStringList getInterfacesListFromObject(QObject *o)
{
auto childs = o->children();
QStringList interfaces;
std::for_each(childs.cbegin(), childs.cend(), [&interfaces](QObject *app) {
if (app->inherits("QDBusAbstractAdaptor")) {
interfaces.emplace_back(getDBusInterface(app->metaObject()->metaType()));
}
});
return interfaces;
}
inline uid_t getCurrentUID()
{
return getuid(); // current use linux getuid