1 /* This file is part of the KDE project
2 
3    Copyright (C) 2012-2014 Inge Wallin            <inge@lysator.liu.se>
4 
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Library General Public
7    License as published by the Free Software Foundation; either
8    version 2 of the License, or (at your option) any later version.
9 
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Library General Public License for more details.
14 
15    You should have received a copy of the GNU Library General Public License
16    along with this library; see the file COPYING.LIB.  If not, write to
17    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18    Boston, MA 02110-1301, USA.
19 */
20 
21 
22 // Own
23 #include "OdsReader.h"
24 
25 // Qt
26 #include <QStringList>
27 #include <QBuffer>
28 
29 // KF5
30 #include <klocalizedstring.h>
31 
32 // Calligra
33 #include <KoStore.h>
34 #include <KoXmlStreamReader.h>
35 #include <KoXmlNS.h>
36 #include <KoXmlWriter.h>  // For copyXmlElement
37 #include <KoOdfReadStore.h>
38 
39 // Reader library
40 #include "OdsReaderBackend.h"
41 #include "OdfReaderContext.h"
42 #include "OdfTextReader.h"
43 #include "OdfReaderDebug.h"
44 
45 
46 #if 0
47 static int debugIndent = 0;
48 #define DEBUGSTART() \
49     ++debugIndent; \
50     DEBUG_READING("entering")
51 #define DEBUGEND() \
52     DEBUG_READING("exiting"); \
53     --debugIndent
54 #define DEBUG_READING(param) \
55     debugOdfReader << QString("%1").arg(" ", debugIndent * 2) << param << ": " \
56     << (reader.isStartElement() ? "start": (reader.isEndElement() ? "end" : "other")) \
57     << reader.qualifiedName().toString()
58 #else
59 #define DEBUGSTART() \
60     // NOTHING
61 #define DEBUGEND() \
62     // NOTHING
63 #define DEBUG_READING(param) \
64     // NOTHING
65 #endif
66 
67 
OdsReader()68 OdsReader::OdsReader()
69     : OdfReader()
70 {
71 }
72 
~OdsReader()73 OdsReader::~OdsReader()
74 {
75 }
76 
77 
78 #if 0
79 // This is a template function for the reader library.
80 // Copy this one and change the name and fill in the code.
81 void OdsReader::readElementNamespaceTagname(KoXmlStreamReader &reader)
82 {
83    DEBUGSTART();
84 
85     // <namespace:tagname> has the following children in ODF 1.2:
86     //   FILL IN THE CHILDREN LIKE THIS EXAMPLE (taken from office:document-content):
87     //          <office:automatic-styles> 3.15.3
88     //          <office:body> 3.3
89     //          <office:font-face-decls> 3.14
90     //          <office:scripts> 3.12.
91     while (reader.readNextStartElement()) {
92         QString tagName = reader.qualifiedName().toString();
93 
94         if (tagName == "office:automatic-styles") {
95             // FIXME: NYI
96         }
97         else if (tagName == "office:body") {
98             readElementOfficeBody(reader);
99         }
100         ...  MORE else if () HERE
101         else {
102             reader.skipCurrentElement();
103         }
104     }
105 
106     m_backend->elementNamespaceTagname(reader, m_context);
107     DEBUGEND();
108 }
109 #endif
110 
111 
112 // Reimplemented from OdfReader
readElementOfficeSpreadsheet(KoXmlStreamReader & reader)113 void OdsReader::readElementOfficeSpreadsheet(KoXmlStreamReader &reader)
114 {
115     DEBUGSTART();
116     OdsReaderBackend *backend = dynamic_cast<OdsReaderBackend *>(m_backend);
117     backend->elementOfficeSpreadsheet(reader, m_context);
118 
119     // <office:spreadsheet> has the following children in ODF 1.2:
120     //
121     //          <table:calculation-settings> 9.4.1
122     //          <table:consolidation> 9.7
123     //          <table:content-validations> 9.4.4
124     //          <table:database-ranges> 9.4.14
125     //          <table:data-pilot-tables> 9.6.2
126     //          <table:dde-links> 9.8
127     //          <table:label-ranges> 9.4.10
128     //          <table:named-expressions> 9.4.11
129     //   [done] <table:table> 9.1.2
130     //          <table:tracked-changes> 9.9.2
131     //          <text:alphabetical-index-auto-mark-file> 8.8.3
132     //          <text:dde-connection-decls> 14.6.2
133     //          <text:sequence-decls> 7.4.11
134     //          <text:user-field-decls> 7.4.7
135     //          <text:variable-decls> 7.4.2
136 
137     //
138     // FIXME: For now, only very few of these are handled.
139     while (reader.readNextStartElement()) {
140         DEBUG_READING("loop-start");
141 
142         QString tagName = reader.qualifiedName().toString();
143         if (tagName == "table:table") {
144             if (m_textReader) {
145 		// <table:table> is handled in the text reader even in spreadsheets.
146                 m_textReader->readElementTableTable(reader);
147             }
148             else {
149                 reader.skipCurrentElement();
150             }
151         }
152         else if (tagName == "table:calculation-settings") {
153             // FIXME: NYI
154             reader.skipCurrentElement();
155         }
156         else if (tagName == "table:consolidation") {
157             reader.skipCurrentElement();
158         }
159         else if (tagName == "table:content-validation") {
160             reader.skipCurrentElement();
161         }
162         else if (tagName == "table:database-ranges") {
163             reader.skipCurrentElement();
164         }
165         else if (tagName == "table:data-pilot-tables") {
166             reader.skipCurrentElement();
167         }
168         else if (tagName == "table:dde-links") {
169             reader.skipCurrentElement();
170         }
171         else if (tagName == "table:label-ranges") {
172             reader.skipCurrentElement();
173         }
174         else if (tagName == "table:named-expressions") {
175             reader.skipCurrentElement();
176         }
177         else if (tagName == "table:tracked-changes") {
178             reader.skipCurrentElement();
179         }
180         else if (tagName == "text:alphabetical-index-auto-mark-file") {
181             reader.skipCurrentElement();
182         }
183         else if (tagName == "text:dde-connection-decls") {
184             reader.skipCurrentElement();
185         }
186         else if (tagName == "text:sequence-decls") {
187             reader.skipCurrentElement();
188         }
189         else if (tagName == "text:user-field-decls") {
190             reader.skipCurrentElement();
191         }
192         else if (tagName == "text:variable-decls") {
193             reader.skipCurrentElement();
194         }
195         else {
196 	    reader.skipCurrentElement();
197         }
198         DEBUG_READING("loop-end");
199     }
200 
201     backend->elementOfficeSpreadsheet(reader, m_context);
202     DEBUGEND();
203 }
204 
205 
206 // ----------------------------------------------------------------
207 //                             Other functions
208