Akonadi Search

searchstore.cpp
1/*
2 * This file is part of the KDE Akonadi Search Project
3 * SPDX-FileCopyrightText: 2013 Vishesh Handa <me@vhanda.in>
4 *
5 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 *
7 */
8
9#include "searchstore.h"
10#include "akonadi_search_core_debug.h"
11
12#include <QCoreApplication>
13#include <QDir>
14#include <QMutex>
15#include <QPluginLoader>
16#include <QSharedPointer>
17#include <QThreadStorage>
18
19using namespace Akonadi::Search;
20
21SearchStore::SearchStore(QObject *parent)
22 : QObject(parent)
23{
24}
25
26SearchStore::~SearchStore() = default;
27
28QUrl SearchStore::url(int)
29{
30 return {};
31}
32
33QString SearchStore::icon(int)
34{
35 return {};
36}
37
38QString SearchStore::text(int)
39{
40 return {};
41}
42
43QString SearchStore::property(int, const QString &)
44{
45 return {};
46}
47
48Q_GLOBAL_STATIC(SearchStore::List, s_overrideSearchStores)
49
50void SearchStore::overrideSearchStores(const QList<SearchStore *> &overrideSearchStores)
51{
52 List *list = &(*s_overrideSearchStores);
53 list->clear();
54 list->reserve(overrideSearchStores.count());
55
56 for (SearchStore *store : overrideSearchStores) {
58 }
59}
60
61//
62// Search Stores
63//
64// static
66{
67 static QMutex mutex;
68 QMutexLocker lock(&mutex);
69
70 if (s_overrideSearchStores && !s_overrideSearchStores->isEmpty()) {
71 qCDebug(AKONADI_SEARCH_CORE_LOG) << "Overriding search stores.";
72 return *s_overrideSearchStores;
73 }
74
75 // Get all the plugins
76 QStringList plugins;
77 QStringList pluginPaths;
78
80 for (const QString &libraryPath : paths) {
81 const QString path(libraryPath + QStringLiteral("/pim6/akonadi"));
82 QDir dir(path);
83
84 if (!dir.exists()) {
85 continue;
86 }
87
88 const QStringList entryList = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
89 for (const QString &fileName : entryList) {
90 if (plugins.contains(fileName)) {
91 continue;
92 }
93
94 plugins << fileName;
95 pluginPaths << dir.absoluteFilePath(fileName);
96 }
97 }
98 plugins.clear();
99
100 SearchStore::List stores;
101 for (const QString &pluginPath : std::as_const(pluginPaths)) {
102 QPluginLoader loader(pluginPath);
103
104 const QVariantMap metadata = loader.metaData().toVariantMap()[QStringLiteral("MetaData")].toMap();
105 if (metadata[QStringLiteral("X-Akonadi-PluginType")].toString() != QLatin1StringView("SearchStore")) {
106 continue;
107 }
108 if (!loader.load()) {
109 qCWarning(AKONADI_SEARCH_CORE_LOG) << "Could not create Akonadi Search Store: " << pluginPath;
110 qCWarning(AKONADI_SEARCH_CORE_LOG) << loader.errorString();
111 continue;
112 }
113 QObject *obj = loader.instance();
114 if (obj) {
116 if (ex) {
118 qCDebug(AKONADI_SEARCH_CORE_LOG) << " Loaded plugins: " << pluginPath;
119 } else {
120 qCDebug(AKONADI_SEARCH_CORE_LOG) << "Plugin could not be converted to an Akonadi::Search::SearchStore " << pluginPath;
121 }
122 } else {
123 qCDebug(AKONADI_SEARCH_CORE_LOG) << "Plugin could not create instance" << pluginPath;
124 }
125 }
126 return stores;
127}
128
129#include "moc_searchstore.cpp"
static List searchStores()
Gives a list of available search stores.
Akonadi search infrastructure.
Definition core/query.h:21
QStringList libraryPaths()
QVariantMap toVariantMap() const const
void append(QList< T > &&value)
void clear()
void reserve(qsizetype size)
T qobject_cast(QObject *object)
QString errorString() const const
QObject * instance()
QJsonObject metaData() const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:15:27 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.