~ubuntu-branches/debian/jessie/stellarium/jessie

« back to all changes in this revision

Viewing changes to src/external/kfilter/kfilterdev.h

  • Committer: Bazaar Package Importer
  • Author(s): Cédric Delfosse
  • Date: 2009-03-13 20:07:22 UTC
  • mfrom: (1.1.8 upstream)
  • mto: (11.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: james.westby@ubuntu.com-20090313200722-gbgujsmzsa8a02ty
Import upstream version 0.10.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 version 2 as published by the Free Software Foundation.
 
7
 
 
8
   This library is distributed in the hope that it will be useful,
 
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
   Library General Public License for more details.
 
12
 
 
13
   You should have received a copy of the GNU Library General Public License
 
14
   along with this library; see the file COPYING.LIB.  If not, write to
 
15
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
16
   Boston, MA 02110-1301, USA.
 
17
*/
 
18
#ifndef __kfilterdev_h
 
19
#define __kfilterdev_h
 
20
 
 
21
#include <QtCore/QIODevice>
 
22
#include <QtCore/QString>
 
23
 
 
24
class QFile;
 
25
class KFilterBase;
 
26
 
 
27
/**
 
28
 * A class for reading and writing compressed data onto a device
 
29
 * (e.g. file, but other usages are possible, like a buffer or a socket).
 
30
 *
 
31
 * To simply read/write compressed files, see deviceForFile.
 
32
 *
 
33
 * @author David Faure <faure@kde.org>
 
34
 */
 
35
class KFilterDev : public QIODevice
 
36
{
 
37
public:
 
38
    /**
 
39
     * Destructs the KFilterDev.
 
40
     * Calls close() if the filter device is still open.
 
41
     */
 
42
    virtual ~KFilterDev();
 
43
 
 
44
    /**
 
45
     * Open for reading or writing.
 
46
     * If the KFilterBase's device is not opened, it will be opened.
 
47
     */
 
48
    virtual bool open( QIODevice::OpenMode mode );
 
49
    /**
 
50
     * Close after reading or writing.
 
51
     * If the KFilterBase's device was opened by open(), it will be closed.
 
52
     */
 
53
    virtual void close();
 
54
 
 
55
    /**
 
56
     * For writing gzip compressed files only:
 
57
     * set the name of the original file, to be used in the gzip header.
 
58
     * @param fileName the name of the original file
 
59
     */
 
60
    void setOrigFileName( const QByteArray & fileName );
 
61
 
 
62
    /**
 
63
     * Call this let this device skip the gzip headers when reading/writing.
 
64
     * This way KFilterDev (with gzip filter) can be used as a direct wrapper
 
65
     * around zlib - this is used by KZip.
 
66
     */
 
67
    void setSkipHeaders();
 
68
 
 
69
    /**
 
70
     * That one can be quite slow, when going back. Use with care.
 
71
     */
 
72
    virtual bool seek( qint64 );
 
73
 
 
74
    virtual bool atEnd() const;
 
75
 
 
76
    /// Reimplemented to return true. KFilterDev is a sequential QIODevice.
 
77
    /// Well, not really, since it supports seeking and KZip uses that.
 
78
    //virtual bool isSequential() const { return true; }
 
79
 
 
80
public:
 
81
 
 
82
 
 
83
    // KDE4 TODO: turn those static methods into constructors
 
84
 
 
85
    /**
 
86
     * Creates an i/o device that is able to read from @p fileName,
 
87
     * whether it's compressed or not. Available compression filters
 
88
     * (gzip/bzip2 etc.) will automatically be used.
 
89
     *
 
90
     * The compression filter to be used is determined from the @p fileName
 
91
     * if @p mimetype is empty. Pass "application/x-gzip" or "application/x-bzip"
 
92
     * to force the corresponding decompression filter, if available.
 
93
     *
 
94
     * Warning: application/x-bzip may not be available.
 
95
     * In that case a QFile opened on the compressed data will be returned !
 
96
     * Use KFilterBase::findFilterByMimeType and code similar to what
 
97
     * deviceForFile is doing, to better control what's happening.
 
98
     *
 
99
     * The returned QIODevice has to be deleted after using.
 
100
     *
 
101
     * @param fileName the name of the file to filter
 
102
     * @param mimetype the mime type of the file to filter, or QString() if unknown
 
103
     * @param forceFilter if true, the function will either find a compression filter, or return 0.
 
104
     *                    If false, it will always return a QIODevice. If no
 
105
     *                    filter is available it will return a simple QFile.
 
106
     *                    This can be useful if the file is usable without a filter.
 
107
     * @return if a filter has been found, the QIODevice for the filter. If the
 
108
     *         filter does not exist, the return value depends on @p forceFilter.
 
109
     *         The returned QIODevice has to be deleted after using.
 
110
     */
 
111
    static QIODevice * deviceForFile( const QString & fileName, const QString & mimetype = QString(),
 
112
                                      bool forceFilter = false );
 
113
 
 
114
    /**
 
115
     * Creates an i/o device that is able to read from the QIODevice @p inDevice,
 
116
     * whether the data is compressed or not. Available compression filters
 
117
     * (gzip/bzip2 etc.) will automatically be used.
 
118
     *
 
119
     * The compression filter to be used is determined @p mimetype .
 
120
     * Pass "application/x-gzip" or "application/x-bzip"
 
121
     * to use the corresponding decompression filter.
 
122
     *
 
123
     * Warning: application/x-bzip may not be available.
 
124
     * In that case 0 will be returned !
 
125
     *
 
126
     * The returned QIODevice has to be deleted after using.
 
127
     * @param inDevice input device. Won't be deleted if @p autoDeleteInDevice = false
 
128
     * @param mimetype the mime type for the filter
 
129
     * @param autoDeleteInDevice if true, @p inDevice will be deleted automatically
 
130
     * @return a QIODevice that filters the original stream. Must be deleted after
 
131
     *         using
 
132
     */
 
133
    static QIODevice * device( QIODevice* inDevice, const QString & mimetype, bool autoDeleteInDevice = true );
 
134
 
 
135
protected:
 
136
    virtual qint64 readData( char *data, qint64 maxlen );
 
137
    virtual qint64 writeData( const char *data, qint64 len );
 
138
 
 
139
private:
 
140
    /**
 
141
     * Constructs a KFilterDev for a given filter (e.g. gzip, bzip2 etc.).
 
142
     * @param filter the KFilterBase to use
 
143
     * @param autoDeleteFilterBase when true this object will become the
 
144
     * owner of @p filter.
 
145
     */
 
146
    explicit KFilterDev( KFilterBase * filter, bool autoDeleteFilterBase = false );
 
147
private:
 
148
    class Private;
 
149
    Private* const d;
 
150
};
 
151
 
 
152
 
 
153
#endif