Warning, /multimedia/plasmatube/src/ui/components/BaseGridView.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com 0002 // SPDX-License-Identifier: GPL-3.0-or-later 0003 0004 import QtQuick 0005 import QtQuick.Controls as QQC2 0006 import QtQuick.Layouts 0007 import Qt.labs.qmlmodels 0008 0009 import org.kde.kirigami as Kirigami 0010 import org.kde.kirigamiaddons.components as Components 0011 0012 import org.kde.plasmatube 0013 0014 GridView { 0015 id: gridView 0016 0017 property string currentVideoId 0018 property int currentVideoIndex 0019 property string currentVideoTitle 0020 property string currentChannelName 0021 property string currentChannelId 0022 0023 readonly property real effectiveWidth: width - leftMargin - rightMargin 0024 readonly property real targetDelegateWidth: Kirigami.Units.gridUnit * 14 + Kirigami.Units.largeSpacing * 2 0025 readonly property int columns: Math.floor(effectiveWidth / targetDelegateWidth) 0026 0027 topMargin: root.width > 900 ? Kirigami.Units.gridUnit * 2 : Kirigami.Units.largeSpacing 0028 bottomMargin: root.width > 900 ? Kirigami.Units.gridUnit * 2 : Kirigami.Units.largeSpacing 0029 leftMargin: root.width > 900 ? Kirigami.Units.gridUnit * 4 : Kirigami.Units.largeSpacing 0030 rightMargin: root.width > 900 ? Kirigami.Units.gridUnit * 4 : Kirigami.Units.largeSpacing 0031 0032 currentIndex: -1 0033 // TODO: look into this assumption if we ever want to use gridview in the video player 0034 enabled: !applicationWindow().videoPlayerOpen 0035 0036 keyNavigationEnabled: true 0037 cellWidth: effectiveWidth / columns 0038 cellHeight: (cellWidth / 16 * 9) + Kirigami.Units.gridUnit * 5 + Kirigami.Units.mediumSpacing 0039 0040 Connections { 0041 target: model 0042 0043 function onIsLoadingChanged() { 0044 root.refreshing = gridView.model.isLoading; 0045 } 0046 0047 function onErrorOccured(errorText) { 0048 message.text = i18nc("@info:status Network status", "Failed to contact server: %1. Please check your proxy settings.", errorText); 0049 message.visible = true; 0050 } 0051 } 0052 0053 delegate: DelegateChooser { 0054 role: "type" 0055 0056 DelegateChoice { 0057 roleValue: "video" 0058 0059 VideoGridItem { 0060 width: gridView.cellWidth 0061 height: gridView.cellHeight 0062 0063 vid: model.id 0064 thumbnail: model.thumbnail 0065 liveNow: model.liveNow 0066 length: model.length 0067 title: model.title 0068 author: model.author 0069 authorId: model.authorId 0070 description: model.description 0071 viewCount: model.viewCount 0072 publishedText: model.publishedText 0073 watched: model.watched 0074 0075 onClicked: { 0076 videoModel.markAsWatched(index); 0077 PlasmaTube.videoController.play(vid); 0078 } 0079 0080 onContextMenuRequested: { 0081 currentVideoId = vid; 0082 currentVideoIndex = index; 0083 currentVideoTitle = title; 0084 currentChannelName = author; 0085 currentChannelId = authorId; 0086 videoMenu.isWatched = watched; 0087 videoMenu.popup(); 0088 } 0089 } 0090 } 0091 DelegateChoice { 0092 roleValue: "channel" 0093 0094 ChannelGridItem { 0095 width: gridView.cellWidth 0096 height: gridView.cellHeight 0097 0098 name: model.channelName 0099 avatarUrl: model.channelAvatar 0100 0101 onClicked: { 0102 pageStack.push(Qt.createComponent("org.kde.plasmatube", "ChannelPage"), {author: model.channelName, authorId: model.id}); 0103 } 0104 } 0105 } 0106 DelegateChoice { 0107 roleValue: "playlist" 0108 0109 PlaylistGridItem { 0110 width: gridView.cellWidth 0111 height: gridView.cellHeight 0112 0113 title: model.title 0114 thumbnail: model.thumbnail 0115 videoCount: model.videoCount 0116 0117 onClicked: { 0118 pageStack.push(Qt.createComponent("org.kde.plasmatube", "PlaylistPage"), {playlistId: model.id, title: model.title}) 0119 } 0120 } 0121 } 0122 } 0123 0124 Kirigami.PlaceholderMessage { 0125 anchors.centerIn: parent 0126 text: i18nc("@info:status", "Loading…") 0127 visible: gridView.model.isLoading 0128 } 0129 0130 Kirigami.PlaceholderMessage { 0131 anchors.centerIn: parent 0132 text: i18n("No videos") 0133 visible: !gridView.model.isLoading && gridView.count === 0 0134 } 0135 0136 VideoMenu { 0137 id: videoMenu 0138 0139 videoId: currentVideoId 0140 channelName: currentChannelName 0141 channelId: currentChannelId 0142 0143 onMarkWatched: videoModel.markAsWatched(currentVideoIndex) 0144 onMarkUnwatched: videoModel.markAsUnwatched(currentVideoIndex) 0145 0146 onAddToPlaylist: { 0147 addToPlaylistLoader.active = true; 0148 addToPlaylistLoader.item.open(); 0149 } 0150 } 0151 0152 Loader { 0153 id: addToPlaylistLoader 0154 0155 active: false 0156 sourceComponent: Kirigami.PromptDialog { 0157 id: addToPlaylistDialog 0158 0159 title: i18n("Add to playlist") 0160 0161 standardButtons: Kirigami.Dialog.NoButton 0162 0163 mainItem: ColumnLayout { 0164 Repeater { 0165 id: playlists 0166 0167 model: PlaylistsModel { 0168 id: playlistsModel 0169 } 0170 0171 delegate: QQC2.ItemDelegate { 0172 text: model.title 0173 0174 Layout.fillWidth: true 0175 0176 onClicked: { 0177 PlasmaTube.selectedSource.addToPlaylist(model.id, currentVideoId); 0178 addToPlaylistDialog.close(); 0179 } 0180 } 0181 } 0182 } 0183 onClosed: addToPlaylistLoader.active = false 0184 } 0185 } 0186 0187 Component.onCompleted: videoModel.requestQuery(initialQuery) 0188 }