diff --git a/plasmoid/contents/ui/HintsView.qml b/plasmoid/contents/ui/HintsView.qml index 9c07d7a..2bfe91f 100644 --- a/plasmoid/contents/ui/HintsView.qml +++ b/plasmoid/contents/ui/HintsView.qml @@ -1,156 +1,74 @@ -/* Copyright 2016 Aditya Mehra - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) version 3, or any - later version accepted by the membership of KDE e.V. (or its - successor approved by the membership of KDE e.V.), which shall - act as a proxy defined in Section 6 of version 3 of the license. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library. If not, see . -*/ - import QtQuick 2.9 +import QtQml.Models 2.2 +import QtQuick.Controls 2.2 as Controls import QtQuick.Layouts 1.3 -import QtQuick.Controls 2.2 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.components 2.0 as PlasmaComponents +import org.kde.plasma.components 3.0 as PlasmaComponents3 import org.kde.plasma.extras 2.0 as PlasmaExtras -import org.kde.private.mycroftplasmoid 1.0 as PlasmaLa +import QtGraphicalEffects 1.0 import org.kde.kirigami 2.5 as Kirigami import Mycroft 1.0 as Mycroft -Rectangle { - id: tipscontent - height: Kirigami.Units.gridUnit * 5 - anchors.left: parent.left - anchors.right: parent.right - border.width: 1 - border.color: Qt.darker(theme.linkColor, 1.2) - color: Qt.darker(theme.backgroundColor, 1.2) - - RowLayout { - anchors.fill: parent - - Image { - id: innerskImg - source: Pic - Layout.preferredWidth: Kirigami.Units.gridUnit * 1.2 - Layout.preferredHeight: Kirigami.Units.gridUnit * 1.2 - Layout.alignment: Qt.AlignLeft - Layout.leftMargin: units.gridUnit * 0.25 - } - - PlasmaCore.SvgItem { - Layout.preferredWidth: lineskillpgSvg.elementSize("vertical-line").width - Layout.fillHeight: true - z: 110 - elementId: "vertical-line" - - svg: PlasmaCore.Svg { - id: lineskillpgSvg; - imagePath: "widgets/line" - } - } - - Item { - id: skilltipsinner - Layout.fillWidth: true - Layout.fillHeight: true - - ColumnLayout { - id: innerskillscolumn - anchors.fill: parent - - PlasmaComponents.Label { - id: innerskllname - Layout.fillWidth: true - wrapMode: Text.WordWrap; - font.bold: true; - text: i18n(Skill) - } - - PlasmaComponents.Label { - id: cmd0label - Layout.fillWidth: true - wrapMode: Text.WordWrap; - width: root.width; - text: i18n('Command: ' + CommandList.get(0).Commands) + Kirigami.AbstractCard { + id: skillDelegate; - MouseArea { - anchors.fill: parent - hoverEnabled: true + contentItem: Item { + implicitWidth: delegateLayout.implicitWidth; + implicitHeight: delegateLayout.implicitHeight; - onEntered: { - cmd0label.color = theme.linkColor - cmd0label.font.underline = true - cmd0label.font.bold = true - } - onExited: { - cmd0label.color = theme.textColor - cmd0label.font.underline = false - cmd0label.font.bold = false - } - onClicked: { - var genExampleQuery = CommandList.get(0).Commands - var exampleQuery = genExampleQuery.toString().split(",") - var socketmessage = {}; - socketmessage.type = "recognizer_loop:utterance"; - socketmessage.data = {}; - socketmessage.data.utterances = [exampleQuery[1].toLowerCase()]; - socket.onSendMessagesendTextMessage(JSON.stringify(socketmessage)); - tabBar.currentTab = mycroftTab - qinput.text = ""; - } + ColumnLayout { + id: delegateLayout + anchors { + left: parent.left; + top: parent.top; + right: parent.right; } - } - PlasmaComponents.Label { - id: cmd1label - Layout.fillWidth: true - wrapMode: Text.WordWrap; - width: root.width; - text: i18n('Command: ' + CommandList.get(1).Commands) - - MouseArea { - anchors.fill: parent - hoverEnabled: true + Kirigami.Heading { + id: skillName + Layout.fillWidth: true; + wrapMode: Text.WordWrap; + font.bold: true; + text: qsTr(modelData.title); + level: 3; + color: Kirigami.Theme.textColor; + } - onEntered: { - cmd1label.color = theme.linkColor - cmd1label.font.underline = true - cmd1label.font.bold = true - } - onExited: { - cmd1label.color = theme.textColor - cmd1label.font.underline = false - cmd1label.font.bold = false + RowLayout { + id: skillTopRowLayout + spacing: Kirigami.Units.largeSpacing + Layout.fillWidth: true; + + PlasmaCore.IconItem { + id: innerskImg + source: "curve-connector"; + //fillMode: PreserveAspectFit + Layout.preferredWidth: innerskImg.width + Layout.preferredHeight: innerskImg.height + width: Kirigami.Units.gridUnit * 2 + height: Kirigami.Units.gridUnit * 2 } - onClicked: { - tabBar.currentTab = mycroftTab - var genExampleQuery = CommandList.get(1).Commands - var exampleQuery = genExampleQuery.toString().split(",") - var socketmessage = {}; - socketmessage.type = "recognizer_loop:utterance"; - socketmessage.data = {}; - socketmessage.data.utterances = [exampleQuery[1].toLowerCase()]; - socket.onSendMessagesendTextMessage(JSON.stringify(socketmessage)); - tabBar.currentTab = mycroftTab - qinput.text = ""; + + ColumnLayout { + id: innerskillscolumn + spacing: 2; + Layout.fillHeight: true + Controls.Label { + wrapMode: Text.WordWrap; + Layout.fillWidth: true; + color: Kirigami.Theme.textColor; + text: modelData.examples[1]; + } + Controls.Label { + wrapMode: Text.WordWrap; + Layout.fillWidth: true; + color: Kirigami.Theme.textColor; + text: modelData.examples[2]; + } } } } } } - } -} - - diff --git a/plasmoid/contents/ui/HintsViewComponent.qml b/plasmoid/contents/ui/HintsViewComponent.qml index 529b218..a999771 100644 --- a/plasmoid/contents/ui/HintsViewComponent.qml +++ b/plasmoid/contents/ui/HintsViewComponent.qml @@ -1,29 +1,72 @@ import QtQuick 2.9 import QtQml.Models 2.2 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.3 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.components 3.0 as PlasmaComponents3 import org.kde.plasma.extras 2.0 as PlasmaExtras import QtGraphicalEffects 1.0 import org.kde.kirigami 2.5 as Kirigami import Mycroft 1.0 as Mycroft Rectangle { Layout.fillWidth: true Layout.fillHeight: true color: Kirigami.Theme.backgroundColor + property var modelCreatedObject - ListView { - id: hintsListView - anchors.fill: parent - model: HintsModel{} - delegate: HintsView{} - spacing: 4 - focus: false - interactive: true + Component.onCompleted: { + createHintModel() + } + + function createHintModel(){ + var hintList = [] + var defaultFold = '/opt/mycroft/skills' + var fileToFind = "README.md" + var getList = Mycroft.FileReader.checkForMeta(defaultFold, fileToFind) + for(var i=0; i < getList.length; i++){ + var fileParse = Mycroft.FileReader.read(getList[i]+"/"+fileToFind); + var matchedRegex = getImgSrc(fileParse) + var matchedExamples = getExamples(fileParse) + var matchedCategory = getCategory(fileParse) + if(matchedRegex !== null && matchedRegex.length > 0 && matchedExamples !== null && matchedExamples.length > 0 && matchedCategory !== null && matchedCategory.length > 0) { + var metaFileObject = { + imgSrc: matchedRegex[1], + title: matchedRegex[2], + category: matchedCategory[1], + examples: matchedExamples + } + hintList.push(metaFileObject); + } + } + modelCreatedObject = hintList + } + + function getImgSrc(fileText){ + var re = new RegExp(/]*src='([^']*)'.*\/>\s(.*)/g); + var match = re.exec(fileText); + return match; + } + + function getExamples(fileText){ + var re = new RegExp(/Examples \n.*"(.*)"\n\*\s"(.*)"/g); + var match = re.exec(fileText); + return match; + } + + function getCategory(fileText){ + var re = new RegExp(/## Category\n\*\*(.*)\*\*/g); + var match = re.exec(fileText); + return match; + } + + Kirigami.CardsListView { + id: skillslistmodelview + anchors.fill: parent; clip: true; + model: modelCreatedObject + delegate: HintsView{} } } diff --git a/plasmoid/contents/ui/MsmView.qml b/plasmoid/contents/ui/MsmView.qml index 1f7345f..0a44c3a 100644 --- a/plasmoid/contents/ui/MsmView.qml +++ b/plasmoid/contents/ui/MsmView.qml @@ -1,213 +1,112 @@ /* Copyright 2016 Aditya Mehra This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ import QtQuick 2.9 -import QtQuick.Layouts 1.3 +import QtQml.Models 2.2 import QtQuick.Controls 2.2 +import QtQuick.Layouts 1.3 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.components 2.0 as PlasmaComponents +import org.kde.plasma.components 3.0 as PlasmaComponents3 import org.kde.plasma.extras 2.0 as PlasmaExtras +import QtGraphicalEffects 1.0 +import org.kde.kirigami 2.5 as Kirigami +import Mycroft 1.0 as Mycroft -Rectangle { - id: skillcontent - Layout.fillWidth: true; - anchors { - left: parent.left; - leftMargin: 0.5; - right: parent.right - } - height: units.gridUnit * 4 - border.width: 1 - border.color: Qt.darker(theme.linkColor, 1.2) - color: Qt.darker(theme.backgroundColor, 1.2) - property var configPath - focus: false - -// function exec(msmparam) { -// if(main.coreinstallstartpath == packagemcorestartcmd){ -// if(innerset.versionIndex == 0){ -// var createSkillMsg = "install " + model.name -// var socketmessage = {}; -// socketmessage.type = "recognizer_loop:utterance"; -// socketmessage.data = {}; -// socketmessage.data.utterances = [createSkillMsg]; -// socket.onSendMessage(JSON.stringify(socketmessage)); -// } -// else { -// return launchinstaller.msmapp("bash msm install " + model.url) -// } -// } -// else { -// if(innerset.versionIndex == 0){ -// var createSkillMsg = "install " + model.name -// var socketmessage = {}; -// socketmessage.type = "recognizer_loop:utterance"; -// socketmessage.data = {}; -// socketmessage.data.utterances = [createSkillMsg]; -// socket.onSendMessage(JSON.stringify(socketmessage)); -// } -// else { -// var bscrpt = "/usr/share/plasma/plasmoids/org.kde.plasma.mycroftplasmoid/contents/code/msm.sh" -// return launchinstaller.msmapp("bash " + bscrpt + " install " + model.url) -// } -// } -// } -// -// function execUninstall(msmparam) { -// if(main.coreinstallstartpath == packagemcorestartcmd){ -// if(innerset.versionIndex == 0){ -// var createSkillMsg = "uninstall " + model.name -// var socketmessage = {}; -// socketmessage.type = "recognizer_loop:utterance"; -// socketmessage.data = {}; -// socketmessage.data.utterances = [createSkillMsg]; -// socket.onSendMessage(JSON.stringify(socketmessage)); -// } -// else { -// return launchinstaller.msmapp("bash msm remove " + model.name) -// } -// } -// else { -// if(innerset.versionIndex == 0){ -// var createSkillMsg = "uninstall " + model.name -// var socketmessage = {}; -// socketmessage.type = "recognizer_loop:utterance"; -// socketmessage.data = {}; -// socketmessage.data.utterances = [createSkillMsg]; -// socket.onSendMessage(JSON.stringify(socketmessage)); -// } -// else { -// var bscrpt = "/usr/share/plasma/plasmoids/org.kde.plasma.mycroftplasmoid/contents/code/msm.sh" -// return launchinstaller.msmapp("bash " + bscrpt + " remove " + model.name) -// } -// } -// } - -// function execUpdate(msmparam) { -// if(main.coreinstallstartpath == packagemcorestartcmd){ -// return launchinstaller.msmapp("bash msm update " + model.name) -// } -// else { -// var bscrpt = "/usr/share/plasma/plasmoids/org.kde.plasma.mycroftplasmoid/contents/code/msm.sh" -// return launchinstaller.msmapp("bash " + bscrpt + " update " + model.name) -// } -// } -// -// function execConfiguration(msmparam) { -// var openConfigUrl = Qt.resolvedUrl(configPath) -// Qt.openUrlExternally(openConfigUrl) -// } -// -// function getSkillInfoLocal() { -// var customFold = launchinstaller.skillsPath() -// var defaultFold = '/opt/mycroft/skills' -// var skillPath = (defaultFold || customFold) + "/" + model.name -// var defskillPath = (defaultFold || customFold) + "/" + "mycroft-" + model.name -// configPath = (defaultFold || customFold) + "/" + model.name + "/" + "settingsmeta.json" -// if(PlasmaLa.FileReader.file_exists_local(skillPath)){ -// installUpdateLabl.text = "Installed" -// //updateskillviamsm.enabled = true -// } -// else if(PlasmaLa.FileReader.file_exists_local(defskillPath)){ -// installUpdateLabl.text = "Installed" -// } -// // if(PlasmaLa.FileReader.file_exists_local(configPath)){ -// // configureSkillLabl.enabled = true -// // } -// } - -// Component.onCompleted: { - //getSkillInfoLocal(); -// } - - PlasmaComponents.Label { - id: skllname - font.capitalization: Font.AllUppercase - anchors.top: parent.top - anchors.left: parent.left - anchors.leftMargin: units.gridUnit * 0.5 - anchors.right: parent.right - anchors.rightMargin: units.gridUnit * 0.5 - wrapMode: Text.WordWrap - text: model.name - Rectangle { - id: sepratrmsm - width: parent.width - height: 1 - anchors.left: parent.left - anchors.bottom: parent.bottom - anchors.bottomMargin: 2 - color: Qt.darker(theme.linkColor, 1.2) - } - } - - PlasmaComponents.Label { - id: urlskllable - anchors.top: skllname.bottom - anchors.topMargin: units.gridUnit * 0.03 - anchors.left: parent.left - anchors.leftMargin: units.gridUnit * 0.5 - anchors.right: parent.right - anchors.rightMargin: units.gridUnit * 0.5 - wrapMode: Text.WordWrap - color: theme.textColor - text: model.url - - MouseArea{ - id: gotoGit - anchors.fill: parent - hoverEnabled: true - onClicked: {Qt.openUrlExternally(model.url)} - onEntered: { - urlskllable.color = Qt.darker(theme.linkColor, 1.2) +Kirigami.AbstractCard { + id: skillInstallerDelegate + + contentItem: Item { + implicitWidth: delegateLayout.implicitWidth; + implicitHeight: delegateLayout.implicitHeight; + + ColumnLayout{ + id: delegateLayout + anchors { + left: parent.left; + top: parent.top; + right: parent.right; } - onExited: { - urlskllable.color = theme.textColor + + Kirigami.Heading { + id: skillName + Layout.fillWidth: true; + wrapMode: Text.WordWrap; + font.bold: true; + text: qsTr(model.name); + level: 3; + color: Kirigami.Theme.textColor; } - } - } - Rectangle { - id: getskillviamsmRect - width: parent.width - height: units.gridUnit * 1 - anchors.bottom: parent.bottom - color: Qt.darker(theme.linkColor, 1.2) - - PlasmaComponents.Button{ - id: installUpdateLabl - width: parent.width - height: parent.height - anchors.left: parent.left - text: "Install" + + RowLayout { + id: skillInfoRow + spacing: Kirigami.Units.largeSpacing + Layout.fillWidth: true + + PlasmaCore.IconItem { + id: innerskImg + source: "download"; + Layout.preferredWidth: innerskImg.width + Layout.preferredHeight: innerskImg.height + width: Kirigami.Units.gridUnit * 2 + height: Kirigami.Units.gridUnit * 2 + } + + Label { + id: skillURL + wrapMode: Text.WordWrap + color: theme.textColor + text: "View Repository" + Layout.fillWidth: true; - onClicked:{ - switch(installUpdateLabl.text){ - case "Install": - var msmprogress = exec() - break - case "Uninstall": - var msmprogress = execUninstall() - break + MouseArea{ + id: gotoGit + anchors.fill: parent + hoverEnabled: true + onClicked: {Qt.openUrlExternally(model.url)} + onEntered: { + skillURL.color = Qt.darker(theme.linkColor, 1.2) + } + onExited: { + skillURL.color = theme.textColor + } + } + } + } + + PlasmaComponents.Button{ + id: actionItem + text: "Install" + Layout.fillWidth: true + onClicked:{ + switch(actionItem.text){ + case "Install": + Mycroft.MycroftController.sendText("install" + skillName) + break + case "Uninstall": + var msmprogress = execUninstall() + break + } } } } } } diff --git a/plasmoid/contents/ui/SkillsInstallerComponent.qml b/plasmoid/contents/ui/SkillsInstallerComponent.qml index 86cfe37..60c6d46 100644 --- a/plasmoid/contents/ui/SkillsInstallerComponent.qml +++ b/plasmoid/contents/ui/SkillsInstallerComponent.qml @@ -1,148 +1,145 @@ import QtQuick 2.9 import QtQml.Models 2.2 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.3 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.components 3.0 as PlasmaComponents3 import org.kde.plasma.extras 2.0 as PlasmaExtras import QtGraphicalEffects 1.0 import org.kde.kirigami 2.5 as Kirigami import Mycroft 1.0 as Mycroft Rectangle { id: skillsInstallerComponent Layout.fillWidth: true Layout.fillHeight: true color: Kirigami.Theme.backgroundColor property var skillList: [] function refreshAllSkills(){ getSkills(); msmskillsModel.reload(); } function getAllSkills(){ if(skillList.length <= 0){ getSkills(); } return skillList; } function getSkillByName(skillName){ var tempSN=[]; for(var i = 0; i 0 ) { msmskillsModel.applyFilter(text.toLowerCase()); } else { msmskillsModel.reload(); } } } PlasmaComponents.ToolButton { id: getskillsbx anchors.right: parent.right anchors.top: parent.top anchors.bottom: parent.bottom iconSource: "view-refresh" tooltip: i18n("Refresh List") flat: true width: Math.round(units.gridUnit * 2) height: width z: 102 onClicked: { msmskillsModel.clear(); refreshAllSkills(); } } } ListModel { id: msmskillsModel Component.onCompleted: { reload(); } function reload() { var skList = getAllSkills(); msmskillsModel.clear(); for( var i=0; i < skList.length ; ++i ) { msmskillsModel.append(skList[i]); } } function applyFilter(skName) { var skList = getSkillByName(skName); msmskillsModel.clear(); for( var i=0; i < skList.length ; ++i ) { msmskillsModel.append(skList[i]); } } } - ListView { + Kirigami.CardsListView { id: msmlistView anchors.top: msmtabtopbar.bottom - anchors.topMargin: 5 + anchors.topMargin: Kirigami.Units.largeSpacing anchors.left: parent.left anchors.right: parent.right anchors.bottom: parent.bottom model: msmskillsModel delegate: MsmView{} - spacing: 4 - focus: false - interactive: true clip: true; } }