FlatpakResource.h 6.15 KB
Newer Older
1
2
3
4
5
6
7
/*
 *   SPDX-FileCopyrightText: 2013 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
 *   SPDX-FileCopyrightText: 2017 Jan Grulich <jgrulich@redhat.com>
 *
 *   SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
 */

Jan Grulich's avatar
Jan Grulich committed
8
9
10
#ifndef FLATPAKRESOURCE_H
#define FLATPAKRESOURCE_H

11
#include <resources/AbstractResource.h>
Jan Grulich's avatar
Jan Grulich committed
12

13
#include "flatpak-helper.h"
Jan Grulich's avatar
Jan Grulich committed
14

15
16
#include <AppStreamQt/component.h>

Jan Grulich's avatar
Jan Grulich committed
17
18
#include <QPixmap>

Jan Grulich's avatar
Jan Grulich committed
19
class AddonList;
20
class FlatpakBackend;
21
22
class FlatpakSource;

Jan Grulich's avatar
Jan Grulich committed
23
24
class FlatpakResource : public AbstractResource
{
Alexander Lohnau's avatar
Alexander Lohnau committed
25
    Q_OBJECT
26
27
    Q_PROPERTY(QStringList topObjects MEMBER m_objects CONSTANT)
    Q_PROPERTY(QString attentionText READ attentionText CONSTANT)
Jan Grulich's avatar
Jan Grulich committed
28
public:
Alexander Lohnau's avatar
Alexander Lohnau committed
29
    explicit FlatpakResource(const AppStream::Component &component, FlatpakInstallation *installation, FlatpakBackend *parent);
30

31
32
33
    enum PropertyKind {
        DownloadSize = 0,
        InstalledSize,
34
        RequiredRuntime,
35
    };
36
    Q_ENUM(PropertyKind)
37
38
39
40
41

    enum PropertyState {
        NotKnownYet = 0,
        AlreadyKnown,
        UnknownOrFailed,
42
        Fetching,
43
    };
44
    Q_ENUM(PropertyState)
45

46
47
    enum ResourceType {
        DesktopApp = 0,
48
        Runtime,
49
        Extension,
50
        Source,
51
    };
52
    Q_ENUM(ResourceType)
53

54
55
56
57
58
59
60
    enum FlatpakFileType {
        NotAFile,
        FileFlatpak,
        FileFlatpakRef,
    };
    Q_ENUM(FlatpakFileType)

61
    struct Id {
62
        const QString id;
63
64
        QString branch;
        QString arch;
Alexander Lohnau's avatar
Alexander Lohnau committed
65
66
67
68
69
70
71
        bool operator!=(const Id &other) const
        {
            return !operator==(other);
        }
        bool operator==(const Id &other) const
        {
            return &other == this
72
                || (other.id == id //
73
74
75
                    && other.branch == branch //
                    && other.arch == arch //
                );
Alexander Lohnau's avatar
Alexander Lohnau committed
76
        }
77
78
    };

Alexander Lohnau's avatar
Alexander Lohnau committed
79
80
    static QString typeAsString(ResourceType type)
    {
81
82
83
84
85
86
        if (type == DesktopApp) {
            return QLatin1String("app");
        }
        return QLatin1String("runtime");
    }

87
    QString installationPath() const;
Alexander Lohnau's avatar
Alexander Lohnau committed
88
    static QString installationPath(FlatpakInstallation *installation);
89

90
    AppStream::Component appstreamComponent() const;
Jan Grulich's avatar
Jan Grulich committed
91
92
93
94
    QList<PackageState> addonsInformation() override;
    QString availableVersion() const override;
    QString appstreamId() const override;
    QString arch() const;
95
    QString branch() const;
Jan Grulich's avatar
Jan Grulich committed
96
97
98
99
    bool canExecute() const override;
    QStringList categories() override;
    QString comment() override;
    QString commit() const;
100
    quint64 downloadSize() const;
Jan Grulich's avatar
Jan Grulich committed
101
102
    QVariant icon() const override;
    QString installedVersion() const override;
103
    quint64 installedSize() const;
104
    AbstractResource::Type type() const override;
Jan Grulich's avatar
Jan Grulich committed
105
    QUrl homepage() override;
106
107
108
    QUrl helpURL() override;
    QUrl bugURL() override;
    QUrl donationURL() override;
109
    FlatpakFileType flatpakFileType() const;
Jan Grulich's avatar
Jan Grulich committed
110
    QString flatpakName() const;
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
111
    QJsonArray licenses() override;
Jan Grulich's avatar
Jan Grulich committed
112
    QString longDescription() override;
113
    QString name() const override;
Jan Grulich's avatar
Jan Grulich committed
114
115
    QString origin() const override;
    QString packageName() const override;
116
    PropertyState propertyState(PropertyKind kind) const;
Jan Grulich's avatar
Jan Grulich committed
117
    QUrl resourceFile() const;
118
    QString runtime() const;
Jan Grulich's avatar
Jan Grulich committed
119
    QString section() override;
120
    quint64 size() override;
121
    QString sizeDescription() override;
Jan Grulich's avatar
Jan Grulich committed
122
    AbstractResource::State state() override;
123
    ResourceType resourceType() const;
124
    QString typeAsString() const;
125
    FlatpakResource::Id uniqueId() const;
126
    QUrl url() const override;
127
    QDate releaseDate() const override;
128
    QString author() const override;
129
    QStringList extends() const override;
130
    QString versionString() override;
Jan Grulich's avatar
Jan Grulich committed
131

Alexander Lohnau's avatar
Alexander Lohnau committed
132
133
    FlatpakInstallation *installation() const
    {
134
        return m_installation;
Alexander Lohnau's avatar
Alexander Lohnau committed
135
    }
136

Jan Grulich's avatar
Jan Grulich committed
137
138
139
    void invokeApplication() const override;
    void fetchChangelog() override;
    void fetchScreenshots() override;
140
    QSet<QString> alternativeAppstreamIds() const override;
141
    QStringList mimetypes() const override;
Jan Grulich's avatar
Jan Grulich committed
142

143
    void setBranch(const QString &branch);
Jan Grulich's avatar
Jan Grulich committed
144
    void setBundledIcon(const QPixmap &pixmap);
145
    void setDownloadSize(quint64 size);
146
    void setIconPath(const QString &path);
147
    void setInstalledSize(quint64 size);
148
    void setFlatpakFileType(FlatpakFileType fileType);
Jan Grulich's avatar
Jan Grulich committed
149
    void setFlatpakName(const QString &name);
150
    void setOrigin(const QString &origin);
151
    void setPropertyState(PropertyKind kind, PropertyState state);
Jan Grulich's avatar
Jan Grulich committed
152
    void setResourceFile(const QUrl &url);
153
    void setRuntime(const QString &runtime);
154
    void setState(State state, bool shouldEmit = true);
155
    void setType(ResourceType type);
156
157
158
159
    void setResourceLocation(const QUrl &location)
    {
        m_resourceLocation = location;
    }
Jan Grulich's avatar
Jan Grulich committed
160

Alexander Lohnau's avatar
Alexander Lohnau committed
161
    void updateFromRef(FlatpakRef *ref);
162
    QString ref() const;
163
    QString sourceIcon() const override;
164
    QString installPath() const;
165
    void updateFromAppStream();
166
    void setArch(const QString &arch);
167
    QString attentionText() const;
168
169
170
171
    void setAvailableVersion(const QString &version)
    {
        m_availableVersion = version;
    }
172

173
174
175
176
177
178
179
180
181
    void setTemporarySource(const QSharedPointer<FlatpakSource> &temp)
    {
        m_temp = temp;
    }
    QSharedPointer<FlatpakSource> temporarySource() const
    {
        return m_temp;
    }

182
Q_SIGNALS:
183
    void propertyStateChanged(FlatpakResource::PropertyKind kind, FlatpakResource::PropertyState state);
184

185
186
187
private:
    void setCommit(const QString &commit);

Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
188
    const AppStream::Component m_appdata;
189
    FlatpakResource::Id m_id;
190
    FlatpakRefKind m_flatpakRefKind;
Jan Grulich's avatar
Jan Grulich committed
191
    QPixmap m_bundledIcon;
Jan Grulich's avatar
Jan Grulich committed
192
    QString m_commit;
193
    qint64 m_downloadSize;
194
    FlatpakFileType m_flatpakFileType = FlatpakResource::NotAFile;
Jan Grulich's avatar
Jan Grulich committed
195
    QString m_flatpakName;
196
    QString m_iconPath;
197
    qint64 m_installedSize;
198
    QHash<PropertyKind, PropertyState> m_propertyStates;
Jan Grulich's avatar
Jan Grulich committed
199
    QUrl m_resourceFile;
200
    QUrl m_resourceLocation;
201
    QString m_runtime;
202
    AbstractResource::State m_state;
203
204
    FlatpakInstallation *const m_installation;
    QString m_origin;
205
    QString m_availableVersion;
206
    FlatpakResource::ResourceType m_type = DesktopApp;
207
    QSharedPointer<FlatpakSource> m_temp;
208
    static const QStringList m_objects;
Jan Grulich's avatar
Jan Grulich committed
209
210
};

211
212
inline uint qHash(const FlatpakResource::Id &key)
{
213
    return qHash(key.id) ^ qHash(key.branch) ^ qHash(key.arch);
214
215
}

Jan Grulich's avatar
Jan Grulich committed
216
#endif // FLATPAKRESOURCE_H