1 /* This file is part of the KDE libraries 2 SPDX-FileCopyrightText: 2011 Mario Bensi <mbensi@ipsquad.net> 3 4 SPDX-License-Identifier: LGPL-2.0-or-later 5 */ 6 #ifndef K7ZIP_H 7 #define K7ZIP_H 8 9 #include <karchive.h> 10 11 /** 12 * @class K7Zip k7zip.h K7Zip 13 * 14 * A class for reading / writing p7zip archives. 15 * 16 * @author Mario Bensi 17 */ 18 class KARCHIVE_EXPORT K7Zip : public KArchive 19 { 20 Q_DECLARE_TR_FUNCTIONS(K7Zip) 21 22 public: 23 /** 24 * Creates an instance that operates on the given filename 25 * using the compression filter associated to given mimetype. 26 * 27 * @param filename is a local path (e.g. "/home/user/myfile.7z") 28 */ 29 explicit K7Zip(const QString &filename); 30 31 /** 32 * Creates an instance that operates on the given device. 33 * The device can be compressed (KFilterDev) or not (QFile, etc.). 34 * @warning Do not assume that giving a QFile here will decompress the file, 35 * in case it's compressed! 36 * @param dev the device to read from. If the source is compressed, the 37 * QIODevice must take care of decompression 38 */ 39 explicit K7Zip(QIODevice *dev); 40 41 /** 42 * If the archive is still opened, then it will be 43 * closed automatically by the destructor. 44 */ 45 virtual ~K7Zip(); 46 47 protected: 48 49 /// Reimplemented from KArchive 50 bool doWriteSymLink(const QString &name, const QString &target, 51 const QString &user, const QString &group, 52 mode_t perm, const QDateTime &atime, const QDateTime &mtime, const QDateTime &ctime) override; 53 /// Reimplemented from KArchive 54 bool doWriteDir(const QString &name, const QString &user, const QString &group, 55 mode_t perm, const QDateTime &atime, const QDateTime &mtime, const QDateTime &ctime) override; 56 /// Reimplemented from KArchive 57 bool doPrepareWriting(const QString &name, const QString &user, 58 const QString &group, qint64 size, mode_t perm, 59 const QDateTime &atime, const QDateTime &mtime, const QDateTime &ctime) override; 60 /// Reimplemented from KArchive 61 bool doFinishWriting(qint64 size) override; 62 63 /// Reimplemented from KArchive 64 bool writeData(const char *data, qint64 size) override; 65 66 /** 67 * Opens the archive for reading. 68 * Parses the directory listing of the archive 69 * and creates the KArchiveDirectory/KArchiveFile entries. 70 * @param mode the mode of the file 71 */ 72 bool openArchive(QIODevice::OpenMode mode) override; 73 bool closeArchive() override; 74 75 protected: 76 void virtual_hook(int id, void *data) override; 77 private: 78 class K7ZipPrivate; 79 K7ZipPrivate *const d; 80 }; 81 82 #endif 83