~smartboyhw/ubuntu/raring/calligra/2.6.0-0ubuntu1

« back to all changes in this revision

Viewing changes to filters/words/epub/OdfParser.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-10-23 21:09:16 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20121023210916-m82w6zxnxhaxz7va
Tags: 1:2.5.90-0ubuntu1
* New upstream alpha release (LP: #1070436)
  - Add libkactivities-dev and libopenimageio-dev to build-depends
  - Add kubuntu_build_calligraactive.diff to build calligraactive by default
  - Add package for calligraauthor and move files that are shared between
    calligrawords and calligraauthor to calligrawords-common
* Document the patches
* Remove numbers from patches so they follow the same naming scheme as
  the rest of our patches.
* calligra-data breaks replaces krita-data (<< 1:2.5.3) (LP: #1071686)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
 
 
3
   Copyright (C) 2012 Mojtaba Shahi Senobari <mojtaba.shahi3000@gmail.com>
 
4
   Copyright (C) 2012 Inge Wallin            <inge@lysator.liu.se>
 
5
 
 
6
   This library is free software; you can redistribute it and/or
 
7
   modify it under the terms of the GNU Library General Public
 
8
   License as published by the Free Software Foundation; either
 
9
   version 2 of the License, or (at your option) any later version.
 
10
 
 
11
   This library is distributed in the hope that it will be useful,
 
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
   Library General Public License for more details.
 
15
 
 
16
   You should have received a copy of the GNU Library General Public License
 
17
   along with this library; see the file COPYING.LIB.  If not, write to
 
18
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
19
 * Boston, MA 02110-1301, USA.
 
20
*/
 
21
 
 
22
 
 
23
// Own
 
24
#include "OdfParser.h"
 
25
 
 
26
// Qt
 
27
#include <QSvgGenerator>
 
28
#include <QBuffer>
 
29
#include <QPainter>
 
30
 
 
31
// KDE
 
32
#include <kdebug.h>
 
33
#include <kpluginfactory.h>
 
34
 
 
35
// Calligra
 
36
#include <KoFilterChain.h>
 
37
#include <KoOdfWriteStore.h>
 
38
#include <KoGenStyles.h>
 
39
#include <KoXmlWriter.h>
 
40
#include <KoStoreDevice.h>
 
41
#include <KoXmlReader.h>
 
42
#include <KoXmlNS.h>
 
43
 
 
44
OdfParser::OdfParser()
 
45
{
 
46
}
 
47
 
 
48
OdfParser::~OdfParser()
 
49
{
 
50
}
 
51
 
 
52
 
 
53
 
 
54
KoFilter::ConversionStatus OdfParser::parseMetadata(KoStore *odfStore,
 
55
                                                    QHash<QString, QString> &metadata)
 
56
{
 
57
    if (!odfStore->open("meta.xml")) {
 
58
        kDebug(30517) << "Cannot open meta.xml";
 
59
        return KoFilter::FileNotFound;
 
60
    }
 
61
 
 
62
    KoXmlDocument doc;
 
63
    QString errorMsg;
 
64
    int errorLine;
 
65
    int errorColumn;
 
66
    if (!doc.setContent(odfStore->device(), true, &errorMsg, &errorLine, &errorColumn)) {
 
67
        kDebug() << "Error occurred while parsing meta.xml "
 
68
                 << errorMsg << " in Line: " << errorLine
 
69
                 << " Column: " << errorColumn;
 
70
        odfStore->close();
 
71
        return KoFilter::ParsingError;
 
72
    }
 
73
 
 
74
    KoXmlNode childNode = doc.documentElement();
 
75
    childNode = KoXml::namedItemNS(childNode, KoXmlNS::office, "meta");
 
76
    KoXmlElement element;
 
77
    forEachElement (element, childNode) {
 
78
        metadata.insert(element.tagName(), element.text());
 
79
    }
 
80
 
 
81
    odfStore->close();
 
82
    return KoFilter::OK;
 
83
}
 
84
 
 
85
 
 
86
KoFilter::ConversionStatus OdfParser::parseManifest(KoStore *odfStore,
 
87
                                                    QHash<QString, QString> &manifest)
 
88
{
 
89
    if (!odfStore->open("META-INF/manifest.xml")) {
 
90
        kDebug(30517) << "Cannot to open manifest.xml.";
 
91
        return KoFilter::FileNotFound;
 
92
    }
 
93
 
 
94
    KoXmlDocument doc;
 
95
    QString errorMsg;
 
96
    int errorLine, errorColumn;
 
97
    if (!doc.setContent(odfStore->device(), true, &errorMsg, &errorLine, &errorColumn)) {
 
98
        kDebug() << "Error occurred while parsing meta.xml "
 
99
                 << errorMsg << " in Line: " << errorLine
 
100
                 << " Column: " << errorColumn;
 
101
        return KoFilter::ParsingError;
 
102
    }
 
103
 
 
104
    KoXmlNode childNode = doc.documentElement();
 
105
    KoXmlElement nodeElement;
 
106
    forEachElement (nodeElement, childNode) {
 
107
        QString path = nodeElement.attribute("full-path");
 
108
        QString type = nodeElement.attribute("media-type");
 
109
 
 
110
        manifest.insert(path, type);
 
111
    }
 
112
 
 
113
    odfStore->close();
 
114
    return KoFilter::OK;
 
115
}