filters
mathmlexport.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <qstring.h>
00021 #include <qtextstream.h>
00022 #include <qfile.h>
00023
00024 #include <kapplication.h>
00025 #include <kdebug.h>
00026 #include <kgenericfactory.h>
00027 #include <kmessagebox.h>
00028
00029 #include <KoFilterChain.h>
00030 #include <KoStoreDevice.h>
00031
00032 #include <kformuladocument.h>
00033 #include <kformulacontainer.h>
00034 #include <kformulamimesource.h>
00035
00036 #include "mathmlexport.h"
00037
00038
00039 typedef KGenericFactory<MathMLExport, KoFilter> MathMLExportFactory;
00040 K_EXPORT_COMPONENT_FACTORY( libkfomathmlexport, MathMLExportFactory( "kofficefilters" ) )
00041
00042
00043 MathMLExport::MathMLExport( KoFilter *, const char *, const QStringList& )
00044 : KoFilter()
00045 {
00046 }
00047
00048
00049 KoFilter::ConversionStatus MathMLExport::convert( const QCString& from, const QCString& to )
00050 {
00051 if ( to != "application/mathml+xml" || from != "application/x-kformula" )
00052 return KoFilter::NotImplemented;
00053
00054 KoStoreDevice* in = m_chain->storageFile( "root", KoStore::Read );
00055 if(!in) {
00056 QApplication::restoreOverrideCursor();
00057 KMessageBox::error( 0, i18n( "Failed to read data." ), i18n( "MathML Export Error" ) );
00058 return KoFilter::StorageCreationError;
00059 }
00060
00061 QDomDocument dom;
00062 if ( !dom.setContent( in, false ) ) {
00063 QApplication::restoreOverrideCursor();
00064 KMessageBox::error( 0, i18n( "Malformed XML data." ), i18n( "MathML Export Error" ) );
00065 return KoFilter::WrongFormat;
00066 }
00067
00068 QFile f( m_chain->outputFile() );
00069 if( !f.open( IO_Truncate | IO_ReadWrite ) ) {
00070 QApplication::restoreOverrideCursor();
00071 KMessageBox::error( 0, i18n( "Failed to write file." ), i18n( "MathML Export Error" ) );
00072 return KoFilter::FileNotFound;
00073 }
00074
00075 KFormula::DocumentWrapper* wrapper = new KFormula::DocumentWrapper( kapp->config(), 0 );
00076 KFormula::Document* doc = new KFormula::Document;
00077 wrapper->document( doc );
00078 KFormula::Container* formula = doc->createFormula();
00079 if ( !doc->loadXML( dom ) ) {
00080 kdError() << "Failed." << endl;
00081 }
00082
00083 QTextStream stream(&f);
00084 stream.setEncoding( QTextStream::UnicodeUTF8 );
00085 formula->saveMathML( stream );
00086 f.close();
00087
00088 delete formula;
00089 delete wrapper;
00090
00091 return KoFilter::OK;
00092 }
00093
00094 #include "mathmlexport.moc"
|