Changeset View
Changeset View
Standalone View
Standalone View
mpris2/dbusabstractadaptor.cpp
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | * Copyright 2018 Friedrich W. H. Kossebau <kossebau@kde.org> * | ||||
3 | * * | ||||
4 | * This program is free software; you can redistribute it and/or modify * | ||||
5 | * it under the terms of the GNU General Public License as published by * | ||||
6 | * the Free Software Foundation; either version 2 of the License, or * | ||||
7 | * (at your option) any later version. * | ||||
8 | ***************************************************************************/ | ||||
9 | | ||||
10 | #include "dbusabstractadaptor.h" | ||||
11 | | ||||
12 | // Qt | ||||
13 | #include <QMetaClassInfo> | ||||
14 | #include <QDBusMessage> | ||||
15 | #include <QDBusConnection> | ||||
16 | | ||||
17 | namespace Okular | ||||
18 | { | ||||
19 | | ||||
20 | DBusAbstractAdaptor::DBusAbstractAdaptor(const QString &objectDBusPath, QObject *parent) | ||||
21 | : QDBusAbstractAdaptor(parent) | ||||
22 | , mObjectPath(objectDBusPath) | ||||
23 | { | ||||
24 | Q_ASSERT(!mObjectPath.isEmpty()); | ||||
25 | } | ||||
26 | | ||||
27 | void DBusAbstractAdaptor::signalPropertyChange(const QString &propertyName, const QVariant &value) | ||||
28 | { | ||||
29 | const bool firstChange = mChangedProperties.isEmpty(); | ||||
30 | | ||||
31 | mChangedProperties.insert(propertyName, value); | ||||
32 | | ||||
33 | if (firstChange) { | ||||
34 | // trigger signal emission on next event loop | ||||
35 | QMetaObject::invokeMethod(this, "emitPropertiesChangeDBusSignal", Qt::QueuedConnection); | ||||
36 | } | ||||
37 | } | ||||
38 | | ||||
39 | | ||||
40 | void DBusAbstractAdaptor::emitPropertiesChangeDBusSignal() | ||||
41 | { | ||||
42 | if (mChangedProperties.isEmpty()) { | ||||
43 | return; | ||||
44 | } | ||||
45 | | ||||
46 | const QMetaObject* metaObject = this->metaObject(); | ||||
47 | const int dBusInterfaceNameIndex = metaObject->indexOfClassInfo("D-Bus Interface"); | ||||
48 | Q_ASSERT(dBusInterfaceNameIndex >= 0); | ||||
49 | const char* dBusInterfaceName = metaObject->classInfo(dBusInterfaceNameIndex).value(); | ||||
50 | | ||||
51 | QDBusMessage signalMessage = QDBusMessage::createSignal(mObjectPath, | ||||
52 | QStringLiteral("org.freedesktop.DBus.Properties"), | ||||
53 | QStringLiteral("PropertiesChanged")); | ||||
54 | signalMessage | ||||
55 | << dBusInterfaceName | ||||
56 | << mChangedProperties | ||||
57 | << QStringList(); | ||||
58 | | ||||
59 | QDBusConnection::sessionBus().send(signalMessage); | ||||
60 | | ||||
61 | mChangedProperties.clear(); | ||||
62 | } | ||||
63 | | ||||
64 | } |