File indexing completed on 2024-05-12 15:59:50

0001 /*
0002  * SPDX-FileCopyrightText: 2018 Boudewijn Rempt <boud@valdyas.org>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #ifndef KISRESOURCELOADERREGISTRY_H
0008 #define KISRESOURCELOADERREGISTRY_H
0009 
0010 #include <QObject>
0011 #include <QSet>
0012 #include <QStringList>
0013 
0014 #include <KoGenericRegistry.h>
0015 #include "KisResourceLoader.h"
0016 
0017 #include <kritaresources_export.h>
0018 
0019 /**
0020  * @brief The KisResourceLoaderRegistry class manages the loader plugins for resources. Every resource can be loaded
0021  * by a KisResourceLoader instance. A loader corresponds to a particular file type. Resources are organized in
0022  * folders that represent the main type of a certain resource (brushes) and subtypes, that identify a particular
0023  * resource format (gbr, gih, png, svg).
0024  * 
0025  * KisResourceLoaderRegistry has full knowledge of all resource types that are defined for Krita.
0026  */
0027 class KRITARESOURCES_EXPORT KisResourceLoaderRegistry : public QObject, public KoGenericRegistry<KisResourceLoaderBase*>
0028 {
0029     Q_OBJECT
0030 public:
0031     ~KisResourceLoaderRegistry() override;
0032 
0033     static KisResourceLoaderRegistry *instance();
0034 
0035     /**
0036      * Adds the given loader and registers its type in the database, if it hasn't been registered yet.
0037      */
0038     void registerLoader(KisResourceLoaderBase* loader);
0039 
0040     /// @return the first loader for the given resource type and mimetype
0041     KisResourceLoaderBase *loader(const QString &resourceType, const QString &mimetype) const;
0042 
0043     /**
0044      * @return a list of filename extensions that can be present for the given resource type
0045      */
0046     QStringList filters(const QString &resourceType) const;
0047 
0048     /**
0049      * @return a list of mimetypes that can be loaded for the given resourde type
0050      */
0051     QStringList mimeTypes(const QString &resourceType) const;
0052 
0053     /**
0054      * @return the list of folders for which resource loaders have been registered
0055      */
0056     QStringList resourceTypes() const;
0057 
0058     /**
0059      * @return a list of loader plugins that can handle the resources stored in the folder. A folder can contain multiple subtypes.
0060      */
0061     QVector<KisResourceLoaderBase*> resourceTypeLoaders(const QString &resourceType) const;
0062 
0063     /**
0064      * Sometimes the database needs updates without changing
0065      * the schema of the database. E.g. when we need to update
0066      * the resources' metadata. In such cacse, fix up should
0067      * be created.
0068      */
0069     struct ResourceCacheFixup {
0070         virtual ~ResourceCacheFixup() {};
0071         virtual QStringList executeFix() = 0;
0072     };
0073 
0074     void registerFixup(int priority, ResourceCacheFixup *fixup);
0075     QStringList executeAllFixups();
0076 
0077 private:
0078 
0079     KisResourceLoaderRegistry(QObject *parent);
0080     KisResourceLoaderRegistry(const KisResourceLoaderRegistry&);
0081     KisResourceLoaderRegistry operator=(const KisResourceLoaderRegistry&);
0082 private:
0083 
0084     struct Private;
0085     QScopedPointer<Private> m_d;
0086 };
0087 
0088 #endif // KISRESOURCELOADERREGISTRY_H