| 1 | /* This file is part of the KDE libraries |
| 2 | SPDX-FileCopyrightText: 2000-2005 David Faure <faure@kde.org> |
| 3 | SPDX-FileCopyrightText: 2003 Leo Savernik <l.savernik@aon.at> |
| 4 | |
| 5 | Moved from ktar.h by Roberto Teixeira <maragato@kde.org> |
| 6 | |
| 7 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 8 | */ |
| 9 | #ifndef KARCHIVEDIRECTORY_H |
| 10 | #define KARCHIVEDIRECTORY_H |
| 11 | |
| 12 | #include <sys/stat.h> |
| 13 | #include <sys/types.h> |
| 14 | |
| 15 | #include <QDate> |
| 16 | #include <QString> |
| 17 | #include <QStringList> |
| 18 | |
| 19 | #include <karchiveentry.h> |
| 20 | |
| 21 | class KArchiveDirectoryPrivate; |
| 22 | class KArchiveFile; |
| 23 | /*! |
| 24 | * \class KArchiveDirectory |
| 25 | * \inmodule KArchive |
| 26 | * |
| 27 | * \brief A directory in an archive. |
| 28 | * |
| 29 | * \sa KArchive |
| 30 | * \sa KArchiveFile |
| 31 | */ |
| 32 | class KARCHIVE_EXPORT KArchiveDirectory : public KArchiveEntry |
| 33 | { |
| 34 | public: |
| 35 | /*! |
| 36 | * Creates a new directory entry. |
| 37 | * |
| 38 | * \a archive the entries archive |
| 39 | * |
| 40 | * \a name the name of the entry |
| 41 | * |
| 42 | * \a access the permissions in unix format |
| 43 | * |
| 44 | * \a date the date (in seconds since 1970) |
| 45 | * |
| 46 | * \a user the user that owns the entry |
| 47 | * |
| 48 | * \a group the group that owns the entry |
| 49 | * |
| 50 | * \a symlink the symlink, or QString() |
| 51 | */ |
| 52 | KArchiveDirectory(KArchive *archive, |
| 53 | const QString &name, |
| 54 | int access, |
| 55 | const QDateTime &date, |
| 56 | const QString &user, |
| 57 | const QString &group, |
| 58 | const QString &symlink); |
| 59 | |
| 60 | ~KArchiveDirectory() override; |
| 61 | |
| 62 | /*! |
| 63 | * Returns a list of sub-entries. |
| 64 | * |
| 65 | * Note that the list is not sorted, it's even in random order (due to using a hashtable). |
| 66 | * Use sort() on the result to sort the list by filename. |
| 67 | * |
| 68 | * Returns the names of all entries in this directory (filenames, no path). |
| 69 | */ |
| 70 | QStringList entries() const; |
| 71 | |
| 72 | /*! |
| 73 | * Returns the entry in the archive with the given name. |
| 74 | * |
| 75 | * The entry could be a file or a directory, use isFile() to find out which one it is. |
| 76 | * |
| 77 | * \a name may be "test1", "mydir/test3", "mydir/mysubdir/test3", etc. |
| 78 | * |
| 79 | * Returns a pointer to the entry in the directory, or a null pointer if there is no such entry. |
| 80 | */ |
| 81 | const KArchiveEntry *entry(const QString &name) const; |
| 82 | |
| 83 | /*! |
| 84 | * Returns the file entry in the archive with the given name. |
| 85 | * |
| 86 | * If the entry exists and is a file, a KArchiveFile is returned. |
| 87 | * |
| 88 | * Otherwise, a null pointer is returned. |
| 89 | * |
| 90 | * This is a convenience method for entry(), when we know the entry is expected to be a file. |
| 91 | * |
| 92 | * |
| 93 | * \a name may be "test1", "mydir/test3", "mydir/mysubdir/test3", etc. |
| 94 | * |
| 95 | * Returns a pointer to the file entry in the directory, or a null pointer if there is no such file entry. |
| 96 | * \since 5.3 |
| 97 | */ |
| 98 | const KArchiveFile *file(const QString &name) const; |
| 99 | |
| 100 | #if KARCHIVE_ENABLE_DEPRECATED_SINCE(6, 13) |
| 101 | /*! |
| 102 | * \internal |
| 103 | * Adds a new entry to the directory. |
| 104 | * |
| 105 | * Note: this can delete the entry if another one with the same name is already present |
| 106 | * |
| 107 | * \deprecated[6.13] |
| 108 | * |
| 109 | * Use addEntryV2() instead. |
| 110 | */ |
| 111 | KARCHIVE_DEPRECATED_VERSION(6, 13, "Use addEntryV2() instead." ) |
| 112 | void addEntry(KArchiveEntry *); // KF7 TODO: remove |
| 113 | #endif |
| 114 | |
| 115 | /*! |
| 116 | * \internal |
| 117 | * Adds a new entry to the directory. |
| 118 | * |
| 119 | * Returns whether the entry was added or not. Non added entries are deleted |
| 120 | * \since 6.13 |
| 121 | * |
| 122 | * Returns whether the entry was added or not. Non added entries are deleted |
| 123 | */ |
| 124 | [[nodiscard]] bool addEntryV2(KArchiveEntry *); // KF7 TODO: rename to addEntry |
| 125 | |
| 126 | #if KARCHIVE_ENABLE_DEPRECATED_SINCE(6, 13) |
| 127 | /*! |
| 128 | * \internal |
| 129 | * |
| 130 | * Removes an entry from the directory. |
| 131 | * |
| 132 | * \deprecated[6.13] |
| 133 | * Use removeEntryV2() instead. |
| 134 | */ |
| 135 | KARCHIVE_DEPRECATED_VERSION(6, 13, "Use removeEntryV2() instead." ) |
| 136 | void removeEntry(KArchiveEntry *); // KF7 TODO: remove |
| 137 | #endif |
| 138 | |
| 139 | /*! |
| 140 | * Removes an entry from the directory. |
| 141 | * |
| 142 | * Returns whether the entry was removed or not. |
| 143 | * \since 6.13 |
| 144 | */ |
| 145 | [[nodiscard]] bool removeEntryV2(KArchiveEntry *); // KF7 TODO: rename to removeEntry |
| 146 | |
| 147 | /* |
| 148 | * Returns true, since this entry is a directory |
| 149 | */ |
| 150 | bool isDirectory() const override; |
| 151 | |
| 152 | /*! |
| 153 | * Extracts all entries in this archive directory to the directory |
| 154 | * |
| 155 | * \a dest. |
| 156 | * |
| 157 | * \a dest the directory to extract to |
| 158 | * |
| 159 | * \a recursive if set to true, subdirectories are extracted as well |
| 160 | * |
| 161 | * Returns true on success, false if the directory (dest + '/' + name()) couldn't be created |
| 162 | */ |
| 163 | bool copyTo(const QString &dest, bool recursive = true) const; |
| 164 | |
| 165 | protected: |
| 166 | void virtual_hook(int id, void *data) override; |
| 167 | |
| 168 | private: |
| 169 | friend class KArchiveDirectoryPrivate; |
| 170 | KArchiveDirectoryPrivate *const d; |
| 171 | }; |
| 172 | |
| 173 | #endif |
| 174 | |