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