on xenial help sign in
reverted unitymenumodel aware VisibleModel
1832aceNick Dedekind
Panel/IndicatorItem.qml+1
@@ -26,6 +26,7 @@ Item {
26 property bool highlighted: false
26 property bool highlighted: false
27 property bool dimmed: false
27 property bool dimmed: false
28 property var indicatorProperties: undefined
28 property var indicatorProperties: undefined
29+ property bool indicatorVisible: loader.item != undefined && loader.status == Loader.Ready ? loader.item.enabled : false
29
30
30 opacity: dimmed ? 0.4 : 1
31 opacity: dimmed ? 0.4 : 1
31 Behavior on opacity { StandardAnimation {} }
32 Behavior on opacity { StandardAnimation {} }
Panel/IndicatorRow.qml+8−6
@@ -53,16 +53,11 @@ Item {
53 objectName: "rowRepeater"
53 objectName: "rowRepeater"
54 model: indicatorsModel ? indicatorsModel : undefined
54 model: indicatorsModel ? indicatorsModel : undefined
55
55
56− onItemRemoved: {
57− if (currentItemIndex == -1) {
58− setDefaultItem(0);
59− }
60− }
61−
62 Item {
56 Item {
63 id: itemWrapper
57 id: itemWrapper
64 height: indicatorRow.height
58 height: indicatorRow.height
65 width: indicatorItem.width
59 width: indicatorItem.width
60+ visible: indicatorItem.indicatorVisible
66
61
67 property int ownIndex: index
62 property int ownIndex: index
68 property alias highlighted: indicatorItem.highlighted
63 property alias highlighted: indicatorItem.highlighted
@@ -77,6 +72,13 @@ Item {
77
72
78 widgetSource: model.widgetSource
73 widgetSource: model.widgetSource
79 indicatorProperties : model.indicatorProperties
74 indicatorProperties : model.indicatorProperties
75+
76+ Component.onCompleted: {
77+ indicatorsModel.setData(index, indicatorVisible, Indicators.IndicatorsModelRole.IsVisible);
78+ }
79+ onIndicatorVisibleChanged: {
80+ indicatorsModel.setData(index, indicatorVisible, Indicators.IndicatorsModelRole.IsVisible);
81+ }
80 }
82 }
81
83
82 opacity: {
84 opacity: {
Panel/Indicators.qml+2−16
@@ -17,8 +17,6 @@
17import QtQuick 2.0
17import QtQuick 2.0
18import Ubuntu.Components 0.1
18import Ubuntu.Components 0.1
19import Ubuntu.Gestures 0.1
19import Ubuntu.Gestures 0.1
20−import Unity.Indicators 0.1 as Indicators
21−import Utils 0.1
22
20
23import "../Components"
21import "../Components"
24import "../Components/ListItems"
22import "../Components/ListItems"
@@ -177,7 +175,7 @@ Showable {
177 top: indicatorRow.bottom
175 top: indicatorRow.bottom
178 bottom: handle.top
176 bottom: handle.top
179 }
177 }
180− indicatorsModel: filteredIndicators
178+ indicatorsModel: indicatorsModel
181 clip: !indicators.fullyOpened
179 clip: !indicators.fullyOpened
182 activeHeader: indicators.state == "hint" || indicators.state == "reveal"
180 activeHeader: indicators.state == "hint" || indicators.state == "reveal"
183
181
@@ -251,18 +249,6 @@ Showable {
251 id: indicatorsModel
249 id: indicatorsModel
252 }
250 }
253
251
254− SortFilterProxyModel {
255− id: filteredIndicators
256− model: Indicators.VisibleIndicatorsModel {
257− model: indicatorsModel
258− profile: "phone"
259− }
260− dynamicSortFilter: true
261−
262− filterRole: Indicators.IndicatorsModelRole.IsVisible
263− filterRegExp: RegExp("^true$")
264− }
265−
266 IndicatorRow {
252 IndicatorRow {
267 id: indicatorRow
253 id: indicatorRow
268 objectName: "indicatorRow"
254 objectName: "indicatorRow"
@@ -271,7 +257,7 @@ Showable {
271 right: parent.right
257 right: parent.right
272 }
258 }
273 height: indicators.panelHeight
259 height: indicators.panelHeight
274− indicatorsModel: filteredIndicators
260+ indicatorsModel: indicatorsModel
275 state: indicators.state
261 state: indicators.state
276
262
277 Connections {
263 Connections {
Panel/MenuContent.qml+18−6
@@ -17,6 +17,7 @@
17import QtQuick 2.0
17import QtQuick 2.0
18import Ubuntu.Components 0.1
18import Ubuntu.Components 0.1
19import Unity.Indicators 0.1 as Indicators
19import Unity.Indicators 0.1 as Indicators
20+import Utils 0.1
20import "../Components"
21import "../Components"
21
22
22// FIXME : We dont want to use MainView.
23// FIXME : We dont want to use MainView.
@@ -27,7 +28,7 @@ MainView {
27
28
28 property QtObject indicatorsModel: null
29 property QtObject indicatorsModel: null
29 property bool __contentActive: false
30 property bool __contentActive: false
30− readonly property int currentMenuIndex : tabs.selectedTabIndex
31+ readonly property int currentMenuIndex : filteredIndicators.mapToSource(tabs.selectedTabIndex)
31 backgroundColor: "#221e1c" // FIXME not in palette yet
32 backgroundColor: "#221e1c" // FIXME not in palette yet
32 property int contentReleaseInterval: 20000
33 property int contentReleaseInterval: 20000
33 property bool activeHeader: false
34 property bool activeHeader: false
@@ -36,11 +37,13 @@ MainView {
36 height: units.gu(42)
37 height: units.gu(42)
37
38
38 function setCurrentMenuIndex(index) {
39 function setCurrentMenuIndex(index) {
40+ var filteredIndex = filteredIndicators.mapFromSource(index)
41+
39− if (tabs.selectedTabIndex !== index) {
42+ if (tabs.selectedTabIndex !== filteredIndex) {
40 if (tabs.selectedTabIndex == -1) {
43 if (tabs.selectedTabIndex == -1) {
41 tabs.tabBar.animate = false;
44 tabs.tabBar.animate = false;
42 }
45 }
43− tabs.selectedTabIndex = index;
46+ tabs.selectedTabIndex = filteredIndex;
44 tabs.tabBar.animate = true;
47 tabs.tabBar.animate = true;
45 }
48 }
46 }
49 }
@@ -61,6 +64,15 @@ MainView {
61 tabs.tabBar.alwaysSelectionMode = activeHeader;
64 tabs.tabBar.alwaysSelectionMode = activeHeader;
62 }
65 }
63
66
67+ SortFilterProxyModel {
68+ id: filteredIndicators
69+ model: indicatorsModel
70+ dynamicSortFilter: true
71+
72+ filterRole: Indicators.IndicatorsModelRole.IsVisible
73+ filterRegExp: RegExp("^true$")
74+ }
75+
64 Tabs {
76 Tabs {
65 id: tabs
77 id: tabs
66 objectName: "tabs"
78 objectName: "tabs"
@@ -69,8 +81,8 @@ MainView {
69
81
70 Repeater {
82 Repeater {
71 id: repeater
83 id: repeater
72− model: indicatorsModel
84+ model: filteredIndicators
73− objectName: "tabsRepeater"
85+ objectName: "menus"
74
86
75 // FIXME: This is needed because tabs dont handle repeaters well.
87 // FIXME: This is needed because tabs dont handle repeaters well.
76 // Due to the child ordering happening after child insertion.
88 // Due to the child ordering happening after child insertion.
@@ -114,7 +126,7 @@ MainView {
114 item[pName] = indicatorProperties[pName]
126 item[pName] = indicatorProperties[pName]
115 }
127 }
116 }
128 }
117− if (contentActive && tabs.visible) {
129+ if (contentActive && menus.visible) {
118 item.start()
130 item.start()
119 }
131 }
120 }
132 }
plugins/Unity/Indicators/CMakeLists.txt−2
@@ -24,7 +24,6 @@ include_directories(
24)
24)
25
25
26set(IndicatorsQML_SOURCES
26set(IndicatorsQML_SOURCES
27− cachedunitymenumodel.cpp
28 indicator.cpp
27 indicator.cpp
29 indicators.h
28 indicators.h
30 indicatorsmanager.cpp
29 indicatorsmanager.cpp
@@ -35,7 +34,6 @@ set(IndicatorsQML_SOURCES
35 rootactionstate.cpp
34 rootactionstate.cpp
36 unitymenumodelcache.cpp
35 unitymenumodelcache.cpp
37 unitymenumodelstack.cpp
36 unitymenumodelstack.cpp
38− visibleindicatorsmodel.cpp
39)
37)
40add_definitions(-DUNITYINDICATORS_LIBRARY)
38add_definitions(-DUNITYINDICATORS_LIBRARY)
41
39
plugins/Unity/Indicators/cachedunitymenumodel.cppdeleted−113
@@ -1,113 +0,0 @@
1−/*
2− * Copyright (C) 2012, 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 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− * Authors:
17− * Nick Dedekind <nick.dedekind@canonical.com>
18− */
19−
20−// self
21−#include "cachedunitymenumodel.h"
22−#include "unitymenumodelcache.h"
23−
24−#include <unitymenumodel.h>
25−
26−CachedUnityMenuModel::CachedUnityMenuModel(QObject* parent)
27− : QObject(parent),
28− m_model(NULL)
29−{
30−}
31−
32−CachedUnityMenuModel::~CachedUnityMenuModel()
33−{
34− // deref old model.
35− if (m_model) {
36− UnityMenuModelCache::cache()->deref(m_menuObjectPath);
37− m_model = NULL;
38− }
39−}
40−
41−UnityMenuModel* CachedUnityMenuModel::model() const
42−{
43− return m_model;
44−}
45−
46−QString CachedUnityMenuModel::busName() const
47−{
48− return m_busName;
49−}
50−
51−void CachedUnityMenuModel::setBusName(const QString &name)
52−{
53− if (m_busName != name) {
54− m_busName = name;
55− Q_EMIT busNameChanged(m_busName);
56−
57− if (m_model && m_model->busName() != m_busName) {
58− m_model->setBusName(m_busName.toUtf8());
59− }
60− }
61−}
62−
63−QVariantMap CachedUnityMenuModel::actions() const
64−{
65− return m_model->actions();
66−}
67−
68−void CachedUnityMenuModel::setActions(const QVariantMap &actions)
69−{
70− if (m_actions != actions) {
71− m_actions = actions;
72− Q_EMIT actionsChanged(m_actions);
73−
74− if (m_model && m_model->actions() != m_actions) {
75− m_model->setActions(m_actions);
76− }
77− }
78−}
79−
80−QString CachedUnityMenuModel::menuObjectPath() const
81−{
82− return m_model->menuObjectPath();
83−}
84−
85−void CachedUnityMenuModel::setMenuObjectPath(const QString &path)
86−{
87− if (m_menuObjectPath != path) {
88− // deref old model.
89− if (m_model) {
90− UnityMenuModelCache::cache()->deref(m_menuObjectPath);
91− m_model = NULL;
92− }
93−
94− m_menuObjectPath = path;
95− Q_EMIT menuObjectPathChanged(m_menuObjectPath);
96−
97− // create new model.
98− if (!m_menuObjectPath.isEmpty()) {
99− m_model = UnityMenuModelCache::cache()->model(m_menuObjectPath);
100− if (!m_model) {
101− m_model = new UnityMenuModel;
102− if (!m_busName.isEmpty()) m_model->setBusName(m_busName.toUtf8());
103− if (!m_actions.isEmpty()) m_model->setActions(m_actions);
104− m_model->setMenuObjectPath(m_menuObjectPath.toUtf8());
105−
106− UnityMenuModelCache::cache()->registerModel(m_menuObjectPath, m_model);
107− }
108− UnityMenuModelCache::cache()->ref(m_menuObjectPath);
109− }
110−
111− Q_EMIT modelChanged(m_model);
112− }
113−}
plugins/Unity/Indicators/cachedunitymenumodel.hdeleted−66
@@ -1,66 +0,0 @@
1−/*
2− * Copyright (C) 2012, 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 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− * Authors:
17− * Nick Dedekind <nick.dedekind@canonical.com>
18− */
19−
20−#ifndef CACHEDUNITYMENUMODEL_H
21−#define CACHEDUNITYMENUMODEL_H
22−
23− #include <QObject>
24− #include <QVariantMap>
25−
26−class UnityMenuModel;
27−
28−class CachedUnityMenuModel : public QObject
29−{
30− Q_OBJECT
31−
32− Q_PROPERTY(UnityMenuModel* model READ model NOTIFY modelChanged)
33− Q_PROPERTY(QString busName READ busName WRITE setBusName NOTIFY busNameChanged)
34− Q_PROPERTY(QVariantMap actions READ actions WRITE setActions NOTIFY actionsChanged)
35− Q_PROPERTY(QString menuObjectPath READ menuObjectPath WRITE setMenuObjectPath NOTIFY menuObjectPathChanged)
36−
37−public:
38− explicit CachedUnityMenuModel(QObject *parent = 0);
39− CachedUnityMenuModel(UnityMenuModel* model);
40− ~CachedUnityMenuModel();
41−
42− UnityMenuModel* model() const;
43−
44− QString busName() const;
45− void setBusName(const QString &name);
46−
47− QVariantMap actions() const;
48− void setActions(const QVariantMap &actions);
49−
50− QString menuObjectPath() const;
51− void setMenuObjectPath(const QString &path);
52−
53−Q_SIGNALS:
54− void modelChanged(UnityMenuModel* model);
55− void busNameChanged(const QString& busName);
56− void actionsChanged(const QVariantMap& action);
57− void menuObjectPathChanged(const QString& menuObjectPath);
58−
59−private:
60− UnityMenuModel* m_model;
61− QString m_busName;
62− QVariantMap m_actions;
63− QString m_menuObjectPath;
64−};
65−
66−#endif // CACHEDUNITYMENUMODEL_H
plugins/Unity/Indicators/indicator.cpp+17−3
@@ -18,14 +18,13 @@
18 */
18 */
19
19
20#include "indicator.h"
20#include "indicator.h"
21−#include "cachedunitymenumodel.h"
22
21
23#include <QStringList>
22#include <QStringList>
24−#include <unitymenumodel.h>
25
23
26Indicator::Indicator(QObject *parent)
24Indicator::Indicator(QObject *parent)
27 : QObject(parent),
25 : QObject(parent),
28− m_position(0)
26+ m_position(0),
27+ m_visible(false)
29{
28{
30}
29}
31
30
@@ -88,6 +87,21 @@ void Indicator::setPosition(int position)
88 }
87 }
89}
88}
90
89
90+bool Indicator::isVisible() const
91+{
92+ return m_visible;
93+}
94+
95+bool Indicator::setVisible(bool visible)
96+{
97+ if (visible != m_visible) {
98+ m_visible = visible;
99+ Q_EMIT visibleChanged(m_visible);
100+ return true;
101+ }
102+ return false;
103+}
104+
91QVariant Indicator::indicatorProperties() const
105QVariant Indicator::indicatorProperties() const
92{
106{
93 return m_properties;
107 return m_properties;
plugins/Unity/Indicators/indicator.h+6−2
@@ -25,8 +25,6 @@
25
25
26#include <QObject>
26#include <QObject>
27#include <QSettings>
27#include <QSettings>
28−class QAbstractItemModel;
29−class CachedUnityMenuModel;
30
28
31class UNITYINDICATORS_EXPORT Indicator : public QObject
29class UNITYINDICATORS_EXPORT Indicator : public QObject
32{
30{
@@ -42,10 +40,15 @@ public:
42 QString identifier() const;
40 QString identifier() const;
43 int position() const;
41 int position() const;
44 QVariant indicatorProperties() const;
42 QVariant indicatorProperties() const;
43+ bool isVisible() const;
44+
45+ // is set once we know if we're connected.
46+ bool setVisible(bool visible);
45
47
46Q_SIGNALS:
48Q_SIGNALS:
47 void identifierChanged(const QString &identifier);
49 void identifierChanged(const QString &identifier);
48 void positionChanged(int position);
50 void positionChanged(int position);
51+ void visibleChanged(bool visible);
49 void indicatorPropertiesChanged(const QVariant &properties);
52 void indicatorPropertiesChanged(const QVariant &properties);
50
53
51protected:
54protected:
@@ -56,6 +59,7 @@ protected:
56private:
59private:
57 QString m_identifier;
60 QString m_identifier;
58 int m_position;
61 int m_position;
62+ bool m_visible;
59 QVariant m_properties;
63 QVariant m_properties;
60};
64};
61
65
plugins/Unity/Indicators/indicatorsmanager.cpp+7−4
@@ -214,11 +214,14 @@ void IndicatorsManager::unloadFile(const QFileInfo& file)
214 IndicatorData* data = iter.value();
214 IndicatorData* data = iter.value();
215 if (data->m_fileInfo.absoluteFilePath() == file.absoluteFilePath())
215 if (data->m_fileInfo.absoluteFilePath() == file.absoluteFilePath())
216 {
216 {
217+ if (!data->m_verified)
218+ {
217− QString name = data->m_name;
219+ QString name = data->m_name;
218− Q_EMIT indicatorAboutToBeUnloaded(name);
220+ Q_EMIT indicatorAboutToBeUnloaded(name);
219
221
220− delete data;
222+ delete data;
221− iter.remove();
223+ iter.remove();
224+ }
222 }
225 }
223 }
226 }
224
227
plugins/Unity/Indicators/indicatorsmodel.cpp+31−3
@@ -229,9 +229,9 @@ QVariant IndicatorsModel::defaultData(Indicator::Ptr indicator, int role)
229 case IndicatorsModelRole::Description:
229 case IndicatorsModelRole::Description:
230 return "";
230 return "";
231 case IndicatorsModelRole::WidgetSource:
231 case IndicatorsModelRole::WidgetSource:
232− return shellAppDirectory()+"/Panel/Indicators/DefaultIndicatorWidget.qml";
232+ return shellAppDirectory()+"/Panel/Indicators/DefaultIndicatorWidget2.qml";
233 case IndicatorsModelRole::PageSource:
233 case IndicatorsModelRole::PageSource:
234− return shellAppDirectory()+"/Panel/Indicators/DefaultIndicatorPage.qml";
234+ return shellAppDirectory()+"/Panel/Indicators/DefaultIndicatorPage2.qml";
235 }
235 }
236 return QVariant();
236 return QVariant();
237}
237}
@@ -270,7 +270,7 @@ QVariant IndicatorsModel::data(const QModelIndex &index, int role) const
270 }
270 }
271 break;
271 break;
272 case IndicatorsModelRole::IsVisible:
272 case IndicatorsModelRole::IsVisible:
273− return true;
273+ return (indicator ? indicator->isVisible() : false);
274 case IndicatorsModelRole::Title:
274 case IndicatorsModelRole::Title:
275 case IndicatorsModelRole::Description:
275 case IndicatorsModelRole::Description:
276 case IndicatorsModelRole::WidgetSource:
276 case IndicatorsModelRole::WidgetSource:
@@ -282,6 +282,34 @@ QVariant IndicatorsModel::data(const QModelIndex &index, int role) const
282 return QVariant();
282 return QVariant();
283}
283}
284
284
285+void IndicatorsModel::setData(int row, const QVariant& value, int role)
286+{
287+ setData(index(row, 0), value, role);
288+}
289+
290+bool IndicatorsModel::setData(const QModelIndex & index, const QVariant & value, int role)
291+{
292+ if (!index.isValid() || index.row() >= m_indicators.size())
293+ return false;
294+
295+ Indicator::Ptr indicator = m_indicators[index.row()];
296+
297+ switch (role)
298+ {
299+ case IndicatorsModelRole::IsVisible:
300+ if (indicator) {
301+ if (indicator->setVisible(value.toBool())) {
302+ dataChanged(index, index, QVector<int>() << role);
303+ }
304+ return true;
305+ }
306+ break;
307+ default:
308+ break;
309+ }
310+ return false;
311+}
312+
285QVariant IndicatorsModel::indicatorData(const Indicator::Ptr& indicator, int role) const
313QVariant IndicatorsModel::indicatorData(const Indicator::Ptr& indicator, int role) const
286{
314{
287 if (indicator && m_parsed_indicator_data.contains(indicator->identifier()))
315 if (indicator && m_parsed_indicator_data.contains(indicator->identifier()))
plugins/Unity/Indicators/indicatorsmodel.h+4
@@ -37,6 +37,7 @@ class UNITYINDICATORS_EXPORT IndicatorsModel : public QAbstractListModel
37 Q_PROPERTY(QVariant indicatorData READ indicatorData WRITE setIndicatorData NOTIFY indicatorDataChanged)
37 Q_PROPERTY(QVariant indicatorData READ indicatorData WRITE setIndicatorData NOTIFY indicatorDataChanged)
38
38
39public:
39public:
40+
40 IndicatorsModel(QObject *parent=0);
41 IndicatorsModel(QObject *parent=0);
41 ~IndicatorsModel();
42 ~IndicatorsModel();
42
43
@@ -44,17 +45,20 @@ public:
44 Q_INVOKABLE void unload();
45 Q_INVOKABLE void unload();
45
46
46 Q_INVOKABLE QVariant data(int row, int role) const;
47 Q_INVOKABLE QVariant data(int row, int role) const;
48+ Q_INVOKABLE void setData(int row, const QVariant& value, int role);
47
49
48 /* QAbstractItemModel */
50 /* QAbstractItemModel */
49 QHash<int, QByteArray> roleNames() const;
51 QHash<int, QByteArray> roleNames() const;
50 int columnCount(const QModelIndex &parent = QModelIndex()) const;
52 int columnCount(const QModelIndex &parent = QModelIndex()) const;
51 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
53 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
54+ bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);
52 QModelIndex parent (const QModelIndex &index) const;
55 QModelIndex parent (const QModelIndex &index) const;
53 int rowCount(const QModelIndex &parent = QModelIndex()) const;
56 int rowCount(const QModelIndex &parent = QModelIndex()) const;
54
57
55 void setIndicatorData(const QVariant& data);
58 void setIndicatorData(const QVariant& data);
56 QVariant indicatorData() const;
59 QVariant indicatorData() const;
57
60
61+
58Q_SIGNALS:
62Q_SIGNALS:
59 void countChanged();
63 void countChanged();
60 void indicatorDataChanged(const QVariant& data);
64 void indicatorDataChanged(const QVariant& data);
plugins/Unity/Indicators/plugin.cpp+1−5
@@ -32,25 +32,21 @@
32#include "rootactionstate.h"
32#include "rootactionstate.h"
33#include "unitymenumodelcache.h"
33#include "unitymenumodelcache.h"
34#include "unitymenumodelstack.h"
34#include "unitymenumodelstack.h"
35−#include "visibleindicatorsmodel.h"
36−#include "cachedunitymenumodel.h"
37
35
38static QObject* menuModelCacheSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
36static QObject* menuModelCacheSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
39 Q_UNUSED(engine);
37 Q_UNUSED(engine);
40 Q_UNUSED(scriptEngine);
38 Q_UNUSED(scriptEngine);
41− return UnityMenuModelCache::cache();
39+ return new UnityMenuModelCache;
42}
40}
43
41
44void Indicators2Plugin::registerTypes(const char *uri)
42void Indicators2Plugin::registerTypes(const char *uri)
45{
43{
46 qmlRegisterType<IndicatorsManager>(uri, 0, 1, "IndicatorsManager");
44 qmlRegisterType<IndicatorsManager>(uri, 0, 1, "IndicatorsManager");
47 qmlRegisterType<IndicatorsModel>(uri, 0, 1, "IndicatorsModel");
45 qmlRegisterType<IndicatorsModel>(uri, 0, 1, "IndicatorsModel");
48− qmlRegisterType<VisibleIndicatorsModel>(uri, 0, 1, "VisibleIndicatorsModel");
49 qmlRegisterType<MenuContentActivator>(uri, 0, 1, "MenuContentActivator");
46 qmlRegisterType<MenuContentActivator>(uri, 0, 1, "MenuContentActivator");
50 qmlRegisterType<UnityMenuModelStack>(uri, 0, 1, "UnityMenuModelStack");
47 qmlRegisterType<UnityMenuModelStack>(uri, 0, 1, "UnityMenuModelStack");
51 qmlRegisterType<RootActionState>(uri, 0, 1, "RootActionState");
48 qmlRegisterType<RootActionState>(uri, 0, 1, "RootActionState");
52 qmlRegisterType<ModelPrinter>(uri, 0, 1, "ModelPrinter");
49 qmlRegisterType<ModelPrinter>(uri, 0, 1, "ModelPrinter");
53− qmlRegisterType<CachedUnityMenuModel>(uri, 0, 1, "CachedUnityMenuModel");
54
50
55 qmlRegisterSingletonType<UnityMenuModelCache>(uri, 0, 1, "UnityMenuModelCache", menuModelCacheSingleton);
51 qmlRegisterSingletonType<UnityMenuModelCache>(uri, 0, 1, "UnityMenuModelCache", menuModelCacheSingleton);
56
52
plugins/Unity/Indicators/qml/CachedUnityMenuModel.qmlnew file+60
@@ -0,0 +1,60 @@
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+import QMenuModel 0.1 as QMenuModel
22+import Unity.Indicators 0.1 as Indicators
23+
24+// Make sure we don't duplicate models.
25+Item {
26+ id: cachedModel
27+ property string busName: ""
28+ property string actionsObjectPath: ""
29+ property string menuObjectPath: ""
30+
31+ readonly property bool ready: busName!=="" && actionsObjectPath!=="" && menuObjectPath!==""
32+
33+ property QtObject model: {
34+ if (!ready) {
35+ return null;
36+ }
37+
38+ var component = Indicators.UnityMenuModelCache.model(menuObjectPath);
39+ if (!component) {
40+ component = modelComponent.createObject(cachedModel);
41+ return component;
42+ }
43+ return component;
44+ }
45+
46+ Component {
47+ id: modelComponent
48+
49+ QMenuModel.UnityMenuModel {
50+ id: unityModel
51+ busName: cachedModel.busName
52+ actions: { "indicator": cachedModel.actionsObjectPath }
53+ menuObjectPath: cachedModel.menuObjectPath
54+
55+ Component.onCompleted: {
56+ Indicators.UnityMenuModelCache.registerModel(cachedModel.menuObjectPath, unityModel);
57+ }
58+ }
59+ }
60+}
plugins/Unity/Indicators/qml/IndicatorBase.qml+3−3
@@ -39,10 +39,10 @@ Item {
39
39
40 property alias menuModel: cachedModel.model
40 property alias menuModel: cachedModel.model
41
41
42− Indicators.CachedUnityMenuModel {
42+ CachedUnityMenuModel {
43 id: cachedModel
43 id: cachedModel
44− busName: indicatorItem.busName
44+ busName: active ? indicatorItem.busName : ""
45− actions: { "indicator": indicatorItem.actionsObjectPath }
45+ actionsObjectPath: active ? indicatorItem.actionsObjectPath : ""
46 menuObjectPath: active ? indicatorItem.deviceMenuObjectPath : ""
46 menuObjectPath: active ? indicatorItem.deviceMenuObjectPath : ""
47 }
47 }
48}
48}
plugins/Unity/Indicators/qml/qmldir+1
@@ -4,6 +4,7 @@ typeinfo plugin.qmltypes
4
4
5BaseMenuItem 0.1 BaseMenuItem.qml
5BaseMenuItem 0.1 BaseMenuItem.qml
6ButtonMenuItem 0.1 ButtonMenuItem.qml
6ButtonMenuItem 0.1 ButtonMenuItem.qml
7+CachedUnityMenuModel 0.1 CachedUnityMenuModel.qml
7DivMenuItem 0.1 DivMenuItem.qml
8DivMenuItem 0.1 DivMenuItem.qml
8FramedMenuItem 0.1 FramedMenuItem.qml
9FramedMenuItem 0.1 FramedMenuItem.qml
9HLine 0.1 HLine.qml
10HLine 0.1 HLine.qml
plugins/Unity/Indicators/rootactionstate.cpp+11−14
@@ -30,7 +30,8 @@ extern "C" {
30}
30}
31
31
32RootActionState::RootActionState(QObject *parent)
32RootActionState::RootActionState(QObject *parent)
33− : ActionStateParser(parent)
33+ : ActionStateParser(parent),
34+ m_menu(NULL)
34{
35{
35}
36}
36
37
@@ -46,17 +47,18 @@ UnityMenuModel* RootActionState::menu() const
46void RootActionState::setMenu(UnityMenuModel* menu)
47void RootActionState::setMenu(UnityMenuModel* menu)
47{
48{
48 if (m_menu != menu) {
49 if (m_menu != menu) {
49− if (!m_menu.isNull()) {
50+ if (m_menu) {
50 m_menu->disconnect(this);
51 m_menu->disconnect(this);
51 }
52 }
52 m_menu = menu;
53 m_menu = menu;
53
54
54− if (menu) {
55+ if (m_menu) {
55− connect(menu, SIGNAL(rowsInserted(const QModelIndex&, int, int)), SLOT(onModelRowsAdded(const QModelIndex&, int, int)));
56+ connect(m_menu, SIGNAL(rowsInserted(const QModelIndex&, int, int)), SLOT(onModelRowsAdded(const QModelIndex&, int, int)));
56− connect(menu, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), SLOT(onModelRowsRemoved(const QModelIndex&, int, int)));
57+ connect(m_menu, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), SLOT(onModelRowsRemoved(const QModelIndex&, int, int)));
57− connect(menu, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)), SLOT(onModelDataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)));
58+ connect(m_menu, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)), SLOT(onModelDataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)));
58− }
59
59
60+ m_menu->setActionStateParser(this);
61+ }
60 updateActionState();
62 updateActionState();
61 Q_EMIT menuChanged();
63 Q_EMIT menuChanged();
62 }
64 }
@@ -92,13 +94,8 @@ void RootActionState::onModelDataChanged(const QModelIndex& topLeft, const QMode
92
94
93void RootActionState::updateActionState()
95void RootActionState::updateActionState()
94{
96{
95− if (!m_menu.isNull() && m_menu->rowCount() > 0) {
97+ if (m_menu && m_menu->rowCount() > 0) {
96− ActionStateParser* oldParser = m_menu->actionStateParser();
97− m_menu->setActionStateParser(this);
98−
99 m_cachedState = m_menu->get(0, "actionState").toMap();
98 m_cachedState = m_menu->get(0, "actionState").toMap();
100−
101− m_menu->setActionStateParser(oldParser);
102 } else {
99 } else {
103 m_cachedState.clear();
100 m_cachedState.clear();
104 }
101 }
@@ -108,7 +105,7 @@ void RootActionState::updateActionState()
108
105
109bool RootActionState::isValid() const
106bool RootActionState::isValid() const
110{
107{
111− return !m_menu.isNull() && m_menu->rowCount() > 0;
108+ return m_menu && m_menu->rowCount() > 0;
112}
109}
113
110
114QString RootActionState::label() const
111QString RootActionState::label() const
plugins/Unity/Indicators/rootactionstate.h+1−2
@@ -23,7 +23,6 @@
23#include "unityindicatorsglobal.h"
23#include "unityindicatorsglobal.h"
24
24
25#include <actionstateparser.h>
25#include <actionstateparser.h>
26−#include <QPointer>
27
26
28class UnityMenuModel;
27class UnityMenuModel;
29
28
@@ -76,7 +75,7 @@ private Q_SLOTS:
76private:
75private:
77 void updateActionState();
76 void updateActionState();
78
77
79− QPointer<UnityMenuModel> m_menu;
78+ UnityMenuModel* m_menu;
80 QVariantMap m_cachedState;
79 QVariantMap m_cachedState;
81};
80};
82
81
plugins/Unity/Indicators/unitymenumodelcache.cpp+1−29
@@ -39,32 +39,4 @@ void UnityMenuModelCache::registerModel(const QString& path, UnityMenuModel* men
39{
39{
40 menuModel->setParent(this);
40 menuModel->setParent(this);
41 m_menuModels[path] = menuModel;
41 m_menuModels[path] = menuModel;
42−}
42+}
43−
44−UnityMenuModelCache* UnityMenuModelCache::cache()
45−{
46− static UnityMenuModelCache* model = new UnityMenuModelCache;
47− return model;
48−}
49−
50−void UnityMenuModelCache::ref(const QString& path)
51−{
52− if (!m_refs.contains(path)) {
53− m_refs[path] = 1;
54− } else {
55− m_refs[path]++;
56− }
57−}
58−
59−bool UnityMenuModelCache::deref(const QString& path)
60−{
61− if (m_refs.contains(path)) {
62− if (--m_refs[path] <= 0) {
63− delete m_menuModels.value(path, NULL);
64− m_menuModels.remove(path);
65− m_refs.remove(path);
66− return false;
67− }
68− }
69− return true;
70−}
plugins/Unity/Indicators/unitymenumodelcache.h−6
@@ -37,14 +37,8 @@ public:
37 Q_INVOKABLE UnityMenuModel* model(const QString& path) const;
37 Q_INVOKABLE UnityMenuModel* model(const QString& path) const;
38 Q_INVOKABLE void registerModel(const QString& path, UnityMenuModel* menuModel);
38 Q_INVOKABLE void registerModel(const QString& path, UnityMenuModel* menuModel);
39
39
40− void ref(const QString& path);
41− bool deref(const QString& path);
42−
43− static UnityMenuModelCache* cache();
44−
45private:
40private:
46 QHash<QString, UnityMenuModel*> m_menuModels;
41 QHash<QString, UnityMenuModel*> m_menuModels;
47− QHash<QString, int> m_refs;
48};
42};
49
43
50#endif // UNITYMENUMODELCACHE_H
44#endif // UNITYMENUMODELCACHE_H
plugins/Unity/Indicators/visibleindicatorsmodel.cppdeleted−191
@@ -1,191 +0,0 @@
1−/*
2− * Copyright (C) 2012, 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 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−// self
18−#include "visibleindicatorsmodel.h"
19−#include "rootactionstate.h"
20−#include "indicators.h"
21−#include "cachedunitymenumodel.h"
22−
23−#include <unitymenumodel.h>
24−
25−// Qt
26−#include <QDebug>
27−
28−VisibleIndicatorsModel::VisibleIndicatorsModel(QObject *parent)
29− : QIdentityProxyModel(parent)
30−{
31− connect(this, SIGNAL(modelReset()), SIGNAL(countChanged()));
32− connect(this, SIGNAL(rowsInserted(QModelIndex,int,int)), SIGNAL(countChanged()));
33− connect(this, SIGNAL(rowsRemoved(QModelIndex,int,int)), SIGNAL(countChanged()));
34−}
35−
36−VisibleIndicatorsModel::~VisibleIndicatorsModel()
37−{
38− qDeleteAll(m_rootActions);
39− m_rootActions.clear();
40−
41− qDeleteAll(m_cachedModels);
42− m_cachedModels.clear();
43−
44− m_visible.clear();
45−}
46−
47−QHash<int, QByteArray> VisibleIndicatorsModel::roleNames() const
48−{
49− return sourceModel() ? sourceModel()->roleNames() : QHash<int, QByteArray>();
50−}
51−
52−QString VisibleIndicatorsModel::profile() const
53−{
54− return m_profile;
55−}
56−
57−void VisibleIndicatorsModel::setProfile(const QString& profile)
58−{
59− if (m_profile != profile) {
60− m_profile = profile;
61− Q_EMIT profileChanged();
62− }
63−}
64−
65−void VisibleIndicatorsModel::setModel(QAbstractItemModel *itemModel)
66−{
67− if (itemModel != sourceModel()) {
68− if (sourceModel() != NULL) {
69− sourceModel()->disconnect(this);
70− }
71−
72− setSourceModel(itemModel);
73−
74− if (sourceModel() != NULL) {
75− // ... and use our own
76− connect(sourceModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
77− SLOT(sourceRowsInserted(QModelIndex,int,int)));
78− connect(sourceModel(), SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
79− SLOT(sourceRowsAboutToBeRemoved(QModelIndex,int,int)));
80− connect(sourceModel(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
81− SLOT(sourceDataChanged(QModelIndex,QModelIndex)));
82− }
83− Q_EMIT modelChanged();
84− }
85−}
86−
87−void VisibleIndicatorsModel::sourceRowsInserted(const QModelIndex&, int start, int end)
88−{
89− for (int row = start; row <= end; row++) {
90− RootActionState* actionState = new RootActionState();
91− connect(actionState, SIGNAL(updated()), SLOT(onActionStateUpdated()));
92− m_rootActions.insert(row, actionState);
93− m_visible.insert(row, false);
94−
95− m_cachedModels.insert(row, new CachedUnityMenuModel);
96− updateCachedModel(sourceModel()->index(row, 0));
97− }
98−}
99−
100−void VisibleIndicatorsModel::sourceRowsAboutToBeRemoved(const QModelIndex&, int start, int end)
101−{
102− for (int row = start; row <= end; row++) {
103− if (m_rootActions.count() > start) {
104− delete m_rootActions[start];
105− m_rootActions.removeAt(start);
106− }
107− if (m_visible.count() > start) {
108− m_visible.removeAt(start);
109− }
110− if (m_cachedModels.count() > start) {
111− delete m_cachedModels[start];
112− m_cachedModels.removeAt(start);
113− }
114− }
115−}
116−
117−void VisibleIndicatorsModel::sourceDataChanged(const QModelIndex& topRight, const QModelIndex& bottomRight)
118−{
119− for (int row = topRight.row(); row <= bottomRight.row(); row++) {
120− updateCachedModel(sourceModel()->index(row, 0));
121− }
122−}
123−
124−void VisibleIndicatorsModel::onActionStateUpdated()
125−{
126− RootActionState* actionState = qobject_cast<RootActionState*>(sender());
127− int changedRow = m_rootActions.indexOf(actionState);
128−
129− QModelIndex modelIndex = this->index(changedRow, 0);
130− if (!modelIndex.isValid()) {
131− return;
132− }
133−
134− while (m_visible.count() <= changedRow) {
135− m_visible.append(false);
136− }
137−
138− if (actionState->isVisible() != m_visible[changedRow]) {
139− m_visible[changedRow] = actionState->isVisible();
140−
141− Q_EMIT dataChanged(modelIndex, modelIndex, QVector<int>() << IndicatorsModelRole::IsVisible);
142− }
143−}
144−
145−QVariant VisibleIndicatorsModel::data(const QModelIndex &index, int role) const
146−{
147− if (role != IndicatorsModelRole::IsVisible)
148− return QIdentityProxyModel::data(index, role);
149−
150− if (!index.isValid() || m_visible.count() <= index.row())
151− return false;
152−
153− return m_visible[index.row()];
154−}
155−
156−void VisibleIndicatorsModel::updateCachedModel(const QModelIndex& index)
157−{
158− if (!index.isValid()) {
159− return;
160− }
161− QVariant data = sourceModel()->data(index, IndicatorsModelRole::IndicatorProperties);
162− if (!data.isValid()) {
163− return;
164− }
165− int row = index.row();
166−
167− if (m_cachedModels.count() <= row) {
168− return;
169− }
170− CachedUnityMenuModel* cachedModel = m_cachedModels[row];
171−
172− QVariantMap properties = data.toMap();
173−
174− QVariantMap menuObjectPaths = properties["menuObjectPaths"].toMap();
175− if (!menuObjectPaths.contains(m_profile)) {
176− return;
177− }
178−
179− QString menuObjectPath = menuObjectPaths[m_profile].toString();
180− QString busName = properties["busName"].toString();
181− QString actionsObjectPath = properties["actionsObjectPath"].toString();
182−
183− cachedModel->setBusName(busName);
184− cachedModel->setMenuObjectPath(menuObjectPath);
185− QVariantMap actions; actions["indicator"] = actionsObjectPath;
186− cachedModel->setActions(actions);
187−
188− if (m_rootActions.count() > row) {
189− m_rootActions[row]->setMenu(cachedModel->model());
190− }
191−}
plugins/Unity/Indicators/visibleindicatorsmodel.hdeleted−73
@@ -1,73 +0,0 @@
1−/*
2− * Copyright (C) 2012, 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 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− * Authors:
17− * Nick Dedekind <nick.dedekind@canonical.com>
18− */
19−
20−#ifndef VISIBLEINDICATORSMODEL_H
21−#define VISIBLEINDICATORSMODEL_H
22−
23−#include <QIdentityProxyModel>
24−#include <QPersistentModelIndex>
25−
26−class RootActionState;
27−class CachedUnityMenuModel;
28−
29−class VisibleIndicatorsModel : public QIdentityProxyModel
30−{
31− Q_OBJECT
32−
33− Q_PROPERTY(QAbstractItemModel* model READ sourceModel WRITE setModel NOTIFY modelChanged)
34− Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
35− Q_PROPERTY(QString profile READ profile WRITE setProfile NOTIFY profileChanged)
36−
37−public:
38− explicit VisibleIndicatorsModel(QObject *parent = 0);
39− ~VisibleIndicatorsModel();
40−
41− /* getters */
42− QHash<int, QByteArray> roleNames() const;
43− QString profile() const;
44−
45− /* setters */
46− void setModel(QAbstractItemModel *model);
47− void setProfile(const QString& profile);
48−
49− virtual QVariant data(const QModelIndex &index, int role) const;
50−
51−Q_SIGNALS:
52− void totalCountChanged();
53− void countChanged();
54− void modelChanged();
55− void profileChanged();
56−
57−private Q_SLOTS:
58− void sourceRowsInserted(const QModelIndex &parent, int start, int end);
59− void sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
60− void sourceDataChanged(const QModelIndex& topRight, const QModelIndex& bottomRight);
61−
62− void onActionStateUpdated();
63−
64−private:
65− void updateCachedModel(const QModelIndex& index);
66−
67− QList<RootActionState*> m_rootActions;
68− QList<CachedUnityMenuModel*> m_cachedModels;
69− QList<bool> m_visible;
70− QString m_profile;
71−};
72−
73−#endif // VISIBLEINDICATORSMODEL_H