KArchive

kfilterdev.h
1 /* This file is part of the KDE libraries
2  SPDX-FileCopyrightText: 2000 David Faure <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 #ifndef __kfilterdev_h
7 #define __kfilterdev_h
8 
9 #include <karchive_export.h>
10 #include <kcompressiondevice.h>
11 
12 #include <QString>
13 
14 #if KARCHIVE_ENABLE_DEPRECATED_SINCE(5, 85)
15 
16 class QFile;
17 class KFilterBase;
18 
19 /**
20  * @class KFilterDev kfilterdev.h KFilterDev
21  *
22  * A class for reading and writing compressed data onto a device
23  * (e.g. file, but other usages are possible, like a buffer or a socket).
24  *
25  * To simply read/write compressed files, see deviceForFile.
26  *
27  * KFilterDev adds MIME type support to KCompressionDevice, and also
28  * provides compatibility methods for KDE 4 code.
29  *
30  * @author David Faure <[email protected]>
31  * @deprecated Since 5.85, use KCompressionDevice directly
32  */
33 class KARCHIVE_EXPORT KFilterDev : public KCompressionDevice
34 {
35  Q_OBJECT
36 public:
37  /**
38  * Constructs a KFilterDev for a given FileName.
39  * @param fileName the name of the file to filter.
40  * @since 5.0
41  * @deprecated Since 5.85, use KCompressionDevice(const QString &)
42  */
43  KFilterDev(const QString &fileName);
44 
45  /**
46  * Returns the compression type for the given mimetype, if possible. Otherwise returns None.
47  * This handles simple cases like application/gzip, but also application/x-compressed-tar, and inheritance.
48  * @deprecated Since 5.85, use KCompressionDevice::compressionTypeForMimeType(const QString &)
49  */
50  KARCHIVE_DEPRECATED_VERSION(5, 85, "Use KCompressionDevice::compressionTypeForMimeType(const QString &)")
51  static CompressionType compressionTypeForMimeType(const QString &mimetype);
52 
53 #if KARCHIVE_ENABLE_DEPRECATED_SINCE(5, 0)
54  /**
55  * @deprecated Since 5.0, use the constructor instead (if mimetype is empty), or KCompressionDevice (if
56  * the mimetype is known).
57  *
58  * Use:
59  * KFilterDev dev(fileName)
60  * instead of:
61  * QIODevice * dev = KFilterDev::deviceForFile(fileName);
62  *
63  * If the mimetype was specified explicitly, use:
64  * KCompressionDevice dev(fileName, KCompressionDevice::GZip);
65  * instead of:
66  * QIODevice * dev = KFilterDev::deviceForFile(fileName, "application/gzip");
67  *
68  * Creates an i/o device that is able to read from @p fileName,
69  * whether it's compressed or not. Available compression filters
70  * (gzip/bzip2 etc.) will automatically be used.
71  *
72  * The compression filter to be used is determined from the @p fileName
73  * if @p mimetype is empty. Pass "application/gzip" or "application/x-bzip"
74  * to force the corresponding decompression filter, if available.
75  *
76  * Warning: application/x-bzip may not be available.
77  * In that case a QFile opened on the compressed data will be returned !
78  * Use KFilterBase::findFilterByMimeType and code similar to what
79  * deviceForFile is doing, to better control what's happening.
80  *
81  * The returned QIODevice has to be deleted after using.
82  *
83  * @param fileName the name of the file to filter
84  * @param mimetype the mime type of the file to filter, or QString() if unknown
85  * @param forceFilter if true, the function will either find a compression filter, or return 0.
86  * If false, it will always return a QIODevice. If no
87  * filter is available it will return a simple QFile.
88  * This can be useful if the file is usable without a filter.
89  * @return if a filter has been found, the KCompressionDevice for the filter. If the
90  * filter does not exist, the return value depends on @p forceFilter.
91  * The returned KCompressionDevice has to be deleted after using.
92  */
93  KARCHIVE_DEPRECATED_VERSION(5, 0, "See API docs")
94  static KCompressionDevice *deviceForFile(const QString &fileName, const QString &mimetype = QString(), bool forceFilter = false)
95  {
96  KCompressionDevice *device;
97  if (mimetype.isEmpty()) {
98  device = new KFilterDev(fileName);
99  } else {
100  device = new KCompressionDevice(fileName, compressionTypeForMimeType(mimetype));
101  }
102  if (device->compressionType() == KCompressionDevice::None && forceFilter) {
103  delete device;
104  return nullptr;
105  } else {
106  return device;
107  }
108  }
109 #endif
110 
111 #if KARCHIVE_ENABLE_DEPRECATED_SINCE(5, 0)
112  /**
113  * @deprecated Since 5.0, use KCompressionDevice
114  *
115  * Use:
116  * KCompressionDevice::CompressionType type = KFilterDev::compressionTypeForMimeType(mimeType);
117  * KCompressionDevice flt(&file, false, type);
118  * instead of:
119  * QIODevice *flt = KFilterDev::device(&file, mimeType, false);
120  *
121  * Creates an i/o device that is able to read from the QIODevice @p inDevice,
122  * whether the data is compressed or not. Available compression filters
123  * (gzip/bzip2 etc.) will automatically be used.
124  *
125  * The compression filter to be used is determined @p mimetype .
126  * Pass "application/gzip" or "application/x-bzip"
127  * to use the corresponding decompression filter.
128  *
129  * Warning: application/x-bzip may not be available.
130  * In that case 0 will be returned !
131  *
132  * The returned QIODevice has to be deleted after using.
133  * @param inDevice input device. Won't be deleted if @p autoDeleteInDevice = false
134  * @param mimetype the mime type for the filter
135  * @param autoDeleteInDevice if true, @p inDevice will be deleted automatically
136  * @return a KCompressionDevice that filters the original stream. Must be deleted after using
137  */
138  KARCHIVE_DEPRECATED_VERSION(5, 0, "See API docs")
139  static KCompressionDevice *device(QIODevice *inDevice, const QString &mimetype, bool autoDeleteInDevice = true)
140  {
141  if (inDevice == nullptr) {
142  return nullptr;
143  }
145  KCompressionDevice *device = new KCompressionDevice(inDevice, autoDeleteInDevice, type);
146  return device;
147  }
148 #endif
149 };
150 
151 #endif // KARCHIVE_ENABLE_DEPRECATED_SINCE(5, 85)
152 
153 #endif
static CompressionType compressionTypeForMimeType(const QString &mimetype)
Returns the compression type for the given MIME type, if possible.
KCompressionDevice(QIODevice *inputDevice, bool autoDeleteInputDevice, CompressionType type)
Constructs a KCompressionDevice for a given CompressionType (e.g.
CompressionType compressionType() const
The compression actually used by this device.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue Aug 16 2022 04:03:12 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.