wpexport.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002 Ariya Hidayat <ariya@kde.org>
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 <config.h>
21
22#ifdef HAVE_UNISTD_H
23#include <unistd.h>
24#endif
25
26#include <tqtextcodec.h>
27#include <tqfile.h>
28#include <tqfileinfo.h>
29#include <tqtextstream.h>
30
31#include <kdebug.h>
32#include <KoFilterChain.h>
33#include <kgenericfactory.h>
34
35#include <KWEFBaseWorker.h>
36#include <KWEFKWordLeader.h>
37
38#include <wpexport.h>
39#include <wp5.h>
40#include <wp6.h>
41
42typedef KGenericFactory<WPExport, KoFilter> WPExportFactory;
43K_EXPORT_COMPONENT_FACTORY( libwpexport, WPExportFactory( "kofficefilters" ) )
44
45WPExport::WPExport( KoFilter *, const char *, const TQStringList& ):
46 KoFilter()
47{
48}
49
50KoFilter::ConversionStatus
51WPExport::convert( const TQCString& from,
52 const TQCString& to )
53{
54 // check for proper conversion
55 if( to!= "application/wordperfect" || from != "application/x-kword" )
56 return KoFilter::NotImplemented;
57
58 // document version is determined using file extension,
59 // "WP" is for WP 5.x, "WPD" or else is for WP 6/7
60 // e.g /home/ariya/test.wp is a WP 5 document
61 // TODO ask user with a dialog box
62 TQString outfile = m_chain->outputFile();
63 TQString extension = TQFileInfo( outfile ).extension().lower();
64 int version = ( extension == "wp" ) ? 5 : 6 ;
65
66 KWEFBaseWorker* worker;
67 if( version == 5 ) worker = new WPFiveWorker();
68 else worker = new WPSixWorker();
69
70 KWEFKWordLeader* leader = new KWEFKWordLeader( worker );
71
72 KoFilter::ConversionStatus result;
73 result = leader->convert( m_chain, from, to );
74
75 delete worker;
76 delete leader;
77
78 return result;
79}
80
81#include "wpexport.moc"
Base worker of the libexport system.