Debian Codegraph @

src/plugins/PluginFinder.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2021 Damir Porobic <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "PluginFinder.h"
21
22 PluginFinder::PluginFinder(
23 const QSharedPointer<IPluginLoader> &loader,
24 const QSharedPointer<IDirectoryService> &directoryService,
25 const QSharedPointer<IPluginSearchPathProvider> &searchPathProvider) :
26 mLoader(loader),
27 mDirectoryService(directoryService),
28 mSearchPathProvider(searchPathProvider)
29 {
30
31 }
32
33 QList<PluginInfo> PluginFinder::find(const QString &path) const
34 {
35 auto plugins = QList<PluginInfo>();
36
37 auto pluginsInDirectory = findPluginsInDirectory(path);
38 plugins.append(pluginsInDirectory);
39
40 auto childDirectoryInfos = mDirectoryService->childDirectories(path);
41 for (const auto& childDirectoryInfo : childDirectoryInfos) {
42 auto pluginsInChildDirectory = findPluginsInDirectory(childDirectoryInfo.filePath());
43 plugins.append(pluginsInChildDirectory);
44 }
45
46 return plugins;
47 }
48
49 QList<PluginInfo> PluginFinder::find() const
50 {
51 auto plugins = QList<PluginInfo>();
52 for (const auto& path : mSearchPathProvider->searchPaths()) {
53 plugins.append(find(path));
54 }
55 return plugins;
56 }
57
58 QList<PluginInfo> PluginFinder::findPluginsInDirectory(const QString &path) const
59 {
60 auto plugins = QList<PluginInfo>();
61 auto childFileInfos = mDirectoryService->childFiles(path);
62
63 for (const auto& childFileInfo : childFileInfos) {
64 auto plugin = mLoader->load(childFileInfo.filePath());
65
66 if (plugin != nullptr) {
67 auto ocrPlugin = qobject_cast<IPluginOcr*>(plugin);
68
69 if (ocrPlugin != nullptr) {
70 PluginInfo pluginInfo(PluginType::Ocr, ocrPlugin->version(), childFileInfo.filePath());
71 plugins.append(pluginInfo);
72 }
73 }
74 }
75 return plugins;
76 }