filters

wpexport.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002 Ariya Hidayat <ariya@kde.org>
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 <config.h>
00021 
00022 #ifdef HAVE_UNISTD_H
00023 #include <unistd.h>
00024 #endif
00025 
00026 #include <qtextcodec.h>
00027 #include <qfile.h>
00028 #include <qfileinfo.h>
00029 #include <qtextstream.h>
00030 
00031 #include <kdebug.h>
00032 #include <KoFilterChain.h>
00033 #include <kgenericfactory.h>
00034 
00035 #include <KWEFBaseWorker.h>
00036 #include <KWEFKWordLeader.h>
00037 
00038 #include <wpexport.h>
00039 #include <wp5.h>
00040 #include <wp6.h>
00041 
00042 typedef KGenericFactory<WPExport, KoFilter> WPExportFactory;
00043 K_EXPORT_COMPONENT_FACTORY( libwpexport, WPExportFactory( "kofficefilters" ) )
00044 
00045 WPExport::WPExport( KoFilter *, const char *, const QStringList& ):
00046                      KoFilter()
00047 {
00048 }
00049 
00050 KoFilter::ConversionStatus 
00051 WPExport::convert( const QCString& from, 
00052   const QCString& to )
00053 {
00054   // check for proper conversion
00055   if( to!= "application/wordperfect" || from != "application/x-kword" )
00056      return KoFilter::NotImplemented;
00057 
00058   // document version is determined using file extension, 
00059   // "WP" is for WP 5.x, "WPD" or else is for WP 6/7
00060   // e.g /home/ariya/test.wp is a WP 5 document
00061   // TODO ask user with a dialog box
00062   QString outfile = m_chain->outputFile();
00063   QString extension = QFileInfo( outfile ).extension().lower();
00064   int version = ( extension == "wp" ) ? 5 : 6 ;
00065 
00066   KWEFBaseWorker* worker;
00067   if( version == 5 ) worker = new WPFiveWorker();
00068   else worker = new WPSixWorker();
00069 
00070   KWEFKWordLeader* leader = new KWEFKWordLeader( worker );
00071 
00072   KoFilter::ConversionStatus result;
00073   result = leader->convert( m_chain, from, to );
00074 
00075   delete worker;
00076   delete leader;
00077 
00078   return result; 
00079 }
00080 
00081 #include "wpexport.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys