mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-26 04:33:06 +01:00
Add reddit and dw rss atom feed examples
This commit is contained in:
parent
1b65e2ae18
commit
2e65371df9
47
Content/widget_rss_dw_news/PostDelegate.qml
Normal file
47
Content/widget_rss_dw_news/PostDelegate.qml
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3
Content/widget_rss_dw_news/Readme.md
Normal file
3
Content/widget_rss_dw_news/Readme.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Widget that shows the latest dw feed
|
||||||
|
|
||||||
|
https://corporate.dw.com/en/rss/s-31500
|
51
Content/widget_rss_dw_news/main.qml
Normal file
51
Content/widget_rss_dw_news/main.qml
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
BIN
Content/widget_rss_dw_news/preview.png
Normal file
BIN
Content/widget_rss_dw_news/preview.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 111 KiB |
10
Content/widget_rss_dw_news/project.json
Normal file
10
Content/widget_rss_dw_news/project.json
Normal 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"
|
||||||
|
}
|
64
Content/widget_rss_reddit/PostDelegate.qml
Normal file
64
Content/widget_rss_reddit/PostDelegate.qml
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1
Content/widget_rss_reddit/Readme.md
Normal file
1
Content/widget_rss_reddit/Readme.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
Widget that shows the latest reddit feed
|
45
Content/widget_rss_reddit/main.qml
Normal file
45
Content/widget_rss_reddit/main.qml
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
BIN
Content/widget_rss_reddit/preview.png
Normal file
BIN
Content/widget_rss_reddit/preview.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 184 KiB |
16
Content/widget_rss_reddit/project.json
Normal file
16
Content/widget_rss_reddit/project.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -42,6 +42,8 @@ int main(int argc, char* argv[])
|
|||||||
QStringList contentFolder = {
|
QStringList contentFolder = {
|
||||||
"/widget_analogClock",
|
"/widget_analogClock",
|
||||||
"/widget_digitalClock",
|
"/widget_digitalClock",
|
||||||
|
"/widget_rss_reddit",
|
||||||
|
"/widget_rss_dw_news",
|
||||||
"/widget_xkcd"
|
"/widget_xkcd"
|
||||||
};
|
};
|
||||||
QString projectPath = exampleContentPath + contentFolder.at(0);
|
QString projectPath = exampleContentPath + contentFolder.at(0);
|
||||||
|
Loading…
Reference in New Issue
Block a user