File indexing completed on 2024-12-08 03:41:24

0001 /*
0002     SPDX-FileCopyrightText: 2011 Aaron Seigo <aseigo@kde.org>
0003     SPDX-FileCopyrightText: 2023 Alexander Lohnau <alexander.lohnau@gmx.de>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KPACKAGE_PACKAGESTRUCTURE_H
0009 #define KPACKAGE_PACKAGESTRUCTURE_H
0010 
0011 #include <QStringList>
0012 
0013 #include <KPluginFactory>
0014 
0015 #include <kpackage/package.h>
0016 #include <kpackage/package_export.h>
0017 
0018 namespace KPackage
0019 {
0020 /**
0021  * @class PackageStructure kpackage/packagestructure.h <KPackage/PackageStructure>
0022  *
0023  * This class is used to define the filesystem structure of a package type.
0024  * A PackageStructure is implemented as a dynamically loaded plugin, in the reimplementation
0025  * of initPackage the allowed fines and directories in the package are set into the package,
0026  * for instance:
0027  *
0028  * @code
0029  * package->addFileDefinition("mainscript", QStringLiteral("ui/main.qml"));
0030  * package->setDefaultPackageRoot(QStringLiteral("plasma/wallpapers/"));
0031  * package->addDirectoryDefinition("images", QStringLiteral("images"));
0032  * package->addDirectoryDefinition("theme", QStringLiteral("theme"));
0033  * QStringList mimetypes{QStringLiteral("image/svg+xml"), QStringLiteral("image/png"), QStringLiteral("image/jpeg")};
0034  * package->setMimeTypes("images", mimetypes);
0035  * @endcode
0036  */
0037 class KPACKAGE_EXPORT PackageStructure : public QObject
0038 {
0039     Q_OBJECT
0040 
0041 public:
0042     explicit PackageStructure(QObject *parent = nullptr, const QVariantList &args = QVariantList());
0043 
0044     ~PackageStructure() override;
0045 
0046     /**
0047      * Called when a the PackageStructure should initialize a Package with the initial
0048      * structure. This allows setting paths before setPath is called.
0049      *
0050      * Note: one special value is "metadata" which can be set to the location of KPluginMetaData
0051      * compatible .json file within the package. If not defined, it is assumed that this file
0052      * exists under the top level directory of the package.
0053      *
0054      * @param package the Package to set up. The object is empty of all definition when
0055      *      first passed in.
0056      */
0057     virtual void initPackage(Package *package);
0058 
0059     /**
0060      * Called whenever the path changes so that subclasses may take
0061      * package specific actions.
0062      */
0063     virtual void pathChanged(Package *package);
0064 
0065 private:
0066     void *d;
0067 };
0068 
0069 } // KPackage namespace
0070 
0071 #endif