KPackage

packagestructure.h
1 /*
2  SPDX-FileCopyrightText: 2011 Aaron Seigo <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef KPACKAGE_PACKAGESTRUCTURE_H
8 #define KPACKAGE_PACKAGESTRUCTURE_H
9 
10 #include <QStringList>
11 
12 #include <KPluginFactory>
13 
14 #include <kpackage/package.h>
15 #include <kpackage/package_export.h>
16 
17 namespace KPackage
18 {
19 class PackageStructurePrivate;
20 
21 /**
22  * @class PackageStructure kpackage/packagestructure.h <KPackage/PackageStructure>
23  *
24  * This class is used to define the filesystem structure of a package type.
25  * A PackageStructure is implemented as a dynamically loaded plugin, in the reimplementation
26  * of initPackage the allowed fines and directories in the package are set into the package,
27  * for instance:
28  *
29  * @code
30  * package->addFileDefinition("mainscript", QStringLiteral("ui/main.qml"), i18n("Main Script File"));
31  * package->setDefaultPackageRoot(QStringLiteral("plasma/wallpapers/"));
32  * package->addDirectoryDefinition("images", QStringLiteral("images"), i18n("Images"));
33  * package->addDirectoryDefinition("theme", QStringLiteral("theme"), i18n("Themed Images"));
34  * QStringList mimetypes;
35  * mimetypes << QStringLiteral("image/svg+xml") << QStringLiteral("image/png") << QStringLiteral("image/jpeg");
36  * package->setMimeTypes("images", mimetypes);
37  * @endcode
38  *
39  * @author Aaron Seigo
40  */
41 class KPACKAGE_EXPORT PackageStructure : public QObject
42 {
43  Q_OBJECT
44 
45 public:
46  explicit PackageStructure(QObject *parent = nullptr, const QVariantList &args = QVariantList());
47 
49 
50  /**
51  * Called when a the PackageStructure should initialize a Package with the initial
52  * structure. This allows setting paths before setPath is called.
53  *
54  * Note: one special value is "metadata" which can be set to the location of KPluginMetaData
55  * compatible .desktop file within the package. If not defined, it is assumed that this file
56  * exists under the top level directory of the package.
57  *
58  * @param package the Package to set up. The object is empty of all definition when
59  * first passed in.
60  */
61  virtual void initPackage(Package *package);
62 
63  /**
64  * Called whenever the path changes so that subclasses may take
65  * package specific actions.
66  */
67  virtual void pathChanged(Package *package);
68 
69  /**
70  * Installs a package matching this package structure. By default installs a
71  * native KPackage::Package.
72  *
73  * @param package the instance of Package that is being used for the install; useful for
74  * accessing file paths
75  * @param archivePath path to the package archive file
76  * @param packageRoot path to the directory where the package should be
77  * installed to
78  * @return KJob* to track the installation status
79  **/
80  virtual KJob *install(Package *package, const QString &archivePath, const QString &packageRoot);
81 
82  /**
83  * Updates a package matching this package structure. By default installs a
84  * native KPackage::Package. If an older version is already installed,
85  * it removes the old one. If the installed one is newer,
86  * an error will occur.
87  *
88  * @param package the instance of Package that is being used for the install; useful for
89  * accessing file paths
90  * @param archivePath path to the package archive file
91  * @param packageRoot path to the directory where the package should be
92  * installed to
93  * @return KJob* to track the installation status
94  * @since 5.17
95  **/
96  virtual KJob *update(Package *package, const QString &archivePath, const QString &packageRoot);
97 
98  /**
99  * Uninstalls a package matching this package structure.
100  *
101  * @param package the instance of Package that is being used for the install; useful for
102  * accessing file paths
103  * @param packageName the name of the package to remove
104  * @param packageRoot path to the directory where the package should be installed to
105  * @return KJob* to track the installation status
106  */
107  virtual KJob *uninstall(Package *package, const QString &packageRoot);
108 
109 private:
110  PackageStructurePrivate *d;
111 };
112 
113 } // KPackage namespace
114 
115 /**
116  * Register a Package class when it is contained in a loadable module
117  */
118 
119 #define K_EXPORT_KPACKAGE_PACKAGE_WITH_JSON(classname, jsonFile) K_PLUGIN_FACTORY_WITH_JSON(factory, jsonFile, registerPlugin<classname>();)
120 
121 #endif
This class is used to define the filesystem structure of a package type.
object representing an installed package
Definition: package.h:66
Namespace for everything in kpackage.
Definition: package.cpp:33
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Oct 24 2021 22:53:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.