Loading...
Searching...
No Matches
PluginItemModel.hpp
1#pragma once
2#include <score/plugins/Addon.hpp>
3
4#include <ossia/detail/algorithms.hpp>
5#include <ossia/detail/flat_map.hpp>
6#include <ossia/detail/optional.hpp>
7
8#include <boost/iterator/filter_iterator.hpp>
9
10#include <QAbstractItemModel>
11#include <QFileSystemWatcher>
12#include <QImage>
13#include <QUrl>
14#include <QUuid>
15
16#include <verdigris>
17
18namespace score
19{
20struct ApplicationContext;
21}
22namespace PM
23{
24struct Package
25{
26 static std::optional<Package> fromJson(const QJsonObject& obj) noexcept;
27
28 UuidKey<score::Addon> key; // Can be the same as plug-in's
30 QUuid uuid() const noexcept
31 {
32 return QUuid::fromString(QLatin1String{score::uuids::toByteArray(key.impl())});
33 }
34
35 QString raw_name;
36 QString name;
37 int version{}; // version of the add-on
38 QString target; // version of score targeted by this version of the add-on
39 QString
40 kind; // what kind of package it is (for now: "addon", "sdk", "library", "media", "presets")
41 std::vector<QUrl> files; // URL to a file containing the current version.
42 QMap<QString, std::vector<QUrl>> arch_files; // if there are per-architecture files
43 QString url; // Link to the homepage of the package if any
44
45 QString shortDescription;
46 QString longDescription;
47 QString smallImagePath;
48 QString largeImagePath;
49 QImage smallImage;
50 QImage largeImage;
51 QString size;
52 bool enabled = true;
53 bool corePlugin = false; // For plug-ins shipped with score
54};
55
56class PackagesModel : public QAbstractItemModel
57{
58public:
59 std::vector<Package> m_vec;
60
61 void addAddon(Package e);
62 void removeAddon(Package e);
63
64 auto& addons() { return m_vec; }
65 auto& addons() const { return m_vec; }
66
67 void clear();
68
69private:
70 enum class Column
71 {
72 Name,
73 Version,
74 Size,
75 Kind,
76 ShortDesc
77 };
78 static constexpr const int ColumnCount = 5;
79
80 QModelIndex index(int row, int column, const QModelIndex& parent) const override;
81 QModelIndex parent(const QModelIndex& child) const override;
82 int rowCount(const QModelIndex& parent) const override;
83 int columnCount(const QModelIndex& parent) const override;
84 QVariant data(const QModelIndex& index, int role) const override;
85 Qt::ItemFlags flags(const QModelIndex& index) const override;
86
87 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
88};
89
91{
93 void registerAddon(const QString& p);
94 QFileSystemWatcher m_addonsWatch;
95};
96
98{
99public:
100 template <typename Fun>
101 void updateAddon(UuidKey<score::Addon> k, Fun f)
102 {
103 if(auto add = addon(k))
104 {
105 beginResetModel();
106 f(*add);
107 endResetModel();
108 }
109 }
110
111private:
113 {
114 auto it = ossia::find_if(m_vec, [&](auto& add) { return add.key == k; });
115
116 if(it != m_vec.end())
117 return &*it;
118
119 return nullptr;
120 }
121};
122}
123
124Q_DECLARE_METATYPE(PM::Package)
125W_REGISTER_ARGTYPE(PM::Package)
Definition PluginItemModel.hpp:57
Definition PluginItemModel.hpp:98
Definition ClipMode.hpp:10
Definition UuidKey.hpp:345
Base toolkit upon which the software is built.
Definition Application.cpp:83
Definition PluginItemModel.hpp:91
Definition PluginItemModel.hpp:25
QUuid uuid() const noexcept
The key as package.json files and the library store it.
Definition PluginItemModel.hpp:30
Used to access all the application-wide state and structures.
Definition ApplicationContext.hpp:25