File indexing completed on 2024-04-21 14:56:06

0001 /* This file is part of the KDE project
0002    Copyright (C) 1999 Simon Hausmann <hausmann@kde.org>
0003              (C) 1999 David Faure <faure@kde.org>
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 
0010    This library is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this library; see the file COPYING.LIB.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018    Boston, MA 02110-1301, USA.
0019 */
0020 
0021 #include "factory.h"
0022 #include "kparts/part.h"
0023 
0024 #include <QWidget>
0025 
0026 #include <kpluginloader.h>
0027 #include <klocalizedstring.h>
0028 #include <assert.h>
0029 
0030 using namespace KParts;
0031 
0032 Factory::Factory(QObject *parent)
0033 {
0034     setParent(parent);
0035 }
0036 
0037 Factory::~Factory()
0038 {
0039 }
0040 
0041 Part *Factory::createPart(QWidget *parentWidget, QObject *parent, const char *classname, const QStringList &args)
0042 {
0043     Part *part = createPartObject(parentWidget, parent, classname, args);
0044     if (part) {
0045         emit objectCreated(part);
0046     }
0047     return part;
0048 }
0049 
0050 KComponentData Factory::partComponentData()
0051 {
0052     return KComponentData();
0053 }
0054 
0055 KComponentData Factory::partComponentDataFromLibrary(const QString &libraryName)
0056 {
0057     KPluginLoader loader(libraryName);
0058 
0059     KPluginFactory *factory = loader.factory();
0060     if (!factory) {
0061         return KComponentData();
0062     }
0063     KParts::Factory *pfactory = dynamic_cast<KParts::Factory *>(factory);
0064     if (!pfactory) {
0065         return KComponentData();
0066     }
0067     return pfactory->partComponentData();
0068 }
0069 
0070 Part *Factory::createPartObject(QWidget *, QObject *, const char *, const QStringList &)
0071 {
0072     return nullptr;
0073 }
0074 
0075 QObject *Factory::createObject(QObject *parent, const char *classname, const QStringList &args)
0076 {
0077     assert(!parent || parent->isWidgetType());
0078     return createPart(static_cast<QWidget *>(parent), parent, classname, args);
0079 }
0080 
0081 #include "moc_factory.cpp"