OSDN Git Service

use only one case switch in DBusMenu::eventFilter()
[kde/libdbusmenu-qt.git] / src / dbusmenuexporter.h
1 /* This file is part of the dbusmenu-qt library
2    Copyright 2009 Canonical
3    Author: Aurelien Gateau <aurelien.gateau@canonical.com>
4
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Library General Public
7    License (LGPL) as published by the Free Software Foundation;
8    either version 2 of the License, or (at your option) any later
9    version.
10
11    This library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Library General Public License for more details.
15
16    You should have received a copy of the GNU Library General Public License
17    along with this library; see the file COPYING.LIB.  If not, write to
18    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19    Boston, MA 02110-1301, USA.
20 */
21 #ifndef DBUSMENUEXPORTER_H
22 #define DBUSMENUEXPORTER_H
23
24 // Qt
25 #include <QtCore/QObject>
26 #include <QtDBus/QDBusConnection>
27 #include <QAction>
28 #include <QMenu>
29
30 // Local
31 #include <dbusmenu_export.h>
32
33 class DBusMenuExporterPrivate;
34
35 /**
36  * A DBusMenuExporter instance can serialize a menu over DBus
37  */
38 class DBUSMENU_EXPORT DBusMenuExporter : public QObject
39 {
40     Q_OBJECT
41 public:
42     /**
43      * Creates a DBusMenuExporter exporting menu at the dbus object path
44      * dbusObjectPath, using the given dbusConnection.
45      * The instance adds itself to the menu children.
46      */
47     DBusMenuExporter(const QString &dbusObjectPath, QMenu *menu, const QDBusConnection &dbusConnection = QDBusConnection::sessionBus());
48
49     virtual ~DBusMenuExporter();
50
51     /**
52      * Asks the matching DBusMenuImporter to activate @p action. For menus it
53      * means popup them, for items it means triggering the associated action.
54      */
55     void activateAction(QAction *action);
56
57     /**
58      * The status of the menu. Can be one of "normal" or "notice". This can be
59      * used to notify the other side the menu should be made more visible.
60      * For example, appmenu uses it to tell Unity panel to show/hide the menubar
61      * when the Alt modifier is pressed/released.
62      */
63     void setStatus(const QString &status);
64
65     /**
66      * Returns the status of the menu.
67      * @ref setStatus
68      */
69     QString status() const;
70
71 protected:
72     /**
73      * Must extract the icon name for action. This is the name which will
74      * be used to present the icon over DBus.
75      * Default implementation returns action->icon().name() when built on Qt
76      * >= 4.7 and a null string otherwise.
77      */
78     virtual QString iconNameForAction(QAction *action);
79
80 private Q_SLOTS:
81     void doUpdateActions();
82     void doEmitLayoutUpdated();
83     void slotActionDestroyed(QObject*);
84
85 private:
86     Q_DISABLE_COPY(DBusMenuExporter)
87     DBusMenuExporterPrivate *const d;
88
89     friend class DBusMenuExporterPrivate;
90     friend class DBusMenuExporterDBus;
91     friend class DBusMenu;
92 };
93
94 #endif /* DBUSMENUEXPORTER_H */