File indexing completed on 2024-11-10 05:11:09
0001 /* 0002 * Copyright 2018 by Marco Martin <mart@kde.org> 0003 * Copyright 2018 David Edmundson <davidedmundson@kde.org> 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 #pragma once 0020 0021 #include "mycroftcontroller.h" 0022 0023 #include <QQuickItem> 0024 #include <QPointer> 0025 0026 class ActiveSkillsModel; 0027 class AbstractSkillView; 0028 class AbstractDelegate; 0029 class SessionDataMap; 0030 class QTranslator; 0031 0032 class AbstractSkillView: public QQuickItem 0033 { 0034 Q_OBJECT 0035 Q_PROPERTY(MycroftController::Status status READ status NOTIFY statusChanged) 0036 0037 Q_PROPERTY(ActiveSkillsModel *activeSkills READ activeSkills CONSTANT) 0038 0039 public: 0040 enum CustomFocusReasons { 0041 ServerEventFocusReason = Qt::OtherFocusReason 0042 }; 0043 0044 AbstractSkillView(QQuickItem *parent = nullptr); 0045 ~AbstractSkillView(); 0046 0047 MycroftController::Status status() const; 0048 0049 ActiveSkillsModel *activeSkills() const; 0050 0051 0052 //API for MycroftController, NOT QML 0053 /** 0054 * Url of the Web socket 0055 */ 0056 QUrl url() const; 0057 0058 /** 0059 * Sets the url for the web socket 0060 */ 0061 void setUrl(const QUrl &url); 0062 0063 /** 0064 * Unique identifier for this GUI 0065 */ 0066 QString id() const; 0067 0068 /** 0069 * @internal triggers an event: invoked by the c++ side of the delegates via AbstractDelegate::triggerEvent 0070 */ 0071 void triggerEvent(const QString &skillId, const QString &eventName, const QVariantMap ¶meters); 0072 0073 /** 0074 * @returns the property map that contains the data for a given skill, 0075 * if no data is present for a skill, it gets created if and only if it's an active skill. 0076 * @internal this is strictly for internal use only and must *NOT* be exposed to QML. used by the class itself and the autotests. 0077 */ 0078 SessionDataMap *sessionDataForSkill(const QString &skillId); 0079 0080 void writeProperties(const QString &skillId, const QVariantMap &data); 0081 void deleteProperty(const QString &skillId, const QString &property); 0082 0083 Q_SIGNALS: 0084 /** 0085 * The skill that was open due voice interaction has been closed either due to timeout or user interaction 0086 */ 0087 void activeSkillClosed(); 0088 //socket stuff 0089 void statusChanged(); 0090 void closed(); 0091 0092 private: 0093 void onGuiSocketMessageReceived(const QString &message); 0094 0095 QTimer m_reconnectTimer; 0096 QTimer m_trimComponentsTimer; 0097 QString m_id; 0098 QUrl m_url; 0099 QHash<QString, SessionDataMap *> m_skillData; 0100 QHash<QString, QTranslator *> m_translatorsForSkill; 0101 0102 MycroftController *m_controller; 0103 QWebSocket *m_guiWebSocket; 0104 ActiveSkillsModel *m_activeSkillsModel; 0105 }; 0106