1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-22 02:32:29 +01:00

Add reddit and dw rss atom feed examples

This commit is contained in:
Elias Steurer 2023-02-25 12:44:46 +01:00
parent 1b65e2ae18
commit 2e65371df9
11 changed files with 239 additions and 0 deletions

View File

@ -0,0 +1,47 @@
// SPDX-License-Identifier: BSD-3-Clause
import QtQuick
import QtQuick.Layouts
Item {
id: root
implicitHeight: 100
implicitWidth: 300
property string published
property string rights
property string updated
property string category
property string title
property string link
property string summary
ColumnLayout {
anchors.fill: parent
Text {
Layout.fillWidth: true
font.pointSize: 14
wrapMode: Text.Wrap
text: model.title
height: 20
color: "white"
}
Text {
Layout.fillWidth: true
wrapMode: Text.Wrap
text: model.summary
font.pointSize: 10
height: 20
color: "white"
}
}
MouseArea {
anchors.fill: parent
onClicked: {
print(model.link)
Qt.openUrlExternally(model.link)
}
}
}

View File

@ -0,0 +1,3 @@
Widget that shows the latest dw feed
https://corporate.dw.com/en/rss/s-31500

View File

@ -0,0 +1,51 @@
// SPDX-License-Identifier: BSD-3-Clause
import QtQuick
import QtQuick.Controls
import QtQuick.Effects
import QtQuick.Particles
import QtQml.XmlListModel
Item {
id: root
implicitWidth: 480
implicitHeight: 480
XmlListModel {
id: feedModel
source: "https://rss.dw.com/atom/rss-en-all"
query: "/feed/entry"
onCountChanged: {
console.log("count ",count)
}
onStatusChanged: {
print("status ",status)
console.log("count ",count)
if (status === XmlListModel.Error) {
console.log("Error: " + errorString);
}
}
XmlListModelRole { name: "published"; elementName: "published" }
XmlListModelRole { name: "rights"; elementName: "rights" }
XmlListModelRole { name: "updated"; elementName: "updated" }
XmlListModelRole { name: "category"; elementName: "category"; attributeName: "term" }
XmlListModelRole { name: "title"; elementName: "title"}
XmlListModelRole { name: "link"; elementName: "link"; attributeName: "href" }
XmlListModelRole { name: "summary"; elementName: "summary"}
}
ListView {
id: list
anchors.fill: parent
anchors.margins: 10
anchors.topMargin: 20
spacing: 10
model: feedModel
delegate: PostDelegate {
width: parent.width
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

View File

@ -0,0 +1,10 @@
{
"description": "Widget that shows the latest Detusche Welle feed",
"file": "main.qml",
"preview": "preview.png",
"tags": [
"dw"
],
"title": "dw",
"type": "qmlWidget"
}

View File

@ -0,0 +1,64 @@
// SPDX-License-Identifier: BSD-3-Clause
import QtQuick
import QtQuick.Layouts
Item {
id: root
implicitHeight: 300
implicitWidth: 300
property string contentRaw: model.content
property url href
onContentRawChanged: {
// Define the regular expression to match the image URL
var regex = /<a\s+href="((?:https?:\/\/)?i\.redd\.it\/[^"]+\.jpg)">\[link\]<\/a>/i;
// Parse the image URL from the HTML content
var match = regex.exec(contentRaw);
if (match != null) {
var imageUrl = match[1];
var href = match[2];
img.source = "" + imageUrl
root.href = "" + href
}
}
Image {
id: img
asynchronous: true
anchors.fill: parent
clip:true
fillMode: Image.PreserveAspectCrop
}
Rectangle {
anchors.fill: img
gradient: Gradient {
GradientStop { position: 0; color: "#00333333" }
GradientStop { position: 1; color: "#ff333333" }
}
}
Text {
anchors {
right: parent.right
bottom: parent.bottom
left: parent.left
leftMargin: 10
}
wrapMode: Text.Wrap
width: parent.width
text: model.title
height: 20
color: "white"
}
MouseArea {
anchors.fill: parent
onClicked: {
print(model.link)
Qt.openUrlExternally(model.link)
}
}
}

View File

@ -0,0 +1 @@
Widget that shows the latest reddit feed

View File

@ -0,0 +1,45 @@
// SPDX-License-Identifier: BSD-3-Clause
import QtQuick
import QtQuick.Controls
import QtQuick.Effects
import QtQuick.Particles
import QtQml.XmlListModel
Item {
id: root
implicitWidth: 480
implicitHeight: 480
property string subreddit: "funny"
XmlListModel {
id: feedModel
onStatusChanged: {
print("status ",status)
if (status === XmlListModel.Error) {
console.log("Error: " + errorString);
}
}
source: "https://www.reddit.com/r/" + root.subreddit + "/.rss"
query: "/feed/entry"
XmlListModelRole { name: "updated"; elementName: "updated" }
XmlListModelRole { name: "subtitle"; elementName: "subtitle"}
XmlListModelRole { name: "content"; elementName: "content"}
XmlListModelRole { name: "link"; elementName: "link"; attributeName: "href" }
XmlListModelRole { name: "title"; elementName: "title"}
}
ListView {
id: list
anchors.fill: parent
model: feedModel
delegate: PostDelegate {
width: parent.width
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 184 KiB

View File

@ -0,0 +1,16 @@
{
"description": "Widget that shows the latest reddit feed",
"file": "main.qml",
"preview": "preview.png",
"tags": [
"reddit"
],
"title": "reddit",
"type": "qmlWidget",
"properties": {
"subreddit": {
"type": "string",
"value": "funny"
}
}
}

View File

@ -42,6 +42,8 @@ int main(int argc, char* argv[])
QStringList contentFolder = {
"/widget_analogClock",
"/widget_digitalClock",
"/widget_rss_reddit",
"/widget_rss_dw_news",
"/widget_xkcd"
};
QString projectPath = exampleContentPath + contentFolder.at(0);