Baloo

clearentry.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 "transaction.h"
16
17#include "clearentry.h"
18
19using namespace Baloo;
20
21// ClearEntry Constructors
22// Wraps Transaction, presuming ReadWrite access
23
24ClearEntry::ClearEntry(const Database &db, QTextStream &out)
25 : Transaction(db, TransactionType::ReadWrite)
26 , m_out(out) {};
27
28ClearEntry::ClearEntry(Database *db, QTextStream &out)
29 : ClearEntry(*db, out) {};
30
31// ClearEntry::clearEntryNow
32// Removes the entry for the file from the index
33// Done in the foreground, the user will have to wait until it's done
34
35bool ClearEntry::clearEntryNow(const QString &fileName)
36{
37 const auto fileInfo = QFileInfo(fileName);
38 const QString canonicalPath = fileInfo.canonicalFilePath();
39 quint64 id = filePathToId(QFile::encodeName(canonicalPath));
40
41 if (id) {
42 m_out << "Clearing " << canonicalPath << '\n';
43 } else {
44 id = this->documentId(QFile::encodeName(fileName));
45 if (id == 0) {
46 m_out << "File not found on filesystem or in DB: " << fileName << '\n';
47 return false;
48 } else {
49 m_out << "File has been deleted, clearing from DB: " << fileName << '\n';
50 }
51 }
52
53 this->removeDocument(id);
54 return true;
55}
Implements storage for docIds without any associated data Instantiated for:
Definition coding.cpp:11
QByteArray encodeName(const QString &fileName)
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.