• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • kdeutils
  • Sitemap
  • Contact Us
 

ark

archive.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2007 Henrique Pinto <henrique.pinto@kdemail.net>
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  *
00014  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00015  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00016  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00017  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00018  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ( INCLUDING, BUT
00019  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00020  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
00021  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00022  * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
00023  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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(); // TODO: cache these
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 } // namespace Kerfuffle

ark

Skip menu "ark"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdeutils

Skip menu "kdeutils"
  • ark
  • kcalc
  • kcharselect
  • kdelirc
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • kjots
  • klaptopdaemon
  • kmilo
  • ksim
  • ktimer
  • kwallet
  • superkaramba
Generated for kdeutils by doxygen 1.5.4
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