Merge remote-tracking branch 'origin/api_changes'
[profile/ivi/qtbase.git] / src / dbus / qdbusextratypes.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtDBus module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QDBUSEXTRATYPES_H
43 #define QDBUSEXTRATYPES_H
44
45 // define some useful types for D-BUS
46
47 #include <QtCore/qvariant.h>
48 #include <QtCore/qstring.h>
49 #include <QtDBus/qdbusmacros.h>
50 #include <QtCore/qhash.h>
51
52 #ifndef QT_NO_DBUS
53
54 QT_BEGIN_HEADER
55
56 QT_BEGIN_NAMESPACE
57
58
59 class Q_DBUS_EXPORT QDBusObjectPath
60 {
61     QString m_path;
62 public:
63     inline QDBusObjectPath() { }
64
65     inline explicit QDBusObjectPath(const char *path);
66     inline explicit QDBusObjectPath(const QLatin1String &path);
67     inline explicit QDBusObjectPath(const QString &path);
68
69     inline void setPath(const QString &path);
70
71     inline QString path() const
72     { return m_path; }
73
74 private:
75     void doCheck();
76 };
77
78 inline QDBusObjectPath::QDBusObjectPath(const char *objectPath)
79     : m_path(QString::fromLatin1(objectPath))
80 { doCheck(); }
81
82 inline QDBusObjectPath::QDBusObjectPath(const QLatin1String &objectPath)
83     : m_path(objectPath)
84 { doCheck(); }
85
86 inline QDBusObjectPath::QDBusObjectPath(const QString &objectPath)
87     : m_path(objectPath)
88 { doCheck(); }
89
90 inline void QDBusObjectPath::setPath(const QString &objectPath)
91 { m_path = objectPath; doCheck(); }
92
93 inline bool operator==(const QDBusObjectPath &lhs, const QDBusObjectPath &rhs)
94 { return lhs.path() == rhs.path(); }
95
96 inline bool operator!=(const QDBusObjectPath &lhs, const QDBusObjectPath &rhs)
97 { return lhs.path() != rhs.path(); }
98
99 inline bool operator<(const QDBusObjectPath &lhs, const QDBusObjectPath &rhs)
100 { return lhs.path() < rhs.path(); }
101
102 inline uint qHash(const QDBusObjectPath &objectPath, uint seed)
103 { return qHash(objectPath.path(), seed); }
104
105
106 class Q_DBUS_EXPORT QDBusSignature
107 {
108     QString m_signature;
109 public:
110     inline QDBusSignature() { }
111
112     inline explicit QDBusSignature(const char *signature);
113     inline explicit QDBusSignature(const QLatin1String &signature);
114     inline explicit QDBusSignature(const QString &signature);
115
116     inline void setSignature(const QString &signature);
117
118     inline QString signature() const
119     { return m_signature; }
120
121 private:
122     void doCheck();
123 };
124
125 inline QDBusSignature::QDBusSignature(const char *dBusSignature)
126     : m_signature(QString::fromAscii(dBusSignature))
127 { doCheck(); }
128
129 inline QDBusSignature::QDBusSignature(const QLatin1String &dBusSignature)
130     : m_signature(dBusSignature)
131 { doCheck(); }
132
133 inline QDBusSignature::QDBusSignature(const QString &dBusSignature)
134     : m_signature(dBusSignature)
135 { doCheck(); }
136
137 inline void QDBusSignature::setSignature(const QString &dBusSignature)
138 { m_signature = dBusSignature; doCheck(); }
139
140 inline bool operator==(const QDBusSignature &lhs, const QDBusSignature &rhs)
141 { return lhs.signature() == rhs.signature(); }
142
143 inline bool operator!=(const QDBusSignature &lhs, const QDBusSignature &rhs)
144 { return lhs.signature() != rhs.signature(); }
145
146 inline bool operator<(const QDBusSignature &lhs, const QDBusSignature &rhs)
147 { return lhs.signature() < rhs.signature(); }
148
149 inline uint qHash(const QDBusSignature &signature, uint seed)
150 { return qHash(signature.signature(), seed); }
151
152 class QDBusVariant
153 {
154     QVariant m_variant;
155 public:
156     inline QDBusVariant() { }
157     inline explicit QDBusVariant(const QVariant &variant);
158
159     inline void setVariant(const QVariant &variant);
160
161     inline QVariant variant() const
162     { return m_variant; }
163 };
164
165 inline  QDBusVariant::QDBusVariant(const QVariant &dBusVariant)
166     : m_variant(dBusVariant) { }
167
168 inline void QDBusVariant::setVariant(const QVariant &dBusVariant)
169 { m_variant = dBusVariant; }
170
171 inline bool operator==(const QDBusVariant &v1, const QDBusVariant &v2)
172 { return v1.variant() == v2.variant(); }
173
174 QT_END_NAMESPACE
175
176 Q_DECLARE_METATYPE(QDBusVariant)
177 Q_DECLARE_METATYPE(QDBusObjectPath)
178 Q_DECLARE_METATYPE(QList<QDBusObjectPath>)
179 Q_DECLARE_METATYPE(QDBusSignature)
180 Q_DECLARE_METATYPE(QList<QDBusSignature>)
181
182 QT_END_HEADER
183
184 #endif // QT_NO_DBUS
185 #endif