filters

htmlexport.cc

00001 /*
00002    This file is part of the KDE project
00003    Copyright (C) 2001, 2002, 2004 Nicolas GOUTTE <goutte@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 /*
00022    This file is based on the old file:
00023     /home/kde/koffice/filters/kword/ascii/asciiexport.cc
00024 
00025    The old file was copyrighted by
00026     Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
00027     Copyright (c) 2000 ID-PRO Deutschland GmbH. All rights reserved.
00028                        Contact: Wolf-Michael Bolle <Bolle@ID-PRO.de>
00029 
00030    The old file was licensed under the terms of the GNU Library General Public
00031    License version 2.
00032 */
00033 
00034 #include <qtextcodec.h>
00035 
00036 #include <kdebug.h>
00037 #include <kgenericfactory.h>
00038 #include <KoFilterChain.h>
00039 #include <KoFilterManager.h>
00040 
00041 #include <KWEFBaseWorker.h>
00042 #include <KWEFKWordLeader.h>
00043 
00044 #include "ExportDialog.h"
00045 #include "ExportFilter.h"
00046 #include "ExportCss.h"
00047 #include "ExportBasic.h"
00048 #include "ExportDocStruct.h"
00049 
00050 #include <htmlexport.h>
00051 #include <htmlexport.moc>
00052 
00053 typedef KGenericFactory<HTMLExport, KoFilter> HTMLExportFactory;
00054 K_EXPORT_COMPONENT_FACTORY( libhtmlexport, HTMLExportFactory( "kofficefilters" ) )
00055 
00056 //
00057 // HTMLExport
00058 //
00059 
00060 HTMLExport::HTMLExport(KoFilter *, const char *, const QStringList &) :
00061                      KoFilter() {
00062 }
00063 
00064 KoFilter::ConversionStatus HTMLExport::convert( const QCString& from, const QCString& to )
00065 {
00066     if ((from != "application/x-kword") || (to != "text/html"))
00067     {
00068         return KoFilter::NotImplemented;
00069     }
00070 
00071     bool batch=false;
00072     if ( m_chain->manager() )
00073         batch = m_chain->manager()->getBatchMode();
00074 
00075     HtmlWorker* worker;
00076 
00077     if (batch)
00078     {
00079         worker=new HtmlCssWorker();
00080         worker->setXML(true);
00081         worker->setCodec(QTextCodec::codecForName("UTF-8"));
00082     }
00083     else
00084     {
00085         HtmlExportDialog dialog;
00086 
00087         if (!dialog.exec())
00088         {
00089             kdDebug(30503) << "Dialog was aborted! Aborting filter!" << endl;
00090             return KoFilter::UserCancelled;
00091         }
00092 
00093         const HtmlExportDialog::Mode mode = dialog.getMode();
00094         switch (mode)
00095         {
00096         case HtmlExportDialog::Light:
00097         worker=new HtmlDocStructWorker();
00098         break;
00099         case HtmlExportDialog::Basic:
00100         worker=new HtmlBasicWorker();
00101         break;
00102         case HtmlExportDialog::CustomCSS:
00103         worker=new HtmlBasicWorker( dialog.cssURL() );
00104         break;
00105         default: // Default CSS
00106         worker=new HtmlCssWorker();
00107         }
00108 
00109         worker->setXML(dialog.isXHtml());
00110         worker->setCodec(dialog.getCodec());
00111     }
00112 
00113     KWEFKWordLeader* leader=new KWEFKWordLeader(worker);
00114 
00115     if (!leader)
00116     {
00117         kdError(30503) << "Cannot create Worker! Aborting!" << endl;
00118         delete worker;
00119         return KoFilter::StupidError;
00120     }
00121     KoFilter::ConversionStatus result=leader->convert(m_chain,from,to);
00122 
00123     delete leader;
00124     delete worker;
00125 
00126     return result;
00127 }
KDE Home | KDE Accessibility Home | Description of Access Keys