diff --git a/autotests/extractorcollectiontest.cpp b/autotests/extractorcollectiontest.cpp --- a/autotests/extractorcollectiontest.cpp +++ b/autotests/extractorcollectiontest.cpp @@ -39,6 +39,19 @@ QVERIFY(collection.fetchExtractors("unknown/mimetype").isEmpty()); QVERIFY(!collection.fetchExtractors("text/plain").isEmpty()); } + + void testMultipleExtractorCollections() + { + QCoreApplication::setLibraryPaths({QCoreApplication::applicationDirPath()}); + ExtractorCollection collection; + QVERIFY(collection.fetchExtractors("unknown/mimetype").isEmpty()); + QVERIFY(!collection.fetchExtractors("text/plain").isEmpty()); + ExtractorCollection collection2; + QVERIFY(collection.fetchExtractors("unknown/mimetype").isEmpty()); + QVERIFY(!collection.fetchExtractors("text/plain").isEmpty()); + QVERIFY(collection2.fetchExtractors("unknown/mimetype").isEmpty()); + QVERIFY(!collection2.fetchExtractors("text/plain").isEmpty()); + } }; QTEST_GUILESS_MAIN(ExtractorCollectionTest) diff --git a/src/extractor.h b/src/extractor.h --- a/src/extractor.h +++ b/src/extractor.h @@ -33,6 +33,10 @@ class KFILEMETADATA_EXPORT Extractor { public: + Extractor(Extractor &&other); + + void operator =(Extractor &&other); + virtual ~Extractor(); void extract(ExtractionResult* result); diff --git a/src/extractor.cpp b/src/extractor.cpp --- a/src/extractor.cpp +++ b/src/extractor.cpp @@ -29,9 +29,34 @@ { } +Extractor::Extractor(Extractor &&other) : d(other.d) +{ + other.d = nullptr; +} + +void Extractor::operator =(Extractor &&other) +{ + if (d) { + if (d->m_pluginLoader.isLoaded()) { + d->m_pluginLoader.unload(); + } else { + delete d->m_plugin; + } + } + delete d; + d = other.d; + other.d = nullptr; +} + Extractor::~Extractor() { - delete d->m_plugin; + if (d) { + if (d->m_pluginLoader.isLoaded()) { + d->m_pluginLoader.unload(); + } else { + delete d->m_plugin; + } + } delete d; } diff --git a/src/extractor_p.h b/src/extractor_p.h --- a/src/extractor_p.h +++ b/src/extractor_p.h @@ -21,14 +21,18 @@ #ifndef KFILEMETADATA_EXTRACTOR_P_H #define KFILEMETADATA_EXTRACTOR_P_H +#include + namespace KFileMetaData { class ExtractorPlugin; class ExtractorPrivate { public: ExtractorPlugin *m_plugin; + + QPluginLoader m_pluginLoader; }; } diff --git a/src/extractorcollection.cpp b/src/extractorcollection.cpp --- a/src/extractorcollection.cpp +++ b/src/extractorcollection.cpp @@ -107,19 +107,20 @@ QList extractors; Q_FOREACH (const QString& pluginPath, pluginPaths) { - QPluginLoader loader(pluginPath); + Extractor newExtractor; + newExtractor.d->m_pluginLoader.setFileName(pluginPath); - if (!loader.load()) { + if (!newExtractor.d->m_pluginLoader.load()) { qWarning() << "Could not create Extractor: " << pluginPath; - qWarning() << loader.errorString(); + qWarning() << newExtractor.d->m_pluginLoader.errorString(); continue; } - QObject* obj = loader.instance(); + QObject* obj = newExtractor.d->m_pluginLoader.instance(); if (obj) { ExtractorPlugin* plugin = qobject_cast(obj); if (plugin) { - Extractor* ex= new Extractor; + Extractor* ex= new Extractor(std::move(newExtractor)); ex->d->m_plugin = plugin; extractors << ex;