File: MsooXmlImport.h

package info (click to toggle)
calligra 1%3A2.9.11%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 189,332 kB
  • sloc: cpp: 919,806; xml: 27,759; ansic: 10,472; python: 8,190; perl: 2,724; yacc: 2,557; sh: 1,675; lex: 1,431; java: 1,304; sql: 903; ruby: 734; makefile: 48
file content (188 lines) | stat: -rw-r--r-- 7,960 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
 * This file is part of Office 2007 Filters for Calligra
 * Copyright (C) 2002 Laurent Montel <lmontel@mandrakesoft.com>
 * Copyright (C) 2003 David Faure <faure@kde.org>
 * Copyright (C) 2002, 2003, 2004 Nicolas GOUTTE <goutte@kde.org>
 * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
 *
 * Contact: Suresh Chande suresh.chande@nokia.com
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

#ifndef MSOOXMLIMPORT_H
#define MSOOXMLIMPORT_H

#include "komsooxml_export.h"

#include <QByteArray>
#include <QHash>
#include <QVariant>

#include <KoBorder.h>
#include <KoOdfExporter.h>
#include <KoXmlReader.h>

#include "PredefinedShapeHelper.h"

class QSize;
class KZip;
class KTemporaryFile;
class KoStore;

namespace MSOOXML
{

class MsooXmlReader;
class MsooXmlReaderContext;
class MsooXmlRelationships;

//! A base class for MSOOXML-to-ODF import filters
class KOMSOOXML_EXPORT MsooXmlImport : public KoOdfExporter
{
    Q_OBJECT
public:
    MsooXmlImport(const QString& bodyContentElement, QObject * parent);

    virtual ~MsooXmlImport();

    KoStore* outputStore() const { return m_outputStore; }

    //! KoFilter::UsageError is returned if this method is called outside
    //! of the importing process, i.e. not from within parseParts().
    KoFilter::ConversionStatus loadAndParseDocument(MsooXmlReader *reader, const QString& path,
            MsooXmlReaderContext* context = 0);

    //! KoFilter::UsageError is returned if this method is called outside
    //! of the importing process, i.e. not from within parseParts().
    KoFilter::ConversionStatus loadAndParseDocument(MsooXmlReader *reader, const QString& path,
            QString& errorMessage,
            MsooXmlReaderContext* context = 0);

    //! Loads a file from a device
    KoFilter::ConversionStatus loadAndParseFromDevice(MsooXmlReader* reader, QIODevice* device,
            MsooXmlReaderContext* context);

    /*! Copies file @a sourceName from the input archive to the output document
    under @a destinationName name. @return KoFilter::OK on success.
    On failure @a errorMessage is set.
    KoFilter::UsageError is returned if this method is called outside
    of the importing process, i.e. not from within parseParts(). */
    KoFilter::ConversionStatus copyFile(const QString& sourceName,
                                        const QString& destinationName,
                                        bool oleFile);

    /* Creates an image to the resulting odf with the given name */
    KoFilter::ConversionStatus createImage(const QImage& source,
                                           const QString& destinationName);

    /*! @return image from the file for modifications */
    KoFilter::ConversionStatus imageFromFile(const QString& sourceName, QImage& image);

    /*! @return size of image file @a sourceName read from zip archive @a zip.
    Size of the image is returned in @a size.
    @return KoFilter::OK on success.
    On failure @a errorMessage is set. */
    KoFilter::ConversionStatus imageSize(const QString& sourceName, QSize& size);

    //! Helper class to get information about predefined ooxml shapes
    PredefinedShapeHelper m_shapeHelper;

    /*! report progress of the filter */
    void reportProgress(unsigned progress);

protected:
    virtual KoFilter::ConversionStatus createDocument(KoStore *outputStore,
                                                      KoOdfWriters *writers);

    virtual void writeConfigurationSettings(KoXmlWriter* settings) const;

    bool isPasswordProtectedFile(QString &filename);
    KTemporaryFile* tryDecryptFile(QString &filename);

    virtual KoFilter::ConversionStatus parseParts(KoOdfWriters *writers,
            MsooXmlRelationships *relationships, QString& errorMessage) = 0;

    //! KoFilter::UsageError is returned if this method is called outside
    //! of the importing process, i.e. not from within parseParts().
    KoFilter::ConversionStatus loadAndParseDocument(
        const QByteArray& contentType, MsooXmlReader *reader, KoOdfWriters *writers,
        QString& errorMessage, MsooXmlReaderContext* context = 0);

    //! Like @ref loadAndParseDocument(const QByteArray&, MsooXmlReader*, KoOdfWriters*, QString&, MsooXmlReaderContext*)
    //! but file name is provided directly instead of content type
    KoFilter::ConversionStatus loadAndParseDocumentFromFile(
        const QString& fileName, MsooXmlReader *reader, KoOdfWriters *writers,
        QString& errorMessage, MsooXmlReaderContext* context);

    //! Like @ref loadAndParseDocument(const QByteArray&, MsooXmlReader*, KoOdfWriters*, QString&, MsooXmlReaderContext*)
    //! but return KoFilter::OK if the document for the content type is not found.
    KoFilter::ConversionStatus loadAndParseDocumentIfExists(
        const QByteArray& contentType, MsooXmlReader *reader, KoOdfWriters *writers,
        QString& errorMessage, MsooXmlReaderContext* context = 0);

    //! Like @ref loadAndParseDocumentIfExists(const QByteArray&, MsooXmlReader*, KoOdfWriters*, QString&, MsooXmlReaderContext*)
    //! but file name is provided directly instead of content type
    KoFilter::ConversionStatus loadAndParseDocumentFromFileIfExists(
        const QString& fileName, MsooXmlReader *reader, KoOdfWriters *writers,
        QString& errorMessage, MsooXmlReaderContext* context = 0);

    //! @return all part names.
    QMultiHash<QByteArray, QByteArray> partNames() const { return m_contentTypes; }
    //! @return part names associated with @a contentType
    QList<QByteArray> partNames(const QByteArray& contentType) const { return m_contentTypes.values(contentType); }

    QMap<QString, QVariant> documentProperties() const { return m_documentProperties; }
    QVariant documentProperty(const QString& propertyName) const { return m_documentProperties.value(propertyName); }

protected:
    KoFilter::ConversionStatus loadAndParse(const QString& filename,
                                            KoXmlDocument& doc, QString& errorMessage);

private:
    //! Opens file for converting and performs convertions.
    //! @return status of convertion.
    KoFilter::ConversionStatus openFile(KoOdfWriters *writers, QString& errorMessage);

    KoFilter::ConversionStatus loadAndParseDocumentInternal(
        const QByteArray& contentType, MsooXmlReader *reader, KoOdfWriters *writers,
        QString& errorMessage, MsooXmlReaderContext* context, bool *pathFound);

    KoFilter::ConversionStatus loadAndParseDocumentFromFileInternal(
        const QString& fileName, MsooXmlReader *reader, KoOdfWriters *writers,
        QString& errorMessage, MsooXmlReaderContext* context, bool *pathFound);

    KZip* m_zip; //!< Input zip file

    KoStore* m_outputStore; //!< output store used for copying files

    //! XML from "[Content_Types].xml" file.
    KoXmlDocument m_contentTypesXML;
    //! Content types from m_contentTypesXML: ContentType -> PartName mapping
    QMultiHash<QByteArray, QByteArray> m_contentTypes;

    //! Content types from m_appXML: tagName -> content mapping
    QMap<QString, QVariant> m_documentProperties;

    //! XML with document contents, typically /word/document.xml
    KoXmlDocument m_documentXML;

    QMap<QString, QSize> m_imageSizes; //!< collects image sizes to avoid multiple checks
};

} // namespace MSOOXML

#endif