on xenial help sign in
Support switching the indicator profile on the fly, as the greeter appears and disappears. (But don't use it yet, not until the settings panel to control this is in place.)
7754b78Michael Terry
plugins/Unity/Indicators/indicator.cpp+23−8
@@ -31,24 +31,26 @@ Indicator::~Indicator()
31{
31{
32}
32}
33
33
34−void Indicator::init(const QString &profile, const QString& busName, const QSettings& settings)
34+void Indicator::init(const QString& busName, const QSettings& settings)
35{
35{
36− setId(settings.value("Indicator Service/Name").toString());
36+ // Save all keys we care about from the QSettings object. It's annoying
37+ // that we can't just copy the object.
38+ m_settings.clear();
39+ Q_FOREACH(const QString& key, settings.allKeys()) {
40+ if (key.endsWith("/Position") || key.endsWith("/ObjectPath")) {
41+ m_settings.insert(key, settings.value(key));
42+ }
43+ }
37
44
38− QVariant pos = settings.value(profile + "/Position");
39− if (!pos.isValid())
40− pos = settings.value("Indicator Service/Position", QVariant::fromValue(0));
45+ setId(settings.value("Indicator Service/Name").toString());
41− setPosition(pos.toInt());
42
46
43 QString actionObjectPath = settings.value("Indicator Service/ObjectPath").toString();
47 QString actionObjectPath = settings.value("Indicator Service/ObjectPath").toString();
44− QString menuObjectPath = settings.value(profile + "/ObjectPath").toString();
45
48
46 QVariantMap properties;
49 QVariantMap properties;
47 properties.clear();
50 properties.clear();
48 properties.insert("busType", 1);
51 properties.insert("busType", 1);
49 properties.insert("busName", busName);
52 properties.insert("busName", busName);
50 properties.insert("actionsObjectPath", actionObjectPath);
53 properties.insert("actionsObjectPath", actionObjectPath);
51− properties.insert("menuObjectPath", menuObjectPath);
52 setIndicatorProperties(properties);
54 setIndicatorProperties(properties);
53}
55}
54
56
@@ -78,6 +80,19 @@ void Indicator::setPosition(int position)
78 }
80 }
79}
81}
80
82
83+void Indicator::setProfile(const QString& profile)
84+{
85+ QVariant pos = m_settings.value(profile + "/Position");
86+ if (!pos.isValid())
87+ pos = m_settings.value("Indicator Service/Position", QVariant::fromValue(0));
88+ setPosition(pos.toInt());
89+
90+ QString menuObjectPath = m_settings.value(profile + "/ObjectPath").toString();
91+ QVariantMap map = m_properties.toMap();
92+ map.insert("menuObjectPath", menuObjectPath);
93+ setIndicatorProperties(map);
94+}
95+
81QVariant Indicator::indicatorProperties() const
96QVariant Indicator::indicatorProperties() const
82{
97{
83 return m_properties;
98 return m_properties;
plugins/Unity/Indicators/indicator.h+5−1
@@ -35,12 +35,15 @@ public:
35 Indicator(QObject *parent = 0);
35 Indicator(QObject *parent = 0);
36 virtual ~Indicator();
36 virtual ~Indicator();
37
37
38− void init(const QString &profile, const QString& busName, const QSettings& settings);
38+ void init(const QString& busName, const QSettings& settings);
39
39
40 QString identifier() const;
40 QString identifier() const;
41 int position() const;
41 int position() const;
42 QVariant indicatorProperties() const;
42 QVariant indicatorProperties() const;
43
43
44+public Q_SLOTS:
45+ void setProfile(const QString& profile);
46+
44Q_SIGNALS:
47Q_SIGNALS:
45 void identifierChanged(const QString &identifier);
48 void identifierChanged(const QString &identifier);
46 void positionChanged(int position);
49 void positionChanged(int position);
@@ -55,6 +58,7 @@ private:
55 QString m_identifier;
58 QString m_identifier;
56 int m_position;
59 int m_position;
57 QVariant m_properties;
60 QVariant m_properties;
61+ QVariantMap m_settings;
58};
62};
59
63
60#endif // INDICATOR_H
64#endif // INDICATOR_H
plugins/Unity/Indicators/indicatorsmanager.cpp+17−3
@@ -54,10 +54,9 @@ IndicatorsManager::~IndicatorsManager()
54
54
55}
55}
56
56
57−void IndicatorsManager::load(const QString& profile)
57+void IndicatorsManager::load()
58{
58{
59 unload();
59 unload();
60− m_profile = profile;
61
60
62 QStringList xdgLocations = shellDataDirs();//QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
61 QStringList xdgLocations = shellDataDirs();//QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
63
62
@@ -216,6 +215,19 @@ void IndicatorsManager::setLoaded(bool loaded)
216 }
215 }
217}
216}
218
217
218+QString IndicatorsManager::profile() const
219+{
220+ return m_profile;
221+}
222+
223+void IndicatorsManager::setProfile(const QString& profile)
224+{
225+ if (m_profile != profile) {
226+ m_profile = profile;
227+ Q_EMIT profileChanged(m_profile);
228+ }
229+}
230+
219void IndicatorsManager::startVerify(const QString& path)
231void IndicatorsManager::startVerify(const QString& path)
220{
232{
221 QHashIterator<QString, IndicatorData*> iter(m_indicatorsData);
233 QHashIterator<QString, IndicatorData*> iter(m_indicatorsData);
@@ -268,7 +280,9 @@ Indicator::Ptr IndicatorsManager::indicator(const QString& indicator_name)
268 Indicator::Ptr new_indicator(new Indicator(this));
280 Indicator::Ptr new_indicator(new Indicator(this));
269 data->m_indicator = new_indicator;
281 data->m_indicator = new_indicator;
270 QSettings settings(data->m_fileInfo.absoluteFilePath(), QSettings::IniFormat, this);
282 QSettings settings(data->m_fileInfo.absoluteFilePath(), QSettings::IniFormat, this);
271− new_indicator->init(m_profile, data->m_fileInfo.fileName(), settings);
283+ new_indicator->init(data->m_fileInfo.fileName(), settings);
284+ new_indicator->setProfile(m_profile);
285+ QObject::connect(this, SIGNAL(profileChanged(const QString&)), new_indicator.data(), SLOT(setProfile(const QString&)));
272 return new_indicator;
286 return new_indicator;
273}
287}
274
288
plugins/Unity/Indicators/indicatorsmanager.h+6−1
@@ -32,13 +32,17 @@ class UNITYINDICATORS_EXPORT IndicatorsManager : public QObject
32{
32{
33 Q_OBJECT
33 Q_OBJECT
34 Q_PROPERTY(bool loaded READ isLoaded NOTIFY loadedChanged)
34 Q_PROPERTY(bool loaded READ isLoaded NOTIFY loadedChanged)
35+ Q_PROPERTY(QString profile READ profile WRITE setProfile NOTIFY profileChanged)
35public:
36public:
36 explicit IndicatorsManager(QObject* parent = 0);
37 explicit IndicatorsManager(QObject* parent = 0);
37 ~IndicatorsManager();
38 ~IndicatorsManager();
38
39
39− Q_INVOKABLE void load(const QString& profile);
40+ Q_INVOKABLE void load();
40 Q_INVOKABLE void unload();
41 Q_INVOKABLE void unload();
41
42
43+ QString profile() const;
44+ void setProfile(const QString& profile);
45+
42 Indicator::Ptr indicator(const QString& indicator_name);
46 Indicator::Ptr indicator(const QString& indicator_name);
43
47
44 QList<Indicator::Ptr> indicators();
48 QList<Indicator::Ptr> indicators();
@@ -47,6 +51,7 @@ public:
47
51
48Q_SIGNALS:
52Q_SIGNALS:
49 void loadedChanged(bool);
53 void loadedChanged(bool);
54+ void profileChanged(const QString&);
50
55
51 void indicatorLoaded(const QString& indicator_name);
56 void indicatorLoaded(const QString& indicator_name);
52 void indicatorAboutToBeUnloaded(const QString& indicator_name);
57 void indicatorAboutToBeUnloaded(const QString& indicator_name);
plugins/Unity/Indicators/indicatorsmodel.cpp+25−2
@@ -56,6 +56,7 @@ IndicatorsModel::IndicatorsModel(QObject *parent)
56 m_manager = new IndicatorsManager(this);
56 m_manager = new IndicatorsManager(this);
57 QObject::connect(m_manager, SIGNAL(indicatorLoaded(const QString&)), this, SLOT(onIndicatorLoaded(const QString&)));
57 QObject::connect(m_manager, SIGNAL(indicatorLoaded(const QString&)), this, SLOT(onIndicatorLoaded(const QString&)));
58 QObject::connect(m_manager, SIGNAL(indicatorAboutToBeUnloaded(const QString&)), this, SLOT(onIndicatorAboutToBeUnloaded(const QString&)));
58 QObject::connect(m_manager, SIGNAL(indicatorAboutToBeUnloaded(const QString&)), this, SLOT(onIndicatorAboutToBeUnloaded(const QString&)));
59+ QObject::connect(m_manager, SIGNAL(profileChanged(const QString&)), this, SIGNAL(profileChanged()));
59
60
60 QObject::connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SIGNAL(countChanged()));
61 QObject::connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SIGNAL(countChanged()));
61 QObject::connect(this, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SIGNAL(countChanged()));
62 QObject::connect(this, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SIGNAL(countChanged()));
@@ -80,15 +81,37 @@ int IndicatorsModel::count() const
80 return rowCount();
81 return rowCount();
81}
82}
82
83
84+/*!
85+ \qmlproperty IndicatorsModel::profile
86+ The indicator profile to use for the model.
87+
88+ \b Note: methods should only be called after the Component has completed.
89+*/
90+QString IndicatorsModel::profile() const
91+{
92+ return m_manager->profile();
93+}
94+
95+/*!
96+ \qmlproperty IndicatorsModel::setProfile
97+ Set the indicator profile to use for the model.
98+
99+ \b Note: methods should only be called after the Component has completed.
100+*/
101+void IndicatorsModel::setProfile(const QString &profile)
102+{
103+ m_manager->setProfile(profile);
104+}
105+
83/*!
106/*!
84 \qmlmethod IndicatorsModel::unload()
107 \qmlmethod IndicatorsModel::unload()
85
108
86 Load all indicators.
109 Load all indicators.
87*/
110*/
88−void IndicatorsModel::load(const QString& profile)
111+void IndicatorsModel::load()
89{
112{
90 m_indicators.clear();
113 m_indicators.clear();
91− m_manager->load(profile);
114+ m_manager->load();
92}
115}
93
116
94/*!
117/*!
plugins/Unity/Indicators/indicatorsmodel.h+6−1
@@ -34,17 +34,21 @@ class UNITYINDICATORS_EXPORT IndicatorsModel : public QAbstractListModel
34 Q_OBJECT
34 Q_OBJECT
35 Q_ENUMS(Roles)
35 Q_ENUMS(Roles)
36 Q_PROPERTY(int count READ count NOTIFY countChanged)
36 Q_PROPERTY(int count READ count NOTIFY countChanged)
37+ Q_PROPERTY(QString profile READ profile WRITE setProfile NOTIFY profileChanged)
37
38
38public:
39public:
39
40
40 IndicatorsModel(QObject *parent=0);
41 IndicatorsModel(QObject *parent=0);
41 ~IndicatorsModel();
42 ~IndicatorsModel();
42
43
43− Q_INVOKABLE void load(const QString& profile);
44+ Q_INVOKABLE void load();
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;
47
48
49+ QString profile() const;
50+ void setProfile(const QString& profile);
51+
48 /* QAbstractItemModel */
52 /* QAbstractItemModel */
49 QHash<int, QByteArray> roleNames() const;
53 QHash<int, QByteArray> roleNames() const;
50 int columnCount(const QModelIndex &parent = QModelIndex()) const;
54 int columnCount(const QModelIndex &parent = QModelIndex()) const;
@@ -55,6 +59,7 @@ public:
55
59
56Q_SIGNALS:
60Q_SIGNALS:
57 void countChanged();
61 void countChanged();
62+ void profileChanged();
58 void indicatorDataChanged(const QVariant& data);
63 void indicatorDataChanged(const QVariant& data);
59
64
60private Q_SLOTS:
65private Q_SLOTS:
plugins/Unity/Indicators/modelactionrootstate.cpp+4−2
@@ -71,7 +71,7 @@ void ModelActionRootState::setMenu(UnityMenuModel* menu)
71
71
72bool ModelActionRootState::valid() const
72bool ModelActionRootState::valid() const
73{
73{
74− return m_menu && m_menu->rowCount() > 0;
74+ return !currentState().empty();
75}
75}
76
76
77void ModelActionRootState::onModelRowsAdded(const QModelIndex& parent, int start, int end)
77void ModelActionRootState::onModelRowsAdded(const QModelIndex& parent, int start, int end)
@@ -121,7 +121,9 @@ void ModelActionRootState::updateActionState()
121 m_menu->setActionStateParser(oldParser);
121 m_menu->setActionStateParser(oldParser);
122
122
123 setCurrentState(state);
123 setCurrentState(state);
124− } else {
124+ } else if (!m_menu) {
125 setCurrentState(QVariantMap());
125 setCurrentState(QVariantMap());
126 }
126 }
127+ // else if m_menu->rowCount() == 0, let's leave existing cache in place
128+ // until the new menu comes in, to avoid flashing the UI empty for a moment
127}
129}
plugins/Unity/Indicators/unitymenumodelcache.cpp+8−11
@@ -46,17 +46,14 @@ QSharedPointer<UnityMenuModel> UnityMenuModelCache::model(const QByteArray& path
46 QQmlEngine::setObjectOwnership(model, QQmlEngine::CppOwnership);
46 QQmlEngine::setObjectOwnership(model, QQmlEngine::CppOwnership);
47
47
48 QSharedPointer<UnityMenuModel> menuModel(model);
48 QSharedPointer<UnityMenuModel> menuModel(model);
49− connect(model, &QObject::destroyed, this, [this] {
49+
50− QMutableHashIterator<QByteArray, QWeakPointer<UnityMenuModel>> iter(m_registry);
50+ // Keep a shared pointer (rather than weak pointer which would cause the
51− while(iter.hasNext()) {
51+ // model to be deleted when all shared pointers we give out are deleted).
52− auto keyVal = iter.next();
52+ // We want to keep all models cached because when we switch indicator
53− if (keyVal.value().isNull()) {
53+ // profiles, we will be switching paths often. And we want to keep the
54− iter.remove();
54+ // old model around, ready to be used. Otherwise the UI might momentarily
55− break;
55+ // wait as we populate the model from DBus yet again.
56− }
57− }
58− });
59− m_registry[path] = menuModel.toWeakRef();
56+ m_registry[path] = menuModel;
60
57
61 menuModel->setMenuObjectPath(path);
58 menuModel->setMenuObjectPath(path);
62 return menuModel;
59 return menuModel;
plugins/Unity/Indicators/unitymenumodelcache.h+2−2
@@ -25,7 +25,7 @@
25#include <QObject>
25#include <QObject>
26#include <QHash>
26#include <QHash>
27#include <QPointer>
27#include <QPointer>
28−#include <QWeakPointer>
28+#include <QSharedPointer>
29
29
30class UnityMenuModel;
30class UnityMenuModel;
31
31
@@ -43,7 +43,7 @@ public:
43 Q_INVOKABLE virtual bool contains(const QByteArray& path);
43 Q_INVOKABLE virtual bool contains(const QByteArray& path);
44
44
45protected:
45protected:
46− QHash<QByteArray, QWeakPointer<UnityMenuModel>> m_registry;
46+ QHash<QByteArray, QSharedPointer<UnityMenuModel>> m_registry;
47 static QPointer<UnityMenuModelCache> theCache;
47 static QPointer<UnityMenuModelCache> theCache;
48};
48};
49
49
qml/Shell.qml+3−1
@@ -766,7 +766,9 @@ Item {
766 expandedPanelHeight: units.gu(7)
766 expandedPanelHeight: units.gu(7)
767
767
768 indicatorsModel: Indicators.IndicatorsModel {
768 indicatorsModel: Indicators.IndicatorsModel {
769+ // TODO: This should be sourced by device type (e.g. "desktop", "tablet", "phone"...)
770+ profile: indicatorProfile
769− Component.onCompleted: load(indicatorProfile);
771+ Component.onCompleted: load()
770 }
772 }
771 }
773 }
772 callHint {
774 callHint {
tests/mocks/Unity/Indicators/fakeindicatorsmodel.cpp+13−1
@@ -21,7 +21,8 @@
21#include "indicators.h"
21#include "indicators.h"
22
22
23FakeIndicatorsModel::FakeIndicatorsModel(QObject *parent)
23FakeIndicatorsModel::FakeIndicatorsModel(QObject *parent)
24− : QAbstractListModel(parent)
24+ : QAbstractListModel(parent),
25+ m_profile("phone")
25{
26{
26 QObject::connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SIGNAL(countChanged()));
27 QObject::connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SIGNAL(countChanged()));
27 QObject::connect(this, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SIGNAL(countChanged()));
28 QObject::connect(this, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SIGNAL(countChanged()));
@@ -38,6 +39,17 @@ int FakeIndicatorsModel::count() const
38 return rowCount();
39 return rowCount();
39}
40}
40
41
42+QString FakeIndicatorsModel::profile() const
43+{
44+ return m_profile;
45+}
46+
47+void FakeIndicatorsModel::setProfile(const QString& profile)
48+{
49+ m_profile = profile;
50+ Q_EMIT profileChanged();
51+}
52+
41void FakeIndicatorsModel::load(const QString&)
53void FakeIndicatorsModel::load(const QString&)
42{
54{
43}
55}
tests/mocks/Unity/Indicators/fakeindicatorsmodel.h+6
@@ -27,7 +27,9 @@ class FakeIndicatorsModel : public QAbstractListModel
27 Q_OBJECT
27 Q_OBJECT
28 Q_ENUMS(Roles)
28 Q_ENUMS(Roles)
29 Q_PROPERTY(int count READ count NOTIFY countChanged)
29 Q_PROPERTY(int count READ count NOTIFY countChanged)
30+ Q_PROPERTY(QString profile READ profile WRITE setProfile NOTIFY profileChanged)
30 Q_PROPERTY(QVariant modelData READ modelData WRITE setModelData NOTIFY modelDataChanged)
31 Q_PROPERTY(QVariant modelData READ modelData WRITE setModelData NOTIFY modelDataChanged)
32+
31public:
33public:
32
34
33 FakeIndicatorsModel(QObject *parent=0);
35 FakeIndicatorsModel(QObject *parent=0);
@@ -42,6 +44,8 @@ public:
42
44
43 Q_INVOKABLE QVariant data(int row, int role) const;
45 Q_INVOKABLE QVariant data(int row, int role) const;
44
46
47+ QString profile() const;
48+ void setProfile(const QString& profile);
45 void setModelData(const QVariant& data);
49 void setModelData(const QVariant& data);
46 QVariant modelData() const { return m_modelData; }
50 QVariant modelData() const { return m_modelData; }
47
51
@@ -54,11 +58,13 @@ public:
54
58
55Q_SIGNALS:
59Q_SIGNALS:
56 void countChanged();
60 void countChanged();
61+ void profileChanged();
57 void modelDataChanged();
62 void modelDataChanged();
58
63
59private:
64private:
60 int count() const;
65 int count() const;
61
66
67+ QString m_profile;
62 QVariant m_modelData;
68 QVariant m_modelData;
63};
69};
64
70
tests/plugins/Unity/Indicators/indicatorsmanagertest.cpp+30−5
@@ -50,7 +50,8 @@ private Q_SLOTS:
50 QVERIFY(!manager.isLoaded());
50 QVERIFY(!manager.isLoaded());
51 QCOMPARE(manager.indicators().count(), 0);
51 QCOMPARE(manager.indicators().count(), 0);
52
52
53− manager.load("test1");
53+ manager.setProfile("test1");
54+ manager.load();
54
55
55 QVERIFY(manager.isLoaded());
56 QVERIFY(manager.isLoaded());
56 QCOMPARE(manager.indicators().count(), 4);
57 QCOMPARE(manager.indicators().count(), 4);
@@ -67,7 +68,8 @@ private Q_SLOTS:
67 void testPluginInterfaceProfile1()
68 void testPluginInterfaceProfile1()
68 {
69 {
69 IndicatorsManager manager;
70 IndicatorsManager manager;
70− manager.load("test1");
71+ manager.setProfile("test1");
72+ manager.load();
71
73
72 Indicator::Ptr indicator = manager.indicator("indicator-fake1");
74 Indicator::Ptr indicator = manager.indicator("indicator-fake1");
73 QVERIFY(indicator ? true : false);
75 QVERIFY(indicator ? true : false);
@@ -90,7 +92,8 @@ private Q_SLOTS:
90 void testPluginInterfaceProfile2()
92 void testPluginInterfaceProfile2()
91 {
93 {
92 IndicatorsManager manager;
94 IndicatorsManager manager;
93− manager.load("test2");
95+ manager.setProfile("test2");
96+ manager.load();
94
97
95 Indicator::Ptr indicator = manager.indicator("indicator-fake1");
98 Indicator::Ptr indicator = manager.indicator("indicator-fake1");
96 QVERIFY(indicator ? true : false);
99 QVERIFY(indicator ? true : false);
@@ -107,13 +110,34 @@ private Q_SLOTS:
107 QCOMPARE(props["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake1/test2"));
110 QCOMPARE(props["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake1/test2"));
108 }
111 }
109
112
113+ /*
114+ * Test switching the indicator profile data
115+ */
116+ void testPluginInterfaceProfileSwitch()
117+ {
118+ IndicatorsManager manager;
119+ manager.setProfile("test1");
120+ manager.load();
121+
122+ Indicator::Ptr indicator = manager.indicator("indicator-fake1");
123+ QVERIFY(indicator ? true : false);
124+
125+ QVariantMap props = indicator->indicatorProperties().toMap();
126+ QCOMPARE(props["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake1/test1"));
127+
128+ manager.setProfile("test2");
129+ props = indicator->indicatorProperties().toMap();
130+ QCOMPARE(props["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake1/test2"));
131+ }
132+
110 /*
133 /*
111 * Test if a new plugin object is create for each different plugin
134 * Test if a new plugin object is create for each different plugin
112 */
135 */
113 void testPluginInstance()
136 void testPluginInstance()
114 {
137 {
115 IndicatorsManager manager;
138 IndicatorsManager manager;
116− manager.load("test2");
139+ manager.setProfile("test2");
140+ manager.load();
117
141
118 Indicator::Ptr i0 = manager.indicator("indicator-fake1");
142 Indicator::Ptr i0 = manager.indicator("indicator-fake1");
119 Indicator::Ptr i1 = manager.indicator("indicator-fake1");
143 Indicator::Ptr i1 = manager.indicator("indicator-fake1");
@@ -133,7 +157,8 @@ private Q_SLOTS:
133 void testPluginInitAndShutdown()
157 void testPluginInitAndShutdown()
134 {
158 {
135 IndicatorsManager manager;
159 IndicatorsManager manager;
136− manager.load("test1");
160+ manager.setProfile("test1");
161+ manager.load();
137
162
138 QWeakPointer<Indicator> wp0;
163 QWeakPointer<Indicator> wp0;
139 QWeakPointer<Indicator> wp1;
164 QWeakPointer<Indicator> wp1;
tests/plugins/Unity/Indicators/indicatorsmodeltest.cpp+6−3
@@ -47,10 +47,11 @@ private Q_SLOTS:
47 void testLoad()
47 void testLoad()
48 {
48 {
49 IndicatorsModel model;
49 IndicatorsModel model;
50+ model.setProfile("test1");
50
51
51 QCOMPARE(model.property("count").toInt(), 0);
52 QCOMPARE(model.property("count").toInt(), 0);
52
53
53− model.load("test1");
54+ model.load();
54
55
55 QCOMPARE(model.property("count").toInt(), 4);
56 QCOMPARE(model.property("count").toInt(), 4);
56
57
@@ -67,7 +68,8 @@ private Q_SLOTS:
67 {
68 {
68 // Priority order. (2, 1, 4, 3)
69 // Priority order. (2, 1, 4, 3)
69 IndicatorsModel model;
70 IndicatorsModel model;
70− model.load("test1");
71+ model.setProfile("test1");
72+ model.load();
71
73
72 // should be in order:
74 // should be in order:
73 // fake3, fake4, fake1, fake2
75 // fake3, fake4, fake1, fake2
@@ -104,7 +106,8 @@ private Q_SLOTS:
104 {
106 {
105 // Priority order. (2, 1, 4, 3)
107 // Priority order. (2, 1, 4, 3)
106 IndicatorsModel model;
108 IndicatorsModel model;
107− model.load("test2");
109+ model.setProfile("test2");
110+ model.load();
108
111
109 // should be in order:
112 // should be in order:
110 // fake3, fake4, fake1, fake2
113 // fake3, fake4, fake1, fake2
tests/plugins/Unity/Indicators/sharedunitymenumodeltest.cpp+2−2
@@ -61,7 +61,7 @@ private Q_SLOTS:
61 QCOMPARE(model1->model(), model2->model());
61 QCOMPARE(model1->model(), model2->model());
62 }
62 }
63
63
64− void testSharedOwnership()
64+ void testSavedData()
65 {
65 {
66 QSharedPointer<SharedUnityMenuModel> model1(createFullModel("test1"));
66 QSharedPointer<SharedUnityMenuModel> model1(createFullModel("test1"));
67 QSharedPointer<SharedUnityMenuModel> model2(createFullModel("test1"));
67 QSharedPointer<SharedUnityMenuModel> model2(createFullModel("test1"));
@@ -70,7 +70,7 @@ private Q_SLOTS:
70 model1.clear();
70 model1.clear();
71 QCOMPARE(UnityMenuModelCache::singleton()->contains("/com/canonical/test1"), true);
71 QCOMPARE(UnityMenuModelCache::singleton()->contains("/com/canonical/test1"), true);
72 model2.clear();
72 model2.clear();
73− QCOMPARE(UnityMenuModelCache::singleton()->contains("/com/canonical/test1"), false);
73+ QCOMPARE(UnityMenuModelCache::singleton()->contains("/com/canonical/test1"), true);
74 }
74 }
75
75
76 // Tests that changing cached model data does not change the model path of others
76 // Tests that changing cached model data does not change the model path of others
tests/qmltests/tst_Shell.qml+29
@@ -25,6 +25,7 @@ import Ubuntu.Components 1.1
25import Ubuntu.Telephony 0.1 as Telephony
25import Ubuntu.Telephony 0.1 as Telephony
26import Unity.Application 0.1
26import Unity.Application 0.1
27import Unity.Connectivity 0.1
27import Unity.Connectivity 0.1
28+import Unity.Indicators 0.1
28import Unity.Notifications 1.0
29import Unity.Notifications 1.0
29import Unity.Test 0.1 as UT
30import Unity.Test 0.1 as UT
30import Powerd 0.1
31import Powerd 0.1
@@ -172,6 +173,7 @@ Item {
172
173
173 function init() {
174 function init() {
174 tryCompare(shell, "enabled", true); // enabled by greeter when ready
175 tryCompare(shell, "enabled", true); // enabled by greeter when ready
176+ shell.indicatorProfile = "phone";
175
177
176 swipeAwayGreeter();
178 swipeAwayGreeter();
177
179
@@ -567,6 +569,33 @@ Item {
567 && itemRectInShell.y + itemRectInShell.height <= shell.height;
569 && itemRectInShell.y + itemRectInShell.height <= shell.height;
568 }
570 }
569
571
572+ function test_greeterDoesNotChangeIndicatorProfile() {
573+ var panel = findChild(shell, "panel");
574+ tryCompare(panel.indicators.indicatorsModel, "profile", shell.indicatorProfile);
575+
576+ LightDM.Greeter.showGreeter();
577+ tryCompare(panel.indicators.indicatorsModel, "profile", shell.indicatorProfile);
578+
579+ LightDM.Greeter.hideGreeter();
580+ tryCompare(panel.indicators.indicatorsModel, "profile", shell.indicatorProfile);
581+ }
582+
583+ function test_shellProfileChangesReachIndicators() {
584+ var panel = findChild(shell, "panel");
585+
586+ shell.indicatorProfile = "test1";
587+ for (var i = 0; i < panel.indicators.indicatorsModel.count; ++i) {
588+ var properties = panel.indicators.indicatorsModel.data(i, IndicatorsModelRole.IndicatorProperties);
589+ verify(properties["menuObjectPath"].substr(-5), "test1");
590+ }
591+
592+ shell.indicatorProfile = "test2";
593+ for (var i = 0; i < panel.indicators.indicatorsModel.count; ++i) {
594+ var properties = panel.indicators.indicatorsModel.data(i, IndicatorsModelRole.IndicatorProperties);
595+ verify(properties["menuObjectPath"].substr(-5), "test2");
596+ }
597+ }
598+
570 function test_focusRequestedHidesGreeter() {
599 function test_focusRequestedHidesGreeter() {
571 var greeter = findChild(shell, "greeter");
600 var greeter = findChild(shell, "greeter");
572
601
tests/qmltests/tst_ShellWithPin.qml+16
@@ -232,6 +232,22 @@ Item {
232 tryCompare(ApplicationManager, "focusedApplicationId", app)
232 tryCompare(ApplicationManager, "focusedApplicationId", app)
233 }
233 }
234
234
235+ function test_greeterChangesIndicatorProfile() {
236+ skip("Not supported yet, waiting on design for new settings panel");
237+
238+ var panel = findChild(shell, "panel");
239+ tryCompare(panel.indicators.indicatorsModel, "profile", shell.indicatorProfile + "_greeter");
240+
241+ LightDM.Greeter.hideGreeter();
242+ tryCompare(panel.indicators.indicatorsModel, "profile", shell.indicatorProfile);
243+
244+ LightDM.Greeter.showGreeter();
245+ tryCompare(panel.indicators.indicatorsModel, "profile", shell.indicatorProfile + "_greeter");
246+
247+ LightDM.Greeter.hideGreeter();
248+ tryCompare(panel.indicators.indicatorsModel, "profile", shell.indicatorProfile);
249+ }
250+
235 function test_login() {
251 function test_login() {
236 sessionSpy.clear()
252 sessionSpy.clear()
237 tryCompare(sessionSpy, "count", 0)
253 tryCompare(sessionSpy, "count", 0)