on xenial help sign in
review comments
0abe415Nick Dedekind
plugins/Unity/Indicators/qmldir−3
@@ -1,6 +1,3 @@
1module Unity.Indicators
1module Unity.Indicators
2plugin IndicatorsQml
2plugin IndicatorsQml
3typeinfo Indicators.qmltypes
3typeinfo Indicators.qmltypes
4−
5−CachedUnityMenuModel 0.1 CachedUnityMenuModel.qml
6−IndicatorBase 0.1 IndicatorBase.qml
plugins/Unity/Indicators/unitymenumodelcache.cpp+17−14
@@ -20,9 +20,6 @@
20#include "unitymenumodelcache.h"
20#include "unitymenumodelcache.h"
21#include <unitymenumodel.h>
21#include <unitymenumodel.h>
22
22
23−#include <QQmlEngine>
24−#include <QDebug>
25−
26UnityMenuModelCache::UnityMenuModelCache(QObject* parent)
23UnityMenuModelCache::UnityMenuModelCache(QObject* parent)
27 : QObject(parent)
24 : QObject(parent)
28{
25{
@@ -32,24 +29,30 @@ UnityMenuModelCache::~UnityMenuModelCache()
32{
29{
33}
30}
34
31
35−UnityMenuModel* UnityMenuModelCache::model(const QString& path) const
32+UnityMenuModel* UnityMenuModelCache::model(const QByteArray& bus,
33+ const QByteArray& path,
34+ const QVariantMap& actions)
36{
35{
37− return m_menuModels.value(path, NULL);
36+ if (m_registry.contains(path))
38−}
37+ return m_registry[path];
39−
40−void UnityMenuModelCache::registerModel(const QString& path, UnityMenuModel* menuModel)
41−{
42− m_menuModels[path] = menuModel;
43
38
39+ UnityMenuModel* menuModel = new UnityMenuModel;
44 connect(menuModel, &QObject::destroyed, this, [menuModel, this](QObject*) {
40 connect(menuModel, &QObject::destroyed, this, [menuModel, this](QObject*) {
45− QList<QString> keys = m_menuModels.keys(menuModel);
41+ QList<QByteArray> keys = m_registry.keys(menuModel);
46− Q_FOREACH(const QString& key, keys) {
42+ Q_FOREACH(const QByteArray& key, keys) {
47− m_menuModels.remove(key);
43+ m_registry.remove(key);
44+ qDebug() << "removed " << key;
48 }
45 }
49 });
46 });
47+ m_registry[path] = menuModel;
48+
49+ menuModel->setBusName(bus);
50+ menuModel->setMenuObjectPath(path);
51+ menuModel->setActions(actions);
52+ return menuModel;
50}
53}
51
54
52bool UnityMenuModelCache::contains(UnityMenuModel* menuModel)
55bool UnityMenuModelCache::contains(UnityMenuModel* menuModel)
53{
56{
54− return !m_menuModels.keys(menuModel).isEmpty();
57+ return !m_registry.keys(menuModel).isEmpty();
55}
58}
plugins/Unity/Indicators/unitymenumodelcache.h+4−4
@@ -34,13 +34,13 @@ public:
34 UnityMenuModelCache(QObject*parent=NULL);
34 UnityMenuModelCache(QObject*parent=NULL);
35 ~UnityMenuModelCache();
35 ~UnityMenuModelCache();
36
36
37− Q_INVOKABLE UnityMenuModel* model(const QString& path) const;
37+ Q_INVOKABLE UnityMenuModel* model(const QByteArray& bus,
38− Q_INVOKABLE void registerModel(const QString& path, UnityMenuModel* menuModel);
38+ const QByteArray& path,
39−
39+ const QVariantMap& actions);
40 Q_INVOKABLE bool contains(UnityMenuModel* menuModel);
40 Q_INVOKABLE bool contains(UnityMenuModel* menuModel);
41
41
42private:
42private:
43− QHash<QString, UnityMenuModel*> m_menuModels;
43+ QHash<QByteArray, UnityMenuModel*> m_registry;
44};
44};
45
45
46#endif // UNITYMENUMODELCACHE_H
46#endif // UNITYMENUMODELCACHE_H
qml/Greeter/Clock.qml+2−1
@@ -16,6 +16,7 @@
16
16
17import QtQuick 2.0
17import QtQuick 2.0
18import Ubuntu.Components 0.1
18import Ubuntu.Components 0.1
19+import "../Panel/Indicators"
19import Unity.Indicators 0.1 as Indicators
20import Unity.Indicators 0.1 as Indicators
20
21
21Item {
22Item {
@@ -33,7 +34,7 @@ Item {
33 }
34 }
34 }
35 }
35
36
36− Indicators.CachedUnityMenuModel {
37+ CachedUnityMenuModel {
37 id: timeModel
38 id: timeModel
38 objectName: "timeModel"
39 objectName: "timeModel"
39
40
plugins/Unity/Indicators/CachedUnityMenuModel.qml → qml/Panel/Indicators/CachedUnityMenuModel.qmlrenamed+4−17
@@ -29,24 +29,11 @@ Item {
29 property string menuObjectPath
29 property string menuObjectPath
30 readonly property bool ready: busName!=="" && actionsObjectPath!=="" && menuObjectPath!==""
30 readonly property bool ready: busName!=="" && actionsObjectPath!=="" && menuObjectPath!==""
31
31
32− property UnityMenuModel model: {
32+ property var model: {
33 if (!ready) return null;
33 if (!ready) return null;
34
34
35− var newModel = Indicators.UnityMenuModelCache.model(menuObjectPath);
35+ return Indicators.UnityMenuModelCache.model(cachedModel.busName,
36− if (!newModel) {
37− newModel = modelComponent.createObject(null,
38− {
39− "busName": cachedModel.busName,
40− "menuObjectPath": cachedModel.menuObjectPath,
36+ cachedModel.menuObjectPath,
41− "actions": { "indicator": cachedModel.actionsObjectPath },
37+ { "indicator": cachedModel.actionsObjectPath });
42− });
43− Indicators.UnityMenuModelCache.registerModel(newModel.menuObjectPath, newModel);
44− }
45− return newModel;
46− }
47−
48− Component {
49− id: modelComponent
50− UnityMenuModel {}
51 }
38 }
52}
39}
qml/Panel/Indicators/DefaultIndicatorWidget.qml+2−1
@@ -63,6 +63,7 @@ IndicatorBase {
63 }
63 }
64
64
65 Row {
65 Row {
66+ id: iconRow
66 anchors {
67 anchors {
67 top: parent.top
68 top: parent.top
68 bottom: parent.bottom
69 bottom: parent.bottom
@@ -73,7 +74,7 @@ IndicatorBase {
73
74
74 Item {
75 Item {
75 width: itemImage.width + units.gu(1)
76 width: itemImage.width + units.gu(1)
76− anchors { top: parent.top; bottom: parent.bottom }
77+ height: iconRow.height
77
78
78 StatusIcon {
79 StatusIcon {
79 id: itemImage
80 id: itemImage
qml/Panel/Indicators/IndicatorBase.qml+4−2
@@ -34,6 +34,7 @@ Item {
34 property string deviceMenuObjectPath: menuObjectPath
34 property string deviceMenuObjectPath: menuObjectPath
35
35
36 property alias menuModel: cachedModel.model
36 property alias menuModel: cachedModel.model
37+ property alias rootActionState: rootAction
37
38
38 CachedUnityMenuModel {
39 CachedUnityMenuModel {
39 id: cachedModel
40 id: cachedModel
@@ -42,8 +43,9 @@ Item {
42 menuObjectPath: indicatorItem.deviceMenuObjectPath
43 menuObjectPath: indicatorItem.deviceMenuObjectPath
43 }
44 }
44
45
45− property RootActionState rootActionState: RootActionState {
46+ RootActionState {
47+ id: rootAction
46− menu: menuModel
48+ menu: menuModel ? menuModel : null
47 onUpdated: indicatorItem.rootActionStateChanged()
49 onUpdated: indicatorItem.rootActionStateChanged()
48 }
50 }
49}
51}
tests/mocks/QMenuModel/unitymenumodel.cpp−1
@@ -17,7 +17,6 @@
17 */
17 */
18
18
19#include "unitymenumodel.h"
19#include "unitymenumodel.h"
20−#include <QDebug>
21
20
22enum MenuRoles {
21enum MenuRoles {
23 LabelRole = Qt::DisplayRole + 1,
22 LabelRole = Qt::DisplayRole + 1,
tests/mocks/Unity/Indicators/CMakeLists.txt+6−1
@@ -14,6 +14,7 @@ set(IndicatorsFakeQml_SOURCES
14 fakeplugin.cpp
14 fakeplugin.cpp
15 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/indicators.h
15 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/indicators.h
16 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/menucontentactivator.cpp
16 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/menucontentactivator.cpp
17+ ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/unitymenumodelcache.cpp
17 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/unitymenumodelstack.cpp
18 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/unitymenumodelstack.cpp
18 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/visibleindicatorsmodel.cpp
19 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/visibleindicatorsmodel.cpp
19 fakeindicatorsmodel.cpp
20 fakeindicatorsmodel.cpp
@@ -33,7 +34,11 @@ add_library(IndicatorsFakeQml SHARED
33)
34)
34add_definitions(-DUNITYINDICATORS_LIBRARY)
35add_definitions(-DUNITYINDICATORS_LIBRARY)
35
36
37+add_dependencies(IndicatorsFakeQml QMenuModelQml)
36−target_link_libraries(IndicatorsFakeQml)
38+target_link_libraries(IndicatorsFakeQml
39+ -L${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel
40+ -lqmenumodel
41+)
37
42
38qt5_use_modules(IndicatorsFakeQml Core Qml Quick)
43qt5_use_modules(IndicatorsFakeQml Core Qml Quick)
39
44
tests/mocks/Unity/Indicators/CachedUnityMenuModel.qmldeleted−30
@@ -1,30 +0,0 @@
1−/*
2− * Copyright 2013 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Authors:
17− * Nick Dedekind <nick.dedekind@canonical.com>
18− */
19−
20−import QtQuick 2.0
21−
22−Item {
23− property string busName: ""
24− property string actionsObjectPath: ""
25− property string menuObjectPath: ""
26−
27− readonly property bool ready: false
28−
29− property QtObject model: null
30−}
tests/mocks/Unity/Indicators/fakeplugin.cpp+9
@@ -26,9 +26,16 @@
26#include "fakeindicatorsmodel.h"
26#include "fakeindicatorsmodel.h"
27#include "indicators.h"
27#include "indicators.h"
28#include "menucontentactivator.h"
28#include "menucontentactivator.h"
29+#include "unitymenumodelcache.h"
29#include "unitymenumodelstack.h"
30#include "unitymenumodelstack.h"
30#include "visibleindicatorsmodel.h"
31#include "visibleindicatorsmodel.h"
31
32
33+static QObject* menuModelCacheSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
34+ Q_UNUSED(engine);
35+ Q_UNUSED(scriptEngine);
36+ return new UnityMenuModelCache;
37+}
38+
32void IndicatorsFakePlugin::registerTypes(const char * uri)
39void IndicatorsFakePlugin::registerTypes(const char * uri)
33{
40{
34 Q_INIT_RESOURCE(indicators_fake);
41 Q_INIT_RESOURCE(indicators_fake);
@@ -41,6 +48,8 @@ void IndicatorsFakePlugin::registerTypes(const char * uri)
41 qmlRegisterType<UnityMenuModelStack>(uri, 0, 1, "UnityMenuModelStack");
48 qmlRegisterType<UnityMenuModelStack>(uri, 0, 1, "UnityMenuModelStack");
42 qmlRegisterType<VisibleIndicatorsModel>(uri, 0, 1, "VisibleIndicatorsModel");
49 qmlRegisterType<VisibleIndicatorsModel>(uri, 0, 1, "VisibleIndicatorsModel");
43
50
51+ qmlRegisterSingletonType<UnityMenuModelCache>(uri, 0, 1, "UnityMenuModelCache", menuModelCacheSingleton);
52+
44 // external uncreatables
53 // external uncreatables
45 qmlRegisterUncreatableType<MenuContentState>(uri, 0, 1, "MenuContentState", "Can't create MenuContentState class");
54 qmlRegisterUncreatableType<MenuContentState>(uri, 0, 1, "MenuContentState", "Can't create MenuContentState class");
46 qmlRegisterUncreatableType<ActionState>(uri, 0, 1, "ActionState", "Can't create ActionState class");
55 qmlRegisterUncreatableType<ActionState>(uri, 0, 1, "ActionState", "Can't create ActionState class");
tests/mocks/Unity/Indicators/qmldir−1
@@ -2,7 +2,6 @@ module Unity.Indicators
2plugin IndicatorsFakeQml
2plugin IndicatorsFakeQml
3typeinfo Indicators.qmltypes
3typeinfo Indicators.qmltypes
4
4
5−CachedUnityMenuModel 0.1 CachedUnityMenuModel.qml
6IndicatorsModel 0.1 IndicatorsModel.qml
5IndicatorsModel 0.1 IndicatorsModel.qml
7FakeMenuPage 0.1 FakeMenuPage.qml
6FakeMenuPage 0.1 FakeMenuPage.qml
8RootActionState 0.1 RootActionState.qml
7RootActionState 0.1 RootActionState.qml
tests/qmltests/CMakeLists.txt+1−1
@@ -72,7 +72,7 @@ add_qml_test(Panel Panel)
72add_qml_test(Panel SearchIndicator)
72add_qml_test(Panel SearchIndicator)
73add_qml_test(Panel/Indicators DefaultIndicatorWidget ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
73add_qml_test(Panel/Indicators DefaultIndicatorWidget ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
74add_qml_test(Panel/Indicators DefaultIndicatorPage ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
74add_qml_test(Panel/Indicators DefaultIndicatorPage ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
75−add_qml_test(Panel/Indicators CachedUnityMenuModel IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${CMAKE_BINARY_DIR}/tests/utils/modules)
75+add_qml_test(Panel/Indicators CachedUnityMenuModel ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
76# These MenuItemFactory tests need the test/mocks/ to come before plugins/
76# These MenuItemFactory tests need the test/mocks/ to come before plugins/
77add_qml_test(Panel/Indicators MenuItemFactory IMPORT_PATHS ${CMAKE_BINARY_DIR}/tests/mocks ${qmltest_DEFAULT_IMPORT_PATHS})
77add_qml_test(Panel/Indicators MenuItemFactory IMPORT_PATHS ${CMAKE_BINARY_DIR}/tests/mocks ${qmltest_DEFAULT_IMPORT_PATHS})
78add_qml_test(Panel/Indicators MessageMenuItemFactory IMPORT_PATHS ${CMAKE_BINARY_DIR}/tests/mocks ${qmltest_DEFAULT_IMPORT_PATHS})
78add_qml_test(Panel/Indicators MessageMenuItemFactory IMPORT_PATHS ${CMAKE_BINARY_DIR}/tests/mocks ${qmltest_DEFAULT_IMPORT_PATHS})
tests/qmltests/Panel/Indicators/tst_CachedUnityMenuModel.qml+2−2
@@ -18,7 +18,7 @@ import QtQuick 2.0
18import QtTest 1.0
18import QtTest 1.0
19import Unity.Test 0.1 as UT
19import Unity.Test 0.1 as UT
20import QMenuModel 0.1
20import QMenuModel 0.1
21−import Unity.Indicators 0.1 as Indicators
21+import "../../../../qml/Panel/Indicators"
22
22
23Item {
23Item {
24 id: root
24 id: root
@@ -27,7 +27,7 @@ Item {
27
27
28 Component {
28 Component {
29 id: model
29 id: model
30− Indicators.CachedUnityMenuModel {}
30+ CachedUnityMenuModel {}
31 }
31 }
32
32
33 UT.UnityTestCase {
33 UT.UnityTestCase {