Akonadi Search

searchstore.cpp
1 /*
2  * This file is part of the KDE Akonadi Search Project
3  * SPDX-FileCopyrightText: 2013 Vishesh Handa <[email protected]>
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 
19 using namespace Akonadi::Search;
20 
21 SearchStore::SearchStore(QObject *parent)
22  : QObject(parent)
23 {
24 }
25 
26 SearchStore::~SearchStore() = default;
27 
28 QUrl SearchStore::url(int)
29 {
30  return {};
31 }
32 
33 QString SearchStore::icon(int)
34 {
35  return {};
36 }
37 
38 QString SearchStore::text(int)
39 {
40  return {};
41 }
42 
43 QString SearchStore::property(int, const QString &)
44 {
45  return {};
46 }
47 
48 Q_GLOBAL_STATIC(SearchStore::List, s_overrideSearchStores)
49 
50 void 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) {
57  list->append(QSharedPointer<SearchStore>(store));
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;
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() != QLatin1String("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) {
115  SearchStore *ex = qobject_cast<SearchStore *>(obj);
116  if (ex) {
117  stores << QSharedPointer<SearchStore>(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"
void append(const T &value)
QVariantMap toVariantMap() const const
bool contains(const QString &str, Qt::CaseSensitivity cs) const const
QJsonObject metaData() const const
Q_GLOBAL_STATIC(Internal::StaticControl, s_instance) class ControlPrivate
QStringList libraryPaths()
void reserve(int alloc)
Akonadi search infrastructure.
Definition: core/query.h:20
QCA_EXPORT QStringList pluginPaths()
static List searchStores()
Gives a list of available search stores.
Definition: searchstore.cpp:65
void clear()
QObject * instance()
QString errorString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Dec 2 2023 04:09:00 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.