Baloo

xattrindexer.cpp
1/*
2 SPDX-FileCopyrightText: 2015 Vishesh Handa <vhanda@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6
7#include "xattrindexer.h"
8#include "basicindexingjob.h"
9#include "fileindexerconfig.h"
10
11#include "database.h"
12#include "transaction.h"
13
14#include <QMimeDatabase>
15
16using namespace Baloo;
17
18XAttrIndexer::XAttrIndexer(Database* db, const FileIndexerConfig* config, const QStringList& files)
19 : m_db(db)
20 , m_config(config)
21 , m_files(files)
22{
23 Q_ASSERT(m_db);
24 Q_ASSERT(m_config);
25 Q_ASSERT(!m_files.isEmpty());
26}
27
28void XAttrIndexer::run()
29{
31 BasicIndexingJob::IndexingLevel level = m_config->onlyBasicIndexing() ? BasicIndexingJob::NoLevel
32 : BasicIndexingJob::MarkForContentIndexing;
33
34 Transaction tr(m_db, Transaction::ReadWrite);
35
36 for (const QString& filePath : std::as_const(m_files)) {
37 Q_ASSERT(!filePath.endsWith(QLatin1Char('/')));
38
39 QString fileName = filePath.mid(filePath.lastIndexOf(QLatin1Char('/')) + 1);
40 if (!m_config->shouldFileBeIndexed(fileName)) {
41 continue;
42 }
43
44 QString mimetype = mimeDb.mimeTypeForFile(filePath, QMimeDatabase::MatchExtension).name();
45
46 // FIXME: The BasicIndexingJob extracts too much info. We only need the xattr
47 BasicIndexingJob job(filePath, mimetype, BasicIndexingJob::NoLevel);
48 if (!job.index()) {
49 continue;
50 }
51
52 // FIXME: This slightly defeats the point of having separate indexers
53 // But we can get xattr changes of a file, even when it doesn't exist
54 // cause we missed its creation somehow
55 Baloo::Document doc = job.document();
56 if (!tr.hasDocument(doc.id())) {
57 doc.setContentIndexing(level == BasicIndexingJob::MarkForContentIndexing);
58 tr.addDocument(doc);
59 continue;
60 }
61
62 tr.replaceDocument(doc, XAttrTerms | DocumentTime | FileNameTerms | DocumentUrl);
63 }
64
65 tr.commit();
66 Q_EMIT done();
67}
68
69#include "moc_xattrindexer.cpp"
A document represents an indexed file to be stored in the Baloo engine.
Definition document.h:31
void setContentIndexing(bool val)
This flag is used to signify if the file needs its contents to be indexed.
Definition document.cpp:92
Active config class which emits signals if the config was changed, for example if the KCM saved the c...
Implements storage for docIds without any associated data Instantiated for:
Definition coding.cpp:11
KIOCORE_EXPORT MimetypeJob * mimetype(const QUrl &url, JobFlags flags=DefaultFlags)
QStringView level(QStringView ifopt)
Q_EMITQ_EMIT
QString tr(const char *sourceText, const char *disambiguation, int n)
QString mid(qsizetype position, qsizetype n) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.