| 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 KARCHIVEFILE_H |
| 10 | #define KARCHIVEFILE_H |
| 11 | |
| 12 | #include <karchiveentry.h> |
| 13 | |
| 14 | class KArchiveFilePrivate; |
| 15 | /*! |
| 16 | * \class KArchiveFile |
| 17 | * \inmodule KArchive |
| 18 | * |
| 19 | * \brief A file in an archive. |
| 20 | * |
| 21 | * \sa KArchive |
| 22 | * \sa KArchiveDirectory |
| 23 | */ |
| 24 | class KARCHIVE_EXPORT KArchiveFile : public KArchiveEntry |
| 25 | { |
| 26 | public: |
| 27 | /*! |
| 28 | * Creates a new file entry. Do not call this, KArchive takes care of it. |
| 29 | * \a archive the entries archive |
| 30 | * \a name the name of the entry |
| 31 | * \a access the permissions in unix format |
| 32 | * \a date the date (in seconds since 1970) |
| 33 | * \a user the user that owns the entry |
| 34 | * \a group the group that owns the entry |
| 35 | * \a symlink the symlink, or QString() |
| 36 | * \a pos the position of the file in the directory |
| 37 | * \a size the size of the file |
| 38 | */ |
| 39 | KArchiveFile(KArchive *archive, |
| 40 | const QString &name, |
| 41 | int access, |
| 42 | const QDateTime &date, |
| 43 | const QString &user, |
| 44 | const QString &group, |
| 45 | const QString &symlink, |
| 46 | qint64 pos, |
| 47 | qint64 size); |
| 48 | |
| 49 | /*! |
| 50 | * Destructor. Do not call this, KArchive takes care of it. |
| 51 | */ |
| 52 | ~KArchiveFile() override; |
| 53 | |
| 54 | /*! |
| 55 | * Position of the data in the [uncompressed] archive. |
| 56 | * Returns the position of the file |
| 57 | */ |
| 58 | qint64 position() const; |
| 59 | /*! |
| 60 | * Size of the data. |
| 61 | * Returns the size of the file |
| 62 | */ |
| 63 | qint64 size() const; |
| 64 | /*! |
| 65 | * Set size of data, usually after writing the file. |
| 66 | * \a s the new size of the file |
| 67 | */ |
| 68 | void setSize(qint64 s); |
| 69 | |
| 70 | /*! |
| 71 | * Returns the data of the file. |
| 72 | * Call data() with care (only once per file), this data isn't cached. |
| 73 | * Returns the content of this file. |
| 74 | */ |
| 75 | virtual QByteArray data() const; |
| 76 | |
| 77 | /*! |
| 78 | * This method returns QIODevice (internal class: KLimitedIODevice) |
| 79 | * on top of the underlying QIODevice. This is obviously for reading only. |
| 80 | * |
| 81 | * WARNING: Note that the ownership of the device is being transferred to the caller, |
| 82 | * who will have to delete it. |
| 83 | * |
| 84 | * The returned device auto-opens (in readonly mode), no need to open it. |
| 85 | * Returns the QIODevice of the file |
| 86 | */ |
| 87 | virtual QIODevice *createDevice() const; |
| 88 | |
| 89 | /*! |
| 90 | * Checks whether this entry is a file. |
| 91 | * Returns true, since this entry is a file |
| 92 | */ |
| 93 | bool isFile() const override; |
| 94 | |
| 95 | /*! |
| 96 | * Extracts the file to the directory \a dest |
| 97 | * \a dest the directory to extract to |
| 98 | * Returns true on success, false if the file (dest + '/' + name()) couldn't be created |
| 99 | */ |
| 100 | bool copyTo(const QString &dest) const; |
| 101 | |
| 102 | protected: |
| 103 | void virtual_hook(int id, void *data) override; |
| 104 | |
| 105 | private: |
| 106 | KArchiveFilePrivate *const d; |
| 107 | }; |
| 108 | |
| 109 | #endif |
| 110 | |