File indexing completed on 2024-04-14 04:46:50

0001 /*
0002     SPDX-FileCopyrightText: 2021 Julius Künzel <jk.kdedev@smartlab.uber.space>
0003     SPDX-FileCopyrightText: 2011 Jean-Baptiste Mardelle <jb@kdenlive.org>
0004     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #pragma once
0008 
0009 #include "definitions.h"
0010 #include "providermodel.hpp"
0011 #include <QReadWriteLock>
0012 #include <mutex>
0013 #include <unordered_map>
0014 
0015 /** @class ProvidersRepository
0016     @brief This class is used to read all the provider configs available.
0017     You can then query providers based on their paths
0018     Note that this class is a Singleton, with Mutex protections to allow concurrent access.
0019  */
0020 class ProvidersRepository
0021 {
0022 public:
0023     // Returns the instance of the Singleton
0024     static std::unique_ptr<ProvidersRepository> &get();
0025 
0026     /** @brief Reloads all the providers from the disk */
0027     void refresh(bool fullRefresh = true); // TODO: change to false
0028 
0029     QVector<QPair<QString, QString>> getAllProviers() const;
0030     std::unique_ptr<ProviderModel> &getProvider(const QString &path);
0031 
0032 protected:
0033     ProvidersRepository();
0034 
0035     static std::unique_ptr<ProvidersRepository> instance;
0036     /** @brief flag to create the repository only once */
0037     static std::once_flag m_onceFlag;
0038 
0039     mutable QReadWriteLock m_mutex;
0040 
0041     std::unordered_map<QString, std::unique_ptr<ProviderModel>> m_providers;
0042 };