on xenial help sign in
Added utilization of new LauncherModel::setProgress() API, corresponding tests and visual tweaks to a launcher-item's progress-overlay.
commitf3ce9db9ad5d595a9145c8e6e59ac480aac19940 authorMirco Müller <mirco.mueller@ubuntu.com> dateFri 19 Jun 2015, 15:11 (11 years ago) parentfa49897
14 files changed+94−25
plugins/Greeter/Unity/Launcher/launchermodelas.cpp+10 plugins/Greeter/Unity/Launcher/launchermodelas.h+1 plugins/Unity/Launcher/dbusinterface.cpp+9 plugins/Unity/Launcher/dbusinterface.h+1 plugins/Unity/Launcher/launchermodel.cpp+10 plugins/Unity/Launcher/launchermodel.h+1 qml/Launcher/LauncherDelegate.qml+14−15 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/qmltests/Launcher/tst_Launcher.qml+37
plugins/Greeter/Unity/Launcher/launchermodelas.cpp+10
@@ -123,6 +123,16 @@ void LauncherModel::quickListActionInvoked(const QString &appId, int actionIndex
123123 }
124124}
125125
126+void LauncherModel::setProgress(const QString &appId, int progress)
127+{
128+ int index = findApplication(appId);
129+ if (index >= 0) {
130+ m_list.at(index)->setProgress(progress);
131+ QModelIndex modelIndex = this->index(index);
132+ Q_EMIT dataChanged(modelIndex, modelIndex);
133+ }
134+}
135+
126136void LauncherModel::setUser(const QString &username)
127137{
128138 if (m_user != username) {
plugins/Greeter/Unity/Launcher/launchermodelas.h+1
@@ -45,6 +45,7 @@ public:
4545 Q_INVOKABLE void move(int oldIndex, int newIndex) override;
4646 Q_INVOKABLE void pin(const QString &appId, int index = -1) override;
4747 Q_INVOKABLE void quickListActionInvoked(const QString &appId, int actionIndex) override;
48+ Q_INVOKABLE void setProgress(const QString &appId, int progress) override;
4849 Q_INVOKABLE void setUser(const QString &username) override;
4950 Q_INVOKABLE QString getUrlForAppId(const QString &appId) const;
5051
plugins/Unity/Launcher/dbusinterface.cpp+9
@@ -168,6 +168,8 @@ bool DBusInterface::handleMessage(const QDBusMessage& message, const QDBusConnec
168168 retval.append(QVariant::fromValue(QDBusVariant(item->count())));
169169 } else if (message.arguments()[1].toString() == "countVisible") {
170170 retval.append(QVariant::fromValue(QDBusVariant(item->countVisible())));
171+ } else if (message.arguments()[1].toString() == "progress") {
172+ retval.append(QVariant::fromValue(QDBusVariant(item->progress())));
171173 }
172174 } else if (message.member() == "Set") {
173175 if (message.arguments()[1].toString() == "count") {
@@ -182,12 +184,19 @@ bool DBusInterface::handleMessage(const QDBusMessage& message, const QDBusConnec
182184 Q_EMIT countVisibleChanged(appid, newVisible);
183185 notifyPropertyChanged("com.canonical.Unity.Launcher.Item", encodeAppId(appid), "countVisible", newVisible);
184186 }
187+ } else if (message.arguments()[1].toString() == "progress") {
188+ int newProgress = message.arguments()[2].value<QDBusVariant>().variant().toInt();
189+ if (!item || newProgress != item->progress()) {
190+ Q_EMIT progressChanged(appid, newProgress);
191+ notifyPropertyChanged("com.canonical.Unity.Launcher.Item", encodeAppId(appid), "progress", QVariant(newProgress));
192+ }
185193 }
186194 } else if (message.member() == "GetAll") {
187195 if (item) {
188196 QVariantMap all;
189197 all.insert("count", item->count());
190198 all.insert("countVisible", item->countVisible());
199+ all.insert("progress", item->progress());
191200 retval.append(all);
192201 }
193202 } 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
4142private:
plugins/Unity/Launcher/launchermodel.cpp+10
@@ -199,6 +199,16 @@ void LauncherModel::quickListActionInvoked(const QString &appId, int actionIndex
199199 }
200200}
201201
202+void LauncherModel::setProgress(const QString &appId, int progress)
203+{
204+ int index = findApplication(appId);
205+ if (index >= 0) {
206+ m_list.at(index)->setProgress(progress);
207+ QModelIndex modelIndex = this->index(index);
208+ Q_EMIT dataChanged(modelIndex, modelIndex);
209+ }
210+}
211+
202212void LauncherModel::setUser(const QString &username)
203213{
204214 Q_UNUSED(username)
plugins/Unity/Launcher/launchermodel.h+1
@@ -49,6 +49,7 @@ public:
4949 Q_INVOKABLE void move(int oldIndex, int newIndex) override;
5050 Q_INVOKABLE void pin(const QString &appId, int index = -1) override;
5151 Q_INVOKABLE void quickListActionInvoked(const QString &appId, int actionIndex) override;
52+ Q_INVOKABLE void setProgress(const QString &appId, int progress) override;
5253 Q_INVOKABLE void setUser(const QString &username) override;
5354 Q_INVOKABLE QString getUrlForAppId(const QString &appId) const;
5455
qml/Launcher/LauncherDelegate.qml+14−15
@@ -15,7 +15,7 @@
1515 */
1616
1717import QtQuick 2.0
18−import Ubuntu.Components 0.1
18+import Ubuntu.Components 1.1
1919
2020Item {
2121 id: root
@@ -30,6 +30,7 @@ Item {
3030
3131 readonly property int effectiveHeight: Math.cos(angle * Math.PI / 180) * itemHeight
3232 readonly property real foldedHeight: Math.cos(maxAngle * Math.PI / 180) * itemHeight
33+ readonly property bool progressVisible: progressOverlay.visible
3334
3435 property int itemWidth
3536 property int itemHeight
@@ -100,23 +101,19 @@ Item {
100101 }
101102 }
102103
103− BorderImage {
104+ UbuntuShape {
104105 id: progressOverlay
105− objectName: "progressOverlay"
106106 anchors {
107107 left: iconItem.left
108108 right: iconItem.right
109− bottom: iconItem.bottom
110− leftMargin: units.gu(1)
111− rightMargin: units.gu(1)
112− bottomMargin: units.gu(1)
109+ verticalCenter: parent.verticalCenter
110+ leftMargin: units.gu(1.5)
111+ rightMargin: units.gu(1.5)
113112 }
114− height: units.gu(1.5)
113+ height: units.gu(1)
115114 visible: root.progress > -1
116− source: "graphics/progressbar-trough.sci"
117−
118− // For fill calculation we need to remove the 2 units of border defined in .sci file
119− property int adjustedWidth: width - units.gu(2)
115+ color: UbuntuColors.darkGrey
116+ borderSource: "none"
120117
121118 Item {
122119 anchors {
@@ -124,20 +121,22 @@ Item {
124121 top: parent.top
125122 bottom: parent.bottom
126123 }
127− width: Math.min(100, root.progress) / 100 * parent.adjustedWidth + units.gu(1)
124+ width: Math.min(100, root.progress) / 100 * parent.width + units.gu(1)
128125 clip: true
129126
130− BorderImage {
127+ UbuntuShape {
131128 anchors {
132129 left: parent.left
133130 top: parent.top
134131 bottom: parent.bottom
135132 }
133+ color: "white"
134+ borderSource: "none"
136135 width: progressOverlay.width
137− source: "graphics/progressbar-fill.sci"
138136 }
139137 }
140138 }
139+
141140 Image {
142141 objectName: "focusedHighlight"
143142 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
@@ -195,6 +195,16 @@ int MockLauncherModel::findApp(const QString &appId)
195195 return -1;
196196}
197197
198+void MockLauncherModel::setProgress(const QString &appId, int progress)
199+{
200+ int index = findApp(appId);
201+ if (index >= 0) {
202+ m_list.at(index)->setProgress(progress);
203+ QModelIndex modelIndex = this->index(index);
204+ Q_EMIT dataChanged(modelIndex, modelIndex);
205+ }
206+}
207+
198208void MockLauncherModel::setUser(const QString &username)
199209{
200210 Q_UNUSED(username)
tests/mocks/Unity/Launcher/MockLauncherModel.h+1
@@ -43,6 +43,7 @@ public:
4343 Q_INVOKABLE void pin(const QString &appId, int index = -1) override;
4444 Q_INVOKABLE void requestRemove(const QString &appId) override;
4545 Q_INVOKABLE void quickListActionInvoked(const QString &appId, int actionIndex) override;
46+ Q_INVOKABLE void setProgress(const QString &appId, int progress) override;
4647 Q_INVOKABLE void setUser(const QString &username) override;
4748 Q_INVOKABLE QString getUrlForAppId(const QString &appId) const;
4849
tests/qmltests/Launcher/tst_Launcher.qml+37
@@ -93,6 +93,32 @@ Item {
9393 onClicked: launcherLoader.item.inverted = !launcherLoader.item.inverted
9494 Layout.fillWidth: true
9595 }
96+
97+ Row {
98+ spacing: units.gu(1)
99+
100+ Button {
101+ text: "35% bar"
102+ onClicked: LauncherModel.setProgress(LauncherModel.get(parseInt(appIdEntry.displayText)).appId, 35)
103+ Layout.fillWidth: true
104+ }
105+
106+ TextArea {
107+ id: appIdEntry
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(appIdEntry.displayText)).appId, -1)
119+ Layout.fillWidth: true
120+ }
121+ }
96122 }
97123
98124 SignalSpy {
@@ -636,5 +662,16 @@ Item {
636662 tryCompare(launcher, "state", "", 1000, "Launcher didn't hide after moving mouse away from it");
637663 waitUntilLauncherDisappears();
638664 }
665+
666+ function test_progressChangeViaModel() {
667+ dragLauncherIntoView();
668+ var item = findChild(launcher, "launcherDelegate0")
669+ verify(item != undefined)
670+ LauncherModel.setProgress(LauncherModel.get(0).appId, -1)
671+ tryCompare(item, "progressVisible", false, 1000, "progress-overlay of item #1 should not be visible")
672+ LauncherModel.setProgress(LauncherModel.get(0).appId, 20)
673+ tryCompare(item, "progressVisible", true, 1000, "progress-overlay of item #1 should not be invisible")
674+ LauncherModel.setProgress(LauncherModel.get(0).appId, 0)
675+ }
639676 }
640677}