Changeset View
Changeset View
Standalone View
Standalone View
lib/mpris2/dbusabstractadaptor.h
- 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 | #ifndef DBUSABSTRACTADAPTOR_H | ||||
21 | #define DBUSABSTRACTADAPTOR_H | ||||
22 | | ||||
23 | // Qt | ||||
24 | #include <QDBusAbstractAdaptor> | ||||
25 | #include <QVariantMap> | ||||
26 | | ||||
27 | namespace Gwenview | ||||
28 | { | ||||
29 | | ||||
30 | /** | ||||
31 | * Extension of QDBusAbstractAdaptor for proper signalling of D-Bus object property changes | ||||
32 | * | ||||
33 | * QDBusAbstractAdaptor seems to fail on mapping QObject properties | ||||
34 | * to D-Bus object properties when it comes to signalling changes to a property. | ||||
35 | * The NOTIFY entry of Q_PROPERTY is not turned into respective D-Bus signalling of a | ||||
36 | * property change. So we have to do this explicitly ourselves, instead of using a normal | ||||
37 | * QObject signal and expecting the adaptor to translate it. | ||||
38 | * | ||||
39 | * To reduce D-Bus traffic, all registered property changes are accumulated and squashed | ||||
40 | * between event loops where then the D-Bus signal is emitted. | ||||
41 | */ | ||||
42 | class DBusAbstractAdaptor : public QDBusAbstractAdaptor | ||||
43 | { | ||||
44 | Q_OBJECT | ||||
45 | | ||||
46 | public: | ||||
47 | /** | ||||
48 | * Ideally we could query the D-Bus path of the object when used, but no idea yet how to do that. | ||||
49 | * So one has to additionally pass here the D-Bus path at which the object is registered | ||||
50 | * for which this interface is added. | ||||
51 | * | ||||
52 | * @param objectDBusPath D-Bus name of the property | ||||
53 | * @param parent memory management parent or nullptr | ||||
54 | */ | ||||
55 | explicit DBusAbstractAdaptor(const QString &objectDBusPath, QObject *parent); | ||||
56 | | ||||
57 | protected: | ||||
58 | /** | ||||
59 | * @param propertyName D-Bus name of the property | ||||
60 | * @param value the new value of the property | ||||
61 | */ | ||||
62 | void signalPropertyChange(const QString &propertyName, const QVariant &value); | ||||
63 | | ||||
64 | private Q_SLOTS: | ||||
65 | void emitPropertiesChangeDBusSignal(); | ||||
66 | | ||||
67 | private: | ||||
68 | QVariantMap mChangedProperties; | ||||
69 | const QString mObjectPath; | ||||
70 | }; | ||||
71 | | ||||
72 | } | ||||
73 | | ||||
74 | #endif // DBUSABSTRACTADAPTOR_H |