Baloo

taglistjob.cpp
1 /*
2  This file is part of the KDE Baloo Project
3  SPDX-FileCopyrightText: 2014-2015 Vishesh Handa <[email protected]>
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 
15 using namespace Baloo;
16 
17 class BALOO_CORE_NO_EXPORT TagListJob::Private {
18 public:
19  QStringList tags;
20 };
21 
22 TagListJob::TagListJob(QObject* parent)
23  : KJob(parent)
24  , d(new Private)
25 {
26 }
27 
28 TagListJob::~TagListJob()
29 {
30  delete d;
31 }
32 
33 void TagListJob::start()
34 {
35  Database *db = globalDatabaseInstance();
36 
37  if (!db->open(Database::ReadOnlyDatabase)) {
38  // if we have no index, we have no tags
39  if (!db->isAvailable()) {
40  emitResult();
41  return;
42  }
43 
44  setError(UserDefinedError);
45  setErrorText(QStringLiteral("Failed to open the database"));
46  emitResult();
47  return;
48  }
49 
50  QVector<QByteArray> tagList;
51  {
52  Transaction tr(db, Transaction::ReadOnly);
53  tagList = tr.fetchTermsStartingWith("TAG-");
54  }
55  d->tags.reserve(tagList.size());
56  for (const QByteArray& ba : std::as_const(tagList)) {
57  d->tags << QString::fromUtf8(ba.mid(4));
58  }
59 
60  emitResult();
61 }
62 
63 QStringList TagListJob::tags()
64 {
65  return d->tags;
66 }
67 
68 #include "moc_taglistjob.cpp"
QString fromUtf8(const char *str, int size)
Q_SCRIPTABLE Q_NOREPLY void start()
Implements storage for docIds without any associated data Instantiated for:
Definition: coding.cpp:11
void reserve(int size)
int size() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Nov 29 2023 03:56:26 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.