File indexing completed on 2025-01-05 03:58:20

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2014-08-05
0007  * Description : Plasma file indexer interface.
0008  *
0009  * SPDX-FileCopyrightText: 2014 by Veaceslav Munteanu <veaceslav dot munteanu90 at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "baloowrap.h"
0016 
0017 // Qt includes
0018 
0019 #include <QUrl>
0020 
0021 // KDE includes
0022 
0023 #include <klocalizedstring.h>
0024 #include <kfilemetadata/usermetadata.h>
0025 
0026 // Local includes
0027 
0028 #include "digikam_debug.h"
0029 
0030 namespace Digikam
0031 {
0032 
0033 class Q_DECL_HIDDEN BalooWrap::Private
0034 {
0035 public:
0036 
0037     explicit Private()
0038       : syncFromDigikamToBaloo(false),
0039         syncFromBalooToDigikam(false)
0040     {
0041     }
0042 
0043     bool syncFromDigikamToBaloo;
0044     bool syncFromBalooToDigikam;
0045 };
0046 
0047 QPointer<BalooWrap> BalooWrap::internalPtr = QPointer<BalooWrap>();
0048 
0049 BalooWrap::BalooWrap()
0050     : d(new Private)
0051 {
0052 }
0053 
0054 BalooWrap::~BalooWrap()
0055 {
0056     delete d;
0057 }
0058 
0059 bool BalooWrap::isCreated()
0060 {
0061     return (!internalPtr.isNull());
0062 }
0063 
0064 BalooWrap* BalooWrap::instance()
0065 {
0066     if (BalooWrap::internalPtr.isNull())
0067     {
0068         BalooWrap::internalPtr = new BalooWrap();
0069     }
0070 
0071     return BalooWrap::internalPtr;
0072 }
0073 
0074 void BalooWrap::setSemanticInfo(const QUrl& url, const BalooInfo& bInfo)
0075 {
0076     if (!d->syncFromDigikamToBaloo)
0077     {
0078         return;
0079     }
0080 
0081     KFileMetaData::UserMetaData md(url.toLocalFile());
0082 
0083     md.setTags(bInfo.tags);
0084     md.setUserComment(bInfo.comment);
0085 
0086     // digiKam store rating as value form 0 to 5
0087     // while baloo store it as value from 0 to 10
0088 
0089     md.setRating((bInfo.rating == -1) ? 0 : bInfo.rating * 2);
0090 }
0091 
0092 BalooInfo BalooWrap::getSemanticInfo(const QUrl& url) const
0093 {
0094     if (!d->syncFromBalooToDigikam)
0095     {
0096         return BalooInfo();
0097     }
0098 
0099     KFileMetaData::UserMetaData md(url.toLocalFile());
0100 
0101     BalooInfo bInfo;
0102 
0103     // Baloo have rating from 0 to 10, while digiKam have only from 0 to 5
0104 
0105     bInfo.comment = md.userComment();
0106     bInfo.rating  = md.rating() / 2;
0107     bInfo.tags    = md.tags();
0108 
0109     return bInfo;
0110 }
0111 
0112 void BalooWrap::setSyncToBaloo(bool value)
0113 {
0114     d->syncFromDigikamToBaloo = value;
0115 }
0116 
0117 bool BalooWrap::getSyncToBaloo() const
0118 {
0119     return d->syncFromDigikamToBaloo;
0120 }
0121 
0122 bool BalooWrap::getSyncToDigikam() const
0123 {
0124     return d->syncFromBalooToDigikam;
0125 }
0126 
0127 void BalooWrap::setSyncToDigikam(bool value)
0128 {
0129     d->syncFromBalooToDigikam = value;
0130 }
0131 
0132 } // namespace Digikam
0133 
0134 #include "moc_baloowrap.cpp"