File indexing completed on 2024-05-05 05:50:39
0001 /* 0002 SPDX-FileCopyrightText: 2016 Vladyslav Batyrenko <mvlabat@gmail.com> 0003 0004 SPDX-License-Identifier: BSD-2-Clause 0005 */ 0006 0007 #ifndef ARCHIVEENTRY_H 0008 #define ARCHIVEENTRY_H 0009 0010 #include "archive_kerfuffle.h" 0011 0012 #include <QDateTime> 0013 #include <QIcon> 0014 0015 namespace Kerfuffle 0016 { 0017 enum PathFormat { NoTrailingSlash, WithTrailingSlash }; 0018 0019 class KERFUFFLE_EXPORT Archive::Entry : public QObject 0020 { 0021 Q_OBJECT 0022 0023 /** 0024 * Meta data related to one entry in a compressed archive. 0025 * 0026 * When creating a plugin, information about every single entry in 0027 * an archive is contained in an ArchiveEntry, and metadata 0028 * is set with the entries in this enum. 0029 * 0030 * Please notice that not all archive formats support all the properties 0031 * below, so set those that are available. 0032 */ 0033 Q_PROPERTY(QString fullPath MEMBER m_fullPath WRITE setFullPath) 0034 /// The internal name of the entry in the archive. 0035 Q_PROPERTY(QString name READ name) 0036 /// The visible name of the entry in the UI. This is usually (but not necessarily) equal to the name of the entry. 0037 Q_PROPERTY(QString displayName READ displayName WRITE setDisplayName) 0038 Q_PROPERTY(QString permissions MEMBER m_permissions) 0039 Q_PROPERTY(QString owner MEMBER m_owner) 0040 Q_PROPERTY(QString group MEMBER m_group) 0041 Q_PROPERTY(qulonglong size MEMBER m_size) 0042 Q_PROPERTY(qulonglong compressedSize MEMBER m_compressedSize) 0043 Q_PROPERTY(qulonglong sparseSize MEMBER m_sparseSize) 0044 Q_PROPERTY(QString link MEMBER m_link) 0045 Q_PROPERTY(QString ratio MEMBER m_ratio) 0046 Q_PROPERTY(QString CRC MEMBER m_CRC) 0047 Q_PROPERTY(QString BLAKE2 MEMBER m_BLAKE2) 0048 Q_PROPERTY(QString method MEMBER m_method) 0049 Q_PROPERTY(QString version MEMBER m_version) 0050 Q_PROPERTY(QDateTime timestamp MEMBER m_timestamp) 0051 Q_PROPERTY(bool isDirectory MEMBER m_isDirectory WRITE setIsDirectory) 0052 Q_PROPERTY(bool isExecutable MEMBER m_isExecutable WRITE setIsExecutable) 0053 Q_PROPERTY(bool isPasswordProtected MEMBER m_isPasswordProtected) 0054 Q_PROPERTY(bool isSparse MEMBER m_isSparse) 0055 0056 public: 0057 explicit Entry(QObject *parent = nullptr, const QString &fullPath = {}, const QString &rootNode = {}); 0058 ~Entry() override; 0059 0060 void copyMetaData(const Archive::Entry *sourceEntry); 0061 0062 QVector<Entry *> entries(); 0063 const QVector<Entry *> entries() const; 0064 void setEntryAt(int index, Entry *value); 0065 void appendEntry(Entry *entry); 0066 void removeEntryAt(int index); 0067 Entry *getParent() const; 0068 void setParent(Entry *parent); 0069 void setFullPath(const QString &fullPath); 0070 QString fullPath(PathFormat format = WithTrailingSlash) const; 0071 QString displayName() const; 0072 QString name() const; 0073 QStringView nameView() const; 0074 void setDisplayName(const QString &displayName); 0075 void setIsDirectory(const bool isDirectory); 0076 bool isDir() const; 0077 void setIsExecutable(const bool isExecutable); 0078 bool isExecutable() const; 0079 int row() const; 0080 Entry *find(QStringView name) const; 0081 Entry *findByPath(const QStringList &pieces, int index = 0) const; 0082 QIcon icon() const; 0083 qulonglong size() const; 0084 qulonglong sparseSize() const; 0085 bool isSparse() const; 0086 0087 /** 0088 * Fills @p dirs and @p files with the number of directories and files 0089 * in the entry (both will be 0 if the entry is not a directory). 0090 */ 0091 void countChildren(uint &dirs, uint &files) const; 0092 0093 bool operator==(const Archive::Entry &right) const; 0094 0095 public: 0096 QString rootNode; 0097 bool compressedSizeIsSet; 0098 0099 private: 0100 QVector<Entry *> m_entries; 0101 QString m_name; 0102 QString m_displayName; 0103 Entry *m_parent; 0104 0105 QString m_fullPath; 0106 QString m_permissions; 0107 QString m_owner; 0108 QString m_group; 0109 qulonglong m_size; 0110 qulonglong m_compressedSize; 0111 qulonglong m_sparseSize; 0112 QString m_link; 0113 QString m_ratio; 0114 QString m_CRC; 0115 QString m_BLAKE2; 0116 QString m_method; 0117 QString m_version; 0118 QDateTime m_timestamp; 0119 bool m_isDirectory; 0120 bool m_isExecutable; 0121 bool m_isPasswordProtected; 0122 bool m_isSparse; 0123 mutable QIcon m_icon; 0124 }; 0125 0126 QDebug KERFUFFLE_EXPORT operator<<(QDebug d, const Kerfuffle::Archive::Entry &entry); 0127 QDebug KERFUFFLE_EXPORT operator<<(QDebug d, const Kerfuffle::Archive::Entry *entry); 0128 0129 } 0130 0131 Q_DECLARE_METATYPE(Kerfuffle::Archive::Entry *) 0132 0133 #endif // ARCHIVEENTRY_H