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(const QString &serviceName); | ||||
45 | ~Menu(); | ||||
46 | | ||||
47 | void init(); | ||||
48 | void cleanup(); | ||||
49 | | ||||
50 | WId winId() const; | ||||
51 | void setWinId(WId winId); | ||||
52 | | ||||
53 | QString serviceName() const; | ||||
54 | | ||||
55 | QString applicationObjectPath() const; | ||||
56 | void setApplicationObjectPath(const QString &applicationObjectPath); | ||||
57 | | ||||
58 | QString unityObjectPath() const; | ||||
59 | void setUnityObjectPath(const QString &unityObjectPath); | ||||
60 | | ||||
61 | QString windowObjectPath() const; | ||||
62 | void setWindowObjectPath(const QString &windowObjectPath); | ||||
63 | | ||||
64 | QString applicationMenuObjectPath() const; | ||||
65 | void setApplicationMenuObjectPath(const QString &applicationMenuObjectPath); | ||||
66 | | ||||
67 | QString menuBarObjectPath() const; | ||||
68 | void setMenuBarObjectPath(const QString &menuBarObjectPath); | ||||
69 | | ||||
70 | QString currentMenuObjectPath() const; | ||||
71 | | ||||
72 | QString proxyObjectPath() const; | ||||
73 | | ||||
74 | // DBus | ||||
75 | bool AboutToShow(int id); | ||||
76 | void Event(int id, const QString &eventId, const QDBusVariant &data, uint timestamp); | ||||
77 | DBusMenuItemList GetGroupProperties(const QList<int> &ids, const QStringList &propertyNames); | ||||
78 | uint GetLayout(int parentId, int recursionDepth, const QStringList &propertyNames, DBusMenuLayoutItem &dbusItem); | ||||
79 | QDBusVariant GetProperty(int id, const QString &property); | ||||
80 | | ||||
81 | QString status() const; | ||||
82 | uint version() const; | ||||
83 | | ||||
84 | signals: | ||||
85 | // don't want to pollute X stuff into Menu, let all of that be in MenuProxy | ||||
86 | void requestWriteWindowProperties(); | ||||
87 | void requestRemoveWindowProperties(); | ||||
88 | | ||||
89 | // DBus | ||||
90 | void ItemActivationRequested(int id, uint timestamp); | ||||
91 | void ItemsPropertiesUpdated(const DBusMenuItemList &updatedProps, const DBusMenuItemKeysList &removedProps); | ||||
92 | void LayoutUpdated(uint revision, int parent); | ||||
93 | | ||||
94 | private slots: | ||||
95 | void onApplicationMenuChanged(const GMenuChangeList &changes); | ||||
96 | void onMenuBarChanged(const GMenuChangeList &changes); | ||||
97 | void onApplicationActionsChanged(const QStringList &removed, const StringBoolMap &enabledChanges, const QVariantMap &stateChanges, const GMenuActionMap &added); | ||||
98 | void onUnityActionsChanged(const QStringList &removed, const StringBoolMap &enabledChanges, const QVariantMap &stateChanges, const GMenuActionMap &added); | ||||
99 | void onWindowActionsChanged(const QStringList &removed, const StringBoolMap &enabledChanges, const QVariantMap &stateChanges, const GMenuActionMap &added); | ||||
100 | | ||||
101 | private: | ||||
102 | void initMenu(); | ||||
103 | void start(uint id); | ||||
104 | void stop(const QList<uint> &id); | ||||
105 | | ||||
106 | bool registerDBusObject(); | ||||
107 | | ||||
108 | void getActions(const QString &path, const std::function<void(GMenuActionMap,bool)> &cb); | ||||
109 | bool getAction(const QString &name, GMenuAction &action) const; | ||||
110 | void triggerAction(const QString &name, uint timestamp = 0); | ||||
111 | | ||||
112 | void menuChanged(const GMenuChangeList &changes); | ||||
113 | void actionsChanged(const QStringList &removed, const StringBoolMap &enabledChanges, const QVariantMap &stateChanges, const GMenuActionMap &added, | ||||
114 | GMenuActionMap &actions, const QString &prefix); | ||||
115 | | ||||
116 | static int treeStructureToInt(int subscription, int section, int index); | ||||
117 | static void intToTreeStructure(int source, int &subscription, int §ion, int &index); | ||||
118 | | ||||
119 | static QString actionNameOfItem(const QVariantMap &item); | ||||
120 | | ||||
121 | static GMenuItem findSection(const QList<GMenuItem> &list, int section); | ||||
122 | | ||||
123 | QVariantMap gMenuToDBusMenuProperties(const QVariantMap &source) const; | ||||
124 | | ||||
125 | WId m_winId = 0; | ||||
126 | QString m_serviceName; // original GMenu service (the gtk app) | ||||
127 | | ||||
128 | QString m_applicationObjectPath; | ||||
129 | QString m_unityObjectPath; | ||||
130 | QString m_windowObjectPath; | ||||
131 | QString m_applicationMenuObjectPath; | ||||
132 | QString m_menuBarObjectPath; | ||||
133 | | ||||
134 | QString m_currentMenuObjectPath; | ||||
135 | | ||||
136 | QString m_proxyObjectPath; // our object path on this proxy app | ||||
137 | | ||||
138 | // QSet? | ||||
139 | QList<uint> m_subscriptions; // keeps track of which menu trees we're subscribed to | ||||
140 | | ||||
141 | QHash<uint, GMenuItemList> m_menus; | ||||
142 | | ||||
143 | QHash<int, QDBusMessage> m_pendingGetLayouts; | ||||
144 | | ||||
145 | GMenuActionMap m_applicationActions; | ||||
146 | GMenuActionMap m_windowActions; | ||||
147 | GMenuActionMap m_unityActions; | ||||
148 | | ||||
149 | bool m_menuInited = false; | ||||
150 | | ||||
151 | }; |