File indexing completed on 2024-09-15 04:49:26
0001 /** 0002 * SPDX-FileCopyrightText: 2022 Suhaas Joshi <joshiesuhaas0@gmail.com> 0003 * SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk> 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "flatpakpermission.h" 0010 0011 #include <QAbstractListModel> 0012 #include <QList> 0013 #include <QPointer> 0014 #include <QString> 0015 #include <QUrl> 0016 0017 class FlatpakReferencesModel; 0018 class FlatpakPermissionModel; 0019 0020 // Slightly similar to FlatpakResource from libdiscover 0021 class FlatpakReference : public QObject 0022 { 0023 Q_OBJECT 0024 Q_PROPERTY(QString version READ version CONSTANT FINAL) 0025 Q_PROPERTY(QString displayName READ displayName CONSTANT FINAL) 0026 Q_PROPERTY(QUrl iconSource READ iconSource CONSTANT FINAL) 0027 0028 public: 0029 explicit FlatpakReference(FlatpakReferencesModel *parent, 0030 const QString &flatpakName, 0031 const QString &arch, 0032 const QString &branch, 0033 const QString &version, 0034 const QString &displayName, 0035 const QUrl &iconSource, 0036 const QStringList &metadataAndOverridesFiles); 0037 0038 FlatpakReferencesModel *parent() const; 0039 0040 QString arch() const; 0041 QString branch() const; 0042 QString version() const; 0043 0044 QUrl iconSource() const; 0045 0046 const QStringList &metadataAndOverridesFiles() const; 0047 QStringList defaultsFiles() const; 0048 const QString &userLevelPerAppOverrideFile() const; 0049 0050 QString displayName() const; 0051 QString flatpakName() const; 0052 QString ref() const; 0053 0054 FlatpakPermissionModel *permissionsModel(); 0055 void setPermissionsModel(FlatpakPermissionModel *model); 0056 0057 void load(); 0058 void save(); 0059 void defaults(); 0060 bool isSaveNeeded() const; 0061 bool isDefaults() const; 0062 0063 Q_SIGNALS: 0064 void needsLoad(); 0065 void settingsChanged(); 0066 0067 private: 0068 // ID of a ref constitutes of these three members: 0069 QString m_flatpakName; 0070 QString m_arch; 0071 QString m_branch; 0072 // Human-readable version string. 0073 QString m_version; 0074 // Human-readable app name, only exists for installed apps. 0075 // Might be empty, in which case code should fallback to flatpakName. 0076 QString m_displayName; 0077 0078 QUrl m_iconSource; 0079 // List of metadata and overrides files, in the order they should be 0080 // loaded and merged, starting from base app metadata and ending with 0081 // per-app user-level override. 0082 QStringList m_metadataAndOverridesFiles; 0083 0084 QPointer<FlatpakPermissionModel> m_permissionsModel; 0085 }; 0086 0087 class FlatpakReferencesModel : public QAbstractListModel 0088 { 0089 Q_OBJECT 0090 public: 0091 explicit FlatpakReferencesModel(QObject *parent = nullptr); 0092 0093 enum Roles { Name = Qt::UserRole + 1, Version, Icon, Ref }; 0094 Q_ENUM(Roles) 0095 0096 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0097 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0098 QHash<int, QByteArray> roleNames() const override; 0099 0100 void load(int index); 0101 void save(int index); 0102 void defaults(int index); 0103 bool isSaveNeeded(int index) const; 0104 bool isDefaults(int index) const; 0105 0106 const QList<FlatpakReference *> &references() const; 0107 0108 Q_SIGNALS: 0109 void needsLoad(); 0110 void settingsChanged(); 0111 0112 private: 0113 QList<FlatpakReference *> m_references; 0114 };