File indexing completed on 2024-05-12 16:29:03

0001 /* This file is part of the KDE project
0002    Copyright (C) 2007 Thorsten Zachmann <zachmann@kde.org>
0003    Copyright (C) 2009 Jarosław Staniek <staniek@kde.org>
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 
0010    This library is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this library; see the file COPYING.LIB.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019 */
0020 
0021 #ifndef KOODFEXPORTER_H
0022 #define KOODFEXPORTER_H
0023 
0024 #include "komsooxml_export.h"
0025 #include <KoFilter.h>
0026 
0027 class KoXmlWriter;
0028 class KoStore;
0029 class KoGenStyles;
0030 
0031 /**
0032  * @brief Convenience structure encapsulating XML writers used when writing ODF document.
0033  */
0034 struct KOMSOOXML_EXPORT KoOdfWriters {
0035     /**
0036     * Creates structure encapsulating XML writers. All members are set initially to 0.
0037     */
0038     KoOdfWriters();
0039     KoXmlWriter *content;
0040     KoXmlWriter *body;
0041     KoXmlWriter *meta;
0042     KoXmlWriter *manifest;
0043     KoGenStyles *mainStyles;
0044 };
0045 
0046 /**
0047  * @brief The base class for filters exporting to ODF.
0048  *
0049  * @todo Move to libs, e.g. komain
0050  *
0051  * @author Jarosław Staniek <staniek@kde.org>
0052  */
0053 class KOMSOOXML_EXPORT KoOdfExporter : public KoFilter
0054 {
0055     Q_OBJECT
0056 public:
0057     ~KoOdfExporter() override;
0058 
0059     KoFilter::ConversionStatus convert(const QByteArray& from, const QByteArray& to) override;
0060 
0061 protected:
0062     /**
0063      * This is the constructor your filter has to call, obviously.
0064      * @param bodyContentElement element name for the content:
0065      *                           "text" for ODT format, "presentation" for ODP,
0066      *                           "spreadsheet" for ODS, "drawing" for ODG.
0067      *                           office:text element will be created within office:body, etc.
0068      * @param parent parent object.
0069      */
0070     KoOdfExporter(const QString& bodyContentElement, QObject* parent = 0);
0071 
0072     /**
0073      * @return true if @a mime is accepted source mime type.
0074      * Implement it for your filter.
0075      */
0076     virtual bool acceptsSourceMimeType(const QByteArray& mime) const = 0;
0077 
0078     /**
0079      * @return true if @a mime is accepted destination mime type.
0080      * Implement it for your filter.
0081      */
0082     virtual bool acceptsDestinationMimeType(const QByteArray& mime) const = 0;
0083 
0084     /**
0085      * This method is called in convert() after creating @a outputStore, @a writers and @a mainStyles.
0086      * Implement it for your filter with code that fills the ODF structures with converted data.
0087      */
0088     virtual KoFilter::ConversionStatus createDocument(KoStore *outputStore,
0089             KoOdfWriters *writers) = 0;
0090 
0091     /**
0092      * This method is called when writing the xml-settings to the ODF document.
0093      */
0094     virtual void writeConfigurationSettings(KoXmlWriter* settings) const = 0;
0095 
0096 private:
0097     class Private;
0098     Private* d;
0099 };
0100 
0101 #endif /* KOODFEXPORTER_H */