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"
10using namespace Qt::Literals::StringLiterals;
11
12#include "akonadi_search_core_debug.h"
13
14#include <QCoreApplication>
15#include <QDir>
16#include <QMutex>
17#include <QPluginLoader>
18#include <QSharedPointer>
19#include <QThreadStorage>
20
21using namespace Akonadi::Search;
22
23SearchStore::SearchStore(QObject *parent)
24 : QObject(parent)
25{
26}
27
28SearchStore::~SearchStore() = default;
29
30QUrl SearchStore::url(int)
31{
32 return {};
33}
34
35QString SearchStore::icon(int)
36{
37 return {};
38}
39
40QString SearchStore::text(int)
41{
42 return {};
43}
44
45QString SearchStore::property(int, const QString &)
46{
47 return {};
48}
49
50Q_GLOBAL_STATIC(SearchStore::List, s_overrideSearchStores)
51
52void SearchStore::overrideSearchStores(const QList<SearchStore *> &overrideSearchStores)
53{
54 List *list = &(*s_overrideSearchStores);
55 list->clear();
56 list->reserve(overrideSearchStores.count());
57
58 for (SearchStore *store : overrideSearchStores) {
60 }
61}
62
63//
64// Search Stores
65//
66// static
68{
69 static QMutex mutex;
70 QMutexLocker lock(&mutex);
71
72 if (s_overrideSearchStores && !s_overrideSearchStores->isEmpty()) {
73 qCDebug(AKONADI_SEARCH_CORE_LOG) << "Overriding search stores.";
74 return *s_overrideSearchStores;
75 }
76
77 // Get all the plugins
78 QStringList plugins;
79 QStringList pluginPaths;
80
82 for (const QString &libraryPath : paths) {
83 const QString path(libraryPath + QStringLiteral("/pim6/akonadi"));
84 QDir dir(path);
85
86 if (!dir.exists()) {
87 continue;
88 }
89
90 const QStringList entryList = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
91 for (const QString &fileName : entryList) {
92 if (plugins.contains(fileName)) {
93 continue;
94 }
95
96 plugins << fileName;
97 pluginPaths << dir.absoluteFilePath(fileName);
98 }
99 }
100 plugins.clear();
101
102 SearchStore::List stores;
103 for (const QString &pluginPath : std::as_const(pluginPaths)) {
104 QPluginLoader loader(pluginPath);
105
106 const QVariantMap metadata = loader.metaData().toVariantMap()[QStringLiteral("MetaData")].toMap();
107 if (metadata[QStringLiteral("X-Akonadi-PluginType")].toString() != "SearchStore"_L1) {
108 continue;
109 }
110 if (!loader.load()) {
111 qCWarning(AKONADI_SEARCH_CORE_LOG) << "Could not create Akonadi Search Store: " << pluginPath;
112 qCWarning(AKONADI_SEARCH_CORE_LOG) << loader.errorString();
113 continue;
114 }
115 QObject *obj = loader.instance();
116 if (obj) {
118 if (ex) {
119 stores << QSharedPointer<SearchStore>(ex);
120 qCDebug(AKONADI_SEARCH_CORE_LOG) << " Loaded plugins: " << pluginPath;
121 } else {
122 qCDebug(AKONADI_SEARCH_CORE_LOG) << "Plugin could not be converted to an Akonadi::Search::SearchStore " << pluginPath;
123 }
124 } else {
125 qCDebug(AKONADI_SEARCH_CORE_LOG) << "Plugin could not create instance" << pluginPath;
126 }
127 }
128 return stores;
129}
130
131#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 Mon Nov 18 2024 12:10:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.