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{
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& filePath : std::as_const(m_files)) {
38 Q_ASSERT(!filePath.endsWith(QLatin1Char('/')));
39
41 QFileInfo fileInfo(filePath);
42
43 if (fileInfo.isSymLink()) {
44 continue;
45 }
46
47 if (fileInfo.isDir()) {
48 if (!m_config->shouldFolderBeIndexed(filePath)) {
49 continue;
50 }
51 mimetype = QStringLiteral("inode/directory");
52
53 } else {
54 QString fileName = filePath.mid(filePath.lastIndexOf(QLatin1Char('/')) + 1);
55 if (!m_config->shouldFileBeIndexed(fileName)) {
56 continue;
57 }
58 mimetype = mimeDb.mimeTypeForFile(filePath, QMimeDatabase::MatchExtension).name();
59 }
60
61 BasicIndexingJob job(filePath, mimetype, level);
62 if (!job.index()) {
63 continue;
64 }
65
66 // The same file can be sent twice though it shouldn't be.
67 // Lets just silently ignore it instead of crashing
68 if (tr.hasDocument(job.document().id())) {
69 continue;
70 }
71 tr.addDocument(job.document());
72 }
73
74 tr.commit();
75 Q_EMIT done();
76}
77
78#include "moc_newfileindexer.cpp"
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.