Warning, /system/mycroft-gui/application/HintsPage.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * Copyright 2018 Marco Martin <mart@kde.org> 0003 * Copyright 2018 by Aditya Mehra <aix.m@outlook.com> 0004 * 0005 * Licensed under the Apache License, Version 2.0 (the "License"); 0006 * you may not use this file except in compliance with the License. 0007 * You may obtain a copy of the License at 0008 * 0009 * http://www.apache.org/licenses/LICENSE-2.0 0010 * 0011 * Unless required by applicable law or agreed to in writing, software 0012 * distributed under the License is distributed on an "AS IS" BASIS, 0013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0014 * See the License for the specific language governing permissions and 0015 * limitations under the License. 0016 * 0017 */ 0018 0019 import QtQuick 2.15 0020 import QtQuick.Layouts 1.15 0021 import QtQuick.Controls 2.15 as QQC2 0022 import org.kde.kirigami 2.19 as Kirigami 0023 import Mycroft 1.0 as Mycroft 0024 import Qt5Compat.GraphicalEffects 0025 0026 Kirigami.Page { 0027 title: "Hints" 0028 objectName: "hints" 0029 property var modelCreatedObject 0030 property var filteredModel 0031 0032 Component.onCompleted: { 0033 createHintModel() 0034 } 0035 0036 function createHintModel(){ 0037 var hintList = [] 0038 var defaultFold = '/opt/mycroft/skills' 0039 var fileToFind = "README.md" 0040 var getList = Mycroft.FileReader.checkForMeta(defaultFold, fileToFind) 0041 for(var i=0; i < getList.length; i++){ 0042 var fileName = getList[i] + "/" + fileToFind; 0043 var fileParse = Mycroft.FileReader.read(fileName); 0044 console.log("Loading hints from", fileName); 0045 var matchedRegex = getDataFromRegex(fileName, fileParse, /<img[^>]*src='([^']*)'.*\/>\s(.*)/g) 0046 var matchedExamples = getDataFromRegex(fileName, fileParse, /## Examples.*\n.*"(.*)"\n\*\s"(.*)"/g) 0047 var matchedCategory = getDataFromRegex(fileName, fileParse, /## Category.*\n\*\*(.*)\*\*/g) 0048 if(matchedRegex !== null && matchedRegex.length > 0 && matchedExamples !== null && matchedExamples.length > 0 && matchedCategory !== null && matchedCategory.length > 0) { 0049 console.log("All good. \n"); 0050 var metaFileObject = { 0051 imgSrc: matchedRegex[1], 0052 title: matchedRegex[2], 0053 category: matchedCategory[1], 0054 examples: matchedExamples 0055 } 0056 hintList.push(metaFileObject); 0057 } 0058 } 0059 modelCreatedObject = hintList 0060 filteredModel = modelCreatedObject 0061 } 0062 0063 function getDataFromRegex(fileName, fileText, matchRegex){ 0064 var re = new RegExp(matchRegex); 0065 var match = re.exec(fileText); 0066 if (match === null || match.length == 0) { 0067 console.log("README.md file is not properly defined, it's missing data for the following regex:"); 0068 console.log(re); 0069 console.log("Please fix the README.md file of the skill"); 0070 console.log("This warning is for skill developers"); 0071 console.log("if you are not a developer, fill a bug on the corresponding skill.\n"); 0072 } 0073 return match; 0074 } 0075 0076 function filterModel(text) { 0077 var result = [] 0078 for (var i = 0; i < modelCreatedObject.length; i++) { 0079 var obj = modelCreatedObject[i]; 0080 if (obj.title.toLowerCase().includes(text) 0081 || obj.category.toLowerCase().includes(text) 0082 || obj.examples[0].toLowerCase().includes(text) 0083 || obj.examples[1].toLowerCase().includes(text)) { 0084 result.push(obj) 0085 } 0086 } 0087 return result; 0088 } 0089 0090 ColumnLayout { 0091 anchors.fill: parent 0092 0093 QQC2.TextField { 0094 id: filterHints 0095 placeholderText: qsTr("Search:") 0096 Layout.fillWidth: true 0097 onTextChanged: { 0098 filteredModel = filterModel(text.toLowerCase()) 0099 } 0100 } 0101 0102 Kirigami.ScrollablePage { 0103 Layout.fillWidth: true 0104 Layout.fillHeight: true 0105 Kirigami.CardsListView { 0106 id: skillslistmodelview 0107 clip: true; 0108 model: filteredModel 0109 anchors.fill: parent 0110 0111 delegate: HintsDelegate { 0112 imageSource: modelData.imgSrc 0113 title: modelData.title 0114 examples: modelData.examples 0115 category: modelData.category 0116 } 0117 } 0118 } 0119 } 0120 }