Warning, /utilities/mycroft-plasmoid/plasmoid/contents/ui/SkillsInstallerComponent.qml is written in an unsupported language. File is not indexed.
0001 /* Copyright 2019 Aditya Mehra <aix.m@outlook.com> 0002 0003 This library is free software; you can redistribute it and/or 0004 modify it under the terms of the GNU Lesser General Public 0005 License as published by the Free Software Foundation; either 0006 version 2.1 of the License, or (at your option) version 3, or any 0007 later version accepted by the membership of KDE e.V. (or its 0008 successor approved by the membership of KDE e.V.), which shall 0009 act as a proxy defined in Section 6 of version 3 of the license. 0010 0011 This library is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 Lesser General Public License for more details. 0015 0016 You should have received a copy of the GNU Lesser General Public 0017 License along with this library. If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 0020 import QtQuick 2.9 0021 import QtQml.Models 2.2 0022 import QtQuick.Controls 2.2 0023 import QtQuick.Layouts 1.3 0024 import org.kde.plasma.core 2.0 as PlasmaCore 0025 import org.kde.plasma.plasmoid 2.0 0026 import org.kde.plasma.components 2.0 as PlasmaComponents 0027 import org.kde.plasma.components 3.0 as PlasmaComponents3 0028 import org.kde.plasma.extras 2.0 as PlasmaExtras 0029 import QtGraphicalEffects 1.0 0030 import org.kde.kirigami 2.5 as Kirigami 0031 import Mycroft 1.0 as Mycroft 0032 0033 Rectangle { 0034 id: skillsInstallerComponent 0035 Layout.fillWidth: true 0036 Layout.fillHeight: true 0037 color: Kirigami.Theme.backgroundColor 0038 property var skillList: [] 0039 0040 function refreshAllSkills(){ 0041 getSkills(); 0042 msmskillsModel.reload(); 0043 } 0044 0045 function getAllSkills(){ 0046 if(skillList.length <= 0){ 0047 getSkills(); 0048 } 0049 return skillList; 0050 } 0051 function getSkillByName(skillName){ 0052 var tempSN=[]; 0053 for(var i = 0; i <skillList.length;i++){ 0054 var sList = skillList[i].name; 0055 if(sList.indexOf(skillName) !== -1){ 0056 tempSN.push(skillList[i]); 0057 } 0058 } 0059 return tempSN; 0060 } 0061 0062 function getSkills() { 0063 var doc = new XMLHttpRequest() 0064 var url = "https://raw.githubusercontent.com/MycroftAI/mycroft-skills/20.02/.gitmodules" 0065 doc.open("GET", url, true); 0066 doc.send(); 0067 0068 doc.onreadystatechange = function() { 0069 if (doc.readyState === XMLHttpRequest.DONE) { 0070 var path, list; 0071 var tempRes = doc.responseText 0072 var moduleList = tempRes.split("["); 0073 skillList.length = 0 0074 for (var i = 1; i < moduleList.length; i++) { 0075 path = moduleList[i].substring(moduleList[i].indexOf("= ") + 2, moduleList[i].indexOf("url")).replace(/^\s+|\s+$/g, ''); 0076 url = moduleList[i].substring(moduleList[i].search("url =") + 6).replace(/^\s+|\s+$/g, ''); 0077 skillList[i-1] = {"name": path, "url": url}; 0078 msmskillsModel.reload(); 0079 } 0080 } 0081 } 0082 } 0083 0084 Item { 0085 id: msmtabtopbar 0086 width: parent.width 0087 anchors.left: parent.left 0088 anchors.right: parent.right 0089 height: units.gridUnit * 2 0090 0091 PlasmaComponents.TextField { 0092 id: msmsearchfld 0093 anchors.left: parent.left 0094 anchors.leftMargin: units.gridUnit * 0.50 0095 anchors.top: parent.top 0096 anchors.bottom: parent.bottom 0097 anchors.right: getskillsbx.left 0098 placeholderText: i18n("Search Skills") 0099 clearButtonShown: true 0100 0101 onTextChanged: { 0102 if(text.length > 0 ) { 0103 msmskillsModel.applyFilter(text.toLowerCase()); 0104 } else { 0105 msmskillsModel.reload(); 0106 } 0107 } 0108 } 0109 0110 PlasmaComponents.ToolButton { 0111 id: getskillsbx 0112 anchors.right: parent.right 0113 anchors.top: parent.top 0114 anchors.bottom: parent.bottom 0115 iconSource: "view-refresh" 0116 tooltip: i18n("Refresh List") 0117 flat: true 0118 width: Math.round(units.gridUnit * 2) 0119 height: width 0120 z: 102 0121 0122 onClicked: { 0123 msmskillsModel.clear(); 0124 refreshAllSkills(); 0125 } 0126 } 0127 } 0128 0129 ListModel { 0130 id: msmskillsModel 0131 0132 Component.onCompleted: { 0133 reload(); 0134 } 0135 0136 function reload() { 0137 var skList = getAllSkills(); 0138 msmskillsModel.clear(); 0139 for( var i=0; i < skList.length ; ++i ) { 0140 msmskillsModel.append(skList[i]); 0141 } 0142 } 0143 0144 function applyFilter(skName) { 0145 var skList = getSkillByName(skName); 0146 msmskillsModel.clear(); 0147 for( var i=0; i < skList.length ; ++i ) { 0148 msmskillsModel.append(skList[i]); 0149 } 0150 } 0151 } 0152 0153 Kirigami.CardsListView { 0154 id: msmlistView 0155 anchors.top: msmtabtopbar.bottom 0156 anchors.topMargin: Kirigami.Units.largeSpacing 0157 anchors.left: parent.left 0158 anchors.right: parent.right 0159 anchors.bottom: parent.bottom 0160 model: msmskillsModel 0161 delegate: MsmView{} 0162 clip: true; 0163 } 0164 }