Warning, /utilities/mycroft-plasmoid/plasmoid/contents/ui/BottomBarViewComponent.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 as Controls
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.extras 2.0 as PlasmaExtras
0028 import org.kde.kirigami 2.5 as Kirigami
0029 import QtGraphicalEffects 1.0
0030 import Mycroft 1.0 as Mycroft
0031 
0032 Item {
0033     id: appletBottomBarComponent
0034     anchors.fill: parent
0035     property alias autoCompModel: completionItems
0036     property alias queryInput: qinput
0037     property var lastMessage
0038     
0039     function autoAppend(model, getinputstring, setinputstring) {
0040         for(var i = 0; i < model.count; ++i)
0041             if (getinputstring(model.get(i))){
0042                 return true
0043             }
0044         return null
0045     }
0046 
0047     function evalAutoLogic() {
0048         if (suggestionsBox.currentIndex === -1) {
0049         } else {
0050             suggestionsBox.complete(suggestionsBox.currentItem)
0051         }
0052     }
0053 
0054 
0055     ListModel {
0056         id: completionItems
0057     }
0058     
0059     ColumnLayout {
0060         anchors.fill: parent
0061         
0062         
0063         RowLayout{
0064             Layout.fillWidth: true
0065             Layout.fillHeight: true
0066         
0067             PlasmaComponents.TextField {
0068                 id: qinput
0069                 Layout.fillWidth: true
0070                 Layout.preferredHeight: Kirigami.Units.gridUnit * 2
0071                 placeholderText: i18n("Enter Query or Say 'Hey Mycroft'")
0072                 clearButtonShown: true
0073 
0074                 onAccepted: {
0075                     if(qinput.text !== ""){
0076                         lastMessage = qinput.text
0077                     }
0078                     var doesExist = appletBottomBarComponent.autoAppend(autoCompModel, function(item) { return item.name === qinput.text }, qinput.text)
0079                     var evaluateExist = doesExist
0080                     if(evaluateExist === null){
0081                         autoCompModel.append({"name": qinput.text});
0082                     }
0083                     Mycroft.MycroftController.sendText(qinput.text);
0084                     Mycroft.MycroftController.sendRequest('mycroft.qinput.text', {"inputQuery": qinput.Text})
0085                     qinput.text = "";
0086                 }
0087 
0088                 onTextChanged: {
0089                     appletBottomBarComponent.evalAutoLogic();
0090                 }
0091 
0092                 AutocompleteBox {
0093                     id: suggestionsBox
0094                     model: completionItems
0095                     width: parent.width
0096                     anchors.bottom: parent.top
0097                     anchors.left: parent.left
0098                     anchors.right: parent.right
0099                     filter: qinput.text
0100                     property: "name"
0101                     onItemSelected: complete(item)
0102 
0103                     function complete(item) {
0104                         if (item !== undefined)
0105                             qinput.text = item.name
0106                     }
0107                 }
0108             }
0109             
0110             PlasmaComponents.Button {
0111                 Layout.preferredHeight: Kirigami.Units.iconSizes.medium
0112                 Layout.preferredWidth: Kirigami.Units.iconSizes.medium
0113                 Kirigami.Icon{
0114                     anchors.centerIn: parent
0115                     width: Kirigami.Units.iconSizes.small
0116                     height: Kirigami.Units.iconSizes.small
0117                     source: "audio-input-microphone"
0118                 }
0119                 onClicked:  {
0120                         audioRecorder.open()  
0121                 }
0122                 visible: plasmoid.configuration.enableRemoteSTT
0123             }
0124         }
0125     }
0126 }