KPackage 5.109.0
package.h
1/*
2 SPDX-FileCopyrightText: 2007-2011 Aaron Seigo <aseigo@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KPACKAGE_PACKAGE_H
8#define KPACKAGE_PACKAGE_H
9
10#include <QCryptographicHash>
11#include <QMetaType>
12#include <QStringList>
13#include <QUrl>
14
15#include <KPluginMetaData>
16
17#include <kpackage/package_export.h>
18
19#include <KJob>
20
21namespace KPackage
22{
61// TODO: write documentation on USING a package
62
63class PackagePrivate;
64class PackageStructure;
65
66class KPACKAGE_EXPORT Package
67{
68public:
73 enum JobError {
74 RootCreationError = KJob::UserDefinedError + 1,
88 };
89
97 explicit Package(PackageStructure *structure = nullptr);
98
103 Package(const Package &other);
104
105 virtual ~Package();
106
112
119 bool hasValidStructure() const;
120
124 bool isValid() const;
125
131 void setPath(const QString &path);
132
136 const QString path() const;
137
150 QString filePath(const QByteArray &key, const QString &filename = QString()) const;
151
165 QUrl fileUrl(const QByteArray &key, const QString &filename = QString()) const;
166
174 QStringList entryList(const QByteArray &key) const;
175
176#if KPACKAGE_ENABLE_DEPRECATED_SINCE(5, 106)
181 KPACKAGE_DEPRECATED_VERSION(5, 106, "deprecated for lack of usage")
182 QString name(const QByteArray &key) const;
183#endif
184
188 bool isRequired(const QByteArray &key) const;
189
193 QStringList mimeTypes(const QByteArray &key) const;
194
200 QStringList contentsPrefixPaths() const;
201
205 QString defaultPackageRoot() const;
206
211 bool allowExternalPaths() const;
212
219 void setMetadata(const KPluginMetaData &data);
220
224 KPluginMetaData metadata() const;
225
226#if KPACKAGE_ENABLE_DEPRECATED_SINCE(5, 21)
232 KPACKAGE_DEPRECATED_VERSION(5, 21, "Use Package::cryptographicHash(QCryptographicHash::Algorithm)")
233 QString contentsHash() const;
234#endif
235
240 QByteArray cryptographicHash(QCryptographicHash::Algorithm algorithm) const;
241
253 void addDirectoryDefinition(const QByteArray &key, const QString &path, const QString &name = QString());
254
266 void addFileDefinition(const QByteArray &key, const QString &path, const QString &name = QString());
267
273 void removeDefinition(const QByteArray &key);
274
283 void setRequired(const QByteArray &key, bool required);
284
292 void setDefaultMimeTypes(const QStringList &mimeTypes);
293
302 void setMimeTypes(const QByteArray &key, const QStringList &mimeTypes);
303
315 void setContentsPrefixPaths(const QStringList &prefixPaths);
316
322 void setAllowExternalPaths(bool allow);
323
327 void setDefaultPackageRoot(const QString &packageRoot);
328
337
342
343 // Content structure description methods
347 QList<QByteArray> directories() const;
348
352 QList<QByteArray> requiredDirectories() const;
353
357 QList<QByteArray> files() const;
358
362 QList<QByteArray> requiredFiles() const;
363
373 KJob *install(const QString &sourcePackage, const QString &packageRoot = QString());
374
387 KJob *update(const QString &sourcePackage, const QString &packageRoot = QString());
388
394 KJob *uninstall(const QString &packageName, const QString &packageRoot);
395
396private:
397 QExplicitlySharedDataPointer<PackagePrivate> d;
398 friend class PackagePrivate;
399};
400
401}
402
403Q_DECLARE_METATYPE(KPackage::Package)
404#endif
This class is used to define the filesystem structure of a package type.
Definition packagestructure.h:42
object representing an installed package
Definition package.h:67
void setContentsPrefixPaths(const QStringList &prefixPaths)
Sets the prefixes that all the contents in this package should appear under.
QByteArray cryptographicHash(QCryptographicHash::Algorithm algorithm) const
Package & operator=(const Package &rhs)
Assignment operator.
void addDirectoryDefinition(const QByteArray &key, const QString &path, const QString &name=QString())
Adds a directory to the structure of the package.
void setRequired(const QByteArray &key, bool required)
Sets whether or not a given part of the structure is required or not.
bool hasValidStructure() const
void setMimeTypes(const QByteArray &key, const QStringList &mimeTypes)
Define mimeTypes for a given part of the structure The path must already have been added using addDir...
void setPath(const QString &path)
Sets the path to the root of this package.
QUrl fileUrl(const QByteArray &key, const QString &filename=QString()) const
Get the url to a given file based on the key and an optional filename, is the file:// or qrc:// forma...
Package(PackageStructure *structure=nullptr)
Default constructor.
QString defaultPackageRoot() const
bool isValid() const
void addFileDefinition(const QByteArray &key, const QString &path, const QString &name=QString())
Adds a file to the structure of the package.
JobError
Error codes for the install/update/remove jobs.
Definition package.h:73
@ PackageMoveError
Failure to move a package from the system temporary folder to its final destination.
Definition package.h:85
@ UnsupportedArchiveFormatError
The archive format of the package is not supported.
Definition package.h:76
@ PackageAlreadyInstalledError
The package is already installed and a normal install (not update) was performed.
Definition package.h:84
@ PluginNameInvalidError
The plugin name contains characters different from letters, digits, dots and underscores.
Definition package.h:80
@ OldVersionRemovalError
Failed to remove the old version of the package during an upgrade.
Definition package.h:82
@ UpdatePackageTypeMismatchError
A package with this plugin name was already installed, but has a different type in the metadata....
Definition package.h:81
@ NewerVersionAlreadyInstalledError
We tried to update, but the same version or a newer one is already installed.
Definition package.h:83
@ MetadataFileMissingError
The package doesn't have a metadata.desktop file.
Definition package.h:78
@ PackageFileNotFoundError
The package file does not exist.
Definition package.h:75
@ PackageCopyError
Failure to copy a package folder from somewhere in the filesystem to its final destination.
Definition package.h:86
@ PackageOpenError
Can't open the package file for reading.
Definition package.h:77
@ PackageUninstallError
Failure to uninstall a package.
Definition package.h:87
@ PluginNameMissingError
The metadata.desktop file doesn't specify a plugin name.
Definition package.h:79
KJob * install(const QString &sourcePackage, const QString &packageRoot=QString())
Installs a package matching this package structure.
QStringList entryList(const QByteArray &key) const
Get the list of files of a given type.
KJob * update(const QString &sourcePackage, const QString &packageRoot=QString())
Updates a package matching this package structure.
QList< QByteArray > requiredDirectories() const
bool isRequired(const QByteArray &key) const
const QString path() const
void setMetadata(const KPluginMetaData &data)
Sets the metadata for the KPackage.
void setDefaultPackageRoot(const QString &packageRoot)
Sets preferred package root.
QString filePath(const QByteArray &key, const QString &filename=QString()) const
Get the path to a given file based on the key and an optional filename.
void setAllowExternalPaths(bool allow)
Sets whether or not external paths/symlinks can be followed by a package.
KPluginMetaData metadata() const
KPackage::Package fallbackPackage() const
void removeDefinition(const QByteArray &key)
Removes a definition from the structure of the package.
KJob * uninstall(const QString &packageName, const QString &packageRoot)
Uninstalls a package matching this package structure.
QStringList contentsPrefixPaths() const
bool allowExternalPaths() const
QList< QByteArray > files() const
Package(const Package &other)
Copy constructor.
void setFallbackPackage(const KPackage::Package &package)
Sets the fallback package root path If a file won't be found in this package, it will search it in th...
QList< QByteArray > directories() const
QList< QByteArray > requiredFiles() const
QStringList mimeTypes(const QByteArray &key) const
void setDefaultMimeTypes(const QStringList &mimeTypes)
Defines the default mimeTypes for any definitions that do not have associated mimeTypes.