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 0009 // Own 0010 #include "OdfReaderContext.h" 0011 0012 // Calligra 0013 #include <KoXmlReader.h> 0014 #include <KoOdfStyleManager.h> 0015 0016 // Odftraverse library 0017 #include "OdfParser.h" 0018 0019 0020 // ---------------------------------------------------------------- 0021 // class OdfReaderContext::Private 0022 0023 0024 class Q_DECL_HIDDEN OdfReaderContext::Private 0025 { 0026 public: 0027 Private(KoStore *store); 0028 ~Private(); 0029 0030 KoStore *odfStore; 0031 0032 // This data is used for conversion while traversing the content tree. 0033 // It's created from the store that is given to us at construction time. 0034 QHash<QString, QString> metadata; 0035 QHash<QString, QString> manifest; 0036 KoOdfStyleManager *styleManager; 0037 0038 // This data changes while the parsing proceeds. 0039 bool isInsideParagraph; // True while we are parsing paragraph contents. 0040 0041 // This data is created during the reading and can be used after 0042 // it is finished. 0043 QHash<QString, QSizeF> images; 0044 QHash<QString, QString> mediaFiles; 0045 }; 0046 0047 0048 OdfReaderContext::Private::Private(KoStore *store) 0049 : odfStore(store) 0050 , styleManager(new KoOdfStyleManager()) 0051 , isInsideParagraph(false) 0052 { 0053 } 0054 0055 OdfReaderContext::Private::~Private() 0056 { 0057 delete styleManager; 0058 } 0059 0060 0061 // ---------------------------------------------------------------- 0062 // class OdfReaderContext 0063 0064 0065 OdfReaderContext::OdfReaderContext(KoStore *store) 0066 : d(new OdfReaderContext::Private(store)) 0067 { 0068 } 0069 0070 OdfReaderContext::~OdfReaderContext() 0071 { 0072 delete d; 0073 } 0074 0075 0076 KoFilter::ConversionStatus OdfReaderContext::analyzeOdfFile() 0077 { 0078 if (!d->odfStore) { 0079 return KoFilter::FileNotFound; 0080 } 0081 0082 // ---------------------------------------------------------------- 0083 // Parse input files 0084 0085 OdfParser odfParser; 0086 KoFilter::ConversionStatus status; 0087 0088 // Parse meta.xml into m_metadata 0089 status = odfParser.parseMetadata(*d->odfStore, &d->metadata); 0090 if (status != KoFilter::OK) { 0091 return status; 0092 } 0093 0094 // Parse manifest 0095 status = odfParser.parseManifest(*d->odfStore, &d->manifest); 0096 if (status != KoFilter::OK) { 0097 return status; 0098 } 0099 0100 // Load the styles 0101 d->styleManager->loadStyles(d->odfStore); 0102 0103 return KoFilter::OK; 0104 } 0105 0106 0107 KoStore *OdfReaderContext::odfStore() const 0108 { 0109 return d->odfStore; 0110 } 0111 0112 KoOdfStyleManager *OdfReaderContext::styleManager() const 0113 { 0114 return d->styleManager; 0115 } 0116 0117 QHash<QString, QString> OdfReaderContext::metadata() const 0118 { 0119 return d->metadata; 0120 } 0121 0122 QHash<QString, QString> OdfReaderContext::manifest() const 0123 { 0124 return d->manifest; 0125 } 0126 0127 0128 bool OdfReaderContext::isInsideParagraph() const 0129 { 0130 return d->isInsideParagraph; 0131 } 0132 0133 void OdfReaderContext::setIsInsideParagraph(bool isInside) 0134 { 0135 d->isInsideParagraph = isInside; 0136 } 0137 0138 0139 QHash<QString, QSizeF> OdfReaderContext::images() const 0140 { 0141 return d->images; 0142 } 0143 0144 #if 0 // NYI 0145 QHash<QString, QString> OdfReaderContext::mediaFiles() const 0146 { 0147 return d->mediaFiles; 0148 } 0149 #endif