1 /* This file is part of the KDE project
2 
3    Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
4    Copyright (C) 2000-2005 David Faure <faure@kde.org>
5    Copyright (C) 2007 Thorsten Zachmann <zachmann@kde.org>
6    Copyright (C) 2009 Boudewijn Rempt <boud@valdyas.org>
7 
8    This library is free software; you can redistribute it and/or
9    modify it under the terms of the GNU Library General Public
10    License as published by the Free Software Foundation; either
11    version 2 of the License, or (at your option) any later version.
12 
13    This library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    Library General Public License for more details.
17 
18    You should have received a copy of the GNU Library General Public License
19    along with this library; see the file COPYING.LIB.  If not, write to
20    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21   Boston, MA 02110-1301, USA.
22 */
23 #ifndef KODOCUMENTBASE_H
24 #define KODOCUMENTBASE_H
25 
26 class KoStore;
27 class KoOdfReadStore;
28 class KoOdfWriteStore;
29 class KoEmbeddedDocumentSaver;
30 class KoXmlElement;
31 class KoOdfLoadingContext;
32 
33 class QUrl;
34 class QByteArray;
35 class QString;
36 
37 #include "koodf_export.h"
38 
39 /**
40  * Base class for documents that can load and save ODF. Most of the
41  * implementation is still in KoDocument, though that should probably
42  * change.
43  */
44 class KOODF_EXPORT KoDocumentBase
45 {
46 public:
47 
48     // context passed on saving to saveOdf
49     struct SavingContext {
SavingContextSavingContext50         SavingContext(KoOdfWriteStore &odfStore, KoEmbeddedDocumentSaver &embeddedSaver)
51                 : odfStore(odfStore)
52                 , embeddedSaver(embeddedSaver) {}
53 
54         KoOdfWriteStore &odfStore;
55         KoEmbeddedDocumentSaver &embeddedSaver;
56     };
57 
58     /**
59      * create a new KoDocumentBase
60      */
61     KoDocumentBase();
62 
63     /**
64      * delete this document
65      */
66     virtual ~KoDocumentBase();
67 
68     /**
69      * Set when you want an external embedded document to be stored internally
70      */
71     void setStoreInternal(bool i);
72 
73     /**
74      * @return true when external embedded documents are stored internally
75      */
76     bool storeInternal() const;
77 
78     /**
79      * Return true if url() is a real filename, false if url() is
80      * an internal url in the store, like "tar:/..."
81      */
82     virtual bool isStoredExtern() const = 0;
83 
84     /**
85      * @return the current URL
86      */
87     virtual QUrl url() const = 0;
88 
89     virtual void setUrl(const QUrl &url) = 0;
90 
91     /**
92      * Returns the OASIS OpenDocument mimetype of the document, if supported
93      * This comes from the X-KDE-NativeOasisMimeType key in the .desktop file
94      */
95     virtual QByteArray nativeOasisMimeType() const = 0;
96 
97     /**
98      *  @brief Saves a document to a store.
99      */
100     virtual bool saveToStore(KoStore *store, const QString &path) = 0;
101 
102     /**
103      *  Reimplement this method to load the odf document. Take care to
104      *  make sure styles are loaded before body text is loaded by the
105      *  text shape.
106      */
107     virtual bool loadOdf(KoOdfReadStore &odfStore) = 0;
108 
109     /**
110      *  Reimplement this method to save the contents of your %Calligra document,
111      *  using the ODF format.
112      */
113     virtual bool saveOdf(SavingContext &documentContext) = 0;
114 
115     /**
116      * Checks whether the document is currently in the process of autosaving
117      */
118     virtual bool isAutosaving() const = 0;
119 
120     /**
121      * Returns true if this document or any of its internal child documents are modified.
122      */
123     virtual bool isModified() const = 0;
124 
125     /**
126      *  @return true if the document is empty.
127      */
128     virtual bool isEmpty() const = 0;
129 
130     /**
131      * Returns the actual mimetype of the document
132      */
133     virtual QByteArray mimeType() const = 0;
134 
135     /**
136      * @brief Sets the mime type for the document.
137      *
138      * When choosing "save as" this is also the mime type
139      * selected by default.
140      */
141     virtual void setMimeType(const QByteArray & mimeType) = 0;
142 
143     virtual QString localFilePath() const = 0;
144 
145     /**
146      * Return the set of SupportedSpecialFormats that the application wants to
147      * offer in the "Save" file dialog.
148      */
149     virtual int supportedSpecialFormats() const = 0;
150 
151     /// Enum values used by specialOutputFlag - note that it's a bitfield for supportedSpecialFormats
152     enum { /*SaveAsCalligra1dot1 = 1,*/ // old and removed
153         SaveAsDirectoryStore = 2,
154         SaveAsFlatXML = 4,
155         SaveEncrypted = 8
156                         // bitfield! next value is 16
157     };
158     virtual int specialOutputFlag() const = 0;
159 
160     /**
161      * @brief Set the format in which the document should be saved.
162      *
163      * This is called on loading, and in "save as", so you shouldn't
164      * have to call it.
165      *
166      * @param mimeType the mime type (format) to use.
167      * @param specialOutputFlag is for "save as older version" etc.
168      */
169     virtual void setOutputMimeType(const QByteArray & mimeType, int specialOutputFlag = 0) = 0;
170 
171     virtual QByteArray outputMimeType() const = 0;
172 
173     /**
174      * Sets the document URL to empty URL
175      * KParts doesn't allow this, but %Calligra apps have e.g. templates
176      * After using loadNativeFormat on a template, one wants
177      * to set the url to QUrl()
178      */
179     virtual void resetURL() = 0;
180 
181     /// Re-implement to load odf document from @p store
182     virtual bool loadOasisFromStore(KoStore *store) = 0;
183 
184 private:
185     class Private;
186     Private *const d;
187 };
188 
189 
190 #endif
191