• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.8 API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • kdecore
  • compression
kfilterbase.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2000-2005 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 #include "kfilterbase.h"
21 #include <config-compression.h>
22 
23 #include <QDebug>
24 #include <QtCore/QIODevice>
25 #include <kmimetype.h>
26 #include "kgzipfilter.h"
27 #if HAVE_BZIP2_SUPPORT
28 #include "kbzip2filter.h"
29 #endif
30 #if HAVE_XZ_SUPPORT
31 #include "kxzfilter.h"
32 #endif
33 
34 class KFilterBase::Private
35 {
36 public:
37  Private()
38  : m_flags(WithHeaders) {}
39  FilterFlags m_flags;
40 };
41 
42 KFilterBase::KFilterBase()
43  : m_dev( 0L ), m_bAutoDel( false ), d(new Private)
44 {
45 }
46 
47 KFilterBase::~KFilterBase()
48 {
49  if ( m_bAutoDel )
50  delete m_dev;
51  delete d;
52 }
53 
54 void KFilterBase::setDevice( QIODevice * dev, bool autodelete )
55 {
56  m_dev = dev;
57  m_bAutoDel = autodelete;
58 }
59 
60 QIODevice * KFilterBase::device()
61 {
62  return m_dev;
63 }
64 
65 bool KFilterBase::inBufferEmpty() const
66 {
67  return inBufferAvailable() == 0;
68 }
69 
70 bool KFilterBase::outBufferFull() const
71 {
72  return outBufferAvailable() == 0;
73 }
74 
75 KFilterBase * KFilterBase::findFilterByFileName( const QString & fileName )
76 {
77  if ( fileName.endsWith( QLatin1String(".gz"), Qt::CaseInsensitive ) )
78  {
79  return new KGzipFilter;
80  }
81 #if HAVE_BZIP2_SUPPORT
82  if ( fileName.endsWith( QLatin1String(".bz2"), Qt::CaseInsensitive ) )
83  {
84  return new KBzip2Filter;
85  }
86 #endif
87 #if HAVE_XZ_SUPPORT
88  if ( fileName.endsWith( QLatin1String(".lzma"), Qt::CaseInsensitive ) || fileName.endsWith( QLatin1String(".xz"), Qt::CaseInsensitive ) )
89  {
90  return new KXzFilter;
91  }
92 #endif
93  else
94  {
95  // not a warning, since this is called often with other mimetypes (see #88574)...
96  // maybe we can avoid that though?
97  //qDebug() << "KFilterBase::findFilterByFileName : no filter found for " << fileName;
98  }
99 
100  return 0;
101 }
102 
103 KFilterBase * KFilterBase::findFilterByMimeType( const QString & mimeType )
104 {
105  if (mimeType == QLatin1String("application/x-gzip")) {
106  return new KGzipFilter;
107  }
108 #if HAVE_BZIP2_SUPPORT
109  if (mimeType == QLatin1String("application/x-bzip")
110  || mimeType == QLatin1String("application/x-bzip2") // old name, kept for compatibility
111  ) {
112  return new KBzip2Filter;
113  }
114 #endif
115 #if HAVE_XZ_SUPPORT
116  if ( mimeType == QLatin1String( "application/x-lzma" ) // legacy name, still used
117  || mimeType == QLatin1String( "application/x-xz" ) // current naming
118  ) {
119  return new KXzFilter;
120  }
121 #endif
122  const KMimeType::Ptr mime = KMimeType::mimeType(mimeType);
123  if (mime) {
124  if (mime->is(QString::fromLatin1("application/x-gzip"))) {
125  return new KGzipFilter;
126  }
127 #if HAVE_BZIP2_SUPPORT
128  if (mime->is(QString::fromLatin1("application/x-bzip"))) {
129  return new KBzip2Filter;
130  }
131 #endif
132 #if HAVE_XZ_SUPPORT
133  if (mime->is(QString::fromLatin1("application/x-lzma"))) {
134  return new KXzFilter;
135  }
136 
137  if (mime->is(QString::fromLatin1("application/x-xz"))) {
138  return new KXzFilter;
139  }
140 #endif
141  }
142 
143  // not a warning, since this is called often with other mimetypes (see #88574)...
144  // maybe we can avoid that though?
145  //qDebug() << "no filter found for" << mimeType;
146  return 0;
147 }
148 
149 void KFilterBase::terminate()
150 {
151 }
152 
153 void KFilterBase::reset()
154 {
155 }
156 
157 void KFilterBase::setFilterFlags(FilterFlags flags)
158 {
159  d->m_flags = flags;
160 }
161 
162 KFilterBase::FilterFlags KFilterBase::filterFlags() const
163 {
164  return d->m_flags;
165 }
166 
167 void KFilterBase::virtual_hook( int, void* )
168 { /*BASE::virtual_hook( id, data );*/ }
KSharedPtr< KMimeType >
KFilterBase::outBufferFull
virtual bool outBufferFull() const
Definition: kfilterbase.cpp:70
kmimetype.h
KFilterBase::virtual_hook
virtual void virtual_hook(int id, void *data)
Virtual hook, used to add new &quot;virtual&quot; functions while maintaining binary compatibility.
Definition: kfilterbase.cpp:167
KFilterBase::reset
virtual void reset()
Definition: kfilterbase.cpp:153
QString
kgzipfilter.h
KFilterBase::filterFlags
FilterFlags filterFlags() const
Definition: kfilterbase.cpp:162
kbzip2filter.h
KGzipFilter
Internal class used by KFilterDev.
Definition: kgzipfilter.h:32
KFilterBase::inBufferEmpty
virtual bool inBufferEmpty() const
Definition: kfilterbase.cpp:65
KFilterBase::device
QIODevice * device()
Returns the device on which the filter will work.
Definition: kfilterbase.cpp:60
kfilterbase.h
kxzfilter.h
KFilterBase::inBufferAvailable
virtual int inBufferAvailable() const =0
KFilterBase::~KFilterBase
virtual ~KFilterBase()
Definition: kfilterbase.cpp:47
KFilterBase
This is the base class for compression filters such as gzip and bzip2.
Definition: kfilterbase.h:36
KFilterBase::m_bAutoDel
bool m_bAutoDel
Definition: kfilterbase.h:121
KFilterBase::terminate
virtual void terminate()
Definition: kfilterbase.cpp:149
KFilterBase::findFilterByFileName
static KFilterBase * findFilterByFileName(const QString &fileName)
Call this to create the appropriate filter for the file named fileName.
Definition: kfilterbase.cpp:75
KFilterBase::setDevice
void setDevice(QIODevice *dev, bool autodelete=false)
Sets the device on which the filter will work.
Definition: kfilterbase.cpp:54
KFilterBase::setFilterFlags
void setFilterFlags(FilterFlags flags)
Definition: kfilterbase.cpp:157
KFilterBase::m_dev
QIODevice * m_dev
Definition: kfilterbase.h:120
KMimeType::mimeType
static Ptr mimeType(const QString &name, FindByNameOption options=ResolveAliases)
Retrieve a pointer to the mime type name.
Definition: kmimetype.cpp:58
KFilterBase::KFilterBase
KFilterBase()
Definition: kfilterbase.cpp:42
KFilterBase::WithHeaders
Definition: kfilterbase.h:94
KFilterBase::outBufferAvailable
virtual int outBufferAvailable() const =0
QIODevice
KFilterBase::findFilterByMimeType
static KFilterBase * findFilterByMimeType(const QString &mimeType)
Call this to create the appropriate filter for the mimetype mimeType.
Definition: kfilterbase.cpp:103
KFilterBase::FilterFlags
FilterFlags
Definition: kfilterbase.h:92
KMimeType::is
bool is(const QString &mimeTypeName) const
Do not use name()==&quot;somename&quot; anymore, to check for a given mimetype.
Definition: kmimetype.cpp:556
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Apr 1 2020 06:26:11 by doxygen 1.8.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.8 API Reference

Skip menu "kdelibs-4.14.8 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal