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 Kind,
70 ShortDesc
71 };
72 static constexpr const int ColumnCount = 5;
73
74 QModelIndex index(int row, int column, const QModelIndex& parent) const override;
75 QModelIndex parent(const QModelIndex& child) const override;
76 int rowCount(const QModelIndex& parent) const override;
77 int columnCount(const QModelIndex& parent) const override;
78 QVariant data(const QModelIndex& index, int role) const override;
79 Qt::ItemFlags flags(const QModelIndex& index) const override;
80
81 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
82};
83
85{
87 void registerAddon(const QString& p);
88 QFileSystemWatcher m_addonsWatch;
89};
90
92{
93public:
94 template <typename Fun>
95 void updateAddon(UuidKey<score::Addon> k, Fun f)
96 {
97 if(auto add = addon(k))
98 {
99 beginResetModel();
100 f(*add);
101 endResetModel();
102 }
103 }
104
105private:
107 {
108 auto it = ossia::find_if(m_vec, [&](auto& add) { return add.key == k; });
109
110 if(it != m_vec.end())
111 return &*it;
112
113 return nullptr;
114 }
115};
116}
117
118Q_DECLARE_METATYPE(PM::Package)
119W_REGISTER_ARGTYPE(PM::Package)
Definition PluginItemModel.hpp:51
Definition PluginItemModel.hpp:92
Definition ClipMode.hpp:10
Definition UuidKey.hpp:345
Base toolkit upon which the software is built.
Definition Application.cpp:117
Definition PluginItemModel.hpp:85
Definition PluginItemModel.hpp:24
Used to access all the application-wide state and structures.
Definition ApplicationContext.hpp:25