on xenial help sign in
Added registry for application menus
cb0eedfNick Dedekind
plugins/Unity/ApplicationMenu/CMakeLists.txtnew file+19
@@ -0,0 +1,19 @@
1+find_package(Qt5DBus REQUIRED)
2+
3+include_directories(
4+ ${CMAKE_CURRENT_SOURCE_DIR}
5+ ${CMAKE_CURRENT_BINARY_DIR}
6+)
7+
8+set(applicationMenu_SRCS
9+ applicationmenuregistry.cpp
10+ dbusapplicationmenuregistry.cpp
11+ plugin.cpp)
12+
13+qt5_add_dbus_adaptor(applicationMenu_SRCS com.ubuntu.MenuRegistrar.xml dbusapplicationmenuregistry.h DBusApplicationMenuRegistry)
14+
15+add_library(ApplicationMenu-qml MODULE ${applicationMenu_SRCS})
16+
17+qt5_use_modules(ApplicationMenu-qml DBus Qml)
18+
19+add_unity8_plugin(Unity.ApplicationMenu 0.1 Unity/ApplicationMenu TARGETS ApplicationMenu-qml)
plugins/Unity/ApplicationMenu/applicationmenuregistry.cppnew file+141
@@ -0,0 +1,141 @@
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+#include "applicationmenuregistry.h"
18+
19+#include <QQmlEngine>
20+#include <QDebug>
21+
22+Q_LOGGING_CATEGORY(UNITY_APPMENU, "unity.appmenu", QtDebugMsg)
23+
24+#define DEBUG_MSG qCDebug(UNITY_APPMENU).nospace().noquote() << "ApplicationMenuRegistry::" << __func__
25+#define WARNING_MSG qCWarning(UNITY_APPMENU).nospace().noquote() << "ApplicationMenuRegistry::" << __func__
26+
27+ApplicationMenuRegistry::ApplicationMenuRegistry(QObject *parent)
28+ : QObject(parent)
29+{
30+}
31+
32+ApplicationMenuRegistry::~ApplicationMenuRegistry()
33+{
34+ qDeleteAll(m_appMenus);
35+ m_appMenus.clear();
36+
37+ qDeleteAll(m_surfaceMenus);
38+ m_surfaceMenus.clear();
39+}
40+
41+void ApplicationMenuRegistry::RegisterAppMenu(pid_t processId,
42+ const QDBusObjectPath &menuObjectPath,
43+ const QDBusObjectPath &actionObjectPath,
44+ const QString &service)
45+{
46+ DEBUG_MSG << "(pid=" << processId
47+ << ", menuPath=" << menuObjectPath.path()
48+ << ", actionPath=" << actionObjectPath.path()
49+ << ", service=" << service;
50+
51+ auto i = m_appMenus.find(processId);
52+ while (i != m_appMenus.end() && i.key() == processId) {
53+ if (i.value()->m_menuPath == menuObjectPath.path().toUtf8()) {
54+ WARNING_MSG << "Already have a menu for application (pid= " << processId
55+ << ", service=" << service
56+ << ", menuPath=" << menuObjectPath.path() << ")";
57+ return;
58+ }
59+ ++i;
60+ }
61+
62+ auto menu = new MenuServicePath(service, menuObjectPath, actionObjectPath);
63+ QQmlEngine::setObjectOwnership(menu, QQmlEngine::CppOwnership);
64+
65+ m_appMenus.insert(processId, menu);
66+ Q_EMIT appMenuRegistered(processId);
67+}
68+
69+void ApplicationMenuRegistry::UnregisterAppMenu(pid_t processId, const QDBusObjectPath &menuObjectPath)
70+{
71+ DEBUG_MSG << "(pid=" << processId
72+ << ", menuPath=" << menuObjectPath.path();
73+
74+ auto i = m_appMenus.find(processId);
75+ while (i != m_appMenus.end() && i.key() == processId) {
76+ if (i.value()->m_menuPath == menuObjectPath.path().toUtf8()) {
77+ i.value()->deleteLater();
78+ m_appMenus.erase(i);
79+ Q_EMIT appMenuUnregistered(processId);
80+ break;
81+ }
82+ ++i;
83+ }
84+}
85+
86+void ApplicationMenuRegistry::RegisterSurfaceMenu(const QString &surfaceId,
87+ const QDBusObjectPath &menuObjectPath,
88+ const QDBusObjectPath &actionObjectPath,
89+ const QString &service)
90+{
91+ DEBUG_MSG << "(surfaceId=" << surfaceId
92+ << ", menuPath=" << menuObjectPath.path()
93+ << ", actionPath=" << actionObjectPath.path()
94+ << ", service=" << service;
95+
96+ auto i = m_surfaceMenus.find(surfaceId);
97+ while (i != m_surfaceMenus.end() && i.key() == surfaceId) {
98+ if (i.value()->m_menuPath == menuObjectPath.path().toUtf8()) {
99+ WARNING_MSG << "Already have a menu for surface (surfaceId= " << surfaceId
100+ << ", service=" << service
101+ << ", menuPath=" << menuObjectPath.path() << ")";
102+ return;
103+ }
104+ ++i;
105+ }
106+
107+ auto menu = new MenuServicePath(service, menuObjectPath, actionObjectPath);
108+ QQmlEngine::setObjectOwnership(menu, QQmlEngine::CppOwnership);
109+
110+ m_surfaceMenus.insert(surfaceId, menu);
111+ Q_EMIT surfaceMenuRegistered(surfaceId);
112+}
113+
114+void ApplicationMenuRegistry::UnregisterSurfaceMenu(const QString &surfaceId, const QDBusObjectPath &menuObjectPath)
115+{
116+ DEBUG_MSG << "(surfaceId=" << surfaceId
117+ << ", menuPath=" << menuObjectPath.path();
118+
119+ auto i = m_surfaceMenus.find(surfaceId);
120+ while (i != m_surfaceMenus.end() && i.key() == surfaceId) {
121+ if (i.value()->m_menuPath == menuObjectPath.path().toUtf8()) {
122+ i.value()->deleteLater();
123+ m_surfaceMenus.erase(i);
124+ Q_EMIT surfaceMenuUnregistered(surfaceId);
125+ break;
126+ }
127+ ++i;
128+ }
129+}
130+
131+QList<QObject*> ApplicationMenuRegistry::getMenusForSurface(const QString &surfaceId) const
132+{
133+ QList<QObject*> list;
134+
135+ auto i = m_surfaceMenus.find(surfaceId);
136+ while (i != m_surfaceMenus.constEnd() && i.key() == surfaceId) {
137+ list << i.value();
138+ ++i;
139+ }
140+ return list;
141+}
plugins/Unity/ApplicationMenu/applicationmenuregistry.hnew file+83
@@ -0,0 +1,83 @@
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
plugins/Unity/ApplicationMenu/com.ubuntu.MenuRegistrar.xmlnew file+83
@@ -0,0 +1,83 @@
1+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
2+<node xmlns:dox="http://www.ayatana.org/dbus/dox.dtd">
3+ <dox:d><![CDATA[
4+ @mainpage
5+
6+ An interface to register menus that are associated with a window in an application. The
7+ main interface is documented here: @ref com::ubuntu::MenuRegistrar.
8+
9+ The actual menus are transported using the gmenumodel protocol
10+ ]]></dox:d>
11+ <interface name="com.ubuntu.MenuRegistrar" xmlns:dox="http://www.ayatana.org/dbus/dox.dtd">
12+ <dox:d>
13+ An interface to register a menu from an application to be displayed in another
14+ window. This manages that association between processes and/or Mir surface IDs and the dbus
15+ address and object that provides the menus using the org.gtk.Menus interface.
16+ </dox:d>
17+ <method name="RegisterAppMenu">
18+ <dox:d><![CDATA[
19+ Associates a gmenumodel with an application
20+
21+ /note this method assumes that the connection from the caller is the DBus connection
22+ to use for the object. Applications that use multiple DBus connections will need to
23+ ensure this method is called with the same connection that implements the object.
24+ ]]></dox:d>
25+ <arg name="pid" type="u" direction="in">
26+ <dox:d>The process ID of the application for which the menu is associated</dox:d>
27+ </arg>
28+ <arg name="menuObjectPath" type="o" direction="in">
29+ <dox:d>The dbus path where the gmenumodel interface for the application menu has been exported</dox:d>
30+ </arg>
31+ <arg name="actionObjectPath" type="o" direction="in">
32+ <dox:d>The dbus path where the gactionmenu interface for the application menu actions has been exported</dox:d>
33+ </arg>
34+ <arg name="service" type="s" direction="in">
35+ <dox:d>The dbus conection name of the client application to be registered (e.g. :1.23 or org.example.service)</dox:d>
36+ </arg>
37+ </method>
38+ <method name="UnregisterAppMenu">
39+ <dox:d>
40+ A method to allow removing an application menu from the database.
41+ </dox:d>
42+ <arg name="pid" type="u" direction="in">
43+ <dox:d>The process id of the application</dox:d>
44+ </arg>
45+ <arg name="menuObjectPath" type="o" direction="in">
46+ <dox:d>The dbus path for the registered application menu to be unregistered</dox:d>
47+ </arg>
48+ </method>
49+
50+ <method name="RegisterSurfaceMenu">
51+ <dox:d><![CDATA[
52+ Associates a gmenumodel with a surface
53+
54+ /note this method assumes that the connection from the caller is the DBus connection
55+ to use for the object. Applications that use multiple DBus connections will need to
56+ ensure this method is called with the same connection that implements the object.
57+ ]]></dox:d>
58+ <arg name="surface" type="s" direction="in">
59+ <dox:d>The surface ID of the surface</dox:d>
60+ </arg>
61+ <arg name="menuObjectPath" type="o" direction="in">
62+ <dox:d>The dbus path where the gmenumodel interface for the surface menu has been exported</dox:d>
63+ </arg>
64+ <arg name="actionObjectPath" type="o" direction="in">
65+ <dox:d>The dbus path where the gactionmenu interface for the surface menu actions has been exported</dox:d>
66+ </arg>
67+ <arg name="service" type="s" direction="in">
68+ <dox:d>The dbus conection name of the client application to be registered (e.g. :1.23 or org.example.service)</dox:d>
69+ </arg>
70+ </method>
71+ <method name="UnregisterSurfaceMenu">
72+ <dox:d>
73+ A method to allow removing a surface menu from the database.
74+ </dox:d>
75+ <arg name="surfaceId" type="s" direction="in">
76+ <dox:d>The surface id of the surface</dox:d>
77+ </arg>
78+ <arg name="menuObjectPath" type="o" direction="in">
79+ <dox:d>The dbus path for the registered surface menu to be unregistered</dox:d>
80+ </arg>
81+ </method>
82+ </interface>
83+</node>
plugins/Unity/ApplicationMenu/dbusapplicationmenuregistry.cppnew file+44
@@ -0,0 +1,44 @@
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+#include "dbusapplicationmenuregistry.h"
18+#include "menuregistraradaptor.h"
19+
20+DBusApplicationMenuRegistry::DBusApplicationMenuRegistry(QObject *parent)
21+ : ApplicationMenuRegistry(parent)
22+{
23+ new MenuRegistrarAdaptor(this);
24+
25+ QDBusConnection connection = QDBusConnection::sessionBus();
26+ if (!connection.registerObject("/com/ubuntu/MenuRegistrar", this)) {
27+ qCWarning(UNITY_APPMENU) << "Unable to register DBus object /com/ubuntu/MenuRegistrar";
28+ }
29+ if (!connection.registerService("com.ubuntu.MenuRegistrar")) {
30+ qCWarning(UNITY_APPMENU) << "Unable to register DBus service com.ubuntu.MenuRegistrar";
31+ }
32+}
33+
34+DBusApplicationMenuRegistry::~DBusApplicationMenuRegistry()
35+{
36+ QDBusConnection connection = QDBusConnection::sessionBus();
37+ connection.unregisterObject("/com/ubuntu/MenuRegistrar");
38+}
39+
40+ApplicationMenuRegistry *DBusApplicationMenuRegistry::instance()
41+{
42+ static ApplicationMenuRegistry* reg(new DBusApplicationMenuRegistry());
43+ return reg;
44+}
plugins/Unity/ApplicationMenu/dbusapplicationmenuregistry.hnew file+34
@@ -0,0 +1,34 @@
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 DBUSAPPLICATIONMENUREGISTRY_H
18+#define DBUSAPPLICATIONMENUREGISTRY_H
19+
20+#include "applicationmenuregistry.h"
21+
22+class DBusApplicationMenuRegistry : public ApplicationMenuRegistry,
23+ protected QDBusContext
24+{
25+ Q_OBJECT
26+public:
27+ ~DBusApplicationMenuRegistry();
28+ static ApplicationMenuRegistry* instance();
29+
30+protected:
31+ explicit DBusApplicationMenuRegistry(QObject *parent = 0);
32+};
33+
34+#endif // DBUSAPPLICATIONMENUREGISTRY_H
plugins/Unity/ApplicationMenu/plugin.cppnew file+42
@@ -0,0 +1,42 @@
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+#include "plugin.h"
18+#include "dbusapplicationmenuregistry.h"
19+
20+#include <QtQml>
21+
22+static QObject *menuRegistry(QQmlEngine *engine, QJSEngine *scriptEngine)
23+{
24+ Q_UNUSED(engine)
25+ Q_UNUSED(scriptEngine)
26+ return DBusApplicationMenuRegistry::instance();
27+}
28+
29+void ApplicationMenuPlugin::registerTypes(const char *uri)
30+{
31+ Q_ASSERT(uri == QLatin1String("Unity.ApplicationMenu"));
32+
33+ qmlRegisterUncreatableType<MenuServicePath>(uri, 0, 1, "MenuServicePath", "You cannot create a MenuServicePath");
34+ qmlRegisterSingletonType<DBusApplicationMenuRegistry>(uri, 0, 1, "ApplicationMenuRegistry", menuRegistry);
35+}
36+
37+void ApplicationMenuPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
38+{
39+ QQmlExtensionPlugin::initializeEngine(engine, uri);
40+
41+ menuRegistry(nullptr, nullptr);
42+}
plugins/Unity/ApplicationMenu/plugin.hnew file+32
@@ -0,0 +1,32 @@
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 APPLICATIONMENU_PLUGIN_H
18+#define APPLICATIONMENU_PLUGIN_H
19+
20+#include <QQmlExtensionPlugin>
21+
22+class ApplicationMenuPlugin : public QQmlExtensionPlugin
23+{
24+ Q_OBJECT
25+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
26+
27+public:
28+ void registerTypes(const char *uri) override;
29+ void initializeEngine(QQmlEngine *engine, const char *uri) override;
30+};
31+
32+#endif // APPLICATIONMENU_PLUGIN_H
plugins/Unity/ApplicationMenu/qmldirnew file+3
@@ -0,0 +1,3 @@
1+module Unity.ApplicationMenu
2+plugin ApplicationMenu-qml
3+typeinfo ApplicationMenu.qmltypes
plugins/Unity/CMakeLists.txt+1
@@ -1,3 +1,4 @@
1+add_subdirectory(ApplicationMenu)
1add_subdirectory(Connectivity)
2add_subdirectory(Connectivity)
2add_subdirectory(Indicators)
3add_subdirectory(Indicators)
3add_subdirectory(Launcher)
4add_subdirectory(Launcher)
tests/mocks/Unity/ApplicationMenu/CMakeLists.txtnew file+18
@@ -0,0 +1,18 @@
1+find_package(Qt5DBus REQUIRED)
2+
3+include_directories(
4+ ${CMAKE_SOURCE_DIR}/plugins/Unity/ApplicationMenu
5+ ${CMAKE_CURRENT_SOURCE_DIR}
6+ ${CMAKE_CURRENT_BINARY_DIR}
7+)
8+
9+set(FakeApplicationMenu_SRCS
10+ ${CMAKE_SOURCE_DIR}/plugins/Unity/ApplicationMenu/applicationmenuregistry.cpp
11+ mockapplicationmenuregistry.cpp
12+ plugin.cpp)
13+
14+add_library(FakeApplicationMenu-qml MODULE ${FakeApplicationMenu_SRCS})
15+
16+qt5_use_modules(FakeApplicationMenu-qml Qml DBus)
17+
18+add_unity8_mock(Unity.ApplicationMenu 1.0 Unity/ApplicationMenu PREFIX mocks TARGETS FakeApplicationMenu-qml)
tests/mocks/Unity/ApplicationMenu/mockapplicationmenuregistry.cppnew file+42
@@ -0,0 +1,42 @@
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+#include "mockapplicationmenuregistry.h"
18+
19+#include <QQmlEngine>
20+#include <QDebug>
21+
22+ApplicationMenuRegistry *MockApplicationMenuRegistry::instance()
23+{
24+ static ApplicationMenuRegistry* reg(new MockApplicationMenuRegistry(nullptr));
25+ return reg;
26+}
27+
28+MockApplicationMenuRegistry::MockApplicationMenuRegistry(QObject *parent)
29+ : ApplicationMenuRegistry(parent)
30+{
31+}
32+
33+void MockApplicationMenuRegistry::RegisterSurfaceMenu(const QString &surface,
34+ const QString &menuObjectPath,
35+ const QString &actionObjectPath,
36+ const QString &service)
37+{
38+ ApplicationMenuRegistry::RegisterSurfaceMenu(surface,
39+ QDBusObjectPath(menuObjectPath),
40+ QDBusObjectPath(actionObjectPath),
41+ service);
42+}
tests/mocks/Unity/ApplicationMenu/mockapplicationmenuregistry.hnew file+38
@@ -0,0 +1,38 @@
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 MOCKAPPLICATIONMENUREGISTRY_H
18+#define MOCKAPPLICATIONMENUREGISTRY_H
19+
20+#include <applicationmenuregistry.h>
21+
22+class MockApplicationMenuRegistry : public ApplicationMenuRegistry
23+{
24+ Q_OBJECT
25+public:
26+
27+ static ApplicationMenuRegistry* instance();
28+
29+ Q_INVOKABLE void RegisterSurfaceMenu(const QString &surface,
30+ const QString &menuObjectPath,
31+ const QString &actionObjectPath,
32+ const QString &service);
33+
34+private:
35+ MockApplicationMenuRegistry(QObject *parent = 0);
36+};
37+
38+#endif // MOCKAPPLICATIONMENUREGISTRY_H
tests/mocks/Unity/ApplicationMenu/plugin.cppnew file+42
@@ -0,0 +1,42 @@
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+#include "plugin.h"
18+#include "mockapplicationmenuregistry.h"
19+
20+#include <QtQml>
21+
22+static QObject *menuRegistry(QQmlEngine *engine, QJSEngine *scriptEngine)
23+{
24+ Q_UNUSED(engine)
25+ Q_UNUSED(scriptEngine)
26+ return MockApplicationMenuRegistry::instance();
27+}
28+
29+void ApplicationMenuPlugin::registerTypes(const char *uri)
30+{
31+ Q_ASSERT(uri == QLatin1String("Unity.ApplicationMenu"));
32+
33+ qmlRegisterUncreatableType<MenuServicePath>(uri, 0, 1, "MenuServicePath", "You cannot create a MenuServicePath");
34+ qmlRegisterSingletonType<ApplicationMenuRegistry>(uri, 0, 1, "ApplicationMenuRegistry", menuRegistry);
35+}
36+
37+void ApplicationMenuPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
38+{
39+ QQmlExtensionPlugin::initializeEngine(engine, uri);
40+
41+ menuRegistry(nullptr, nullptr);
42+}
tests/mocks/Unity/ApplicationMenu/plugin.hnew file+32
@@ -0,0 +1,32 @@
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 APPLICATIONMENU_PLUGIN_H
18+#define APPLICATIONMENU_PLUGIN_H
19+
20+#include <QQmlExtensionPlugin>
21+
22+class ApplicationMenuPlugin : public QQmlExtensionPlugin
23+{
24+ Q_OBJECT
25+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
26+
27+public:
28+ void registerTypes(const char *uri) override;
29+ void initializeEngine(QQmlEngine *engine, const char *uri) override;
30+};
31+
32+#endif // APPLICATIONMENU_PLUGIN_H
tests/mocks/Unity/ApplicationMenu/qmldirnew file+3
@@ -0,0 +1,3 @@
1+module Unity.ApplicationMenu
2+plugin FakeApplicationMenu-qml
3+typeinfo ApplicationMenu.qmltypes
tests/mocks/Unity/CMakeLists.txt+1
@@ -1,4 +1,5 @@
1add_subdirectory(Application)
1add_subdirectory(Application)
2+add_subdirectory(ApplicationMenu)
2add_subdirectory(Connectivity)
3add_subdirectory(Connectivity)
3add_subdirectory(Indicators)
4add_subdirectory(Indicators)
4add_subdirectory(InputInfo)
5add_subdirectory(InputInfo)