File indexing completed on 2024-05-19 04:49:36
0001 /* 0002 * Copyright 2012 Alex Merry <alex.merry@kdemail.net> 0003 * 0004 * Redistribution and use in source and binary forms, with or without 0005 * modification, are permitted provided that the following conditions 0006 * are met: 0007 * 0008 * 1. Redistributions of source code must retain the above copyright 0009 * notice, this list of conditions and the following disclaimer. 0010 * 2. Redistributions in binary form must reproduce the above copyright 0011 * notice, this list of conditions and the following disclaimer in the 0012 * documentation and/or other materials provided with the distribution. 0013 * 0014 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 0015 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 0016 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 0017 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 0018 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 0019 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0020 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0021 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0022 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 0023 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0024 */ 0025 0026 #ifndef DBUSABSTRACTADAPTOR_H 0027 #define DBUSABSTRACTADAPTOR_H 0028 0029 #include <QDBusAbstractAdaptor> 0030 #include <QDBusConnection> 0031 0032 #include <QStringList> 0033 #include <QVariantMap> 0034 0035 class PropertiesChangedAdaptor : public QDBusAbstractAdaptor 0036 { 0037 Q_OBJECT 0038 Q_CLASSINFO("D-Bus Interface", "org.freedesktop.DBus.Properties") 0039 0040 public: 0041 explicit PropertiesChangedAdaptor( QObject *parent ); 0042 void emitPropertiesChanged( const QString &interface, 0043 const QVariantMap &updatedProperties, 0044 const QStringList &invalidatedProperties ); 0045 0046 Q_SIGNALS: 0047 void propertiesChanged( const QString &interface, 0048 const QVariantMap &updatedProperties, 0049 const QStringList &invalidatedProperties ); 0050 }; 0051 0052 /** 0053 * Hack for property notification support 0054 */ 0055 class DBusAbstractAdaptor : public QDBusAbstractAdaptor 0056 { 0057 Q_OBJECT 0058 0059 public: 0060 explicit DBusAbstractAdaptor( QObject *parent ); 0061 0062 // These are hackish methods that are necessary because 0063 // of the way QtDBus is implemented; it is impossible to 0064 // find out what bus or path this adaptor is at, and adding 0065 // another adaptor for the properties interface prevents 0066 // Qt's internal properties implementation from working 0067 QDBusConnection connection() const; 0068 void setConnection( const QDBusConnection &conn ); 0069 QString dBusPath() const; 0070 void setDBusPath( const QString &path ); 0071 0072 protected: 0073 void signalPropertyChange( const QString &property, const QVariant &value ); 0074 void signalPropertyChange( const QString &property ); 0075 0076 private Q_SLOTS: 0077 void _m_emitPropertiesChanged(); 0078 0079 private: 0080 QStringList m_invalidatedProperties; 0081 QVariantMap m_updatedProperties; 0082 QString m_path; 0083 QDBusConnection m_connection; 0084 }; 0085 0086 #endif // DBUSABSTRACTADAPTOR_H