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