1 /*
2  * Copyright 2012  Alex Merry <alex.merry@kdemail.net>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef DBUSABSTRACTADAPTOR_H
27 #define DBUSABSTRACTADAPTOR_H
28 
29 #include <QDBusAbstractAdaptor>
30 #include <QDBusConnection>
31 
32 #include <QStringList>
33 #include <QVariantMap>
34 
35 class PropertiesChangedAdaptor : public QDBusAbstractAdaptor
36 {
37     Q_OBJECT
38     Q_CLASSINFO("D-Bus Interface", "org.freedesktop.DBus.Properties")
39 
40 public:
41     explicit PropertiesChangedAdaptor( QObject *parent );
42     void emitPropertiesChanged( const QString &interface,
43                                 const QVariantMap &updatedProperties,
44                                 const QStringList &invalidatedProperties );
45 
46 Q_SIGNALS:
47     void propertiesChanged( const QString &interface,
48                             const QVariantMap &updatedProperties,
49                             const QStringList &invalidatedProperties );
50 };
51 
52 /**
53  * Hack for property notification support
54  */
55 class DBusAbstractAdaptor : public QDBusAbstractAdaptor
56 {
57     Q_OBJECT
58 
59 public:
60     explicit DBusAbstractAdaptor( QObject *parent );
61 
62     // These are hackish methods that are necessary because
63     // of the way QtDBus is implemented; it is impossible to
64     // find out what bus or path this adaptor is at, and adding
65     // another adaptor for the properties interface prevents
66     // Qt's internal properties implementation from working
67     QDBusConnection connection() const;
68     void setConnection( const QDBusConnection &conn );
69     QString dBusPath() const;
70     void setDBusPath( const QString &path );
71 
72 protected:
73     void signalPropertyChange( const QString &property, const QVariant &value );
74     void signalPropertyChange( const QString &property );
75 
76 private Q_SLOTS:
77     void _m_emitPropertiesChanged();
78 
79 private:
80     QStringList     m_invalidatedProperties;
81     QVariantMap     m_updatedProperties;
82     QString         m_path;
83     QDBusConnection m_connection;
84 };
85 
86 #endif // DBUSABSTRACTADAPTOR_H
87