ark
archive.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "archive.h"
00026 #include "archivefactory.h"
00027
00028 #include <QFile>
00029
00030 #include <KDebug>
00031 #include <KMimeType>
00032 #include <KMimeTypeTrader>
00033 #include <KServiceTypeTrader>
00034 #include <KLibLoader>
00035
00036 static bool comparePlugins( const KService::Ptr &p1, const KService::Ptr &p2 )
00037 {
00038 return ( p1->property( "X-KDE-Priority" ).toInt() ) > ( p2->property( "X-KDE-Priority" ).toInt() );
00039 }
00040
00041 namespace Kerfuffle
00042 {
00043 Archive *factory( const QString & filename, const QString & requestedMimeType )
00044 {
00045 kDebug( 1601 ) ;
00046 qRegisterMetaType<ArchiveEntry>( "ArchiveEntry" );
00047 QString mimeType = requestedMimeType.isEmpty()? KMimeType::findByPath( filename )->name() : requestedMimeType;
00048 KService::List offers = KMimeTypeTrader::self()->query( mimeType, "Kerfuffle/Plugin", "(exist Library)" );
00049
00050 qSort( offers.begin(), offers.end(), comparePlugins );
00051
00052 if ( !offers.isEmpty() )
00053 {
00054 QString libraryName = offers[ 0 ]->library();
00055 KLibrary *lib = KLibLoader::self()->library( QFile::encodeName( libraryName ), QLibrary::ExportExternalSymbolsHint );
00056
00057 kDebug( 1601 ) << "Loading library " << libraryName ;
00058 if ( lib )
00059 {
00060 ArchiveFactory *( *pluginFactory )() = ( ArchiveFactory *( * )() )lib->resolveFunction( "pluginFactory" );
00061 if ( pluginFactory )
00062 {
00063 ArchiveFactory *factory = pluginFactory();
00064 Archive *arch = factory->createArchive( filename, 0 );
00065 delete factory;
00066 return arch;
00067 }
00068 }
00069 kDebug( 1601 ) << "Couldn't load library " << libraryName ;
00070 }
00071 kDebug( 1601 ) << "Couldn't find a library capable of handling " << filename ;
00072 return 0;
00073 }
00074
00075 QStringList supportedMimeTypes()
00076 {
00077 QStringList supported;
00078 KService::List offers = KServiceTypeTrader::self()->query( "Kerfuffle/Plugin", "(exist Library)" );
00079
00080 foreach( KService::Ptr service, offers )
00081 {
00082 foreach( const QString& mimeType, service->serviceTypes() )
00083 {
00084 if ( !mimeType.contains( "Kerfuffle" ) )
00085 {
00086 supported << mimeType;
00087 }
00088 }
00089 }
00090 return supported;
00091 }
00092
00093 QStringList supportedWriteMimeTypes()
00094 {
00095 QStringList supported;
00096 KService::List offers = KServiceTypeTrader::self()->query( "Kerfuffle/Plugin", "(exist Library) and ([X-KDE-Kerfuffle-ReadWrite] == true)" );
00097
00098 foreach( KService::Ptr service, offers )
00099 {
00100 foreach( const QString& mimeType, service->serviceTypes() )
00101 {
00102 if ( !mimeType.contains( "Kerfuffle" ) )
00103 {
00104 supported << mimeType;
00105 }
00106 }
00107 }
00108 kDebug( 1601 ) << "Returning" << supported;
00109 return supported;
00110 }
00111 }