Warning, /utilities/telly-skout/src/qml/ChannelTablePage.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2022 Plata Hill <plata.hill@kdemail.net>
0002 // SPDX-License-Identifier: LGPL-2.1-or-later
0003 
0004 import Qt.labs.platform 1.1
0005 import QtQuick 2.14
0006 import QtQuick.Controls 2.15 as Controls
0007 import QtQuick.Layouts 1.14
0008 import org.kde.TellySkout 1.0
0009 import org.kde.kirigami 2.19 as Kirigami
0010 
0011 Kirigami.Page {
0012     id: root
0013 
0014     readonly property int columnWidth: _settings.columnWidth
0015     property int windowHeight: 0
0016     property real currentTimestamp: 0
0017 
0018     function updateTime() {
0019         var now = new Date();
0020         currentTimestamp = now.getTime();
0021     }
0022 
0023     title: i18n("Favorites")
0024     padding: 0
0025     Component.onCompleted: {
0026         Fetcher.fetchFavorites();
0027         updateTime();
0028     }
0029 
0030     Timer {
0031         interval: 60000
0032         repeat: true
0033         running: true
0034         onTriggered: updateTime()
0035     }
0036 
0037     Kirigami.PlaceholderMessage {
0038         visible: contentRepeater.count === 0
0039         width: Kirigami.Units.gridUnit * 20
0040         icon.name: "favorite"
0041         anchors.centerIn: parent
0042         text: i18n("Please select favorites")
0043     }
0044 
0045     Row {
0046         id: header
0047 
0048         x: -channelTable.contentX
0049         visible: contentRepeater.count !== 0
0050         z: 100 // TODO: remove workaround for mobile (channelTable "anchors.top: header.bottom" not respected)
0051 
0052         Repeater {
0053             id: headerRepeater
0054 
0055             model: channelsModel
0056 
0057             delegate: Column {
0058                 width: columnWidth
0059 
0060                 Rectangle {
0061                     color: Kirigami.Theme.backgroundColor
0062                     width: parent.width
0063                     height: 30
0064                     border.color: Kirigami.Theme.textColor
0065 
0066                     Text {
0067                         text: modelData.name
0068                         color: Kirigami.Theme.textColor
0069                         anchors.centerIn: parent
0070                     }
0071 
0072                 }
0073 
0074             }
0075 
0076         }
0077 
0078     }
0079 
0080     Controls.ScrollView {
0081         width: parent.width
0082         height: parent.height - header.height
0083         anchors.top: header.bottom
0084 
0085         Flickable {
0086             id: channelTable
0087 
0088             readonly property int pxPerMin: _settings.programHeight
0089             readonly property var date: new Date()
0090             readonly property var start: new Date(date.getFullYear(), date.getMonth(), date.getDate()) // today 00:00h
0091             readonly property var stop: new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 0) // today 23:59h
0092 
0093             visible: contentRepeater.count !== 0
0094             contentHeight: 24 * 60 * pxPerMin
0095             contentWidth: content.width
0096             boundsBehavior: Flickable.StopAtBounds
0097             Component.onCompleted: {
0098                 // scroll to current time
0099                 var today = new Date();
0100                 today.setHours(0);
0101                 today.setMinutes(0);
0102                 today.setSeconds(0);
0103                 const now = new Date();
0104                 // offset [s] to 00:00h
0105                 const offsetS = (now.getTime() - today.getTime()) / 1000;
0106                 // center in window (vertically)
0107                 contentY = (offsetS / (24 * 60 * 60)) * contentHeight - (windowHeight / 2);
0108             }
0109 
0110             Row {
0111                 id: content
0112 
0113                 Repeater {
0114                     id: contentRepeater
0115 
0116                     model: channelsModel
0117 
0118                     delegate: Column {
0119                         id: column
0120 
0121                         property int idx: index
0122 
0123                         width: root.columnWidth
0124 
0125                         // show info if program is not available
0126                         Rectangle {
0127                             width: parent.width
0128                             height: channelTable.contentHeight
0129                             visible: programRepeater.count === 0
0130                             color: Kirigami.Theme.negativeBackgroundColor
0131                             border.color: Kirigami.Theme.textColor
0132 
0133                             Text {
0134                                 anchors.centerIn: parent
0135                                 text: i18n("not available")
0136                                 wrapMode: Text.Wrap
0137                                 color: Kirigami.Theme.textColor
0138                             }
0139 
0140                         }
0141 
0142                         Repeater {
0143                             id: programRepeater
0144 
0145                             model: ProgramsProxyModel {
0146                                 id: proxyProgramModel
0147 
0148                                 start: channelTable.start
0149                                 stop: channelTable.stop
0150                                 sourceModel: modelData.programsModel
0151                             }
0152 
0153                             delegate: ChannelTableDelegate {
0154                                 channelIdx: column.idx
0155                                 overlay: overlaySheet
0156                                 pxPerMin: channelTable.pxPerMin
0157                                 width: root.columnWidth
0158                                 startTime: channelTable.start
0159                                 stopTime: channelTable.stop
0160                                 currentTimestamp: root.currentTimestamp
0161                             }
0162 
0163                         }
0164 
0165                     }
0166 
0167                 }
0168 
0169             }
0170 
0171         }
0172 
0173     }
0174 
0175     ChannelsModel {
0176         id: channelsModel
0177 
0178         onlyFavorites: true
0179     }
0180 
0181     Kirigami.OverlaySheet {
0182         id: overlaySheet
0183 
0184         property string programId: ""
0185         property alias text: overlaySheetText.text
0186 
0187         Text {
0188             id: overlaySheetText
0189 
0190             Layout.fillWidth: true
0191             color: Kirigami.Theme.textColor
0192             wrapMode: Text.WordWrap
0193         }
0194 
0195     }
0196 
0197 }