filters

kword/html/export/htmlexport.cpp
1/*
2 This file is part of the KDE project
3 Copyright (C) 2001, 2002, 2004 Nicolas GOUTTE <goutte@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21/*
22 This file is based on the old file:
23 /home/kde/koffice/filters/kword/ascii/asciiexport.cpp
24
25 The old file was copyrighted by
26 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
27 Copyright (c) 2000 ID-PRO Deutschland GmbH. All rights reserved.
28 Contact: Wolf-Michael Bolle <Bolle@ID-PRO.de>
29
30 The old file was licensed under the terms of the GNU Library General Public
31 License version 2.
32*/
33
34#include <tqtextcodec.h>
35
36#include <kdebug.h>
37#include <kgenericfactory.h>
38#include <KoFilterChain.h>
39#include <KoFilterManager.h>
40
41#include <KWEFBaseWorker.h>
42#include <KWEFKWordLeader.h>
43
44#include "ExportDialog.h"
45#include "ExportFilter.h"
46#include "ExportCss.h"
47#include "ExportBasic.h"
48#include "ExportDocStruct.h"
49
50#include <htmlexport.h>
51#include <htmlexport.moc>
52
53typedef KGenericFactory<HTMLExport, KoFilter> HTMLExportFactory;
54K_EXPORT_COMPONENT_FACTORY( libhtmlexport, HTMLExportFactory( "kofficefilters" ) )
55
56//
57// HTMLExport
58//
59
60HTMLExport::HTMLExport(KoFilter *, const char *, const TQStringList &) :
61 KoFilter() {
62}
63
64KoFilter::ConversionStatus HTMLExport::convert( const TQCString& from, const TQCString& to )
65{
66 if ((from != "application/x-kword") || (to != "text/html"))
67 {
68 return KoFilter::NotImplemented;
69 }
70
71 bool batch=false;
72 if ( m_chain->manager() )
73 batch = m_chain->manager()->getBatchMode();
74
75 HtmlWorker* worker;
76
77 if (batch)
78 {
79 worker=new HtmlCssWorker();
80 worker->setXML(true);
81 worker->setCodec(TQTextCodec::codecForName("UTF-8"));
82 }
83 else
84 {
85 HtmlExportDialog dialog;
86
87 if (!dialog.exec())
88 {
89 kdDebug(30503) << "Dialog was aborted! Aborting filter!" << endl;
90 return KoFilter::UserCancelled;
91 }
92
93 const HtmlExportDialog::Mode mode = dialog.getMode();
94 switch (mode)
95 {
96 case HtmlExportDialog::Light:
97 worker=new HtmlDocStructWorker();
98 break;
99 case HtmlExportDialog::Basic:
100 worker=new HtmlBasicWorker();
101 break;
102 case HtmlExportDialog::CustomCSS:
103 worker=new HtmlBasicWorker( dialog.cssURL() );
104 break;
105 default: // Default CSS
106 worker=new HtmlCssWorker();
107 }
108
109 worker->setXML(dialog.isXHtml());
110 worker->setCodec(dialog.getCodec());
111 }
112
113 KWEFKWordLeader* leader=new KWEFKWordLeader(worker);
114
115 if (!leader)
116 {
117 kdError(30503) << "Cannot create Worker! Aborting!" << endl;
118 delete worker;
119 return KoFilter::StupidError;
120 }
121 KoFilter::ConversionStatus result=leader->convert(m_chain,from,to);
122
123 delete leader;
124 delete worker;
125
126 return result;
127}