Baloo

taglistjob.cpp
1/*
2 This file is part of the KDE Baloo Project
3 SPDX-FileCopyrightText: 2014-2015 Vishesh Handa <vhanda@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.1-or-later
6*/
7
8#include "taglistjob.h"
9#include "global.h"
10#include "database.h"
11#include "transaction.h"
12
13#include <QStringList>
14
15using namespace Baloo;
16
17class BALOO_CORE_NO_EXPORT TagListJob::Private {
18public:
19 QStringList tags;
20};
21
22TagListJob::TagListJob(QObject* parent)
23 : KJob(parent)
24 , d(new Private)
25{
26}
27
28TagListJob::~TagListJob() = default;
29
30void TagListJob::start()
31{
32 Database *db = globalDatabaseInstance();
33
34 if (!db->open(Database::ReadOnlyDatabase)) {
35 // if we have no index, we have no tags
36 if (!db->isAvailable()) {
37 emitResult();
38 return;
39 }
40
41 setError(UserDefinedError);
42 setErrorText(QStringLiteral("Failed to open the database"));
43 emitResult();
44 return;
45 }
46
47 QVector<QByteArray> tagList;
48 {
49 Transaction tr(db, Transaction::ReadOnly);
50 tagList = tr.fetchTermsStartingWith("TAG-");
51 }
52 d->tags.reserve(tagList.size());
53 for (const QByteArray& ba : std::as_const(tagList)) {
54 d->tags << QString::fromUtf8(ba.mid(4));
55 }
56
57 emitResult();
58}
59
60QStringList TagListJob::tags()
61{
62 return d->tags;
63}
64
65#include "moc_taglistjob.cpp"
void setErrorText(const QString &errorText)
void emitResult()
void setError(int errorCode)
Implements storage for docIds without any associated data Instantiated for:
Definition coding.cpp:11
qsizetype size() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
QString fromUtf8(QByteArrayView str)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Aug 30 2024 11:48:47 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.