File indexing completed on 2024-05-12 15:59:53

0001 /*
0002  * SPDX-FileCopyrightText: 2018 Boudewijn Rempt <boud@valdyas.org>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #ifndef KISTAGLOADER_H
0008 #define KISTAGLOADER_H
0009 
0010 #include <QDebug>
0011 #include <QString>
0012 #include <QScopedPointer>
0013 #include <QSharedPointer>
0014 
0015 class QIODevice;
0016 
0017 #include "kritaresources_export.h"
0018 
0019 class KisTag;
0020 typedef QSharedPointer<KisTag> KisTagSP;
0021 
0022 
0023 /**
0024  * @brief The KisTag loads a tag from a .tag file.
0025  * A .tag file is a .desktop file. The following fields
0026  * are important:
0027  *
0028  * name: the name of the tag, which can be translated
0029  * comment: a tooltip for the tag, which can be translagted
0030  * url: the untranslated name of the tag
0031  *
0032  */
0033 class KRITARESOURCES_EXPORT KisTag
0034 {
0035 public:
0036     KisTag();
0037     virtual ~KisTag();
0038     KisTag(const KisTag &rhs);
0039     KisTag &operator=(const KisTag &rhs);
0040     KisTagSP clone() const;
0041 
0042     static QString currentLocale();
0043 
0044     bool valid() const;
0045 
0046     int id() const;
0047     bool active() const;
0048 
0049     QString filename();
0050     void setFilename(const QString &fileName);
0051 
0052     /// The unique identifier for the tag. Since tag urls are compared COLLATE NOCASE, tag urls must be ASCII only.
0053     QString url() const;
0054     void setUrl(const QString &url);
0055 
0056     /// The translated names of the tag
0057     QString name(bool translated = true) const;
0058     void setName(const QString &name);
0059     QMap<QString, QString> names() const;
0060     void setNames(const QMap<QString, QString> &names);
0061 
0062     /// The translated tooltips for the tag
0063     QString comment(bool translated = true) const;
0064     void setComment(const QString comment);
0065     QMap<QString, QString> comments() const;
0066     void setComments(const QMap<QString, QString> &comments);
0067 
0068     QString resourceType() const;
0069     void setResourceType(const QString &resourceType);
0070 
0071     QStringList defaultResources() const;
0072     void setDefaultResources(const QStringList &defaultResources);
0073 
0074     bool load(QIODevice &io);
0075     bool save(QIODevice &io);
0076 
0077 private:
0078 
0079     friend class KisTagModel;
0080     friend class KisAllTagsModel;
0081     friend class KisAllTagResourceModel;
0082     friend class KisAllResourcesModel;
0083     friend class KisResourceModel;
0084     friend class KisTagChooserWidget;
0085     friend class TestTagModel;
0086     friend class KisResourceLocator;
0087     friend class BundleTagIterator;
0088     friend class AbrTagIterator;
0089 
0090     void setId(int id);
0091     void setActive(bool active);
0092     void setValid(bool valid);
0093 
0094     static const QString s_group;
0095     static const QString s_type;
0096     static const QString s_tag;
0097     static const QString s_name;
0098     static const QString s_resourceType;
0099     static const QString s_url;
0100     static const QString s_comment;
0101     static const QString s_defaultResources;
0102     static const QString s_desktop;
0103 
0104     class Private;
0105     QScopedPointer<Private> d;
0106 };
0107 
0108 
0109 inline QDebug operator<<(QDebug dbg, const KisTagSP tag)
0110 {
0111     if (tag) {
0112         dbg.space() << "[TAG] Name" << tag->name()
0113                     << "Url" << tag->url()
0114                     << "Comment" << tag->comment()
0115                     << "Default resources" << tag->defaultResources().join(", ");
0116     } else {
0117         dbg.space() << "[TAG] NULL";
0118     }
0119 
0120     return dbg.space();
0121 }
0122 
0123 Q_DECLARE_METATYPE(QSharedPointer<KisTag>)
0124 
0125 #endif // KISTAGLOADER_H