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

0001 /*
0002  *  SPDX-FileCopyrightText: 2014 Victor Lafon metabolic.ewilan @hotmail.fr
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #ifndef KORESOURCEBUNDLE_H
0008 #define KORESOURCEBUNDLE_H
0009 
0010 #include <QSet>
0011 #include <QList>
0012 #include <QSharedPointer>
0013 #include <QDomDocument>
0014 
0015 #include <KoXmlWriter.h>
0016 
0017 #include <KoResource.h>
0018 #include "KoResourceBundleManifest.h"
0019 
0020 #include "kritaresources_export.h"
0021 
0022 #include <KisTag.h>
0023 
0024 class KoStore;
0025 
0026 /**
0027  * @brief A KoResourceBundle is a zip file that contains resources,
0028  * some metadata about the creator of the bundle and a manifest file
0029  * that lists the contained resources.
0030  */
0031 class KRITARESOURCES_EXPORT KoResourceBundle
0032 {
0033 
0034 public:
0035     /**
0036      * @brief ResourceBundle : Ctor * @param bundlePath the path of the bundle
0037      */
0038     KoResourceBundle(QString const& fileName);
0039 
0040     /**
0041      * @brief ~ResourceBundle : Dtor
0042      */
0043     virtual ~KoResourceBundle();
0044 
0045     /**
0046      * @brief defaultFileExtension
0047      * @return the default file extension which should be when saving the resource
0048      */
0049     QString defaultFileExtension() const;
0050 
0051     /**
0052      * @brief load : Load this resource.
0053      * @return true if succeed, false otherwise.
0054      */
0055     bool load();
0056     bool loadFromDevice(QIODevice *dev);
0057 
0058     /**
0059      * @brief save : Save this resource.
0060      * @return true if succeed, false otherwise.
0061      */
0062     bool save();
0063 
0064     bool saveToDevice(QIODevice* dev) const;
0065 
0066     /**
0067      * @brief addMeta : Add a Metadata to the resource
0068      * @param type type of the metadata
0069      * @param value value of the metadata
0070      */
0071     void setMetaData(const QString &key, const QString &value);
0072     const QString metaData(const QString &key, const QString &defaultValue = QString()) const;
0073 
0074     /**
0075      * @brief addFile : Add a file to the bundle
0076      * @param fileType type of the resource file
0077      * @param filePath path of the resource file
0078      */
0079     void addResource(QString fileType, QString filePath, QVector<KisTagSP> fileTagList, const QString md5sum, const int resourceId = -1, const QString filenameInBundle = "");
0080 
0081     QList<QString> getTagsList();
0082 
0083     void setThumbnail(QString);
0084 
0085     /**
0086      * @brief saveMetadata: saves bundle metadata
0087      * @param store bundle where to save the metadata
0088      */
0089     void saveMetadata(QScopedPointer<KoStore> &store);
0090 
0091     /**
0092      * @brief saveManifest: saves bundle manifest
0093      * @param store bundle where to save the manifest
0094      */
0095     void saveManifest(QScopedPointer<KoStore> &store);
0096 
0097     QStringList resourceTypes() const;
0098     int resourceCount() const;
0099 
0100     KoResourceBundleManifest &manifest();
0101 
0102     KoResourceSP resource(const QString &resourceType, const QString &filepath);
0103     bool exportResource(const QString &resourceType, const QString &fileName, QIODevice *device);
0104     bool loadResource(KoResourceSP resource);
0105 
0106     QImage image() const;
0107 
0108     QString filename() const;
0109 
0110     QString resourceMd5(const QString &url);
0111 private:
0112 
0113     void writeMeta(const QString &metaTag, KoXmlWriter *writer);
0114     void writeUserDefinedMeta(const QString &metaTag, KoXmlWriter *writer);
0115     bool readMetaData(KoStore *resourceStore);
0116 
0117 private:
0118     QImage m_thumbnail;
0119     KoResourceBundleManifest m_manifest;
0120     QMap<QString, QString> m_metadata;
0121     QSet<QString> m_bundletags;
0122     QList<QByteArray> m_gradientsMd5Installed;
0123     QList<QByteArray> m_patternsMd5Installed;
0124     QList<QByteArray> m_brushesMd5Installed;
0125     QList<QByteArray> m_palettesMd5Installed;
0126     QList<QByteArray> m_workspacesMd5Installed;
0127     QList<QByteArray> m_presetsMd5Installed;
0128     QString m_filename;
0129     QString m_bundleVersion;
0130 
0131 };
0132 
0133 typedef QSharedPointer<KoResourceBundle> KoResourceBundleSP;
0134 
0135 #endif // KORESOURCEBUNDLE_H