filters

aiimport.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002, Dirk Schönberger <dirk.schoenberger@sz-online.de>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include <tqdom.h>
21#include <tqcstring.h>
22#include <tqfile.h>
23#include <tqstring.h>
24
25#include <kgenericfactory.h>
26#include <KoFilterChain.h>
27#include <KoStore.h>
28
29#include <kdebug.h>
30
31#include "aiimport.h"
32#include "karbonaiparserbase.h"
33
34class AiImportFactory : KGenericFactory<AiImport, KoFilter>
35{
36public:
37 AiImportFactory( void )
38 : KGenericFactory<AiImport, KoFilter>( "karbonaiimport" )
39 {}
40
41protected:
42 virtual void setupTranslations( void )
43 {
44 TDEGlobal::locale()->insertCatalogue( "kofficefilters" );
45 }
46};
47
48K_EXPORT_COMPONENT_FACTORY( libkarbonaiimport, AiImportFactory() )
49
50AiImport::AiImport( KoFilter*, const char*, const TQStringList& )
51 : KoFilter()
52{
53}
54
55AiImport::~AiImport()
56{
57}
58
59KoFilter::ConversionStatus
60AiImport::convert( const TQCString& from, const TQCString& to )
61{
62 if ( from != "application/illustrator" || to != "application/x-karbon" )
63 {
64 return KoFilter::NotImplemented;
65 }
66 TQFile fileIn( m_chain->inputFile() );
67 if( !fileIn.open( IO_ReadOnly ) )
68 {
69 fileIn.close();
70 return KoFilter::FileNotFound;
71 }
72
73 TQDomDocument doc ("DOC");
74 KarbonAIParserBase parser;
75
76 if (!parser.parse(fileIn, doc))
77 {
78 fileIn.close();
79 return KoFilter::CreationError;
80 }
81 TQString result = doc.toString();
82
83 kdDebug() << result << endl;
84 KoStoreDevice* storeOut = m_chain->storageFile( "root", KoStore::Write );
85 if( !storeOut )
86 {
87 fileIn.close();
88 return KoFilter::StorageCreationError;
89 }
90
91 TQCString cStr = result.latin1();
92 storeOut->writeBlock( cStr, cStr.size() - 1 );
93
94 return KoFilter::OK;
95}
96
97
98#include "aiimport.moc"
99
100
101