Baloo

newfileindexer.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 "newfileindexer.h"
8#include "basicindexingjob.h"
9#include "fileindexerconfig.h"
10
11#include "database.h"
12#include "transaction.h"
13
14#include <QMimeDatabase>
15#include <QFileInfo>
16
17using namespace Baloo;
18
19NewFileIndexer::NewFileIndexer(Database* db, const FileIndexerConfig* config, const QStringList& newFiles)
20 : m_db(db)
21 , m_config(config)
22 , m_files(newFiles)
23{
24 Q_ASSERT(m_db);
25 Q_ASSERT(m_config);
26 Q_ASSERT(!m_files.isEmpty());
27}
28
29void NewFileIndexer::run()
30{
31 QMimeDatabase mimeDb;
32 BasicIndexingJob::IndexingLevel level = m_config->onlyBasicIndexing() ? BasicIndexingJob::NoLevel
33 : BasicIndexingJob::MarkForContentIndexing;
34
35 Transaction tr(m_db, Transaction::ReadWrite);
36
37 for (const QString &path : m_files) {
38 auto filePath = path;
39 if (filePath.endsWith(QLatin1Char('/'))) {
40 filePath.chop(1);
41 }
42
44 QFileInfo fileInfo(filePath);
45
46 if (fileInfo.isSymLink()) {
47 continue;
48 }
49
50 if (fileInfo.isDir()) {
51 if (!m_config->shouldFolderBeIndexed(filePath)) {
52 continue;
53 }
54 mimetype = QStringLiteral("inode/directory");
55
56 } else {
57 QString fileName = filePath.mid(filePath.lastIndexOf(QLatin1Char('/')) + 1);
58 if (!m_config->shouldFileBeIndexed(fileName)) {
59 continue;
60 }
62 }
63
64 BasicIndexingJob job(filePath, mimetype, level);
65 if (!job.index()) {
66 continue;
67 }
68
69 // The same file can be sent twice though it shouldn't be.
70 // Lets just silently ignore it instead of crashing
71 if (tr.hasDocument(job.document().id())) {
72 continue;
73 }
74 tr.addDocument(job.document());
75 }
76
77 tr.commit();
78 Q_EMIT done();
79}
80
81#include "moc_newfileindexer.cpp"
Active config class which emits signals if the config was changed, for example if the KCM saved the c...
bool shouldFolderBeIndexed(const QString &path) const
Check if the folder at path should be indexed.
bool shouldFileBeIndexed(const QString &fileName) const
Check fileName for all exclude filters.
Implements storage for docIds without any associated data Instantiated for:
Definition coding.cpp:11
KIOCORE_EXPORT MimetypeJob * mimetype(const QUrl &url, JobFlags flags=DefaultFlags)
QString path(const QString &relativePath)
QStringView level(QStringView ifopt)
QMimeType mimeTypeForFile(const QFileInfo &fileInfo, MatchMode mode) const const
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 Mon Nov 18 2024 12:18:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.