• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDECore

kfilterbase.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2000-2005 David Faure <faure@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kfilterbase.h"
00021 #include <config.h>
00022 
00023 #include <kdebug.h>
00024 #include <QtCore/QIODevice>
00025 #include <kmimetype.h>
00026 #include "kgzipfilter.h"
00027 #ifdef HAVE_BZIP2_SUPPORT
00028 #include "kbzip2filter.h"
00029 #endif
00030 #ifdef HAVE_XZ_SUPPORT
00031 #include "kxzfilter.h"
00032 #endif
00033 
00034 class KFilterBase::Private
00035 {
00036 public:
00037     Private()
00038         : m_flags(WithHeaders) {}
00039     FilterFlags m_flags;
00040 };
00041 
00042 KFilterBase::KFilterBase()
00043     : m_dev( 0L ), m_bAutoDel( false ), d(new Private)
00044 {
00045 }
00046 
00047 KFilterBase::~KFilterBase()
00048 {
00049     if ( m_bAutoDel )
00050         delete m_dev;
00051     delete d;
00052 }
00053 
00054 void KFilterBase::setDevice( QIODevice * dev, bool autodelete )
00055 {
00056     m_dev = dev;
00057     m_bAutoDel = autodelete;
00058 }
00059 
00060 QIODevice * KFilterBase::device()
00061 {
00062     return m_dev;
00063 }
00064 
00065 bool KFilterBase::inBufferEmpty() const
00066 {
00067     return inBufferAvailable() == 0;
00068 }
00069 
00070 bool KFilterBase::outBufferFull() const
00071 {
00072     return outBufferAvailable() == 0;
00073 }
00074 
00075 KFilterBase * KFilterBase::findFilterByFileName( const QString & fileName )
00076 {
00077     if ( fileName.endsWith( ".gz", Qt::CaseInsensitive ) )
00078     {
00079         return new KGzipFilter;
00080     }
00081 #ifdef HAVE_BZIP2_SUPPORT
00082     if ( fileName.endsWith( ".bz2", Qt::CaseInsensitive ) )
00083     {
00084         return new KBzip2Filter;
00085     }
00086 #endif
00087 #ifdef HAVE_XZ_SUPPORT
00088     if ( fileName.endsWith( ".lzma", Qt::CaseInsensitive ) || fileName.endsWith( ".xz", Qt::CaseInsensitive ) )
00089     {
00090         return new KXzFilter;
00091     }
00092 #endif
00093     else
00094     {
00095         // not a warning, since this is called often with other mimetypes (see #88574)...
00096         // maybe we can avoid that though?
00097         kDebug(7005) << "KFilterBase::findFilterByFileName : no filter found for " << fileName;
00098     }
00099 
00100     return 0;
00101 }
00102 
00103 KFilterBase * KFilterBase::findFilterByMimeType( const QString & mimeType )
00104 {
00105     if (mimeType == QLatin1String("application/x-gzip")) {
00106         return new KGzipFilter;
00107     }
00108 #ifdef HAVE_BZIP2_SUPPORT
00109     if (mimeType == QLatin1String("application/x-bzip")
00110         || mimeType == QLatin1String("application/x-bzip2") // old name, kept for compatibility
00111        ) {
00112         return new KBzip2Filter;
00113     }
00114 #endif
00115 #ifdef HAVE_XZ_SUPPORT
00116     if ( mimeType == QLatin1String( "application/x-lzma" ) // legacy name, still used
00117         || mimeType == QLatin1String( "application/x-xz" ) // current naming
00118        ) {
00119         return new KXzFilter;
00120     }
00121 #endif
00122     const KMimeType::Ptr mime = KMimeType::mimeType(mimeType);
00123     if (mime) {
00124         if (mime->is("application/x-gzip")) {
00125             return new KGzipFilter;
00126         }
00127 #ifdef HAVE_BZIP2_SUPPORT
00128         if (mime->is("application/x-bzip")) {
00129             return new KBzip2Filter;
00130         }
00131 #endif
00132 #ifdef HAVE_XZ_SUPPORT
00133         if (mime->is("application/x-lzma")) {
00134             return new KXzFilter;
00135         }
00136 
00137         if (mime->is("application/x-xz")) {
00138             return new KXzFilter;
00139         }
00140 #endif
00141     }
00142 
00143     // not a warning, since this is called often with other mimetypes (see #88574)...
00144     // maybe we can avoid that though?
00145     kDebug(7005) << "no filter found for" << mimeType;
00146     return 0;
00147 }
00148 
00149 void KFilterBase::terminate()
00150 {
00151 }
00152 
00153 void KFilterBase::reset()
00154 {
00155 }
00156 
00157 void KFilterBase::setFilterFlags(FilterFlags flags)
00158 {
00159     d->m_flags = flags;
00160 }
00161 
00162 KFilterBase::FilterFlags KFilterBase::filterFlags() const
00163 {
00164     return d->m_flags;
00165 }
00166 
00167 void KFilterBase::virtual_hook( int, void* )
00168 { /*BASE::virtual_hook( id, data );*/ }

KDECore

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal