Warning, file /frameworks/baloo/src/lib/taglistjob.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 This file is part of the KDE Baloo Project 0003 SPDX-FileCopyrightText: 2014-2015 Vishesh Handa <vhanda@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.1-or-later 0006 */ 0007 0008 #include "taglistjob.h" 0009 #include "global.h" 0010 #include "database.h" 0011 #include "transaction.h" 0012 0013 #include <QStringList> 0014 0015 using namespace Baloo; 0016 0017 class BALOO_CORE_NO_EXPORT TagListJob::Private { 0018 public: 0019 QStringList tags; 0020 }; 0021 0022 TagListJob::TagListJob(QObject* parent) 0023 : KJob(parent) 0024 , d(new Private) 0025 { 0026 } 0027 0028 TagListJob::~TagListJob() 0029 { 0030 delete d; 0031 } 0032 0033 void TagListJob::start() 0034 { 0035 Database *db = globalDatabaseInstance(); 0036 0037 if (!db->open(Database::ReadOnlyDatabase)) { 0038 // if we have no index, we have no tags 0039 if (!db->isAvailable()) { 0040 emitResult(); 0041 return; 0042 } 0043 0044 setError(UserDefinedError); 0045 setErrorText(QStringLiteral("Failed to open the database")); 0046 emitResult(); 0047 return; 0048 } 0049 0050 QVector<QByteArray> tagList; 0051 { 0052 Transaction tr(db, Transaction::ReadOnly); 0053 tagList = tr.fetchTermsStartingWith("TAG-"); 0054 } 0055 d->tags.reserve(tagList.size()); 0056 for (const QByteArray& ba : std::as_const(tagList)) { 0057 d->tags << QString::fromUtf8(ba.mid(4)); 0058 } 0059 0060 emitResult(); 0061 } 0062 0063 QStringList TagListJob::tags() 0064 { 0065 return d->tags; 0066 } 0067 0068 #include "moc_taglistjob.cpp"