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

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