filters

palmdocexport.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002 Ariya Hidayat <ariyahidayat@yahoo.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 <config.h>
00021 
00022 #ifdef HAVE_UNISTD_H
00023 #include <unistd.h>
00024 #endif
00025 
00026 #include <qfile.h>
00027 #include <qfileinfo.h>
00028 #include <qtextstream.h>
00029 
00030 #include <kdebug.h>
00031 #include <KoFilterChain.h>
00032 #include <kgenericfactory.h>
00033 
00034 #include <KWEFStructures.h>
00035 #include <KWEFBaseWorker.h>
00036 #include <KWEFKWordLeader.h>
00037 
00038 #include "palmdoc.h"
00039 
00040 #include "palmdocexport.h"
00041 
00042 typedef KGenericFactory<PalmDocExport, KoFilter> PalmDocExportFactory;
00043 K_EXPORT_COMPONENT_FACTORY( libpalmdocexport, PalmDocExportFactory( "kofficefilters" ) )
00044 
00045 class PalmDocWorker : public KWEFBaseWorker
00046 {
00047 public:
00048     PalmDocWorker(void)  { }
00049     virtual ~PalmDocWorker(void) { }
00050 public:
00051     virtual bool doOpenFile(const QString& filenameOut, const QString& to);
00052     virtual bool doCloseFile(void);
00053     virtual bool doOpenDocument(void);
00054     virtual bool doCloseDocument(void);
00055     virtual bool doFullDocumentInfo(const KWEFDocumentInfo& docInfo);
00056     virtual bool doFullParagraph(const QString& paraText, const LayoutData& layout,
00057         const ValueListFormatData& paraFormatDataList);
00058 private:
00059     QString title;
00060     QString outfile;
00061     QString text;
00062 };
00063 
00064 bool PalmDocWorker::doOpenFile(const QString& filenameOut, const QString& /*to*/)
00065 {
00066   outfile = filenameOut;
00067   return TRUE;
00068 }
00069 
00070 bool PalmDocWorker::doCloseFile(void)
00071 {
00072   if( title.isEmpty() )
00073   {
00074     QFileInfo info( outfile );
00075     title = info.baseName();
00076   }
00077   
00078   PalmDoc doc;
00079   doc.setName( title );
00080   doc.setText( text );
00081   doc.save( outfile.latin1() );
00082 
00083   return TRUE;
00084 }
00085 
00086 bool PalmDocWorker::doOpenDocument(void)
00087 {
00088   text = QString::null;
00089   return TRUE;
00090 }
00091 
00092 bool PalmDocWorker::doCloseDocument(void)
00093 {
00094   return TRUE;
00095 }
00096 
00097 bool PalmDocWorker::doFullDocumentInfo( const KWEFDocumentInfo& docInfo )
00098 {
00099   title = docInfo.title;
00100   return TRUE;
00101 }
00102 
00103 bool PalmDocWorker::doFullParagraph(const QString& paraText, 
00104   const LayoutData& /*layout*/, const ValueListFormatData& /*paraFormatDataList*/)
00105 {
00106   kdDebug(30525) << "Entering ::doFullParagraph" << endl;
00107   text.append( paraText );
00108   text.append( "\n\n" );
00109 
00110   return TRUE;
00111 }
00112 
00113 PalmDocExport::PalmDocExport( KoFilter *, const char *, const QStringList& ):
00114                      KoFilter()
00115 {
00116 }
00117 
00118 KoFilter::ConversionStatus PalmDocExport::convert( const QCString& from, 
00119   const QCString& to )
00120 {
00121   // check for proper conversion
00122   if( to!= "application/vnd.palm" || from != "application/x-kword" )
00123      return KoFilter::NotImplemented;
00124 
00125   PalmDocWorker* worker = new PalmDocWorker();
00126   KWEFKWordLeader* leader = new KWEFKWordLeader( worker );
00127 
00128   KoFilter::ConversionStatus result;
00129   result = leader->convert( m_chain, from, to );
00130 
00131   delete worker;
00132   delete leader;
00133 
00134   return result; 
00135 }
00136 
00137 #include "palmdocexport.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys