Warning, /plasma-bigscreen/peertube-voice-application/ui/CategoryBoxView.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * Copyright 2018 by Aditya Mehra <aix.m@outlook.com> 0003 * 0004 * This program is free software: you can redistribute it and/or modify 0005 * it under the terms of the GNU General Public License as published by 0006 * the Free Software Foundation, either version 3 of the License, or 0007 * (at your option) any later version. 0008 0009 * This program is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 * GNU General Public License for more details. 0013 0014 * You should have received a copy of the GNU General Public License 0015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0016 */ 0017 0018 import QtQuick 2.9 0019 import QtQuick.Layouts 1.4 0020 import QtGraphicalEffects 1.0 0021 import QtQuick.Controls 2.3 0022 import org.kde.kirigami 2.8 as Kirigami 0023 import org.kde.plasma.core 2.0 as PlasmaCore 0024 import org.kde.plasma.components 3.0 as PlasmaComponents3 0025 import org.kde.plasma.components 2.0 as PlasmaComponents 0026 import Mycroft 1.0 as Mycroft 0027 import "views" as Views 0028 import "delegates" as Delegates 0029 0030 Item { 0031 id: cbView 0032 property alias model: videoListView.model 0033 Layout.fillWidth: true 0034 Layout.fillHeight: true 0035 readonly property int responsiveCellWidth: width >= 800 ? videoListView.view.width / 4 : videoListView.view.width / 2 0036 readonly property bool miniModeState: delegate.delegateMiniMode 0037 0038 states: [ 0039 State { 0040 name: "miniModeType" 0041 0042 AnchorChanges { 0043 target: videoListView 0044 anchors.top: cbView.top 0045 } 0046 }, 0047 State { 0048 name: "maxModeType" 0049 0050 AnchorChanges { 0051 target: videoListView 0052 anchors.top: searchBarArea.bottom 0053 } 0054 } 0055 ] 0056 0057 onMiniModeStateChanged: { 0058 if(miniModeState) { 0059 cbView.state = "miniModeType" 0060 } else { 0061 cbView.state = "maxModeType" 0062 } 0063 } 0064 0065 onFocusChanged: { 0066 if(focus && !delegate.delegateMiniMode){ 0067 searchBarArea.forceActiveFocus() 0068 } else if(focus && delegate.delegateMiniMode){ 0069 videoListView.forceActiveFocus() 0070 } 0071 } 0072 0073 function timeSanitize(sec) { 0074 var millisec = sec * 1000; 0075 var seconds = (millisec / 1000).toFixed(0); 0076 var minutes = Math.floor(seconds / 60); 0077 var hours = ""; 0078 if (minutes > 59) { 0079 hours = Math.floor(minutes / 60); 0080 hours = (hours >= 10) ? hours : "0" + hours; 0081 minutes = minutes - (hours * 60); 0082 minutes = (minutes >= 10) ? minutes : "0" + minutes; 0083 } 0084 0085 seconds = Math.floor(seconds % 60); 0086 seconds = (seconds >= 10) ? seconds : "0" + seconds; 0087 if (hours != "") { 0088 return hours + ":" + minutes + ":" + seconds; 0089 } 0090 return minutes + ":" + seconds; 0091 } 0092 0093 function searchpTResults(query){ 0094 triggerGuiEvent("PeerTube.SearchQuery", {"search_query": query}) 0095 categoryLayout.currentIndex = 5 0096 searchQuery = query 0097 busyIndicatorPop.open() 0098 } 0099 0100 function setPublishedDate(publishDate){ 0101 var date1 = new Date(publishDate).getTime(); 0102 var date2 = new Date().getTime(); 0103 console.log(date1) 0104 console.log(date2) 0105 0106 var msec = date2 - date1; 0107 var mins = Math.floor(msec / 60000); 0108 var hrs = Math.floor(mins / 60); 0109 var days = Math.floor(hrs / 24); 0110 var yrs = Math.floor(days / 365); 0111 mins = mins % 60; 0112 hrs = hrs % 24; 0113 days = days % 365; 0114 var result = "" 0115 if(days == 0 && hrs > 0) { 0116 result = hrs + " hours, " + mins + " minutes ago" 0117 } else if (days == 0 && hrs == 0) { 0118 result = mins + " minutes ago" 0119 } else { 0120 result = days + " days, " + hrs + " hours, " + mins + " minutes ago" 0121 } 0122 return result 0123 } 0124 0125 function returnCategory(){ 0126 switch(catName){ 0127 case "News": 0128 return homeCatButton 0129 break 0130 case "Music": 0131 return musicCatButton 0132 break 0133 case "Technology": 0134 return techCatButton 0135 break 0136 case "Entertainment": 0137 return entertainmentCatButton 0138 break 0139 case "Gaming": 0140 return gamingCatButton 0141 break 0142 case "Search Results": 0143 return searchCatButton 0144 break 0145 } 0146 } 0147 0148 Rectangle { 0149 id: searchBarArea 0150 anchors.top: parent.top 0151 anchors.topMargin: Kirigami.Units.largeSpacing 0152 anchors.horizontalCenter: parent.horizontalCenter 0153 height: !delegate.delegateMiniMode ? Kirigami.Units.gridUnit * 3 : 0 0154 width: parent.width / 3 0155 radius: 12 0156 color: searchBarArea.activeFocus ? Qt.rgba(Kirigami.Theme.highlightColor.r, Kirigami.Theme.highlightColor.g, Kirigami.Theme.highlightColor.b, 0.95) : Qt.rgba(Kirigami.Theme.backgroundColor.r, Kirigami.Theme.backgroundColor.g, Kirigami.Theme.backgroundColor.b, 0.95) 0157 visible: !delegate.delegateMiniMode 0158 enabled: !delegate.delegateMiniMode 0159 0160 Keys.onReturnPressed: { 0161 videoQueryBox.forceActiveFocus() 0162 } 0163 0164 KeyNavigation.up: returnCategory() 0165 KeyNavigation.down: videoListView 0166 0167 RowLayout { 0168 anchors.fill: parent 0169 TextField { 0170 id: videoQueryBox 0171 Layout.leftMargin: Kirigami.Units.largeSpacing 0172 Layout.fillWidth: true 0173 placeholderText: "Search here..." 0174 Layout.fillHeight: true 0175 text: searchQuery.length > 0 ? searchQuery : "" 0176 onAccepted: { 0177 searchpTResults(videoQueryBox.text) 0178 } 0179 KeyNavigation.down: videoListView 0180 KeyNavigation.right: searchVideoQuery 0181 0182 onTextChanged: { 0183 searchQuery = videoQueryBox.text 0184 } 0185 } 0186 0187 Kirigami.Icon { 0188 id: searchVideoQuery 0189 Layout.preferredWidth: Kirigami.Units.gridUnit * 2 0190 Layout.fillHeight: true 0191 source: "search" 0192 KeyNavigation.left: videoQueryBox 0193 KeyNavigation.down: videoListView 0194 0195 Keys.onReturnPressed: { 0196 searchpTResults(videoQueryBox.text) 0197 } 0198 0199 MouseArea { 0200 anchors.fill: parent 0201 onClicked: { 0202 searchpTResults(videoQueryBox.text) 0203 } 0204 } 0205 0206 ColorOverlay { 0207 anchors.fill: parent 0208 source: searchVideoQuery 0209 color: Kirigami.Theme.highlightColor 0210 visible: searchVideoQuery.activeFocus ? 1 : 0 0211 } 0212 } 0213 } 0214 } 0215 0216 Views.TileView { 0217 id: videoListView 0218 focus: true 0219 anchors { 0220 top: searchBarArea.bottom 0221 left: parent.left 0222 right: parent.right 0223 bottom: parent.bottom 0224 } 0225 delegate: Delegates.VideoCard { 0226 width: videoListView.cellWidth 0227 height: videoListView.cellHeight 0228 } 0229 cellWidth: cbView.responsiveCellWidth 0230 cellHeight: cellWidth / 1.8 + Kirigami.Units.gridUnit * 5 0231 KeyNavigation.up: searchBarArea 0232 } 0233 }