filters

palmdocexport.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002 Ariya Hidayat <ariyahidayat@yahoo.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 <config.h>
21
22#ifdef HAVE_UNISTD_H
23#include <unistd.h>
24#endif
25
26#include <tqfile.h>
27#include <tqfileinfo.h>
28#include <tqtextstream.h>
29
30#include <kdebug.h>
31#include <KoFilterChain.h>
32#include <kgenericfactory.h>
33
34#include <KWEFStructures.h>
35#include <KWEFBaseWorker.h>
36#include <KWEFKWordLeader.h>
37
38#include "palmdoc.h"
39
40#include "palmdocexport.h"
41
42typedef KGenericFactory<PalmDocExport, KoFilter> PalmDocExportFactory;
43K_EXPORT_COMPONENT_FACTORY( libpalmdocexport, PalmDocExportFactory( "kofficefilters" ) )
44
45class PalmDocWorker : public KWEFBaseWorker
46{
47public:
48 PalmDocWorker(void) { }
49 virtual ~PalmDocWorker(void) { }
50public:
51 virtual bool doOpenFile(const TQString& filenameOut, const TQString& to);
52 virtual bool doCloseFile(void);
53 virtual bool doOpenDocument(void);
54 virtual bool doCloseDocument(void);
55 virtual bool doFullDocumentInfo(const KWEFDocumentInfo& docInfo);
56 virtual bool doFullParagraph(const TQString& paraText, const LayoutData& layout,
57 const ValueListFormatData& paraFormatDataList);
58private:
59 TQString title;
60 TQString outfile;
61 TQString text;
62};
63
64bool PalmDocWorker::doOpenFile(const TQString& filenameOut, const TQString& /*to*/)
65{
66 outfile = filenameOut;
67 return true;
68}
69
70bool PalmDocWorker::doCloseFile(void)
71{
72 if( title.isEmpty() )
73 {
74 TQFileInfo info( outfile );
75 title = info.baseName();
76 }
77
78 PalmDoc doc;
79 doc.setName( title );
80 doc.setText( text );
81 doc.save( outfile.latin1() );
82
83 return true;
84}
85
86bool PalmDocWorker::doOpenDocument(void)
87{
88 text = TQString();
89 return true;
90}
91
92bool PalmDocWorker::doCloseDocument(void)
93{
94 return true;
95}
96
97bool PalmDocWorker::doFullDocumentInfo( const KWEFDocumentInfo& docInfo )
98{
99 title = docInfo.title;
100 return true;
101}
102
103bool PalmDocWorker::doFullParagraph(const TQString& paraText,
104 const LayoutData& /*layout*/, const ValueListFormatData& /*paraFormatDataList*/)
105{
106 kdDebug(30525) << "Entering ::doFullParagraph" << endl;
107 text.append( paraText );
108 text.append( "\n\n" );
109
110 return true;
111}
112
113PalmDocExport::PalmDocExport( KoFilter *, const char *, const TQStringList& ):
114 KoFilter()
115{
116}
117
118KoFilter::ConversionStatus PalmDocExport::convert( const TQCString& from,
119 const TQCString& to )
120{
121 // check for proper conversion
122 if( to!= "application/vnd.palm" || from != "application/x-kword" )
123 return KoFilter::NotImplemented;
124
125 PalmDocWorker* worker = new PalmDocWorker();
126 KWEFKWordLeader* leader = new KWEFKWordLeader( worker );
127
128 KoFilter::ConversionStatus result;
129 result = leader->convert( m_chain, from, to );
130
131 delete worker;
132 delete leader;
133
134 return result;
135}
136
137#include "palmdocexport.moc"
Base worker of the libexport system.
Paragraph layout.