127
127
KoFilter::ConversionStatus MsooXmlImport::copyFile(const QString& sourceName,
128
const QString& destinationName)
128
const QString& destinationName, bool oleFile)
130
130
if (!m_zip || !m_outputStore) {
131
131
return KoFilter::UsageError;
133
133
QString errorMessage;
134
134
const KoFilter::ConversionStatus status = Utils::copyFile(
135
m_zip, errorMessage, sourceName, m_outputStore, destinationName);
135
m_zip, errorMessage, sourceName, m_outputStore, destinationName, oleFile);
136
//! @todo transmit the error to the GUI...
137
if(status != KoFilter::OK)
138
kWarning() << "Failed to copyFile:" << errorMessage;
142
KoFilter::ConversionStatus MsooXmlImport::imageSize(const QString& sourceName, QSize& size)
145
return KoFilter::UsageError;
148
QString errorMessage;
149
KoFilter::ConversionStatus status = KoFilter::OK;
151
const QMap<QString, QSize>::ConstIterator it(m_imageSizes.constFind(sourceName));
152
if (it == m_imageSizes.constEnd()) {
153
status = Utils::imageSize(m_zip, errorMessage, sourceName, &size);
155
if (status != KoFilter::OK)
156
size = QSize(-1, -1);
157
m_imageSizes.insert(sourceName, size);
136
163
//! @todo transmit the error to the GUI...
137
164
kDebug() << errorMessage;
144
171
QString& errorMessage, MsooXmlReaderContext* context, bool *pathFound)
146
173
*pathFound = false;
148
return KoFilter::UsageError;
150
const QString path = m_contentTypes.value(contentType);
152
kDebug() << contentType << " path=" << path;
153
if (path.isEmpty()) {
174
const QString fileName = m_contentTypes.value(contentType);
175
kDebug() << contentType << "fileName=" << fileName;
176
if (fileName.isEmpty()) {
154
177
errorMessage = i18n("Could not find path for type %1", QString(contentType));
155
178
kWarning() << errorMessage;
156
179
return KoFilter::FileNotFound;
181
KoFilter::ConversionStatus status = loadAndParseDocumentFromFileInternal(
182
fileName, reader, writers, errorMessage, context, pathFound);
183
*pathFound = status != KoFilter::FileNotFound;
160
return Utils::loadAndParseDocument(
161
reader, m_zip, writers, errorMessage, path, context);
188
KoFilter::ConversionStatus MsooXmlImport::loadAndParseDocumentFromFileInternal(
189
const QString& fileName, MsooXmlReader *reader, KoOdfWriters *writers,
190
QString& errorMessage, MsooXmlReaderContext* context, bool *pathFound)
194
return KoFilter::UsageError;
196
KoFilter::ConversionStatus status = Utils::loadAndParseDocument(
197
reader, m_zip, writers, errorMessage, fileName, context);
198
*pathFound = status != KoFilter::FileNotFound;
167
205
QString& errorMessage, MsooXmlReaderContext* context)
170
return loadAndParseDocumentInternal( contentType, reader, writers, errorMessage, context, &pathFound);
208
return loadAndParseDocumentInternal(contentType, reader, writers, errorMessage, context, &pathFound);
212
KoFilter::ConversionStatus MsooXmlImport::loadAndParseDocumentFromFile(
213
const QString& fileName, MsooXmlReader *reader, KoOdfWriters *writers,
214
QString& errorMessage, MsooXmlReaderContext* context)
217
return loadAndParseDocumentFromFileInternal(fileName, reader, writers, errorMessage, context, &pathFound);
173
221
KoFilter::ConversionStatus MsooXmlImport::loadAndParseDocumentIfExists(
174
222
const QByteArray& contentType, MsooXmlReader *reader, KoOdfWriters *writers,
175
223
QString& errorMessage, MsooXmlReaderContext* context)
234
KoFilter::ConversionStatus MsooXmlImport::loadAndParseDocumentFromFileIfExists(
235
const QString& fileName, MsooXmlReader *reader, KoOdfWriters *writers,
236
QString& errorMessage, MsooXmlReaderContext* context)
239
const KoFilter::ConversionStatus status( loadAndParseDocumentFromFileInternal(
240
fileName, reader, writers, errorMessage, context, &pathFound) );
185
246
KoFilter::ConversionStatus MsooXmlImport::loadAndParseDocument(
186
247
MsooXmlReader *reader, const QString& path,
187
248
MsooXmlReaderContext* context)
212
273
KoFilter::ConversionStatus MsooXmlImport::openFile(KoOdfWriters *writers, QString& errorMessage)
214
static const char *Content_Types_xml = "[Content_Types].xml";
275
static const char *Content_Types_xml = "[Content_Types].xml";
215
276
KoFilter::ConversionStatus status = loadAndParse(Content_Types_xml, m_contentTypesXML, errorMessage);
216
277
if (status != KoFilter::OK) {
217
278
kDebug() << Content_Types_xml << "could not be parsed correctly! Aborting!";
221
281
RETURN_IF_ERROR( Utils::loadContentTypes(m_contentTypesXML, m_contentTypes) )
283
static const char *docPropy_core_xml = "docProps/core.xml";
284
KoXmlDocument coreXML;
285
if (loadAndParse(docPropy_core_xml, coreXML, errorMessage) == KoFilter::OK) {
286
RETURN_IF_ERROR( Utils::loadDocumentProperties(coreXML, m_documentProperties) )
289
static const char *docPropy_app_xml = "docProps/app.xml";
290
KoXmlDocument appXML;
291
if (loadAndParse(docPropy_app_xml, appXML, errorMessage) == KoFilter::OK) {
292
RETURN_IF_ERROR( Utils::loadDocumentProperties(appXML, m_documentProperties) )
222
295
MsooXmlRelationships relationships(*this, writers, errorMessage);
223
296
RETURN_IF_ERROR( parseParts(writers, &relationships, errorMessage) )
224
297
//! @todo sigProgress()
232
305
return Utils::loadAndParse(doc, m_zip, errorMessage, filename);
235
KoFilter::ConversionStatus MsooXmlImport::parseThemes(QMap<QString, MSOOXML::DrawingMLTheme*>& themes,
236
KoOdfWriters *writers, QString& errorMessage)
238
std::auto_ptr<MSOOXML::DrawingMLTheme> theme( new MSOOXML::DrawingMLTheme );
239
MSOOXML::MsooXmlThemesReader themesReader(writers);
240
MSOOXML::MsooXmlThemesReaderContext context(*theme.get());
241
//! @todo use m_contentTypes.values() beacuse multiple paths for themes are expected
242
RETURN_IF_ERROR( loadAndParseDocumentIfExists(
243
MSOOXML::ContentTypes::theme, &themesReader, writers, errorMessage, &context) )
244
if (!theme.get()->name.isEmpty()) {
246
themes.insert(theme.get()->name, theme.get());
252
308
#include "MsooXmlImport.moc"