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 QtGui 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/*
41 This file was originally created by qdbusxml2cpp version 0.8
42 Command line was:
43 qdbusxml2cpp -a dbusmenu ../../3rdparty/dbus-ifaces/dbus-menu.xml
44
45 However it is maintained manually.
46*/
47
48#include "qdbusmenuadaptor_p.h"
49#include "qdbusplatformmenu_p.h"
50#include <QtCore/QMetaObject>
51#include <QtCore/QByteArray>
52#include <QtCore/QList>
53#include <QtCore/QMap>
54#include <QtCore/QString>
55#include <QtCore/QStringList>
56#include <QtCore/QVariant>
57
58QT_BEGIN_NAMESPACE
59
60QDBusMenuAdaptor::QDBusMenuAdaptor(QDBusPlatformMenu *topLevelMenu)
61 : QDBusAbstractAdaptor(topLevelMenu)
62 , m_topLevelMenu(topLevelMenu)
63{
64 setAutoRelaySignals(true);
65}
66
67QDBusMenuAdaptor::~QDBusMenuAdaptor()
68{
69}
70
71QString QDBusMenuAdaptor::status() const
72{
73 qCDebug(qLcMenu);
74 return QLatin1String("normal");
75}
76
77QString QDBusMenuAdaptor::textDirection() const
78{
79 return QLocale().textDirection() == Qt::RightToLeft ? QLatin1String("rtl") : QLatin1String("ltr");
80}
81
82uint QDBusMenuAdaptor::version() const
83{
84 return 4;
85}
86
87bool QDBusMenuAdaptor::AboutToShow(int id)
88{
89 qCDebug(qLcMenu) << id;
90 if (id == 0) {
91 emit m_topLevelMenu->aboutToShow();
92 } else {
93 QDBusPlatformMenuItem *item = QDBusPlatformMenuItem::byId(id);
94 if (item) {
95 const QDBusPlatformMenu *menu = static_cast<const QDBusPlatformMenu *>(item->menu());
96 if (menu)
97 emit const_cast<QDBusPlatformMenu *>(menu)->aboutToShow();
98 }
99 }
100 return false; // updateNeeded (we don't know that, so false)
101}
102
103QList<int> QDBusMenuAdaptor::AboutToShowGroup(const QList<int> &ids, QList<int> &idErrors)
104{
105 qCDebug(qLcMenu) << ids;
106 Q_UNUSED(idErrors);
107 idErrors.clear();
108 for (int id : ids)
109 AboutToShow(id);
110 return QList<int>(); // updatesNeeded
111}
112
113void QDBusMenuAdaptor::Event(int id, const QString &eventId, const QDBusVariant &data, uint timestamp)
114{
115 Q_UNUSED(data);
116 Q_UNUSED(timestamp);
117 QDBusPlatformMenuItem *item = QDBusPlatformMenuItem::byId(id);
118 qCDebug(qLcMenu) << id << (item ? item->text() : QLatin1String("")) << eventId;
119 if (item && eventId == QLatin1String("clicked"))
120 item->trigger();
121 if (item && eventId == QLatin1String("hovered"))
122 emit item->hovered();
123 if (eventId == QLatin1String("closed")) {
124 // There is no explicit AboutToHide method, so map closed event to aboutToHide method
125 const QDBusPlatformMenu *menu = nullptr;
126 if (item)
127 menu = static_cast<const QDBusPlatformMenu *>(item->menu());
128 else if (id == 0)
129 menu = m_topLevelMenu;
130 if (menu)
131 emit const_cast<QDBusPlatformMenu *>(menu)->aboutToHide();
132 }
133}
134
135QList<int> QDBusMenuAdaptor::EventGroup(const QDBusMenuEventList &events)
136{
137 for (const QDBusMenuEvent &ev : events)
138 Event(ev.m_id, ev.m_eventId, ev.m_data, ev.m_timestamp);
139 return QList<int>(); // idErrors
140}
141
142QDBusMenuItemList QDBusMenuAdaptor::GetGroupProperties(const QList<int> &ids, const QStringList &propertyNames)
143{
144 qCDebug(qLcMenu) << ids << propertyNames << "=>" << QDBusMenuItem::items(ids, propertyNames);
145 return QDBusMenuItem::items(ids, propertyNames);
146}
147
148uint QDBusMenuAdaptor::GetLayout(int parentId, int recursionDepth, const QStringList &propertyNames, QDBusMenuLayoutItem &layout)
149{
150 uint ret = layout.populate(parentId, recursionDepth, propertyNames, m_topLevelMenu);
151 qCDebug(qLcMenu) << parentId << "depth" << recursionDepth << propertyNames << layout.m_id << layout.m_properties << "revision" << ret << layout;
152 return ret;
153}
154
155QDBusVariant QDBusMenuAdaptor::GetProperty(int id, const QString &name)
156{
157 qCDebug(qLcMenu) << id << name;
158 // handle method call com.canonical.dbusmenu.GetProperty
159 QDBusVariant value;
160 return value;
161}
162
163QT_END_NAMESPACE
164