kio
kfilterbase.cpp
Go to the documentation of this file.00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2000 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 version 2 as published by the Free Software Foundation. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Library General Public License for more details. 00012 00013 You should have received a copy of the GNU Library General Public License 00014 along with this library; see the file COPYING.LIB. If not, write to 00015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 Boston, MA 02110-1301, USA. 00017 */ 00018 00019 #include "kfilterbase.h" 00020 #include <klibloader.h> 00021 #include <kmimetype.h> 00022 #include <ktrader.h> 00023 #include <kdebug.h> 00024 00025 KFilterBase::KFilterBase() 00026 : m_dev( 0L ), m_bAutoDel( false ) 00027 { 00028 } 00029 00030 KFilterBase::~KFilterBase() 00031 { 00032 if ( m_bAutoDel ) 00033 delete m_dev; 00034 } 00035 00036 void KFilterBase::setDevice( QIODevice * dev, bool autodelete ) 00037 { 00038 m_dev = dev; 00039 m_bAutoDel = autodelete; 00040 } 00041 00042 KFilterBase * KFilterBase::findFilterByFileName( const QString & fileName ) 00043 { 00044 KMimeType::Ptr mime = KMimeType::findByPath( fileName ); 00045 kdDebug(7005) << "KFilterBase::findFilterByFileName mime=" << mime->name() << endl; 00046 return findFilterByMimeType(mime->name()); 00047 } 00048 00049 KFilterBase * KFilterBase::findFilterByMimeType( const QString & mimeType ) 00050 { 00051 KTrader::OfferList offers = KTrader::self()->query( "KDECompressionFilter", 00052 QString("'") + mimeType + "' in ServiceTypes" ); 00053 KTrader::OfferList::ConstIterator it = offers.begin(); 00054 KTrader::OfferList::ConstIterator end = offers.end(); 00055 00056 kdDebug(7005) << "KFilterBase::findFilterByMimeType(" << mimeType << ") got " << offers.count() << " offers" << endl; 00057 for (; it != end; ++it ) 00058 { 00059 if ((*it)->library().isEmpty()) { continue; } 00060 KLibFactory *factory = KLibLoader::self()->factory((*it)->library().latin1()); 00061 if (!factory) { continue; } 00062 KFilterBase *filter = static_cast<KFilterBase*>( factory->create(0, (*it)->desktopEntryName().latin1() ) ); 00063 if ( filter ) 00064 return filter; 00065 } 00066 00067 if ( mimeType == "application/x-bzip2" || mimeType == "application/x-gzip" ) // #88574 00068 kdWarning(7005) << "KFilterBase::findFilterByMimeType : no filter found for " << mimeType << endl; 00069 00070 return 0L; 00071 } 00072 00073 void KFilterBase::virtual_hook( int, void* ) 00074 { /*BASE::virtual_hook( id, data );*/ } 00075 00076 #include "kfilterbase.moc"