| 1 | /* This file is part of the dbusmenu-qt library |
| 2 | Copyright 2009 Canonical |
| 3 | Author: Aurelien Gateau <[email protected]> |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Library General Public |
| 7 | License (LGPL) as published by the Free Software Foundation; |
| 8 | either version 2 of the License, or (at your option) any later |
| 9 | version. |
| 10 | |
| 11 | This library is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | Library General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU Library General Public License |
| 17 | along with this library; see the file COPYING.LIB. If not, write to |
| 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 | Boston, MA 02110-1301, USA. |
| 20 | */ |
| 21 | #include "dbusmenutypes_p.h" |
| 22 | |
| 23 | // Local |
| 24 | #include <dbusmenushortcut_p.h> |
| 25 | #include <debug_p.h> |
| 26 | |
| 27 | // Qt |
| 28 | #include <QDBusArgument> |
| 29 | #include <QDBusMetaType> |
| 30 | |
| 31 | //// DBusMenuItem |
| 32 | QDBusArgument &operator<<(QDBusArgument &argument, const DBusMenuItem &obj) |
| 33 | { |
| 34 | argument.beginStructure(); |
| 35 | argument << obj.id << obj.properties; |
| 36 | argument.endStructure(); |
| 37 | return argument; |
| 38 | } |
| 39 | |
| 40 | const QDBusArgument &operator>>(const QDBusArgument &argument, DBusMenuItem &obj) |
| 41 | { |
| 42 | argument.beginStructure(); |
| 43 | argument >> obj.id >> obj.properties; |
| 44 | argument.endStructure(); |
| 45 | return argument; |
| 46 | } |
| 47 | |
| 48 | //// DBusMenuItemKeys |
| 49 | QDBusArgument &operator<<(QDBusArgument &argument, const DBusMenuItemKeys &obj) |
| 50 | { |
| 51 | argument.beginStructure(); |
| 52 | argument << obj.id << obj.properties; |
| 53 | argument.endStructure(); |
| 54 | return argument; |
| 55 | } |
| 56 | |
| 57 | const QDBusArgument &operator>>(const QDBusArgument &argument, DBusMenuItemKeys &obj) |
| 58 | { |
| 59 | argument.beginStructure(); |
| 60 | argument >> obj.id >> obj.properties; |
| 61 | argument.endStructure(); |
| 62 | return argument; |
| 63 | } |
| 64 | |
| 65 | //// DBusMenuLayoutItem |
| 66 | QDBusArgument &operator<<(QDBusArgument &argument, const DBusMenuLayoutItem &obj) |
| 67 | { |
| 68 | argument.beginStructure(); |
| 69 | argument << obj.id << obj.properties; |
| 70 | argument.beginArray(qMetaTypeId<QDBusVariant>()); |
| 71 | Q_FOREACH(const DBusMenuLayoutItem& child, obj.children) { |
| 72 | argument << QDBusVariant(QVariant::fromValue<DBusMenuLayoutItem>(child)); |
| 73 | } |
| 74 | argument.endArray(); |
| 75 | argument.endStructure(); |
| 76 | return argument; |
| 77 | } |
| 78 | |
| 79 | const QDBusArgument &operator>>(const QDBusArgument &argument, DBusMenuLayoutItem &obj) |
| 80 | { |
| 81 | argument.beginStructure(); |
| 82 | argument >> obj.id >> obj.properties; |
| 83 | argument.beginArray(); |
| 84 | while (!argument.atEnd()) { |
| 85 | QDBusVariant dbusVariant; |
| 86 | argument >> dbusVariant; |
| 87 | QDBusArgument childArgument = dbusVariant.variant().value<QDBusArgument>(); |
| 88 | |
| 89 | DBusMenuLayoutItem child; |
| 90 | childArgument >> child; |
| 91 | obj.children.append(child); |
| 92 | } |
| 93 | argument.endArray(); |
| 94 | argument.endStructure(); |
| 95 | return argument; |
| 96 | } |
| 97 | |
| 98 | void DBusMenuTypes_register() |
| 99 | { |
| 100 | static bool registered = false; |
| 101 | if (registered) { |
| 102 | return; |
| 103 | } |
| 104 | qDBusRegisterMetaType<DBusMenuItem>(); |
| 105 | qDBusRegisterMetaType<DBusMenuItemList>(); |
| 106 | qDBusRegisterMetaType<DBusMenuItemKeys>(); |
| 107 | qDBusRegisterMetaType<DBusMenuItemKeysList>(); |
| 108 | qDBusRegisterMetaType<DBusMenuLayoutItem>(); |
| 109 | qDBusRegisterMetaType<DBusMenuLayoutItemList>(); |
| 110 | qDBusRegisterMetaType<DBusMenuShortcut>(); |
| 111 | registered = true; |
| 112 | } |