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(mode: 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(term: "TAG-");
51 }
52 d->tags.reserve(asize: tagList.size());
53 for (const QByteArray& ba : std::as_const(t&: tagList)) {
54 d->tags << QString::fromUtf8(ba: ba.mid(index: 4));
55 }
56
57 emitResult();
58}
59
60QStringList TagListJob::tags()
61{
62 return d->tags;
63}
64
65#include "moc_taglistjob.cpp"
66

source code of baloo/src/lib/taglistjob.cpp