on xenial help sign in
Added corresponding tests and visual tweaks to a launcher-item's progress-overlay.

Approved by: Michael Zanetti

commit9f578c0b0a4518af347a71539bf8a93076e46010 authorMirco Müller <mirco.mueller@ubuntu.com> dateWed 29 Jul 2015, 12:37 (11 years ago) parentda0fcd1faf26a9
19 files changed+125−43
plugins/Greeter/Unity/Launcher/launchermodelas.cpp+22−12 plugins/Unity/Launcher/asadapter.cpp+1 plugins/Unity/Launcher/dbusinterface.cpp+16−4 plugins/Unity/Launcher/dbusinterface.h+1 plugins/Unity/Launcher/launchermodel.cpp+1 qml/Launcher/LauncherDelegate.qml+14−14 qml/Launcher/graphics/progressbar-fill@30.png qml/Launcher/graphics/progressbar-fill@30.sci−5 qml/Launcher/graphics/progressbar-trough@30.png qml/Launcher/graphics/progressbar-trough@30.sci−5 tests/mocks/Unity/Launcher/MockLauncherModel.cpp+10 tests/mocks/Unity/Launcher/MockLauncherModel.h+1 tests/plugins/Greeter/Unity/Launcher/launchermodelastest.cpp+3 tests/qmltests/Launcher/tst_Launcher.qml+40−3 tests/scripts/README+4 tests/scripts/get-progress.sh+3 tests/scripts/set-count-visible.sh+3 tests/scripts/set-count.sh+3 tests/scripts/set-progress.sh+3
plugins/Greeter/Unity/Launcher/launchermodelas.cpp+22−12
@@ -207,16 +207,24 @@ void LauncherModel::refresh()
207207 Q_FOREACH (LauncherItem* item, m_list) {
208208 bool found = false;
209209 Q_FOREACH(const QVariant &asItem, items) {
210− if (asItem.toMap().value("id").toString() == item->appId()) {
210+ QVariantMap cachedMap = asItem.toMap();
211+ if (cachedMap.value("id").toString() == item->appId()) {
211212 // Only keep and update it if we either show unpinned or it is pinned
212− if (!m_onlyPinned || asItem.toMap().value("pinned").toBool()) {
213+ if (!m_onlyPinned || cachedMap.value("pinned").toBool()) {
213214 found = true;
214− item->setName(asItem.toMap().value("name").toString());
215− item->setIcon(asItem.toMap().value("icon").toString());
216− item->setCount(asItem.toMap().value("count").toInt());
217− item->setCountVisible(asItem.toMap().value("countVisible").toBool());
215+ item->setName(cachedMap.value("name").toString());
216+ item->setIcon(cachedMap.value("icon").toString());
217+ item->setCount(cachedMap.value("count").toInt());
218+ item->setCountVisible(cachedMap.value("countVisible").toBool());
219+ item->setProgress(cachedMap.value("progress").toInt());
218220 int idx = m_list.indexOf(item);
219− Q_EMIT dataChanged(index(idx), index(idx), QVector<int>() << RoleName << RoleIcon);
221+ Q_EMIT dataChanged(index(idx),
222+ index(idx),
223+ {RoleName,
224+ RoleIcon,
225+ RoleCount,
226+ RoleCountVisible,
227+ RoleProgress});
220228 }
221229 break;
222230 }
@@ -254,14 +262,16 @@ void LauncherModel::refresh()
254262 }
255263
256264 if (itemIndex == -1) {
265+ QVariantMap chachedMap = entry.toMap();
257266 // Need to add it. Just add it into the addedIndex to keep same ordering as the list in AS.
258− LauncherItem *item = new LauncherItem(entry.toMap().value("id").toString(),
259− entry.toMap().value("name").toString(),
260− entry.toMap().value("icon").toString(),
267+ LauncherItem *item = new LauncherItem(chachedMap.value("id").toString(),
268+ chachedMap.value("name").toString(),
269+ chachedMap.value("icon").toString(),
261270 this);
262271 item->setPinned(true);
263− item->setCount(entry.toMap().value("count").toInt());
264− item->setCountVisible(entry.toMap().value("countVisible").toBool());
272+ item->setCount(chachedMap.value("count").toInt());
273+ item->setCountVisible(chachedMap.value("countVisible").toBool());
274+ item->setProgress(chachedMap.value("progress").toInt());
265275 beginInsertRows(QModelIndex(), newPosition, newPosition);
266276 m_list.insert(newPosition, item);
267277 endInsertRows();
plugins/Unity/Launcher/asadapter.cpp+1
@@ -56,5 +56,6 @@ QVariantMap ASAdapter::itemToVariant(LauncherItem *item) const
5656 details.insert("count", item->count());
5757 details.insert("countVisible", item->countVisible());
5858 details.insert("pinned", item->pinned());
59+ details.insert("progress", item->progress());
5960 return details;
6061}
plugins/Unity/Launcher/dbusinterface.cpp+16−4
@@ -62,6 +62,7 @@ QString DBusInterface::introspect(const QString &path) const
6262 "<interface name=\"com.canonical.Unity.Launcher.Item\">"
6363 "<property name=\"count\" type=\"i\" access=\"readwrite\" />"
6464 "<property name=\"countVisible\" type=\"b\" access=\"readwrite\" />"
65+ "<property name=\"progress\" type=\"i\" access=\"readwrite\" />"
6566 "<method name=\"Alert\" />"
6667 "</interface>";
6768 return nodeiface;
@@ -175,33 +176,44 @@ bool DBusInterface::handleMessage(const QDBusMessage& message, const QDBusConnec
175176
176177 QVariantList retval;
177178 if (message.member() == "Get") {
179+ QString cachedString = message.arguments()[1].toString();
178180 if (!item) {
179181 return false;
180182 }
181− if (message.arguments()[1].toString() == "count") {
183+ if (cachedString == "count") {
182184 retval.append(QVariant::fromValue(QDBusVariant(item->count())));
183− } else if (message.arguments()[1].toString() == "countVisible") {
185+ } else if (cachedString == "countVisible") {
184186 retval.append(QVariant::fromValue(QDBusVariant(item->countVisible())));
187+ } else if (cachedString == "progress") {
188+ retval.append(QVariant::fromValue(QDBusVariant(item->progress())));
185189 }
186190 } else if (message.member() == "Set") {
187− if (message.arguments()[1].toString() == "count") {
191+ QString cachedString = message.arguments()[1].toString();
192+ if (cachedString == "count") {
188193 int newCount = message.arguments()[2].value<QDBusVariant>().variant().toInt();
189194 if (!item || newCount != item->count()) {
190195 Q_EMIT countChanged(appid, newCount);
191196 notifyPropertyChanged("com.canonical.Unity.Launcher.Item", encodeAppId(appid), "count", QVariant(newCount));
192197 }
193− } else if (message.arguments()[1].toString() == "countVisible") {
198+ } else if (cachedString == "countVisible") {
194199 bool newVisible = message.arguments()[2].value<QDBusVariant>().variant().toBool();
195200 if (!item || newVisible != item->countVisible()) {
196201 Q_EMIT countVisibleChanged(appid, newVisible);
197202 notifyPropertyChanged("com.canonical.Unity.Launcher.Item", encodeAppId(appid), "countVisible", newVisible);
198203 }
204+ } else if (cachedString == "progress") {
205+ int newProgress = message.arguments()[2].value<QDBusVariant>().variant().toInt();
206+ if (!item || newProgress != item->progress()) {
207+ Q_EMIT progressChanged(appid, newProgress);
208+ notifyPropertyChanged("com.canonical.Unity.Launcher.Item", encodeAppId(appid), "progress", QVariant(newProgress));
209+ }
199210 }
200211 } else if (message.member() == "GetAll") {
201212 if (item) {
202213 QVariantMap all;
203214 all.insert("count", item->count());
204215 all.insert("countVisible", item->countVisible());
216+ all.insert("progress", item->progress());
205217 retval.append(all);
206218 }
207219 } else {
plugins/Unity/Launcher/dbusinterface.h+1
@@ -36,6 +36,7 @@ public:
3636Q_SIGNALS:
3737 void countChanged(const QString &appId, int count);
3838 void countVisibleChanged(const QString &appId, bool countVisible);
39+ void progressChanged(const QString &appId, int progress);
3940 void refreshCalled();
4041 void alertCalled(const QString &appId);
4142
plugins/Unity/Launcher/launchermodel.cpp+1
@@ -40,6 +40,7 @@ LauncherModel::LauncherModel(QObject *parent):
4040{
4141 connect(m_dbusIface, &DBusInterface::countChanged, this, &LauncherModel::countChanged);
4242 connect(m_dbusIface, &DBusInterface::countVisibleChanged, this, &LauncherModel::countVisibleChanged);
43+ connect(m_dbusIface, &DBusInterface::progressChanged, this, &LauncherModel::progressChanged);
4344 connect(m_dbusIface, &DBusInterface::refreshCalled, this, &LauncherModel::refresh);
4445 connect(m_dbusIface, &DBusInterface::alertCalled, this, &LauncherModel::alert);
4546
qml/Launcher/LauncherDelegate.qml+14−14
@@ -153,7 +153,7 @@ Item {
153153 objectName: "countEmblem"
154154 anchors {
155155 right: parent.right
156− top: parent.top
156+ bottom: parent.bottom
157157 margins: units.dp(3)
158158 }
159159 width: Math.min(root.itemWidth, Math.max(units.gu(2), countLabel.implicitWidth + units.gu(1)))
@@ -178,23 +178,21 @@ Item {
178178 }
179179 }
180180
181− BorderImage {
181+ UbuntuShape {
182182 id: progressOverlay
183183 objectName: "progressOverlay"
184+
184185 anchors {
185186 left: iconItem.left
186187 right: iconItem.right
187− bottom: iconItem.bottom
188− leftMargin: units.gu(1)
189− rightMargin: units.gu(1)
190− bottomMargin: units.gu(1)
188+ verticalCenter: parent.verticalCenter
189+ leftMargin: units.gu(1.5)
190+ rightMargin: units.gu(1.5)
191191 }
192− height: units.gu(1.5)
192+ height: units.gu(1)
193193 visible: root.progress > -1
194− source: "graphics/progressbar-trough.sci"
195−
196− // For fill calculation we need to remove the 2 units of border defined in .sci file
197− property int adjustedWidth: width - units.gu(2)
194+ color: UbuntuColors.darkGrey
195+ borderSource: "none"
198196
199197 Item {
200198 anchors {
@@ -202,20 +200,22 @@ Item {
202200 top: parent.top
203201 bottom: parent.bottom
204202 }
205− width: Math.min(100, root.progress) / 100 * parent.adjustedWidth + units.gu(1)
203+ width: Math.min(100, root.progress) / 100 * parent.width
206204 clip: true
207205
208− BorderImage {
206+ UbuntuShape {
209207 anchors {
210208 left: parent.left
211209 top: parent.top
212210 bottom: parent.bottom
213211 }
212+ color: "white"
213+ borderSource: "none"
214214 width: progressOverlay.width
215− source: "graphics/progressbar-fill.sci"
216215 }
217216 }
218217 }
218+
219219 Image {
220220 objectName: "focusedHighlight"
221221 anchors {
qml/Launcher/graphics/progressbar-fill@30.pngdeleted

Binary file not shown.

qml/Launcher/graphics/progressbar-fill@30.scideleted−5
@@ -1,5 +0,0 @@
1−border.left: 36
2−border.top: 16
3−border.bottom: 28
4−border.right: 36
5−source: progressbar-fill@30.png
qml/Launcher/graphics/progressbar-trough@30.pngdeleted

Binary file not shown.

qml/Launcher/graphics/progressbar-trough@30.scideleted−5
@@ -1,5 +0,0 @@
1−border.left: 36
2−border.top: 16
3−border.bottom: 26
4−border.right: 36
5−source: progressbar-trough@30.png
tests/mocks/Unity/Launcher/MockLauncherModel.cpp+10
@@ -215,6 +215,16 @@ int MockLauncherModel::findApp(const QString &appId)
215215 return -1;
216216}
217217
218+void MockLauncherModel::setProgress(const QString &appId, int progress)
219+{
220+ int index = findApp(appId);
221+ if (index >= 0) {
222+ m_list.at(index)->setProgress(progress);
223+ QModelIndex modelIndex = this->index(index);
224+ Q_EMIT dataChanged(modelIndex, modelIndex, QVector<int>() << RoleProgress);
225+ }
226+}
227+
218228void MockLauncherModel::setUser(const QString &username)
219229{
220230 Q_UNUSED(username)
tests/mocks/Unity/Launcher/MockLauncherModel.h+1
@@ -55,6 +55,7 @@ public:
5555
5656 // For testing
5757 Q_INVOKABLE void emitHint();
58+ Q_INVOKABLE void setProgress(const QString &appId, int progress);
5859 Q_INVOKABLE void setCount(const QString &appId, int count);
5960 Q_INVOKABLE void setCountVisible(const QString &appId, bool countVisible);
6061
tests/plugins/Greeter/Unity/Launcher/launchermodelastest.cpp+3
@@ -43,6 +43,7 @@ private Q_SLOTS:
4343 item.insert("name", "Item 1");
4444 item.insert("icon", "fake.svg");
4545 item.insert("count", 0);
46+ item.insert("progress", 0);
4647 item.insert("countVisible", false);
4748 item.insert("pinned", true);
4849 list.append(item);
@@ -67,6 +68,7 @@ private Q_SLOTS:
6768 inSync &= model->get(i)->name() == list.at(i).value("name").toString();
6869 inSync &= model->get(i)->icon() == list.at(i).value("icon").toString();
6970 inSync &= model->get(i)->count() == list.at(i).value("count").toInt();
71+ inSync &= model->get(i)->progress() == list.at(i).value("progress").toInt();
7072 inSync &= model->get(i)->countVisible() == list.at(i).value("countVisible").toBool();
7173 }
7274 return inSync;
@@ -111,6 +113,7 @@ private Q_SLOTS:
111113 newEntry.insert("name", "New app");
112114 newEntry.insert("icon", "some-icon.svg");
113115 newEntry.insert("count", 0);
116+ newEntry.insert("progress", 42);
114117 newEntry.insert("countVisible", false);
115118 newEntry.insert("pinned", true);
116119 newList.append(newEntry);
tests/qmltests/Launcher/tst_Launcher.qml+40−3
@@ -94,16 +94,42 @@ Item {
9494 Layout.fillWidth: true
9595 }
9696
97+ Row {
98+ spacing: units.gu(1)
99+
100+ Button {
101+ text: "35% bar"
102+ onClicked: LauncherModel.setProgress(LauncherModel.get(parseInt(appIdEntryBar.displayText)).appId, 35)
103+ Layout.fillWidth: true
104+ }
105+
106+ TextArea {
107+ id: appIdEntryBar
108+ anchors.verticalCenter: parent.verticalCenter
109+ width: units.gu(4)
110+ height: units.gu(4)
111+ autoSize: true
112+ text: "2"
113+ maximumLineCount: 1
114+ }
115+
116+ Button {
117+ text: "no bar"
118+ onClicked: LauncherModel.setProgress(LauncherModel.get(parseInt(appIdEntryBar.displayText)).appId, -1)
119+ Layout.fillWidth: true
120+ }
121+ }
122+
97123 Row {
98124 spacing: units.gu(1)
99125
100126 Button {
101127 text: "set alert"
102− onClicked: LauncherModel.setAlerting(LauncherModel.get(parseInt(appIdEntry.displayText)).appId, true)
128+ onClicked: LauncherModel.setAlerting(LauncherModel.get(parseInt(appIdEntryAlert.displayText)).appId, true)
103129 }
104130
105131 TextArea {
106− id: appIdEntry
132+ id: appIdEntryAlert
107133 anchors.verticalCenter: parent.verticalCenter
108134 width: units.gu(5)
109135 height: units.gu(4)
@@ -115,7 +141,7 @@ Item {
115141
116142 Button {
117143 text: "unset alert"
118− onClicked: LauncherModel.setAlerting(LauncherModel.get(parseInt(appIdEntry.displayText)).appId, false)
144+ onClicked: LauncherModel.setAlerting(LauncherModel.get(parseInt(appIdEntryAlert.displayText)).appId, false)
119145 }
120146 }
121147 }
@@ -672,6 +698,17 @@ Item {
672698 waitUntilLauncherDisappears();
673699 }
674700
701+ function test_progressChangeViaModel() {
702+ dragLauncherIntoView();
703+ var item = findChild(launcher, "launcherDelegate0")
704+ verify(item != undefined)
705+ LauncherModel.setProgress(LauncherModel.get(0).appId, -1)
706+ compare(findChild(item, "progressOverlay").visible, false)
707+ LauncherModel.setProgress(LauncherModel.get(0).appId, 20)
708+ compare(findChild(item, "progressOverlay").visible, true)
709+ LauncherModel.setProgress(LauncherModel.get(0).appId, 0)
710+ }
711+
675712 function test_alertPeekingIcon() {
676713 var listView = findChild(launcher, "launcherListView")
677714 verify(listView != undefined)
tests/scripts/README+4
@@ -3,3 +3,7 @@ This directory holds a few handy shell-scripts to simplify runtime-testing of DB
33launcher-icon related:
44 * list-launcher-icons.sh - get all icons of unity8-launcher
55 * alert-launcher-icon.sh - trigger alert/wiggle of unfocused launcher-icon
6+ * get-progress.sh - get progress-value of a launcher-icon
7+ * set-progress.sh - set progress-value of a launcher-icon
8+ * set-count.sh - set the count of a launcher-icon
9+ * set-count-visible.sh - set the count-visible flag of a launcher-icon
tests/scripts/get-progress.shnew file+3
@@ -0,0 +1,3 @@
1+#!/bin/sh
2+
3+qdbus com.canonical.Unity.Launcher /com/canonical/Unity/Launcher/$1 org.freedesktop.DBus.Properties.Get com.canonical.Unity.Launcher.Item progress
tests/scripts/set-count-visible.shnew file+3
@@ -0,0 +1,3 @@
1+#!/bin/sh
2+
3+qdbus com.canonical.Unity.Launcher /com/canonical/Unity/Launcher/$1 org.freedesktop.DBus.Properties.Set com.canonical.Unity.Launcher.Item countVisible $2
tests/scripts/set-count.shnew file+3
@@ -0,0 +1,3 @@
1+#!/bin/sh
2+
3+qdbus com.canonical.Unity.Launcher /com/canonical/Unity/Launcher/$1 org.freedesktop.DBus.Properties.Set com.canonical.Unity.Launcher.Item count $2
tests/scripts/set-progress.shnew file+3
@@ -0,0 +1,3 @@
1+#!/bin/sh
2+
3+qdbus com.canonical.Unity.Launcher /com/canonical/Unity/Launcher/$1 org.freedesktop.DBus.Properties.Set com.canonical.Unity.Launcher.Item progress $2