File indexing completed on 2024-05-12 04:19:46
0001 /* 0002 Gwenview: an image viewer 0003 Copyright 2018 Friedrich W. H. Kossebau <kossebau@kde.org> 0004 0005 This program is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU General Public License 0007 as published by the Free Software Foundation; either version 2 0008 of the License, or (at your option) any later version. 0009 0010 This program is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 GNU General Public License for more details. 0014 0015 You should have received a copy of the GNU General Public License 0016 along with this program; if not, write to the Free Software 0017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef DBUSABSTRACTADAPTOR_H 0021 #define DBUSABSTRACTADAPTOR_H 0022 0023 // Qt 0024 #include <QDBusAbstractAdaptor> 0025 #include <QVariantMap> 0026 0027 namespace Gwenview 0028 { 0029 /** 0030 * Extension of QDBusAbstractAdaptor for proper signalling of D-Bus object property changes 0031 * 0032 * QDBusAbstractAdaptor seems to fail on mapping QObject properties 0033 * to D-Bus object properties when it comes to signalling changes to a property. 0034 * The NOTIFY entry of Q_PROPERTY is not turned into respective D-Bus signalling of a 0035 * property change. So we have to do this explicitly ourselves, instead of using a normal 0036 * QObject signal and expecting the adaptor to translate it. 0037 * 0038 * To reduce D-Bus traffic, all registered property changes are accumulated and squashed 0039 * between event loops where then the D-Bus signal is emitted. 0040 */ 0041 class DBusAbstractAdaptor : public QDBusAbstractAdaptor 0042 { 0043 Q_OBJECT 0044 0045 public: 0046 /** 0047 * Ideally we could query the D-Bus path of the object when used, but no idea yet how to do that. 0048 * So one has to additionally pass here the D-Bus path at which the object is registered 0049 * for which this interface is added. 0050 * 0051 * @param objectDBusPath D-Bus name of the property 0052 * @param parent memory management parent or nullptr 0053 */ 0054 explicit DBusAbstractAdaptor(const QString &objectDBusPath, QObject *parent); 0055 0056 protected: 0057 /** 0058 * @param propertyName D-Bus name of the property 0059 * @param value the new value of the property 0060 */ 0061 void signalPropertyChange(const QString &propertyName, const QVariant &value); 0062 0063 private Q_SLOTS: 0064 void emitPropertiesChangeDBusSignal(); 0065 0066 private: 0067 QVariantMap mChangedProperties; 0068 const QString mObjectPath; 0069 }; 0070 0071 } 0072 0073 #endif // DBUSABSTRACTADAPTOR_H