2025-10-18 21:40:02 +02:00
|
|
|
import QtQuick 6.8
|
|
|
|
|
import QtQuick.Controls 6.8
|
|
|
|
|
import QtQuick.Layouts 6.8
|
|
|
|
|
|
|
|
|
|
import QYRComponents 1.0
|
|
|
|
|
|
2025-10-19 02:58:12 +02:00
|
|
|
Item {
|
2025-10-18 21:40:02 +02:00
|
|
|
anchors.fill: parent
|
|
|
|
|
|
2025-10-19 02:58:12 +02:00
|
|
|
|
2025-10-18 21:40:02 +02:00
|
|
|
property bool loading: true
|
|
|
|
|
property bool failed: false
|
|
|
|
|
|
|
|
|
|
GridView {
|
2025-10-19 02:58:12 +02:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
anchors.top: parent.top
|
|
|
|
|
anchors.topMargin: Player.active ? 96 : 0
|
2025-10-18 21:40:02 +02:00
|
|
|
visible: !loading || !failed
|
2025-10-19 02:58:12 +02:00
|
|
|
anchors.fill: parent
|
2025-10-18 21:40:02 +02:00
|
|
|
model: ListModel { id: model }
|
|
|
|
|
clip: true
|
|
|
|
|
|
|
|
|
|
cellWidth: 384
|
|
|
|
|
cellHeight: 224
|
|
|
|
|
|
|
|
|
|
delegate: VideoEntry {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BusyIndicator {
|
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
visible: loading
|
|
|
|
|
running: loading
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
visible: failed
|
|
|
|
|
|
|
|
|
|
Label {
|
|
|
|
|
text: "Couldn't get videos!"
|
|
|
|
|
heading: "h2"
|
|
|
|
|
font.bold: true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Label {
|
|
|
|
|
text: "This could mean that either your internet or YouVideo is down."
|
|
|
|
|
heading: "h4"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Label {
|
|
|
|
|
Layout.bottomMargin: 25
|
|
|
|
|
text: "Check your network connection and try again!"
|
|
|
|
|
heading: "h4"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Button {
|
|
|
|
|
text: "Retry"
|
|
|
|
|
onClicked: parent.fetchData()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-19 02:58:12 +02:00
|
|
|
Timer {
|
|
|
|
|
interval: 1000
|
|
|
|
|
running: true
|
|
|
|
|
onTriggered: parent.fetchData()
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-18 21:40:02 +02:00
|
|
|
function fetchData() {
|
|
|
|
|
model.clear();
|
|
|
|
|
loading = true;
|
|
|
|
|
failed = false;
|
|
|
|
|
const xhr = new XMLHttpRequest;
|
|
|
|
|
xhr.open("GET", "http://youvideo.nonamesoft.xyz/youvideo/api/videos");
|
|
|
|
|
xhr.onreadystatechange = function() {
|
|
|
|
|
if (xhr.readyState == XMLHttpRequest.DONE) {
|
|
|
|
|
loading = false;
|
|
|
|
|
if (xhr.status != 200) {
|
2025-10-19 02:58:12 +02:00
|
|
|
console.log("Invalid response");
|
2025-10-18 21:40:02 +02:00
|
|
|
failed = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const data = JSON.parse(xhr.responseText);
|
2025-10-19 02:58:12 +02:00
|
|
|
console.log("Received data, found " + data.length + " videos");
|
2025-10-18 21:40:02 +02:00
|
|
|
data.forEach(video => {
|
|
|
|
|
model.append(video);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-10-19 02:58:12 +02:00
|
|
|
xhr.ontimeout = function() {
|
|
|
|
|
loading = false;
|
|
|
|
|
failed = true;
|
|
|
|
|
console.log("Request timed out");
|
|
|
|
|
}
|
2025-10-18 21:40:02 +02:00
|
|
|
xhr.send();
|
|
|
|
|
}
|
2025-10-19 02:58:12 +02:00
|
|
|
|
|
|
|
|
VideoPlayer {
|
|
|
|
|
anchors.left: parent.left
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
anchors.top: parent.top
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
}
|
2025-10-18 21:40:02 +02:00
|
|
|
}
|