1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4/*
5 This file was originally created by qdbusxml2cpp version 0.8
6 Command line was:
7 qdbusxml2cpp -a dbusmenu ../../3rdparty/dbus-ifaces/dbus-menu.xml
8
9 However it is maintained manually.
10*/
11
12#include <QMetaObject>
13#include <QByteArray>
14#include <QList>
15#include <QMap>
16#include <QString>
17#include <QStringList>
18#include <QVariant>
19#include <QLocale>
20
21#include <private/qdbusmenuadaptor_p.h>
22#include <private/qdbusplatformmenu_p.h>
23
24QT_BEGIN_NAMESPACE
25
26using namespace Qt::StringLiterals;
27
28QDBusMenuAdaptor::QDBusMenuAdaptor(QDBusPlatformMenu *topLevelMenu)
29 : QDBusAbstractAdaptor(topLevelMenu)
30 , m_topLevelMenu(topLevelMenu)
31{
32 setAutoRelaySignals(true);
33}
34
35QDBusMenuAdaptor::~QDBusMenuAdaptor()
36{
37}
38
39QString QDBusMenuAdaptor::status() const
40{
41 qCDebug(qLcMenu);
42 return "normal"_L1;
43}
44
45QString QDBusMenuAdaptor::textDirection() const
46{
47 return QLocale().textDirection() == Qt::RightToLeft ? "rtl"_L1 : "ltr"_L1;
48}
49
50uint QDBusMenuAdaptor::version() const
51{
52 return 4;
53}
54
55bool QDBusMenuAdaptor::AboutToShow(int id)
56{
57 qCDebug(qLcMenu) << id;
58 if (id == 0) {
59 emit m_topLevelMenu->aboutToShow();
60 } else {
61 QDBusPlatformMenuItem *item = QDBusPlatformMenuItem::byId(id);
62 if (item) {
63 const QDBusPlatformMenu *menu = static_cast<const QDBusPlatformMenu *>(item->menu());
64 if (menu)
65 emit const_cast<QDBusPlatformMenu *>(menu)->aboutToShow();
66 }
67 }
68 return false; // updateNeeded (we don't know that, so false)
69}
70
71QList<int> QDBusMenuAdaptor::AboutToShowGroup(const QList<int> &ids, QList<int> &idErrors)
72{
73 qCDebug(qLcMenu) << ids;
74 Q_UNUSED(idErrors);
75 idErrors.clear();
76 for (int id : ids)
77 AboutToShow(id);
78 return QList<int>(); // updatesNeeded
79}
80
81void QDBusMenuAdaptor::Event(int id, const QString &eventId, const QDBusVariant &data, uint timestamp)
82{
83 Q_UNUSED(data);
84 Q_UNUSED(timestamp);
85 QDBusPlatformMenuItem *item = QDBusPlatformMenuItem::byId(id);
86 qCDebug(qLcMenu) << id << (item ? item->text() : ""_L1) << eventId;
87 if (item && eventId == "clicked"_L1)
88 item->trigger();
89 if (item && eventId == "hovered"_L1)
90 emit item->hovered();
91 if (eventId == "closed"_L1) {
92 // There is no explicit AboutToHide method, so map closed event to aboutToHide method
93 const QDBusPlatformMenu *menu = nullptr;
94 if (item)
95 menu = static_cast<const QDBusPlatformMenu *>(item->menu());
96 else if (id == 0)
97 menu = m_topLevelMenu;
98 if (menu)
99 emit const_cast<QDBusPlatformMenu *>(menu)->aboutToHide();
100 }
101}
102
103QList<int> QDBusMenuAdaptor::EventGroup(const QDBusMenuEventList &events)
104{
105 for (const QDBusMenuEvent &ev : events)
106 Event(id: ev.m_id, eventId: ev.m_eventId, data: ev.m_data, timestamp: ev.m_timestamp);
107 return QList<int>(); // idErrors
108}
109
110QDBusMenuItemList QDBusMenuAdaptor::GetGroupProperties(const QList<int> &ids, const QStringList &propertyNames)
111{
112 qCDebug(qLcMenu) << ids << propertyNames << "=>" << QDBusMenuItem::items(ids, propertyNames);
113 return QDBusMenuItem::items(ids, propertyNames);
114}
115
116uint QDBusMenuAdaptor::GetLayout(int parentId, int recursionDepth, const QStringList &propertyNames, QDBusMenuLayoutItem &layout)
117{
118 uint ret = layout.populate(id: parentId, depth: recursionDepth, propertyNames, topLevelMenu: m_topLevelMenu);
119 qCDebug(qLcMenu) << parentId << "depth" << recursionDepth << propertyNames << layout.m_id << layout.m_properties << "revision" << ret << layout;
120 return ret;
121}
122
123QDBusVariant QDBusMenuAdaptor::GetProperty(int id, const QString &name)
124{
125 qCDebug(qLcMenu) << id << name;
126 // handle method call com.canonical.dbusmenu.GetProperty
127 QDBusVariant value;
128 return value;
129}
130
131QT_END_NAMESPACE
132
133#include "moc_qdbusmenuadaptor_p.cpp"
134

source code of qtbase/src/gui/platform/unix/dbusmenu/qdbusmenuadaptor.cpp