Warning, /plasma-bigscreen/peertube-voice-application/ui/+mediacenter/CategoryBoxViewSearch.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 "+mediacenter/views" as Views
0028 import "+mediacenter/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     onFocusChanged: {
0039         if(focus){
0040             searchBarArea.forceActiveFocus()
0041         }
0042     }
0043     
0044   function timeSanitize(sec) {
0045         var millisec = sec * 1000;
0046         var seconds = (millisec / 1000).toFixed(0);
0047         var minutes = Math.floor(seconds / 60);
0048         var hours = "";
0049         if (minutes > 59) {
0050             hours = Math.floor(minutes / 60);
0051             hours = (hours >= 10) ? hours : "0" + hours;
0052             minutes = minutes - (hours * 60);
0053             minutes = (minutes >= 10) ? minutes : "0" + minutes;
0054         }
0055 
0056         seconds = Math.floor(seconds % 60);
0057         seconds = (seconds >= 10) ? seconds : "0" + seconds;
0058         if (hours != "") {
0059             return hours + ":" + minutes + ":" + seconds;
0060         }
0061         return minutes + ":" + seconds;
0062     }
0063     
0064     function searchpTResults(query){
0065         triggerGuiEvent("PeerTube.SearchQuery", {"search_query": query})
0066         categoryLayout.currentIndex = 5
0067         searchQuery = query
0068         busyIndicatorPop.open()
0069     }
0070     
0071     function setPublishedDate(publishDate){
0072         var date1 = new Date(publishDate).getTime();
0073         var date2 = new Date().getTime();
0074         console.log(date1)
0075         console.log(date2)
0076         
0077         var msec = date2 - date1;
0078         var mins = Math.floor(msec / 60000);
0079         var hrs = Math.floor(mins / 60);
0080         var days = Math.floor(hrs / 24);
0081         var yrs = Math.floor(days / 365);
0082         mins = mins % 60;
0083         hrs = hrs % 24;
0084         days = days % 365;
0085         var result = ""
0086         if(days == 0 && hrs > 0) {
0087             result = hrs + " hours, " + mins + " minutes ago"
0088         } else if (days == 0 && hrs == 0) {
0089             result = mins + " minutes ago"
0090         } else {
0091             result = days + " days, " + hrs + " hours, " + mins + " minutes ago"
0092         }
0093         return result
0094     }
0095     
0096     function returnCategory(){
0097         switch(catName){
0098             case "News":
0099                 return homeCatButton
0100                 break
0101             case "Music":
0102                 return musicCatButton
0103                 break
0104             case "Technology":
0105                 return techCatButton
0106                 break
0107             case "Entertainment":
0108                 return entertainmentCatButton
0109                 break
0110             case "Gaming": 
0111                 return gamingCatButton
0112                 break
0113             case "Search Results":
0114                 return searchCatButton
0115                 break
0116         }
0117     }
0118     
0119     Rectangle {
0120         id: searchBarArea
0121         anchors.top: parent.top
0122         anchors.topMargin: Kirigami.Units.largeSpacing
0123         anchors.horizontalCenter: parent.horizontalCenter
0124         height: Kirigami.Units.gridUnit * 3
0125         width: miniModeState ? parent.width - Kirigami.Units.gridUnit : parent.width / 3
0126         radius: 12
0127         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)
0128                 
0129         Keys.onReturnPressed: {
0130             videoQueryBox.forceActiveFocus()
0131         }
0132         
0133         KeyNavigation.up: returnCategory()
0134         KeyNavigation.down: videoListView
0135         
0136         RowLayout {
0137             anchors.fill: parent
0138             TextField {
0139                 id: videoQueryBox
0140                 Layout.leftMargin: Kirigami.Units.largeSpacing
0141                 Layout.fillWidth: true
0142                 placeholderText: "Search here..."
0143                 Layout.fillHeight: true
0144                 text: searchQuery.length > 0 ? searchQuery : ""
0145                 onAccepted: {
0146                     searchpTResults(videoQueryBox.text)
0147                 }
0148                 KeyNavigation.down: videoListView
0149                 KeyNavigation.right: searchVideoQuery
0150                 
0151                 onTextChanged: {
0152                     searchQuery = videoQueryBox.text
0153                 }
0154             }
0155             
0156             Kirigami.Icon {
0157                 id: searchVideoQuery
0158                 Layout.preferredWidth: Kirigami.Units.gridUnit * 2
0159                 Layout.fillHeight: true
0160                 source: "search" 
0161                 KeyNavigation.left: videoQueryBox
0162                 KeyNavigation.down: videoListView
0163                 
0164                 Keys.onReturnPressed: {
0165                     searchpTResults(videoQueryBox.text)
0166                 }
0167                 
0168                 MouseArea {
0169                     anchors.fill: parent
0170                     onClicked: {
0171                         searchpTResults(videoQueryBox.text)
0172                     }
0173                 }
0174                 
0175                 ColorOverlay {
0176                     anchors.fill: parent
0177                     source: searchVideoQuery
0178                     color: Kirigami.Theme.highlightColor
0179                     visible: searchVideoQuery.activeFocus ? 1 : 0
0180                 }
0181             }
0182         }
0183     }
0184     
0185     Views.TileView {
0186         id: videoListView
0187         focus: true
0188         title: " "
0189         anchors {
0190             top: searchBarArea.bottom
0191             left: parent.left
0192             right: parent.right
0193             bottom: parent.bottom
0194         }
0195         delegate: Delegates.VideoCard {
0196             width: videoListView.cellWidth
0197             height: videoListView.cellHeight
0198         }
0199         cellWidth: cbView.responsiveCellWidth
0200         cellHeight: cellWidth / 1.8 + Kirigami.Units.gridUnit * 5
0201         KeyNavigation.up: searchBarArea
0202     }
0203 }