Changeset View
Changeset View
Standalone View
Standalone View
src/extractorcollection.cpp
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 38 | public: | |||
---|---|---|---|---|---|
43 | QList<Extractor*> allExtractors() const; | 43 | QList<Extractor*> allExtractors() const; | ||
44 | }; | 44 | }; | ||
45 | 45 | | |||
46 | ExtractorCollection::ExtractorCollection() | 46 | ExtractorCollection::ExtractorCollection() | ||
47 | : d(new Private) | 47 | : d(new Private) | ||
48 | { | 48 | { | ||
49 | d->m_allExtractors = d->allExtractors(); | 49 | d->m_allExtractors = d->allExtractors(); | ||
50 | 50 | | |||
51 | foreach (Extractor* ex, d->m_allExtractors) { | 51 | for (Extractor* ex : qAsConst(d->m_allExtractors)) { | ||
52 | foreach (const QString& type, ex->mimetypes()) { | 52 | const QStringList lstMimetypes = ex->mimetypes(); | ||
53 | for (const QString& type : lstMimetypes) { | ||||
53 | d->m_extractors.insertMulti(type, ex); | 54 | d->m_extractors.insertMulti(type, ex); | ||
54 | } | 55 | } | ||
55 | } | 56 | } | ||
56 | } | 57 | } | ||
57 | 58 | | |||
58 | ExtractorCollection::~ExtractorCollection() | 59 | ExtractorCollection::~ExtractorCollection() | ||
59 | { | 60 | { | ||
60 | qDeleteAll(d->m_allExtractors.begin(), d->m_allExtractors.end()); | 61 | qDeleteAll(d->m_allExtractors.begin(), d->m_allExtractors.end()); | ||
61 | delete d; | 62 | delete d; | ||
62 | } | 63 | } | ||
63 | 64 | | |||
64 | 65 | | |||
65 | QList<Extractor*> ExtractorCollection::allExtractors() const | 66 | QList<Extractor*> ExtractorCollection::allExtractors() const | ||
66 | { | 67 | { | ||
67 | return d->m_allExtractors; | 68 | return d->m_allExtractors; | ||
68 | } | 69 | } | ||
69 | 70 | | |||
70 | QList<Extractor*> ExtractorCollection::Private::allExtractors() const | 71 | QList<Extractor*> ExtractorCollection::Private::allExtractors() const | ||
71 | { | 72 | { | ||
72 | QStringList plugins; | 73 | QStringList plugins; | ||
73 | QStringList pluginPaths; | 74 | QStringList pluginPaths; | ||
74 | QStringList externalPlugins; | 75 | QStringList externalPlugins; | ||
75 | QStringList externalPluginPaths; | 76 | QStringList externalPluginPaths; | ||
76 | 77 | | |||
77 | QStringList paths = QCoreApplication::libraryPaths(); | 78 | const QStringList paths = QCoreApplication::libraryPaths(); | ||
78 | Q_FOREACH (const QString& libraryPath, paths) { | 79 | for (const QString& libraryPath : paths) { | ||
79 | QString path(libraryPath + QStringLiteral("/kf5/kfilemetadata")); | 80 | QString path(libraryPath + QStringLiteral("/kf5/kfilemetadata")); | ||
80 | QDir dir(path); | 81 | QDir dir(path); | ||
81 | 82 | | |||
82 | if (!dir.exists()) { | 83 | if (!dir.exists()) { | ||
83 | continue; | 84 | continue; | ||
84 | } | 85 | } | ||
85 | 86 | | |||
86 | const QStringList entryList = dir.entryList(QDir::Files | QDir::NoDotAndDotDot); | 87 | const QStringList entryList = dir.entryList(QDir::Files | QDir::NoDotAndDotDot); | ||
Show All 17 Lines | 104 | if (externalPlugins.contains(externalPlugin)) | |||
104 | continue; | 105 | continue; | ||
105 | 106 | | |||
106 | externalPlugins << externalPlugin; | 107 | externalPlugins << externalPlugin; | ||
107 | externalPluginPaths << externalPluginDir.absoluteFilePath(externalPlugin); | 108 | externalPluginPaths << externalPluginDir.absoluteFilePath(externalPlugin); | ||
108 | } | 109 | } | ||
109 | externalPlugins.clear(); | 110 | externalPlugins.clear(); | ||
110 | 111 | | |||
111 | QList<Extractor*> extractors; | 112 | QList<Extractor*> extractors; | ||
112 | Q_FOREACH (const QString& pluginPath, pluginPaths) { | 113 | for (const QString& pluginPath : qAsConst(pluginPaths)) { | ||
113 | QPluginLoader loader(pluginPath); | 114 | QPluginLoader loader(pluginPath); | ||
114 | 115 | | |||
115 | if (!loader.load()) { | 116 | if (!loader.load()) { | ||
116 | qWarning() << "Could not create Extractor: " << pluginPath; | 117 | qWarning() << "Could not create Extractor: " << pluginPath; | ||
117 | qWarning() << loader.errorString(); | 118 | qWarning() << loader.errorString(); | ||
118 | continue; | 119 | continue; | ||
119 | } | 120 | } | ||
120 | 121 | | |||
Show All 16 Lines | 136 | } else { | |||
137 | qCDebug(KFILEMETADATA_LOG) << pluginPath; | 138 | qCDebug(KFILEMETADATA_LOG) << pluginPath; | ||
138 | } | 139 | } | ||
139 | } | 140 | } | ||
140 | else { | 141 | else { | ||
141 | qCDebug(KFILEMETADATA_LOG) << "Plugin could not create instance" << pluginPath; | 142 | qCDebug(KFILEMETADATA_LOG) << "Plugin could not create instance" << pluginPath; | ||
142 | } | 143 | } | ||
143 | } | 144 | } | ||
144 | 145 | | |||
145 | Q_FOREACH (const QString& externalPluginPath, externalPluginPaths) { | 146 | for (const QString& externalPluginPath : qAsConst(externalPluginPaths)) { | ||
146 | ExternalExtractor *plugin = new ExternalExtractor(externalPluginPath); | 147 | ExternalExtractor *plugin = new ExternalExtractor(externalPluginPath); | ||
147 | Extractor* extractor = new Extractor; | 148 | Extractor* extractor = new Extractor; | ||
148 | extractor->setExtractorPlugin(plugin); | 149 | extractor->setExtractorPlugin(plugin); | ||
149 | extractor->setAutoDeletePlugin(Extractor::AutoDeletePlugin); | 150 | extractor->setAutoDeletePlugin(Extractor::AutoDeletePlugin); | ||
150 | 151 | | |||
151 | extractors << extractor; | 152 | extractors << extractor; | ||
152 | } | 153 | } | ||
153 | 154 | | |||
Show All 25 Lines |