OSDN Git Service

9f828086decb46ff81c02a85a171926c313360d2
[kde/libdbusmenu-qt.git] / src / dbusmenuimporter.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 DBUSMENUIMPORTER_H
22 #define DBUSMENUIMPORTER_H
23
24 // Qt
25 #include <QtCore/QObject>
26 #include <QtDBus/QDBusAbstractInterface>
27 #include <QtDBus/QDBusPendingCallWatcher>
28 #include <QtDBus/QDBusVariant>
29 #include <QAction>
30 #include <QIcon>
31 #include <QMenu>
32
33 // Local
34 #include <dbusmenu_export.h>
35
36 class DBusMenuImporterPrivate;
37
38 /**
39  * Determine whether internal method calls should allow the Qt event loop
40  * to execute or not
41  */
42 enum DBusMenuImporterType {
43     ASYNCHRONOUS,
44     SYNCHRONOUS
45 };
46
47 /**
48  * A DBusMenuImporter instance can recreate a menu serialized over DBus by
49  * DBusMenuExporter
50  */
51 class DBUSMENU_EXPORT DBusMenuImporter : public QObject
52 {
53     Q_OBJECT
54 public:
55     /**
56      * Creates a DBusMenuImporter listening over DBus on service, path
57      */
58     DBusMenuImporter(const QString &service, const QString &path, QObject *parent = 0);
59
60     /**
61      * Creates a DBusMenuImporter listening over DBus on service, path, with either async
62      * or sync DBus calls
63      */
64     DBusMenuImporter(const QString &service, const QString &path, DBusMenuImporterType type, QObject *parent = 0);
65
66     virtual ~DBusMenuImporter();
67
68     /**
69      * The menu created from listening to the DBusMenuExporter over DBus
70      */
71     QMenu *menu() const;
72
73 public Q_SLOTS:
74     /**
75      * Simulates a QMenu::aboutToShow() signal on the menu returned by menu(),
76      * ensuring it is up to date in case the menu is populated on the fly. It
77      * is not mandatory to call this method, showing the menu with
78      * QMenu::popup() or QMenu::exec() will generates an aboutToShow() signal,
79      * but calling it before ensures the size-hint of the menu is correct when
80      * it is time to show it, avoiding wrong positioning.
81      *
82      * menuUpdated() will be emitted when the menu is ready.
83      *
84      * Not that the aboutToShow() signal is only sent to the root menu, not to
85      * any submenu.
86      */
87     void updateMenu();
88
89 Q_SIGNALS:
90     /**
91      * Emitted after a call to updateMenu().
92      * @see updateMenu()
93      */
94     void menuUpdated();
95
96     /**
97      * Emitted after every aboutToShow of the root menu.
98      * This signal is deprecated and only kept to keep compatibility with
99      * dbusmenu-qt 0.3.x. New code should use updateMenu() and menuUpdated()
100      *
101      * @deprecated
102      */
103     void menuReadyToBeShown();
104
105     /**
106      * Emitted when the exporter was asked to activate an action
107      */
108     void actionActivationRequested(QAction *);
109
110 protected:
111     /**
112      * Must create a menu, may be customized to fit host appearance.
113      * Default implementation creates a simple QMenu.
114      */
115     virtual QMenu *createMenu(QWidget *parent);
116
117     /**
118      * Must convert a name into an icon.
119      * Default implementation returns a null icon.
120      */
121     virtual QIcon iconForName(const QString &);
122
123 private Q_SLOTS:
124     void sendClickedEvent(int);
125     void slotMenuAboutToShow();
126     void slotMenuAboutToHide();
127     void slotAboutToShowDBusCallFinished(QDBusPendingCallWatcher *);
128     void slotItemActivationRequested(int id, uint timestamp);
129     void processPendingLayoutUpdates();
130     void slotLayoutUpdated(uint revision, int parentId);
131     void slotGetLayoutFinished(QDBusPendingCallWatcher *);
132
133 private:
134     Q_DISABLE_COPY(DBusMenuImporter)
135     DBusMenuImporterPrivate *const d;
136     friend class DBusMenuImporterPrivate;
137
138     // Use Q_PRIVATE_SLOT to avoid exposing DBusMenuItemList
139     Q_PRIVATE_SLOT(d, void slotItemsPropertiesUpdated(const DBusMenuItemList &updatedList, const DBusMenuItemKeysList &removedList))
140 };
141
142 #endif /* DBUSMENUIMPORTER_H */