21#include <tqtextstream.h>
24#include <tdeapplication.h>
26#include <kgenericfactory.h>
27#include <tdemessagebox.h>
29#include <KoFilterChain.h>
30#include <KoStoreDevice.h>
32#include <kformuladocument.h>
33#include <kformulacontainer.h>
34#include <kformulamimesource.h>
36#include "mathmlexport.h"
39typedef KGenericFactory<MathMLExport, KoFilter> MathMLExportFactory;
40K_EXPORT_COMPONENT_FACTORY( libkfomathmlexport, MathMLExportFactory(
"kofficefilters" ) )
43MathMLExport::MathMLExport( KoFilter *, const
char *, const TQStringList& )
49KoFilter::ConversionStatus MathMLExport::convert(
const TQCString& from,
const TQCString& to )
51 if ( to !=
"application/mathml+xml" || from !=
"application/x-kformula" )
52 return KoFilter::NotImplemented;
54 KoStoreDevice* in = m_chain->storageFile(
"root", KoStore::Read );
56 TQApplication::restoreOverrideCursor();
57 KMessageBox::error( 0, i18n(
"Failed to read data." ), i18n(
"MathML Export Error" ) );
58 return KoFilter::StorageCreationError;
62 if ( !dom.setContent( in,
false ) ) {
63 TQApplication::restoreOverrideCursor();
64 KMessageBox::error( 0, i18n(
"Malformed XML data." ), i18n(
"MathML Export Error" ) );
65 return KoFilter::WrongFormat;
68 TQFile f( m_chain->outputFile() );
69 if( !f.open( IO_Truncate | IO_ReadWrite ) ) {
70 TQApplication::restoreOverrideCursor();
71 KMessageBox::error( 0, i18n(
"Failed to write file." ), i18n(
"MathML Export Error" ) );
72 return KoFilter::FileNotFound;
75 KFormula::DocumentWrapper* wrapper =
new KFormula::DocumentWrapper( kapp->config(), 0 );
76 KFormula::Document* doc =
new KFormula::Document;
77 wrapper->document( doc );
78 KFormula::Container* formula = doc->createFormula();
79 if ( !doc->loadXML( dom ) ) {
80 kdError() <<
"Failed." << endl;
83 TQTextStream stream(&f);
84 stream.setEncoding( TQTextStream::UnicodeUTF8 );
85 formula->saveMathML( stream );
94#include "mathmlexport.moc"