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 @@ -28,10 +28,17 @@ class ExtractionResult; class ExtractorCollection; -class ExtractorPrivate; +class ExtractorPlugin; class KFILEMETADATA_EXPORT Extractor { + class ExtractorPrivate; + + enum ExtractorPluginOwnership { + PluginOwner, + SharedPlugin, + }; + public: virtual ~Extractor(); @@ -44,6 +51,8 @@ void operator =(const Extractor&); + void setExtractorPlugin(ExtractorPlugin *extractorPlugin, ExtractorPluginOwnership ownership); + ExtractorPrivate *d; friend class ExtractorCollection; }; diff --git a/src/extractor.cpp b/src/extractor.cpp --- a/src/extractor.cpp +++ b/src/extractor.cpp @@ -31,7 +31,10 @@ Extractor::~Extractor() { - delete d->m_plugin; + if (d->m_pluginOwnership == PluginOwner) { + delete d->m_plugin; + } + delete d; } @@ -44,3 +47,9 @@ { return d->m_plugin->mimetypes(); } + +void Extractor::setExtractorPlugin(ExtractorPlugin *extractorPlugin, Extractor::ExtractorPluginOwnership ownership) +{ + d->m_plugin = extractorPlugin; + d->m_pluginOwnership = ownership; +} diff --git a/src/extractor_p.h b/src/extractor_p.h --- a/src/extractor_p.h +++ b/src/extractor_p.h @@ -25,10 +25,12 @@ class ExtractorPlugin; -class ExtractorPrivate +class Extractor::ExtractorPrivate { public: ExtractorPlugin *m_plugin; + + ExtractorPluginOwnership m_pluginOwnership; }; } diff --git a/src/extractorcollection.cpp b/src/extractorcollection.cpp --- a/src/extractorcollection.cpp +++ b/src/extractorcollection.cpp @@ -22,7 +22,6 @@ #include "extractor.h" #include "extractorplugin.h" #include "extractorcollection.h" -#include "extractor_p.h" #include "externalextractor.h" #include @@ -120,7 +119,7 @@ ExtractorPlugin* plugin = qobject_cast(obj); if (plugin) { Extractor* ex= new Extractor; - ex->d->m_plugin = plugin; + ex->setExtractorPlugin(plugin, Extractor::SharedPlugin); extractors << ex; } else { @@ -136,7 +135,7 @@ Q_FOREACH (const QString& externalPluginPath, externalPluginPaths) { ExternalExtractor *plugin = new ExternalExtractor(externalPluginPath); Extractor* extractor = new Extractor; - extractor->d->m_plugin = plugin; + extractor->setExtractorPlugin(plugin, Extractor::PluginOwner); extractors << extractor; }