1/* This file is part of the KDE libraries
2 Copyright (C) 2000 David Faure <faure@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#ifndef __kfilterbase__h
21#define __kfilterbase__h
22
23#include <karchive_export.h>
24
25#include <QtCore/QObject>
26#include <QtCore/QString>
27
28class QIODevice;
29
30/**
31 * This is the base class for compression filters
32 * such as gzip and bzip2. It's pretty much internal.
33 * Don't use directly, use KFilterDev instead.
34 * @internal
35 */
36class KARCHIVE_EXPORT KFilterBase
37{
38public:
39 KFilterBase();
40 virtual ~KFilterBase();
41
42 /**
43 * Sets the device on which the filter will work
44 * @param dev the device on which the filter will work
45 * @param autodelete if true, @p dev is deleted when the filter is deleted
46 */
47 void setDevice( QIODevice * dev, bool autodelete = false );
48 // Note that this isn't in the constructor, because of KLibFactory::create,
49 // but it should be called before using the filterbase !
50
51 /**
52 * Returns the device on which the filter will work.
53 * @returns the device on which the filter will work
54 */
55 QIODevice * device();
56 /** \internal */
57 virtual void init( int mode ) = 0; // KDE5 TODO: return a bool
58 /** \internal */
59 virtual int mode() const = 0;
60 /** \internal */
61 virtual void terminate();
62 /** \internal */
63 virtual void reset();
64 /** \internal */
65 virtual bool readHeader() = 0;
66 /** \internal */
67 virtual bool writeHeader( const QByteArray & filename ) = 0;
68 /** \internal */
69 virtual void setOutBuffer( char * data, uint maxlen ) = 0;
70 /** \internal */
71 virtual void setInBuffer( const char * data, uint size ) = 0;
72 /** \internal */
73 virtual bool inBufferEmpty() const;
74 /** \internal */
75 virtual int inBufferAvailable() const = 0;
76 /** \internal */
77 virtual bool outBufferFull() const;
78 /** \internal */
79 virtual int outBufferAvailable() const = 0;
80
81 /** \internal */
82 enum Result { Ok, End, Error };
83 /** \internal */
84 virtual Result uncompress() = 0;
85 /** \internal */
86 virtual Result compress( bool finish ) = 0;
87
88 /**
89 * \internal
90 * \since 4.3
91 */
92 enum FilterFlags {
93 NoHeaders = 0,
94 WithHeaders = 1
95 };
96 /**
97 * \internal
98 * \since 4.3
99 */
100 void setFilterFlags(FilterFlags flags);
101 FilterFlags filterFlags() const;
102
103 /**
104 * Call this to create the appropriate filter for the file
105 * named @p fileName.
106 * @param fileName the name of the file to filter
107 * @return the filter for the @p fileName, or 0 if not found
108 */
109 static KFilterBase * findFilterByFileName( const QString & fileName );
110
111 /**
112 * Call this to create the appropriate filter for the mimetype
113 * @p mimeType. For instance application/x-gzip.
114 * @param mimeType the mime type of the file to filter
115 * @return the filter for the @p mimeType, or 0 if not found
116 */
117 static KFilterBase * findFilterByMimeType( const QString & mimeType );
118
119protected: // TODO KDE5: move to d pointer
120 QIODevice * m_dev;
121 bool m_bAutoDel;
122protected:
123 /** Virtual hook, used to add new "virtual" functions while maintaining
124 binary compatibility. Unused in this class.
125 */
126 virtual void virtual_hook( int id, void* data );
127private:
128 Q_DISABLE_COPY( KFilterBase )
129 class Private;
130 Private * const d;
131};
132
133#endif
134