aboutsummaryrefslogtreecommitdiffstats
path: root/examples/declarative/shared/FlickrRssModel.qml
diff options
context:
space:
mode:
authorAdrian Herrmann <adrian.herrmann@qt.io>2022-07-29 16:59:50 +0200
committerAdrian Herrmann <adrian.herrmann@qt.io>2022-09-02 18:07:19 +0200
commitef8d3daa8f4d19c48e44874dd6e38a3ed4d02425 (patch)
tree2510b0e02602f5683f87ce16c1e968a71a2bb362 /examples/declarative/shared/FlickrRssModel.qml
parentc0387967f81dcabe3087a741e337d01ca177d0b1 (diff)
Add QML window example + shared QML module
Port the Qt Quick example "Window and Screen" to PySide. This includes a "shared" QML module located in a sibling directory of the example. Task-number: PYSIDE-841 Pick-to: 6.2 6.3 Change-Id: I7c8376701390b10d8b28bbf0ad04dce7a3089b20 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'examples/declarative/shared/FlickrRssModel.qml')
-rw-r--r--examples/declarative/shared/FlickrRssModel.qml45
1 files changed, 45 insertions, 0 deletions
diff --git a/examples/declarative/shared/FlickrRssModel.qml b/examples/declarative/shared/FlickrRssModel.qml
new file mode 100644
index 000000000..66f53b8ef
--- /dev/null
+++ b/examples/declarative/shared/FlickrRssModel.qml
@@ -0,0 +1,45 @@
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+import QtQuick 2.12
+
+ListModel {
+ id: flickrImages
+ property string tags : ""
+ readonly property string queryUrl : "http://api.flickr.com/services/feeds/photos_public.gne?"
+
+ function encodeParams(x) {
+ return encodeURIComponent(x.replace(" ",","));
+ }
+ function fetchImages(format) {
+ var requestURL = queryUrl + (tags ? "tags="+encodeParams(tags)+"&" : "") + "format=" + format + "&nojsoncallback=1";
+ var xhr = new XMLHttpRequest;
+ xhr.onreadystatechange = function() {
+ if (xhr.readyState === XMLHttpRequest.DONE) {
+
+ if (xhr.status !== 200) {
+ console.log("Failed to get images from flickr. status code: " + xhr.status);
+ return;
+ }
+
+ var jsonText = xhr.responseText;
+ var objArray = JSON.parse(jsonText.replace(/\'/g,"'"))
+ if (objArray.errors !== undefined)
+ console.log("Error fetching tweets: " + objArray.errors[0].message)
+ else {
+ for (var key in objArray.items) {
+ var rssItem = objArray.items[key];
+ var jsonObject = "{ \"title\": \"" + rssItem.title +"\",\"media\": \"" + rssItem.media.m + "\", \"thumbnail\": \"" + rssItem.media.m.replace(/\_m\.jpg/,"_s.jpg") +"\"}"
+ flickrImages.append(JSON.parse(jsonObject));
+ }
+ }
+ }
+ }
+ xhr.open("GET", requestURL, true);
+ xhr.send();
+ }
+ Component.onCompleted: {
+ fetchImages("json");
+ }
+}
+