Changeset View
Changeset View
Standalone View
Standalone View
lib/mpris2/dbusabstractadaptor.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Gwenview: an image viewer | ||||
3 | Copyright 2018 Friedrich W. H. Kossebau <kossebau@kde.org> | ||||
4 | | ||||
5 | This program is free software; you can redistribute it and/or | ||||
6 | modify it under the terms of the GNU General Public License | ||||
7 | as published by the Free Software Foundation; either version 2 | ||||
8 | of the License, or (at your option) any later version. | ||||
9 | | ||||
10 | This program is distributed in the hope that it will be useful, | ||||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
13 | GNU General Public License for more details. | ||||
14 | | ||||
15 | You should have received a copy of the GNU General Public License | ||||
16 | along with this program; if not, write to the Free Software | ||||
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #include "dbusabstractadaptor.h" | ||||
21 | | ||||
22 | // Qt | ||||
23 | #include <QMetaClassInfo> | ||||
24 | #include <QDBusMessage> | ||||
25 | #include <QDBusConnection> | ||||
26 | | ||||
27 | namespace Gwenview | ||||
28 | { | ||||
29 | | ||||
30 | DBusAbstractAdaptor::DBusAbstractAdaptor(const QString &objectDBusPath, QObject *parent) | ||||
31 | : QDBusAbstractAdaptor(parent) | ||||
32 | , mObjectPath(objectDBusPath) | ||||
33 | { | ||||
34 | Q_ASSERT(!mObjectPath.isEmpty()); | ||||
35 | } | ||||
36 | | ||||
37 | void DBusAbstractAdaptor::signalPropertyChange(const QString &propertyName, const QVariant &value) | ||||
38 | { | ||||
39 | const bool firstChange = mChangedProperties.isEmpty(); | ||||
40 | | ||||
41 | mChangedProperties.insert(propertyName, value); | ||||
42 | | ||||
43 | if (firstChange) { | ||||
44 | // trigger signal emission on next event loop | ||||
45 | QMetaObject::invokeMethod(this, "emitPropertiesChangeDBusSignal", Qt::QueuedConnection); | ||||
46 | } | ||||
47 | } | ||||
48 | | ||||
49 | | ||||
50 | void DBusAbstractAdaptor::emitPropertiesChangeDBusSignal() | ||||
51 | { | ||||
52 | if (mChangedProperties.isEmpty()) { | ||||
53 | return; | ||||
54 | } | ||||
55 | | ||||
56 | const QMetaObject* metaObject = this->metaObject(); | ||||
57 | const int dBusInterfaceNameIndex = metaObject->indexOfClassInfo("D-Bus Interface"); | ||||
58 | Q_ASSERT(dBusInterfaceNameIndex >= 0); | ||||
59 | const char* dBusInterfaceName = metaObject->classInfo(dBusInterfaceNameIndex).value(); | ||||
60 | | ||||
61 | QDBusMessage signalMessage = QDBusMessage::createSignal(mObjectPath, | ||||
62 | QStringLiteral("org.freedesktop.DBus.Properties"), | ||||
63 | QStringLiteral("PropertiesChanged")); | ||||
64 | signalMessage | ||||
65 | << dBusInterfaceName | ||||
66 | << mChangedProperties | ||||
67 | << QStringList(); | ||||
68 | | ||||
69 | QDBusConnection::sessionBus().send(signalMessage); | ||||
70 | | ||||
71 | mChangedProperties.clear(); | ||||
72 | } | ||||
73 | | ||||
74 | } |