filters

aiimport.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002, Dirk Schönberger <dirk.schoenberger@sz-online.de>
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 <qdom.h>
00021 #include <qcstring.h>
00022 #include <qfile.h>
00023 #include <qstring.h>
00024 
00025 #include <kgenericfactory.h>
00026 #include <KoFilterChain.h>
00027 #include <KoStore.h>
00028 
00029 #include <kdebug.h>
00030 
00031 #include "aiimport.h"
00032 #include "karbonaiparserbase.h"
00033 
00034 class AiImportFactory : KGenericFactory<AiImport, KoFilter>
00035 {
00036 public:
00037     AiImportFactory( void )
00038         : KGenericFactory<AiImport, KoFilter>( "karbonaiimport" )
00039     {}
00040 
00041 protected:
00042     virtual void setupTranslations( void )
00043     {
00044         KGlobal::locale()->insertCatalogue( "kofficefilters" );
00045     }
00046 };
00047 
00048 K_EXPORT_COMPONENT_FACTORY( libkarbonaiimport, AiImportFactory() )
00049 
00050 AiImport::AiImport( KoFilter*, const char*, const QStringList& )
00051     : KoFilter()
00052 {
00053 }
00054 
00055 AiImport::~AiImport()
00056 {
00057 }
00058 
00059 KoFilter::ConversionStatus
00060 AiImport::convert( const QCString& from, const QCString& to )
00061 {
00062     if ( from != "application/illustrator" || to != "application/x-karbon" )
00063     {
00064         return KoFilter::NotImplemented;
00065     }
00066     QFile fileIn( m_chain->inputFile() );
00067     if( !fileIn.open( IO_ReadOnly ) )
00068     {
00069         fileIn.close();
00070         return KoFilter::FileNotFound;
00071     }
00072 
00073         QDomDocument doc ("DOC");
00074     KarbonAIParserBase parser;
00075 
00076         if (!parser.parse (fileIn, doc))
00077         {
00078         fileIn.close();
00079         return KoFilter::CreationError;
00080         }
00081     QString result = doc.toString();
00082 
00083         kdDebug() << result << endl;
00084     KoStoreDevice* storeOut = m_chain->storageFile( "root", KoStore::Write );
00085     if( !storeOut )
00086     {
00087         fileIn.close();
00088         return KoFilter::StorageCreationError;
00089     }
00090 
00091     QCString cStr = result.latin1();
00092     storeOut->writeBlock( cStr, cStr.size() - 1 );
00093 
00094     return KoFilter::OK;
00095 }
00096 
00097 
00098 #include "aiimport.moc"
00099 
00100 
00101 
KDE Home | KDE Accessibility Home | Description of Access Keys