Warning, /plasma-bigscreen/mycroft-skill-installer/app/qml/InstallerView.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  *   SPDX-FileCopyrightText: 2019-2020 Aditya Mehra <aix.m@outlook.org>
0003  *
0004  *   SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 import QtQuick 2.9
0008 import QtQml.Models 2.3
0009 import QtQuick.Controls 2.3
0010 import QtQuick.Layouts 1.3
0011 import org.kde.mycroft.bigscreen 1.0 as BigScreen
0012 import org.kde.kirigami 2.12 as Kirigami
0013 import org.kde.plasma.components 3.0 as PlasmaComponents3
0014 import QMLTermWidget 1.0
0015 import SysInfo 1.0
0016 import QtGraphicalEffects 1.0
0017 import InstallerListModel 1.0
0018 import "delegates" as Delegates
0019 
0020 import "code/SkillUtils.js" as SkillUtils
0021 import "code/Installer.js" as Installer
0022 
0023 Kirigami.Page {
0024     id: mainPageComponent
0025     title: "Mycroft Skill Installer"
0026     property alias skillView: lview.view
0027     property bool lviewFirstItem: lview.view.currentIndex != 0 ? 1 : 0
0028 
0029     background: Rectangle {
0030         color: Qt.rgba(0,0,0,0.8)
0031     }
0032 
0033     function updateInstallerModel(){
0034         modelInstaller.reloadJsonModel()
0035     }
0036 
0037     function fetchLatestInstallerModel(){
0038         modelInstaller.fetchLatestForCurrentModel()
0039     }
0040 
0041     Rectangle {
0042         id: viewBusyOverlay
0043         z: 300
0044         anchors.fill: parent
0045         visible: false
0046         enabled: visible
0047         color: Qt.rgba(0, 0, 0, 0.8)
0048 
0049         PlasmaComponents3.BusyIndicator {
0050             id: viewBusyIndicator
0051             visible: viewBusyOverlay.visible
0052             anchors.centerIn: parent
0053             running: viewBusyOverlay.visible
0054             enabled: viewBusyOverlay.visible
0055 
0056             Label {
0057                 id: viewBusyIndicatorLabel
0058                 visible: viewBusyOverlay.visible
0059                 enabled: viewBusyOverlay.visible
0060                 anchors.top: parent.bottom
0061                 anchors.horizontalCenter: parent.horizontalCenter
0062                 text: "Loading Skills"
0063             }
0064         }
0065     }
0066 
0067     InstallerListModel {
0068         id: modelInstaller
0069         url: informationModel.categoryURL
0070         query: "data"
0071         roles: ["id", "name", "description", "downloadlink1", "previewpic1", "typename", "personid", "downloads", "itemInstallStatus", "itemUpdateStatus", "url", "branch", "warning", "desktopFile", "examples", "platforms", "systemDeps", "authorname", "skillname", "foldername"]
0072 
0073         onDownloadingModelUpdated: {
0074             if(modelInstaller.downloadingModel()){
0075                 viewBusyOverlay.visible = true
0076                 viewBusyIndicatorLabel.text = "Downloading Skills"
0077             }
0078         }
0079 
0080         onCreatingModelUpdated: {
0081             if(modelInstaller.creatingModel()){
0082                 viewBusyOverlay.visible = true
0083                 viewBusyIndicatorLabel.text = "Checking For Updates " + modelInstaller.updatingModelCounter() + "/" + modelInstaller.completeModelCounter()
0084             }
0085         }
0086 
0087         onModelUpdated: {
0088             viewBusyOverlay.visible = false
0089             viewBusyIndicatorLabel.text = ""
0090             SkillUtils.fillListModel()
0091         }
0092 
0093         Component.onCompleted: {
0094             informationModel.categoryURL = modelInstaller.getCurrentCategory()
0095             if(modelInstaller.downloadingModel()){
0096                 viewBusyOverlay.visible = true
0097                 viewBusyIndicatorLabel.text = "Downloading Skills"
0098             }
0099         }
0100     }
0101 
0102     ColumnLayout {
0103         anchors.fill: parent
0104 
0105         RowLayout {
0106             Layout.fillWidth: true
0107             Layout.maximumHeight: Kirigami.Units.gridUnit * 2
0108 
0109             PlasmaComponents3.ComboBox {
0110                 id: categorySelector
0111                 displayText: "Category: " + currentText
0112                 Layout.preferredWidth: parent.width * 0.20
0113                 Layout.fillHeight: true
0114                 model: [ "All Skills", "Configuration", "Entertainment", "Information", "Productivity" ]
0115                 leftPadding: Kirigami.Units.gridUnit
0116                 rightPadding: Kirigami.Units.gridUnit
0117                 currentIndex: 0
0118 
0119                 Keys.onDownPressed: {
0120                     lview.currentItem.forceActiveFocus()
0121                 }
0122                 Keys.onReturnPressed: {
0123                     categorySelector.popup.open()
0124                     categorySelector.popup.forceActiveFocus()
0125                 }
0126 
0127                 KeyNavigation.right: sortByRatingBtn
0128 
0129                 delegate: ItemDelegate {
0130 
0131                     background: Rectangle {
0132                         anchors.fill: parent
0133                         color: "transparent"
0134                     }
0135 
0136                     contentItem: Kirigami.Heading{
0137                         level: 2
0138                         text: modelData
0139                     }
0140                 }
0141 
0142                 indicator: Kirigami.Icon {
0143                     width: Kirigami.Units.iconSizes.small
0144                     height: Kirigami.Units.iconSizes.small
0145                     x: 0
0146                     y: categorySelector.topPadding + (categorySelector.availableHeight - height) / 2
0147                     source: categorySelector.popup.opened ? "arrow-up" : "arrow-down"
0148                 }
0149 
0150                 background: Rectangle {
0151                     anchors.fill: parent
0152                     anchors.rightMargin: -Kirigami.Units.gridUnit * 4
0153                     color: categorySelector.focus ? Kirigami.Theme.highlightColor : "transparent"
0154                 }
0155 
0156                 contentItem: Kirigami.Heading {
0157                     level: 2
0158                     text: categorySelector.displayText
0159                 }
0160 
0161                 popup: Popup {
0162                     y: categorySelector.height - 1
0163                     width: categorySelector.width
0164                     implicitHeight: contentItem.implicitHeight
0165                     padding: 1
0166 
0167                     onVisibleChanged: {
0168                         if(visible){
0169                             pCView.forceActiveFocus()
0170                         }
0171                     }
0172 
0173                     contentItem: ListView {
0174                         id: pCView
0175                         clip: true
0176                         implicitHeight: contentHeight
0177                         model: categorySelector.popup.visible ? categorySelector.delegateModel : null
0178                         currentIndex: categorySelector.highlightedIndex
0179                         keyNavigationEnabled: true
0180                         highlight: informationModel.highlighter
0181                         highlightFollowsCurrentItem: true
0182                         snapMode: ListView.SnapToItem
0183 
0184                         Keys.onReturnPressed: {
0185                             console.log(currentIndex)
0186                             categorySelector.currentIndex = pCView.currentIndex
0187                             categorySelector.popup.close()
0188                             lview.forceActiveFocus()
0189                         }
0190                     }
0191 
0192                     background: Rectangle {
0193                         anchors {
0194                             fill: parent
0195                             margins: -1
0196                         }
0197                         color: Kirigami.Theme.backgroundColor
0198                         border.color: Kirigami.Theme.backgroundColor
0199                         radius: 2
0200                         layer.enabled: true
0201 
0202                         layer.effect: DropShadow {
0203                             transparentBorder: true
0204                             radius: 4
0205                             samples: 8
0206                             horizontalOffset: 2
0207                             verticalOffset: 2
0208                             color: Qt.rgba(0, 0, 0, 0.3)
0209                         }
0210                     }
0211                 }
0212 
0213                 onCurrentIndexChanged: {
0214                     modelInstaller.setCategoryBrowser(currentIndex)
0215 
0216                     if(informationModel.categoryURL != ""){
0217                         if(informationModel.categoryURL !== modelInstaller.getCurrentCategory()){
0218                             informationModel.categoryURL = modelInstaller.getCurrentCategory()
0219                         }
0220                     }
0221 
0222                     lview.forceActiveFocus()
0223                 }
0224             }
0225             Item {
0226                 Layout.fillWidth: true
0227                 Layout.fillHeight: true
0228             }
0229             PlasmaComponents3.Button {
0230                 id: sortByRatingBtn
0231                 Layout.preferredWidth: parent.width * 0.14
0232                 Layout.fillHeight: true
0233                 text: "Sort By Rating"
0234                 icon.name: "view-sort"
0235                 KeyNavigation.down: lview
0236                 KeyNavigation.right: sortByNameBtn
0237 
0238                 Keys.onReturnPressed: {
0239                     clicked()
0240                 }
0241 
0242                 onClicked:{
0243                     sortModel.sortColumnName = "downloads"
0244                     sortModel.order = "desc"
0245                     sortModel.quick_sort()
0246                 }
0247             }
0248 
0249             PlasmaComponents3.Button {
0250                 id: sortByNameBtn
0251                 Layout.preferredWidth: parent.width * 0.14
0252                 Layout.fillHeight: true
0253                 text: "Sort By Name"
0254                 icon.name: "view-sort"
0255                 KeyNavigation.down: lview
0256                 KeyNavigation.right: sortByInstalledBtn
0257                 KeyNavigation.left: sortByRatingBtn
0258 
0259                 Keys.onReturnPressed: {
0260                     clicked()
0261                 }
0262 
0263                 onClicked: {
0264                     sortModel.sortColumnName = "name"
0265                     sortModel.order = "asc"
0266                     sortModel.quick_sort()
0267                 }
0268             }
0269 
0270             PlasmaComponents3.Button {
0271                 id: sortByInstalledBtn
0272                 Layout.preferredWidth: parent.width * 0.14
0273                 Layout.fillHeight: true
0274                 text: "Sort Installed"
0275                 icon.name: "view-sort"
0276                 KeyNavigation.down: lview
0277                 KeyNavigation.right: sortByDefaultBtn
0278                 KeyNavigation.left: sortByNameBtn
0279 
0280                 Keys.onReturnPressed: {
0281                     clicked()
0282                 }
0283 
0284                 onClicked: {
0285                     sortModel.sortColumnName = "itemInstallStatus"
0286                     sortModel.order = "desc"
0287                     sortModel.quick_sort()
0288                 }
0289             }
0290 
0291             PlasmaComponents3.Button {
0292                 id: sortByDefaultBtn
0293                 Layout.preferredWidth: parent.width * 0.14
0294                 Layout.fillHeight: true
0295                 text: "Sort Default"
0296                 icon.name: "view-sort"
0297                 KeyNavigation.down: lview
0298                 KeyNavigation.left: sortByInstalledBtn
0299 
0300                 Keys.onReturnPressed: {
0301                     clicked()
0302                 }
0303 
0304                 onClicked: {
0305                     sortModel.sortColumnName = ""
0306                     sortModel.quick_sort()
0307                 }
0308             }
0309         }
0310 
0311         Kirigami.Separator {
0312             Layout.fillWidth: true
0313             Layout.preferredHeight: 1
0314         }
0315 
0316         Item {
0317             Layout.fillWidth: true
0318             Layout.fillHeight: true
0319 
0320             Kirigami.ShadowedRectangle {
0321                 id: leftArrow
0322                 color: Kirigami.Theme.backgroundColor
0323                 width: Kirigami.Units.iconSizes.large
0324                 height: Kirigami.Units.iconSizes.large
0325                 anchors.verticalCenter: parent.verticalCenter
0326                 anchors.left: parent.left
0327                 radius: width
0328                 anchors.leftMargin: Kirigami.Units.largeSpacing
0329                 enabled: lviewFirstItem
0330                 opacity: lviewFirstItem ? 1 : 0.4
0331 
0332                 shadow {
0333                     size: Kirigami.Units.largeSpacing * 2
0334                 }
0335 
0336                 Kirigami.Icon {
0337                     source: "arrow-left"
0338                     width: Kirigami.Units.iconSizes.medium
0339                     height: Kirigami.Units.iconSizes.medium
0340                     anchors.centerIn: parent
0341                     enabled: lviewFirstItem
0342                     opacity: lviewFirstItem ? 1 : 0.4
0343                 }
0344             }
0345 
0346             Rectangle {
0347                 anchors.left: leftArrow.right
0348                 anchors.leftMargin: Kirigami.Units.largeSpacing
0349                 anchors.right: rightArrow.left
0350                 anchors.rightMargin: Kirigami.Units.largeSpacing
0351                 height: parent.height
0352                 color: "transparent"
0353                 clip: true
0354 
0355                 SortFilterModel {
0356                     id: sortModel
0357                 }
0358 
0359                 BigScreen.TileView {
0360                     id: lview
0361                     focus: true
0362                     model: sortModel
0363                     title: " "
0364                     cellWidth: parent.width / 4
0365                     anchors.left: parent.left
0366                     anchors.leftMargin: Kirigami.Units.gridUnit
0367                     width: parent.width
0368                     height: parent.height
0369 
0370                     property string mbranch
0371                     property string mfolderName
0372                     property string mskillName
0373                     property string mauthorName
0374                     property string mskillUrl
0375                     property string mskillFolderPath
0376                     property bool mdesktopFile
0377                     property bool mskillInstalled
0378                     property bool mSystemDeps
0379                     property int lastIndex
0380 
0381                     delegate: Delegates.TileDelegate {}
0382 
0383                     function resetCIndex(){
0384                         lview.currentIndex = 0
0385                     }
0386 
0387                     onModelChanged: {
0388                         lview.update()
0389                         lview.currentIndex = 0
0390                     }
0391 
0392                     function setItem() {
0393                         installerBox.skillInfo = lview.currentItem.skillInfo
0394                         if(lview.currentItem.skillInfo){
0395                             mbranch = lview.currentItem.skillInfo.branch
0396                             mfolderName = String(lview.currentItem.skillInfo.folderName).toLowerCase()
0397                             mskillName = String(lview.currentItem.skillInfo.skillName).toLowerCase()
0398                             mauthorName = String(lview.currentItem.skillInfo.authorName).toLowerCase()
0399                             mskillUrl = lview.currentItem.skillInfo.skillUrl
0400                             mskillFolderPath = lview.currentItem.skillInfo.skillFolderPath
0401                             mdesktopFile = lview.currentItem.skillInfo.desktopFile
0402                             mskillInstalled = lview.currentItem.skillInfo.skillInstalled
0403                             mSystemDeps = lview.currentItem.skillInfo.systemDeps
0404 
0405                             console.log("Check Upper Case Issue " + mauthorName)
0406                         }
0407                     }
0408 
0409                     navigationUp: categorySelector
0410                     navigationDown: footerArea
0411                 }
0412             }
0413 
0414             Kirigami.ShadowedRectangle {
0415                 id: rightArrow
0416                 color: Kirigami.Theme.backgroundColor
0417                 width: Kirigami.Units.iconSizes.large
0418                 height: Kirigami.Units.iconSizes.large
0419                 anchors.verticalCenter: parent.verticalCenter
0420                 anchors.rightMargin: Kirigami.Units.largeSpacing
0421                 anchors.right: parent.right
0422                 radius: width
0423                 enabled: lview.currentIndex != (lview.view.count - 1) ? 1 : 0
0424                 opacity: lview.currentIndex != (lview.view.count - 1) ? 1 : 0.4
0425 
0426                 shadow {
0427                     size: Kirigami.Units.largeSpacing * 2
0428                 }
0429 
0430                 Kirigami.Icon {
0431                     source: "arrow-right"
0432                     width: Kirigami.Units.iconSizes.medium
0433                     height: Kirigami.Units.iconSizes.medium
0434                     anchors.centerIn: parent
0435                     enabled: lview.currentIndex != (lview.view.count - 1) ? 1 : 0
0436                     opacity: lview.currentIndex != (lview.view.count - 1) ? 1 : 0.4
0437                 }
0438             }
0439         }
0440     }
0441 
0442     InstallerBox {
0443         id: installerBox
0444     }
0445 
0446     InstallerArea {
0447         id: installerArea
0448     }
0449 }