1/* This file is part of the KDE project
2 Copyright 2010 Marijn Kruisselbrink <mkruisselbrink@kde.org>
3 Copyright 2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
4 Copyright 2007 Thorsten Zachmann <zachmann@kde.org>
5 Copyright 2004 Ariya Hidayat <ariya@kde.org>
6 Copyright 2002-2003 Norbert Andres <nandres@web.de>
7 Copyright 2000-2005 Laurent Montel <montel@kde.org>
8 Copyright 2002 John Dailey <dailey@vt.edu>
9 Copyright 2002 Phillip Mueller <philipp.mueller@gmx.de>
10 Copyright 2000 Werner Trobin <trobin@kde.org>
11 Copyright 1999-2000 Simon Hausmann <hausmann@kde.org>
12 Copyright 1999 David Faure <faure@kde.org>
13 Copyright 1998-2000 Torben Weis <weis@kde.org>
14
15 This library is free software; you can redistribute it and/or
16 modify it under the terms of the GNU Library General Public
17 License as published by the Free Software Foundation; either
18 version 2 of the License, or (at your option) any later version.
19
20 This library is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 Library General Public License for more details.
24
25 You should have received a copy of the GNU Library General Public License
26 along with this library; see the file COPYING.LIB. If not, write to
27 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
28 Boston, MA 02110-1301, USA.
29*/
30
31#ifndef CALLIGRA_SHEETS_DOCBASE_H
32#define CALLIGRA_SHEETS_DOCBASE_H
33
34#include <KoDocument.h>
35
36#include "calligra_sheets_export.h"
37
38class KoOasisSettings;
39class KoDocumentResourceManager;
40class KoPart;
41
42#define SHEETS_MIME_TYPE "application/vnd.oasis.opendocument.spreadsheet"
43
44namespace Calligra
45{
46namespace Sheets
47{
48class Map;
49class Sheet;
50class SheetAccessModel;
51
52class CALLIGRA_SHEETS_ODF_EXPORT DocBase : public KoDocument
53{
54 Q_OBJECT
55public:
56 /**
57 * \ingroup OpenDocument
58 */
59 enum SaveFlag { SaveAll, SaveSelected }; // kpresenter and words have have SavePage too
60
61 /**
62 * Creates a new document.
63 * @param part The KoPart that owns the document. XXX: should be removed!
64 */
65 explicit DocBase(KoPart *part);
66 ~DocBase();
67
68 /**
69 * @return list of all documents
70 */
71 static QList<DocBase*> documents();
72
73 virtual void setReadWrite(bool readwrite = true);
74
75 /// reimplemented from KoDocument
76 virtual QByteArray nativeFormatMimeType() const { return SHEETS_MIME_TYPE; }
77 /// reimplemented from KoDocument
78 virtual QByteArray nativeOasisMimeType() const {return SHEETS_MIME_TYPE;}
79 /// reimplemented from KoDocument
80 virtual QStringList extraNativeMimeTypes() const
81 {
82 return QStringList() << "application/vnd.oasis.opendocument.spreadsheet-template"
83 << "application/x-kspread";
84 }
85
86 /**
87 * @return the MIME type of KSpread document
88 */
89 virtual QByteArray mimeType() const {
90 return SHEETS_MIME_TYPE;
91 }
92
93
94 /**
95 * @return the Map that belongs to this Document
96 */
97 Map *map() const;
98
99 /**
100 * Returns the syntax version of the currently opened file
101 */
102 int syntaxVersion() const;
103
104 /**
105 * Return a pointer to the resource manager associated with the
106 * document. The resource manager contains
107 * document wide resources * such as variable managers, the image
108 * collection and others.
109 * @see KoCanvasBase::resourceManager()
110 */
111 KoDocumentResourceManager *resourceManager() const;
112
113 SheetAccessModel *sheetAccessModel() const;
114
115 virtual void initConfig();
116
117
118
119 /**
120 * \ingroup OpenDocument
121 * Main saving method.
122 */
123 virtual bool saveOdf(SavingContext &documentContext);
124
125 /**
126 * \ingroup OpenDocument
127 * Save the whole document, or just the selection, into OASIS format
128 * When saving the selection, also return the data as plain text and/or plain picture,
129 * which are used to insert into the KMultipleDrag drag object.
130 *
131 * @param store the KoStore to save into
132 * @param manifestWriter pointer to a koxmlwriter to add entries to the manifest
133 * @param saveFlag either the whole document, or only the selected text/objects.
134 * @param plainText must be set when saveFlag==SaveSelected.
135 * It returns the plain text format of the saved data, when available.
136 */
137 virtual bool saveOdfHelper(SavingContext &documentContext, SaveFlag saveFlag,
138 QString* plainText = 0);
139
140 /**
141 * \ingroup OpenDocument
142 * Main loading method.
143 * @see Map::loadOdf
144 */
145 virtual bool loadOdf(KoOdfReadStore & odfStore);
146
147protected:
148 class Private;
149 Private * const d;
150
151 virtual void paintContent(QPainter & painter, const QRect & rect);
152 virtual bool loadXML(const KoXmlDocument& doc, KoStore *store);
153
154 virtual void saveOdfViewSettings(KoXmlWriter& settingsWriter);
155 virtual void saveOdfViewSheetSettings(Sheet *sheet, KoXmlWriter& settingsWriter);
156private:
157 Q_DISABLE_COPY(DocBase)
158
159 /**
160 * \ingroup OpenDocument
161 * Saves the Document related settings.
162 * The actual saving takes place in Map::saveOdfSettings.
163 * @see Map::saveOdfSettings
164 */
165 void saveOdfSettings(KoXmlWriter &settingsWriter);
166
167 /**
168 * \ingroup OpenDocument
169 * Loads the Document related settings.
170 * The actual loading takes place in Map::loadOdfSettings.
171 * @see Map::loadOdfSettings
172 */
173 void loadOdfSettings(const KoXmlDocument&settingsDoc);
174
175 /**
176 * \ingroup OpenDocument
177 * Load the spell checker ignore list.
178 */
179 void loadOdfIgnoreList(const KoOasisSettings& settings);
180};
181
182} // namespace Sheets
183} // namespace Calligra
184
185#endif // CALLIGRA_SHEETS_DOCBASE_H
186