1 /* 2 SPDX-FileCopyrightText: 2017 Nicolas Carion 3 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 4 */ 5 6 #ifndef ASSETSREPOSITORY_H 7 #define ASSETSREPOSITORY_H 8 9 #include "definitions.h" 10 #include <QSet> 11 #include <memory> 12 #include <mlt++/Mlt.h> 13 #include <mutex> 14 #include <unordered_map> 15 16 /** @class AbstractAssetsRepository 17 @brief This class is the base class for assets (transitions or effets) repositories 18 */ 19 template <typename AssetType> class AbstractAssetsRepository 20 { 21 22 public: 23 AbstractAssetsRepository(); 24 virtual ~AbstractAssetsRepository() = default; 25 26 /** @brief Returns true if a given asset exists 27 */ 28 bool exists(const QString &assetId) const; 29 30 /** @brief Returns a vector of pair (asset id, asset name) 31 */ 32 QVector<QPair<QString, QString>> getNames() const; 33 34 /** @brief Return type of asset */ 35 AssetType getType(const QString &assetId) const; 36 37 /** @brief Return type of asset */ 38 bool isUnique(const QString &assetId) const; 39 40 /** @brief Return name of asset */ 41 Q_INVOKABLE QString getName(const QString &assetId) const; 42 43 /** @brief Return description of asset */ 44 QString getDescription(const QString &assetId) const; 45 46 /** @brief Returns a DomElement representing the asset's properties */ 47 QDomElement getXml(const QString &assetId) const; 48 49 protected: 50 struct Info 51 { 52 QString id; // identifier of the asset 53 QString mltId; //"tag" of the asset, that is the name of the mlt service 54 QString name, description, author, version_str; 55 int version{}; 56 QDomElement xml; 57 AssetType type; 58 }; 59 60 // Reads the asset list from file and populates appropriate structure 61 void parseAssetList(const QString &filePath, QSet<QString> &destination); 62 63 void init(); 64 virtual Mlt::Properties *retrieveListFromMlt() const = 0; 65 66 /** @brief Parse some info from a mlt structure 67 @param res Datastructure to fill 68 @return true on success 69 */ 70 bool parseInfoFromMlt(const QString &assetId, Info &res); 71 72 /** @brief Returns the metadata associated with the given asset*/ 73 virtual Mlt::Properties *getMetadata(const QString &assetId) const = 0; 74 75 /** @brief Parse one asset from its XML content 76 @param res data structure to fill 77 @return true of success 78 */ 79 bool parseInfoFromXml(const QDomElement ¤tAsset, Info &res) const; 80 81 /** @brief Figure what is the type of the asset based on its metadata and store it in res*/ 82 virtual void parseType(QScopedPointer<Mlt::Properties> &metadata, Info &res) = 0; 83 84 /** @brief Retrieves additional info about asset from a custom XML file 85 The resulting assets are stored in customAssets 86 */ 87 virtual void parseCustomAssetFile(const QString &file_name, std::unordered_map<QString, Info> &customAssets) const = 0; 88 89 /** @brief Returns the path to custom XML description of the assets*/ 90 virtual QStringList assetDirs() const = 0; 91 92 /** @brief Returns the path to the assets' blacklist*/ 93 virtual QString assetBlackListPath() const = 0; 94 95 /** @brief Returns the path to the assets' preferred list*/ 96 virtual QString assetPreferredListPath() const = 0; 97 98 std::unordered_map<QString, Info> m_assets; 99 100 QSet<QString> m_blacklist; 101 102 QSet<QString> m_preferred_list; 103 }; 104 105 #include "abstractassetsrepository.ipp" 106 107 #endif 108