on xenial help sign in
review comments
commit2e1beb4f3556cd1b470b7c134ee61e491feedcb2 authorNick Dedekind <nicholas.dedekind@gmail.com> dateWed 26 Jun 2013, 16:38 (13 years ago) parent384164e
15 files changed+81−152
Panel/Indicators/NetworkIndicatorWidget.qml+1−1 Panel/Menus/Overview/OverviewGrid.qml−1 debian/control+2−3 modules/Unity/Indicators/Network/plugin.cpp+1−1 modules/Unity/Indicators/flatmenuproxymodel.cpp+3−67 modules/Unity/Indicators/flatmenuproxymodel.h+13−9 modules/Unity/Indicators/indicator.h−1 modules/Unity/Indicators/indicatorsmanager.cpp+28−19 modules/Unity/Indicators/indicatorsmanager.h+6−8 modules/Unity/Indicators/indicatorsmodel.cpp+5−21 modules/Unity/Indicators/indicatorsmodel.h+1−1 modules/Unity/Indicators/plugin.cpp+1−1 modules/Unity/Indicators/qml/IndicatorWidget.qml+6−6 paths.h.in+2−1 tests/modules/Unity/Indicators/indicatorsmodeltest.cpp+12−12
Panel/Indicators/NetworkIndicatorWidget.qml+1−1
@@ -40,7 +40,7 @@ Indicators.IndicatorWidget {
4040 anchors.centerIn: parent
4141 }
4242
43− function parseRootElement(type, data) {
43+ function parseRootElement(type) {
4444 if (type == "com.canonical.indicator.root.network") {
4545 return true;
4646 }
Panel/Menus/Overview/OverviewGrid.qml−1
@@ -56,7 +56,6 @@ Item {
5656 interactive: false
5757 delegate:
5858 AbstractButton {
59− id: indicatorButton
6059 objectName: "overviewGridButton" + index
6160 width: grid.cellWidth
6261 height: grid.cellHeight
debian/control+2−3
@@ -67,9 +67,8 @@ Depends: qmenumodel-qml,
6767 unity8 (= ${source:Version}),
6868 ${misc:Depends},
6969 ${shlibs:Depends},
70−Description: Indicators and system settings client application
71− This package contains the client application for indicators and system
72− settings.
70+Description: Indicators client test application
71+ This package contains the client application for indicators used by autopilot
7372
7473Package: unity8-fake-env
7574Replaces: qml-phone-shell-fake-env (<< 7.80~)
modules/Unity/Indicators/Network/plugin.cpp+1−1
@@ -13,7 +13,7 @@
1313 * You should have received a copy of the GNU General Public License
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 *
16− * Author: Michał Sawicz <michal.sawicz@canonical.com>
16+ * Author: Nick Dedekind <nick.dedekind@canonical.com>
1717 */
1818
1919// Qt
modules/Unity/Indicators/flatmenuproxymodel.cpp+3−67
@@ -220,60 +220,6 @@ void FlatMenuProxyModel::onModelReset()
220220 Q_EMIT countChanged();
221221}
222222
223−// void FlatMenuProxyModel::onRowsAboutToBeInserted(const QModelIndex &index, int first, int last)
224−// {
225−// if (index.isValid()) {
226−// int firstIndex = rowOffsetOf(index, first);
227−// int lastIndex = rowOffsetOf(index, last, true);
228−
229−// beginInsertRows(QModelIndex(), firstIndex, lastIndex);
230−// m_rowCount += (lastIndex - firstIndex + 1);
231−// }
232−// }
233−
234−// void FlatMenuProxyModel::onRowsAboutToBeRemoved(const QModelIndex &index, int first, int last)
235−// {
236−// if (index.isValid()) {
237−// int firstIndex = rowOffsetOf(index, first);
238−// int lastIndex = rowOffsetOf(index, last, true);
239−
240−// m_indexCache.clear();
241−// beginRemoveRows(QModelIndex(), firstIndex, lastIndex);
242−// m_rowCount -= (lastIndex - firstIndex + 1);
243−// }
244−// }
245−
246−// void FlatMenuProxyModel::onRowsInserted(const QModelIndex &index, int first, int last)
247−// {
248−// if (index.isValid()) {
249−// m_indexCache.clear();
250−// endInsertRows();
251−// for (int i=first; i <= last; i++) {
252−// QModelIndex subIndex = sourceModel()->index(i, 0, index.parent());
253−// if (subIndex.isValid()) {
254−// int subSectionSize = recursiveRowCount(subIndex);
255−// if (subSectionSize > 0) {
256−// int firstIndex = rowOffsetOf(index, i) + 1;
257−// int lastIndex = rowOffsetOf(index, i, true);
258−
259−// beginInsertRows(QModelIndex(), firstIndex, lastIndex);
260−// m_rowCount += lastIndex - firstIndex + 1;
261−// endInsertRows();
262−// }
263−// }
264−// }
265−// }
266−// Q_EMIT countChanged();
267−// }
268−
269−// void FlatMenuProxyModel::onRowsRemoved(const QModelIndex &index, int, int)
270−// {
271−// if (index.isValid()) {
272−// endRemoveRows();
273−// Q_EMIT countChanged();
274−// }
275−// }
276−
277223int FlatMenuProxyModel::recursiveRowCount(const QModelIndex &index) const
278224{
279225 int size = sourceModel()->rowCount(index);
@@ -316,17 +262,7 @@ int FlatMenuProxyModel::rowOffsetOf(const QModelIndex &index, int row, bool incl
316262 return offset;
317263}
318264
319−/*! \for use in qml */
320−QVariantMap FlatMenuProxyModel::get(int row) const
265+QVariant FlatMenuProxyModel::data(int row, int role) const
321266{
322− QVariantMap result;
323−
324− QModelIndex index = this->index(row);
325− if (index.isValid()) {
326− const QHash<int, QByteArray> roleNames = this->roleNames();
327− Q_FOREACH(int i, roleNames.keys()) {
328− result.insert(roleNames[i], data(index, i));
329− }
330− }
331− return result;
332−}
267+ return QAbstractProxyModel::data(index(row, 0), role);
268+}
modules/Unity/Indicators/flatmenuproxymodel.h+13−9
@@ -34,12 +34,25 @@ class FlatMenuProxyModel : public QAbstractProxyModel
3434 Q_PROPERTY(QString objectPath READ objectPath WRITE setObjectPath NOTIFY objectPathChanged)
3535 Q_PROPERTY(int status READ status NOTIFY statusChanged)
3636
37+ Q_ENUMS(Roles)
3738public:
39+ // Because this is a proxy to qmenumodel, it may change.
40+ enum Roles {
41+ Action = Qt::DisplayRole + 1,
42+ Label,
43+ Extra,
44+ Depth,
45+ hasSection,
46+ hasSubMenu
47+ };
48+
3849 FlatMenuProxyModel(QAbstractItemModel *source=0);
3950 ~FlatMenuProxyModel();
4051
4152 void setSourceModel(QAbstractItemModel * sourceModel);
4253
54+ Q_INVOKABLE QVariant data(int row, int role = Qt::DisplayRole) const;
55+
4356 QModelIndex mapFromSource(const QModelIndex &index) const;
4457 QModelIndex mapToSource(const QModelIndex &index) const;
4558
@@ -60,16 +73,7 @@ public:
6073
6174 int status() const;
6275
63− /* QML */
64− Q_INVOKABLE QVariantMap get(int row) const;
65−
6676public Q_SLOTS:
67− // void onRowsInserted(const QModelIndex &parent, int start, int end);
68− // void onRowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
69−
70− // void onRowsRemoved(const QModelIndex &parent, int start, int end);
71− // void onRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
72−
7377 void onModelAboutToBeReset();
7478 void onModelReset();
7579
modules/Unity/Indicators/indicator.h−1
@@ -23,7 +23,6 @@
2323
2424#include <QObject>
2525#include <QSettings>
26−#include <memory>
2726
2827class Indicator : public QObject
2928{
modules/Unity/Indicators/indicatorsmanager.cpp+28−19
@@ -1,9 +1,6 @@
11/*
22 * Copyright (C) 2013 Canonical, Ltd.
33 *
4− * Authors:
5− * Michał Sawicz <michal.sawicz@canonical.com>
6− *
74 * This program is free software; you can redistribute it and/or modify
85 * it under the terms of the GNU General Public License as published by
96 * the Free Software Foundation; version 3.
@@ -15,6 +12,8 @@
1512 *
1613 * You should have received a copy of the GNU General Public License
1714 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Author: Nick Dedekind <nick.dedekind@canonical.com>
1817 */
1918
2019#include "indicatorsmanager.h"
@@ -29,9 +28,9 @@ class IndicatorsManager::IndicatorData
2928{
3029public:
3130 IndicatorData(const QString& name, const QFileInfo& fileInfo)
32− : m_name(name)
33− , m_fileInfo(fileInfo)
34− , m_verified (true)
31+ : m_name(name)
32+ , m_fileInfo(fileInfo)
33+ , m_verified (true)
3534 {}
3635
3736 QString m_name;
@@ -42,8 +41,8 @@ public:
4241};
4342
4443IndicatorsManager::IndicatorsManager(QObject* parent)
45−: QObject(parent)
46−, m_loaded(false)
44+ : QObject(parent)
45+ , m_loaded(false)
4746{
4847}
4948
@@ -68,7 +67,7 @@ void IndicatorsManager::load()
6867 // watch folder for changes.
6968 m_fsWatcher->addPath(indicator_path);
7069
71− load(indicator_dir);
70+ loadDir(indicator_dir);
7271 }
7372 }
7473
@@ -77,9 +76,9 @@ void IndicatorsManager::load()
7776 setLoaded(true);
7877}
7978
80−void IndicatorsManager::onDirectoryChanged(const QString& direcory)
79+void IndicatorsManager::onDirectoryChanged(const QString& directory)
8180{
82− load(QDir(direcory));
81+ loadDir(QDir(directory));
8382}
8483
8584void IndicatorsManager::onFileChanged(const QString& file)
@@ -87,29 +86,29 @@ void IndicatorsManager::onFileChanged(const QString& file)
8786 QFileInfo file_info(file);
8887 if (!file_info.exists())
8988 {
90− unload(file_info);
89+ unloadFile(file_info);
9190 return;
9291 }
9392 else
9493 {
95− load(QFileInfo(file));
94+ loadFile(QFileInfo(file));
9695 }
9796}
9897
99−void IndicatorsManager::load(const QDir& dir)
98+void IndicatorsManager::loadDir(const QDir& dir)
10099{
101100 startVerify(dir.canonicalPath());
102101
103102 QFileInfoList indicator_files = dir.entryInfoList(QStringList(), QDir::Files|QDir::NoDotAndDotDot);
104103 Q_FOREACH(const QFileInfo& indicator_file, indicator_files)
105104 {
106− load(indicator_file);
105+ loadFile(indicator_file);
107106 }
108107
109108 endVerify(dir.canonicalPath());
110109}
111110
112−void IndicatorsManager::load(const QFileInfo& file_info)
111+void IndicatorsManager::loadFile(const QFileInfo& file_info)
113112{
114113 QSettings indicator_settings(file_info.absoluteFilePath(), QSettings::IniFormat, this);
115114 QString name = indicator_settings.value("Indicator Service/Name").toString();
@@ -128,18 +127,24 @@ void IndicatorsManager::load(const QFileInfo& file_info)
128127
129128 // if we've already got this indicator, we need to make sure we're not overwriting data which is
130129 // from a lower priority standard path
131− QStringList xdgLocations = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
130+ QStringList xdgLocations = shellDataDirs();
132131 for (int i = 0; i < xdgLocations.size(); i++)
133132 {
134133 QString indicatorDir = QDir::cleanPath(xdgLocations[i] + "/unity/indicators");
135134
136135 if (newFileInfoDir == indicatorDir)
137− file_info_location = i;
136+ {
137+ file_info_location = i;
138+ }
138139 if (currentDataDir == indicatorDir)
140+ {
139141 current_data_location = i;
142+ }
140143
141144 if (file_info_location != -1 && current_data_location != -1)
145+ {
142146 break;
147+ }
143148 }
144149
145150 // file location is higher (or of equal) priority. overwrite.
@@ -174,7 +179,7 @@ void IndicatorsManager::unload()
174179 setLoaded(false);
175180}
176181
177−void IndicatorsManager::unload(const QFileInfo& file)
182+void IndicatorsManager::unloadFile(const QFileInfo& file)
178183{
179184 QMutableHashIterator<QString, IndicatorData*> iter(m_indicatorsData);
180185 while(iter.hasNext())
@@ -214,7 +219,9 @@ void IndicatorsManager::startVerify(const QString& path)
214219 iter.next();
215220 IndicatorData* data = iter.value();
216221 if (data->m_fileInfo.canonicalPath() == path)
222+ {
217223 data->m_verified = false;
224+ }
218225 }
219226}
220227
@@ -249,7 +256,9 @@ Indicator::Ptr IndicatorsManager::indicator(const QString& indicator)
249256
250257 IndicatorData *data = m_indicatorsData[indicator];
251258 if (data->m_indicator)
259+ {
252260 return data->m_indicator;
261+ }
253262
254263 Indicator::Ptr plugin(new Indicator(this));
255264 data->m_indicator = plugin;
modules/Unity/Indicators/indicatorsmanager.h+6−8
@@ -1,9 +1,6 @@
11/*
22 * Copyright (C) 2013 Canonical, Ltd.
33 *
4− * Authors:
5− * Michał Sawicz <michal.sawicz@canonical.com>
6− *
74 * This program is free software; you can redistribute it and/or modify
85 * it under the terms of the GNU General Public License as published by
96 * the Free Software Foundation; version 3.
@@ -15,9 +12,10 @@
1512 *
1613 * You should have received a copy of the GNU General Public License
1714 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Author: Nick Dedekind <nick.dedekind@canonical.com>
1817 */
1918
20−
2119#ifndef INDICATORS_MANAGER_H
2220#define INDICATORS_MANAGER_H
2321
@@ -53,13 +51,13 @@ Q_SIGNALS:
5351 void indicatorAboutToBeUnloaded(const QString& indicator);
5452
5553private Q_SLOTS:
56− void onDirectoryChanged(const QString& direcory);
54+ void onDirectoryChanged(const QString& directory);
5755 void onFileChanged(const QString& file);
5856
5957private:
60− void load(const QDir& dir);
61− void load(const QFileInfo& file);
62− void unload(const QFileInfo& dir);
58+ void loadDir(const QDir& dir);
59+ void loadFile(const QFileInfo& file);
60+ void unloadFile(const QFileInfo& dir);
6361
6462 void startVerify(const QString& path);
6563 void endVerify(const QString& path);
modules/Unity/Indicators/indicatorsmodel.cpp+5−21
@@ -67,27 +67,6 @@ IndicatorsModel::~IndicatorsModel()
6767 m_manager->deleteLater();
6868}
6969
70−/*!
71− \qmlmethod IndicatorsModel::get(int)
72−
73− Returns the item at index in the model. This allows the item data to be accessed from JavaScript:
74− \b Note: methods should only be called after the Component has completed.
75−*/
76−QVariantMap IndicatorsModel::get(int row) const
77−{
78− QVariantMap result;
79−
80− QModelIndex index = this->index(row);
81− if (index.isValid()) {
82− QMap<int, QVariant> data = itemData(index);
83− const QHash<int, QByteArray> roleNames = this->roleNames();
84− Q_FOREACH(int i, roleNames.keys()) {
85− result.insert(roleNames[i], data[i]);
86− }
87− }
88− return result;
89−}
90−
9170/*!
9271 \qmlproperty IndicatorsModel::count
9372 The number of data entries in the model.
@@ -246,6 +225,11 @@ QVariant IndicatorsModel::defaultData(Indicator::Ptr plugin, int role)
246225 return QVariant();
247226}
248227
228+Q_INVOKABLE QVariant IndicatorsModel::data(int row, int role) const
229+{
230+ return data(index(row, 0), role);
231+}
232+
249233/*! \internal */
250234QVariant IndicatorsModel::data(const QModelIndex &index, int role) const
251235{
modules/Unity/Indicators/indicatorsmodel.h+1−1
@@ -53,7 +53,7 @@ public:
5353 Q_INVOKABLE void load();
5454 Q_INVOKABLE void unload();
5555
56− Q_INVOKABLE QVariantMap get(int row) const;
56+ Q_INVOKABLE QVariant data(int row, int role = Qt::DisplayRole) const;
5757
5858 /* QAbstractItemModel */
5959 QHash<int, QByteArray> roleNames() const;
modules/Unity/Indicators/plugin.cpp+1−1
@@ -13,7 +13,7 @@
1313 * You should have received a copy of the GNU General Public License
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 *
16− * Author: Michał Sawicz <michal.sawicz@canonical.com>
16+ * Author: Nick Dedekind <nick.dedekind@canonical.com>
1717 */
1818
1919// Qt
modules/Unity/Indicators/qml/IndicatorWidget.qml+6−6
@@ -49,21 +49,21 @@ IndicatorBase {
4949
5050
5151 function update_state() {
52− var data = proxyModel.get(0);
53− if (data == undefined || data.extra == undefined) {
52+ var extra = proxyModel.data(0, Indicators.FlatMenuProxyModel.Extra);
53+ if (extra == undefined) {
5454 return;
5555 }
5656
57− if (!data.extra.hasOwnProperty("canonical_type")) {
57+ if (!extra.hasOwnProperty("canonical_type")) {
5858 return;
5959 }
6060
61− if (parseRootElement(data.extra.canonical_type, data)) {
62− action = actionGroup.action(data.action);
61+ if (parseRootElement(extra.canonical_type)) {
62+ action = actionGroup.action(proxyModel.data(0, Indicators.FlatMenuProxyModel.Action));
6363 }
6464 }
6565
66− function parseRootElement(type, data) {
66+ function parseRootElement(type) {
6767 if (type == "com.canonical.indicator.root")
6868 return true;
6969 return false;
paths.h.in+2−1
@@ -75,7 +75,8 @@ inline QStringList shellDataDirs() {
7575 }
7676 }
7777 else {
78− dirs.prepend(shellAppDirectory());
78+ // append so by default we use xdg files.
79+ dirs.append(shellAppDirectory());
7980 }
8081 return dirs;
8182}
tests/modules/Unity/Indicators/indicatorsmodeltest.cpp+12−12
@@ -78,21 +78,21 @@ private Q_SLOTS:
7878 model.setIndicatorData(map);
7979 model.load();
8080
81− QCOMPARE(model.get(0)["identifier"].toString(), QString("indicator-fake2"));
82− QCOMPARE(model.get(0)["title"].toString(), QString("fake2"));
83− QCOMPARE(model.get(0)["indicatorProperties"].toMap()["busName"].toString(), QString("com.canonical.indicator.fake2"));
81+ QCOMPARE(model.data(0, IndicatorsModel::Identifier).toString(), QString("indicator-fake2"));
82+ QCOMPARE(model.data(0, IndicatorsModel::Title).toString(), QString("fake2"));
83+ QCOMPARE(model.data(0, IndicatorsModel::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake2"));
8484
85− QCOMPARE(model.get(1)["identifier"].toString(), QString("indicator-fake1"));
86− QCOMPARE(model.get(1)["title"].toString(), QString("fake1"));
87− QCOMPARE(model.get(1)["indicatorProperties"].toMap()["busName"].toString(), QString("com.canonical.indicator.fake1"));
85+ QCOMPARE(model.data(1, IndicatorsModel::Identifier).toString(), QString("indicator-fake1"));
86+ QCOMPARE(model.data(1, IndicatorsModel::Title).toString(), QString("fake1"));
87+ QCOMPARE(model.data(1, IndicatorsModel::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake1"));
8888
89− QCOMPARE(model.get(2)["identifier"].toString(), QString("indicator-fake4"));
90− QCOMPARE(model.get(2)["title"].toString(), QString("fake4"));
91− QCOMPARE(model.get(2)["indicatorProperties"].toMap()["busName"].toString(), QString("com.canonical.indicator.fake4"));
89+ QCOMPARE(model.data(2, IndicatorsModel::Identifier).toString(), QString("indicator-fake4"));
90+ QCOMPARE(model.data(2, IndicatorsModel::Title).toString(), QString("fake4"));
91+ QCOMPARE(model.data(2, IndicatorsModel::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake4"));
9292
93− QCOMPARE(model.get(3)["identifier"].toString(), QString("indicator-fake3"));
94− QCOMPARE(model.get(3)["title"].toString(), QString("fake3"));
95− QCOMPARE(model.get(3)["indicatorProperties"].toMap()["busName"].toString(), QString("com.canonical.indicator.fake3"));
93+ QCOMPARE(model.data(3, IndicatorsModel::Identifier).toString(), QString("indicator-fake3"));
94+ QCOMPARE(model.data(3, IndicatorsModel::Title).toString(), QString("fake3"));
95+ QCOMPARE(model.data(3, IndicatorsModel::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake3"));
9696 }
9797};
9898