1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtDBus module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QDBUSEXTRATYPES_H
41#define QDBUSEXTRATYPES_H
42
43// define some useful types for D-BUS
44
45#include <QtDBus/qtdbusglobal.h>
46#include <QtCore/qvariant.h>
47#include <QtCore/qstring.h>
48#if QT_DEPRECATED_SINCE(5, 6)
49#include <QtCore/qhash.h>
50#endif
51#include <QtCore/qhashfunctions.h>
52
53#ifndef QT_NO_DBUS
54
55QT_BEGIN_NAMESPACE
56
57
58class Q_DBUS_EXPORT QDBusObjectPath
59{
60 QString m_path;
61public:
62 QDBusObjectPath() noexcept : m_path() {}
63 // compiler-generated copy/move constructor/assignment operators are ok!
64 // compiler-generated destructor is ok!
65
66 inline explicit QDBusObjectPath(const char *path);
67 inline explicit QDBusObjectPath(QLatin1String path);
68 inline explicit QDBusObjectPath(const QString &path);
69 explicit QDBusObjectPath(QString &&p) : m_path(std::move(p)) { doCheck(); }
70
71 void swap(QDBusObjectPath &other) noexcept { qSwap(m_path, other.m_path); }
72
73 inline void setPath(const QString &path);
74
75 inline QString path() const
76 { return m_path; }
77
78private:
79 void doCheck();
80};
81Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QDBusObjectPath)
82
83inline QDBusObjectPath::QDBusObjectPath(const char *objectPath)
84 : m_path(QString::fromLatin1(objectPath))
85{ doCheck(); }
86
87inline QDBusObjectPath::QDBusObjectPath(QLatin1String objectPath)
88 : m_path(objectPath)
89{ doCheck(); }
90
91inline QDBusObjectPath::QDBusObjectPath(const QString &objectPath)
92 : m_path(objectPath)
93{ doCheck(); }
94
95inline void QDBusObjectPath::setPath(const QString &objectPath)
96{ m_path = objectPath; doCheck(); }
97
98inline bool operator==(const QDBusObjectPath &lhs, const QDBusObjectPath &rhs)
99{ return lhs.path() == rhs.path(); }
100
101inline bool operator!=(const QDBusObjectPath &lhs, const QDBusObjectPath &rhs)
102{ return lhs.path() != rhs.path(); }
103
104inline bool operator<(const QDBusObjectPath &lhs, const QDBusObjectPath &rhs)
105{ return lhs.path() < rhs.path(); }
106
107inline uint qHash(const QDBusObjectPath &objectPath, uint seed = 0)
108{ return qHash(objectPath.path(), seed); }
109
110
111class Q_DBUS_EXPORT QDBusSignature
112{
113 QString m_signature;
114public:
115 QDBusSignature() noexcept : m_signature() {}
116 // compiler-generated copy/move constructor/assignment operators are ok!
117 // compiler-generated destructor is ok!
118
119 inline explicit QDBusSignature(const char *signature);
120 inline explicit QDBusSignature(QLatin1String signature);
121 inline explicit QDBusSignature(const QString &signature);
122 explicit QDBusSignature(QString &&sig) : m_signature(std::move(sig)) { doCheck(); }
123
124 void swap(QDBusSignature &other) noexcept { qSwap(m_signature, other.m_signature); }
125
126 inline void setSignature(const QString &signature);
127
128 inline QString signature() const
129 { return m_signature; }
130
131private:
132 void doCheck();
133};
134Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QDBusSignature)
135
136inline QDBusSignature::QDBusSignature(const char *dBusSignature)
137 : m_signature(QString::fromLatin1(dBusSignature))
138{ doCheck(); }
139
140inline QDBusSignature::QDBusSignature(QLatin1String dBusSignature)
141 : m_signature(dBusSignature)
142{ doCheck(); }
143
144inline QDBusSignature::QDBusSignature(const QString &dBusSignature)
145 : m_signature(dBusSignature)
146{ doCheck(); }
147
148inline void QDBusSignature::setSignature(const QString &dBusSignature)
149{ m_signature = dBusSignature; doCheck(); }
150
151inline bool operator==(const QDBusSignature &lhs, const QDBusSignature &rhs)
152{ return lhs.signature() == rhs.signature(); }
153
154inline bool operator!=(const QDBusSignature &lhs, const QDBusSignature &rhs)
155{ return lhs.signature() != rhs.signature(); }
156
157inline bool operator<(const QDBusSignature &lhs, const QDBusSignature &rhs)
158{ return lhs.signature() < rhs.signature(); }
159
160inline uint qHash(const QDBusSignature &signature, uint seed = 0)
161{ return qHash(signature.signature(), seed); }
162
163class QDBusVariant
164{
165 QVariant m_variant;
166public:
167 QDBusVariant() noexcept : m_variant() {}
168 // compiler-generated copy/move constructor/assignment operators are ok!
169 // compiler-generated destructor is ok!
170
171 inline explicit QDBusVariant(const QVariant &variant);
172 explicit QDBusVariant(QVariant &&v) noexcept : m_variant(std::move(v)) {}
173
174 void swap(QDBusVariant &other) noexcept { qSwap(m_variant, other.m_variant); }
175
176 inline void setVariant(const QVariant &variant);
177
178 inline QVariant variant() const
179 { return m_variant; }
180};
181Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QDBusVariant)
182
183inline QDBusVariant::QDBusVariant(const QVariant &dBusVariant)
184 : m_variant(dBusVariant) { }
185
186inline void QDBusVariant::setVariant(const QVariant &dBusVariant)
187{ m_variant = dBusVariant; }
188
189inline bool operator==(const QDBusVariant &v1, const QDBusVariant &v2)
190{ return v1.variant() == v2.variant(); }
191
192QT_END_NAMESPACE
193
194Q_DECLARE_METATYPE(QDBusVariant)
195Q_DECLARE_METATYPE(QDBusObjectPath)
196Q_DECLARE_METATYPE(QDBusSignature)
197
198#endif // QT_NO_DBUS
199#endif
200