Commit e8959a48 authored by Thorsten Zachmann's avatar Thorsten Zachmann

o refactor to make functions available for future usage.

  Move document loading and paring to KoOdfReadStore.
  rename loadOasis -> loadOdf
  pass a KoOdfReadStore to loadOdf

svn path=/trunk/koffice/; revision=732357
parent d4051f40
......@@ -4,6 +4,7 @@
* Copyright (c) 2001 Toshitaka Fujioka <fujioka@kde.org>
* Copyright (c) 2002, 2003 Patrick Julien <freak@codepimps.org>
* Copyright (c) 2004-2007 Boudewijn Rempt <boud@valdyas.org>
* Copyright (C) 2007 Thorsten Zachmann <zachmann@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -51,6 +52,7 @@
#include <KoFilterManager.h>
#include <KoID.h>
#include <KoMainWindow.h>
#include <KoOdfReadStore.h>
#include <KoOdfWriteStore.h>
#include <KoQueryTrader.h>
#include <KoStore.h>
......@@ -232,14 +234,14 @@ QDomDocument KisDoc2::saveXML()
return doc;
}
bool KisDoc2::loadOasis( const KoXmlDocument& doc, KoOasisStyles&, const KoXmlDocument&, KoStore* store)
bool KisDoc2::loadOdf( KoOdfReadStore & odfStore )
{
kDebug(41008) <<"loading with OpenRaster";
KoXmlNode root = doc.documentElement();
KoXmlNode root = odfStore.contentDoc().documentElement();
for (KoXmlNode node = root.firstChild(); !node.isNull(); node = node.nextSibling()) {
if (node.isElement() && node.nodeName() == "office:body") {
KoXmlElement elem = node.toElement();
KisOasisLoadVisitor olv(this,store);
KisOasisLoadVisitor olv(this,odfStore.store());
olv.loadImage(elem);
if (!olv.image() )
return false;
......
......@@ -3,6 +3,7 @@
* Copyright (c) 2001 Toshitaka Fujioka <fujioka@kde.org>
* Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
* Copyright (c) 2004-2007 Boudewijn Rempt <boud@valdyas.org<
* Copyright (C) 2007 Thorsten Zachmann <zachmann@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -69,7 +70,7 @@ public:
virtual bool wantExportConfirmation() const { return false; }
virtual bool completeLoading(KoStore *store);
virtual bool completeSaving(KoStore*);
virtual bool loadOasis( const KoXmlDocument&, KoOasisStyles&, const KoXmlDocument&, KoStore* );
virtual bool loadOdf( KoOdfReadStore & odfStore );
virtual bool saveOasis( KoStore*, KoXmlWriter* );
virtual bool loadChildren( KoStore* store);
virtual bool loadXML(QIODevice *, const KoXmlDocument& doc);
......
......@@ -24,6 +24,7 @@
#include <KoXmlWriter.h>
#include <KoXmlReader.h>
#include <KoOasisStyles.h>
#include <KoOdfReadStore.h>
#include <KoOdfWriteStore.h>
#include <KoOasisLoadingContext.h>
#include <KoShapeManager.h>
......@@ -74,17 +75,13 @@ bool KoPADocument::loadXML( QIODevice *, const KoXmlDocument & doc )
return true;
}
bool KoPADocument::loadOasis( const KoXmlDocument & doc, KoOasisStyles& oasisStyles,
const KoXmlDocument & settings, KoStore* store )
bool KoPADocument::loadOdf( KoOdfReadStore & odfStore )
{
Q_UNUSED( doc );
Q_UNUSED( settings );
emit sigProgress( 0 );
KoOasisLoadingContext loadingContext( this, oasisStyles, store );
KoOasisLoadingContext loadingContext( this, odfStore.styles(), odfStore.store() );
KoPALoadingContext paContext( loadingContext );
KoXmlElement content = doc.documentElement();
KoXmlElement content = odfStore.contentDoc().documentElement();
KoXmlElement realBody ( KoDom::namedItemNS( content, KoXmlNS::office, "body" ) );
if ( realBody.isNull() ) {
......@@ -100,7 +97,7 @@ bool KoPADocument::loadOasis( const KoXmlDocument & doc, KoOasisStyles& oasisSty
}
//load master pages
const QHash<QString, KoXmlElement*> masterStyles( oasisStyles.masterPages() );
const QHash<QString, KoXmlElement*> masterStyles( odfStore.styles().masterPages() );
QHash<QString, KoXmlElement*>::const_iterator it( masterStyles.constBegin() );
for ( ; it != masterStyles.constEnd(); ++it )
{
......
......@@ -47,8 +47,7 @@ public:
void paintContent( QPainter &painter, const QRect &rect);
bool loadXML( QIODevice *, const KoXmlDocument & doc );
bool loadOasis( const KoXmlDocument & doc, KoOasisStyles& oasisStyles,
const KoXmlDocument & settings, KoStore* store );
bool loadOdf( KoOdfReadStore & odfStore );
bool saveOasis( KoStore* store, KoXmlWriter* manifestWriter );
......
......@@ -1993,35 +1993,11 @@ bool KoDocument::loadFromStore( KoStore* _store, const QString& url )
bool KoDocument::loadOasisFromStore( KoStore* store )
{
KoOasisStyles oasisStyles;
KoXmlDocument contentDoc;
KoXmlDocument settingsDoc;
KoOdfReadStore oasisStore( store );
bool ok = oasisStore.loadAndParse( "content.xml", contentDoc, d->lastErrorMessage );
if ( !ok )
KoOdfReadStore odfStore( store );
if ( ! odfStore.loadAndParse( d->lastErrorMessage ) ) {
return false;
KoXmlDocument stylesDoc;
(void)oasisStore.loadAndParse( "styles.xml", stylesDoc, d->lastErrorMessage );
// Load styles from style.xml
oasisStyles.createStyleMap( stylesDoc, true );
// Also load styles from content.xml
oasisStyles.createStyleMap( contentDoc, false );
// TODO post 1.4, pass manifestDoc to the apps so that they don't have to do it themselves
// (when calling KoDocumentChild::loadOasisDocument)
//QDomDocument manifestDoc;
//KoOdfReadStore oasisStore( store );
//if ( !oasisStore.loadAndParse( "tar:/META-INF/manifest.xml", manifestDoc, d->lastErrorMessage ) )
// return false;
if ( store->hasFile( "settings.xml" ) ) {
(void)oasisStore.loadAndParse( "settings.xml", settingsDoc, d->lastErrorMessage );
}
if ( !loadOasis( contentDoc, oasisStyles, settingsDoc, store ) )
return false;
return true;
return loadOdf( odfStore );
}
bool KoDocument::addVersion( const QString& comment )
......
......@@ -40,6 +40,7 @@ class QXmlSimpleReader;
class QUndoCommand;
class KoStore;
class KoOdfReadStore;
class KoMainWindow;
class KoChild;
class KoDocumentChild;
......@@ -495,11 +496,10 @@ public:
/**
* Reimplement this method to load the contents of your %KOffice document,
* from the XML document ("content.xml"). The styles have been parsed already,
* you can find them in the oasisStyles parameter. The store can be used
* you can find them in the odfStore.styles(). The store can be used
* to load images and embedded documents.
*/
virtual bool loadOasis( const KoXmlDocument & doc, KoOasisStyles& oasisStyles,
const KoXmlDocument & settings, KoStore* store ) = 0;
virtual bool loadOdf( KoOdfReadStore & odfStore ) = 0;
/**
* Reimplement this method to save the contents of your %KOffice document,
......
......@@ -26,6 +26,7 @@
#include <KoXmlReader.h>
#include "KoDocument.h"
#include "KoOasisStyles.h"
#include "KoXmlNS.h"
struct KoOdfReadStore::Private
......@@ -35,6 +36,10 @@ struct KoOdfReadStore::Private
{}
KoStore * store;
KoOasisStyles styles;
KoXmlDocument stylesDoc;
KoXmlDocument contentDoc;
KoXmlDocument settingsDoc;
};
KoOdfReadStore::KoOdfReadStore( KoStore* store )
......@@ -52,6 +57,46 @@ KoStore * KoOdfReadStore::store() const
return d->store;
}
KoOasisStyles & KoOdfReadStore::styles()
{
return d->styles;
}
const KoXmlDocument & KoOdfReadStore::contentDoc() const
{
return d->contentDoc;
}
const KoXmlDocument & KoOdfReadStore::settingsDoc() const
{
return d->settingsDoc;
}
bool KoOdfReadStore::loadAndParse( QString & errorMessage )
{
if ( !loadAndParse( "content.xml", d->contentDoc, errorMessage ) ) {
return false;
}
loadAndParse( "styles.xml", d->stylesDoc, errorMessage );
// Load styles from style.xml
d->styles.createStyleMap( d->stylesDoc, true );
// Also load styles from content.xml
d->styles.createStyleMap( d->contentDoc, false );
// TODO post 1.4, pass manifestDoc to the apps so that they don't have to do it themselves
// (when calling KoDocumentChild::loadOasisDocument)
//QDomDocument manifestDoc;
//KoOdfReadStore oasisStore( store );
//if ( !oasisStore.loadAndParse( "tar:/META-INF/manifest.xml", manifestDoc, d->lastErrorMessage ) )
// return false;
if ( d->store->hasFile( "settings.xml" ) ) {
loadAndParse( "settings.xml", d->settingsDoc, errorMessage );
}
return true;
}
bool KoOdfReadStore::loadAndParse( const QString& fileName, KoXmlDocument& doc, QString& errorMessage )
{
//kDebug(30003) <<"loadAndParse: Trying to open" << fileName;
......
......@@ -20,8 +20,9 @@
#define KOODFREADSTORE_H
class QString;
class KoStore;
class QIODevice;
class KoStore;
class KoOasisStyles;
class KoXmlDocument;
/**
......@@ -42,6 +43,11 @@ public:
~KoOdfReadStore();
KoStore* store() const;
KoOasisStyles & styles();
const KoXmlDocument & contentDoc() const;
const KoXmlDocument & settingsDoc() const;
bool loadAndParse( QString & errorMessage );
/**
* Load a file from an odf store
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment