on xenial help sign in
Added ApplicationMenu plugin
474d3d7Nick Dedekind
plugins/Unity/ApplicationMenu/CMakeLists.txtnew file+20
@@ -0,0 +1,20 @@
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 1.0 Unity/ApplicationMenu TARGETS ApplicationMenu-qml)
20+
plugins/Unity/ApplicationMenu/applicationmenuregistry.cppnew file+125
@@ -0,0 +1,125 @@
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+
23+ApplicationMenuRegistry::ApplicationMenuRegistry(QObject *parent)
24+ : QObject(parent)
25+{
26+}
27+
28+ApplicationMenuRegistry::~ApplicationMenuRegistry()
29+{
30+ qDeleteAll(m_appMenus);
31+ m_appMenus.clear();
32+
33+ qDeleteAll(m_surfaceMenus);
34+ m_surfaceMenus.clear();
35+}
36+
37+void ApplicationMenuRegistry::RegisterAppMenu(pid_t processId,
38+ const QDBusObjectPath &menuObjectPath,
39+ const QDBusObjectPath &actionObjectPath,
40+ const QString &service)
41+{
42+ qInfo() << "RegisterApplicationMenu" << processId << " @ " << service << menuObjectPath.path() << actionObjectPath.path();
43+
44+ QMultiMap<pid_t, MenuServicePath*>::iterator i = m_appMenus.find(processId);
45+ while (i != m_appMenus.end() && i.key() == processId) {
46+ if (i.value()->m_menuPath == menuObjectPath.path().toUtf8()) {
47+ qWarning() << "Already have a menu for application:" << processId << service << menuObjectPath.path();
48+ return;
49+ }
50+ ++i;
51+ }
52+
53+ auto menu = new MenuServicePath(service.toUtf8(), menuObjectPath.path().toUtf8(), actionObjectPath.path().toUtf8());
54+ QQmlEngine::setObjectOwnership(menu, QQmlEngine::CppOwnership);
55+
56+ m_appMenus.insert(processId, menu);
57+ Q_EMIT appMenuRegistered(processId);
58+}
59+
60+void ApplicationMenuRegistry::UnregisterAppMenu(pid_t processId, const QDBusObjectPath &menuObjectPath)
61+{
62+ qInfo() << "RegisterApplicationMenu" << processId << " @ " << menuObjectPath.path();
63+
64+ QMultiMap<pid_t, MenuServicePath*>::iterator i = m_appMenus.find(processId);
65+ while (i != m_appMenus.end() && i.key() == processId) {
66+ if (i.value()->m_menuPath == menuObjectPath.path().toUtf8()) {
67+ i.value()->deleteLater();
68+ m_appMenus.erase(i);
69+ Q_EMIT appMenuUnregistered(processId);
70+ break;
71+ }
72+ ++i;
73+ }
74+}
75+
76+void ApplicationMenuRegistry::RegisterSurfaceMenu(const QString &surfaceId,
77+ const QDBusObjectPath &menuObjectPath,
78+ const QDBusObjectPath &actionObjectPath,
79+ const QString &service)
80+{
81+ qInfo() << "RegisterSurfaceMenu" << surfaceId << " @ " << service << menuObjectPath.path() << actionObjectPath.path();
82+
83+ QMultiMap<QString, MenuServicePath*>::iterator i = m_surfaceMenus.find(surfaceId);
84+ while (i != m_surfaceMenus.end() && i.key() == surfaceId) {
85+ if (i.value()->m_menuPath == menuObjectPath.path().toUtf8()) {
86+ qWarning() << "Already have a menu for surface:" << surfaceId << service << menuObjectPath.path();
87+ return;
88+ }
89+ ++i;
90+ }
91+
92+ auto menu = new MenuServicePath(service.toUtf8(), menuObjectPath.path().toUtf8(), actionObjectPath.path().toUtf8());
93+ QQmlEngine::setObjectOwnership(menu, QQmlEngine::CppOwnership);
94+
95+ m_surfaceMenus.insert(surfaceId, menu);
96+ Q_EMIT surfaceMenuRegistered(surfaceId);
97+}
98+
99+void ApplicationMenuRegistry::UnregisterSurfaceMenu(const QString &surfaceId, const QDBusObjectPath &menuObjectPath)
100+{
101+ qInfo() << "UnregisterSurfaceMenu" << surfaceId << " @ " << menuObjectPath.path();
102+
103+ QMultiMap<QString, MenuServicePath*>::iterator i = m_surfaceMenus.find(surfaceId);
104+ while (i != m_surfaceMenus.end() && i.key() == surfaceId) {
105+ if (i.value()->m_menuPath == menuObjectPath.path().toUtf8()) {
106+ i.value()->deleteLater();
107+ m_surfaceMenus.erase(i);
108+ Q_EMIT surfaceMenuUnregistered(surfaceId);
109+ break;
110+ }
111+ ++i;
112+ }
113+}
114+
115+QList<QObject*> ApplicationMenuRegistry::getMenusForSurface(const QString &surfaceId)
116+{
117+ QList<QObject*> list;
118+
119+ QMultiMap<QString, MenuServicePath*>::iterator i = m_surfaceMenus.find(surfaceId);
120+ while (i != m_surfaceMenus.end() && i.key() == surfaceId) {
121+ list << i.value();
122+ ++i;
123+ }
124+ return list;
125+}
plugins/Unity/ApplicationMenu/applicationmenuregistry.hnew file+81
@@ -0,0 +1,81 @@
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+class MenuServicePath : public QObject
26+{
27+ Q_OBJECT
28+ Q_PROPERTY(QByteArray service MEMBER m_service CONSTANT)
29+ Q_PROPERTY(QByteArray menuPath MEMBER m_menuPath CONSTANT)
30+ Q_PROPERTY(QByteArray actionPath MEMBER m_actionPath CONSTANT)
31+public:
32+ explicit MenuServicePath(const QByteArray &service,
33+ const QByteArray &menuPath,
34+ const QByteArray &actionPath)
35+ : m_service(service)
36+ , m_menuPath(menuPath)
37+ , m_actionPath(actionPath)
38+ {}
39+
40+ const QByteArray m_service;
41+ const QByteArray m_menuPath;
42+ const QByteArray m_actionPath;
43+};
44+
45+class ApplicationMenuRegistry : public QObject
46+{
47+ Q_OBJECT
48+public:
49+ virtual ~ApplicationMenuRegistry();
50+
51+ // for qml
52+ Q_INVOKABLE QList<QObject*> getMenusForSurface(const QString &surfaceId);
53+
54+ // for dbus
55+ void RegisterAppMenu(pid_t processId,
56+ const QDBusObjectPath &menuObjectPath,
57+ const QDBusObjectPath &actionObjectPath,
58+ const QString &service);
59+ void UnregisterAppMenu(pid_t processId, const QDBusObjectPath &menuObjectPath);
60+
61+ void RegisterSurfaceMenu(const QString &surfaceId,
62+ const QDBusObjectPath &menuObjectPath,
63+ const QDBusObjectPath &actionObjectPath,
64+ const QString &service);
65+ void UnregisterSurfaceMenu(const QString &surfaceId, const QDBusObjectPath &menuObjectPath);
66+
67+Q_SIGNALS:
68+ void appMenuRegistered(pid_t processId);
69+ void appMenuUnregistered(pid_t processId);
70+
71+ void surfaceMenuRegistered(const QString& surface);
72+ void surfaceMenuUnregistered(const QString& surface);
73+
74+protected:
75+ explicit ApplicationMenuRegistry(QObject *parent = 0);
76+
77+ QMultiMap<pid_t, MenuServicePath*> m_appMenus;
78+ QMultiMap<QString, MenuServicePath*> m_surfaceMenus;
79+};
80+
81+#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 docuemented 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 Mir surface IDs and the dbus
15+ address and object that provides the menu using the org.gtk.Menus interface.
16+ </dox:d>
17+ <method name="RegisterAppMenu">
18+ <dox:d><![CDATA[
19+ Associates a gmenumodel with a 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 implmenets the object.
24+ ]]></dox:d>
25+ <arg name="pid" type="u" direction="in">
26+ <dox:d>The surface ID of the surface</dox:d>
27+ </arg>
28+ <arg name="menuObjectPath" type="o" direction="in">
29+ <dox:d>The object on the dbus interface implementing the gmenumodel interface</dox:d>
30+ </arg>
31+ <arg name="actionObjectPath" type="o" direction="in">
32+ <dox:d>The object on the dbus interface implementing the gmenumodel interface</dox:d>
33+ </arg>
34+ <arg name="service" type="s" direction="in">
35+ <dox:d>The address of the connection on DBus (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 a 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 object on the dbus interface implementing the gmenumodel interface</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 implmenets 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 object on the dbus interface implementing the gmenumodel interface</dox:d>
63+ </arg>
64+ <arg name="actionObjectPath" type="o" direction="in">
65+ <dox:d>The object on the dbus interface implementing the gmenumodel interface</dox:d>
66+ </arg>
67+ <arg name="service" type="s" direction="in">
68+ <dox:d>The address of the connection on DBus (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 object on the dbus interface implementing the gmenumodel interface</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+ qWarning() << "Unable to register DBus object /com/ubuntu/MenuRegistrar";
28+ }
29+ if (!connection.registerService("com.ubuntu.MenuRegistrar")) {
30+ qWarning() << "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+43
@@ -0,0 +1,43 @@
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 *service_provider(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+ qDebug() << "LOADING!";
32+ Q_ASSERT(uri == QLatin1String("Unity.ApplicationMenu"));
33+
34+ qmlRegisterUncreatableType<MenuServicePath>(uri, 0, 1, "MenuServicePath", "You cannot create a MenuServicePath");
35+ qmlRegisterSingletonType<DBusApplicationMenuRegistry>(uri, 0, 1, "ApplicationMenuRegistry", service_provider);
36+}
37+
38+void ApplicationMenuPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
39+{
40+ QQmlExtensionPlugin::initializeEngine(engine, uri);
41+
42+ service_provider(nullptr, nullptr);
43+}
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 // CONNECTIVITY_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+19
@@ -0,0 +1,19 @@
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)
19+
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+43
@@ -0,0 +1,43 @@
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 *service_provider(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+ qDebug() << "LOADING2!";
32+ Q_ASSERT(uri == QLatin1String("Unity.ApplicationMenu"));
33+
34+ qmlRegisterUncreatableType<MenuServicePath>(uri, 0, 1, "MenuServicePath", "You cannot create a MenuServicePath");
35+ qmlRegisterSingletonType<ApplicationMenuRegistry>(uri, 0, 1, "ApplicationMenuRegistry", service_provider);
36+}
37+
38+void ApplicationMenuPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
39+{
40+ QQmlExtensionPlugin::initializeEngine(engine, uri);
41+
42+ service_provider(nullptr, nullptr);
43+}
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 // CONNECTIVITY_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)