Baloo

kio_search.cpp
1/*
2 SPDX-FileCopyrightText: 2008-2010 Sebastian Trueg <trueg at kde.org>
3 SPDX-FileCopyrightText: 2012-2014 Vishesh Handa <me@vhanda.in>
4 SPDX-FileCopyrightText: 2020 Stefan BrĂ¼ns <bruns@kde.org>
5
6 SPDX-License-Identifier: GPL-2.0-or-later
7*/
8
9#include "kio_search.h"
10#include "../common/udstools.h"
11
12#include "query.h"
13#include "resultiterator.h"
14#include <sys/stat.h>
15
16#include <QUrl>
17#include <QUrlQuery>
18#include <KUser>
19#include <QCoreApplication>
20#include <KLocalizedString>
21
22using namespace Baloo;
23
24// Pseudo plugin class to embed meta data
25class KIOPluginForMetaData : public QObject
26{
28 Q_PLUGIN_METADATA(IID "org.kde.kio.worker.baloosearch" FILE "baloosearch.json")
29};
30
31namespace
32{
33
34KIO::UDSEntry statSearchFolder(const QUrl& url)
35{
36 KIO::UDSEntry uds;
37 uds.reserve(9);
38#ifdef Q_OS_WIN
40#else
41 uds.fastInsert(KIO::UDSEntry::UDS_ACCESS, S_IRUSR | S_IXUSR);
42#endif
43 uds.fastInsert(KIO::UDSEntry::UDS_USER, KUser().loginName());
45 uds.fastInsert(KIO::UDSEntry::UDS_MIME_TYPE, QStringLiteral("inode/directory"));
46 uds.fastInsert(KIO::UDSEntry::UDS_ICON_OVERLAY_NAMES, QStringLiteral("baloo"));
47 uds.fastInsert(KIO::UDSEntry::UDS_DISPLAY_TYPE, i18n("Search Folder"));
49
50 QUrlQuery query(url);
51 QString title = query.queryItemValue(QStringLiteral("title"), QUrl::FullyDecoded);
52 if (!title.isEmpty()) {
55 }
56
57 return uds;
58}
59
60}
61
62SearchProtocol::SearchProtocol(const QByteArray& poolSocket, const QByteArray& appSocket)
63 : KIO::WorkerBase("baloosearch", poolSocket, appSocket)
64{
65}
66
67SearchProtocol::~SearchProtocol()
68{
69}
70
71KIO::WorkerResult SearchProtocol::listDir(const QUrl& url)
72{
73 Query q = Query::fromSearchUrl(url);
74
75 q.setSortingOption(Query::SortNone);
76 ResultIterator it = q.exec();
77
78 UdsFactory udsf;
79
80 while (it.next()) {
81 KIO::UDSEntry uds = udsf.createUdsEntry(it.filePath());
82 if (uds.count()) {
83 listEntry(uds);
84 }
85 }
86
87 KIO::UDSEntry uds;
88 uds.reserve(5);
89 uds.fastInsert(KIO::UDSEntry::UDS_NAME, QStringLiteral("."));
91 uds.fastInsert(KIO::UDSEntry::UDS_MIME_TYPE, QStringLiteral("inode/directory"));
92#ifdef Q_OS_WIN
94#else
95 uds.fastInsert(KIO::UDSEntry::UDS_ACCESS, S_IRUSR | S_IXUSR);
96#endif
97 uds.fastInsert(KIO::UDSEntry::UDS_USER, KUser().loginName());
98 listEntry(uds);
99
101}
102
103KIO::WorkerResult SearchProtocol::mimetype(const QUrl&)
104{
105 mimeType(QStringLiteral("inode/directory"));
107}
108
109KIO::WorkerResult SearchProtocol::stat(const QUrl& url)
110{
111 statEntry(statSearchFolder(url));
113}
114
115extern "C"
116{
117 Q_DECL_EXPORT int kdemain(int argc, char** argv)
118 {
119 QCoreApplication app(argc, argv);
120 app.setApplicationName(QStringLiteral("kio_baloosearch"));
121 Baloo::SearchProtocol worker(argv[2], argv[3]);
122 worker.dispatchLoop();
123 return 0;
124 }
125}
126
127#include "kio_search.moc"
The Query class is the central class to query to search for files from the Index.
Definition query.h:54
@ SortNone
The results are returned in the most efficient order.
Definition query.h:109
void reserve(int size)
void fastInsert(uint field, const QString &value)
int count() const
void statEntry(const UDSEntry &_entry)
void listEntry(const UDSEntry &entry)
void mimeType(const QString &_type)
static WorkerResult pass()
QString i18n(const char *text, const TYPE &arg...)
Implements storage for docIds without any associated data Instantiated for:
Definition coding.cpp:11
KSERVICE_EXPORT KService::List query(FilterFunc filterFunc)
Q_OBJECTQ_OBJECT
bool isEmpty() const const
FullyDecoded
QString url(FormattingOptions options) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 12 2024 12:03:48 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.