on xenial help sign in
Added a "-profile" option to the indicator-client to switch between indicator service profiles.
commit2bed569a6be8a582c04f04514fbe58d94b855cbf authorNick Dedekind <nicholas.dedekind@gmail.com> dateWed 12 Feb 2014, 15:12 (13 years ago) parent071ea3bafb75cf
19 files changed+126−44
plugins/Unity/Indicators/indicatorsmanager.cpp+5−4 plugins/Unity/Indicators/indicatorsmanager.h+2−1 plugins/Unity/Indicators/indicatorsmodel.cpp+2−2 plugins/Unity/Indicators/indicatorsmodel.h+1−1 qml/Panel/Indicators.qml+3−1 qml/Panel/Indicators/VisibleIndicators.qml+2−2 qml/Panel/Indicators/client/IndicatorsClient.qml+1−2 qml/Panel/Indicators/client/IndicatorsList.qml+2−1 src/Panel/Indicators/client/indicatorsclient.cpp+6−1 tests/data/unity/indicators/com.canonical.indicator.fake1+4−4 tests/data/unity/indicators/com.canonical.indicator.fake2+4−4 tests/data/unity/indicators/com.canonical.indicator.fake3+4−4 tests/data/unity/indicators/com.canonical.indicator.fake4+4−4 tests/plugins/Unity/Indicators/indicatorsmanagertest.cpp+29−6 tests/plugins/Unity/Indicators/indicatorsmodeltest.cpp+49−4 tests/qmltests/Panel/tst_IndicatorRow.qml+2−2 tests/qmltests/Panel/tst_Indicators.qml+1 tests/qmltests/Panel/tst_MenuContent.qml+1−1 tests/qmltests/Panel/tst_Panel.qml+4
plugins/Unity/Indicators/indicatorsmanager.cpp+5−4
@@ -26,8 +26,6 @@
2626
2727#include <paths.h>
2828
29−const QString profile = "phone";
30−
3129
3230class IndicatorsManager::IndicatorData
3331{
@@ -49,6 +47,7 @@ public:
4947IndicatorsManager::IndicatorsManager(QObject* parent)
5048 : QObject(parent)
5149 , m_loaded(false)
50+ , m_profile("phone")
5251{
5352}
5453
@@ -58,9 +57,11 @@ IndicatorsManager::~IndicatorsManager()
5857
5958}
6059
61−void IndicatorsManager::load()
60+void IndicatorsManager::load(const QString& profile)
6261{
6362 unload();
63+ m_profile = profile;
64+
6465 QStringList xdgLocations = shellDataDirs();//QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
6566
6667 m_fsWatcher.reset(new QFileSystemWatcher(this));
@@ -300,7 +301,7 @@ Indicator::Ptr IndicatorsManager::indicator(const QString& indicator_name)
300301 Indicator::Ptr new_indicator(new Indicator(this));
301302 data->m_indicator = new_indicator;
302303 QSettings settings(data->m_fileInfo.absoluteFilePath(), QSettings::IniFormat, this);
303− new_indicator->init(profile, data->m_fileInfo.fileName(), settings);
304+ new_indicator->init(m_profile, data->m_fileInfo.fileName(), settings);
304305 return new_indicator;
305306}
306307
plugins/Unity/Indicators/indicatorsmanager.h+2−1
@@ -38,7 +38,7 @@ public:
3838 explicit IndicatorsManager(QObject* parent = 0);
3939 ~IndicatorsManager();
4040
41− Q_INVOKABLE void load();
41+ Q_INVOKABLE void load(const QString& profile);
4242 Q_INVOKABLE void unload();
4343
4444 Indicator::Ptr indicator(const QString& indicator_name);
@@ -71,6 +71,7 @@ private:
7171 QHash<QString, IndicatorData*> m_indicatorsData;
7272 QSharedPointer<QFileSystemWatcher> m_fsWatcher;
7373 bool m_loaded;
74+ QString m_profile;
7475};
7576
7677#endif // INDICATORS_MANAGER_H
plugins/Unity/Indicators/indicatorsmodel.cpp+2−2
@@ -85,10 +85,10 @@ int IndicatorsModel::count() const
8585
8686 Load all indicators.
8787*/
88−void IndicatorsModel::load()
88+void IndicatorsModel::load(const QString& profile)
8989{
9090 m_indicators.clear();
91− m_manager->load();
91+ m_manager->load(profile);
9292}
9393
9494/*!
plugins/Unity/Indicators/indicatorsmodel.h+1−1
@@ -40,7 +40,7 @@ public:
4040 IndicatorsModel(QObject *parent=0);
4141 ~IndicatorsModel();
4242
43− Q_INVOKABLE void load();
43+ Q_INVOKABLE void load(const QString& profile);
4444 Q_INVOKABLE void unload();
4545
4646 Q_INVOKABLE QVariant data(int row, int role) const;
qml/Panel/Indicators.qml+3−1
@@ -31,6 +31,8 @@ Showable {
3131 property bool pinnedMode: true //should be set true if indicators menu can cover whole screen
3232 property alias overFlowWidth: indicatorRow.overFlowWidth
3333 property alias showAll: indicatorRow.showAll
34+ // TODO: This should be sourced by device type (eg "desktop", "tablet", "phone"...)
35+ property string profile: "phone"
3436
3537 readonly property real hintValue: panelHeight + menuContent.headerHeight
3638 readonly property int lockThreshold: openedHeight / 2
@@ -429,6 +431,6 @@ Showable {
429431
430432 Component.onCompleted: initialise();
431433 function initialise() {
432− visibleIndicators.load();
434+ visibleIndicators.load(profile);
433435 }
434436}
qml/Panel/Indicators/VisibleIndicators.qml+2−2
@@ -78,7 +78,7 @@ Item {
7878 }
7979 }
8080
81− function load() {
82− indicatorsModel.load();
81+ function load(profile) {
82+ indicatorsModel.load(profile);
8383 }
8484}
qml/Panel/Indicators/client/IndicatorsClient.qml+1−2
@@ -33,8 +33,7 @@ Rectangle {
3333 function reset() {
3434 clear();
3535 var component = Qt.createComponent("IndicatorsList.qml");
36− var page = component.createObject(pages);
37− console.log(component.errorString());
36+ var page = component.createObject(pages, {"profile": indicatorProfile});
3837 push(page);
3938 }
4039 }
qml/Panel/Indicators/client/IndicatorsList.qml+2−1
@@ -26,12 +26,13 @@ import "../.."
2626Page {
2727 id: page
2828 anchors.fill: parent
29+ property string profile: ""
2930 title: "Plugin list"
3031
3132 Indicators.IndicatorsModel {
3233 id: indicatorsModel
3334
34− Component.onCompleted: load()
35+ Component.onCompleted: load(profile)
3536 }
3637
3738 ListView {
src/Panel/Indicators/client/indicatorsclient.cpp+6−1
@@ -41,9 +41,14 @@ IndicatorsClient::IndicatorsClient(int &argc, char **argv)
4141 prependImportPaths(m_view->engine(), ::overrideImportPaths());
4242 appendImportPaths(m_view->engine(), ::fallbackImportPaths());
4343
44+ QString profile = "phone";
45+ if (args.contains(QLatin1String("-profile")) && args.size() > args.indexOf(QLatin1String("-profile")) + 1) {
46+ profile = args.at(args.indexOf(QLatin1String("-profile")) + 1);
47+ }
48+ m_view->rootContext()->setContextProperty("indicatorProfile", profile);
49+
4450 m_view->setSource(QUrl("IndicatorsClient.qml"));
4551 m_view->setResizeMode(QQuickView::SizeRootObjectToView);
46−
4752 if (args.contains(QLatin1String("-geometry")) && args.size() > args.indexOf(QLatin1String("-geometry")) + 1) {
4853 QStringList geometryArg = args.at(args.indexOf(QLatin1String("-geometry")) + 1).split('x');
4954 if (geometryArg.size() == 2) {
tests/data/unity/indicators/com.canonical.indicator.fake1+4−4
@@ -3,8 +3,8 @@ Name=indicator-fake1
33ObjectPath=/com/canonical/indicator/fake1
44Position=1
55
6−[phone]
7−ObjectPath=/com/canonical/indicator/fake1/phone
6+[test1]
7+ObjectPath=/com/canonical/indicator/fake1/test1
88
9−[desktop]
10−ObjectPath=/com/canonical/indicator/fake1/desktop
9+[test2]
10+ObjectPath=/com/canonical/indicator/fake1/test2
tests/data/unity/indicators/com.canonical.indicator.fake2+4−4
@@ -3,8 +3,8 @@ Name=indicator-fake2
33ObjectPath=/com/canonical/indicator/fake2
44Position=0
55
6−[phone]
7−ObjectPath=/com/canonical/indicator/fake2/phone
6+[test1]
7+ObjectPath=/com/canonical/indicator/fake2/test1
88
9−[desktop]
10−ObjectPath=/com/canonical/indicator/fake2/desktop
9+[test2]
10+ObjectPath=/com/canonical/indicator/fake2/test2
tests/data/unity/indicators/com.canonical.indicator.fake3+4−4
@@ -3,8 +3,8 @@ Name=indicator-fake3
33ObjectPath=/com/canonical/indicator/fake3
44Position=3
55
6−[phone]
7−ObjectPath=/com/canonical/indicator/fake3/phone
6+[test1]
7+ObjectPath=/com/canonical/indicator/fake3/test1
88
9−[desktop]
10−ObjectPath=/com/canonical/indicator/fake3/desktop
9+[test2]
10+ObjectPath=/com/canonical/indicator/fake3/test2
tests/data/unity/indicators/com.canonical.indicator.fake4+4−4
@@ -3,8 +3,8 @@ Name=indicator-fake4
33ObjectPath=/com/canonical/indicator/fake4
44Position=2
55
6−[phone]
7−ObjectPath=/com/canonical/indicator/fake4/phone
6+[test1]
7+ObjectPath=/com/canonical/indicator/fake4/test1
88
9−[desktop]
10−ObjectPath=/com/canonical/indicator/fake4/desktop
9+[test2]
10+ObjectPath=/com/canonical/indicator/fake4/test2
tests/plugins/Unity/Indicators/indicatorsmanagertest.cpp+29−6
@@ -50,7 +50,7 @@ private Q_SLOTS:
5050 QVERIFY(!manager.isLoaded());
5151 QCOMPARE(manager.indicators().count(), 0);
5252
53− manager.load();
53+ manager.load("test1");
5454
5555 QVERIFY(manager.isLoaded());
5656 QCOMPARE(manager.indicators().count(), 4);
@@ -64,10 +64,10 @@ private Q_SLOTS:
6464 /*
6565 * Test the creation & initialising of the indicator data
6666 */
67− void testPluginInterface()
67+ void testPluginInterfaceProfile1()
6868 {
6969 IndicatorsManager manager;
70− manager.load();
70+ manager.load("test1");
7171
7272 Indicator::Ptr indicator = manager.indicator("indicator-fake1");
7373 QVERIFY(indicator ? true : false);
@@ -81,7 +81,30 @@ private Q_SLOTS:
8181 QCOMPARE(props["busName"].toString(), QString("com.canonical.indicator.fake1"));
8282 QCOMPARE(props["actionsObjectPath"].toString(), QString("/com/canonical/indicator/fake1"));
8383
84− QCOMPARE(props["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake1/phone"));
84+ QCOMPARE(props["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake1/test1"));
85+ }
86+
87+ /*
88+ * Test the creation & initialising of the indicator data
89+ */
90+ void testPluginInterfaceProfile2()
91+ {
92+ IndicatorsManager manager;
93+ manager.load("test2");
94+
95+ Indicator::Ptr indicator = manager.indicator("indicator-fake1");
96+ QVERIFY(indicator ? true : false);
97+
98+ QCOMPARE(indicator->identifier(), QString("indicator-fake1"));
99+ QCOMPARE(indicator->position(), 1);
100+
101+ // Check that the initial properties have been set.
102+ QVariantMap props = indicator->indicatorProperties().toMap();
103+ QCOMPARE(props.count(), 4);
104+ QCOMPARE(props["busName"].toString(), QString("com.canonical.indicator.fake1"));
105+ QCOMPARE(props["actionsObjectPath"].toString(), QString("/com/canonical/indicator/fake1"));
106+
107+ QCOMPARE(props["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake1/test2"));
85108 }
86109
87110 /*
@@ -90,7 +113,7 @@ private Q_SLOTS:
90113 void testPluginInstance()
91114 {
92115 IndicatorsManager manager;
93− manager.load();
116+ manager.load("test2");
94117
95118 Indicator::Ptr i0 = manager.indicator("indicator-fake1");
96119 Indicator::Ptr i1 = manager.indicator("indicator-fake1");
@@ -110,7 +133,7 @@ private Q_SLOTS:
110133 void testPluginInitAndShutdown()
111134 {
112135 IndicatorsManager manager;
113− manager.load();
136+ manager.load("test1");
114137
115138 QWeakPointer<Indicator> wp0;
116139 QWeakPointer<Indicator> wp1;
tests/plugins/Unity/Indicators/indicatorsmodeltest.cpp+49−4
@@ -50,7 +50,7 @@ private Q_SLOTS:
5050
5151 QCOMPARE(model.property("count").toInt(), 0);
5252
53− model.load();
53+ model.load("test1");
5454
5555 QCOMPARE(model.property("count").toInt(), 4);
5656
@@ -61,13 +61,13 @@ private Q_SLOTS:
6161 }
6262
6363 /*
64− * Testa that the plugin data was loaded correctly
64+ * Testa that the plugin data was loaded correctly ( "test1" )
6565 */
66− void testDataAndOrder()
66+ void testDataAndOrderProfile1()
6767 {
6868 // Priority order. (2, 1, 4, 3)
6969 IndicatorsModel model;
70− model.load();
70+ model.load("test1");
7171
7272 // should be in order:
7373 // fake3, fake4, fake1, fake2
@@ -75,18 +75,63 @@ private Q_SLOTS:
7575 QCOMPARE(model.data(0, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake3"));
7676 QCOMPARE(model.data(0, IndicatorsModelRole::Position).toInt(), 3);
7777 QCOMPARE(model.data(0, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake3"));
78+ QCOMPARE(model.data(0, IndicatorsModelRole::IndicatorProperties).toMap()["actionsObjectPath"].toString(), QString("/com/canonical/indicator/fake3"));
79+ QCOMPARE(model.data(0, IndicatorsModelRole::IndicatorProperties).toMap()["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake3/test1"));
7880
7981 QCOMPARE(model.data(1, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake4"));
8082 QCOMPARE(model.data(1, IndicatorsModelRole::Position).toInt(), 2);
8183 QCOMPARE(model.data(1, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake4"));
84+ QCOMPARE(model.data(1, IndicatorsModelRole::IndicatorProperties).toMap()["actionsObjectPath"].toString(), QString("/com/canonical/indicator/fake4"));
85+ QCOMPARE(model.data(1, IndicatorsModelRole::IndicatorProperties).toMap()["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake4/test1"));
8286
8387 QCOMPARE(model.data(2, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake1"));
8488 QCOMPARE(model.data(2, IndicatorsModelRole::Position).toInt(), 1);
8589 QCOMPARE(model.data(2, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake1"));
90+ QCOMPARE(model.data(2, IndicatorsModelRole::IndicatorProperties).toMap()["actionsObjectPath"].toString(), QString("/com/canonical/indicator/fake1"));
91+ QCOMPARE(model.data(2, IndicatorsModelRole::IndicatorProperties).toMap()["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake1/test1"));
8692
8793 QCOMPARE(model.data(3, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake2"));
8894 QCOMPARE(model.data(3, IndicatorsModelRole::Position).toInt(), 0);
8995 QCOMPARE(model.data(3, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake2"));
96+ QCOMPARE(model.data(3, IndicatorsModelRole::IndicatorProperties).toMap()["actionsObjectPath"].toString(), QString("/com/canonical/indicator/fake2"));
97+ QCOMPARE(model.data(3, IndicatorsModelRole::IndicatorProperties).toMap()["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake2/test1"));
98+ }
99+
100+ /*
101+ * Testa that the plugin data was loaded correctly ( "test2" )
102+ */
103+ void testDataAndOrderProfile2()
104+ {
105+ // Priority order. (2, 1, 4, 3)
106+ IndicatorsModel model;
107+ model.load("test2");
108+
109+ // should be in order:
110+ // fake3, fake4, fake1, fake2
111+
112+ QCOMPARE(model.data(0, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake3"));
113+ QCOMPARE(model.data(0, IndicatorsModelRole::Position).toInt(), 3);
114+ QCOMPARE(model.data(0, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake3"));
115+ QCOMPARE(model.data(0, IndicatorsModelRole::IndicatorProperties).toMap()["actionsObjectPath"].toString(), QString("/com/canonical/indicator/fake3"));
116+ QCOMPARE(model.data(0, IndicatorsModelRole::IndicatorProperties).toMap()["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake3/test2"));
117+
118+ QCOMPARE(model.data(1, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake4"));
119+ QCOMPARE(model.data(1, IndicatorsModelRole::Position).toInt(), 2);
120+ QCOMPARE(model.data(1, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake4"));
121+ QCOMPARE(model.data(1, IndicatorsModelRole::IndicatorProperties).toMap()["actionsObjectPath"].toString(), QString("/com/canonical/indicator/fake4"));
122+ QCOMPARE(model.data(1, IndicatorsModelRole::IndicatorProperties).toMap()["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake4/test2"));
123+
124+ QCOMPARE(model.data(2, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake1"));
125+ QCOMPARE(model.data(2, IndicatorsModelRole::Position).toInt(), 1);
126+ QCOMPARE(model.data(2, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake1"));
127+ QCOMPARE(model.data(2, IndicatorsModelRole::IndicatorProperties).toMap()["actionsObjectPath"].toString(), QString("/com/canonical/indicator/fake1"));
128+ QCOMPARE(model.data(2, IndicatorsModelRole::IndicatorProperties).toMap()["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake1/test2"));
129+
130+ QCOMPARE(model.data(3, IndicatorsModelRole::Identifier).toString(), QString("indicator-fake2"));
131+ QCOMPARE(model.data(3, IndicatorsModelRole::Position).toInt(), 0);
132+ QCOMPARE(model.data(3, IndicatorsModelRole::IndicatorProperties).toMap()["busName"].toString(), QString("com.canonical.indicator.fake2"));
133+ QCOMPARE(model.data(3, IndicatorsModelRole::IndicatorProperties).toMap()["actionsObjectPath"].toString(), QString("/com/canonical/indicator/fake2"));
134+ QCOMPARE(model.data(3, IndicatorsModelRole::IndicatorProperties).toMap()["menuObjectPath"].toString(), QString("/com/canonical/indicator/fake2/test2"));
90135 }
91136};
92137
tests/qmltests/Panel/tst_IndicatorRow.qml+2−2
@@ -32,7 +32,7 @@ Item {
3232
3333 function init_test()
3434 {
35− indicatorModel.load();
35+ indicatorModel.load("test1");
3636
3737 indicatorRow.state = "initial";
3838 indicatorRow.setCurrentItemIndex(-1);
@@ -52,7 +52,7 @@ Item {
5252
5353 indicatorsModel: indicatorModel
5454
55− Component.onCompleted: indicatorModel.load()
55+ Component.onCompleted: indicatorModel.load("test1")
5656 }
5757
5858 Indicators.IndicatorsModel {
tests/qmltests/Panel/tst_Indicators.qml+1
@@ -43,6 +43,7 @@ Item {
4343 width: (shell.width > units.gu(60)) ? units.gu(40) : shell.width
4444 y: 0
4545 shown: false
46+ profile: "test1"
4647
4748 openedHeight: parent.height - click_me.height
4849 }
tests/qmltests/Panel/tst_MenuContent.qml+1−1
@@ -41,7 +41,7 @@ Item {
4141
4242 Indicators.IndicatorsModel {
4343 id: indicatorsModel
44− Component.onCompleted: load()
44+ Component.onCompleted: load("test1")
4545 }
4646
4747 MenuContent {
tests/qmltests/Panel/tst_Panel.qml+4
@@ -40,6 +40,10 @@ Item {
4040 Panel {
4141 id: panel
4242 anchors.fill: parent
43+
44+ indicators {
45+ profile: "test1"
46+ }
4347 }
4448
4549 UT.UnityTestCase {