Baloo

baloosearchmodule.cpp
1/*
2 This file is part of the KDE Baloo Project
3 SPDX-FileCopyrightText: 2014 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#include "baloosearchmodule.h"
9
10#include <QDBusConnection>
11#include <QUrl>
12#include <QTimer>
13
14#include <kpluginfactory.h>
15
16namespace
17{
18 inline bool isSearchUrl(const QUrl& url)
19 {
20 return url.scheme() == QLatin1String("baloosearch") ||
21 url.scheme() == QLatin1String("timeline") ||
22 url.scheme() == QLatin1String("tags");
23 }
24}
25
26using namespace Baloo;
27
28SearchModule::SearchModule(QObject* parent, const QList<QVariant>&)
29 : KDEDModule(parent)
30 , m_dirNotify(nullptr)
31{
32 QTimer::singleShot(0, this, SLOT(init()));
33}
34
35void SearchModule::init()
36{
37 m_dirNotify = new org::kde::KDirNotify(QString(), QString(),
39 connect(m_dirNotify, &OrgKdeKDirNotifyInterface::enteredDirectory,
40 this, &SearchModule::registerSearchUrl);
41 connect(m_dirNotify, &OrgKdeKDirNotifyInterface::leftDirectory,
42 this, &SearchModule::unregisterSearchUrl);
43
44 // FIXME: Listen to changes from Baloo!!
45 // Listen to dbChanged
47 con.connect(QString(), QStringLiteral("/files"), QStringLiteral("org.kde.baloo"),
48 QStringLiteral("updated"), this, SLOT(slotBalooFileDbChanged()));
49 con.connect(QString(), QStringLiteral("/files"), QStringLiteral("org.kde"),
50 QStringLiteral("changed"), this, SLOT(slotFileMetaDataChanged(QStringList)));
51}
52
53void SearchModule::registerSearchUrl(const QString& urlString)
54{
55 QUrl url(urlString);
56 if (isSearchUrl(url)) {
57 m_searchUrls << url;
58 }
59}
60
61void SearchModule::unregisterSearchUrl(const QString& urlString)
62{
63 QUrl url(urlString);
64 m_searchUrls.removeAll(url);
65}
66
67void SearchModule::slotBalooFileDbChanged()
68{
69 for (const QUrl& dirUrl : std::as_const(m_searchUrls)) {
70 org::kde::KDirNotify::emitFilesAdded(dirUrl);
71 }
72}
73
74void SearchModule::slotFileMetaDataChanged(const QStringList& list)
75{
76 QList<QUrl> localFileUrls;
77 localFileUrls.reserve(list.size());
78 for (const QString& path : list) {
79 localFileUrls << QUrl::fromLocalFile(path);
80 }
81 org::kde::KDirNotify::emitFilesChanged(localFileUrls);
82 slotBalooFileDbChanged();
83}
84
85K_PLUGIN_CLASS_WITH_JSON(SearchModule, "baloosearchmodule.json")
86
87#include "baloosearchmodule.moc"
88#include "moc_baloosearchmodule.cpp"
#define K_PLUGIN_CLASS_WITH_JSON(classname, jsonFile)
Implements storage for docIds without any associated data Instantiated for:
Definition coding.cpp:11
void init(KXmlGuiWindow *window, KGameDifficulty *difficulty=nullptr)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
bool connect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
QDBusConnection sessionBus()
qsizetype removeAll(const AT &t)
void reserve(qsizetype size)
qsizetype size() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QUrl fromLocalFile(const QString &localFile)
QString scheme() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:03:07 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.