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 
0006 This program is free software; you can redistribute it and/or
0007 modify it under the terms of the GNU General Public License
0008 as published by the Free Software Foundation; either version 2
0009 of the License, or (at your option) any later version.
0010 
0011 This program is distributed in the hope that it will be useful,
0012 but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014 GNU General Public License for more details.
0015 
0016 You should have received a copy of the GNU General Public License
0017 along with this program; if not, write to the Free Software
0018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
0019 
0020 */
0021 #ifndef ABSTRACTSEMANTICINFOBACKEND_H
0022 #define ABSTRACTSEMANTICINFOBACKEND_H
0023 
0024 #include <lib/gwenviewlib_export.h>
0025 
0026 // Qt
0027 #include <QObject>
0028 #include <QSet>
0029 
0030 // KF
0031 
0032 // Local
0033 
0034 class QUrl;
0035 
0036 namespace Gwenview
0037 {
0038 using SemanticInfoTag = QString;
0039 
0040 /**
0041  * This class represents the set of tags associated to an url.
0042  *
0043  * It provides convenience methods to convert to and from QVariant, which are
0044  * useful to communicate with SemanticInfoDirModel.
0045  */
0046 class GWENVIEWLIB_EXPORT TagSet : public QSet<SemanticInfoTag>
0047 {
0048 public:
0049     TagSet();
0050     TagSet(const QSet<SemanticInfoTag> &);
0051 
0052     QVariant toVariant() const;
0053     static TagSet fromVariant(const QVariant &);
0054     static TagSet fromList(const QList<SemanticInfoTag> &);
0055 
0056 private:
0057     TagSet(const QList<SemanticInfoTag> &);
0058 };
0059 
0060 /**
0061  * A POD struct used by AbstractSemanticInfoBackEnd to store the metadata
0062  * associated to an url.
0063  */
0064 struct SemanticInfo {
0065     int mRating;
0066     QString mDescription;
0067     TagSet mTags;
0068 };
0069 
0070 /**
0071  * An abstract class, used by SemanticInfoDirModel to store and retrieve metadata.
0072  */
0073 class GWENVIEWLIB_EXPORT AbstractSemanticInfoBackEnd : public QObject
0074 {
0075     Q_OBJECT
0076 public:
0077     explicit AbstractSemanticInfoBackEnd(QObject *parent);
0078 
0079     virtual TagSet allTags() const = 0;
0080 
0081     virtual void refreshAllTags() = 0;
0082 
0083     virtual void storeSemanticInfo(const QUrl &, const SemanticInfo &) = 0;
0084 
0085     virtual void retrieveSemanticInfo(const QUrl &) = 0;
0086 
0087     virtual QString labelForTag(const SemanticInfoTag &) const = 0;
0088 
0089     /**
0090      * Return a tag for a label. Will emit tagAdded() if the tag had to be
0091      * created.
0092      */
0093     virtual SemanticInfoTag tagForLabel(const QString &) = 0;
0094 
0095 Q_SIGNALS:
0096     void semanticInfoRetrieved(const QUrl &, const SemanticInfo &);
0097 
0098     /**
0099      * Emitted whenever a new tag is added to allTags()
0100      */
0101     void tagAdded(const SemanticInfoTag &, const QString &label);
0102 };
0103 
0104 } // namespace
0105 
0106 #endif /* ABSTRACTSEMANTICINFOBACKEND_H */