File indexing completed on 2024-05-12 16:37:11

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2005 David Faure <faure@kde.org>
0003  * Copyright (C) 2007-2009 Thomas Zander <zander@kde.org>
0004  * Copyright (C) 2007 Sebastian Sauer <mail@dipe.org>
0005  * Copyright (C) 2007-2008 Thorsten Zachmann <zachmann@kde.org>
0006  *
0007  * This library is free software; you can redistribute it and/or
0008  * modify it under the terms of the GNU Library General Public
0009  * License as published by the Free Software Foundation; either
0010  * version 2 of the License, or (at your option) any later version.
0011  *
0012  * This library is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  * Library General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Library General Public License
0018  * along with this library; see the file COPYING.LIB.  If not, write to
0019  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020  * Boston, MA 02110-1301, USA.
0021  */
0022 
0023 #ifndef KWODFLOADER_H
0024 #define KWODFLOADER_H
0025 
0026 #include "Words.h"
0027 #include "KoXmlReaderForward.h"
0028 
0029 #include <KoTextLoader.h>
0030 #include <QPointer>
0031 
0032 class KWDocument;
0033 class KoOdfReadStore;
0034 class KoOdfLoadingContext;
0035 class KoShapeLoadingContext;
0036 class KWPageStyle;
0037 class QTextDocument;
0038 class QTextCursor;
0039 
0040 /**
0041  * Class that has a lot of the OpenDocument (ODF) loading code for Words.
0042  */
0043 class KWOdfLoader : public QObject
0044 {
0045     Q_OBJECT
0046 public:
0047     /**
0048      * Constructor
0049      * @param document the document this loader will work for.
0050      */
0051     explicit KWOdfLoader(KWDocument *document);
0052     ~KWOdfLoader() override;
0053 
0054     KWDocument* document() const;
0055 
0056     /**
0057      *  @brief Loads an OASIS OpenDocument from a store.
0058      *  This implements the KoDocument::loadOdf method.
0059      */
0060     bool load(KoOdfReadStore &odfStore);
0061 
0062 Q_SIGNALS:
0063     /**
0064      * This signal is emitted during loading with a percentage within 1-100 range
0065      * \param percent the progress as a percentage
0066      */
0067     void progressUpdate(int percent);
0068 
0069 
0070 private:
0071     enum HFLoadType {
0072         LoadHeader,
0073         LoadFooter
0074     };
0075 
0076     void loadSettings(const KoXmlDocument &settings, QTextDocument *textDoc);
0077     void loadMasterPageStyles(KoShapeLoadingContext& context);
0078     void loadHeaderFooter(KoShapeLoadingContext &context, KWPageStyle &pageStyle, const KoXmlElement &masterPageStyle, HFLoadType headerFooter);
0079     void loadFinished(KoOdfLoadingContext &context, QTextCursor &cursor);
0080 
0081     /// helper function to create a KWTextFrameSet+KWFrame for a header/footer.
0082     void loadHeaderFooterFrame(KoShapeLoadingContext &context, const KWPageStyle &pageStyle, const KoXmlElement &elem, Words::TextFrameSetType fsType);
0083 
0084 private:
0085     /// The Words document.
0086     QPointer<KWDocument> m_document;
0087 };
0088 
0089 #endif