OSDN Git Service

use cached variable for the pkg-config installation path
[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 when the exporter was asked to activate an action
98      */
99     void actionActivationRequested(QAction *);
100
101 protected:
102     /**
103      * Must create a menu, may be customized to fit host appearance.
104      * Default implementation creates a simple QMenu.
105      */
106     virtual QMenu *createMenu(QWidget *parent);
107
108     /**
109      * Must convert a name into an icon.
110      * Default implementation returns a null icon.
111      */
112     virtual QIcon iconForName(const QString &);
113
114 private Q_SLOTS:
115     void sendClickedEvent(int);
116     void slotMenuAboutToShow();
117     void slotMenuAboutToHide();
118     void slotAboutToShowDBusCallFinished(QDBusPendingCallWatcher *);
119     void slotItemActivationRequested(int id, uint timestamp);
120     void processPendingLayoutUpdates();
121     void slotLayoutUpdated(uint revision, int parentId);
122     void slotGetLayoutFinished(QDBusPendingCallWatcher *);
123
124 private:
125     Q_DISABLE_COPY(DBusMenuImporter)
126     DBusMenuImporterPrivate *const d;
127     friend class DBusMenuImporterPrivate;
128
129     // Use Q_PRIVATE_SLOT to avoid exposing DBusMenuItemList
130     Q_PRIVATE_SLOT(d, void slotItemsPropertiesUpdated(const DBusMenuItemList &updatedList, const DBusMenuItemKeysList &removedList))
131 };
132
133 #endif /* DBUSMENUIMPORTER_H */