on xenial help sign in
Make fallback also be fallback when the image is empty and not only on error
76c1fc3Albert Astals Cid
plugins/Dash/CardCreator.js+20−9
@@ -62,6 +62,7 @@ var kBackgroundLoaderCode = 'Loader {\n\
62// %2 is used as image width
62// %2 is used as image width
63// %3 is used as image height
63// %3 is used as image height
64// %4 is injected as code to artImage
64// %4 is injected as code to artImage
65+// %5 is used as image fallback
65var kArtShapeHolderCode = 'Item { \n\
66var kArtShapeHolderCode = 'Item { \n\
66 id: artShapeHolder; \n\
67 id: artShapeHolder; \n\
67 height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height; \n\
68 height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height; \n\
@@ -70,7 +71,8 @@ var kArtShapeHolderCode = 'Item { \n\
70 Loader { \n\
71 Loader { \n\
71 id: artShapeLoader; \n\
72 id: artShapeLoader; \n\
72 objectName: "artShapeLoader"; \n\
73 objectName: "artShapeLoader"; \n\
73− active: cardData && cardData["art"] || false; \n\
74+ readonly property string cardArt: cardData && cardData["art"] || %5; \n\
75+ active: cardArt != ""; \n\
74 asynchronous: root.asynchronous; \n\
76 asynchronous: root.asynchronous; \n\
75 visible: status == Loader.Ready; \n\
77 visible: status == Loader.Ready; \n\
76 sourceComponent: Item { \n\
78 sourceComponent: Item { \n\
@@ -128,7 +130,7 @@ var kArtShapeHolderCode = 'Item { \n\
128 CroppedImageMinimumSourceSize { \n\
130 CroppedImageMinimumSourceSize { \n\
129 id: artImage; \n\
131 id: artImage; \n\
130 objectName: "artImage"; \n\
132 objectName: "artImage"; \n\
131− source: cardData && cardData["art"] || ""; \n\
133+ source: artShapeLoader.cardArt; \n\
132 asynchronous: root.asynchronous; \n\
134 asynchronous: root.asynchronous; \n\
133 width: %2; \n\
135 width: %2; \n\
134 height: %3; \n\
136 height: %3; \n\
@@ -245,11 +247,12 @@ var kMascotShapeLoaderCode = 'Loader { \n\
245// %1 is used as anchors of mascotImage
247// %1 is used as anchors of mascotImage
246// %2 is used as visible of mascotImage
248// %2 is used as visible of mascotImage
247// %3 is injected as code to mascotImage
249// %3 is injected as code to mascotImage
250+// %4 is used as fallback image
248var kMascotImageCode = 'CroppedImageMinimumSourceSize { \n\
251var kMascotImageCode = 'CroppedImageMinimumSourceSize { \n\
249 id: mascotImage; \n\
252 id: mascotImage; \n\
250 objectName: "mascotImage"; \n\
253 objectName: "mascotImage"; \n\
251 anchors { %1 } \n\
254 anchors { %1 } \n\
252− source: cardData && cardData["mascot"] || ""; \n\
255+ source: cardData && cardData["mascot"] || %4; \n\
253 width: units.gu(6); \n\
256 width: units.gu(6); \n\
254 height: units.gu(5.625); \n\
257 height: units.gu(5.625); \n\
255 horizontalAlignment: Image.AlignHCenter; \n\
258 horizontalAlignment: Image.AlignHCenter; \n\
@@ -482,11 +485,15 @@ function cardString(template, components) {
482
485
483 var fallback = components["art"] && components["art"]["fallback"] || "";
486 var fallback = components["art"] && components["art"]["fallback"] || "";
484 fallback = encodeURI(fallback);
487 fallback = encodeURI(fallback);
485− var fallbackCode = "";
488+ var fallbackStatusCode = "";
489+ var fallbackURICode = '""';
486 if (fallback !== "") {
490 if (fallback !== "") {
491+ // fallbackStatusCode has %5 in it because we want to substitute it for fallbackURICode
492+ // which in kArtShapeHolderCode is %5
487− fallbackCode += 'onStatusChanged: if (status === Image.Error) source = decodeURI("%1");'.arg(fallback);
493+ fallbackStatusCode += 'onStatusChanged: if (status === Image.Error) source = %5;';
494+ fallbackURICode = 'decodeURI("%1")'.arg(fallback);
488 }
495 }
489− code += kArtShapeHolderCode.arg(artAnchors).arg(widthCode).arg(heightCode).arg(fallbackCode);
496+ code += kArtShapeHolderCode.arg(artAnchors).arg(widthCode).arg(heightCode).arg(fallbackStatusCode).arg(fallbackURICode);
490 } else {
497 } else {
491 code += 'readonly property size artShapeSize: Qt.size(-1, -1);\n'
498 code += 'readonly property size artShapeSize: Qt.size(-1, -1);\n'
492 }
499 }
@@ -580,11 +587,15 @@ function cardString(template, components) {
580 var mascotImageVisible = useMascotShape ? 'false' : 'showHeader';
587 var mascotImageVisible = useMascotShape ? 'false' : 'showHeader';
581 var fallback = components["mascot"] && components["mascot"]["fallback"] || "";
588 var fallback = components["mascot"] && components["mascot"]["fallback"] || "";
582 fallback = encodeURI(fallback);
589 fallback = encodeURI(fallback);
583− var fallbackCode = "";
590+ var fallbackStatusCode = "";
591+ var fallbackURICode = '""';
584 if (fallback !== "") {
592 if (fallback !== "") {
593+ // fallbackStatusCode has %4 in it because we want to substitute it for fallbackURICode
594+ // which in kMascotImageCode is %4
585− fallbackCode += 'onStatusChanged: if (status === Image.Error) source = decodeURI("%1");'.arg(fallback);
595+ fallbackStatusCode += 'onStatusChanged: if (status === Image.Error) source = %4;';
596+ fallbackURICode = 'decodeURI("%1")'.arg(fallback);
586 }
597 }
587− mascotCode = kMascotImageCode.arg(mascotAnchors).arg(mascotImageVisible).arg(fallbackCode);
598+ mascotCode = kMascotImageCode.arg(mascotAnchors).arg(mascotImageVisible).arg(fallbackStatusCode).arg(fallbackURICode);
588 }
599 }
589
600
590 var summaryColorWithBackground = 'backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white")';
601 var summaryColorWithBackground = 'backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white")';
qml/Dash/Previews/PreviewHeader.qml+1−1
@@ -35,7 +35,7 @@ PreviewWidget {
35 Item {
35 Item {
36 id: headerRoot
36 id: headerRoot
37 objectName: "innerPreviewHeader"
37 objectName: "innerPreviewHeader"
38− readonly property url mascot: root.widgetData["mascot"] || ""
38+ readonly property url mascot: root.widgetData["mascot"] || fallback
39 readonly property url fallback: root.widgetData["fallback"] || ""
39 readonly property url fallback: root.widgetData["fallback"] || ""
40 readonly property string title: root.widgetData["title"] || ""
40 readonly property string title: root.widgetData["title"] || ""
41 readonly property string subtitle: root.widgetData["subtitle"] || ""
41 readonly property string subtitle: root.widgetData["subtitle"] || ""
qml/Dash/Previews/PreviewImageGallery.qml+2−2
@@ -59,7 +59,7 @@ PreviewWidget {
59 top: parent.top
59 top: parent.top
60 bottom: parent.bottom
60 bottom: parent.bottom
61 }
61 }
62− source: modelData ? modelData : ""
62+ source: modelData || root.widgetData["fallback"] || ""
63 scaleTo: "height"
63 scaleTo: "height"
64 initialWidth: units.gu(13)
64 initialWidth: units.gu(13)
65 pressed: mouseArea.pressed
65 pressed: mouseArea.pressed
@@ -128,7 +128,7 @@ PreviewWidget {
128 bottom: parent.bottom
128 bottom: parent.bottom
129 }
129 }
130 width: overlay.width
130 width: overlay.width
131− source: modelData ? modelData : ""
131+ source: modelData || root.widgetData["fallback"] || ""
132 fillMode: Image.PreserveAspectFit
132 fillMode: Image.PreserveAspectFit
133 sourceSize { width: screenshot.width; height: screenshot.height }
133 sourceSize { width: screenshot.width; height: screenshot.height }
134
134
qml/Dash/Previews/PreviewZoomableImage.qml+2−2
@@ -42,7 +42,7 @@ PreviewWidget {
42 right: parent.right
42 right: parent.right
43 }
43 }
44 scaleTo: "width"
44 scaleTo: "width"
45− source: widgetData["source"]
45+ source: widgetData["source"] || widgetData["fallback"] || ""
46 asynchronous: true
46 asynchronous: true
47 useUbuntuShape: false
47 useUbuntuShape: false
48 pressed: mouseArea.pressed
48 pressed: mouseArea.pressed
@@ -86,7 +86,7 @@ PreviewWidget {
86
86
87 delegate: ZoomableImage {
87 delegate: ZoomableImage {
88 anchors.fill: parent
88 anchors.fill: parent
89− source: widgetData["source"]
89+ source: widgetData["source"] || widgetData["fallback"] || ""
90 zoomable: widgetData["zoomable"] ? widgetData["zoomable"] : false
90 zoomable: widgetData["zoomable"] ? widgetData["zoomable"] : false
91 // If modelData would change after failing to load it would not be
91 // If modelData would change after failing to load it would not be
92 // reloaded since the source binding is destroyed by the source = fallback
92 // reloaded since the source binding is destroyed by the source = fallback
tests/plugins/Dash/cardcreator/1.res+3−2
@@ -24,7 +24,8 @@ Item {
24 Loader {
24 Loader {
25 id: artShapeLoader;
25 id: artShapeLoader;
26 objectName: "artShapeLoader";
26 objectName: "artShapeLoader";
27− active: cardData && cardData["art"] || false;
27+ readonly property string cardArt: cardData && cardData["art"] || "";
28+ active: cardArt != "";
28 asynchronous: root.asynchronous;
29 asynchronous: root.asynchronous;
29 visible: status == Loader.Ready;
30 visible: status == Loader.Ready;
30 sourceComponent: Item {
31 sourceComponent: Item {
@@ -82,7 +83,7 @@ Item {
82 CroppedImageMinimumSourceSize {
83 CroppedImageMinimumSourceSize {
83 id: artImage;
84 id: artImage;
84 objectName: "artImage";
85 objectName: "artImage";
85− source: cardData && cardData["art"] || "";
86+ source: artShapeLoader.cardArt;
86 asynchronous: root.asynchronous;
87 asynchronous: root.asynchronous;
87 width: root.width;
88 width: root.width;
88 height: width / artShape.aspect;
89 height: width / artShape.aspect;
tests/plugins/Dash/cardcreator/11.res+4−3
@@ -62,7 +62,8 @@ Item {
62 Loader {
62 Loader {
63 id: artShapeLoader;
63 id: artShapeLoader;
64 objectName: "artShapeLoader";
64 objectName: "artShapeLoader";
65− active: cardData && cardData["art"] || false;
65+ readonly property string cardArt: cardData && cardData["art"] || decodeURI("%5C");
66+ active: cardArt != "";
66 asynchronous: root.asynchronous;
67 asynchronous: root.asynchronous;
67 visible: status == Loader.Ready;
68 visible: status == Loader.Ready;
68 sourceComponent: Item {
69 sourceComponent: Item {
@@ -120,7 +121,7 @@ Item {
120 CroppedImageMinimumSourceSize {
121 CroppedImageMinimumSourceSize {
121 id: artImage;
122 id: artImage;
122 objectName: "artImage";
123 objectName: "artImage";
123− source: cardData && cardData["art"] || "";
124+ source: artShapeLoader.cardArt;
124 asynchronous: root.asynchronous;
125 asynchronous: root.asynchronous;
125 width: root.width;
126 width: root.width;
126 height: width / artShape.aspect;
127 height: width / artShape.aspect;
@@ -148,7 +149,7 @@ left: parent.left;
148 id: mascotImage;
149 id: mascotImage;
149 objectName: "mascotImage";
150 objectName: "mascotImage";
150 anchors { verticalCenter: parent.verticalCenter; }
151 anchors { verticalCenter: parent.verticalCenter; }
151− source: cardData && cardData["mascot"] || "";
152+ source: cardData && cardData["mascot"] || decodeURI("%22");
152 width: units.gu(6);
153 width: units.gu(6);
153 height: units.gu(5.625);
154 height: units.gu(5.625);
154 horizontalAlignment: Image.AlignHCenter;
155 horizontalAlignment: Image.AlignHCenter;
tests/plugins/Dash/cardcreator/3.res+3−2
@@ -24,7 +24,8 @@ Item {
24 Loader {
24 Loader {
25 id: artShapeLoader;
25 id: artShapeLoader;
26 objectName: "artShapeLoader";
26 objectName: "artShapeLoader";
27− active: cardData && cardData["art"] || false;
27+ readonly property string cardArt: cardData && cardData["art"] || decodeURI("IHAVE%5C%22ESCAPED%5C%22QUOTES%5C%22");
28+ active: cardArt != "";
28 asynchronous: root.asynchronous;
29 asynchronous: root.asynchronous;
29 visible: status == Loader.Ready;
30 visible: status == Loader.Ready;
30 sourceComponent: Item {
31 sourceComponent: Item {
@@ -82,7 +83,7 @@ Item {
82 CroppedImageMinimumSourceSize {
83 CroppedImageMinimumSourceSize {
83 id: artImage;
84 id: artImage;
84 objectName: "artImage";
85 objectName: "artImage";
85− source: cardData && cardData["art"] || "";
86+ source: artShapeLoader.cardArt;
86 asynchronous: root.asynchronous;
87 asynchronous: root.asynchronous;
87 width: root.width;
88 width: root.width;
88 height: width / artShape.aspect;
89 height: width / artShape.aspect;
tests/plugins/Dash/cardcreator/5.res+3−2
@@ -24,7 +24,8 @@ Item {
24 Loader {
24 Loader {
25 id: artShapeLoader;
25 id: artShapeLoader;
26 objectName: "artShapeLoader";
26 objectName: "artShapeLoader";
27− active: cardData && cardData["art"] || false;
27+ readonly property string cardArt: cardData && cardData["art"] || "";
28+ active: cardArt != "";
28 asynchronous: root.asynchronous;
29 asynchronous: root.asynchronous;
29 visible: status == Loader.Ready;
30 visible: status == Loader.Ready;
30 sourceComponent: Item {
31 sourceComponent: Item {
@@ -82,7 +83,7 @@ Item {
82 CroppedImageMinimumSourceSize {
83 CroppedImageMinimumSourceSize {
83 id: artImage;
84 id: artImage;
84 objectName: "artImage";
85 objectName: "artImage";
85− source: cardData && cardData["art"] || "";
86+ source: artShapeLoader.cardArt;
86 asynchronous: root.asynchronous;
87 asynchronous: root.asynchronous;
87 width: root.width;
88 width: root.width;
88 height: width / artShape.aspect;
89 height: width / artShape.aspect;
tests/qmltests/Dash/Previews/tst_PreviewHeader.qml+15
@@ -54,6 +54,14 @@ Rectangle {
54 "attributes": [{"value":"text1","icon":"image://theme/ok"},{"value":"text2","icon":"image://theme/cancel"}]
54 "attributes": [{"value":"text1","icon":"image://theme/ok"},{"value":"text2","icon":"image://theme/cancel"}]
55 }
55 }
56
56
57+ property var emptyfallbackheaderjson: {
58+ "title": "THE TITLE",
59+ "subtitle": "Something catchy",
60+ "mascot": "",
61+ "fallback": "../graphics/play_button.png",
62+ "attributes": [{"value":"text1","icon":"image://theme/ok"},{"value":"text2","icon":"image://theme/cancel"}]
63+ }
64+
57 PreviewHeader {
65 PreviewHeader {
58 id: previewHeader
66 id: previewHeader
59 widgetData: headerjson
67 widgetData: headerjson
@@ -150,6 +158,13 @@ Rectangle {
150 var mascot = findChild(previewHeader, "mascotShape");
158 var mascot = findChild(previewHeader, "mascotShape");
151 tryCompare(mascot, "visible", true);
159 tryCompare(mascot, "visible", true);
152 tryCompare(mascot.source, "status", Image.Ready);
160 tryCompare(mascot.source, "status", Image.Ready);
161+
162+ previewHeader.widgetData = {};
163+ previewHeader.widgetData = emptyfallbackheaderjson;
164+ tryCompareFunction(function() { return findChild(previewHeader, "mascotShape") != null }, true);
165+ var mascot = findChild(previewHeader, "mascotShape");
166+ tryCompare(mascot, "visible", true);
167+ tryCompare(mascot.source, "status", Image.Ready);
153 }
168 }
154 }
169 }
155}
170}
tests/qmltests/Dash/Previews/tst_PreviewImageGallery.qml+19
@@ -48,6 +48,16 @@ Rectangle {
48 , "fallback": "../../../tests/graphics/clock@18.png"
48 , "fallback": "../../../tests/graphics/clock@18.png"
49 }
49 }
50
50
51+ property var sourcesModelEmptyWithFallback: {
52+ "sources": [
53+ "../../graphics/phone_background.jpg",
54+ "../../graphics/tablet_background.jpg",
55+ "../../../tests/graphics/clock@18.png",
56+ ""
57+ ]
58+ , "fallback": "../../../tests/graphics/clock@18.png"
59+ }
60+
51 PreviewImageGallery {
61 PreviewImageGallery {
52 id: imageGallery
62 id: imageGallery
53 width: parent.width
63 width: parent.width
@@ -123,5 +133,14 @@ Rectangle {
123 image3 = findChild(imageGallery, "previewImage3");
133 image3 = findChild(imageGallery, "previewImage3");
124 tryCompare(image3, "state", "ready");
134 tryCompare(image3, "state", "ready");
125 }
135 }
136+
137+ function test_empty_fallback() {
138+ var image3 = findChild(imageGallery, "previewImage3");
139+ tryCompare(image3, "state", "error");
140+ imageGallery.widgetData = sourcesModel0;
141+ imageGallery.widgetData = sourcesModelEmptyWithFallback;
142+ image3 = findChild(imageGallery, "previewImage3");
143+ tryCompare(image3, "state", "ready");
144+ }
126 }
145 }
127}
146}
tests/qmltests/Dash/Previews/tst_PreviewZoomableImage.qml+12
@@ -39,6 +39,11 @@ Rectangle {
39 "fallback": "../../graphics/phone_background.jpg"
39 "fallback": "../../graphics/phone_background.jpg"
40 }
40 }
41
41
42+ property var widgetData3: {
43+ "source": "",
44+ "fallback": "../../graphics/phone_background.jpg"
45+ }
46+
42 Loader {
47 Loader {
43 id: loader
48 id: loader
44 width: parent.width
49 width: parent.width
@@ -100,5 +105,12 @@ Rectangle {
100 waitForRendering(lazyImage);
105 waitForRendering(lazyImage);
101 tryCompare(lazyImage, "state", "ready");
106 tryCompare(lazyImage, "state", "ready");
102 }
107 }
108+
109+ function test_emptyfallback() {
110+ zoomableImage.widgetData = widgetData3;
111+ waitForRendering(zoomableImage);
112+ waitForRendering(lazyImage);
113+ tryCompare(lazyImage, "state", "ready");
114+ }
103 }
115 }
104}
116}
tests/qmltests/Dash/tst_Card.qml+18
@@ -476,6 +476,15 @@ Rectangle {
476 card.cardDataChanged();
476 card.cardDataChanged();
477 waitForRendering(card);
477 waitForRendering(card);
478 tryCompare(art, "visible", true);
478 tryCompare(art, "visible", true);
479+ compare(artImage.source, Qt.resolvedUrl("artwork/emblem.png"));
480+
481+ cardTool.components["art"]["fallback"] = Qt.resolvedUrl("artwork/checkers.png");
482+ cardTool.componentsChanged();
483+ card.cardData["art"] = "";
484+ card.cardDataChanged();
485+ waitForRendering(card);
486+ tryCompare(art, "visible", true);
487+ compare(artImage.source, Qt.resolvedUrl("artwork/checkers.png"));
479
488
480 card.cardData["mascot"] = "somethingbroken2";
489 card.cardData["mascot"] = "somethingbroken2";
481 card.cardDataChanged();
490 card.cardDataChanged();
@@ -487,6 +496,15 @@ Rectangle {
487 card.cardDataChanged();
496 card.cardDataChanged();
488 waitForRendering(card);
497 waitForRendering(card);
489 tryCompare(mascotImage, "status", Image.Ready);
498 tryCompare(mascotImage, "status", Image.Ready);
499+ compare(mascotImage.source, Qt.resolvedUrl("artwork/emblem.png"));
500+
501+ cardTool.components["mascot"] = {"fallback": Qt.resolvedUrl("artwork/checkers.png")};
502+ cardTool.componentsChanged();
503+ card.cardData["mascot"] = "";
504+ card.cardDataChanged();
505+ waitForRendering(card);
506+ tryCompare(mascotImage, "status", Image.Ready);
507+ compare(mascotImage.source, Qt.resolvedUrl("artwork/checkers.png"));
490 }
508 }
491
509
492 function test_font_weights_data() {
510 function test_font_weights_data() {