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 APPMENUMODULE_H
27#define APPMENUMODULE_H
28
29#include <kdedmodule.h>
30#include "menuimporter.h"
31#include "gtkicons.h"
32
33class QDBusPendingCallWatcher;
34class KDBusMenuImporter;
35class AppmenuDBus;
36class TopMenuBar;
37class VerticalMenu;
38
39class AppMenuModule : public KDEDModule,
40 protected QDBusContext
41{
42 Q_OBJECT
43public:
44 AppMenuModule(QObject* parent, const QList<QVariant>& list);
45 virtual ~AppMenuModule();
46
47Q_SIGNALS:
48 /**
49 * We do not know where is menu decoration button, so tell kwin to show menu
50 */
51 void showRequest(qulonglong);
52 /**
53 * This signal is emitted whenever application menu becomes available
54 */
55 void menuAvailable(qulonglong);
56 /**
57 * This signal is emitted whenever menus are unavailables
58 */
59 void clearMenus();
60 /**
61 * This signal is emitted whenever popup menu/menubar is hidden
62 * Useful for decorations to know if menu button should be release
63 */
64 void menuHidden(qulonglong);
65 /**
66 * This signal is emitted whenever a window register to appmenu
67 */
68 void WindowRegistered(qulonglong wid, const QString& service, const QDBusObjectPath&);
69 /**
70 * This signal is emitted whenever a window unregister from appmenu
71 */
72 void WindowUnregistered(qulonglong wid);
73
74private Q_SLOTS:
75 /**
76 * Show menu at QPoint(x,y) for id
77 * if x or y == -1, show in application window
78 */
79 void slotShowMenu(int x, int y, WId);
80 /**
81 * Send menuHidden signal over bus when menu is about to hide
82 */
83 void slotAboutToHide();
84 /**
85 * New window registered to appmenu
86 * Emit WindowRegistered signal over bus
87 */
88 void slotWindowRegistered(WId id, const QString& service, const QDBusObjectPath& path);
89 /**
90 * Window unregistered from appmenu
91 * Emit WindowUnregistered signal over bus
92 */
93 void slotWindowUnregistered(WId id);
94 /**
95 * Open a action in current menu
96 */
97 void slotActionActivationRequested(QAction* a);
98 /**
99 * Active window changed, show menubar for id
100 */
101 void slotActiveWindowChanged(WId id);
102 /**
103 * Update menubar with current window menu
104 */
105 void slotShowCurrentWindowMenu();
106 /**
107 * Current screen changed, update menubar
108 */
109 void slotCurrentScreenChanged();
110 /**
111 * Resize menubar
112 */
113 void slotBarNeedResize();
114 /**
115 * Reconfigure module
116 */
117 void reconfigure();
118
119private:
120 /**
121 * return an importer for window id
122 */
123 KDBusMenuImporter* getImporter(WId id);
124 /**
125 * Show menubar and update it with menu
126 */
127 void showMenuBar(QMenu *menu);
128 /**
129 * Hide menubar
130 */
131 void hideMenubar();
132 /**
133 * Return current screen
134 */
135 int currentScreen();
136 /**
137 * Return position of menubar for being centered on screen
138 */
139 QPoint centeredMenubarPos();
140
141 QObject* m_parent;
142 MenuImporter* m_menuImporter;
143 AppmenuDBus* m_appmenuDBus;
144 QHash<WId, KDBusMenuImporter*> m_importers;
145 GtkIcons m_icons;
146 QString m_menuStyle;
147 TopMenuBar* m_menubar;
148 VerticalMenu* m_menu;
149 QTimer* m_screenTimer;
150 QAction *m_waitingAction;
151 int m_currentScreen;
152};
153
154#endif
155