File indexing completed on 2024-05-19 04:27:43

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     void setThumbnail(QImage);
0085 
0086     /**
0087      * @brief saveMetadata: saves bundle metadata
0088      * @param store bundle where to save the metadata
0089      */
0090     void saveMetadata(QScopedPointer<KoStore> &store);
0091 
0092     /**
0093      * @brief saveManifest: saves bundle manifest
0094      * @param store bundle where to save the manifest
0095      */
0096     void saveManifest(QScopedPointer<KoStore> &store);
0097 
0098     QStringList resourceTypes() const;
0099     int resourceCount() const;
0100 
0101     KoResourceBundleManifest &manifest();
0102 
0103     KoResourceSP resource(const QString &resourceType, const QString &filepath);
0104     bool exportResource(const QString &resourceType, const QString &fileName, QIODevice *device);
0105     bool loadResource(KoResourceSP resource);
0106 
0107     QImage image() const;
0108 
0109     QString filename() const;
0110 
0111     QString resourceMd5(const QString &url);
0112 private:
0113 
0114     void writeMeta(const QString &metaTag, KoXmlWriter *writer);
0115     void writeUserDefinedMeta(const QString &metaTag, KoXmlWriter *writer);
0116     bool readMetaData(KoStore *resourceStore);
0117 
0118 private:
0119     QImage m_thumbnail;
0120     KoResourceBundleManifest m_manifest;
0121     QMap<QString, QString> m_metadata;
0122     QSet<QString> m_bundletags;
0123     QList<QByteArray> m_gradientsMd5Installed;
0124     QList<QByteArray> m_patternsMd5Installed;
0125     QList<QByteArray> m_brushesMd5Installed;
0126     QList<QByteArray> m_palettesMd5Installed;
0127     QList<QByteArray> m_workspacesMd5Installed;
0128     QList<QByteArray> m_presetsMd5Installed;
0129     QString m_filename;
0130     QString m_bundleVersion;
0131 
0132 };
0133 
0134 typedef QSharedPointer<KoResourceBundle> KoResourceBundleSP;
0135 
0136 #endif // KORESOURCEBUNDLE_H