on xenial help sign in
reverted unitymenumodel aware VisibleModel
commit1832ace0a6e328b29c2a7f359deb7850e09b7eb2 authorNick Dedekind <nicholas.dedekind@gmail.com> dateFri 30 Aug 2013, 09:17 (13 years ago) parent1aca428
22 files changed+172−544
Panel/IndicatorItem.qml+1 Panel/IndicatorRow.qml+8−6 Panel/Indicators.qml+2−16 Panel/MenuContent.qml+18−6 plugins/Unity/Indicators/CMakeLists.txt−2 plugins/Unity/Indicators/cachedunitymenumodel.cpp−113 plugins/Unity/Indicators/cachedunitymenumodel.h−66 plugins/Unity/Indicators/indicator.cpp+17−3 plugins/Unity/Indicators/indicator.h+6−2 plugins/Unity/Indicators/indicatorsmanager.cpp+7−4 plugins/Unity/Indicators/indicatorsmodel.cpp+31−3 plugins/Unity/Indicators/indicatorsmodel.h+4 plugins/Unity/Indicators/plugin.cpp+1−5 plugins/Unity/Indicators/qml/CachedUnityMenuModel.qml+60 plugins/Unity/Indicators/qml/IndicatorBase.qml+3−3 plugins/Unity/Indicators/qml/qmldir+1 plugins/Unity/Indicators/rootactionstate.cpp+11−14 plugins/Unity/Indicators/rootactionstate.h+1−2 plugins/Unity/Indicators/unitymenumodelcache.cpp+1−29 plugins/Unity/Indicators/unitymenumodelcache.h−6 plugins/Unity/Indicators/visibleindicatorsmodel.cpp−191 plugins/Unity/Indicators/visibleindicatorsmodel.h−73
Panel/IndicatorItem.qml+1
@@ -26,6 +26,7 @@ Item {
2626 property bool highlighted: false
2727 property bool dimmed: false
2828 property var indicatorProperties: undefined
29+ property bool indicatorVisible: loader.item != undefined && loader.status == Loader.Ready ? loader.item.enabled : false
2930
3031 opacity: dimmed ? 0.4 : 1
3132 Behavior on opacity { StandardAnimation {} }
Panel/IndicatorRow.qml+8−6
@@ -53,16 +53,11 @@ Item {
5353 objectName: "rowRepeater"
5454 model: indicatorsModel ? indicatorsModel : undefined
5555
56− onItemRemoved: {
57− if (currentItemIndex == -1) {
58− setDefaultItem(0);
59− }
60− }
61−
6256 Item {
6357 id: itemWrapper
6458 height: indicatorRow.height
6559 width: indicatorItem.width
60+ visible: indicatorItem.indicatorVisible
6661
6762 property int ownIndex: index
6863 property alias highlighted: indicatorItem.highlighted
@@ -77,6 +72,13 @@ Item {
7772
7873 widgetSource: model.widgetSource
7974 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+ }
8082 }
8183
8284 opacity: {
Panel/Indicators.qml+2−16
@@ -17,8 +17,6 @@
1717import QtQuick 2.0
1818import Ubuntu.Components 0.1
1919import Ubuntu.Gestures 0.1
20−import Unity.Indicators 0.1 as Indicators
21−import Utils 0.1
2220
2321import "../Components"
2422import "../Components/ListItems"
@@ -177,7 +175,7 @@ Showable {
177175 top: indicatorRow.bottom
178176 bottom: handle.top
179177 }
180− indicatorsModel: filteredIndicators
178+ indicatorsModel: indicatorsModel
181179 clip: !indicators.fullyOpened
182180 activeHeader: indicators.state == "hint" || indicators.state == "reveal"
183181
@@ -251,18 +249,6 @@ Showable {
251249 id: indicatorsModel
252250 }
253251
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−
266252 IndicatorRow {
267253 id: indicatorRow
268254 objectName: "indicatorRow"
@@ -271,7 +257,7 @@ Showable {
271257 right: parent.right
272258 }
273259 height: indicators.panelHeight
274− indicatorsModel: filteredIndicators
260+ indicatorsModel: indicatorsModel
275261 state: indicators.state
276262
277263 Connections {
Panel/MenuContent.qml+18−6
@@ -17,6 +17,7 @@
1717import QtQuick 2.0
1818import Ubuntu.Components 0.1
1919import Unity.Indicators 0.1 as Indicators
20+import Utils 0.1
2021import "../Components"
2122
2223// FIXME : We dont want to use MainView.
@@ -27,7 +28,7 @@ MainView {
2728
2829 property QtObject indicatorsModel: null
2930 property bool __contentActive: false
30− readonly property int currentMenuIndex : tabs.selectedTabIndex
31+ readonly property int currentMenuIndex : filteredIndicators.mapToSource(tabs.selectedTabIndex)
3132 backgroundColor: "#221e1c" // FIXME not in palette yet
3233 property int contentReleaseInterval: 20000
3334 property bool activeHeader: false
@@ -36,11 +37,13 @@ MainView {
3637 height: units.gu(42)
3738
3839 function setCurrentMenuIndex(index) {
39− if (tabs.selectedTabIndex !== index) {
40+ var filteredIndex = filteredIndicators.mapFromSource(index)
41+
42+ if (tabs.selectedTabIndex !== filteredIndex) {
4043 if (tabs.selectedTabIndex == -1) {
4144 tabs.tabBar.animate = false;
4245 }
43− tabs.selectedTabIndex = index;
46+ tabs.selectedTabIndex = filteredIndex;
4447 tabs.tabBar.animate = true;
4548 }
4649 }
@@ -61,6 +64,15 @@ MainView {
6164 tabs.tabBar.alwaysSelectionMode = activeHeader;
6265 }
6366
67+ SortFilterProxyModel {
68+ id: filteredIndicators
69+ model: indicatorsModel
70+ dynamicSortFilter: true
71+
72+ filterRole: Indicators.IndicatorsModelRole.IsVisible
73+ filterRegExp: RegExp("^true$")
74+ }
75+
6476 Tabs {
6577 id: tabs
6678 objectName: "tabs"
@@ -69,8 +81,8 @@ MainView {
6981
7082 Repeater {
7183 id: repeater
72− model: indicatorsModel
73− objectName: "tabsRepeater"
84+ model: filteredIndicators
85+ objectName: "menus"
7486
7587 // FIXME: This is needed because tabs dont handle repeaters well.
7688 // Due to the child ordering happening after child insertion.
@@ -114,7 +126,7 @@ MainView {
114126 item[pName] = indicatorProperties[pName]
115127 }
116128 }
117− if (contentActive && tabs.visible) {
129+ if (contentActive && menus.visible) {
118130 item.start()
119131 }
120132 }
plugins/Unity/Indicators/CMakeLists.txt−2
@@ -24,7 +24,6 @@ include_directories(
2424)
2525
2626set(IndicatorsQML_SOURCES
27− cachedunitymenumodel.cpp
2827 indicator.cpp
2928 indicators.h
3029 indicatorsmanager.cpp
@@ -35,7 +34,6 @@ set(IndicatorsQML_SOURCES
3534 rootactionstate.cpp
3635 unitymenumodelcache.cpp
3736 unitymenumodelstack.cpp
38− visibleindicatorsmodel.cpp
3937)
4038add_definitions(-DUNITYINDICATORS_LIBRARY)
4139
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 @@
1818 */
1919
2020#include "indicator.h"
21−#include "cachedunitymenumodel.h"
2221
2322#include <QStringList>
24−#include <unitymenumodel.h>
2523
2624Indicator::Indicator(QObject *parent)
2725 : QObject(parent),
28− m_position(0)
26+ m_position(0),
27+ m_visible(false)
2928{
3029}
3130
@@ -88,6 +87,21 @@ void Indicator::setPosition(int position)
8887 }
8988}
9089
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+
91105QVariant Indicator::indicatorProperties() const
92106{
93107 return m_properties;
plugins/Unity/Indicators/indicator.h+6−2
@@ -25,8 +25,6 @@
2525
2626#include <QObject>
2727#include <QSettings>
28−class QAbstractItemModel;
29−class CachedUnityMenuModel;
3028
3129class UNITYINDICATORS_EXPORT Indicator : public QObject
3230{
@@ -42,10 +40,15 @@ public:
4240 QString identifier() const;
4341 int position() const;
4442 QVariant indicatorProperties() const;
43+ bool isVisible() const;
44+
45+ // is set once we know if we're connected.
46+ bool setVisible(bool visible);
4547
4648Q_SIGNALS:
4749 void identifierChanged(const QString &identifier);
4850 void positionChanged(int position);
51+ void visibleChanged(bool visible);
4952 void indicatorPropertiesChanged(const QVariant &properties);
5053
5154protected:
@@ -56,6 +59,7 @@ protected:
5659private:
5760 QString m_identifier;
5861 int m_position;
62+ bool m_visible;
5963 QVariant m_properties;
6064};
6165
plugins/Unity/Indicators/indicatorsmanager.cpp+7−4
@@ -214,11 +214,14 @@ void IndicatorsManager::unloadFile(const QFileInfo& file)
214214 IndicatorData* data = iter.value();
215215 if (data->m_fileInfo.absoluteFilePath() == file.absoluteFilePath())
216216 {
217− QString name = data->m_name;
218− Q_EMIT indicatorAboutToBeUnloaded(name);
217+ if (!data->m_verified)
218+ {
219+ QString name = data->m_name;
220+ Q_EMIT indicatorAboutToBeUnloaded(name);
219221
220− delete data;
221− iter.remove();
222+ delete data;
223+ iter.remove();
224+ }
222225 }
223226 }
224227
plugins/Unity/Indicators/indicatorsmodel.cpp+31−3
@@ -229,9 +229,9 @@ QVariant IndicatorsModel::defaultData(Indicator::Ptr indicator, int role)
229229 case IndicatorsModelRole::Description:
230230 return "";
231231 case IndicatorsModelRole::WidgetSource:
232− return shellAppDirectory()+"/Panel/Indicators/DefaultIndicatorWidget.qml";
232+ return shellAppDirectory()+"/Panel/Indicators/DefaultIndicatorWidget2.qml";
233233 case IndicatorsModelRole::PageSource:
234− return shellAppDirectory()+"/Panel/Indicators/DefaultIndicatorPage.qml";
234+ return shellAppDirectory()+"/Panel/Indicators/DefaultIndicatorPage2.qml";
235235 }
236236 return QVariant();
237237}
@@ -270,7 +270,7 @@ QVariant IndicatorsModel::data(const QModelIndex &index, int role) const
270270 }
271271 break;
272272 case IndicatorsModelRole::IsVisible:
273− return true;
273+ return (indicator ? indicator->isVisible() : false);
274274 case IndicatorsModelRole::Title:
275275 case IndicatorsModelRole::Description:
276276 case IndicatorsModelRole::WidgetSource:
@@ -282,6 +282,34 @@ QVariant IndicatorsModel::data(const QModelIndex &index, int role) const
282282 return QVariant();
283283}
284284
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+
285313QVariant IndicatorsModel::indicatorData(const Indicator::Ptr& indicator, int role) const
286314{
287315 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
3737 Q_PROPERTY(QVariant indicatorData READ indicatorData WRITE setIndicatorData NOTIFY indicatorDataChanged)
3838
3939public:
40+
4041 IndicatorsModel(QObject *parent=0);
4142 ~IndicatorsModel();
4243
@@ -44,17 +45,20 @@ public:
4445 Q_INVOKABLE void unload();
4546
4647 Q_INVOKABLE QVariant data(int row, int role) const;
48+ Q_INVOKABLE void setData(int row, const QVariant& value, int role);
4749
4850 /* QAbstractItemModel */
4951 QHash<int, QByteArray> roleNames() const;
5052 int columnCount(const QModelIndex &parent = QModelIndex()) const;
5153 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
54+ bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);
5255 QModelIndex parent (const QModelIndex &index) const;
5356 int rowCount(const QModelIndex &parent = QModelIndex()) const;
5457
5558 void setIndicatorData(const QVariant& data);
5659 QVariant indicatorData() const;
5760
61+
5862Q_SIGNALS:
5963 void countChanged();
6064 void indicatorDataChanged(const QVariant& data);
plugins/Unity/Indicators/plugin.cpp+1−5
@@ -32,25 +32,21 @@
3232#include "rootactionstate.h"
3333#include "unitymenumodelcache.h"
3434#include "unitymenumodelstack.h"
35−#include "visibleindicatorsmodel.h"
36−#include "cachedunitymenumodel.h"
3735
3836static QObject* menuModelCacheSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
3937 Q_UNUSED(engine);
4038 Q_UNUSED(scriptEngine);
41− return UnityMenuModelCache::cache();
39+ return new UnityMenuModelCache;
4240}
4341
4442void Indicators2Plugin::registerTypes(const char *uri)
4543{
4644 qmlRegisterType<IndicatorsManager>(uri, 0, 1, "IndicatorsManager");
4745 qmlRegisterType<IndicatorsModel>(uri, 0, 1, "IndicatorsModel");
48− qmlRegisterType<VisibleIndicatorsModel>(uri, 0, 1, "VisibleIndicatorsModel");
4946 qmlRegisterType<MenuContentActivator>(uri, 0, 1, "MenuContentActivator");
5047 qmlRegisterType<UnityMenuModelStack>(uri, 0, 1, "UnityMenuModelStack");
5148 qmlRegisterType<RootActionState>(uri, 0, 1, "RootActionState");
5249 qmlRegisterType<ModelPrinter>(uri, 0, 1, "ModelPrinter");
53− qmlRegisterType<CachedUnityMenuModel>(uri, 0, 1, "CachedUnityMenuModel");
5450
5551 qmlRegisterSingletonType<UnityMenuModelCache>(uri, 0, 1, "UnityMenuModelCache", menuModelCacheSingleton);
5652
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 {
3939
4040 property alias menuModel: cachedModel.model
4141
42− Indicators.CachedUnityMenuModel {
42+ CachedUnityMenuModel {
4343 id: cachedModel
44− busName: indicatorItem.busName
45− actions: { "indicator": indicatorItem.actionsObjectPath }
44+ busName: active ? indicatorItem.busName : ""
45+ actionsObjectPath: active ? indicatorItem.actionsObjectPath : ""
4646 menuObjectPath: active ? indicatorItem.deviceMenuObjectPath : ""
4747 }
4848}
plugins/Unity/Indicators/qml/qmldir+1
@@ -4,6 +4,7 @@ typeinfo plugin.qmltypes
44
55BaseMenuItem 0.1 BaseMenuItem.qml
66ButtonMenuItem 0.1 ButtonMenuItem.qml
7+CachedUnityMenuModel 0.1 CachedUnityMenuModel.qml
78DivMenuItem 0.1 DivMenuItem.qml
89FramedMenuItem 0.1 FramedMenuItem.qml
910HLine 0.1 HLine.qml
plugins/Unity/Indicators/rootactionstate.cpp+11−14
@@ -30,7 +30,8 @@ extern "C" {
3030}
3131
3232RootActionState::RootActionState(QObject *parent)
33− : ActionStateParser(parent)
33+ : ActionStateParser(parent),
34+ m_menu(NULL)
3435{
3536}
3637
@@ -46,17 +47,18 @@ UnityMenuModel* RootActionState::menu() const
4647void RootActionState::setMenu(UnityMenuModel* menu)
4748{
4849 if (m_menu != menu) {
49− if (!m_menu.isNull()) {
50+ if (m_menu) {
5051 m_menu->disconnect(this);
5152 }
5253 m_menu = menu;
5354
54− if (menu) {
55− connect(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(menu, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)), SLOT(onModelDataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)));
58− }
55+ if (m_menu) {
56+ connect(m_menu, SIGNAL(rowsInserted(const QModelIndex&, int, int)), SLOT(onModelRowsAdded(const QModelIndex&, int, int)));
57+ connect(m_menu, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), SLOT(onModelRowsRemoved(const QModelIndex&, int, int)));
58+ connect(m_menu, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)), SLOT(onModelDataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)));
5959
60+ m_menu->setActionStateParser(this);
61+ }
6062 updateActionState();
6163 Q_EMIT menuChanged();
6264 }
@@ -92,13 +94,8 @@ void RootActionState::onModelDataChanged(const QModelIndex& topLeft, const QMode
9294
9395void RootActionState::updateActionState()
9496{
95− if (!m_menu.isNull() && m_menu->rowCount() > 0) {
96− ActionStateParser* oldParser = m_menu->actionStateParser();
97− m_menu->setActionStateParser(this);
98−
97+ if (m_menu && m_menu->rowCount() > 0) {
9998 m_cachedState = m_menu->get(0, "actionState").toMap();
100−
101− m_menu->setActionStateParser(oldParser);
10299 } else {
103100 m_cachedState.clear();
104101 }
@@ -108,7 +105,7 @@ void RootActionState::updateActionState()
108105
109106bool RootActionState::isValid() const
110107{
111− return !m_menu.isNull() && m_menu->rowCount() > 0;
108+ return m_menu && m_menu->rowCount() > 0;
112109}
113110
114111QString RootActionState::label() const
plugins/Unity/Indicators/rootactionstate.h+1−2
@@ -23,7 +23,6 @@
2323#include "unityindicatorsglobal.h"
2424
2525#include <actionstateparser.h>
26−#include <QPointer>
2726
2827class UnityMenuModel;
2928
@@ -76,7 +75,7 @@ private Q_SLOTS:
7675private:
7776 void updateActionState();
7877
79− QPointer<UnityMenuModel> m_menu;
78+ UnityMenuModel* m_menu;
8079 QVariantMap m_cachedState;
8180};
8281
plugins/Unity/Indicators/unitymenumodelcache.cpp+1−29
@@ -39,32 +39,4 @@ void UnityMenuModelCache::registerModel(const QString& path, UnityMenuModel* men
3939{
4040 menuModel->setParent(this);
4141 m_menuModels[path] = menuModel;
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−}
42+}
plugins/Unity/Indicators/unitymenumodelcache.h−6
@@ -37,14 +37,8 @@ public:
3737 Q_INVOKABLE UnityMenuModel* model(const QString& path) const;
3838 Q_INVOKABLE void registerModel(const QString& path, UnityMenuModel* menuModel);
3939
40− void ref(const QString& path);
41− bool deref(const QString& path);
42−
43− static UnityMenuModelCache* cache();
44−
4540private:
4641 QHash<QString, UnityMenuModel*> m_menuModels;
47− QHash<QString, int> m_refs;
4842};
4943
5044#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