File: KoOdfWriteStore.h

package info (click to toggle)
koffice 1%3A2.2.1-4
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 157,656 kB
  • ctags: 110,762
  • sloc: cpp: 889,358; xml: 22,758; ansic: 6,533; python: 5,224; perl: 2,771; sh: 1,805; yacc: 1,304; ruby: 1,219; sql: 720; lex: 455; makefile: 76
file content (118 lines) | stat: -rw-r--r-- 4,173 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
/* This file is part of the KDE project
   Copyright (C) 2005 David Faure <faure@kde.org>
   Copyright (C) 2007 Thorsten Zachmann <zachmann@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/
#ifndef KOODFWRITESTORE_H
#define KOODFWRITESTORE_H

class QIODevice;
class KoXmlWriter;
class KoStore;

/**
 * Helper class around KoStore for writing out ODF files.
 * This class helps solving the problem that automatic styles must be before
 * the body, but it's easier to iterate over the application's objects only
 * once. So we open a KoXmlWriter into a memory buffer, write the body into it,
 * collect automatic styles while doing that, write out automatic styles,
 * and then copy the body XML from the buffer into the real KoXmlWriter.
 *
 * The typical use of this class is therefore:
 *   - write body into bodyWriter() and collect auto styles
 *   - write auto styles into contentWriter()
 *   - call closeContentWriter()
 *   - write other files into the store (styles.xml, settings.xml etc.)
 *
 *
 * TODO: maybe we could encapsulate a bit more things, to e.g. handle
 * adding manifest entries automatically.
 *
 * @author: David Faure <faure@kde.org>
 */
#include "koodf_export.h"

class KOODF_EXPORT KoOdfWriteStore
{
public:
    /// @param store recontents the property of the caller
    explicit KoOdfWriteStore(KoStore* store);

    ~KoOdfWriteStore();

    /**
     * Return an XML writer for saving Oasis XML into the device @p dev,
     * including the XML processing instruction,
     * and the root element with all its namespaces.
     * You can add more namespaces afterwards with addAttribute.
     *
     * @param dev the device into which the XML will be written.
     * @param rootElementName the tag name of the root element.
     *    This is either office:document, office:document-content,
     *    office:document-styles, office:document-meta or office:document-settings
     * @return the KoXmlWriter instance. It becomes owned by the caller, which
     * must delete it at some point.
     *
     * Once done with writing the contents of the root element, you
     * will need to call endElement(); endDocument(); before destroying the KoXmlWriter.
     */
    static KoXmlWriter* createOasisXmlWriter(QIODevice* dev, const char* rootElementName);

    KoStore* store() const;

    /**
     * Open contents.xml for writing and return the KoXmlWriter
     */
    KoXmlWriter* contentWriter();

    /**
     * Open another KoXmlWriter for writing out the contents
     * into a temporary file, to collect automatic styles while doing that.
     */
    KoXmlWriter* bodyWriter();

    /**
     * This will copy the body into the content writer,
     * delete the bodyWriter and the contentWriter, and then
     * close contents.xml.
     */
    bool closeContentWriter();

    // For other files in the store, use open/addManifestEntry/KoStoreDevice/createOasisXmlWriter/close

    /**
     * Create and return a manifest writer. It will write to a memory buffer.
     */
    KoXmlWriter* manifestWriter(const char* mimeType);

    /**
     * Return the manifest writer. It has to be created by manifestWriter( mimeType ) before you can use
     * this function.
     */
    KoXmlWriter* manifestWriter();

    /**
     * Close the manifest writer, writing its contents to manifest.xml
     */
    bool closeManifestWriter();

private:
    struct Private;
    Private * const d;
};

#endif /* KOODFWRITESTORE_H */