• Skip to content
  • Skip to link menu
KDE 4.2 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         if ( offers.isEmpty()) {
00051 
00052             kDebug( 1601 ) << "Trying to find the mimetype by looking at file content";
00053 
00054             int acc;
00055             QString mimeType = KMimeType::findByFileContent( filename, &acc )->name();
00056             kDebug(1601) << mimeType << acc;
00057             offers = KMimeTypeTrader::self()->query( mimeType, "Kerfuffle/Plugin", "(exist Library)" );
00058 
00059         }
00060 
00061         qSort( offers.begin(), offers.end(), comparePlugins );
00062 
00063         if ( !offers.isEmpty() )
00064         {
00065             QString libraryName = offers[ 0 ]->library();
00066             KLibrary *lib = KLibLoader::self()->library( QFile::encodeName( libraryName ), QLibrary::ExportExternalSymbolsHint );
00067             //TODO: get rid of the deprecated klibloader::self
00068 #if 0
00069             
00070             KPluginLoader loader(offers.at(0));
00071             KPluginFactory *factory = loader.factory();
00072 #endif
00073 
00074             kDebug( 1601 ) << "Loading library " << libraryName ;
00075             if ( lib )
00076             {
00077                 ArchiveFactory *( *pluginFactory )() = ( ArchiveFactory *( * )() )lib->resolveFunction( "pluginFactory" );
00078                 if ( pluginFactory )
00079                 {
00080                     ArchiveFactory *factory = pluginFactory(); // TODO: cache these
00081                     Archive *arch = factory->createArchive( filename, 0 );
00082                     delete factory;
00083                     return arch;
00084                 }
00085             }
00086             kDebug( 1601 ) << "Couldn't load library " << libraryName ;
00087         }
00088         kDebug( 1601 ) << "Couldn't find a library capable of handling " << filename ;
00089         return 0;
00090     }
00091 
00092     QStringList supportedMimeTypes()
00093     {
00094         QStringList supported;
00095         KService::List offers = KServiceTypeTrader::self()->query( "Kerfuffle/Plugin", "(exist Library)" );
00096 
00097         foreach( const KService::Ptr& service, offers )
00098         {
00099             foreach( const QString& mimeType, service->serviceTypes() )
00100             {
00101                 if ( !mimeType.contains( "Kerfuffle" ) )
00102                 {
00103                     supported << mimeType;
00104                 }
00105             }
00106         }
00107         return supported;
00108     }
00109 
00110     QStringList supportedWriteMimeTypes()
00111     {
00112         QStringList supported;
00113         KService::List offers = KServiceTypeTrader::self()->query( "Kerfuffle/Plugin", "(exist Library) and ([X-KDE-Kerfuffle-ReadWrite] == true)" );
00114 
00115         foreach( const KService::Ptr& service, offers )
00116         {
00117             foreach( const QString& mimeType, service->serviceTypes() )
00118             {
00119                 if ( !mimeType.contains( "Kerfuffle" ) )
00120                 {
00121                     supported << mimeType;
00122                 }
00123             }
00124         }
00125         kDebug( 1601 ) << "Returning" << supported;
00126         return supported;
00127     }
00128 } // 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
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • okteta
  • printer-applet
  • superkaramba
  • sweeper
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