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
57class Q_DBUS_EXPORT QDBusObjectPath
58{
59 QString m_path;
60public:
61 QDBusObjectPath() noexcept : m_path() {}
62 // compiler-generated copy/move constructor/assignment operators are ok!
63 // compiler-generated destructor is ok!
64
65 inline explicit QDBusObjectPath(const char *path);
66 inline explicit QDBusObjectPath(QLatin1String path);
67 inline explicit QDBusObjectPath(const QString &path);
68 explicit QDBusObjectPath(QString &&p) : m_path(std::move(p)) { doCheck(); }
69
70 void swap(QDBusObjectPath &other) noexcept { qSwap(value1&: m_path, value2&: other.m_path); }
71
72 inline void setPath(const QString &path);
73
74 inline QString path() const
75 { return m_path; }
76
77 operator QVariant() const;
78
79private:
80 void doCheck();
81};
82Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QDBusObjectPath)
83
84inline QDBusObjectPath::QDBusObjectPath(const char *objectPath)
85 : m_path(QString::fromLatin1(str: objectPath))
86{ doCheck(); }
87
88inline QDBusObjectPath::QDBusObjectPath(QLatin1String objectPath)
89 : m_path(objectPath)
90{ doCheck(); }
91
92inline QDBusObjectPath::QDBusObjectPath(const QString &objectPath)
93 : m_path(objectPath)
94{ doCheck(); }
95
96inline void QDBusObjectPath::setPath(const QString &objectPath)
97{ m_path = objectPath; doCheck(); }
98
99inline bool operator==(const QDBusObjectPath &lhs, const QDBusObjectPath &rhs)
100{ return lhs.path() == rhs.path(); }
101
102inline bool operator!=(const QDBusObjectPath &lhs, const QDBusObjectPath &rhs)
103{ return lhs.path() != rhs.path(); }
104
105inline bool operator<(const QDBusObjectPath &lhs, const QDBusObjectPath &rhs)
106{ return lhs.path() < rhs.path(); }
107
108inline uint qHash(const QDBusObjectPath &objectPath, uint seed = 0)
109{ return qHash(key: objectPath.path(), seed); }
110
111
112class Q_DBUS_EXPORT QDBusSignature
113{
114 QString m_signature;
115public:
116 QDBusSignature() noexcept : m_signature() {}
117 // compiler-generated copy/move constructor/assignment operators are ok!
118 // compiler-generated destructor is ok!
119
120 inline explicit QDBusSignature(const char *signature);
121 inline explicit QDBusSignature(QLatin1String signature);
122 inline explicit QDBusSignature(const QString &signature);
123 explicit QDBusSignature(QString &&sig) : m_signature(std::move(sig)) { doCheck(); }
124
125 void swap(QDBusSignature &other) noexcept { qSwap(value1&: m_signature, value2&: other.m_signature); }
126
127 inline void setSignature(const QString &signature);
128
129 inline QString signature() const
130 { return m_signature; }
131
132private:
133 void doCheck();
134};
135Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QDBusSignature)
136
137inline QDBusSignature::QDBusSignature(const char *dBusSignature)
138 : m_signature(QString::fromLatin1(str: dBusSignature))
139{ doCheck(); }
140
141inline QDBusSignature::QDBusSignature(QLatin1String dBusSignature)
142 : m_signature(dBusSignature)
143{ doCheck(); }
144
145inline QDBusSignature::QDBusSignature(const QString &dBusSignature)
146 : m_signature(dBusSignature)
147{ doCheck(); }
148
149inline void QDBusSignature::setSignature(const QString &dBusSignature)
150{ m_signature = dBusSignature; doCheck(); }
151
152inline bool operator==(const QDBusSignature &lhs, const QDBusSignature &rhs)
153{ return lhs.signature() == rhs.signature(); }
154
155inline bool operator!=(const QDBusSignature &lhs, const QDBusSignature &rhs)
156{ return lhs.signature() != rhs.signature(); }
157
158inline bool operator<(const QDBusSignature &lhs, const QDBusSignature &rhs)
159{ return lhs.signature() < rhs.signature(); }
160
161inline uint qHash(const QDBusSignature &signature, uint seed = 0)
162{ return qHash(key: signature.signature(), seed); }
163
164class QDBusVariant
165{
166 QVariant m_variant;
167public:
168 QDBusVariant() noexcept : m_variant() {}
169 // compiler-generated copy/move constructor/assignment operators are ok!
170 // compiler-generated destructor is ok!
171
172 inline explicit QDBusVariant(const QVariant &variant);
173 explicit QDBusVariant(QVariant &&v) noexcept : m_variant(std::move(v)) {}
174
175 void swap(QDBusVariant &other) noexcept { qSwap(value1&: m_variant, value2&: other.m_variant); }
176
177 inline void setVariant(const QVariant &variant);
178
179 inline QVariant variant() const
180 { return m_variant; }
181};
182Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QDBusVariant)
183
184inline QDBusVariant::QDBusVariant(const QVariant &dBusVariant)
185 : m_variant(dBusVariant) { }
186
187inline void QDBusVariant::setVariant(const QVariant &dBusVariant)
188{ m_variant = dBusVariant; }
189
190inline bool operator==(const QDBusVariant &v1, const QDBusVariant &v2)
191{ return v1.variant() == v2.variant(); }
192
193QT_END_NAMESPACE
194
195Q_DECLARE_METATYPE(QDBusVariant)
196Q_DECLARE_METATYPE(QDBusObjectPath)
197Q_DECLARE_METATYPE(QDBusSignature)
198
199#endif // QT_NO_DBUS
200#endif
201

source code of qtbase/src/dbus/qdbusextratypes.h