Unity 8
applicationmenuregistry.h
1 /*
2  * Copyright (C) 2016 Canonical, Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef APPLICATIONMENUREGISTRY_H
18 #define APPLICATIONMENUREGISTRY_H
19 
20 #include <QObject>
21 #include <QDBusContext>
22 #include <QDBusObjectPath>
23 #include <QtQml>
24 
25 Q_DECLARE_LOGGING_CATEGORY(UNITY_APPMENU)
26 
27 class MenuServicePath : public QObject
28 {
29  Q_OBJECT
30  Q_PROPERTY(QByteArray service MEMBER m_service CONSTANT)
31  Q_PROPERTY(QByteArray menuPath MEMBER m_menuPath CONSTANT)
32  Q_PROPERTY(QByteArray actionPath MEMBER m_actionPath CONSTANT)
33 public:
34  explicit MenuServicePath(const QString &service,
35  const QDBusObjectPath &menuPath,
36  const QDBusObjectPath &actionPath)
37  : m_service(service.toUtf8())
38  , m_menuPath(menuPath.path().toUtf8())
39  , m_actionPath(actionPath.path().toUtf8())
40  {}
41 
42  const QByteArray m_service;
43  const QByteArray m_menuPath;
44  const QByteArray m_actionPath;
45 };
46 
47 class ApplicationMenuRegistry : public QObject
48 {
49  Q_OBJECT
50 public:
51  virtual ~ApplicationMenuRegistry();
52 
53  // for qml
54  Q_INVOKABLE QList<QObject*> getMenusForSurface(const QString &surfaceId) const;
55 
56  // for dbus
57  void RegisterAppMenu(pid_t processId,
58  const QDBusObjectPath &menuObjectPath,
59  const QDBusObjectPath &actionObjectPath,
60  const QString &service);
61  void UnregisterAppMenu(pid_t processId, const QDBusObjectPath &menuObjectPath);
62 
63  void RegisterSurfaceMenu(const QString &surfaceId,
64  const QDBusObjectPath &menuObjectPath,
65  const QDBusObjectPath &actionObjectPath,
66  const QString &service);
67  void UnregisterSurfaceMenu(const QString &surfaceId, const QDBusObjectPath &menuObjectPath);
68 
69 Q_SIGNALS:
70  void appMenuRegistered(uint processId);
71  void appMenuUnregistered(uint processId);
72 
73  void surfaceMenuRegistered(const QString& surfaceId);
74  void surfaceMenuUnregistered(const QString& surfaceId);
75 
76 protected:
77  explicit ApplicationMenuRegistry(QObject *parent = 0);
78 
79  QMultiMap<pid_t, MenuServicePath*> m_appMenus;
80  QMultiMap<QString, MenuServicePath*> m_surfaceMenus;
81 };
82 
83 #endif // APPLICATIONMENUREGISTRY_H