1/*
2 This file is part of the KDE project.
3
4 Copyright (c) 2011 Lionel Chauvin <megabigbug@yahoo.fr>
5 Copyright (c) 2011,2012 Cédric Bellegarde <gnumdk@gmail.com>
6
7 Permission is hereby granted, free of charge, to any person obtaining a
8 copy of this software and associated documentation files (the "Software"),
9 to deal in the Software without restriction, including without limitation
10 the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 and/or sell copies of the Software, and to permit persons to whom the
12 Software is furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 DEALINGS IN THE SOFTWARE.
24*/
25
26#ifndef MENUIMPORTER_H
27#define MENUIMPORTER_H
28
29// Qt
30#include <QDBusContext>
31#include <QDBusObjectPath>
32#include <QObject>
33#include <QWidget> // For WId
34
35class QDBusObjectPath;
36class QDBusPendingCallWatcher;
37class QDBusServiceWatcher;
38class QMenu;
39
40/**
41 * Represents an item with its children. GetLayout() returns a
42 * DBusMenuLayoutItemList.
43 */
44struct DBusMenuLayoutItem
45{
46 int id;
47 QVariantMap properties;
48 QList<DBusMenuLayoutItem> children;
49};
50Q_DECLARE_METATYPE(DBusMenuLayoutItem)
51
52class MenuImporter : public QObject, protected QDBusContext
53{
54 Q_OBJECT
55
56public:
57 MenuImporter(QObject*);
58 ~MenuImporter();
59
60 bool connectToBus();
61
62 bool serviceExist(WId id) { return m_menuServices.contains(id); }
63 QString serviceForWindow(WId id) { return m_menuServices.value(id); }
64
65 bool pathExist(WId id) { return m_menuPaths.contains(id); }
66 QString pathForWindow(WId id) { return m_menuPaths.value(id).path(); }
67
68 QList<WId> ids() { return m_menuServices.keys(); }
69
70 /**
71 * Return id of first transient/friend window with a menu available
72 */
73 WId recursiveMenuId(WId id);
74
75Q_SIGNALS:
76 void WindowRegistered(WId id, const QString& service, const QDBusObjectPath&);
77 void WindowUnregistered(WId id);
78
79public Q_SLOTS:
80 Q_NOREPLY void RegisterWindow(WId id, const QDBusObjectPath& path);
81 Q_NOREPLY void UnregisterWindow(WId id);
82 QString GetMenuForWindow(WId id, QDBusObjectPath& path);
83
84private Q_SLOTS:
85 void slotServiceUnregistered(const QString& service);
86 void slotLayoutUpdated(uint revision, int parentId);
87 void finishFakeUnityAboutToShow(QDBusPendingCallWatcher*);
88
89private:
90 QDBusServiceWatcher* m_serviceWatcher;
91 QHash<WId, QString> m_menuServices;
92 QHash<WId, QDBusObjectPath> m_menuPaths;
93 QHash<WId, QString> m_windowClasses;
94
95 void fakeUnityAboutToShow();
96};
97
98#endif /* MENUIMPORTER_H */
99