Warning, /maui/clip/src/controllers/YouTube.qml is written in an unsupported language. File is not indexed.
0001 import QtQuick 2.10
0002 import QtQuick.Controls 2.10
0003 import QtQuick.Layouts 1.3
0004 import "../../view_models"
0005 import "../../view_models/BabeTable"
0006 import org.kde.kirigami 2.2 as Kirigami
0007 import org.kde.mauikit 1.0 as Maui
0008 import org.maui.vvave 1.0 as Vvave
0009 import QtWebView 1.1
0010
0011 Maui.Page
0012 {
0013 id: youtubeViewRoot
0014 property var searchRes : []
0015 clip: true
0016 property alias viewer : youtubeViewer
0017 property int openVideo : 0
0018 headBar.visible: false
0019
0020 Connections
0021 {
0022 target: Vvave.YouTube
0023 onQueryResultsReady:
0024 {
0025 searchRes = res;
0026 populate(searchRes)
0027 youtubeTable.forceActiveFocus()
0028
0029 if(openVideo > 0)
0030 {
0031 console.log("trying to open video")
0032 watchVideo(youtubeTable.model.get(openVideo-1))
0033 openVideo = 0
0034 }
0035 }
0036 }
0037
0038
0039 /*this is for playing the track sin the background without showing the actual video*/
0040
0041 WebView
0042 {
0043 id: webView
0044 anchors.fill: parent
0045 visible: false
0046 clip: true
0047 property bool wasPlaying: false
0048
0049 onLoadingChanged:
0050 {
0051 if (loadRequest.errorString)
0052 console.error(loadRequest.errorString);
0053 }
0054
0055 // onRecentlyAudibleChanged:
0056 // {
0057 // console.log("is playing", recentlyAudible)
0058 // if(recentlyAudible && isPlaying)
0059 // Player.pauseTrack()
0060
0061 // if(!recentlyAudible && wasPlaying)
0062 // Player.resumeTrack()
0063 // }
0064 }
0065
0066 Maui.Dialog
0067 {
0068 id: configPopup
0069 parent: parent
0070 page.margins: Maui.Style.contentMargins
0071 widthHint: 0.9
0072 heightHint: 0.9
0073
0074 maxHeight: 200
0075 maxWidth: 300
0076 defaultButtons: false
0077
0078 GridLayout
0079 {
0080 anchors.fill: parent
0081 columns: 1
0082 rows: 6
0083 clip: true
0084
0085 Item
0086 {
0087 Layout.column: 1
0088 Layout.row: 1
0089 Layout.fillWidth: true
0090 Layout.fillHeight: true
0091 }
0092
0093 Label
0094 {
0095 text: i18n("Custom API Key")
0096 verticalAlignment: Qt.AlignVCenter
0097 elide: Text.ElideRight
0098 font.pointSize: Maui.Style.fontSizes.default
0099 Layout.column: 1
0100 Layout.row: 2
0101 Layout.fillWidth: true
0102 }
0103
0104 TextField
0105 {
0106 Layout.column: 1
0107 Layout.row: 3
0108 Layout.fillWidth: true
0109 text: Maui.FM.loadSettings("YOUTUBEKEY", "BABE", Vvave.YouTube.getKey())
0110 }
0111
0112 Label
0113 {
0114 text: i18n("Search results")
0115 verticalAlignment: Qt.AlignVCenter
0116 elide: Text.ElideRight
0117 font.pointSize: Maui.Style.fontSizes.default
0118 Layout.column: 1
0119 Layout.row: 4
0120 Layout.fillWidth: true
0121 }
0122
0123 SpinBox
0124 {
0125 Layout.alignment: Qt.AlignRight
0126 Layout.column: 1
0127 Layout.row: 5
0128 Layout.fillWidth: true
0129 from: 1
0130 to: 50
0131 value: Maui.FM.loadSettings("YOUTUBELIMIT", "BABE", 25)
0132 editable: true
0133 onValueChanged:
0134 {
0135 Maui.FM.saveSettings("YOUTUBELIMIT", value, "BABE")
0136 }
0137 }
0138
0139 Item
0140 {
0141 Layout.column: 1
0142 Layout.row: 6
0143 Layout.fillWidth: true
0144 Layout.fillHeight: true
0145 }
0146
0147 }
0148 }
0149
0150
0151 StackView
0152 {
0153 id: stackView
0154 anchors.fill: parent
0155 focus: true
0156
0157 pushEnter: Transition
0158 {
0159 PropertyAnimation
0160 {
0161 property: "opacity"
0162 from: 0
0163 to:1
0164 duration: 200
0165 }
0166 }
0167
0168 pushExit: Transition
0169 {
0170 PropertyAnimation
0171 {
0172 property: "opacity"
0173 from: 1
0174 to:0
0175 duration: 200
0176 }
0177 }
0178
0179 popEnter: Transition
0180 {
0181 PropertyAnimation {
0182 property: "opacity"
0183 from: 0
0184 to:1
0185 duration: 200
0186 }
0187 }
0188
0189 popExit: Transition
0190 {
0191 PropertyAnimation
0192 {
0193 property: "opacity"
0194 from: 1
0195 to:0
0196 duration: 200
0197 }
0198 }
0199
0200
0201 initialItem: BabeTable
0202 {
0203 id: youtubeTable
0204 trackNumberVisible: false
0205 headBar.visible: false
0206 holder.visible: count === 0
0207 holder.emoji: "qrc:/assets/dialog-information.svg"
0208 holder.isMask: true
0209 holder.title : i18n("No Results!")
0210 holder.body: i18n("Try with another query")
0211 holder.emojiSize: Maui.Style.iconSizes.huge
0212 coverArtVisible: true
0213 model: ListModel{}
0214 onRowClicked:
0215 {
0216 watchVideo(youtubeTable.model.get(index))
0217 }
0218
0219 onQuickPlayTrack:
0220 {
0221 playTrack(youtubeTable.model.get(index).url)
0222 }
0223 }
0224
0225 YoutubeViewer
0226 {
0227 id: youtubeViewer
0228 }
0229 }
0230
0231 footBar.leftContent: ToolButton
0232 {
0233 id: menuBtn
0234 icon.name: "application-menu"
0235 onClicked: configPopup.open()
0236 }
0237
0238 footBar.rightContent: ToolButton
0239 {
0240 icon.name: "edit-clear"
0241 onClicked: clearSearch()
0242 }
0243
0244 footBar.middleContent: Maui.TextField
0245 {
0246 id: searchInput
0247 Layout.fillWidth: true
0248
0249 placeholderText: i18n("Search videos...")
0250 wrapMode: TextEdit.Wrap
0251 onAccepted: runSearch(searchInput.text)
0252 }
0253
0254 function watchVideo(track)
0255 {
0256 if(track && track.url)
0257 {
0258 var url = track.url
0259 if(url && url.length > 0)
0260 {
0261 youtubeViewer.currentYt = track
0262 youtubeViewer.webView.url = url+"?autoplay=1"
0263 stackView.push(youtubeViewer)
0264
0265 }
0266 }
0267 }
0268
0269 function playTrack(url)
0270 {
0271 if(url && url.length > 0)
0272 {
0273 var newURL = url.replace("embed/", "watch?v=")
0274 console.log(newURL)
0275 webView.url = newURL+"?autoplay=1+&vq=tiny"
0276 webView.runJavaScript("document.title", function(result) { console.log(result); });
0277 }
0278 }
0279
0280 function runSearch(searchTxt)
0281 {
0282 if(searchTxt)
0283 if(searchTxt !== youtubeTable.title)
0284 {
0285 youtubeTable.title = searchTxt
0286 Vvave.YouTube.getQuery(searchTxt, Maui.FM.loadSettings("YOUTUBELIMIT", "BABE", 25))
0287 }
0288 }
0289
0290 function clearSearch()
0291 {
0292 searchInput.clear()
0293 youtubeTable.listView.model.clear()
0294 youtubeTable.title = ""
0295 searchRes = []
0296 }
0297
0298 function populate(tracks)
0299 {
0300 youtubeTable.model.clear()
0301 for(var i in tracks)
0302 youtubeTable.model.append(tracks[i])
0303 }
0304 }