on xenial help sign in
review comments
commit0abe41570e25239eb903b844a81df6a3f54de5ed authorNick Dedekind <nicholas.dedekind@gmail.com> dateWed 20 Aug 2014, 09:39 (12 years ago) parent2259142
14 files changed+51−78
plugins/Unity/Indicators/qmldir−3 plugins/Unity/Indicators/unitymenumodelcache.cpp+17−14 plugins/Unity/Indicators/unitymenumodelcache.h+4−4 qml/Greeter/Clock.qml+2−1 plugins/Unity/Indicators/CachedUnityMenuModel.qml → qml/Panel/Indicators/CachedUnityMenuModel.qml+4−17 qml/Panel/Indicators/DefaultIndicatorWidget.qml+2−1 qml/Panel/Indicators/IndicatorBase.qml+4−2 tests/mocks/QMenuModel/unitymenumodel.cpp−1 tests/mocks/Unity/Indicators/CMakeLists.txt+6−1 tests/mocks/Unity/Indicators/CachedUnityMenuModel.qml−30 tests/mocks/Unity/Indicators/fakeplugin.cpp+9 tests/mocks/Unity/Indicators/qmldir−1 tests/qmltests/CMakeLists.txt+1−1 tests/qmltests/Panel/Indicators/tst_CachedUnityMenuModel.qml+2−2
plugins/Unity/Indicators/qmldir−3
@@ -1,6 +1,3 @@
11module Unity.Indicators
22plugin IndicatorsQml
33typeinfo 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 @@
2020#include "unitymenumodelcache.h"
2121#include <unitymenumodel.h>
2222
23−#include <QQmlEngine>
24−#include <QDebug>
25−
2623UnityMenuModelCache::UnityMenuModelCache(QObject* parent)
2724 : QObject(parent)
2825{
@@ -32,24 +29,30 @@ UnityMenuModelCache::~UnityMenuModelCache()
3229{
3330}
3431
35−UnityMenuModel* UnityMenuModelCache::model(const QString& path) const
32+UnityMenuModel* UnityMenuModelCache::model(const QByteArray& bus,
33+ const QByteArray& path,
34+ const QVariantMap& actions)
3635{
37− return m_menuModels.value(path, NULL);
38−}
39−
40−void UnityMenuModelCache::registerModel(const QString& path, UnityMenuModel* menuModel)
41−{
42− m_menuModels[path] = menuModel;
36+ if (m_registry.contains(path))
37+ return m_registry[path];
4338
39+ UnityMenuModel* menuModel = new UnityMenuModel;
4440 connect(menuModel, &QObject::destroyed, this, [menuModel, this](QObject*) {
45− QList<QString> keys = m_menuModels.keys(menuModel);
46− Q_FOREACH(const QString& key, keys) {
47− m_menuModels.remove(key);
41+ QList<QByteArray> keys = m_registry.keys(menuModel);
42+ Q_FOREACH(const QByteArray& key, keys) {
43+ m_registry.remove(key);
44+ qDebug() << "removed " << key;
4845 }
4946 });
47+ m_registry[path] = menuModel;
48+
49+ menuModel->setBusName(bus);
50+ menuModel->setMenuObjectPath(path);
51+ menuModel->setActions(actions);
52+ return menuModel;
5053}
5154
5255bool UnityMenuModelCache::contains(UnityMenuModel* menuModel)
5356{
54− return !m_menuModels.keys(menuModel).isEmpty();
57+ return !m_registry.keys(menuModel).isEmpty();
5558}
plugins/Unity/Indicators/unitymenumodelcache.h+4−4
@@ -34,13 +34,13 @@ public:
3434 UnityMenuModelCache(QObject*parent=NULL);
3535 ~UnityMenuModelCache();
3636
37− Q_INVOKABLE UnityMenuModel* model(const QString& path) const;
38− Q_INVOKABLE void registerModel(const QString& path, UnityMenuModel* menuModel);
39−
37+ Q_INVOKABLE UnityMenuModel* model(const QByteArray& bus,
38+ const QByteArray& path,
39+ const QVariantMap& actions);
4040 Q_INVOKABLE bool contains(UnityMenuModel* menuModel);
4141
4242private:
43− QHash<QString, UnityMenuModel*> m_menuModels;
43+ QHash<QByteArray, UnityMenuModel*> m_registry;
4444};
4545
4646#endif // UNITYMENUMODELCACHE_H
qml/Greeter/Clock.qml+2−1
@@ -16,6 +16,7 @@
1616
1717import QtQuick 2.0
1818import Ubuntu.Components 0.1
19+import "../Panel/Indicators"
1920import Unity.Indicators 0.1 as Indicators
2021
2122Item {
@@ -33,7 +34,7 @@ Item {
3334 }
3435 }
3536
36− Indicators.CachedUnityMenuModel {
37+ CachedUnityMenuModel {
3738 id: timeModel
3839 objectName: "timeModel"
3940
plugins/Unity/Indicators/CachedUnityMenuModel.qml → qml/Panel/Indicators/CachedUnityMenuModel.qmlrenamed+4−17
@@ -29,24 +29,11 @@ Item {
2929 property string menuObjectPath
3030 readonly property bool ready: busName!=="" && actionsObjectPath!=="" && menuObjectPath!==""
3131
32− property UnityMenuModel model: {
32+ property var model: {
3333 if (!ready) return null;
3434
35− var newModel = Indicators.UnityMenuModelCache.model(menuObjectPath);
36− if (!newModel) {
37− newModel = modelComponent.createObject(null,
38− {
39− "busName": cachedModel.busName,
40− "menuObjectPath": cachedModel.menuObjectPath,
41− "actions": { "indicator": cachedModel.actionsObjectPath },
42− });
43− Indicators.UnityMenuModelCache.registerModel(newModel.menuObjectPath, newModel);
44− }
45− return newModel;
46− }
47−
48− Component {
49− id: modelComponent
50− UnityMenuModel {}
35+ return Indicators.UnityMenuModelCache.model(cachedModel.busName,
36+ cachedModel.menuObjectPath,
37+ { "indicator": cachedModel.actionsObjectPath });
5138 }
5239}
qml/Panel/Indicators/DefaultIndicatorWidget.qml+2−1
@@ -63,6 +63,7 @@ IndicatorBase {
6363 }
6464
6565 Row {
66+ id: iconRow
6667 anchors {
6768 top: parent.top
6869 bottom: parent.bottom
@@ -73,7 +74,7 @@ IndicatorBase {
7374
7475 Item {
7576 width: itemImage.width + units.gu(1)
76− anchors { top: parent.top; bottom: parent.bottom }
77+ height: iconRow.height
7778
7879 StatusIcon {
7980 id: itemImage
qml/Panel/Indicators/IndicatorBase.qml+4−2
@@ -34,6 +34,7 @@ Item {
3434 property string deviceMenuObjectPath: menuObjectPath
3535
3636 property alias menuModel: cachedModel.model
37+ property alias rootActionState: rootAction
3738
3839 CachedUnityMenuModel {
3940 id: cachedModel
@@ -42,8 +43,9 @@ Item {
4243 menuObjectPath: indicatorItem.deviceMenuObjectPath
4344 }
4445
45− property RootActionState rootActionState: RootActionState {
46− menu: menuModel
46+ RootActionState {
47+ id: rootAction
48+ menu: menuModel ? menuModel : null
4749 onUpdated: indicatorItem.rootActionStateChanged()
4850 }
4951}
tests/mocks/QMenuModel/unitymenumodel.cpp−1
@@ -17,7 +17,6 @@
1717 */
1818
1919#include "unitymenumodel.h"
20−#include <QDebug>
2120
2221enum MenuRoles {
2322 LabelRole = Qt::DisplayRole + 1,
tests/mocks/Unity/Indicators/CMakeLists.txt+6−1
@@ -14,6 +14,7 @@ set(IndicatorsFakeQml_SOURCES
1414 fakeplugin.cpp
1515 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/indicators.h
1616 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/menucontentactivator.cpp
17+ ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/unitymenumodelcache.cpp
1718 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/unitymenumodelstack.cpp
1819 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/visibleindicatorsmodel.cpp
1920 fakeindicatorsmodel.cpp
@@ -33,7 +34,11 @@ add_library(IndicatorsFakeQml SHARED
3334)
3435add_definitions(-DUNITYINDICATORS_LIBRARY)
3536
36−target_link_libraries(IndicatorsFakeQml)
37+add_dependencies(IndicatorsFakeQml QMenuModelQml)
38+target_link_libraries(IndicatorsFakeQml
39+ -L${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel
40+ -lqmenumodel
41+)
3742
3843qt5_use_modules(IndicatorsFakeQml Core Qml Quick)
3944
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 @@
2626#include "fakeindicatorsmodel.h"
2727#include "indicators.h"
2828#include "menucontentactivator.h"
29+#include "unitymenumodelcache.h"
2930#include "unitymenumodelstack.h"
3031#include "visibleindicatorsmodel.h"
3132
33+static QObject* menuModelCacheSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
34+ Q_UNUSED(engine);
35+ Q_UNUSED(scriptEngine);
36+ return new UnityMenuModelCache;
37+}
38+
3239void IndicatorsFakePlugin::registerTypes(const char * uri)
3340{
3441 Q_INIT_RESOURCE(indicators_fake);
@@ -41,6 +48,8 @@ void IndicatorsFakePlugin::registerTypes(const char * uri)
4148 qmlRegisterType<UnityMenuModelStack>(uri, 0, 1, "UnityMenuModelStack");
4249 qmlRegisterType<VisibleIndicatorsModel>(uri, 0, 1, "VisibleIndicatorsModel");
4350
51+ qmlRegisterSingletonType<UnityMenuModelCache>(uri, 0, 1, "UnityMenuModelCache", menuModelCacheSingleton);
52+
4453 // external uncreatables
4554 qmlRegisterUncreatableType<MenuContentState>(uri, 0, 1, "MenuContentState", "Can't create MenuContentState class");
4655 qmlRegisterUncreatableType<ActionState>(uri, 0, 1, "ActionState", "Can't create ActionState class");
tests/mocks/Unity/Indicators/qmldir−1
@@ -2,7 +2,6 @@ module Unity.Indicators
22plugin IndicatorsFakeQml
33typeinfo Indicators.qmltypes
44
5−CachedUnityMenuModel 0.1 CachedUnityMenuModel.qml
65IndicatorsModel 0.1 IndicatorsModel.qml
76FakeMenuPage 0.1 FakeMenuPage.qml
87RootActionState 0.1 RootActionState.qml
tests/qmltests/CMakeLists.txt+1−1
@@ -72,7 +72,7 @@ add_qml_test(Panel Panel)
7272add_qml_test(Panel SearchIndicator)
7373add_qml_test(Panel/Indicators DefaultIndicatorWidget ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
7474add_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")
7676# These MenuItemFactory tests need the test/mocks/ to come before plugins/
7777add_qml_test(Panel/Indicators MenuItemFactory IMPORT_PATHS ${CMAKE_BINARY_DIR}/tests/mocks ${qmltest_DEFAULT_IMPORT_PATHS})
7878add_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
1818import QtTest 1.0
1919import Unity.Test 0.1 as UT
2020import QMenuModel 0.1
21−import Unity.Indicators 0.1 as Indicators
21+import "../../../../qml/Panel/Indicators"
2222
2323Item {
2424 id: root
@@ -27,7 +27,7 @@ Item {
2727
2828 Component {
2929 id: model
30− Indicators.CachedUnityMenuModel {}
30+ CachedUnityMenuModel {}
3131 }
3232
3333 UT.UnityTestCase {