Baloo

indexentry.cpp
1/*
2 SPDX-FileCopyrightText: 2012-2015 Vishesh Handa <me@vhanda.in>
3
4 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
5*/
6
7#include <QFile>
8
9#include <KLocalizedString>
10#include <QFileInfo>
11#include <QTextStream>
12
13#include "database.h"
14#include "global.h"
15#include "indexer.h"
16#include "transaction.h"
17
18#include "indexentry.h"
19
20using namespace Baloo;
21
22// IndexEntry Constructors
23// Wraps Transaction, presuming ReadWrite access
24
25IndexEntry::IndexEntry(const Database &db, QTextStream &out)
26 : Transaction(db, TransactionType::ReadWrite)
27 , m_out(out) {};
28
29IndexEntry::IndexEntry(Database *db, QTextStream &out)
30 : IndexEntry(*db, out) {};
31
32// Index the given file.
33// Done in the foreground, the user will have to wait until any content
34// indexing done (which for a big file can take a while)
35
36bool IndexEntry::indexFileNow(const QString &fileName)
37{
38 const QFileInfo fileInfo = QFileInfo(fileName);
39 if (!fileInfo.exists()) {
40 m_out << "Could not stat file: " << fileName << '\n';
41 return false;
42 }
43
44 const QString canonicalPath = fileInfo.canonicalFilePath();
45 quint64 id = filePathToId(QFile::encodeName(canonicalPath));
46 if (id == 0) {
47 m_out << "Skipping: " << canonicalPath << " Reason: Bad Document Id for file\n";
48 return false;
49 }
50
51 if (this->inPhaseOne(id)) {
52 m_out << "Skipping: " << canonicalPath << " Reason: Already scheduled for indexing\n";
53 return false;
54 }
55
56 if (!this->documentData(id).isEmpty()) {
57 m_out << "Skipping: " << canonicalPath << " Reason: Already indexed\n";
58 return false;
59 }
60
61 Indexer indexer(canonicalPath, this);
62 m_out << "Indexing " << canonicalPath << '\n';
63 indexer.index();
64 return true;
65}
Implements storage for docIds without any associated data Instantiated for:
Definition coding.cpp:11
QByteArray encodeName(const QString &fileName)
QString canonicalFilePath() const const
bool exists(const QString &path)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:58 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.