File indexing completed on 2024-04-21 08:32:06

0001 /*
0002  * Copyright 2021 Aditya Mehra <aix.m@outlook.com>
0003  *
0004  * Licensed under the Apache License, Version 2.0 (the "License");
0005  * you may not use this file except in compliance with the License.
0006  * You may obtain a copy of the License at
0007  *
0008  *    http://www.apache.org/licenses/LICENSE-2.0
0009  *
0010  * Unless required by applicable law or agreed to in writing, software
0011  * distributed under the License is distributed on an "AS IS" BASIS,
0012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013  * See the License for the specific language governing permissions and
0014  * limitations under the License.
0015  *
0016  */
0017 
0018 #ifndef QSKILL_H
0019 #define QSKILL_H
0020 
0021 #include <QObject>
0022 #include <QVector>
0023 #include <QQmlListProperty>
0024 #include <QStringList>
0025 #include <QSettings>
0026 #include "skillentry.h"
0027 #include "controller.h"
0028 
0029 class Controller;
0030 class SkillManager : public QObject
0031 {
0032     Q_OBJECT
0033     Q_PROPERTY(QString skillNamespace READ skillNamespace WRITE setSkillNamespace NOTIFY skillNamespaceChanged)
0034     Q_PROPERTY(QString socketAddress READ socketAddress WRITE setSocketAddress NOTIFY socketAddressChanged)
0035     Q_PROPERTY(QQmlListProperty<SkillEntry> items READ items)
0036     Q_CLASSINFO("DefaultProperty", "items")
0037 
0038 public:
0039     explicit SkillManager(QObject *parent = nullptr);
0040     ~SkillManager() override;
0041     QString skillNamespace() const;
0042     QString socketAddress() const;
0043     QQmlListProperty<SkillEntry> items();
0044 
0045 public Q_SLOTS:
0046     int itemsCount() const;
0047     SkillEntry *item(int) const;
0048     void setSkillNamespace(QString skillNamespace);
0049     QJsonObject toJson(SkillEntry* &item) const;
0050     void createSkill();
0051     void deleteSkill();
0052     bool isSocketReady() const;
0053     void onMainSocketMessageReceived(const QString &message);
0054     void setSocketAddress(QString socketAddress);
0055 
0056 Q_SIGNALS:
0057     void skillNamespaceChanged();
0058     void socketReadyChanged(bool socketReady);
0059     void intentResponse(const QVariant &response, const QString &action);
0060     void socketAddressChanged();
0061 
0062 private:
0063     bool m_socketReady = false;
0064     QSettings m_settings;
0065     QList<SkillEntry*> m_items;
0066     Controller *m_controller;
0067 };
0068 
0069 #endif // LIBQMYCROFT_H