~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to filters/libmsooxml/MsooXmlImport.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
125
125
}
126
126
 
127
127
KoFilter::ConversionStatus MsooXmlImport::copyFile(const QString& sourceName,
128
 
        const QString& destinationName)
 
128
        const QString& destinationName, bool oleFile)
129
129
{
130
130
    if (!m_zip || !m_outputStore) {
131
131
        return KoFilter::UsageError;
132
132
    }
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;
 
139
    return status;
 
140
}
 
141
 
 
142
KoFilter::ConversionStatus MsooXmlImport::imageSize(const QString& sourceName, QSize& size)
 
143
{
 
144
    if (!m_zip) {
 
145
        return KoFilter::UsageError;
 
146
    }
 
147
 
 
148
    QString errorMessage;
 
149
    KoFilter::ConversionStatus status = KoFilter::OK;
 
150
 
 
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);
 
154
 
 
155
        if (status != KoFilter::OK)
 
156
            size = QSize(-1, -1);
 
157
        m_imageSizes.insert(sourceName, size);
 
158
    }
 
159
    else {
 
160
        size = it.value();
 
161
    }
 
162
 
136
163
//! @todo transmit the error to the GUI...
137
164
    kDebug() << errorMessage;
138
165
    return status;
144
171
    QString& errorMessage, MsooXmlReaderContext* context, bool *pathFound)
145
172
{
146
173
    *pathFound = false;
147
 
    if (!m_zip) {
148
 
        return KoFilter::UsageError;
149
 
    }
150
 
    const QString path = m_contentTypes.value(contentType);
151
 
 
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;
157
180
    }
 
181
    KoFilter::ConversionStatus status = loadAndParseDocumentFromFileInternal(
 
182
        fileName, reader, writers, errorMessage, context, pathFound);
 
183
    *pathFound = status != KoFilter::FileNotFound;
 
184
    return status;
 
185
}
158
186
 
159
 
    *pathFound = true;
160
 
    return Utils::loadAndParseDocument(
161
 
               reader, m_zip, writers, errorMessage, path, context);
 
187
// private
 
188
KoFilter::ConversionStatus MsooXmlImport::loadAndParseDocumentFromFileInternal(
 
189
    const QString& fileName, MsooXmlReader *reader, KoOdfWriters *writers,
 
190
    QString& errorMessage, MsooXmlReaderContext* context, bool *pathFound)
 
191
{
 
192
    *pathFound = false;
 
193
    if (!m_zip) {
 
194
        return KoFilter::UsageError;
 
195
    }
 
196
    KoFilter::ConversionStatus status = Utils::loadAndParseDocument(
 
197
               reader, m_zip, writers, errorMessage, fileName, context);
 
198
    *pathFound = status != KoFilter::FileNotFound;
 
199
    return status;
162
200
}
163
201
 
164
202
// protected
167
205
    QString& errorMessage, MsooXmlReaderContext* context)
168
206
{
169
207
    bool pathFound;
170
 
    return loadAndParseDocumentInternal( contentType, reader, writers, errorMessage, context, &pathFound);
171
 
}
172
 
 
 
208
    return loadAndParseDocumentInternal(contentType, reader, writers, errorMessage, context, &pathFound);
 
209
}
 
210
 
 
211
// protected
 
212
KoFilter::ConversionStatus MsooXmlImport::loadAndParseDocumentFromFile(
 
213
    const QString& fileName, MsooXmlReader *reader, KoOdfWriters *writers,
 
214
    QString& errorMessage, MsooXmlReaderContext* context)
 
215
{
 
216
    bool pathFound;
 
217
    return loadAndParseDocumentFromFileInternal(fileName, reader, writers, errorMessage, context, &pathFound);
 
218
}
 
219
 
 
220
// protected
173
221
KoFilter::ConversionStatus MsooXmlImport::loadAndParseDocumentIfExists(
174
222
    const QByteArray& contentType, MsooXmlReader *reader, KoOdfWriters *writers,
175
223
    QString& errorMessage, MsooXmlReaderContext* context)
182
230
    return status;
183
231
}
184
232
 
 
233
// protected
 
234
KoFilter::ConversionStatus MsooXmlImport::loadAndParseDocumentFromFileIfExists(
 
235
    const QString& fileName, MsooXmlReader *reader, KoOdfWriters *writers,
 
236
    QString& errorMessage, MsooXmlReaderContext* context)
 
237
{
 
238
    bool pathFound;
 
239
    const KoFilter::ConversionStatus status( loadAndParseDocumentFromFileInternal(
 
240
        fileName, reader, writers, errorMessage, context, &pathFound) );
 
241
    if (!pathFound)
 
242
        return KoFilter::OK;
 
243
    return status;
 
244
}
 
245
 
185
246
KoFilter::ConversionStatus MsooXmlImport::loadAndParseDocument(
186
247
    MsooXmlReader *reader, const QString& path,
187
248
    MsooXmlReaderContext* context)
211
272
 
212
273
KoFilter::ConversionStatus MsooXmlImport::openFile(KoOdfWriters *writers, QString& errorMessage)
213
274
{
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!";
218
279
        return status;
219
280
    }
220
 
 
221
281
    RETURN_IF_ERROR( Utils::loadContentTypes(m_contentTypesXML, m_contentTypes) )
 
282
 
 
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) )
 
287
    }
 
288
 
 
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) )
 
293
    }
 
294
 
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);
233
306
}
234
307
 
235
 
KoFilter::ConversionStatus MsooXmlImport::parseThemes(QMap<QString, MSOOXML::DrawingMLTheme*>& themes,
236
 
    KoOdfWriters *writers, QString& errorMessage)
237
 
{
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()) {
245
 
        // theme loaded
246
 
        themes.insert(theme.get()->name, theme.get());
247
 
        theme.release();
248
 
    }
249
 
    return KoFilter::OK;
250
 
}
251
 
 
252
308
#include "MsooXmlImport.moc"