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

0001 /* This file is part of the KDE project
0002    SPDX-FileCopyrightText: 1998, 1999 Torben Weis <weis@kde.org>
0003    SPDX-FileCopyrightText: 2007 David Faure <faure@kde.org>
0004 
0005    SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KOJSONTRADER_H
0009 #define KOJSONTRADER_H
0010 
0011 #include <QList>
0012 #include <QString>
0013 #include <QMutex>
0014 #include <QSharedPointer>
0015 #include <kis_pointer_utils.h>
0016 #include "kritaplugin_export.h"
0017 
0018 class QPluginLoader;
0019 
0020 /**
0021  * Support class to fetch a list of relevant plugins
0022  *
0023  * Static singleton
0024  */
0025 class KRITAPLUGIN_EXPORT KoJsonTrader
0026 {
0027 public:
0028 
0029     /**
0030      * Returns the instance of this class.
0031      */
0032     static KoJsonTrader *instance();
0033 
0034     struct KRITAPLUGIN_EXPORT Plugin {
0035         Plugin() = default;
0036         Plugin(QSharedPointer<QPluginLoader> loader, QMutex *mutex);
0037         ~Plugin();
0038 
0039         QObject *instance() const;
0040 
0041         QJsonObject metaData() const;
0042         QString fileName() const;
0043         QString errorString() const;
0044 
0045     private:
0046         QSharedPointer<QPluginLoader> m_loader;
0047         QMutex *m_mutex = 0;
0048     };
0049 
0050     /**
0051      * The main function in the KoJsonTrader class. It tries to automatically
0052      * locate the base path containing Krita plugins. It attempts to do so in
0053      * the current application directory qApp->applicationDirPath().
0054      *
0055      * The environment variable KRITA_PLUGIN_PATH overrides the automatic search
0056      * path when the algorithm is insufficient. Try setting this if the
0057      * "LittleCMS color management plugin is not installed" error appears.
0058      *
0059      * A better algorithm or another solution could be a welcome alternative.
0060      * One thing that might help would be to build all Krita plugins in a single
0061      * `plugins` folder, so that an installation step is unnecessary to put them
0062      * together in a single folder here. Another solution might be to construct
0063      * several QPluginLoaders.
0064      *
0065      * @param servicetype A service type like 'KMyApp/Plugin' or 'KFilePlugin'.
0066      * @param mimetype    A MimeType to constrain the search.
0067      *
0068      * @return A list of QPluginLoader that satisfy the query
0069      */
0070      QList<Plugin> query(const QString &servicetype, const QString &mimetype);
0071 
0072      // Note: this should not be used
0073      KoJsonTrader();
0074      ~KoJsonTrader();
0075 
0076 private:
0077      void initializePluginLoaderCache();
0078 
0079 private:
0080      QString m_pluginPath;
0081      mutable QMutex m_mutex;
0082 
0083      struct PluginCacheEntry;
0084 
0085      QList<PluginCacheEntry> m_pluginLoaderCache;
0086 };
0087 
0088 #endif