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