| 1 | /* |
|---|---|
| 2 | This file is part of the KDE libraries |
| 3 | SPDX-FileCopyrightText: 2020 Henri Chain <henri.chain@enioka.com> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 6 | */ |
| 7 | |
| 8 | #ifndef DBUSTYPES_H |
| 9 | #define DBUSTYPES_H |
| 10 | |
| 11 | #include <QDBusArgument> |
| 12 | |
| 13 | struct QVariantMultiItem { |
| 14 | QString key; |
| 15 | QVariant value; |
| 16 | }; |
| 17 | Q_DECLARE_METATYPE(QVariantMultiItem) |
| 18 | using QVariantMultiMap = QList<QVariantMultiItem>; |
| 19 | Q_DECLARE_METATYPE(QVariantMultiMap) |
| 20 | |
| 21 | inline QDBusArgument &operator<<(QDBusArgument &argument, const QVariantMultiItem &item) |
| 22 | { |
| 23 | argument.beginStructure(); |
| 24 | argument << item.key << QDBusVariant(item.value); |
| 25 | argument.endStructure(); |
| 26 | return argument; |
| 27 | } |
| 28 | |
| 29 | inline const QDBusArgument &operator>>(const QDBusArgument &argument, QVariantMultiItem &item) |
| 30 | { |
| 31 | argument.beginStructure(); |
| 32 | argument >> item.key >> item.value; |
| 33 | argument.endStructure(); |
| 34 | return argument; |
| 35 | } |
| 36 | |
| 37 | struct ExecCommand { |
| 38 | QString path; |
| 39 | QStringList argv; |
| 40 | bool ignoreFailure; |
| 41 | }; |
| 42 | Q_DECLARE_METATYPE(ExecCommand) |
| 43 | using ExecCommandList = QList<ExecCommand>; |
| 44 | Q_DECLARE_METATYPE(ExecCommandList) |
| 45 | |
| 46 | inline QDBusArgument &operator<<(QDBusArgument &argument, const ExecCommand &execCommand) |
| 47 | { |
| 48 | argument.beginStructure(); |
| 49 | argument << execCommand.path << execCommand.argv << execCommand.ignoreFailure; |
| 50 | argument.endStructure(); |
| 51 | return argument; |
| 52 | } |
| 53 | |
| 54 | inline const QDBusArgument &operator>>(const QDBusArgument &argument, ExecCommand &execCommand) |
| 55 | { |
| 56 | argument.beginStructure(); |
| 57 | argument >> execCommand.path >> execCommand.argv >> execCommand.ignoreFailure; |
| 58 | argument.endStructure(); |
| 59 | return argument; |
| 60 | } |
| 61 | |
| 62 | struct TransientAux { |
| 63 | QString name; |
| 64 | QVariantMultiMap properties; |
| 65 | }; |
| 66 | Q_DECLARE_METATYPE(TransientAux) |
| 67 | using TransientAuxList = QList<TransientAux>; |
| 68 | Q_DECLARE_METATYPE(TransientAuxList) |
| 69 | |
| 70 | inline QDBusArgument &operator<<(QDBusArgument &argument, const TransientAux &aux) |
| 71 | { |
| 72 | argument.beginStructure(); |
| 73 | argument << aux.name << aux.properties; |
| 74 | argument.endStructure(); |
| 75 | return argument; |
| 76 | } |
| 77 | |
| 78 | inline const QDBusArgument &operator>>(const QDBusArgument &argument, TransientAux &aux) |
| 79 | { |
| 80 | argument.beginStructure(); |
| 81 | argument >> aux.name >> aux.properties; |
| 82 | argument.endStructure(); |
| 83 | return argument; |
| 84 | } |
| 85 | |
| 86 | #endif // DBUSTYPES_H |
| 87 |
