Warning, /utilities/mycroft-plasmoid/plasmoid/contents/ui/HintsViewComponent.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     Layout.fillWidth: true
0035     Layout.fillHeight: true
0036     color: Kirigami.Theme.backgroundColor
0037     property var modelCreatedObject
0038     
0039     Component.onCompleted: {
0040         createHintModel()
0041     }
0042 
0043     function createHintModel(){
0044         var hintList = []
0045         var defaultFold = '/opt/mycroft/skills'
0046         var fileToFind = "README.md"
0047         var getList = Mycroft.FileReader.checkForMeta(defaultFold, fileToFind)
0048         for(var i=0; i < getList.length; i++){
0049             var fileParse = Mycroft.FileReader.read(getList[i]+"/"+fileToFind);
0050             var matchedRegex = getImgSrc(fileParse)
0051             var matchedExamples = getExamples(fileParse)
0052             var matchedCategory = getCategory(fileParse)
0053             if(matchedRegex !== null && matchedRegex.length > 0 && matchedExamples !== null && matchedExamples.length > 0 && matchedCategory !== null && matchedCategory.length > 0) {
0054                 var metaFileObject = {
0055                     imgSrc: matchedRegex[1],
0056                     title: matchedRegex[2],
0057                     category: matchedCategory[1],
0058                     examples: matchedExamples
0059                 }
0060                 hintList.push(metaFileObject);
0061             }
0062         }
0063         modelCreatedObject = hintList
0064     }
0065 
0066     function getImgSrc(fileText){
0067         var re = new RegExp(/<img[^>]*src='([^']*)'.*\/>\s(.*)/g);
0068         var match = re.exec(fileText);
0069         return match;
0070     }
0071 
0072     function getExamples(fileText){
0073         var re = new RegExp(/Examples \n.*"(.*)"\n\*\s"(.*)"/g);
0074         var match = re.exec(fileText);
0075         return match;
0076     }
0077 
0078     function getCategory(fileText){
0079         var re = new RegExp(/## Category\n\*\*(.*)\*\*/g);
0080         var match = re.exec(fileText);
0081         return match;
0082     }
0083     
0084     Kirigami.CardsListView {
0085         id: skillslistmodelview
0086         anchors.fill: parent;
0087         clip: true;
0088         model: modelCreatedObject
0089         delegate: HintsView{}
0090     }
0091 }