CuteLogger
Fast and simple logging solution for Qt based applications
qmlextension.h
1/*
2 * Copyright (c) 2025 Meltytech, LLC
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef QMLEXTENSION_H
19#define QMLEXTENSION_H
20
21#include <QDir>
22#include <QObject>
23#include <QQmlListProperty>
24#include <QString>
25
26class QmlExtensionFile : public QObject
27{
28 Q_OBJECT
29 Q_PROPERTY(QString name MEMBER m_name NOTIFY changed)
30 Q_PROPERTY(QString description MEMBER m_description NOTIFY changed)
31 Q_PROPERTY(QString file MEMBER m_file NOTIFY changed)
32 Q_PROPERTY(QString url MEMBER m_url NOTIFY changed)
33 Q_PROPERTY(QString size MEMBER m_size NOTIFY changed)
34 Q_PROPERTY(bool standard MEMBER m_standard NOTIFY changed)
35
36public:
37 explicit QmlExtensionFile(QObject *parent = 0);
38
39 QString name() const { return m_name; }
40 QString description() const { return m_description; }
41 QString file() const { return m_file; }
42 QString url() const { return m_url; }
43 QString size() const { return m_size; }
44 bool standard() const { return m_standard; }
45
46signals:
47 void changed();
48
49private:
50 QString m_name;
51 QString m_description;
52 QString m_file;
53 QString m_url;
54 QString m_size;
55 bool m_standard;
56};
57
58class QmlExtension : public QObject
59{
60 Q_OBJECT
61 Q_PROPERTY(QString id READ id WRITE setId NOTIFY changed)
62 Q_PROPERTY(QString name READ name WRITE setName NOTIFY changed)
63 Q_PROPERTY(QString version READ version WRITE setVersion NOTIFY changed)
64 Q_PROPERTY(QQmlListProperty<QmlExtensionFile> files READ files NOTIFY changed)
65
66public:
67 static QmlExtension *load(const QString &id);
68 static QString extensionFileName(const QString &id);
69 static QDir installDir(const QString &id);
70 static QDir appDir(const QString &id);
71 static const QString WHISPER_ID;
72
73 explicit QmlExtension(QObject *parent = 0);
74
75 QString id() const { return m_id; }
76 void setId(const QString &);
77 QString name() const { return m_name; }
78 void setName(const QString &);
79 QString version() const { return m_version; }
80 void setVersion(const QString &);
81 QQmlListProperty<QmlExtensionFile> files()
82 {
83 return QQmlListProperty<QmlExtensionFile>(this, &m_files);
84 }
85 int fileCount() const { return m_files.count(); }
86 QmlExtensionFile *file(int index) const { return m_files[index]; }
87 QString localPath(int index);
88 bool downloaded(int index);
89
90signals:
91 void changed();
92
93private:
94 QString m_id;
95 QString m_name;
96 QString m_version;
97 QList<QmlExtensionFile *> m_files;
98};
99
100#endif // QMLEXTENSION_H