File indexing completed on 2024-09-01 10:27:11
0001 /* 0002 SPDX-FileCopyrightText: 2009 Rob Scheepmaker <r.scheepmaker@student.utwente.nl> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KPACKAGE_PACKAGE_P_H 0008 #define KPACKAGE_PACKAGE_P_H 0009 0010 #include "../package.h" 0011 0012 #include <QCryptographicHash> 0013 #include <QDir> 0014 #include <QHash> 0015 #include <QPointer> 0016 #include <QSharedData> 0017 #include <QString> 0018 #include <optional> 0019 namespace KPackage 0020 { 0021 // KPackage is is normally used on the stack, explicitly shared and isn't a QObject 0022 // however PackageJob is given a pointer, which could be deleted at any moment 0023 // leaving the PackageJob with a dangling pointer 0024 // we need some way to invalidate the Package* pointer if it gets deleted 0025 0026 // we can't just take a copy in the packagejob as we need to detach and update the *original* KPackage object 0027 // without changing anything else which happened to share the same KPackage::d 0028 0029 // TODO KF6 - make KPackage::install()'s KJob return a new Package copy rather than modify 0030 // an existing object. 0031 class PackageDeletionNotifier : public QObject 0032 { 0033 Q_OBJECT 0034 public: 0035 static PackageDeletionNotifier *self(); 0036 Q_SIGNALS: 0037 void packageDeleted(Package *package); 0038 }; 0039 0040 class ContentStructure 0041 { 0042 public: 0043 ContentStructure() 0044 : directory(false) 0045 , required(false) 0046 { 0047 } 0048 0049 ContentStructure(const ContentStructure &other) 0050 { 0051 paths = other.paths; 0052 name = other.name; 0053 mimeTypes = other.mimeTypes; 0054 directory = other.directory; 0055 required = other.required; 0056 } 0057 0058 ContentStructure &operator=(const ContentStructure &) = default; 0059 0060 QStringList paths; 0061 QString name; 0062 QStringList mimeTypes; 0063 bool directory : 1; 0064 bool required : 1; 0065 }; 0066 0067 class PackagePrivate : public QSharedData 0068 { 0069 public: 0070 PackagePrivate(); 0071 PackagePrivate(const PackagePrivate &other); 0072 ~PackagePrivate(); 0073 0074 PackagePrivate &operator=(const PackagePrivate &rhs); 0075 0076 void createPackageMetadata(const QString &path); 0077 QString unpack(const QString &filePath); 0078 void updateHash(const QString &basePath, const QString &subPath, const QDir &dir, QCryptographicHash &hash); 0079 QString fallbackFilePath(const QByteArray &key, const QString &filename = QString()) const; 0080 bool hasCycle(const KPackage::Package &package); 0081 bool isInsidePackageDir(const QString &canonicalPath) const; 0082 0083 QPointer<PackageStructure> structure; 0084 QString path; 0085 QString tempRoot; 0086 QStringList contentsPrefixPaths; 0087 QString defaultPackageRoot; 0088 QHash<QString, QString> discoveries; 0089 QHash<QByteArray, ContentStructure> contents; 0090 std::unique_ptr<Package> fallbackPackage; 0091 QStringList mimeTypes; 0092 std::optional<KPluginMetaData> metadata; 0093 QString rccPath; 0094 bool externalPaths : 1; 0095 bool valid : 1; 0096 bool checkedValid : 1; 0097 }; 0098 0099 } 0100 0101 #endif