Changeset View
Changeset View
Standalone View
Standalone View
gmenu-dbusmenu-proxy/menu.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2018 Kai Uwe Broulik <kde@privat.broulik.de> | ||||
3 | * | ||||
4 | * This library is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU Lesser General Public | ||||
6 | * License as published by the Free Software Foundation; either | ||||
7 | * version 2.1 of the License, or (at your option) any later version. | ||||
8 | * | ||||
9 | * This library is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | * Lesser General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU Lesser General Public | ||||
15 | * License along with this library; if not, write to the Free Software | ||||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||||
17 | * | ||||
18 | */ | ||||
19 | | ||||
20 | #pragma once | ||||
21 | | ||||
22 | #include <QObject> | ||||
23 | #include <QDBusContext> | ||||
24 | #include <QString> | ||||
25 | #include <QVector> | ||||
26 | #include <QWindow> // for WId | ||||
27 | | ||||
28 | #include <functional> | ||||
29 | | ||||
30 | #include "gdbusmenutypes_p.h" | ||||
31 | #include "../libdbusmenuqt/dbusmenutypes_p.h" | ||||
32 | | ||||
33 | class QDBusVariant; | ||||
34 | | ||||
35 | class Menu : public QObject, protected QDBusContext | ||||
36 | { | ||||
37 | Q_OBJECT | ||||
38 | | ||||
39 | // DBus | ||||
40 | Q_PROPERTY(QString Status READ status) | ||||
41 | Q_PROPERTY(uint Version READ version) | ||||
42 | | ||||
43 | public: | ||||
44 | Menu(WId winId, | ||||
45 | const QString &serviceName, | ||||
46 | const QString &applicationObjectPath, | ||||
47 | const QString &windowObjectPath, | ||||
48 | const QString &menuObjectPath); | ||||
49 | ~Menu(); | ||||
50 | | ||||
51 | WId winId() const; | ||||
52 | QString serviceName() const; | ||||
53 | | ||||
54 | QString applicationObjectPath() const; | ||||
55 | QString windowObjectPath() const; | ||||
56 | QString menuObjectPath() const; | ||||
57 | | ||||
58 | QString proxyObjectPath() const; | ||||
59 | | ||||
60 | // DBus | ||||
61 | bool AboutToShow(int id); | ||||
62 | void Event(int id, const QString &eventId, const QDBusVariant &data, uint timestamp); | ||||
63 | DBusMenuItemList GetGroupProperties(const QList<int> &ids, const QStringList &propertyNames); | ||||
64 | uint GetLayout(int parentId, int recursionDepth, const QStringList &propertyNames, DBusMenuLayoutItem &dbusItem); | ||||
65 | QDBusVariant GetProperty(int id, const QString &property); | ||||
66 | | ||||
67 | QString status() const; | ||||
68 | uint version() const; | ||||
69 | | ||||
70 | signals: | ||||
71 | // don't want to pollute X stuff into Menu, let all of that be in MenuProxy | ||||
72 | void requestWriteWindowProperties(); | ||||
73 | void requestRemoveWindowProperties(); | ||||
74 | | ||||
75 | // DBus | ||||
76 | void ItemActivationRequested(int id, uint timestamp); | ||||
77 | void ItemsPropertiesUpdated(const DBusMenuItemList &updatedProps, const DBusMenuItemKeysList &removedProps); | ||||
78 | void LayoutUpdated(uint revision, int parent); | ||||
79 | | ||||
80 | private slots: | ||||
81 | void onMenuChanged(const GMenuChangeList &changes); | ||||
82 | void onWindowActionsChanged(const GMenuActionsChange &changes); | ||||
83 | | ||||
84 | private: | ||||
85 | void start(); | ||||
86 | void start(uint id); | ||||
87 | void stop(const QList<uint> &id); | ||||
88 | | ||||
89 | bool registerDBusObject(); | ||||
90 | | ||||
91 | void getActions(const QString &path, const std::function<void(GMenuActionMap,bool)> &cb); | ||||
92 | bool getAction(const QString &name, GMenuAction &action) const; | ||||
93 | void triggerAction(const QString &name); | ||||
94 | | ||||
95 | static int treeStructureToInt(int subscription, int section, int index); | ||||
96 | static void intToTreeStructure(int source, int &subscription, int §ion, int &index); | ||||
97 | | ||||
98 | static GMenuItem findSection(const QList<GMenuItem> &list, int section); | ||||
99 | | ||||
100 | QVariantMap gMenuToDBusMenuProperties(const QVariantMap &source) const; | ||||
101 | | ||||
102 | WId m_winId; | ||||
103 | QString m_serviceName; // original GMenu service (the gtk app) | ||||
104 | | ||||
105 | QString m_applicationObjectPath; | ||||
106 | QString m_windowObjectPath; | ||||
107 | QString m_menuObjectPath; | ||||
108 | | ||||
109 | QString m_proxyObjectPath; // our object path on this proxy app | ||||
110 | | ||||
111 | // QSet? | ||||
112 | QList<uint> m_subscriptions; // keeps track of which menu trees we're subscribed to | ||||
113 | | ||||
114 | QHash<uint, GMenuItemList> m_menus; | ||||
115 | | ||||
116 | QHash<int, QDBusMessage> m_pendingGetLayouts; | ||||
117 | | ||||
118 | bool m_queriedApplicationActions = false; | ||||
119 | GMenuActionMap m_applicationActions; | ||||
120 | bool m_queriedWindowActions = false; | ||||
121 | GMenuActionMap m_windowActions; | ||||
122 | | ||||
123 | }; |