File indexing completed on 2024-12-08 12:56:12

0001 /* This file is part of the KDE project
0002 
0003    Copyright (C) 2012-2014 Inge Wallin            <inge@lysator.liu.se>
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 ODFREADER_H
0022 #define ODFREADER_H
0023 
0024 // Qt
0025 #include <QHash>
0026 #include <QString>
0027 
0028 // Calligra
0029 #include <KoXmlStreamReader.h>
0030 
0031 // this library
0032 #include "koodfreader_export.h"
0033 #include "OdfReaderInternals.h"
0034 
0035 
0036 class QSizeF;
0037 
0038 class KoXmlWriter;
0039 class KoStore;
0040 
0041 class OdfReaderBackend;
0042 class OdfReaderContext;
0043 
0044 class OdfTextReader;
0045 class OdfDrawReader;
0046 
0047 
0048 /** @brief Read the XML tree of the content of an ODF file.
0049  *
0050  * The OdfReader is used to traverse (read) the contents of an ODF file using
0051  * an XML stream reader.  For reading a specific type of ODF, e.g. a text
0052  * document, you should create a new class, OdtReader that inherits this
0053  * class.
0054  *
0055  * For every XML element that the reading process comes across it will call a
0056  * specific function in a backend class: @see OdfReaderBackend.
0057  *
0058  * Before the reading process is started the ODF file will be
0059  * analyzed to collect some data that may be needed during the
0060  * read: metadata, manifest and styles are examples of this. This
0061  * data is stored in the so called reading context, which is kept in
0062  * an instance of the OdfReaderContext class.
0063  *
0064  * The context will be passed around to the backend in every call to a
0065  * backend callback function.
0066  *
0067  * In addition to the pre-analyzed data from the ODF file, the context
0068  * can be used to keep track of data that is used in the backend
0069  * processing such as internal links, lists of embedded data such as
0070  * pictures.
0071  */
0072 class KOODFREADER_EXPORT OdfReader
0073 {
0074  public:
0075     OdfReader();
0076     virtual ~OdfReader();
0077 
0078     OdfTextReader *textReader() const;
0079     void setTextReader(OdfTextReader *textReader);
0080 
0081     OdfDrawReader *drawReader() const;
0082     void setDrawReader(OdfDrawReader *drawReader);
0083 
0084     bool analyzeContent(OdfReaderContext *context);
0085 
0086     bool readContent(OdfReaderBackend *backend, OdfReaderContext *context);
0087 
0088  protected:
0089     // All readElement*() are named after the full qualifiedName of
0090     // the element in ODF that they handle.
0091 
0092     // ODF document level functions
0093     DECLARE_READER_FUNCTION(OfficeBody);
0094 
0095     // ONE of these should be reimplemented by each subclass, respectively.
0096     virtual DECLARE_READER_FUNCTION(OfficeText);
0097     virtual DECLARE_READER_FUNCTION(OfficeSpreadsheet);
0098     virtual DECLARE_READER_FUNCTION(OfficePresentation);
0099 
0100     // ----------------------------------------------------------------
0101     // Other functions
0102 
0103     void readUnknownElement(KoXmlStreamReader &reader);
0104 
0105 
0106  protected:
0107     OdfReaderBackend  *m_backend;
0108     OdfReaderContext  *m_context;
0109 
0110     // Helper readers
0111     OdfTextReader     *m_textReader;
0112     OdfDrawReader     *m_drawReader;
0113 };
0114 
0115 #endif // ODFREADER_H