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

0001 /* This file is part of the KDE project
0002    SPDX-FileCopyrightText: 2014 Victor Lafon <metabolic.ewilan@hotmail.fr>
0003 
0004    SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 #ifndef KORESOURCEBUNDLEMANIFEST_H
0008 #define KORESOURCEBUNDLEMANIFEST_H
0009 
0010 #include <QString>
0011 #include <QPair>
0012 #include <QMap>
0013 #include <QMultiMap>
0014 #include <QDomElement>
0015 
0016 #include <kritaresources_export.h>
0017 
0018 class QIODevice;
0019 
0020 class KRITARESOURCES_EXPORT  KoResourceBundleManifest
0021 {
0022 public:
0023 
0024     struct ResourceReference {
0025 
0026         ResourceReference() {}
0027 
0028         ResourceReference(const QString &_resourcePath, const QList<QString> &_tagList, const QString &_fileTypeName,
0029                           const QString &_md5, const int _resourceId = -1, const QString _filenameInBundle = "") {
0030             resourcePath = _resourcePath;
0031             tagList = _tagList;
0032             fileTypeName = _fileTypeName;
0033             md5sum = _md5;
0034             resourceId = _resourceId;
0035             // only necessary to provide if filename in bundle is different from the filename on disk
0036             // for example for versioned resources
0037             filenameInBundle = _filenameInBundle.isEmpty() ? resourcePath : _filenameInBundle;
0038         }
0039 
0040         QString resourcePath;
0041         QList<QString> tagList;
0042         QString fileTypeName;
0043         QString md5sum;
0044         int resourceId;
0045         QString filenameInBundle;
0046     };
0047 
0048     /**
0049      * @brief ResourceBundleManifest : Ctor
0050      * @param xmlName the name of the XML file to be created
0051      */
0052     KoResourceBundleManifest();
0053 
0054     /**
0055      * @brief ~ResourceBundleManifest : Dtor
0056      */
0057     virtual ~KoResourceBundleManifest();
0058 
0059 
0060     /**
0061      * @brief load the ResourceBundleManifest from the given device
0062      */
0063     bool load(QIODevice *device);
0064 
0065     /**
0066      * @brief save the ResourceBundleManifest to the given device
0067      */
0068     bool save(QIODevice *device);
0069 
0070     /**
0071      * @brief addTag : Add a file tag as a child of the fileType tag.
0072      * @param fileType the type of the file to be added
0073      * @param fileName the name of the file to be added
0074      * @param emptyFile true if the file is empty
0075      * @return the element corresponding to the created tag.
0076      */
0077     void addResource(const QString &fileType, const QString &fileName, const QStringList &tagFileList, const QString &md5, const int resourceId = -1, const QString filenameInBundle = "");
0078     void removeResource(ResourceReference &resource);
0079 
0080     QStringList types() const;
0081 
0082     QStringList tags() const;
0083 
0084     QList<ResourceReference> files(const QString &type = QString()) const;
0085 
0086     /**
0087      * @brief removeFile : remove a file from the manifest
0088      * @param fileName : the name of the file to be removed
0089      * @return the list of resource tags to be removed from meta file.
0090      */
0091     void removeFile(QString fileName);
0092 
0093 private:
0094     QMap<QString, QMap<QString, ResourceReference>> m_resources;
0095     bool parseFileEntry(const QDomElement &e);
0096 };
0097 
0098 
0099 #endif