1 // vim: set tabstop=4 shiftwidth=4 expandtab: 2 /* 3 Gwenview: an image viewer 4 Copyright 2008 Aurélien Gâteau <agateau@kde.org> 5 6 This program is free software; you can redistribute it and/or 7 modify it under the terms of the GNU General Public License 8 as published by the Free Software Foundation; either version 2 9 of the License, or (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. 19 20 */ 21 #ifndef ABSTRACTSEMANTICINFOBACKEND_H 22 #define ABSTRACTSEMANTICINFOBACKEND_H 23 24 #include <lib/gwenviewlib_export.h> 25 26 // Qt 27 #include <QObject> 28 #include <QSet> 29 30 // KF 31 32 // Local 33 34 class QUrl; 35 36 namespace Gwenview 37 { 38 using SemanticInfoTag = QString; 39 40 /** 41 * This class represents the set of tags associated to an url. 42 * 43 * It provides convenience methods to convert to and from QVariant, which are 44 * useful to communicate with SemanticInfoDirModel. 45 */ 46 class GWENVIEWLIB_EXPORT TagSet : public QSet<SemanticInfoTag> 47 { 48 public: 49 TagSet(); 50 TagSet(const QSet<SemanticInfoTag> &); 51 52 QVariant toVariant() const; 53 static TagSet fromVariant(const QVariant &); 54 static TagSet fromList(const QList<SemanticInfoTag> &); 55 56 private: 57 TagSet(const QList<SemanticInfoTag> &); 58 }; 59 60 /** 61 * A POD struct used by AbstractSemanticInfoBackEnd to store the metadata 62 * associated to an url. 63 */ 64 struct SemanticInfo { 65 int mRating; 66 QString mDescription; 67 TagSet mTags; 68 }; 69 70 /** 71 * An abstract class, used by SemanticInfoDirModel to store and retrieve metadata. 72 */ 73 class AbstractSemanticInfoBackEnd : public QObject 74 { 75 Q_OBJECT 76 public: 77 explicit AbstractSemanticInfoBackEnd(QObject *parent); 78 79 virtual TagSet allTags() const = 0; 80 81 virtual void refreshAllTags() = 0; 82 83 virtual void storeSemanticInfo(const QUrl &, const SemanticInfo &) = 0; 84 85 virtual void retrieveSemanticInfo(const QUrl &) = 0; 86 87 virtual QString labelForTag(const SemanticInfoTag &) const = 0; 88 89 /** 90 * Return a tag for a label. Will emit tagAdded() if the tag had to be 91 * created. 92 */ 93 virtual SemanticInfoTag tagForLabel(const QString &) = 0; 94 95 Q_SIGNALS: 96 void semanticInfoRetrieved(const QUrl &, const SemanticInfo &); 97 98 /** 99 * Emitted whenever a new tag is added to allTags() 100 */ 101 void tagAdded(const SemanticInfoTag &, const QString &label); 102 }; 103 104 } // namespace 105 106 #endif /* ABSTRACTSEMANTICINFOBACKEND_H */ 107