File indexing completed on 2024-05-12 04:19:48

0001 // vim: set tabstop=4 shiftwidth=4 expandtab:
0002 /*
0003 Gwenview: an image viewer
0004 Copyright 2008 Aurélien Gâteau <agateau@kde.org>
0005 Copyright 2014 Vishesh Handa <me@vhanda.in>
0006 
0007 This program is free software; you can redistribute it and/or
0008 modify it under the terms of the GNU General Public License
0009 as published by the Free Software Foundation; either version 2
0010 of the License, or (at your option) any later version.
0011 
0012 This program is distributed in the hope that it will be useful,
0013 but WITHOUT ANY WARRANTY; without even the implied warranty of
0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0015 GNU General Public License for more details.
0016 
0017 You should have received a copy of the GNU General Public License
0018 along with this program; if not, write to the Free Software
0019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
0020 
0021 */
0022 // Self
0023 #include "baloosemanticinfobackend.h"
0024 
0025 // Local
0026 #include <lib/gvdebug.h>
0027 
0028 // Qt
0029 #include <QUrl>
0030 
0031 // KF
0032 #include <Baloo/TagListJob>
0033 #include <KFileMetaData/UserMetaData>
0034 
0035 namespace Gwenview
0036 {
0037 struct BalooSemanticInfoBackend::Private {
0038     TagSet mAllTags;
0039 };
0040 
0041 BalooSemanticInfoBackend::BalooSemanticInfoBackend(QObject *parent)
0042     : AbstractSemanticInfoBackEnd(parent)
0043     , d(new BalooSemanticInfoBackend::Private)
0044 {
0045 }
0046 
0047 BalooSemanticInfoBackend::~BalooSemanticInfoBackend()
0048 {
0049     delete d;
0050 }
0051 
0052 TagSet BalooSemanticInfoBackend::allTags() const
0053 {
0054     if (d->mAllTags.isEmpty()) {
0055         const_cast<BalooSemanticInfoBackend *>(this)->refreshAllTags();
0056     }
0057     return d->mAllTags;
0058 }
0059 
0060 void BalooSemanticInfoBackend::refreshAllTags()
0061 {
0062     auto job = new Baloo::TagListJob();
0063     job->exec();
0064 
0065     d->mAllTags.clear();
0066     const QStringList tags = job->tags();
0067     for (const QString &tag : tags) {
0068         d->mAllTags << tag;
0069     }
0070 }
0071 
0072 void BalooSemanticInfoBackend::storeSemanticInfo(const QUrl &url, const SemanticInfo &semanticInfo)
0073 {
0074     KFileMetaData::UserMetaData md(url.toLocalFile());
0075     md.setRating(semanticInfo.mRating);
0076     md.setUserComment(semanticInfo.mDescription);
0077     md.setTags(semanticInfo.mTags.values());
0078 }
0079 
0080 void BalooSemanticInfoBackend::retrieveSemanticInfo(const QUrl &url)
0081 {
0082     KFileMetaData::UserMetaData md(url.toLocalFile());
0083 
0084     SemanticInfo si;
0085     si.mRating = md.rating();
0086     si.mDescription = md.userComment();
0087     si.mTags = TagSet::fromList(md.tags());
0088 
0089     Q_EMIT semanticInfoRetrieved(url, si);
0090 }
0091 
0092 QString BalooSemanticInfoBackend::labelForTag(const SemanticInfoTag &uriString) const
0093 {
0094     return uriString;
0095 }
0096 
0097 SemanticInfoTag BalooSemanticInfoBackend::tagForLabel(const QString &label)
0098 {
0099     return label;
0100 }
0101 
0102 } // namespace
0103 
0104 #include "moc_baloosemanticinfobackend.cpp"