File indexing completed on 2024-04-28 08:44:16
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" //for QString hash function 0009 #include "profileinfo.hpp" 0010 #include <QReadWriteLock> 0011 #include <QString> 0012 #include <memory> 0013 #include <mutex> 0014 #include <unordered_map> 0015 0016 class ProfileModel; 0017 0018 /** @class ProfileRepository 0019 @brief This class is used to read all the profiles available to the user (MLT defaults one and Custom ones). 0020 You can then query profiles based on their paths 0021 Note that this class is a Singleton, with Mutex protections to allow concurrent access. 0022 */ 0023 class ProfileRepository 0024 { 0025 0026 public: 0027 // Returns the instance of the Singleton 0028 static std::unique_ptr<ProfileRepository> &get(); 0029 0030 /** @brief Reloads all the profiles from the disk */ 0031 void refresh(); 0032 0033 /** @brief Returns a list of all the pairs (description, path) of all the profiles loaded */ 0034 QVector<QPair<QString, QString>> getAllProfiles() const; 0035 0036 /** @brief Returns a profile model given the profile's @param path 0037 */ 0038 std::unique_ptr<ProfileModel> &getProfile(const QString &path); 0039 0040 /** @brief Returns true if the given profile exists in repository 0041 */ 0042 bool profileExists(const QString &path) const; 0043 0044 /** @brief Find a profile that match the parameters of the given one and return its path. If not found, returns empty string */ 0045 QString findMatchingProfile(ProfileInfo *profile) const; 0046 0047 /** @brief Get the descriptive text for given colorspace code (defined by MLT) 0048 * @param colorspace An int as defined in mlt_profile.h 0049 * @return The string description */ 0050 static QString getColorspaceDescription(int colorspace); 0051 /** @brief This is the opposite function */ 0052 static int getColorspaceFromDescription(const QString &description); 0053 0054 /** @brief Returns all the possible fps of the profiles in the repository*/ 0055 QVector<double> getAllFps() const; 0056 0057 /** @brief Saves given profile as custom one. If the path is left empty, it will be set to the standard custom_profile directory 0058 * @returns The path of the saved folder 0059 */ 0060 const QString saveProfile(ProfileInfo *profile, QString profilePath = QString()); 0061 0062 /** @brief Delete a (custom) profile*/ 0063 bool deleteProfile(const QString &path); 0064 0065 protected: 0066 // Constructor is protected because class is a Singleton 0067 ProfileRepository(); 0068 0069 static std::unique_ptr<ProfileRepository> instance; 0070 static std::once_flag m_onceFlag; // flag to create the repository only once; 0071 0072 static std::vector<std::pair<int, QString>> colorProfiles; 0073 0074 mutable QReadWriteLock m_mutex; 0075 0076 /** @brief map from the profile path to the instance of the profile. 0077 * @details We use unordered_map because QMap and QHash currently don't support 0078 * move insertion, hence inserting unique_ptr is impossible. 0079 */ 0080 std::unordered_map<QString, std::unique_ptr<ProfileModel>> m_profiles; 0081 };