TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

kfilterdev.h 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /* This file is part of the KDE libraries
  2. Copyright (C) 2000 David Faure <faure@kde.org>
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License version 2 as published by the Free Software Foundation.
  6. This library is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9. Library General Public License for more details.
  10. You should have received a copy of the GNU Library General Public License
  11. along with this library; see the file COPYING.LIB. If not, write to
  12. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  13. Boston, MA 02110-1301, USA.
  14. */
  15. #ifndef __kfilterdev_h
  16. #define __kfilterdev_h
  17. #include <tqiodevice.h>
  18. #include <tqstring.h>
  19. #include <kdelibs_export.h>
  20. class TQFile;
  21. class KFilterBase;
  22. /**
  23. * A class for reading and writing compressed data onto a device
  24. * (e.g. file, but other usages are possible, like a buffer or a socket).
  25. *
  26. * To simply read/write compressed files, see deviceForFile.
  27. *
  28. * @author David Faure <faure@kde.org>
  29. */
  30. class KIO_EXPORT KFilterDev : public TQIODevice
  31. {
  32. public:
  33. /**
  34. * Constructs a KFilterDev for a given filter (e.g. gzip, bzip2 etc.).
  35. * @param filter the KFilterBase to use
  36. * @param autoDeleteFilterBase when true this object will become the
  37. * owner of @p filter.
  38. */
  39. KFilterDev( KFilterBase * filter, bool autoDeleteFilterBase = false );
  40. /**
  41. * Destructs the KFilterDev.
  42. * Calls close() if the filter device is still open.
  43. */
  44. virtual ~KFilterDev();
  45. /**
  46. * Open for reading or writing.
  47. * If the KFilterBase's device is not opened, it will be opened.
  48. */
  49. virtual bool open( OpenMode mode );
  50. /**
  51. * Close after reading or writing.
  52. * If the KFilterBase's device was opened by open(), it will be closed.
  53. */
  54. virtual void close();
  55. virtual void flush();
  56. /**
  57. * For writing gzip compressed files only:
  58. * set the name of the original file, to be used in the gzip header.
  59. * @param fileName the name of the original file
  60. */
  61. void setOrigFileName( const TQCString & fileName );
  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. * @since 3.1
  67. */
  68. void setSkipHeaders();
  69. // Not implemented
  70. #ifdef USE_QT4
  71. virtual qint64 size() const;
  72. #else // USE_QT4
  73. virtual TQIODevice::Offset size() const;
  74. #endif // USE_QT4
  75. virtual TQIODevice::Offset at() const;
  76. /**
  77. * That one can be quite slow, when going back. Use with care.
  78. */
  79. virtual bool at( TQIODevice::Offset );
  80. virtual bool atEnd() const;
  81. virtual TQT_TQIO_LONG tqreadBlock( char *data, TQT_TQIO_ULONG maxlen );
  82. virtual TQT_TQIO_LONG tqwriteBlock( const char *data, TQT_TQIO_ULONG len );
  83. //int readLine( char *data, uint maxlen );
  84. virtual int getch();
  85. virtual int putch( int );
  86. virtual int ungetch( int );
  87. #ifdef KDE_NO_COMPAT
  88. private:
  89. #endif
  90. /**
  91. * Call this to create the appropriate filter device for @p base
  92. * working on @p file . The returned TQIODevice has to be deleted
  93. * after using.
  94. * @deprecated. Use deviceForFile instead.
  95. * To be removed in KDE 3.0
  96. */
  97. static TQIODevice* createFilterDevice(KFilterBase* base, TQFile* file) KDE_DEPRECATED;
  98. public:
  99. /**
  100. * Creates an i/o device that is able to read from @p fileName,
  101. * whether it's compressed or not. Available compression filters
  102. * (gzip/bzip2 etc.) will automatically be used.
  103. *
  104. * The compression filter to be used is determined from the @p fileName
  105. * if @p mimetype is empty. Pass "application/x-gzip" or "application/x-bzip2"
  106. * to force the corresponding decompression filter, if available.
  107. *
  108. * Warning: application/x-bzip2 may not be available.
  109. * In that case a TQFile opened on the compressed data will be returned !
  110. * Use KFilterBase::findFilterByMimeType and code similar to what
  111. * deviceForFile is doing, to better control what's happening.
  112. *
  113. * The returned TQIODevice has to be deleted after using.
  114. *
  115. * @param fileName the name of the file to filter
  116. * @param mimetype the mime type of the file to filter, or TQString::null if unknown
  117. * @param forceFilter if true, the function will either find a compression filter, or return 0.
  118. * If false, it will always return a TQIODevice. If no
  119. * filter is available it will return a simple TQFile.
  120. * This can be useful if the file is usable without a filter.
  121. * @return if a filter has been found, the TQIODevice for the filter. If the
  122. * filter does not exist, the return value depends on @p forceFilter.
  123. * The returned TQIODevice has to be deleted after using.
  124. */
  125. static TQIODevice * deviceForFile( const TQString & fileName, const TQString & mimetype = TQString::null,
  126. bool forceFilter = false );
  127. /**
  128. * Creates an i/o device that is able to read from the TQIODevice @p inDevice,
  129. * whether the data is compressed or not. Available compression filters
  130. * (gzip/bzip2 etc.) will automatically be used.
  131. *
  132. * The compression filter to be used is determined @p mimetype .
  133. * Pass "application/x-gzip" or "application/x-bzip2"
  134. * to use the corresponding decompression filter.
  135. *
  136. * Warning: application/x-bzip2 may not be available.
  137. * In that case 0 will be returned !
  138. *
  139. * The returned TQIODevice has to be deleted after using.
  140. * @param inDevice input device, becomes owned by this device! Automatically deleted!
  141. * @param mimetype the mime type for the filter
  142. * @return a TQIODevice that filters the original stream. Must be deleted after
  143. * using
  144. */
  145. static TQIODevice * device( TQIODevice* inDevice, const TQString & mimetype);
  146. // BIC: merge with device() method below, using default value for autoDeleteInDevice
  147. /**
  148. * Creates an i/o device that is able to read from the TQIODevice @p inDevice,
  149. * whether the data is compressed or not. Available compression filters
  150. * (gzip/bzip2 etc.) will automatically be used.
  151. *
  152. * The compression filter to be used is determined @p mimetype .
  153. * Pass "application/x-gzip" or "application/x-bzip2"
  154. * to use the corresponding decompression filter.
  155. *
  156. * Warning: application/x-bzip2 may not be available.
  157. * In that case 0 will be returned !
  158. *
  159. * The returned TQIODevice has to be deleted after using.
  160. * @param inDevice input device. Won't be deleted if @p autoDeleteInDevice = false
  161. * @param mimetype the mime type for the filter
  162. * @param autoDeleteInDevice if true, @p inDevice will be deleted automatically
  163. * @return a TQIODevice that filters the original stream. Must be deleted after
  164. * using
  165. * @since 3.1
  166. */
  167. static TQIODevice * device( TQIODevice* inDevice, const TQString & mimetype, bool autoDeleteInDevice );
  168. private:
  169. KFilterBase *filter;
  170. class KFilterDevPrivate;
  171. KFilterDevPrivate * d;
  172. };
  173. #endif