Commit 02d76bf8 authored by Raphael Kubo da Costa (rakuco)'s avatar Raphael Kubo da Costa (rakuco)
Browse files

Move from KLibLoader::self to KPlugFactory.

Kerfuffle::factory has been mostly rewritten and looks cleaner. The
constructor for ReadOnlyArchiveInterface had to be changed because of
K_EXPORT_PLUGIN as well, so all plugins had to change their constructor
signature too.

svn path=/trunk/KDE/kdeutils/ark/; revision=991479
parent db5c0b66
......@@ -25,17 +25,18 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "archive.h"
#include "archivefactory.h"
#include "archivebase.h"
#include "archiveinterface.h"
#include <QByteArray>
#include <QFile>
#include <QFileInfo>
#include <KDebug>
#include <KPluginLoader>
#include <KMimeType>
#include <KMimeTypeTrader>
#include <KServiceTypeTrader>
#include <KLibLoader>
static bool comparePlugins(const KService::Ptr &p1, const KService::Ptr &p2)
{
......@@ -83,33 +84,30 @@ Archive *factory(const QString & filename, const QString & fixedMimeType)
KService::List offers = findPluginOffers(filename, fixedMimeType);
if (!offers.isEmpty()) {
QString libraryName = offers[ 0 ]->library();
KLibrary *lib = KLibLoader::self()->library(QFile::encodeName(libraryName), QLibrary::ExportExternalSymbolsHint);
//TODO: get rid of the deprecated klibloader::self
#if 0
KPluginLoader loader(offers.at(0));
KPluginFactory *factory = loader.factory();
#endif
kDebug() << "Loading library " << libraryName;
if (lib) {
ArchiveFactory *(*pluginFactory)() = (ArchiveFactory * (*)())lib->resolveFunction("pluginFactory");
if (pluginFactory) {
ArchiveFactory *factory = pluginFactory(); // TODO: cache these
Archive *arch = factory->createArchive(QFileInfo(filename).absoluteFilePath(), 0);
delete factory;
return arch;
}
}
if (offers.isEmpty()) {
kDebug() << "Could not find a plugin to handle" << filename;
return NULL;
}
QString pluginName = offers.first()->library();
kDebug() << "Loading plugin" << pluginName;
KPluginFactory *factory = KPluginLoader(pluginName).factory();
if (!factory) {
kDebug() << "Invalid plugin factory for" << pluginName;
return NULL;
}
QVariantList args;
args.append(QVariant(QFileInfo(filename).absoluteFilePath()));
kDebug() << "Couldn't load library " << libraryName ;
ReadOnlyArchiveInterface *iface = factory->create<ReadOnlyArchiveInterface>(0, args);
if (!iface) {
kDebug() << "Could not create plugin instance" << pluginName << "for" << filename;
return NULL;
}
kDebug() << "Couldn't find a library capable of handling " << filename ;
return NULL;
return new ArchiveBase(iface);;
}
QStringList supportedMimeTypes()
......
/*
* ark -- archiver for the KDE project
*
* Copyright (C) 2007 Henrique Pinto <henrique.pinto@kdemail.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef ARCHIVEFACTORY_H
#define ARCHIVEFACTORY_H
#include "kerfuffle_export.h"
#include "archive.h"
#include "archivebase.h"
#include <QString>
#include <QObject>
namespace Kerfuffle
{
class ArchiveFactory
{
public:
ArchiveFactory() {}
virtual ~ArchiveFactory() {}
virtual Kerfuffle::Archive* createArchive(const QString& filename, QObject *parent) = 0;
};
template<class T> class ArchiveInterfaceFactory: public ArchiveFactory
{
public:
Kerfuffle::Archive* createArchive(const QString& filename, QObject *parent = 0) {
return new ArchiveBase(new T(filename, parent));
}
};
} // namespace Kerfuffle
#define KERFUFFLE_PLUGIN_FACTORY( classname ) \
extern "C" { KDE_EXPORT Kerfuffle::ArchiveFactory *pluginFactory() { return new Kerfuffle::ArchiveInterfaceFactory<classname>(); } }
#endif // ARCHIVEFACTORY_H
......@@ -34,9 +34,11 @@
namespace Kerfuffle
{
ReadOnlyArchiveInterface::ReadOnlyArchiveInterface(const QString & filename, QObject *parent)
: QObject(parent), m_filename(filename), m_waitForFinishedSignal(false)
ReadOnlyArchiveInterface::ReadOnlyArchiveInterface(QObject *parent, const QVariantList & args)
: QObject(parent), m_waitForFinishedSignal(false)
{
kDebug();
m_filename = args.first().toString();
}
ReadOnlyArchiveInterface::~ReadOnlyArchiveInterface()
......@@ -145,8 +147,8 @@ void ReadOnlyArchiveInterface::removeObserver(ArchiveObserver *observer)
m_observers.removeAll(observer);
}
ReadWriteArchiveInterface::ReadWriteArchiveInterface(const QString & filename, QObject *parent)
: ReadOnlyArchiveInterface(filename, parent)
ReadWriteArchiveInterface::ReadWriteArchiveInterface(QObject *parent, const QVariantList & args)
: ReadOnlyArchiveInterface(parent, args)
{
}
......
......@@ -30,6 +30,7 @@
#include <QObject>
#include <QStringList>
#include <QString>
#include <QVariantList>
#include "archive.h"
#include "queries.h"
......@@ -47,7 +48,7 @@ class KERFUFFLE_EXPORT ReadOnlyArchiveInterface: public QObject
{
Q_OBJECT
public:
explicit ReadOnlyArchiveInterface(const QString & filename, QObject *parent = 0);
explicit ReadOnlyArchiveInterface(QObject *parent, const QVariantList & args);
virtual ~ReadOnlyArchiveInterface();
/** Return the filename of currently handled archive. */
......@@ -120,8 +121,6 @@ protected:
*/
void setWaitForFinishedSignal(bool value);
private:
QList<ArchiveObserver*> m_observers;
QString m_filename;
......@@ -133,7 +132,7 @@ class KERFUFFLE_EXPORT ReadWriteArchiveInterface: public ReadOnlyArchiveInterfac
{
Q_OBJECT
public:
explicit ReadWriteArchiveInterface(const QString & filename, QObject *parent = 0);
explicit ReadWriteArchiveInterface(QObject *parent, const QVariantList & args);
virtual ~ReadWriteArchiveInterface();
virtual bool isReadOnly() const;
......
......@@ -36,8 +36,8 @@
namespace Kerfuffle
{
CliInterface::CliInterface(const QString& filename, QObject *parent)
: ReadWriteArchiveInterface(filename, parent),
CliInterface::CliInterface(QObject *parent, const QVariantList & args)
: ReadWriteArchiveInterface(parent, args),
m_process(0)
{
//because this interface uses the event loop
......
......@@ -219,7 +219,7 @@ public:
};
OperationMode m_mode;
explicit CliInterface(const QString& filename, QObject *parent = 0);
explicit CliInterface(QObject *parent, const QVariantList & args);
virtual ~CliInterface();
virtual bool list();
......
......@@ -22,6 +22,7 @@
/* needed for KDE_EXPORT and KDE_IMPORT macros */
#include <kdemacros.h>
#include <kpluginfactory.h>
#ifndef KERFUFFLE_EXPORT
# if defined(MAKE_KERFUFFLE_LIB)
......@@ -37,4 +38,8 @@
# define KERFUFFLE_EXPORT_DEPRECATED KDE_DEPRECATED KERFUFFLE_EXPORT
# endif
#define KERFUFFLE_EXPORT_PLUGIN(p) \
K_PLUGIN_FACTORY( ArkPluginFactory, registerPlugin< p >(); ) \
K_EXPORT_PLUGIN( ArkPluginFactory("p") )
#endif
......@@ -20,8 +20,8 @@
*/
#include "cliplugin.h"
#include "kerfuffle/archivefactory.h"
#include "kerfuffle/cliinterface.h"
#include "kerfuffle/kerfuffle_export.h"
#include <QDir>
#include <QLatin1String>
......@@ -31,8 +31,8 @@
using namespace Kerfuffle;
CliPlugin::CliPlugin(const QString & filename, QObject *parent)
: CliInterface(filename, parent)
CliPlugin::CliPlugin(QObject *parent, const QVariantList & args)
: CliInterface(parent, args)
, m_state(0)
{
}
......@@ -143,6 +143,6 @@ bool CliPlugin::readListLine(QString line)
return true;
}
KERFUFFLE_PLUGIN_FACTORY(CliPlugin)
KERFUFFLE_EXPORT_PLUGIN(CliPlugin)
#include "cliplugin.moc"
......@@ -31,7 +31,7 @@ class CliPlugin : public Kerfuffle::CliInterface
Q_OBJECT
public:
explicit CliPlugin(const QString & filename, QObject *parent = 0);
explicit CliPlugin(QObject *parent, const QVariantList & args);
virtual ~CliPlugin();
protected:
......
......@@ -20,8 +20,8 @@
*/
#include "cliplugin.h"
#include "kerfuffle/archivefactory.h"
#include "kerfuffle/cliinterface.h"
#include "kerfuffle/kerfuffle_export.h"
#include <QDateTime>
#include <QDir>
......@@ -32,8 +32,8 @@
using namespace Kerfuffle;
CliPlugin::CliPlugin(const QString & filename, QObject *parent)
: CliInterface(filename, parent)
CliPlugin::CliPlugin(QObject *parent, const QVariantList & args)
: CliInterface(parent, args)
, m_isFirstLine(true)
, m_isInContentListing(false)
{
......@@ -146,6 +146,6 @@ bool CliPlugin::readListLine(QString line)
return true;
}
KERFUFFLE_PLUGIN_FACTORY(CliPlugin)
KERFUFFLE_EXPORT_PLUGIN(CliPlugin)
#include "cliplugin.moc"
......@@ -30,7 +30,7 @@ class CliPlugin : public Kerfuffle::CliInterface
Q_OBJECT
public:
explicit CliPlugin(const QString & filename, QObject *parent = 0);
explicit CliPlugin(QObject *parent, const QVariantList & args);
virtual ~CliPlugin();
......
......@@ -20,7 +20,7 @@
*/
#include "kerfuffle/cliinterface.h"
#include "kerfuffle/archivefactory.h"
#include "kerfuffle/kerfuffle_export.h"
#include <QDir>
#include <QLatin1String>
......@@ -34,8 +34,8 @@ using namespace Kerfuffle;
class CliPlugin: public CliInterface
{
public:
explicit CliPlugin(const QString & filename, QObject *parent = 0)
: CliInterface(filename, parent),
explicit CliPlugin(QObject *parent, const QVariantList & args)
: CliInterface(parent, args),
m_status(Header) {
}
......@@ -117,5 +117,5 @@ public:
}
};
KERFUFFLE_PLUGIN_FACTORY(CliPlugin)
KERFUFFLE_EXPORT_PLUGIN(CliPlugin)
......@@ -25,7 +25,7 @@
*/
#include "libarchivehandler.h"
#include "kerfuffle/archivefactory.h"
#include "kerfuffle/kerfuffle_export.h"
#include "kerfuffle/queries.h"
#include <archive.h>
......@@ -42,8 +42,8 @@
#include <QList>
#include <QStringList>
LibArchiveInterface::LibArchiveInterface(const QString & filename, QObject *parent)
: ReadWriteArchiveInterface(filename, parent),
LibArchiveInterface::LibArchiveInterface(QObject *parent, const QVariantList & args)
: ReadWriteArchiveInterface(parent, args),
m_cachedArchiveEntryCount(0),
m_emitNoEntries(false),
m_extractedFilesSize(0)
......@@ -664,6 +664,6 @@ bool LibArchiveInterface::writeFile(const QString& fileName, struct archive* arc
return true;
}
KERFUFFLE_PLUGIN_FACTORY(LibArchiveInterface)
KERFUFFLE_EXPORT_PLUGIN(LibArchiveInterface)
#include "libarchivehandler.moc"
......@@ -38,7 +38,7 @@ class LibArchiveInterface: public ReadWriteArchiveInterface
Q_OBJECT
public:
explicit LibArchiveInterface(const QString & filename, QObject *parent = 0);
explicit LibArchiveInterface(QObject *parent, const QVariantList & args);
~LibArchiveInterface();
bool list();
......
......@@ -24,12 +24,12 @@
*/
#include "bz2plugin.h"
#include "kerfuffle/archivefactory.h"
#include "kerfuffle/kerfuffle_export.h"
#include <QString>
LibBzip2Interface::LibBzip2Interface(const QString & filename, QObject *parent)
: LibSingleFileInterface(filename, parent)
LibBzip2Interface::LibBzip2Interface(QObject *parent, const QVariantList & args)
: LibSingleFileInterface(parent, args)
{
m_mimeType = "application/x-bzip";
m_possibleExtensions.append(".bz2");
......@@ -39,6 +39,6 @@ LibBzip2Interface::~LibBzip2Interface()
{
}
KERFUFFLE_PLUGIN_FACTORY(LibBzip2Interface)
KERFUFFLE_EXPORT_PLUGIN(LibBzip2Interface)
#include "bz2plugin.moc"
......@@ -33,7 +33,7 @@ class LibBzip2Interface : public LibSingleFileInterface
Q_OBJECT
public:
LibBzip2Interface(const QString & filename, QObject *parent);
LibBzip2Interface(QObject *parent, const QVariantList & args);
virtual ~LibBzip2Interface();
};
......
......@@ -24,12 +24,12 @@
*/
#include "gzplugin.h"
#include "kerfuffle/archivefactory.h"
#include "kerfuffle/kerfuffle_export.h"
#include <QString>
LibGzipInterface::LibGzipInterface(const QString & filename, QObject *parent)
: LibSingleFileInterface(filename, parent)
LibGzipInterface::LibGzipInterface(QObject *parent, const QVariantList & args)
: LibSingleFileInterface(parent, args)
{
m_mimeType = "application/x-gzip";
m_possibleExtensions.append(".gz");
......@@ -39,6 +39,6 @@ LibGzipInterface::~LibGzipInterface()
{
}
KERFUFFLE_PLUGIN_FACTORY(LibGzipInterface)
KERFUFFLE_EXPORT_PLUGIN(LibGzipInterface)
#include "gzplugin.moc"
......@@ -33,7 +33,7 @@ class LibGzipInterface : public LibSingleFileInterface
Q_OBJECT
public:
LibGzipInterface(const QString & filename, QObject *parent);
LibGzipInterface(QObject *parent, const QVariantList & args);
virtual ~LibGzipInterface();
};
......
......@@ -24,7 +24,7 @@
*/
#include "singlefileplugin.h"
#include "kerfuffle/archivefactory.h"
#include "kerfuffle/kerfuffle_export.h"
#include <QByteArray>
#include <QFile>
......@@ -35,15 +35,13 @@
#include <KFilterDev>
#include <KLocale>
LibSingleFileInterface::LibSingleFileInterface(const QString & filename, QObject *parent)
: Kerfuffle::ReadOnlyArchiveInterface(filename, parent)
LibSingleFileInterface::LibSingleFileInterface(QObject *parent, const QVariantList & args)
: Kerfuffle::ReadOnlyArchiveInterface(parent, args)
{
kDebug() << filename;
}
LibSingleFileInterface::~LibSingleFileInterface()
{
kDebug();
}
bool LibSingleFileInterface::copyFiles(const QList<QVariant> & files, const QString & destinationDirectory, Kerfuffle::ExtractionOptions options)
......
......@@ -33,7 +33,7 @@ class LibSingleFileInterface : public Kerfuffle::ReadOnlyArchiveInterface
Q_OBJECT
public:
LibSingleFileInterface(const QString & filename, QObject *parent);
LibSingleFileInterface(QObject *parent, const QVariantList & args);
virtual ~LibSingleFileInterface();
virtual bool list();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment