File indexing completed on 2024-05-12 16:39:56

0001 /* This file is part of the KDE project
0002    Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
0003    Copyright (C) 2007 David Faure <faure@kde.org>
0004    Copyright (C) 2015 Jarosław Staniek <staniek@kde.org>
0005 
0006    This library is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU Library General Public
0008    License as published by the Free Software Foundation; either
0009    version 2 of the License, or (at your option) any later version.
0010 
0011    This library is distributed in the hope that it will be useful,
0012    but WITHOUT ANY WARRANTY; without even the implied warranty of
0013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014    Library General Public License for more details.
0015 
0016    You should have received a copy of the GNU Library General Public License
0017    along with this library; see the file COPYING.LIB.  If not, write to
0018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019  * Boston, MA 02110-1301, USA.
0020 */
0021 
0022 #ifndef KEXI_JSONTRADER_H
0023 #define KEXI_JSONTRADER_H
0024 
0025 #include "kexiutils_export.h"
0026 
0027 #include <QList>
0028 #include <QString>
0029 
0030 class QPluginLoader;
0031 class QJsonObject;
0032 
0033 /**
0034  *  Support class to fetch a list of relevant plugins
0035  */
0036 class KEXIUTILS_EXPORT KexiJsonTrader
0037 {
0038 public:
0039     //! Creates instance of the trader.
0040     //! @a subDir is a name of subdirectory in which plugin files of given type are stored, e.g. "kexi".
0041     explicit KexiJsonTrader(const QString& subDir);
0042 
0043     ~KexiJsonTrader();
0044 
0045     /**
0046      * The main function in the KexiJsonTrader class.
0047      *
0048      * It will return a list of QPluginLoader objects that match your
0049      * specifications.  The only required parameter is the @a servicetypes.
0050      * The @a mimetype parameter is used to limit the possible choices
0051      * returned based on the constraints you give it.
0052      *
0053      * The keys used in the query (Type, ServiceType, Exec) are all
0054      * fields found in the .desktop files.
0055      *
0056      * @param servicetypes A list of service types like 'KMyApp/Plugin' or 'KFilePlugin'.
0057      *                     At least one has to be found in a plugin.
0058      * @param mimetype    A mimetype constraint to limit the choices returned, QString() to
0059      *                    get all services of the given @p servicetypes.
0060      *
0061      * @return A list of QPluginLoader that satisfy the query
0062      * @see https://techbase.kde.org/Development/Tutorials/Services/Traders#The_KTrader_Query_Language
0063      *
0064      * @note Ownership of the QPluginLoader objects is transferred to the caller.
0065      */
0066      QList<QPluginLoader *> query(const QStringList &servicetypes, const QString &mimetype = QString());
0067 
0068      /**
0069       * @overload QList<QPluginLoader *> query(const QStringList &, const QString &);
0070       */
0071      QList<QPluginLoader *> query(const QString &servicetype, const QString &mimetype = QString());
0072 
0073      /**
0074       * @return very top-level metadata JSON object for @a pluginLoader
0075       */
0076      static QJsonObject metaDataObjectForPluginLoader(const QPluginLoader &pluginLoader);
0077 
0078      /**
0079       * @return root JSON object for @a pluginLoader, a "KPlugin" child item of object
0080       * returned by metaDataObjectForPluginLoader()
0081       */
0082      static QJsonObject rootObjectForPluginLoader(const QPluginLoader &pluginLoader);
0083 
0084 private:
0085      Q_DISABLE_COPY(KexiJsonTrader)
0086      class Private;
0087      Private * const d;
0088 };
0089 
0090 #endif