File indexing completed on 2024-04-21 03:52:30

0001 /* This file is part of the KDE libraries
0002    SPDX-FileCopyrightText: 2011 Mario Bensi <mbensi@ipsquad.net>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 #ifndef K7ZIP_H
0007 #define K7ZIP_H
0008 
0009 #include <karchive.h>
0010 
0011 /**
0012  * @class K7Zip k7zip.h K7Zip
0013  *
0014  * A class for reading / writing p7zip archives.
0015  *
0016  * @author Mario Bensi
0017  */
0018 class KARCHIVE_EXPORT K7Zip : public KArchive
0019 {
0020     Q_DECLARE_TR_FUNCTIONS(K7Zip)
0021 
0022 public:
0023     /**
0024      * Creates an instance that operates on the given filename
0025      * using the compression filter associated to given mimetype.
0026      *
0027      * @param filename is a local path (e.g. "/home/user/myfile.7z")
0028      */
0029     explicit K7Zip(const QString &filename);
0030 
0031     /**
0032      * Creates an instance that operates on the given device.
0033      * The device can be compressed (KCompressionDevice) or not (QFile, etc.).
0034      * @warning Do not assume that giving a QFile here will decompress the file,
0035      * in case it's compressed!
0036      * @param dev the device to read from. If the source is compressed, the
0037      * QIODevice must take care of decompression
0038      */
0039     explicit K7Zip(QIODevice *dev);
0040 
0041     /**
0042      * If the archive is still opened, then it will be
0043      * closed automatically by the destructor.
0044      */
0045     ~K7Zip() override;
0046 
0047 protected:
0048     /// Reimplemented from KArchive
0049     bool doWriteSymLink(const QString &name,
0050                         const QString &target,
0051                         const QString &user,
0052                         const QString &group,
0053                         mode_t perm,
0054                         const QDateTime &atime,
0055                         const QDateTime &mtime,
0056                         const QDateTime &ctime) override;
0057     /// Reimplemented from KArchive
0058     bool doWriteDir(const QString &name,
0059                     const QString &user,
0060                     const QString &group,
0061                     mode_t perm,
0062                     const QDateTime &atime,
0063                     const QDateTime &mtime,
0064                     const QDateTime &ctime) override;
0065     /// Reimplemented from KArchive
0066     bool doPrepareWriting(const QString &name,
0067                           const QString &user,
0068                           const QString &group,
0069                           qint64 size,
0070                           mode_t perm,
0071                           const QDateTime &atime,
0072                           const QDateTime &mtime,
0073                           const QDateTime &ctime) override;
0074     /// Reimplemented from KArchive
0075     bool doFinishWriting(qint64 size) override;
0076 
0077     /// Reimplemented from KArchive
0078     bool doWriteData(const char *data, qint64 size) override;
0079 
0080     /**
0081      * Opens the archive for reading.
0082      * Parses the directory listing of the archive
0083      * and creates the KArchiveDirectory/KArchiveFile entries.
0084      * @param mode the mode of the file
0085      */
0086     bool openArchive(QIODevice::OpenMode mode) override;
0087     bool closeArchive() override;
0088 
0089 protected:
0090     void virtual_hook(int id, void *data) override;
0091 
0092 private:
0093     class K7ZipPrivate;
0094     K7ZipPrivate *const d;
0095 };
0096 
0097 #endif