on xenial help sign in
Merge fallback for empty
commitdc0885ddeabf410862023b7ff70e22bea18200c9 authorAlbert Astals Cid <albert.astals@canonical.com> dateThu 11 Feb 2016, 14:13 (11 years ago) parentcda93c66ab3749
12 files changed+107−28
plugins/Dash/CardCreator.js+25−14 qml/Dash/Previews/PreviewHeader.qml+1−1 qml/Dash/Previews/PreviewImageGallery.qml+2−2 qml/Dash/Previews/PreviewZoomableImage.qml+2−2 tests/plugins/Dash/cardcreator/1.res+3−2 tests/plugins/Dash/cardcreator/11.res+4−3 tests/plugins/Dash/cardcreator/3.res+3−2 tests/plugins/Dash/cardcreator/5.res+3−2 tests/qmltests/Dash/Previews/tst_PreviewHeader.qml+15 tests/qmltests/Dash/Previews/tst_PreviewImageGallery.qml+19 tests/qmltests/Dash/Previews/tst_PreviewZoomableImage.qml+12 tests/qmltests/Dash/tst_Card.qml+18
plugins/Dash/CardCreator.js+25−14
@@ -61,9 +61,10 @@ var kBackgroundLoaderCode = 'Loader {\n\
6161// %1 is used as anchors of artShapeHolder
6262// %2 is used as image width
6363// %3 is used as image height
64−// %4 is used as aspect ratio fallback
65−// %5 is used for artShapeSource.hideSource and inner Loader visible
64+// %4 is used for artShapeSource.hideSource and inner Loader visible
65+// %5 is used as aspect ratio fallback
6666// %6 is injected as code to artImage
67+// %7 is used as image fallback
6768var kArtShapeHolderCode = 'Item { \n\
6869 id: artShapeHolder; \n\
6970 height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height; \n\
@@ -72,7 +73,8 @@ var kArtShapeHolderCode = 'Item { \n\
7273 Loader { \n\
7374 id: artShapeLoader; \n\
7475 objectName: "artShapeLoader"; \n\
75− active: cardData && cardData["art"] || false; \n\
76+ readonly property string cardArt: cardData && cardData["art"] || %7; \n\
77+ active: cardArt != ""; \n\
7678 asynchronous: root.asynchronous; \n\
7779 visible: status == Loader.Ready; \n\
7880 sourceComponent: Item { \n\
@@ -86,11 +88,11 @@ var kArtShapeHolderCode = 'Item { \n\
8688 anchors.centerIn: parent; \n\
8789 width: 1; \n\
8890 height: 1; \n\
89− hideSource: %5; \n\
91+ hideSource: %4; \n\
9092 } \n\
9193 Loader { \n\
9294 anchors.fill: parent; \n\
93− visible: %5; \n\
95+ visible: %4; \n\
9496 sourceComponent: root.artShapeStyle === "icon" ? artShapeIconComponent : artShapeShapeComponent; \n\
9597 Component { \n\
9698 id: artShapeShapeComponent; \n\
@@ -114,7 +116,7 @@ var kArtShapeHolderCode = 'Item { \n\
114116 } \n\
115117 } \n\
116118 readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1; \n\
117− readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : %4; \n\
119+ readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : %5; \n\
118120 Component.onCompleted: { updateWidthHeightBindings(); } \n\
119121 Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); } \n\
120122 function updateWidthHeightBindings() { \n\
@@ -129,7 +131,7 @@ var kArtShapeHolderCode = 'Item { \n\
129131 CroppedImageMinimumSourceSize { \n\
130132 id: artImage; \n\
131133 objectName: "artImage"; \n\
132− source: cardData && cardData["art"] || ""; \n\
134+ source: artShapeLoader.cardArt; \n\
133135 asynchronous: root.asynchronous; \n\
134136 width: %2; \n\
135137 height: %3; \n\
@@ -246,11 +248,12 @@ var kMascotShapeLoaderCode = 'Loader { \n\
246248// %1 is used as anchors of mascotImage
247249// %2 is used as visible of mascotImage
248250// %3 is injected as code to mascotImage
251+// %4 is used as fallback image
249252var kMascotImageCode = 'CroppedImageMinimumSourceSize { \n\
250253 id: mascotImage; \n\
251254 objectName: "mascotImage"; \n\
252255 anchors { %1 } \n\
253− source: cardData && cardData["mascot"] || ""; \n\
256+ source: cardData && cardData["mascot"] || %4; \n\
254257 width: units.gu(6); \n\
255258 height: units.gu(5.625); \n\
256259 horizontalAlignment: Image.AlignHCenter; \n\
@@ -487,11 +490,15 @@ function cardString(template, components) {
487490 }
488491 var fallback = components["art"] && components["art"]["fallback"] || "";
489492 fallback = encodeURI(fallback);
490− var fallbackCode = "";
493+ var fallbackStatusCode = "";
494+ var fallbackURICode = '""';
491495 if (fallback !== "") {
492− fallbackCode += 'onStatusChanged: if (status === Image.Error) source = decodeURI("%1");'.arg(fallback);
496+ // fallbackStatusCode has %6 in it because we want to substitute it for fallbackURICode
497+ // which in kArtShapeHolderCode is %7
498+ fallbackStatusCode += 'onStatusChanged: if (status === Image.Error) source = %7;';
499+ fallbackURICode = 'decodeURI("%1")'.arg(fallback);
493500 }
494− code += kArtShapeHolderCode.arg(artAnchors).arg(widthCode).arg(heightCode).arg(aspectRatio).arg(isConciergeMode ? "false" : "true").arg(fallbackCode);
501+ code += kArtShapeHolderCode.arg(artAnchors).arg(widthCode).arg(heightCode).arg(isConciergeMode ? "false" : "true").arg(aspectRatio).arg(fallbackStatusCode).arg(fallbackURICode);
495502 } else {
496503 code += 'readonly property size artShapeSize: Qt.size(-1, -1);\n'
497504 }
@@ -585,11 +592,15 @@ function cardString(template, components) {
585592 var mascotImageVisible = useMascotShape ? 'false' : 'showHeader';
586593 var fallback = components["mascot"] && components["mascot"]["fallback"] || "";
587594 fallback = encodeURI(fallback);
588− var fallbackCode = "";
595+ var fallbackStatusCode = "";
596+ var fallbackURICode = '""';
589597 if (fallback !== "") {
590− fallbackCode += 'onStatusChanged: if (status === Image.Error) source = decodeURI("%1");'.arg(fallback);
598+ // fallbackStatusCode has %4 in it because we want to substitute it for fallbackURICode
599+ // which in kMascotImageCode is %4
600+ fallbackStatusCode += 'onStatusChanged: if (status === Image.Error) source = %4;';
601+ fallbackURICode = 'decodeURI("%1")'.arg(fallback);
591602 }
592− mascotCode = kMascotImageCode.arg(mascotAnchors).arg(mascotImageVisible).arg(fallbackCode);
603+ mascotCode = kMascotImageCode.arg(mascotAnchors).arg(mascotImageVisible).arg(fallbackStatusCode).arg(fallbackURICode);
593604 }
594605
595606 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 {
3535 Item {
3636 id: headerRoot
3737 objectName: "innerPreviewHeader"
38− readonly property url mascot: root.widgetData["mascot"] || ""
38+ readonly property url mascot: root.widgetData["mascot"] || fallback
3939 readonly property url fallback: root.widgetData["fallback"] || ""
4040 readonly property string title: root.widgetData["title"] || ""
4141 readonly property string subtitle: root.widgetData["subtitle"] || ""
qml/Dash/Previews/PreviewImageGallery.qml+2−2
@@ -59,7 +59,7 @@ PreviewWidget {
5959 top: parent.top
6060 bottom: parent.bottom
6161 }
62− source: modelData ? modelData : ""
62+ source: modelData || root.widgetData["fallback"] || ""
6363 scaleTo: "height"
6464 initialWidth: units.gu(13)
6565 pressed: mouseArea.pressed
@@ -128,7 +128,7 @@ PreviewWidget {
128128 bottom: parent.bottom
129129 }
130130 width: overlay.width
131− source: modelData ? modelData : ""
131+ source: modelData || root.widgetData["fallback"] || ""
132132 fillMode: Image.PreserveAspectFit
133133 sourceSize { width: screenshot.width; height: screenshot.height }
134134
qml/Dash/Previews/PreviewZoomableImage.qml+2−2
@@ -42,7 +42,7 @@ PreviewWidget {
4242 right: parent.right
4343 }
4444 scaleTo: "width"
45− source: widgetData["source"]
45+ source: widgetData["source"] || widgetData["fallback"] || ""
4646 asynchronous: true
4747 useUbuntuShape: false
4848 pressed: mouseArea.pressed
@@ -86,7 +86,7 @@ PreviewWidget {
8686
8787 delegate: ZoomableImage {
8888 anchors.fill: parent
89− source: widgetData["source"]
89+ source: widgetData["source"] || widgetData["fallback"] || ""
9090 zoomable: widgetData["zoomable"] ? widgetData["zoomable"] : false
9191 // If modelData would change after failing to load it would not be
9292 // reloaded since the source binding is destroyed by the source = fallback
tests/plugins/Dash/cardcreator/1.res+3−2
@@ -23,7 +23,8 @@ Item {
2323 Loader {
2424 id: artShapeLoader;
2525 objectName: "artShapeLoader";
26− active: cardData && cardData["art"] || false;
26+ readonly property string cardArt: cardData && cardData["art"] || "";
27+ active: cardArt != "";
2728 asynchronous: root.asynchronous;
2829 visible: status == Loader.Ready;
2930 sourceComponent: Item {
@@ -80,7 +81,7 @@ Item {
8081 CroppedImageMinimumSourceSize {
8182 id: artImage;
8283 objectName: "artImage";
83− source: cardData && cardData["art"] || "";
84+ source: artShapeLoader.cardArt;
8485 asynchronous: root.asynchronous;
8586 width: root.width;
8687 height: width / artShape.aspect;
tests/plugins/Dash/cardcreator/11.res+4−3
@@ -61,7 +61,8 @@ Item {
6161 Loader {
6262 id: artShapeLoader;
6363 objectName: "artShapeLoader";
64− active: cardData && cardData["art"] || false;
64+ readonly property string cardArt: cardData && cardData["art"] || decodeURI("%5C");
65+ active: cardArt != "";
6566 asynchronous: root.asynchronous;
6667 visible: status == Loader.Ready;
6768 sourceComponent: Item {
@@ -118,7 +119,7 @@ Item {
118119 CroppedImageMinimumSourceSize {
119120 id: artImage;
120121 objectName: "artImage";
121− source: cardData && cardData["art"] || "";
122+ source: artShapeLoader.cardArt;
122123 asynchronous: root.asynchronous;
123124 width: root.width;
124125 height: width / artShape.aspect;
@@ -146,7 +147,7 @@ left: parent.left;
146147 id: mascotImage;
147148 objectName: "mascotImage";
148149 anchors { verticalCenter: parent.verticalCenter; }
149− source: cardData && cardData["mascot"] || "";
150+ source: cardData && cardData["mascot"] || decodeURI("%22");
150151 width: units.gu(6);
151152 height: units.gu(5.625);
152153 horizontalAlignment: Image.AlignHCenter;
tests/plugins/Dash/cardcreator/3.res+3−2
@@ -23,7 +23,8 @@ Item {
2323 Loader {
2424 id: artShapeLoader;
2525 objectName: "artShapeLoader";
26− active: cardData && cardData["art"] || false;
26+ readonly property string cardArt: cardData && cardData["art"] || decodeURI("IHAVE%5C%22ESCAPED%5C%22QUOTES%5C%22");
27+ active: cardArt != "";
2728 asynchronous: root.asynchronous;
2829 visible: status == Loader.Ready;
2930 sourceComponent: Item {
@@ -80,7 +81,7 @@ Item {
8081 CroppedImageMinimumSourceSize {
8182 id: artImage;
8283 objectName: "artImage";
83− source: cardData && cardData["art"] || "";
84+ source: artShapeLoader.cardArt;
8485 asynchronous: root.asynchronous;
8586 width: root.width;
8687 height: width / artShape.aspect;
tests/plugins/Dash/cardcreator/5.res+3−2
@@ -23,7 +23,8 @@ Item {
2323 Loader {
2424 id: artShapeLoader;
2525 objectName: "artShapeLoader";
26− active: cardData && cardData["art"] || false;
26+ readonly property string cardArt: cardData && cardData["art"] || "";
27+ active: cardArt != "";
2728 asynchronous: root.asynchronous;
2829 visible: status == Loader.Ready;
2930 sourceComponent: Item {
@@ -80,7 +81,7 @@ Item {
8081 CroppedImageMinimumSourceSize {
8182 id: artImage;
8283 objectName: "artImage";
83− source: cardData && cardData["art"] || "";
84+ source: artShapeLoader.cardArt;
8485 asynchronous: root.asynchronous;
8586 width: root.width;
8687 height: width / artShape.aspect;
tests/qmltests/Dash/Previews/tst_PreviewHeader.qml+15
@@ -54,6 +54,14 @@ Rectangle {
5454 "attributes": [{"value":"text1","icon":"image://theme/ok"},{"value":"text2","icon":"image://theme/cancel"}]
5555 }
5656
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+
5765 PreviewHeader {
5866 id: previewHeader
5967 widgetData: headerjson
@@ -150,6 +158,13 @@ Rectangle {
150158 var mascot = findChild(previewHeader, "mascotShape");
151159 tryCompare(mascot, "visible", true);
152160 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);
153168 }
154169 }
155170}
tests/qmltests/Dash/Previews/tst_PreviewImageGallery.qml+19
@@ -48,6 +48,16 @@ Rectangle {
4848 , "fallback": "../../../tests/graphics/clock@18.png"
4949 }
5050
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+
5161 PreviewImageGallery {
5262 id: imageGallery
5363 width: parent.width
@@ -123,5 +133,14 @@ Rectangle {
123133 image3 = findChild(imageGallery, "previewImage3");
124134 tryCompare(image3, "state", "ready");
125135 }
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+ }
126145 }
127146}
tests/qmltests/Dash/Previews/tst_PreviewZoomableImage.qml+12
@@ -39,6 +39,11 @@ Rectangle {
3939 "fallback": "../../graphics/phone_background.jpg"
4040 }
4141
42+ property var widgetData3: {
43+ "source": "",
44+ "fallback": "../../graphics/phone_background.jpg"
45+ }
46+
4247 Loader {
4348 id: loader
4449 width: parent.width
@@ -100,5 +105,12 @@ Rectangle {
100105 waitForRendering(lazyImage);
101106 tryCompare(lazyImage, "state", "ready");
102107 }
108+
109+ function test_emptyfallback() {
110+ zoomableImage.widgetData = widgetData3;
111+ waitForRendering(zoomableImage);
112+ waitForRendering(lazyImage);
113+ tryCompare(lazyImage, "state", "ready");
114+ }
103115 }
104116}
tests/qmltests/Dash/tst_Card.qml+18
@@ -475,6 +475,15 @@ Rectangle {
475475 card.cardDataChanged();
476476 waitForRendering(card);
477477 tryCompare(art, "visible", true);
478+ compare(artImage.source, Qt.resolvedUrl("artwork/emblem.png"));
479+
480+ cardTool.components["art"]["fallback"] = Qt.resolvedUrl("artwork/checkers.png");
481+ cardTool.componentsChanged();
482+ card.cardData["art"] = "";
483+ card.cardDataChanged();
484+ waitForRendering(card);
485+ tryCompare(art, "visible", true);
486+ compare(artImage.source, Qt.resolvedUrl("artwork/checkers.png"));
478487
479488 card.cardData["mascot"] = "somethingbroken2";
480489 card.cardDataChanged();
@@ -486,6 +495,15 @@ Rectangle {
486495 card.cardDataChanged();
487496 waitForRendering(card);
488497 tryCompare(mascotImage, "status", Image.Ready);
498+ compare(mascotImage.source, Qt.resolvedUrl("artwork/emblem.png"));
499+
500+ cardTool.components["mascot"] = {"fallback": Qt.resolvedUrl("artwork/checkers.png")};
501+ cardTool.componentsChanged();
502+ card.cardData["mascot"] = "";
503+ card.cardDataChanged();
504+ waitForRendering(card);
505+ tryCompare(mascotImage, "status", Image.Ready);
506+ compare(mascotImage.source, Qt.resolvedUrl("artwork/checkers.png"));
489507 }
490508
491509 function test_font_weights_data() {