File indexing completed on 2025-02-16 13:00:36
0001 /* This file is part of the KDE libraries 0002 SPDX-FileCopyrightText: 2000-2005 David Faure <faure@kde.org> 0003 SPDX-FileCopyrightText: 2003 Leo Savernik <l.savernik@aon.at> 0004 0005 Moved from ktar.h by Roberto Teixeira <maragato@kde.org> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 #ifndef KARCHIVEDIRECTORY_H 0010 #define KARCHIVEDIRECTORY_H 0011 0012 #include <sys/stat.h> 0013 #include <sys/types.h> 0014 0015 #include <QDate> 0016 #include <QString> 0017 #include <QStringList> 0018 0019 #include <karchiveentry.h> 0020 0021 class KArchiveDirectoryPrivate; 0022 class KArchiveFile; 0023 /** 0024 * @class KArchiveDirectory karchivedirectory.h KArchiveDirectory 0025 * 0026 * Represents a directory entry in a KArchive. 0027 * @short A directory in an archive. 0028 * 0029 * @see KArchive 0030 * @see KArchiveFile 0031 */ 0032 class KARCHIVE_EXPORT KArchiveDirectory : public KArchiveEntry 0033 { 0034 public: 0035 /** 0036 * Creates a new directory entry. 0037 * @param archive the entries archive 0038 * @param name the name of the entry 0039 * @param access the permissions in unix format 0040 * @param date the date (in seconds since 1970) 0041 * @param user the user that owns the entry 0042 * @param group the group that owns the entry 0043 * @param symlink the symlink, or QString() 0044 */ 0045 KArchiveDirectory(KArchive *archive, 0046 const QString &name, 0047 int access, 0048 const QDateTime &date, 0049 const QString &user, 0050 const QString &group, 0051 const QString &symlink); 0052 0053 ~KArchiveDirectory() override; 0054 0055 /** 0056 * Returns a list of sub-entries. 0057 * Note that the list is not sorted, it's even in random order (due to using a hashtable). 0058 * Use sort() on the result to sort the list by filename. 0059 * 0060 * @return the names of all entries in this directory (filenames, no path). 0061 */ 0062 QStringList entries() const; 0063 0064 /** 0065 * Returns the entry in the archive with the given name. 0066 * The entry could be a file or a directory, use isFile() to find out which one it is. 0067 * @param name may be "test1", "mydir/test3", "mydir/mysubdir/test3", etc. 0068 * @return a pointer to the entry in the directory, or a null pointer if there is no such entry. 0069 */ 0070 const KArchiveEntry *entry(const QString &name) const; 0071 0072 /** 0073 * Returns the file entry in the archive with the given name. 0074 * If the entry exists and is a file, a KArchiveFile is returned. 0075 * Otherwise, a null pointer is returned. 0076 * This is a convenience method for entry(), when we know the entry is expected to be a file. 0077 * 0078 * @param name may be "test1", "mydir/test3", "mydir/mysubdir/test3", etc. 0079 * @return a pointer to the file entry in the directory, or a null pointer if there is no such file entry. 0080 * @since 5.3 0081 */ 0082 const KArchiveFile *file(const QString &name) const; 0083 0084 /** 0085 * @internal 0086 * Adds a new entry to the directory. 0087 * Note: this can delete the entry if another one with the same name is already present 0088 */ 0089 void addEntry(KArchiveEntry *); // KF6 TODO: return bool 0090 0091 /** 0092 * @internal 0093 * Adds a new entry to the directory. 0094 * @return whether the entry was added or not. Non added entries are deleted 0095 */ 0096 bool addEntryV2(KArchiveEntry *); // KF6 TODO: merge with the one above 0097 0098 /** 0099 * @internal 0100 * Removes an entry from the directory. 0101 */ 0102 void removeEntry(KArchiveEntry *); // KF6 TODO: return bool since it can fail 0103 0104 /** 0105 * Checks whether this entry is a directory. 0106 * @return true, since this entry is a directory 0107 */ 0108 bool isDirectory() const override; 0109 0110 /** 0111 * Extracts all entries in this archive directory to the directory 0112 * @p dest. 0113 * @param dest the directory to extract to 0114 * @param recursive if set to true, subdirectories are extracted as well 0115 * @return true on success, false if the directory (dest + '/' + name()) couldn't be created 0116 */ 0117 bool copyTo(const QString &dest, bool recursive = true) const; 0118 0119 protected: 0120 void virtual_hook(int id, void *data) override; 0121 0122 private: 0123 friend class KArchiveDirectoryPrivate; 0124 KArchiveDirectoryPrivate *const d; 0125 }; 0126 0127 #endif