File indexing completed on 2025-02-16 13:00:36
0001 /* This file is part of the KDE libraries 0002 SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef __kfilterbase__h 0008 #define __kfilterbase__h 0009 0010 #include <karchive_export.h> 0011 0012 #include <QObject> 0013 #include <QString> 0014 class KFilterBasePrivate; 0015 0016 class QIODevice; 0017 0018 /** 0019 * @class KFilterBase kfilterbase.h KFilterBase 0020 * 0021 * This is the base class for compression filters 0022 * such as gzip and bzip2. It's pretty much internal. 0023 * Don't use directly, use KCompressionDevice instead. 0024 * @internal 0025 */ 0026 class KARCHIVE_EXPORT KFilterBase 0027 { 0028 public: 0029 KFilterBase(); 0030 virtual ~KFilterBase(); 0031 0032 /** 0033 * Sets the device on which the filter will work 0034 * @param dev the device on which the filter will work 0035 * @param autodelete if true, @p dev is deleted when the filter is deleted 0036 */ 0037 void setDevice(QIODevice *dev, bool autodelete = false); 0038 // Note that this isn't in the constructor, because of KLibFactory::create, 0039 // but it should be called before using the filterbase ! 0040 0041 /** 0042 * Returns the device on which the filter will work. 0043 * @returns the device on which the filter will work 0044 */ 0045 QIODevice *device(); 0046 /** \internal */ 0047 virtual bool init(int mode) = 0; 0048 /** \internal */ 0049 virtual int mode() const = 0; 0050 /** \internal */ 0051 virtual bool terminate(); 0052 /** \internal */ 0053 virtual void reset(); 0054 /** \internal */ 0055 virtual bool readHeader() = 0; 0056 /** \internal */ 0057 virtual bool writeHeader(const QByteArray &filename) = 0; 0058 /** \internal */ 0059 virtual void setOutBuffer(char *data, uint maxlen) = 0; 0060 /** \internal */ 0061 virtual void setInBuffer(const char *data, uint size) = 0; 0062 /** \internal */ 0063 virtual bool inBufferEmpty() const; 0064 /** \internal */ 0065 virtual int inBufferAvailable() const = 0; 0066 /** \internal */ 0067 virtual bool outBufferFull() const; 0068 /** \internal */ 0069 virtual int outBufferAvailable() const = 0; 0070 0071 /** \internal */ 0072 enum Result { 0073 Ok, 0074 End, 0075 Error, 0076 }; 0077 /** \internal */ 0078 virtual Result uncompress() = 0; 0079 /** \internal */ 0080 virtual Result compress(bool finish) = 0; 0081 0082 /** 0083 * \internal 0084 * \since 4.3 0085 */ 0086 enum FilterFlags { 0087 NoHeaders = 0, 0088 WithHeaders = 1, 0089 ZlibHeaders = 2, // only use for gzip compression 0090 }; 0091 /** 0092 * \internal 0093 * \since 4.3 0094 */ 0095 void setFilterFlags(FilterFlags flags); 0096 FilterFlags filterFlags() const; 0097 0098 protected: 0099 /** Virtual hook, used to add new "virtual" functions while maintaining 0100 binary compatibility. Unused in this class. 0101 */ 0102 virtual void virtual_hook(int id, void *data); 0103 0104 private: 0105 Q_DISABLE_COPY(KFilterBase) 0106 KFilterBasePrivate *const d; 0107 }; 0108 0109 #endif