kformula/png/pngexport.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002 Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.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 <tqstring.h>
21#include <tqtextstream.h>
22#include <tqfile.h>
23#include <tqobject.h>
24
25#include <tdeapplication.h>
26#include <kdebug.h>
27#include <kgenericfactory.h>
28#include <tdemessagebox.h>
29
30#include <KoFilterChain.h>
31#include <KoStore.h>
32#include <KoStoreDevice.h>
33
34
35#include "pngexport.h"
36#include "pngexportdia.h"
37
38
39typedef KGenericFactory<PNGExport, KoFilter> PNGExportFactory;
40K_EXPORT_COMPONENT_FACTORY( libkfopngexport, PNGExportFactory( "kofficefilters" ) )
41
42
43PNGExport::PNGExport( KoFilter */*parent*/, const char */*name*/, const TQStringList& )
44 : KoFilter()
45{
46}
47
48
49KoFilter::ConversionStatus PNGExport::convert( const TQCString& from, const TQCString& to )
50{
51 if ( to != "image/png" || from != "application/x-kformula" )
52 return KoFilter::NotImplemented;
53
54 KoStoreDevice* in = m_chain->storageFile( "root", KoStore::Read );
55 if(!in) {
56 kapp->restoreOverrideCursor();
57 KMessageBox::error( 0, i18n( "Failed to read data." ), i18n( "PNG Export Error" ) );
58 return KoFilter::FileNotFound;
59 }
60
61 TQDomDocument dom( "KFORMULA" );
62 if ( !dom.setContent( in, false ) ) {
63 kapp->restoreOverrideCursor();
64 KMessageBox::error( 0, i18n( "Malformed XML data." ), i18n( "PNG Export Error" ) );
65 return KoFilter::WrongFormat;
66 }
67
68 PNGExportDia* dialog = new PNGExportDia( dom, m_chain->outputFile() );
69 dialog->exec();
70 delete dialog;
71 return KoFilter::OK;
72}
73
74#include "pngexport.moc"