[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    Page size of ODT document unknown after loading
From:       Jos van den Oever <jos.van.den.oever () kogmbh ! com>
Date:       2009-06-07 10:00:23
Message-ID: 200906071200.24212.jos.van.den.oever () kogmbh ! com
[Download RAW message or body]

Hi all,

I'm looking into how to load KOffice documents into a small application.
After loading an odt document, the width and height of the pages is said to be 
0. This is obviously not right. I would expect that the number of pages as 
well as the size of each page is known after loading a document.

What am I doing wrong? The code I'm using is attached.

Cheers,
Jos


["documentloader.h" (text/x-chdr)]

#ifndef DOCUMENTLOADER_H
#define DOCUMENTLOADER_H

#include <QtCore/QObject>

class KoDocument;

class DocumentLoader : public QObject {
    Q_OBJECT
    class Private;
    Private* const d;
    DocumentLoader(const QString& path);
    ~DocumentLoader();
    void timerEvent(QTimerEvent *);
private slots:
    void slotCompleted();
public:
    static KoDocument* loadDocument(const QString& doc);
};

#endif

["documentloader.cpp" (text/x-c++src)]

#include "documentloader.h"
#include <KoDocument.h>
#include <KDE/KMimeType>
#include <KDE/KParts/ComponentFactory>
#include <QtCore/QAbstractEventDispatcher>
#include <QtCore/QDebug>
#include <QtCore/QCoreApplication>

class DocumentLoader::Private {
public:
    bool completed;
    KoDocument* doc;
};
KoDocument*
DocumentLoader::loadDocument(const QString& path) {
    DocumentLoader loader(path);

    // loop idle for 5 seconds to make sure that the document has been layed out
    QTime now;
    now.start();
    while (now.elapsed() < 15000) {
        QCoreApplication::processEvents();
    }

return loader.d->doc;
}
DocumentLoader::DocumentLoader(const QString& path) :d(new Private()) {
    QString mimetype = KMimeType::findByPath( path )->name();

    d->doc = KParts::ComponentFactory::createPartInstanceFromQuery<KoDocument>(
                 mimetype, QString());

    if (!d->doc) return;

    connect(d->doc, SIGNAL(completed()), SLOT(slotCompleted()));

    KUrl url;
    url.setPath( path );
    d->doc->setCheckAutoSaveFile( false );
    d->doc->setAutoErrorHandlingEnabled( false ); // don't show message boxes
    if ( !d->doc->openUrl( url ) )
        return;
    d->completed = false;
    startTimer(5000); // safety for stopping the loading
    QAbstractEventDispatcher::instance()->unregisterTimers(this);
    qDebug() << "end of constructor";
}
DocumentLoader::~DocumentLoader() {
    delete d;
}
void
DocumentLoader::timerEvent(QTimerEvent *) {
    qDebug() << "timerEvent";
    d->doc->closeUrl();
    d->completed = true;
}
void
DocumentLoader::slotCompleted() {
    qDebug() << "completed";
    d->completed = true;
}

#include "documentloader.moc"

["testdocument.odt" (application/vnd.oasis.opendocument.text)]

_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic