diff --git a/plasmoid/contents/ui/Applet.js b/plasmoid/contents/ui/Applet.js index 4a6207b..d02c64c 100644 --- a/plasmoid/contents/ui/Applet.js +++ b/plasmoid/contents/ui/Applet.js @@ -1,130 +1,197 @@ function detectInstallType(){ if(locationUserSelected == false && PlasmaLa.FileReader.file_exists_local("/usr/bin/mycroft-messagebus")){ settingsTabUnitsOpOne.checked = true coreinstallstartpath = packagemcorestartcmd coreinstallstoppath = packagemcorestopcmd } } function checkConnectionStatus(){ var isConnected = PlasmaLa.ConnectionCheck.checkConnection() if(!isConnected){ if(!connectCtx){ var conError = i18n("I am not connected to the internet, Please check your network connection") mycroftConversationComponent.conversationModel.append({"itemType": "NonVisual", "InputQuery": conError}); connectCtx = true } } else { geoDataSource.connectedSources = ["location"] } } function toggleInputMethod(selection){ switch(selection){ case "KeyboardSetActive": qinput.visible = true suggestionbottombox.visible = true customMicIndicator.visible = false keybindic.color = "green" break case "KeyboardSetDisable": qinput.visible = false suggestionbottombox.visible = false customMicIndicator.visible = true keybindic.color = theme.textColor break } } function isBottomEdge() { return plasmoid.location == PlasmaCore.Types.BottomEdge; } function clearList() { inputlistView.clear() } function checkMicrophoneState(){ var socketmessage = {}; socketmessage.type = "mycroft.mic.get_status"; socketmessage.data = {}; socket.sendTextMessage(JSON.stringify(socketmessage)); } function muteMicrophone() { var socketmessage = {}; socketmessage.type = "mycroft.mic.mute"; socketmessage.data = {}; socket.sendTextMessage(JSON.stringify(socketmessage)); - qinputmicbx.iconSource = "mic-off" + topBarView.micIcon = "mic-off" } function unmuteMicrophone(){ var socketmessage = {}; socketmessage.type = "mycroft.mic.unmute"; socketmessage.data = {}; socket.sendTextMessage(JSON.stringify(socketmessage)); - qinputmicbx.iconSource = "mic-on" + topBarView.micIcon = "mic-on" } function getFileExtenion(filePath){ var ext = filePath.split('.').pop(); return ext; } function validateFileExtension(filePath) { var ext = filePath.split('.').pop(); return ext === "jpg" || ext === "png" || ext === "jpeg" || ext === 'mp3' || ext === 'wav' || ext === 'mp4' } function readFile(filename) { if (PlasmaLa.FileReader.file_exists_local(filename)) { try { var content = PlasmaLa.FileReader.read(filename).toString("utf-8"); return content; } catch (e) { return 0; } } else { return 0; } } function playwaitanim(recoginit){ switch(recoginit){ case "recognizer_loop:record_begin": - drawer.open() - waitanimoutter.aniRunWorking() + bottomBarView.animationDrawer.open() + bottomBarView.animateStepWorking() break case "recognizer_loop:wakeword": - waitanimoutter.aniRunHappy() + bottomBarView.animateStepHappy() break case "intent_failure": - waitanimoutter.aniRunError() + bottomBarView.animateStepError() intentfailure = true break case "recognizer_loop:audio_output_start": if (intentfailure === false){ - drawer.close() + bottomBarView.animationDrawer.close() } else { delay(1500, function() { - drawer.close() + bottomBarView.animationDrawer.close() intentfailure = false; }) } break case "mycroft.skill.handler.complete": if (intentfailure === false){ - drawer.close() + bottomBarView.animationDrawer.close() } else { delay(1500, function() { - drawer.close() + bottomBarView.animationDrawer.close() intentfailure = false; }) } break } } + + function preSocketStatus(){ + if (mycroftStatusCheckSocket.status == WebSocket.Open && socket.status == WebSocket.Closed) { + socket.active = true + mycroftStatusCheckSocket._socketIsAlreadyActive = true + disclaimbox.visible = false; + topBarView.startSwitch.checked = true + topBarView.mycroftStatus.text = i18n("Connected") + topBarView.mycroftStatus.color = "green" + topBarView.mycroftStatus.visible = true + } + + else if (mycroftStatusCheckSocket.status == WebSocket.Error) { + topBarView.startSwitch.checked = false + mycroftStatusCheckSocket._socketIsAlreadyActive = false + topBarView.mycroftStatus.text = i18n("Disabled") + topBarView.mycroftStatus.color = theme.textColor + topBarView.mycroftStatus.visible = true + } + } + + function mainSocketStatus(){ + if (socket.status == WebSocket.Error) { + topBarView.mycroftStatus.text = i18n("Connection error") + topBarView.mycroftStatus.color = "red" + topBarView.startSwitch.circolour = "red" + topBarView.talkAnimation.showstatsId() + topBarView.retryButton.visible = true + topBarView.retryButton.enabled = true + bottomBarView.animationDrawer.open() + bottomBarView.animateStepError() + delay(1250, function() { + bottomBarView.animationDrawer.close() + }) + + } else if (socket.status == WebSocket.Open) { + topBarView.mycroftStatus.text = i18n("Connected") + topBarView.mycroftStatus.color = "green" + topBarView.retryButton.visible = false + topBarView.retryButton.enabled = false + topBarView.startSwitch.circolour = "green" + mycroftStatusCheckSocket.active = false; + topBarView.talkAnimation.showstatsId() + PlasmaLa.Notify.mycroftConnectionStatus("Connected") + bottomBarView.animationDrawer.open() + bottomBarView.animateStepHappy() + delay(1250, function() { + bottomBarView.animationDrawer.close() + Applet.checkMicrophoneState() + }) + } else if (socket.status == WebSocket.Closed) { + topBarView.mycroftStatus.text = i18n("Disabled") + topBarView.mycroftStatus.color = theme.textColor + PlasmaLa.Notify.mycroftConnectionStatus("Disconnected") + topBarView.startSwitch.circolour = Qt.lighter(theme.backgroundColor, 1.5) + topBarView.talkAnimation.showstatsId() + } else if (socket.status == WebSocket.Connecting) { + topBarView.mycroftStatus.text = i18n("Starting up..please wait") + topBarView.mycroftStatus.color = theme.linkColor + topBarView.startSwitch.circolour = "steelblue" + topBarView.talkAnimation.showstatsId() + } else if (socket.status == WebSocket.Closing) { + topBarView.mycroftStatus.text = i18n("Shutting down") + topBarView.mycroftStatus.color = theme.textColor + topBarView.talkAnimation.showstatsId() + } + } diff --git a/plasmoid/contents/ui/BottomBarViewComponent.qml b/plasmoid/contents/ui/BottomBarViewComponent.qml new file mode 100644 index 0000000..10f18df --- /dev/null +++ b/plasmoid/contents/ui/BottomBarViewComponent.qml @@ -0,0 +1,198 @@ +/* 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 +import QtQuick.Layouts 1.3 +import Qt.WebSockets 1.0 +import Qt.labs.settings 1.0 +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 QtQuick.Window 2.0 +import QtGraphicalEffects 1.0 +import "Applet.js" as Applet +import "Autocomplete.js" as Autocomplete +import "Conversation.js" as Conversation +import "Dashboard.js" as Dash + +Item { + id: appletBottomBarComponent + anchors.fill: parent + property alias autoCompModel: completionItems + property alias queryInput: qinput + property alias animationDrawer: drawer + property alias suggestBox: suggst + signal animateStepWorking + signal animateStepHappy + signal animateStepError + + Connections { + target: appletBottomBarComponent + onAnimateStepWorking: { + console.log("Here") + waitanimoutter.aniRunWorking() + } + onAnimateStepHappy: { + waitanimoutter.aniRunHappy() + } + onAnimateStepError: { + waitanimoutter.aniRunError() + } + } + + ListModel { + id: completionItems + } + + Drawer { + id: drawer + width: dwrpaddedwidth + height: units.gridUnit * 5.5 + edge: Qt.BottomEdge + + Rectangle { + color: theme.backgroundColor + anchors.fill: parent + } + + CustomIndicator { + id: waitanimoutter + height: 70 + width: 70 + anchors.verticalCenter: parent.verticalCenter + anchors.horizontalCenter: parent.horizontalCenter + } + } + + Rectangle { + id: suggestionbottombox + anchors.top: parent.top + anchors.bottom: qinput.top + anchors.right: parent.right + anchors.left: parent.left + color: theme.backgroundColor + + Suggestions { + id: suggst + visible: true; + } + } + + Rectangle { + id: keyboardactivaterect + color: theme.backgroundColor + border.width: 1 + border.color: Qt.lighter(theme.backgroundColor, 1.2) + width: units.gridUnit * 2 + height: qinput.height + anchors.bottom: parent.bottom + anchors.left: parent.left + + PlasmaCore.IconItem { + id: keybdImg + source: "input-keyboard" + anchors.centerIn: parent + width: units.gridUnit * 1.5 + height: units.gridUnit * 1.5 + } + + Rectangle { + id: keybindic + anchors.bottom: parent.bottom + anchors.bottomMargin: 4 + anchors.left: parent.left + anchors.right: parent.right + anchors.leftMargin: 8 + anchors.rightMargin: 8 + height: 2 + color: "green" + } + + MouseArea{ + anchors.fill: parent + hoverEnabled: true + onEntered: {} + onExited: {} + onClicked: { + if(qinput.visible === false){ + toggleInputMethod("KeyboardSetActive") + } + else if(qinput.visible === true){ + toggleInputMethod("KeyboardSetDisable") + } + } + } + } + + PlasmaComponents.TextField { + id: qinput + anchors.left: keyboardactivaterect.right + anchors.bottom: parent.bottom + anchors.right: parent.right + placeholderText: i18n("Enter Query or Say 'Hey Mycroft'") + clearButtonShown: true + + onAccepted: { + var doesExist = Autocomplete.autoAppend(autoCompModel, function(item) { return item.name === qinput.text }, qinput.text) + var evaluateExist = doesExist + if(evaluateExist === null){ + autoCompModel.append({"name": qinput.text}); + } + suggst.visible = true; + var socketmessage = {}; + socketmessage.type = "recognizer_loop:utterance"; + socketmessage.data = {}; + socketmessage.data.utterances = [qinput.text]; + socket.sendTextMessage(JSON.stringify(socketmessage)); + qinput.text = ""; + } + + onTextChanged: { + Autocomplete.evalAutoLogic(); + } + } + + CustomMicIndicator { + id: customMicIndicator + anchors.centerIn: parent + visible: false + } + + AutocompleteBox { + id: suggestionsBox + model: completionItems + width: parent.width + anchors.bottom: qinput.top + anchors.left: parent.left + anchors.right: parent.right + filter: textInput.text + property: "name" + onItemSelected: complete(item) + + function complete(item) { + if (item !== undefined) + textInput.text = item.name + } + } +} diff --git a/plasmoid/contents/ui/ConversationLogic.js b/plasmoid/contents/ui/ConversationLogic.js new file mode 100644 index 0000000..555232e --- /dev/null +++ b/plasmoid/contents/ui/ConversationLogic.js @@ -0,0 +1,107 @@ +function filterConversation(msgType, somestring){ + if (msgType === "mycroft.mic.get_status.response") { + var micState = somestring.data.muted + if(micState) { + micIsMuted = true + topBarView.micIcon = "mic-off" + } + else if(!micState) { + micIsMuted = false + topBarView.micIcon = "mic-on" + } + } + + if (msgType === "mycroft.skills.initialized") { + PlasmaLa.Notify.mycroftConnectionStatus(i18n("Ready..Let's Talk")) + } + + if (msgType === "recognizer_loop:utterance") { + bottomBarView.queryInput.focus = false; + var intpost = somestring.data.utterances; + bottomBarView.queryInput.text = intpost.toString() + mycroftConversationComponent.conversationModel.append({"itemType": "AskType", "InputQuery": intpost.toString()}) + topBarView.animateTalk() + } + + if (msgType === "recognizer_loop:utterance" && dashLmodel.count != 0){ + Dash.showDash("setHide") + } + + if (somestring.data.handler === "fallback" && somestring.data.fallback_handler === "WolframAlphaSkill.handle_fallback" && somestring.type === "mycroft.skill.handler.complete"){ + if(wolframfallbackswitch.checked == true){ + Conversation.getFallBackResult(bottomBarView.queryInput.text) + } + } + + if (somestring && somestring.data && typeof somestring.data.intent_type !== 'undefined'){ + smintent = somestring.data.intent_type; + console.log(smintent) + } + + if(somestring && somestring.data && typeof somestring.data.utterance !== 'undefined' && somestring.type === 'speak'){ + Conversation.filterSpeak(somestring.data.utterance); + } + + if(somestring && somestring.data && typeof somestring.data.desktop !== 'undefined' && somestring.type === "data") { + dataContent = somestring.data.desktop + Conversation.filterincoming(smintent, dataContent) + } + + if(somestring && somestring.data && typeof somestring.data.desktop !== 'undefined' && somestring.type === "visualObject") { + dataContent = somestring.data.desktop + Conversation.filtervisualObj(dataContent) + } + + if(somestring && somestring.data && typeof somestring.data.desktop !== 'undefined' && somestring.type === "placesObject") { + dataContent = somestring.data.desktop + Conversation.filterplacesObj(dataContent) + } + + if(somestring && somestring.data && typeof somestring.data.desktop !== 'undefined' && somestring.type === "recipesObject") { + dataContent = somestring.data.desktop + Conversation.filterRecipeObj(dataContent) + } + + if(somestring && somestring.data && typeof somestring.data.desktop !== 'undefined' && somestring.type === "balooObject") { + dataContent = somestring.data.desktop + Conversation.filterBalooObj(dataContent) + } + + if(somestring && somestring.data && typeof somestring.data.desktop !== 'undefined' && somestring.type === "stackresponseObject") { + dataContent = somestring.data.desktop + Conversation.filterstackObj(dataContent) + } + + if(somestring && somestring.data && typeof somestring.data.desktop !== 'undefined' && somestring.type === "bookObject") { + dataContent = somestring.data.desktop + Conversation.filterbookObj(dataContent) + } + + if(somestring && somestring.data && typeof somestring.data.desktop !== 'undefined' && somestring.type === "wikiObject") { + dataContent = somestring.data.desktop + Conversation.filterwikiObj(dataContent) + } + + if(somestring && somestring.data && typeof somestring.data.desktop !== 'undefined' && somestring.type === "wikiaddObject") { + dataContent = somestring.data.desktop + Conversation.filterwikiMoreObj(dataContent) + } + + if(somestring && somestring.data && typeof somestring.data.desktop !== 'undefined' && somestring.type === "yelpObject") { + dataContent = somestring.data.desktop + Conversation.filteryelpObj(dataContent) + } + + if(somestring && somestring.data && typeof somestring.data.desktop !== 'undefined' && somestring.type === "imageObject") { + dataContent = somestring.data.desktop + Conversation.filterImageObject(dataContent) + } + + + if (msgType === "speak" && !plasmoid.expanded && appletSettings.innerset.notifybool == true) { + var post = somestring.data.utterance; + var title = "Mycroft's Reply:" + var notiftext = " "+ post; + PlasmaLa.Notify.mycroftResponse(title, notiftext); + } +} diff --git a/plasmoid/contents/ui/ConversationView.qml b/plasmoid/contents/ui/ConversationView.qml index 87f8f81..6e64a7e 100644 --- a/plasmoid/contents/ui/ConversationView.qml +++ b/plasmoid/contents/ui/ConversationView.qml @@ -1,87 +1,138 @@ +/* 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 import QtQuick.Layouts 1.3 import Qt.WebSockets 1.0 import Qt.labs.settings 1.0 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 QtQuick.Window 2.0 import QtGraphicalEffects 1.0 Item { anchors.fill: parent property alias conversationModel: convoLmodel property alias conversationListView: inputlistView + property alias conversationViewScrollBar: conversationListScrollBar + + DropArea { + anchors.fill: parent; + id: dragTarget + onEntered: { + for(var i = 0; i < drag.urls.length; i++) + if(validateFileExtension(drag.urls[i])) + return + console.log("No valid files, refusing drag event") + drag.accept() + dragTarget.enabled = false + } + + onDropped: { + for(var i = 0; i < drop.urls.length; i++){ + var ext = getFileExtenion(drop.urls[i]); + if(ext === "jpg" || ext === "png" || ext === "jpeg"){ + var durl = String(drop.urls[i]); + mycroftConversationComponent.conversationModel.append({ + "itemType": "DropImg", + "InputQuery": durl + }) + inputlistView.positionViewAtEnd(); + } + + if(ext === 'mp3'){ + console.log('mp3'); + } + } + } ListModel{ id: convoLmodel } Item { id: messageBox anchors.fill: parent ColumnLayout { id: colconvo anchors.fill: parent ListView { id: inputlistView anchors.left: parent.left anchors.right: parent.right anchors.top: parent.top anchors.bottom: parent.bottom anchors.rightMargin: units.gridUnit * 0.15 verticalLayoutDirection: ListView.TopToBottom spacing: 12 clip: true model: convoLmodel ScrollBar.vertical: conversationListScrollBar delegate: Component { Loader { source: switch(itemType) { case "NonVisual": return "SimpleMessageType.qml" case "WebViewType": return "WebViewType.qml" case "CurrentWeather": return "CurrentWeatherType.qml" case "DropImg" : return "ImgRecogType.qml" case "AskType" : return "AskMessageType.qml" case "LoaderType" : return "LoaderType.qml" case "PlacesType" : return "PlacesType.qml" case "RecipeType" : return "RecipeType.qml" case "DashboardType" : return "DashboardType.qml" case "AudioFileType" : return "AudioFileDelegate.qml" case "VideoFileType" : return "VideoFileDelegate.qml" case "DocumentFileType" : return "DocumentFileDelegate.qml" case "FallBackType" : return "FallbackWebSearchType.qml" case "StackObjType" : return "StackObjType.qml" case "BookType" : return "BookType.qml" case "WikiType" : return "WikiType.qml" case "YelpType" : return "YelpType.qml" case "ImageType" : return "ImageType.qml" } property var metacontent : dataContent } } onCountChanged: { inputlistView.positionViewAtEnd(); } } PlasmaComponents3.ScrollBar { id: conversationListScrollBar orientation: Qt.Vertical interactive: true anchors.right: parent.right anchors.top: parent.top anchors.bottom: parent.bottom + } } } } } diff --git a/plasmoid/contents/ui/DashboardDelegate.qml b/plasmoid/contents/ui/DashboardDelegate.qml index 797f289..96f6455 100644 --- a/plasmoid/contents/ui/DashboardDelegate.qml +++ b/plasmoid/contents/ui/DashboardDelegate.qml @@ -1,234 +1,234 @@ /* 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 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 Item { id: dashdelegteType height: dashdelegatelview.height width: parent.width property Component delegateComponentDisclaimer: Qt.createComponent("DisclaimerCardDelegate.qml") property Component delegateComponentWeather: Qt.createComponent("DashWeatherDelegate.qml") property Component delegateComponentNews: Qt.createComponent("DashNewsDelegate.qml") property Component delegateComponentCrypto: Qt.createComponent("DashCryptoDelegate.qml") Component.onCompleted: { filterSwitchDash(iType, iObj) } function filterSwitchDash(iType, iObj){ switch(iType){ case "Disclaimer": filterDashDisclaimerObj() break case "DashNews": filterDashNewsObj(iObj) break case "DashWeather": filterDashWeatherObj(iObj) break case "DashCryptoPrice": filterDashCryptoObj(iObj) break } } function filterDashDisclaimerObj() { dashCardCollectionModel.append({itemType: "Disclaimer", itemAt: 0, contents:{}}) dashdelegatelview.delegate = delegateComponentDisclaimer } function filterDashWeatherObj(weatherobj){ var filteredMetric if(weatherMetric.indexOf('metric') != -1){ filteredMetric = "°c" } else if (weatherMetric.indexOf('imperial') != -1){ filteredMetric = "°f" } if(weatherobj){ var filteredWeatherObject = JSON.parse(weatherobj) var weatherIcnTypeHourZero = "http://openweathermap.org/img/w/" + filteredWeatherObject.list[0].weather[0].icon + ".png" var weatherIcnTypeHourA = "http://openweathermap.org/img/w/" + filteredWeatherObject.list[1].weather[0].icon + ".png" var weatherIcnTypeHourB = "http://openweathermap.org/img/w/" + filteredWeatherObject.list[2].weather[0].icon + ".png" var weatherdateHourZero = filteredWeatherObject.list[0].dt_txt var weatherdateHourA = filteredWeatherObject.list[1].dt_txt var weatherdateHourB = filteredWeatherObject.list[2].dt_txt dashCardCollectionModel.append({itemType: "DashWeather", itemAt: 1, contents:{itemWeatherTempHourZero: filteredWeatherObject.list[0].main.temp, itemWeatherTempHourA: filteredWeatherObject.list[1].main.temp, itemWeatherTempHourB: filteredWeatherObject.list[2].main.temp, itemWeatherTempMinHourZero: filteredWeatherObject.list[0].main.temp_min, itemWeatherTempMinHourA: filteredWeatherObject.list[1].main.temp_min, itemWeatherTempMinHourB: filteredWeatherObject.list[2].main.temp_min, itemWeatherTempMaxHourZero: filteredWeatherObject.list[0].main.temp_max, itemWeatherTempMaxHourA: filteredWeatherObject.list[1].main.temp_max, itemWeatherTempMaxHourB: filteredWeatherObject.list[2].main.temp_max, itemWeatherTempTypeHourZero: filteredWeatherObject.list[0].weather[0].main, itemWeatherTempTypeHourA: filteredWeatherObject.list[1].weather[0].main, itemWeatherTempTypeHourB: filteredWeatherObject.list[2].weather[0].main, itemWeatherMetricType: filteredMetric, itemWeatherIconTypeHourZero: weatherIcnTypeHourZero, itemWeatherIconTypeHourA: weatherIcnTypeHourA, itemWeatherIconTypeHourB: weatherIcnTypeHourB, itemWeatherWindHourZero: filteredWeatherObject.list[0].wind.speed, itemWeatherWindHourA: filteredWeatherObject.list[1].wind.speed, itemWeatherWindHourB: filteredWeatherObject.list[2].wind.speed, itemWeatherCity: filteredWeatherObject.city.name, itemWeatherDateHourZero: weatherdateHourZero, itemWeatherDateHourA: weatherdateHourA, itemWeatherDateHourB: weatherdateHourB}}) dashdelegatelview.delegate = delegateComponentWeather } } function filterDashNewsObj(newsobj){ if(newsobj){ var filteredNewsObject = JSON.parse(newsobj) for (var i=0; i 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 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 Item { id: dashbdtypebg - width: cbwidth + width: cbwidth - units.gridUnit * 0.12 height: cbheight property alias dashlvmodel: dashboardmodelview.model property alias dashlvdelegate: dashboardmodelview.delegate - + PulleyItemDash { id: dashlistPulley visible: true barColor: theme.linkColor anchors.bottom: parent.bottom anchors.bottomMargin: units.gridUnit * 0.10 _isVisible: true z: 900 } ListView { id: dashboardmodelview anchors.top: parent.top anchors.left: parent.left - anchors.right: parent.right + anchors.right: dashscrollBar.left + anchors.rightMargin: units.gridUnit * 0.15 height: cbheight / 1.05 model: dashLmodel spacing: 2 - focus: false + focus: true interactive: true clip: true; delegate: DashboardDelegate{} ScrollBar.vertical: dashscrollBar } - - PlasmaComponents3.ScrollBar { + +PlasmaComponents3.ScrollBar { id: dashscrollBar + //flickableItem: dashdelegatelview orientation: Qt.Vertical interactive: true anchors.right: parent.right anchors.top: parent.top anchors.bottom: parent.bottom - } + } } diff --git a/plasmoid/contents/ui/Suggestions.qml b/plasmoid/contents/ui/Suggestions.qml index 070a423..7786eee 100644 --- a/plasmoid/contents/ui/Suggestions.qml +++ b/plasmoid/contents/ui/Suggestions.qml @@ -1,240 +1,241 @@ /* 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.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.extras 2.0 as PlasmaExtras +import "Dashboard.js" as Dash Rectangle { id: suggestionsmainitem color: theme.backgroundColor anchors.fill: parent property alias suggest1: suggestiontext1.text property alias suggest2: suggestiontext2.text property alias suggest3: suggestiontext3.text Rectangle { id: suggestionbutton1 color: theme.backgroundColor anchors.top: parent.top anchors.topMargin: 0 anchors.bottom: parent.bottom anchors.bottomMargin: 0 border.width: 0.2 border.color: theme.textColor anchors.left: parent.left anchors.leftMargin: 0 width: suggestionsmainitem.width / 3 PlasmaCore.IconItem { id: suggest1imageicon anchors.left: parent.left anchors.leftMargin: units.gridUnit * 0.5 source: "set-language" width: units.gridUnit * 2 height: units.gridUnit * 2 } MouseArea { id: mouseArea1 anchors.fill: parent hoverEnabled: true onEntered: { suggestionbutton1.color = theme.textColor suggestiontext1.color = theme.backgroundColor } onExited: { suggestionbutton1.color = theme.backgroundColor suggestiontext1.color = theme.textColor } onClicked: { //var suggest1 = qinput.text //var lastIndex = suggest1.lastIndexOf(" "); //qinput.text = suggest1.substring(0, lastIndex) + " " + suggestiontext1.text + " " var socketmessage = {}; socketmessage.type = "recognizer_loop:utterance"; socketmessage.data = {}; socketmessage.data.utterances = [qinput.text]; socket.sendTextMessage(JSON.stringify(socketmessage)); } } PlasmaComponents.Label { id: suggestiontext1 text: i18n("Ask Another") anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter } } PlasmaCore.SvgItem { id: suggestbarDividerline1 anchors { left: suggestionbutton1.right //rightMargin: units.gridUnit * 0.25 top: parent.top topMargin: 0 bottom: parent.bottom bottomMargin: 0 } width: linesuggest1vertSvg.elementSize("vertical-line").width z: 110 elementId: "vertical-line" svg: PlasmaCore.Svg { id: linesuggest1vertSvg; imagePath: "widgets/line" } } Rectangle { id: suggestionbutton2 color: theme.backgroundColor anchors.bottom: parent.bottom anchors.bottomMargin: 0 anchors.top: parent.top anchors.topMargin: 0 anchors.right: suggestionbutton3.left anchors.rightMargin: 0 border.width: 0.2 anchors.left: suggestbarDividerline1.right anchors.leftMargin: 0 border.color: theme.textColor PlasmaCore.IconItem { id: suggest2imageicon anchors.left: parent.left anchors.leftMargin: units.gridUnit * 1.3 source: "gtk-stop" width: units.gridUnit * 2 height: units.gridUnit * 2 } MouseArea { id: mouseArea2 anchors.fill: parent hoverEnabled: true onEntered: { suggestionbutton2.color = theme.textColor suggestiontext2.color = theme.backgroundColor } onExited: { suggestionbutton2.color = theme.backgroundColor suggestiontext2.color = theme.textColor } onClicked: { var socketmessage = {}; socketmessage.type = "recognizer_loop:utterance"; socketmessage.data = {}; socketmessage.data.utterances = ["stop"]; socket.sendTextMessage(JSON.stringify(socketmessage)); } } PlasmaComponents.Label { id: suggestiontext2 text: i18n("Stop") anchors.verticalCenter: parent.verticalCenter anchors.horizontalCenter: parent.horizontalCenter } } PlasmaCore.SvgItem { id: suggestbarDividerline2 anchors { right: suggestionbutton3.left top: parent.top topMargin: 0 bottom: parent.bottom bottomMargin: 0 } width: linesuggest2vertSvg.elementSize("vertical-line").width z: 110 elementId: "vertical-line" svg: PlasmaCore.Svg { id: linesuggest2vertSvg; imagePath: "widgets/line" } } Rectangle { id: suggestionbutton3 color: theme.backgroundColor anchors.bottom: parent.bottom anchors.bottomMargin: 0 anchors.top: parent.top border.color: theme.textColor anchors.topMargin: 0 anchors.right: parent.right anchors.rightMargin: 0 border.width: 0.2 width: parent.width / 3 PlasmaCore.IconItem { id: suggest3imageicon anchors.left: parent.left anchors.leftMargin: units.gridUnit * 1.3 source: "code-function" width: units.gridUnit * 2 height: units.gridUnit * 2 } MouseArea { id: mouseArea3 anchors.fill: parent hoverEnabled: true onEntered: { suggestionbutton3.color = theme.textColor suggestiontext3.color = theme.backgroundColor } onExited: { suggestionbutton3.color = theme.backgroundColor suggestiontext3.color = theme.textColor } onClicked: { - convoLmodel.clear() - if(dashswitch.checked == true && dashLmodel.count == 0){ - showDash("setVisible") + mycroftConversationComponent.conversationModel.clear() + if(appletSettings.dasboardSwitch.checked == true && dashLmodel.count == 0){ + Dash.showDash("setVisible") } } } PlasmaComponents.Label { id: suggestiontext3 text: i18n("Clear") anchors.verticalCenter: parent.verticalCenter anchors.horizontalCenter: parent.horizontalCenter } } } diff --git a/plasmoid/contents/ui/TopBarViewComponent.qml b/plasmoid/contents/ui/TopBarViewComponent.qml index 005c66b..017e009 100644 --- a/plasmoid/contents/ui/TopBarViewComponent.qml +++ b/plasmoid/contents/ui/TopBarViewComponent.qml @@ -1,211 +1,238 @@ +/* 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 import QtQuick.Layouts 1.3 import Qt.WebSockets 1.0 import Qt.labs.settings 1.0 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 QtWebKit 3.0 import QtQuick.Window 2.0 import QtGraphicalEffects 1.0 import "Applet.js" as Applet import "Autocomplete.js" as Autocomplete import "Conversation.js" as Conversation import "Dashboard.js" as Dash Item { id: topBarBGrect anchors.fill: parent z: 101 - + property alias mycroftStatus: statusId + property alias talkAnimation: midbarAnim + property alias startSwitch: mycroftstartservicebutton + property alias retryButton: statusRetryBtn + property alias micIcon: qinputmicbx.iconSource + + function animateTalk(){ + midbarAnim.wsistalking() + } + Image { id: barAnim anchors.left: parent.left anchors.leftMargin: units.gridUnit * 0.1 anchors.verticalCenter: parent.verticalCenter source: "../images/mycroftsmaller.png" width: units.gridUnit * 1.4 height: units.gridUnit * 1.5 } ColorOverlay { anchors.fill: barAnim source: barAnim color: theme.linkColor } PlasmaComponents.Label { anchors.top: parent.top anchors.topMargin: 4 anchors.left: barAnim.right anchors.leftMargin: units.gridUnit * 0.25 font.capitalization: Font.SmallCaps id: logotextId text: i18n("Mycroft") font.bold: false; color: theme.textColor } PlasmaCore.SvgItem { id: topbarLeftDividerline anchors { left: logotextId.right leftMargin: units.gridUnit * 0.34 top: parent.top topMargin: 0 bottom: parent.bottom bottomMargin: 0 } width: linetopleftvertSvg.elementSize("vertical-line").width z: 110 elementId: "vertical-line" svg: PlasmaCore.Svg { id: linetopleftvertSvg; imagePath: "widgets/line" } } PlasmaComponents.Label { anchors.top: parent.top anchors.topMargin: 4 anchors.left: topbarLeftDividerline.right anchors.leftMargin: units.gridUnit * 0.25 font.capitalization: Font.SmallCaps id: statusId text: i18n("Disabled") font.bold: false; color: theme.textColor } PlasmaComponents.Button { id: statusRetryBtn anchors.top: parent.top anchors.topMargin: 1 anchors.left: statusId.right anchors.leftMargin: units.gridUnit * 0.50 anchors.bottom: parent.bottom anchors.bottomMargin: units.gridUnit * 0.25 text: i18n("Reconnect") width: units.gridUnit * 6 visible: false focus: false enabled: false onClicked: { - connectionObject.socket.active = false - connectionObject.socket.active = true - if (connectionObject.socket.active = false){ - mycroftConversationComponent.conversationModel.append({"itemType": "NonVisual", "InputQuery": connectionObject.socket.errorString}) + socket.active = false + socket.active = true + if (socket.active = false){ + mycroftConversationComponent.conversationModel.append({"itemType": "NonVisual", "InputQuery": socket.errorString}) } } } TopBarAnim { id: midbarAnim anchors.verticalCenter: parent.verticalCenter anchors.left: statusId.left anchors.right: topbarDividerline.left height: units.gridUnit * 4 z: 6 } PlasmaCore.SvgItem { id: topbarDividerline anchors { right: mycroftstartservicebutton.left rightMargin: units.gridUnit * 0.25 top: parent.top topMargin: 0 bottom: parent.bottom bottomMargin: 0 } width: linetopvertSvg.elementSize("vertical-line").width z: 110 elementId: "vertical-line" svg: PlasmaCore.Svg { id: linetopvertSvg; imagePath: "widgets/line" } } SwitchButton { anchors.right: qinputmicbx.left anchors.verticalCenter: topBarBGrect.verticalCenter id: mycroftstartservicebutton checked: false width: Math.round(units.gridUnit * 2) height: width z: 102 onClicked: { if (mycroftstartservicebutton.checked === false) { statusRetryBtn.visible = false statusRetryBtn.enabled = false PlasmaLa.LaunchApp.runCommand("bash", coreinstallstoppath); mycroftConversationComponent.conversationModel.clear() - suggst.visible = true; - connectionObject.socket.active = false; + bottomBarView.suggestBox.visible = true; + socket.active = false; midbarAnim.showstatsId() Dash.showDash("setVisible") } if (mycroftstartservicebutton.checked === true) { disclaimbox.visible = false; PlasmaLa.LaunchApp.runCommand("bash", coreinstallstartpath); if(appletSettings.innerset.dashboardSetting == "false"){ mycroftConversationComponent.conversationModel.clear() } - suggst.visible = true; + bottomBarView.suggestBox.visible = true; statusId.color = theme.linkColor statusId.text = i18n("Starting up..please wait") statusId.visible = true delay(15000, function() { - connectionObject.socket.active = true; + socket.active = true; }) } } } PlasmaComponents.ToolButton { id: qinputmicbx anchors.right: pinButton.left anchors.verticalCenter: parent.verticalCenter iconSource: "mic-on" tooltip: i18n("Toggle Mic") flat: true width: Math.round(units.gridUnit * 2) height: width z: 102 onClicked: { if (qinputmicbx.iconSource == "mic-on") { Applet.muteMicrophone() } else if (qinputmicbx.iconSource == "mic-off") { Applet.unmuteMicrophone() } } } PlasmaComponents.ToolButton { id: pinButton anchors.right: parent.right anchors.verticalCenter: topBarBGrect.verticalCenter width: Math.round(units.gridUnit * 1.5) height: width checkable: true iconSource: "window-pin" onCheckedChanged: plasmoid.hideOnWindowDeactivate = !checked z: 102 } } diff --git a/plasmoid/contents/ui/main.qml b/plasmoid/contents/ui/main.qml index af6e47a..510cc86 100644 --- a/plasmoid/contents/ui/main.qml +++ b/plasmoid/contents/ui/main.qml @@ -1,791 +1,460 @@ /* 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 import QtQuick.Layouts 1.3 import Qt.WebSockets 1.0 import Qt.labs.settings 1.0 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 QtQuick.Window 2.0 import QtGraphicalEffects 1.0 import "Applet.js" as Applet import "Autocomplete.js" as Autocomplete import "Conversation.js" as Conversation +import "ConversationLogic.js" as ConversationLogic import "Dashboard.js" as Dash Item { id: main Layout.fillWidth: true; Plasmoid.toolTipMainText: i18n("Mycroft") Plasmoid.switchWidth: units.gridUnit * 15 Plasmoid.switchHeight: units.gridUnit * 15 Layout.minimumWidth: units.gridUnit * 26 Component.onCompleted: { mycroftStatusCheckSocket.active = true Applet.detectInstallType(); Applet.refreshAllSkills(); } property var skillList: [] - property alias cbwidth: rectangle2.width - property var cbwidthmargin: rectangle2.width - conversationListScrollBar.width - units.gridUnit * 0.25 - property alias cbheight: rectangle2.height + property alias cbwidth: conversationViewFrameBox.width + property var cbwidthmargin: conversationViewFrameBox.width - mycroftConversationComponent.conversationViewScrollBar.width - units.gridUnit * 0.25 + property alias cbheight: conversationViewFrameBox.height property var dwrpaddedwidth: main.width + units.gridUnit * 1 property var cbdrawercontentheight: parent.height + units.gridUnit * 0.5 - rectanglebottombar.height property string defaultmcorestartpath: "/usr/share/plasma/plasmoids/org.kde.plasma.mycroftplasmoid/contents/code/startservice.sh" property string defaultmcorestoppath: "/usr/share/plasma/plasmoids/org.kde.plasma.mycroftplasmoid/contents/code/stopservice.sh" property string packagemcorestartcmd: "/usr/share/plasma/plasmoids/org.kde.plasma.mycroftplasmoid/contents/code/pkgstartservice.sh" property string packagemcorestopcmd: "/usr/share/plasma/plasmoids/org.kde.plasma.mycroftplasmoid/contents/code/pkgstopservice.sh" property string customlocstartpath: startsrvcustom.text property string customlocstoppath: stopsrvcustom.text property string customloc: " " property string coreinstallstartpath: defaultmcorestartpath property string coreinstallstoppath: defaultmcorestoppath property variant searchIndex: [] property variant results: [] property var smintent property var dataContent - property alias autoCompModel: completionItems - property alias textInput: qinput + property alias textInput: bottomBarView.queryInput property alias plcLmodel: placesListModel property alias dashLmodel: dashListModel property alias recipeLmodel: recipesListModel property alias recipeReadLmodel: recipeReadListModel property alias stackLmodel: stackexListModel property alias bookLmodel: bookListModel property alias wikiLmodel: wikiListModel property alias yelpLmodel: yelpListModel property bool intentfailure: false property bool locationUserSelected: false property bool connectCtx: false property bool micIsMuted property var geoLat property var geoLong property var globalcountrycode property var weatherMetric: "metric" property date currentDate: new Date() Connections { target: plasmoid onExpandedChanged: { if (plasmoid.expanded) { Dash.checkDashStatus() } } } Connections { target: PlasmaLa.Notify onNotificationStopSpeech: { var socketmessage = {}; socketmessage.type = "recognizer_loop:utterance"; socketmessage.data = {}; socketmessage.data.utterances = ["stop"]; socket.sendTextMessage(JSON.stringify(socketmessage)); } onNotificationShowResponse: { plasmoid.expanded = !plasmoid.expanded tabBar.currentTab = mycroftTab } } Connections { target: main2 ignoreUnknownSignals: true onSendShowMycroft: { plasmoid.expanded = !plasmoid.expanded tabBar.currentTab = mycroftTab } onSendShowSkills: { tabBar.currentTab = mycroftSkillsTab if(plasmoid.expanded = !plasmoid.expanded){ plasmoid.expanded } } onInstallList: { tabBar.currentTab = mycroftMSMinstTab if(plasmoid.expanded = !plasmoid.expanded){ plasmoid.expanded } } onKioMethod: { var sentFromKio = msgKioMethod var socketmessage = {}; socketmessage.type = "recognizer_loop:utterance"; socketmessage.data = {}; socketmessage.data.utterances = [sentFromKio]; socket.sendTextMessage(JSON.stringify(socketmessage)); } } -PlasmaCore.DataSource { + PlasmaCore.DataSource { id: geoDataSource dataEngine: "geolocation" onSourceAdded: { connectSource(source) } onNewData: { mycroftConversationComponent.conversationModel.clear() if (sourceName == "location"){ geoLat = data.latitude geoLong = data.longitude var globalcountry = data.country globalcountrycode = globalcountry.substring(0, 2) Dash.showDash("setVisible") } } } ListModel { id: dashListModel } ListModel { id: placesListModel } ListModel{ id: recipesListModel } ListModel { id: recipeReadListModel } ListModel { id: stackexListModel } ListModel { id: bookListModel } ListModel { id: wikiListModel } ListModel { id: yelpListModel } Timer { id: timer } - function delay(delayTime, cb) { - timer.interval = delayTime; - timer.repeat = false; - timer.triggered.connect(cb); - timer.start(); +function delay(delayTime, cb) { + timer.interval = delayTime; + timer.repeat = false; + timer.triggered.connect(cb); + timer.start(); } Item { - id: topBar - Layout.fillWidth: true - height: units.gridUnit * 2 - z: 101 - anchors { - top: main.top - topMargin: -1 - left: main.left - leftMargin: -1 - right: main.right - rightMargin: -1 + id: topBar + Layout.fillWidth: true + height: units.gridUnit * 2 + z: 101 + anchors { + top: main.top + topMargin: -1 + left: main.left + leftMargin: -1 + right: main.right + rightMargin: -1 } TopBarViewComponent { id: topBarView } } PlasmaCore.SvgItem { - anchors { - left: main.left - right: main.right - top: root.top - } - width: 1 - height: horlinetopbarSvg.elementSize("horizontal-line").height + anchors { + left: main.left + right: main.right + top: root.top + } + width: 1 + height: horlinetopbarSvg.elementSize("horizontal-line").height - elementId: "horizontal-line" - z: 110 - svg: PlasmaCore.Svg { - id: horlinetopbarSvg; - imagePath: "widgets/line" - } + elementId: "horizontal-line" + z: 110 + svg: PlasmaCore.Svg { + id: horlinetopbarSvg; + imagePath: "widgets/line" + } } Item { - id: root - anchors { - top: topBar.bottom - bottom: rectanglebottombar.top - left: parent.left - right: parent.right - } + id: root + anchors { + top: topBar.bottom + bottom: rectanglebottombar.top + left: parent.left + right: parent.right + } WebSocket { id: mycroftStatusCheckSocket url: appletSettings.innerset.wsurl active: true property bool _socketIsAlreadyActive: false - onStatusChanged: - if (mycroftStatusCheckSocket.status == WebSocket.Open && socket.status == WebSocket.Closed) { - socket.active = true - mycroftStatusCheckSocket._socketIsAlreadyActive = true - disclaimbox.visible = false; - mycroftstartservicebutton.checked = true - statusId.text = i18n("Connected") - statusId.color = "green" - statusId.visible = true - } - - else if (mycroftStatusCheckSocket.status == WebSocket.Error) { - mycroftstartservicebutton.checked = false - mycroftStatusCheckSocket._socketIsAlreadyActive = false - statusId.text = i18n("Disabled") - statusId.color = theme.textColor - statusId.visible = true - } + onStatusChanged: Applet.preSocketStatus() } WebSocket { id: socket url: appletSettings.innerset.wsurl onTextMessageReceived: { var somestring = JSON.parse(message) var msgType = somestring.type; Applet.playwaitanim(msgType); - - if (msgType === "mycroft.mic.get_status.response") { - var micState = somestring.data.muted - if(micState) { - micIsMuted = true - qinputmicbx.iconSource = "mic-off" - } - else if(!micState) { - micIsMuted = false - qinputmicbx.iconSource = "mic-on" - } - } - - if (msgType === "mycroft.skills.initialized") { - PlasmaLa.Notify.mycroftConnectionStatus(i18n("Ready..Let's Talk")) - } - - if (msgType === "recognizer_loop:utterance") { - qinput.focus = false; - var intpost = somestring.data.utterances; - qinput.text = intpost.toString() - mycroftConversationComponent.conversationModel.append({"itemType": "AskType", "InputQuery": intpost.toString()}) - midbarAnim.wsistalking() - } - - if (msgType === "recognizer_loop:utterance" && dashLmodel.count != 0){ - Dash.showDash("setHide") - } - - if (somestring.data.handler === "fallback" && somestring.data.fallback_handler === "WolframAlphaSkill.handle_fallback" && somestring.type === "mycroft.skill.handler.complete"){ - if(wolframfallbackswitch.checked == true){ - Conversation.getFallBackResult(qinput.text) - } - } - - if (somestring && somestring.data && typeof somestring.data.intent_type !== 'undefined'){ - smintent = somestring.data.intent_type; - console.log(smintent) - } - - if(somestring && somestring.data && typeof somestring.data.utterance !== 'undefined' && somestring.type === 'speak'){ - Conversation.filterSpeak(somestring.data.utterance); - } - - if(somestring && somestring.data && typeof somestring.data.desktop !== 'undefined' && somestring.type === "data") { - dataContent = somestring.data.desktop - Conversation.filterincoming(smintent, dataContent) - } - - if(somestring && somestring.data && typeof somestring.data.desktop !== 'undefined' && somestring.type === "visualObject") { - dataContent = somestring.data.desktop - Conversation.filtervisualObj(dataContent) - } - - if(somestring && somestring.data && typeof somestring.data.desktop !== 'undefined' && somestring.type === "placesObject") { - dataContent = somestring.data.desktop - Conversation.filterplacesObj(dataContent) - } - - if(somestring && somestring.data && typeof somestring.data.desktop !== 'undefined' && somestring.type === "recipesObject") { - dataContent = somestring.data.desktop - Conversation.filterRecipeObj(dataContent) - } - - if(somestring && somestring.data && typeof somestring.data.desktop !== 'undefined' && somestring.type === "balooObject") { - dataContent = somestring.data.desktop - Conversation.filterBalooObj(dataContent) - } - - if(somestring && somestring.data && typeof somestring.data.desktop !== 'undefined' && somestring.type === "stackresponseObject") { - dataContent = somestring.data.desktop - Conversation.filterstackObj(dataContent) - } - - if(somestring && somestring.data && typeof somestring.data.desktop !== 'undefined' && somestring.type === "bookObject") { - dataContent = somestring.data.desktop - Conversation.filterbookObj(dataContent) - } - - if(somestring && somestring.data && typeof somestring.data.desktop !== 'undefined' && somestring.type === "wikiObject") { - dataContent = somestring.data.desktop - Conversation.filterwikiObj(dataContent) - } - - if(somestring && somestring.data && typeof somestring.data.desktop !== 'undefined' && somestring.type === "wikiaddObject") { - dataContent = somestring.data.desktop - Conversation.filterwikiMoreObj(dataContent) - } - - if(somestring && somestring.data && typeof somestring.data.desktop !== 'undefined' && somestring.type === "yelpObject") { - dataContent = somestring.data.desktop - Conversation.filteryelpObj(dataContent) - } - - if(somestring && somestring.data && typeof somestring.data.desktop !== 'undefined' && somestring.type === "imageObject") { - dataContent = somestring.data.desktop - Conversation.filterImageObject(dataContent) - } - - - if (msgType === "speak" && !plasmoid.expanded && notificationswitch.checked == true) { - var post = somestring.data.utterance; - var title = "Mycroft's Reply:" - var notiftext = " "+ post; - PlasmaLa.Notify.mycroftResponse(title, notiftext); - } - - midbarAnim.wsistalking() + ConversationLogic.filterConversation(msgType, somestring) + topBarView.animateTalk() } - - onStatusChanged: if (socket.status == WebSocket.Error) { - statusId.text = i18n("Connection error") - statusId.color = "red" - mycroftstartservicebutton.circolour = "red" - midbarAnim.showstatsId() - statusRetryBtn.visible = true - statusRetryBtn.enabled = true - drawer.open() - waitanimoutter.aniRunError() - delay(1250, function() { - drawer.close() - }) - - } else if (socket.status == WebSocket.Open) { - statusId.text = i18n("Connected") - statusId.color = "green" - statusRetryBtn.visible = false - statusRetryBtn.enabled = false - mycroftstartservicebutton.circolour = "green" - mycroftStatusCheckSocket.active = false; - midbarAnim.showstatsId() - PlasmaLa.Notify.mycroftConnectionStatus("Connected") - drawer.open() - waitanimoutter.aniRunHappy() - delay(1250, function() { - drawer.close() - Applet.checkMicrophoneState() - }) - } else if (socket.status == WebSocket.Closed) { - statusId.text = i18n("Disabled") - statusId.color = theme.textColor - PlasmaLa.Notify.mycroftConnectionStatus("Disconnected") - mycroftstartservicebutton.circolour = Qt.lighter(theme.backgroundColor, 1.5) - midbarAnim.showstatsId() - } else if (socket.status == WebSocket.Connecting) { - statusId.text = i18n("Starting up..please wait") - statusId.color = theme.linkColor - mycroftstartservicebutton.circolour = "steelblue" - midbarAnim.showstatsId() - } else if (socket.status == WebSocket.Closing) { - statusId.text = i18n("Shutting down") - statusId.color = theme.textColor - midbarAnim.showstatsId() - } + onStatusChanged: Applet.mainSocketStatus() } ColumnLayout { - id: sidebar - height: units.gridUnit * 6 - width: units.gridUnit * 2 - - PlasmaComponents.TabBar { - id: tabBar - anchors.fill: parent - tabPosition: Qt.LeftEdge; + id: sidebar + height: units.gridUnit * 6 + width: units.gridUnit * 2 - PlasmaComponents.TabButton { - id: mycroftTab - Layout.fillHeight: true - Layout.fillWidth: true - iconSource: "go-home" + PlasmaComponents.TabBar { + id: tabBar + anchors.fill: parent + tabPosition: Qt.LeftEdge; + PlasmaComponents.TabButton { + id: mycroftTab + Layout.fillHeight: true + Layout.fillWidth: true + iconSource: "go-home" + PlasmaCore.ToolTipArea { - id: tooltiptab1 - mainText: i18n("Conversation") - anchors.fill: parent + id: tooltiptab1 + mainText: i18n("Conversation") + anchors.fill: parent + } } - } + + PlasmaComponents.TabButton { + id: mycroftSkillsTab + Layout.fillHeight: true + Layout.fillWidth: true + iconSource: "games-hint" - PlasmaComponents.TabButton { - id: mycroftSkillsTab - Layout.fillHeight: true - Layout.fillWidth: true - iconSource: "games-hint" - PlasmaCore.ToolTipArea { - id: tooltiptab2 - mainText: i18n("Hints/Tips") - anchors.fill: parent + id: tooltiptab2 + mainText: i18n("Hints/Tips") + anchors.fill: parent + } } - } - - PlasmaComponents.TabButton { - id: mycroftSettingsTab - Layout.fillHeight: true - Layout.fillWidth: true - iconSource: "games-config-options" - + + PlasmaComponents.TabButton { + id: mycroftSettingsTab + Layout.fillHeight: true + Layout.fillWidth: true + iconSource: "games-config-options" + PlasmaCore.ToolTipArea { - id: tooltiptab3 - mainText: i18n("Settings") - anchors.fill: parent + id: tooltiptab3 + mainText: i18n("Settings") + anchors.fill: parent + } } - } - - PlasmaComponents.TabButton { - id: mycroftMSMinstTab - Layout.fillHeight: true - Layout.fillWidth: true - iconSource: "kmouth-phresebook-new" - - + + PlasmaComponents.TabButton { + id: mycroftMSMinstTab + Layout.fillHeight: true + Layout.fillWidth: true + iconSource: "kmouth-phresebook-new" + PlasmaCore.ToolTipArea { id: tooltiptab4 mainText: i18n("Skill Browser") anchors.fill: parent } } } } PlasmaCore.SvgItem { anchors { left: parent.left leftMargin: sidebar.width top: parent.top topMargin: 1 bottom: parent.bottom bottomMargin: 1 } width: lineSvg.elementSize("vertical-line").width z: 110 elementId: "vertical-line" svg: PlasmaCore.Svg { id: lineSvg; imagePath: "widgets/line" } } ColumnLayout { - id: mycroftcolumntab - visible: tabBar.currentTab == mycroftTab; - anchors.top: root.top - anchors.left: sidebar.right - anchors.leftMargin: units.gridUnit * 0.25 - anchors.right: root.right - anchors.bottom: root.bottom - - Item { - id: rectangle2 - anchors.top: mycroftcolumntab.top - anchors.topMargin:15 - anchors.left: mycroftcolumntab.left - anchors.right: mycroftcolumntab.right - anchors.bottom: mycroftcolumntab.bottom - - DropArea { - anchors.fill: parent; - id: dragTarget - onEntered: { - for(var i = 0; i < drag.urls.length; i++) - if(validateFileExtension(drag.urls[i])) - return - console.log("No valid files, refusing drag event") - drag.accept() - dragTarget.enabled = false - } - - onDropped: { - for(var i = 0; i < drop.urls.length; i++){ - var ext = getFileExtenion(drop.urls[i]); - if(ext === "jpg" || ext === "png" || ext === "jpeg"){ - var durl = String(drop.urls[i]); - mycroftConversationComponent.conversationModel.append({ - "itemType": "DropImg", - "InputQuery": durl - }) - inputlistView.positionViewAtEnd(); - } - - if(ext === 'mp3'){ - console.log('mp3'); - } - } - } - - Disclaimer{ - id: disclaimbox - visible: false - } - - ConversationView{ - id: mycroftConversationComponent - anchors.fill: parent + id: mycroftcolumntab + visible: tabBar.currentTab == mycroftTab; + anchors.top: root.top + anchors.left: sidebar.right + anchors.leftMargin: units.gridUnit * 0.25 + anchors.right: root.right + anchors.bottom: root.bottom + + Item { + id: conversationViewFrameBox + anchors.top: mycroftcolumntab.top + anchors.topMargin:15 + anchors.left: mycroftcolumntab.left + anchors.right: mycroftcolumntab.right + anchors.bottom: mycroftcolumntab.bottom + + Disclaimer{ + id: disclaimbox + visible: false + } + + ConversationView{ + id: mycroftConversationComponent + anchors.fill: parent } } } -} ColumnLayout { - id: mycroftSkillscolumntab - visible: tabBar.currentTab == mycroftSkillsTab; - anchors.top: root.top - anchors.left: sidebar.right - anchors.leftMargin: units.gridUnit * 0.25 - anchors.right: root.right - anchors.bottom: root.bottom + id: mycroftSkillscolumntab + visible: tabBar.currentTab == mycroftSkillsTab; + anchors.top: root.top + anchors.left: sidebar.right + anchors.leftMargin: units.gridUnit * 0.25 + anchors.right: root.right + anchors.bottom: root.bottom SkillsTipViewComponent { id: skillTipsView } } ColumnLayout { - id: mycroftSettingsColumn - visible: tabBar.currentTab == mycroftSettingsTab; - anchors.top: root.top - anchors.left: sidebar.right - anchors.leftMargin: units.gridUnit * 0.25 - anchors.right: root.right - anchors.bottom: root.bottom - + id: mycroftSettingsColumn + visible: tabBar.currentTab == mycroftSettingsTab; + anchors.top: root.top + anchors.left: sidebar.right + anchors.leftMargin: units.gridUnit * 0.25 + anchors.right: root.right + anchors.bottom: root.bottom + SettingsComponent{ id: appletSettings } } ColumnLayout { - id: mycroftMsmColumn - visible: tabBar.currentTab == mycroftMSMinstTab; - anchors.top: root.top - anchors.left: sidebar.right - anchors.leftMargin: units.gridUnit * 0.25 - anchors.right: root.right - anchors.bottom: root.bottom - + id: mycroftMsmColumn + visible: tabBar.currentTab == mycroftMSMinstTab; + anchors.top: root.top + anchors.left: sidebar.right + anchors.leftMargin: units.gridUnit * 0.25 + anchors.right: root.right + anchors.bottom: root.bottom + SkillsInstallerComponent{ id: skillsInstallerView } } } PlasmaCore.SvgItem { anchors { left: main.left right: main.right bottom: root.bottom } width: 1 height: horlineSvg.elementSize("horizontal-line").height elementId: "horizontal-line" z: 110 svg: PlasmaCore.Svg { id: horlineSvg; imagePath: "widgets/line" } } Item { id: rectanglebottombar height: units.gridUnit * 3.5 anchors.left: main.left anchors.right: main.right anchors.bottom: main.bottom z: 110 - ListModel { - id: completionItems - } - - Drawer { - id: drawer - width: dwrpaddedwidth - height: units.gridUnit * 5.5 - edge: Qt.BottomEdge - - Rectangle { - color: theme.backgroundColor - anchors.fill: parent - } - - CustomIndicator { - id: waitanimoutter - height: 70 - width: 70 - anchors.verticalCenter: parent.verticalCenter - anchors.horizontalCenter: parent.horizontalCenter - } - } - - Rectangle { - id: suggestionbottombox - anchors.top: parent.top - anchors.bottom: qinput.top - anchors.right: parent.right - anchors.left: parent.left - color: theme.backgroundColor - - Suggestions { - id: suggst - visible: true; - } - } - - Rectangle { - id: keyboardactivaterect - color: theme.backgroundColor - border.width: 1 - border.color: Qt.lighter(theme.backgroundColor, 1.2) - width: units.gridUnit * 2 - height: qinput.height - anchors.bottom: parent.bottom - anchors.left: parent.left - - PlasmaCore.IconItem { - id: keybdImg - source: "input-keyboard" - anchors.centerIn: parent - width: units.gridUnit * 1.5 - height: units.gridUnit * 1.5 - } - - Rectangle { - id: keybindic - anchors.bottom: parent.bottom - anchors.bottomMargin: 4 - anchors.left: parent.left - anchors.right: parent.right - anchors.leftMargin: 8 - anchors.rightMargin: 8 - height: 2 - color: "green" - } - - MouseArea{ - anchors.fill: parent - hoverEnabled: true - onEntered: {} - onExited: {} - onClicked: { - if(qinput.visible === false){ - toggleInputMethod("KeyboardSetActive") - } - else if(qinput.visible === true){ - toggleInputMethod("KeyboardSetDisable") - } - } - } - } - - PlasmaComponents.TextField { - id: qinput - anchors.left: keyboardactivaterect.right - anchors.bottom: parent.bottom - anchors.right: parent.right - placeholderText: i18n("Enter Query or Say 'Hey Mycroft'") - clearButtonShown: true - - onAccepted: { - var doesExist = Autocomplete.autoAppend(autoCompModel, function(item) { return item.name === qinput.text }, qinput.text) - var evaluateExist = doesExist - if(evaluateExist === null){ - autoCompModel.append({"name": qinput.text}); - } - suggst.visible = true; - var socketmessage = {}; - socketmessage.type = "recognizer_loop:utterance"; - socketmessage.data = {}; - socketmessage.data.utterances = [qinput.text]; - socket.sendTextMessage(JSON.stringify(socketmessage)); - qinput.text = ""; - } - - onTextChanged: { - Autocomplete.evalAutoLogic(); + BottomBarViewComponent { + id: bottomBarView } } - - CustomMicIndicator { - id: customMicIndicator - anchors.centerIn: parent - visible: false - } - - AutocompleteBox { - id: suggestionsBox - model: completionItems - width: parent.width - anchors.bottom: qinput.top - anchors.left: parent.left - anchors.right: parent.right - filter: textInput.text - property: "name" - onItemSelected: complete(item) - - function complete(item) { - if (item !== undefined) - textInput.text = item.name - } - } -} - }