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

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 
0022 // Own
0023 #include "OdsReader.h"
0024 
0025 // Qt
0026 #include <QStringList>
0027 #include <QBuffer>
0028 
0029 // KF5
0030 #include <klocalizedstring.h>
0031 
0032 // Calligra
0033 #include <KoStore.h>
0034 #include <KoXmlStreamReader.h>
0035 #include <KoXmlNS.h>
0036 #include <KoXmlWriter.h>  // For copyXmlElement
0037 #include <KoOdfReadStore.h>
0038 
0039 // Reader library
0040 #include "OdsReaderBackend.h"
0041 #include "OdfReaderContext.h"
0042 #include "OdfTextReader.h"
0043 #include "OdfReaderDebug.h"
0044 
0045 
0046 #if 0
0047 static int debugIndent = 0;
0048 #define DEBUGSTART() \
0049     ++debugIndent; \
0050     DEBUG_READING("entering")
0051 #define DEBUGEND() \
0052     DEBUG_READING("exiting"); \
0053     --debugIndent
0054 #define DEBUG_READING(param) \
0055     debugOdfReader << QString("%1").arg(" ", debugIndent * 2) << param << ": " \
0056     << (reader.isStartElement() ? "start": (reader.isEndElement() ? "end" : "other")) \
0057     << reader.qualifiedName().toString()
0058 #else
0059 #define DEBUGSTART() \
0060     // NOTHING
0061 #define DEBUGEND() \
0062     // NOTHING
0063 #define DEBUG_READING(param) \
0064     // NOTHING
0065 #endif
0066 
0067 
0068 OdsReader::OdsReader()
0069     : OdfReader()
0070 {
0071 }
0072 
0073 OdsReader::~OdsReader()
0074 {
0075 }
0076 
0077 
0078 #if 0
0079 // This is a template function for the reader library.
0080 // Copy this one and change the name and fill in the code.
0081 void OdsReader::readElementNamespaceTagname(KoXmlStreamReader &reader)
0082 { 
0083    DEBUGSTART();
0084 
0085     // <namespace:tagname> has the following children in ODF 1.2:
0086     //   FILL IN THE CHILDREN LIKE THIS EXAMPLE (taken from office:document-content):
0087     //          <office:automatic-styles> 3.15.3
0088     //          <office:body> 3.3
0089     //          <office:font-face-decls> 3.14
0090     //          <office:scripts> 3.12.
0091     while (reader.readNextStartElement()) {
0092         QString tagName = reader.qualifiedName().toString();
0093         
0094         if (tagName == "office:automatic-styles") {
0095             // FIXME: NYI
0096         }
0097         else if (tagName == "office:body") {
0098             readElementOfficeBody(reader);
0099         }
0100         ...  MORE else if () HERE
0101         else {
0102             reader.skipCurrentElement();
0103         }
0104     }
0105 
0106     m_backend->elementNamespaceTagname(reader, m_context);
0107     DEBUGEND();
0108 }
0109 #endif
0110 
0111 
0112 // Reimplemented from OdfReader
0113 void OdsReader::readElementOfficeSpreadsheet(KoXmlStreamReader &reader)
0114 {
0115     DEBUGSTART();
0116     OdsReaderBackend *backend = dynamic_cast<OdsReaderBackend *>(m_backend);
0117     backend->elementOfficeSpreadsheet(reader, m_context);
0118 
0119     // <office:spreadsheet> has the following children in ODF 1.2:
0120     //
0121     //          <table:calculation-settings> 9.4.1
0122     //          <table:consolidation> 9.7
0123     //          <table:content-validations> 9.4.4
0124     //          <table:database-ranges> 9.4.14
0125     //          <table:data-pilot-tables> 9.6.2
0126     //          <table:dde-links> 9.8
0127     //          <table:label-ranges> 9.4.10
0128     //          <table:named-expressions> 9.4.11
0129     //   [done] <table:table> 9.1.2
0130     //          <table:tracked-changes> 9.9.2
0131     //          <text:alphabetical-index-auto-mark-file> 8.8.3
0132     //          <text:dde-connection-decls> 14.6.2
0133     //          <text:sequence-decls> 7.4.11
0134     //          <text:user-field-decls> 7.4.7
0135     //          <text:variable-decls> 7.4.2
0136 
0137     //
0138     // FIXME: For now, only very few of these are handled.
0139     while (reader.readNextStartElement()) {
0140         DEBUG_READING("loop-start");
0141         
0142         QString tagName = reader.qualifiedName().toString();
0143         if (tagName == "table:table") {
0144             if (m_textReader) {
0145         // <table:table> is handled in the text reader even in spreadsheets.
0146                 m_textReader->readElementTableTable(reader);
0147             }
0148             else {
0149                 reader.skipCurrentElement();
0150             }
0151         }
0152         else if (tagName == "table:calculation-settings") {
0153             // FIXME: NYI
0154             reader.skipCurrentElement();
0155         }
0156         else if (tagName == "table:consolidation") {
0157             reader.skipCurrentElement();
0158         }
0159         else if (tagName == "table:content-validation") {
0160             reader.skipCurrentElement();
0161         }
0162         else if (tagName == "table:database-ranges") {
0163             reader.skipCurrentElement();
0164         }
0165         else if (tagName == "table:data-pilot-tables") {
0166             reader.skipCurrentElement();
0167         }
0168         else if (tagName == "table:dde-links") {
0169             reader.skipCurrentElement();
0170         }
0171         else if (tagName == "table:label-ranges") {
0172             reader.skipCurrentElement();
0173         }
0174         else if (tagName == "table:named-expressions") {
0175             reader.skipCurrentElement();
0176         }
0177         else if (tagName == "table:tracked-changes") {
0178             reader.skipCurrentElement();
0179         }
0180         else if (tagName == "text:alphabetical-index-auto-mark-file") {
0181             reader.skipCurrentElement();
0182         }
0183         else if (tagName == "text:dde-connection-decls") {
0184             reader.skipCurrentElement();
0185         }
0186         else if (tagName == "text:sequence-decls") {
0187             reader.skipCurrentElement();
0188         }
0189         else if (tagName == "text:user-field-decls") {
0190             reader.skipCurrentElement();
0191         }
0192         else if (tagName == "text:variable-decls") {
0193             reader.skipCurrentElement();
0194         }
0195         else {
0196         reader.skipCurrentElement();
0197         }
0198         DEBUG_READING("loop-end");
0199     }
0200 
0201     backend->elementOfficeSpreadsheet(reader, m_context);
0202     DEBUGEND();
0203 }
0204 
0205 
0206 // ----------------------------------------------------------------
0207 //                             Other functions