File indexing completed on 2024-04-21 04:51:03

0001 /*
0002     SPDX-FileCopyrightText: 2017 Nicolas Carion
0003     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 */
0005 
0006 #pragma once
0007 
0008 #include "definitions.h"
0009 #include <QSet>
0010 #include <memory>
0011 #include <mlt++/Mlt.h>
0012 #include <mutex>
0013 #include <unordered_map>
0014 
0015 /** @class AbstractAssetsRepository
0016     @brief This class is the base class for assets (transitions or effets) repositories
0017  */
0018 template <typename AssetType> class AbstractAssetsRepository
0019 {
0020 
0021 public:
0022     AbstractAssetsRepository();
0023     virtual ~AbstractAssetsRepository() = default;
0024 
0025     /** @brief Returns true if a given asset exists
0026      */
0027     bool exists(const QString &assetId) const;
0028 
0029     /** @brief Returns a vector of pair (asset id, asset name)
0030      */
0031     QVector<QPair<QString, QString>> getNames() const;
0032 
0033     /** @brief Return type of asset */
0034     AssetType getType(const QString &assetId) const;
0035 
0036     /** @brief Return type of asset */
0037     bool isUnique(const QString &assetId) const;
0038 
0039     /** @brief Return name of asset */
0040     Q_INVOKABLE QString getName(const QString &assetId) const;
0041 
0042     /** @brief Return description of asset */
0043     QString getDescription(const QString &assetId) const;
0044     /** @brief Return version of asset */
0045     int getVersion(const QString &assetId) const;
0046 
0047     /** @brief Returns a DomElement representing the asset's properties */
0048     QDomElement getXml(const QString &assetId) const;
0049 
0050 protected:
0051     struct Info
0052     {
0053         QString id;    // identifier of the asset
0054         QString mltId; //"tag" of the asset, that is the name of the mlt service
0055         QString name, description, author, version_str;
0056         int version{};
0057         QDomElement xml;
0058         AssetType type;
0059     };
0060 
0061     // Reads the asset list from file and populates appropriate structure
0062     void parseAssetList(const QString &filePath, QSet<QString> &destination);
0063 
0064     void init();
0065     virtual Mlt::Properties *retrieveListFromMlt() const = 0;
0066 
0067     /** @brief Parse some info from a mlt structure
0068        @param res Datastructure to fill
0069        @return true on success
0070     */
0071     bool parseInfoFromMlt(const QString &assetId, Info &res);
0072 
0073     /** @brief Returns the metadata associated with the given asset*/
0074     virtual Mlt::Properties *getMetadata(const QString &assetId) const = 0;
0075 
0076     /** @brief Parse one asset from its XML content
0077        @param res data structure to fill
0078        @return true of success
0079      */
0080     bool parseInfoFromXml(const QDomElement &currentAsset, Info &res) const;
0081 
0082     /** @brief Figure what is the type of the asset based on its metadata and store it in res*/
0083     virtual void parseType(Mlt::Properties *metadata, Info &res) = 0;
0084 
0085     /** @brief Retrieves additional info about asset from a custom XML file
0086        The resulting assets are stored in customAssets
0087      */
0088     virtual void parseCustomAssetFile(const QString &file_name, std::unordered_map<QString, Info> &customAssets) const = 0;
0089 
0090     /** @brief Returns the path to custom XML description of the assets*/
0091     virtual QStringList assetDirs() const = 0;
0092 
0093     /** @brief Returns the path to the assets' blacklist*/
0094     virtual QString assetBlackListPath() const = 0;
0095 
0096     /** @brief Returns the path to the assets' preferred list*/
0097     virtual QString assetPreferredListPath() const = 0;
0098 
0099     std::unordered_map<QString, Info> m_assets;
0100 
0101     QSet<QString> m_blacklist;
0102 
0103     QSet<QString> m_preferred_list;
0104 };
0105 
0106 #include "abstractassetsrepository.ipp"