File indexing completed on 2024-04-28 08:50:39

0001 /*  This file is part of the KDE project
0002     SPDX-FileCopyrightText: 1999 Simon Hausmann <hausmann@kde.org>
0003     SPDX-FileCopyrightText: 1999 David Faure <faure@kde.org>
0004     SPDX-FileCopyrightText: 1999 Torben Weis <weis@kde.org>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef __konq_factory_h__
0010 #define __konq_factory_h__
0011 
0012 #include "konqprivate_export.h"
0013 #include "pluginmetadatautils.h"
0014 
0015 #include <KService>
0016 #include <KPluginMetaData>
0017 
0018 class KPluginFactory;
0019 namespace KParts
0020 {
0021 class ReadOnlyPart;
0022 }
0023 
0024 class KonqViewFactory // TODO rename to KonqPartLoader?
0025 {
0026 public:
0027     /**
0028      * Create null factory
0029      */
0030     KonqViewFactory() : m_factory(nullptr), m_args() {}
0031 
0032     KonqViewFactory(const KPluginMetaData &data, KPluginFactory *factory);
0033 
0034     // The default copy ctor and operator= can be used, this is a value class.
0035 
0036     void setArgs(const QVariantList &args);
0037 
0038     KParts::ReadOnlyPart *create(QWidget *parentWidget, QObject *parent);
0039 
0040     bool isNull() const
0041     {
0042         return m_factory ? false : true;
0043     }
0044 
0045 private:
0046     KPluginMetaData m_metaData;
0047     KPluginFactory *m_factory;
0048     QVariantList m_args;
0049 };
0050 
0051 /**
0052  * Factory for creating (loading) parts when creating a view.
0053  */
0054 class KONQ_TESTS_EXPORT KonqFactory
0055 {
0056 public:
0057     /**
0058      * Return the factory that can be used to actually create the part inside a view.
0059      *
0060      * The implementation locates the part module (library), using the trader
0061      * and opens it (using klibfactory), which gives us a factory that can be used to
0062      * actually create the part (later on, when the KonqView exists).
0063      *
0064      * Not a static method so that we can define an abstract base class
0065      * with another implementation, for unit tests, if wanted.
0066      */
0067     KonqViewFactory createView(const QString &serviceType,
0068                                const QString &serviceName = QString(),
0069                                KPluginMetaData *serviceImpl = nullptr,
0070                                QVector<KPluginMetaData> *partServiceOffers = nullptr,
0071                                KService::List *appServiceOffers = nullptr,
0072                                bool forceAutoEmbed = false);
0073 
0074     static void getOffers(const QString& serviceType, QVector<KPluginMetaData> *partServiceOffers = nullptr, KService::List* appServiceOffers = nullptr);
0075 };
0076 
0077 #endif