File indexing completed on 2025-01-19 10:49:27

0001 /* This file is part of the KDE project
0002 
0003    SPDX-FileCopyrightText: 2013 Inge Wallin <inge@lysator.liu.se>
0004 
0005    SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef ODFREADERCONTEXT_H
0009 #define ODFREADERCONTEXT_H
0010 
0011 // Qt
0012 #include <QHash>
0013 
0014 // Calligra
0015 #include <KoFilter.h>
0016 
0017 // this library
0018 #include "koodfreader_export.h"
0019 
0020 
0021 class QSizeF;
0022 class KoStore;
0023 class KoOdfStyleManager;
0024 
0025 
0026 /** @brief The OdfReaderContext contains data that is usable while reading an ODF file.
0027  *
0028  * In the process of reading content.xml of an ODF file, it is often
0029  * necessary to access other parts of the ODF files.  In particular,
0030  * the styles (both named and automatic), the manifest and the
0031  * metadata are such resources. The OdfReaderContext provides a
0032  * storage for this type of data.
0033  *
0034  * At the beginning of the traverse process, the Reader class is
0035  * supposed to call analyzeOdfFile() in this class. This initializes
0036  * the style, metadata and manifest store of the context. This data is
0037  * not changed during the traverse and can be considered const.
0038  *
0039  * Another use of the OdfReaderContext class is to collect data
0040  * during the traversal that can be used afterwards. One such example
0041  * is that a list of all images that are accessed in the content is
0042  * created. This list can be accessed afterwards by calling images().
0043  *
0044  * When you create a file format filter using a reader
0045  * (e.g. OdtReader or OdsReader), you should inherit this class
0046  * to create your own context class and extend it with storage of all
0047  * data that is relevant for you during the conversion. Such data
0048  * could be data about internal links, current list level, etc.
0049  *
0050  * @Note: At the time of writing there is only an OdtReader, no other readers.
0051  *
0052  * @see OdtReader
0053  * @see OdtReaderBackend
0054  */
0055 
0056 class KOODFREADER_EXPORT OdfReaderContext
0057 {
0058  public:
0059     explicit OdfReaderContext(KoStore *store);
0060     virtual ~OdfReaderContext();
0061 
0062     /** Analyze (parse) the data in an ODF file other than the content
0063      *  and store it internally.  This data can later be accessed by
0064      *  the getters such as metadata() and manifest().
0065      */
0066     KoFilter::ConversionStatus analyzeOdfFile();
0067 
0068     /** Return the store that is used during the parsing.
0069      */
0070     KoStore *odfStore() const;
0071 
0072     /** Return the styles of the ODF file.
0073       */
0074     KoOdfStyleManager *styleManager() const;
0075 
0076     /** Return the metadata of an ODF file.
0077      *
0078      * Format is QHash<name, value>
0079      * where
0080      *   name  is the name of the metadata tag
0081      *   value is its value
0082      *
0083      * This data is created before the traversal starts and can be
0084      * accessed during the traversal.
0085      */
0086     QHash<QString, QString> metadata() const;
0087 
0088     /*** Return the manifest of an ODF file.
0089      *
0090      * Format is QHash<path, type>
0091      * where
0092      *   path  is the full path of the file stored in the manifest
0093      *   type  is the mimetype of the file.
0094      *
0095      * This data is created before the traversal starts and can be
0096      * accessed during the traversal.
0097      */
0098     QHash<QString, QString> manifest() const;
0099 
0100     // This data changes while the parsing proceeds.
0101     bool isInsideParagraph() const;
0102     void setIsInsideParagraph(bool isInside);
0103 
0104 
0105     // This data below is created during the traversal and can be
0106     // accessed after the traversal is finished.
0107 
0108     /** Return a list of images and their sizes. This list is
0109      * collected during the traversal of an ODF file.
0110      *
0111      * The format is QHash<name, size>
0112      * where
0113      *    name   is the name of the picture inside the ODT file
0114      *    size   is the size in points.
0115      */
0116     QHash<QString, QSizeF>   images() const;
0117 
0118     //QHash<QString, QString>  mediaFiles() const;
0119 
0120  private:
0121     class Private;
0122     Private * const d;
0123 };
0124 
0125 
0126 #endif // ODFREADERCONTEXT_H