Subversion Repositories Scribus

Rev

Rev 12285 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
3487 craig 7
#ifndef SCRIBUS_LOADSAVEPLUGIN_H
8
#define SCRIBUS_LOADSAVEPLUGIN_H
9
 
10
#include "scplugin.h"
11
 
9953 cbradney 12
#include <QString>
13
#include <QRegExp>
14
#include <QIODevice>
15
#include <QProgressBar>
16
#include <QStringList>
9803 fschmid 17
#include <QList>
3487 craig 18
 
4034 cbradney 19
class FileFormat;
5642 cbradney 20
//TODO REmove includes one day
21
//class ScribusDoc;
22
//class ScribusView;
23
#include "scfonts.h"
24
#include "scribusdoc.h"
25
#include "scribusview.h"
4024 craig 26
 
3487 craig 27
/*
28
 * @brief Superclass for all file import/export/load/save plugins
29
 *
30
 * This class provides the interface common to all file load/save/import/export
31
 * plugins. It provides the facilities for discovering what format(s) a plugin
32
 * supports, how they should be identified, etc.
33
 */
3696 craig 34
class SCRIBUS_API LoadSavePlugin : public ScPlugin
3487 craig 35
{
36
        Q_OBJECT
37
 
38
        public:
39
                // Construct a plugin instance.
40
                LoadSavePlugin();
41
                ~LoadSavePlugin();
42
 
5540 mrdocs 43
                enum loadFlags
44
                {
45
                        lfCreateDoc = 1,
46
                        lfUseCurrentPage = 2,
47
                        lfInsertPage = 4,
8262 fschmid 48
                        lfInteractive = 8,
49
                        lfScripted = 16
5540 mrdocs 50
                };
51
 
3686 craig 52
                // Static functions:
3487 craig 53
 
3696 craig 54
                // Return a list of format descriptions suitable for use with
55
                // QFileDialog.  You can convert it to QString form with
56
                // fileDialogSaveFilter().join(";;")
57
                static const QStringList fileDialogLoadFilter();
3686 craig 58
 
3696 craig 59
                // Same deal but for save
60
                static const QStringList fileDialogSaveFilter();
61
 
4024 craig 62
                // Get the highest priority format of a given id, or 0 if
63
                // not found / not available.
64
                static const FileFormat * getFormatById(const int id);
65
 
3686 craig 66
                // Non-static members implemented by plugins:
4024 craig 67
                //
68
                // Load the requested format from the specified path.
5540 mrdocs 69
                // Default implementation always reports failure.
70
                virtual bool loadFile(const QString & fileName, const FileFormat & fmt, int flags, int index = 0);
3686 craig 71
 
4024 craig 72
                // Save the requested format to the requested path.
73
                virtual bool saveFile(const QString & fileName, const FileFormat & fmt);
74
 
11212 jghali 75
                // Return last file saved, this may be the last fileName argument passed to saveFile(),
76
                // a temporary file name or an empty string if last call to saveFile() could not create
77
                // a valid file
78
                virtual const QString& lastSavedFile(void);
79
 
3487 craig 80
                // Examine the passed file and test to see whether it appears to be
81
                // loadable with this plugin. This test must be quick and simple.
82
                // It need not verify a file, just confirm that it looks like a supported
83
                // file type (eg "XML doc with root element SCRIBUSXML and version 1.3.1").
84
                // All plugins must implement this method.
5642 cbradney 85
                virtual bool fileSupported(QIODevice* file, const QString & fileName=QString::null) const = 0;
5243 cbradney 86
 
5642 cbradney 87
                // Return a list of all formats supported by all currently loaded and
88
                // active plugins. This list is sorted in a very specific order:
89
                // First, by descending order of `id', then descending order of priority.
9803 fschmid 90
                static const QList<FileFormat> & supportedFormats();
5642 cbradney 91
 
9953 cbradney 92
                virtual void setupTargets(ScribusDoc *targetDoc, ScribusView* targetView, ScribusMainWindow* targetMW, QProgressBar* targetMWPRogressBar, SCFonts* targetAvailableFonts);
9803 fschmid 93
                virtual void getReplacedFontData(bool & getNewReplacement, QMap<QString,QString> &getReplacedFonts, QList<ScFace> &getDummyScFaces);
5642 cbradney 94
                virtual bool loadPage(const QString & fileName, int pageNumber, bool Mpage, QString renamedPageName=QString::null);
12343 pierre 95
                virtual bool readStyles(const QString& fileName, ScribusDoc* doc);
96
                virtual bool readCharStyles(const QString& fileName, ScribusDoc* doc);
5642 cbradney 97
                virtual bool readLineStyles(const QString& fileName, QMap<QString,multiLine> *Sty);
98
                virtual bool readColors(const QString& fileName, ColorList & colors);
99
                virtual bool readPageCount(const QString& fileName, int *num1, int *num2, QStringList & masterPageNames);
100
 
3686 craig 101
        protected:
4024 craig 102
 
5540 mrdocs 103
                /// Check a loadFlags combination
104
                virtual bool checkFlags(int flags);
105
 
3696 craig 106
                /// Register the passed format so it can be used by the app
4024 craig 107
                void registerFormat(const FileFormat & fmt);
3686 craig 108
 
3696 craig 109
                /// Unregister the format with format ID `id' that references by the calling plugin.
110
                void unregisterFormat(unsigned int id);
3686 craig 111
 
112
                /// Unregister all formats owned by the calling plugin
113
                void unregisterAll();
5642 cbradney 114
 
11212 jghali 115
                ScribusDoc*        m_Doc;
116
                ScribusView*       m_View; //For 1.2.x loader at the moment
5781 cbradney 117
                ScribusMainWindow* m_ScMW; //For plugins when required
11212 jghali 118
                QProgressBar*      m_mwProgressBar;
119
                SCFonts*           m_AvailableFonts;
120
                QString            m_lastSavedFile;
3686 craig 121
 
122
        private:
123
                // A list of all supported formats. This is maintained by plugins
124
                // using the protected `registerFormat(...)', `unregisterFormat(...)'
3696 craig 125
                // and `unregisterAll(...)' methods. This is sorted in a very specific
126
                // order - ascending ID, then descending priority.
9803 fschmid 127
                static QList<FileFormat> formats;
3686 craig 128
 
129
                // Return an iterator referencing the first format structure named `name'.
130
                // If specified, only return formats implmented by `plug'.
131
                // If `start' is specified, start searching at this iterator rather than the
132
                // start of the list.
133
                // The end iterator is returned if no match was found.
3696 craig 134
                // Note that due to the sort order maintained in `formats', the first
135
                // iterator returned by this method will always be to the highest
136
                // priority format of the required ID, and each subsequent call will
137
                // return the next lowest priority format.
9803 fschmid 138
                static QList<FileFormat>::iterator findFormat(unsigned int id,
3686 craig 139
                                LoadSavePlugin* plug = 0,
9803 fschmid 140
                                QList<FileFormat>::iterator it = formats.begin());
5642 cbradney 141
 
9803 fschmid 142
                static QList<FileFormat>::iterator findFormat(const QString& extension,
5642 cbradney 143
                                LoadSavePlugin* plug = 0,
9803 fschmid 144
                                QList<FileFormat>::iterator it = formats.begin());
3696 craig 145
 
146
                // Print out a format list for debugging purposes
147
                static void printFormatList();
148
 
149
                // Base implementation for fileDialogLoadFilter and fileDialogSaveFilter
150
                static const QStringList getDialogFilter(bool forLoad);
3487 craig 151
};
152
 
5642 cbradney 153
 
154
 
4024 craig 155
// Info on each supported format. A plugin must register a
156
// FileFormat structure for every format it knows how to load or
157
// save. If it both loads and saves a given format, one structure must
158
// be registered for load and one for save.
159
// Plugins must unregister formats when being unloaded to ensure that
160
// no attempt is made to load a file using a plugin that's no longer
161
// available.
162
//
163
// This class also provides methods to ask the implementation to load / save a
164
// file in this format.
4034 cbradney 165
class SCRIBUS_API FileFormat
4024 craig 166
{
4034 cbradney 167
        public:
168
                // Default ctor to make QValueList happy
169
                FileFormat() : load(false), save(false), plug(0) {}
170
                // Standard ctor that sets up a valid FileFormat
171
                FileFormat(LoadSavePlugin * plug) : load(false), save(false), plug(plug) {}
172
                // Load a file with this format
5540 mrdocs 173
                bool loadFile(const QString & fileName, int flags, int index = 0) const;
4034 cbradney 174
                // Save a file with this format
175
                bool saveFile(const QString & fileName) const;
11212 jghali 176
                // Get last saved file
177
                QString lastSavedFile(void) const;
5642 cbradney 178
 
9953 cbradney 179
                void setupTargets(ScribusDoc *targetDoc, ScribusView* targetView, ScribusMainWindow* targetMW, QProgressBar* targetMWPRogressBar, SCFonts* targetAvailableFonts) const;
9803 fschmid 180
                void getReplacedFontData(bool & getNewReplacement, QMap<QString,QString> &getReplacedFonts, QList<ScFace> &getDummyScFaces) const;
5642 cbradney 181
                bool loadPage(const QString & fileName, int pageNumber, bool Mpage, QString renamedPageName=QString::null) const;
12343 pierre 182
                bool readStyles(const QString& fileName, ScribusDoc* doc) const;
183
                bool readCharStyles(const QString& fileName, ScribusDoc* doc) const;
5642 cbradney 184
                bool readLineStyles(const QString& fileName, QMap<QString,multiLine> *Sty) const;
185
                bool readColors(const QString& fileName, ColorList & colors) const;
186
                bool readPageCount(const QString& fileName, int *num1, int *num2, QStringList & masterPageNames) const;
4034 cbradney 187
                //
188
                // Data members
189
                //
190
                // An integer ID code used to idenfify formats. Should be unique
191
                // across all FileFormat structures except where they implement
192
                // support for the same file format, eg sla 1.2.x, sla 1.3.x and
193
                // "new format" SLA should all have equal IDs (with different
194
                // priorities to control what order they're tried in when a user
195
                // tries to open a file).
196
                // Note that dialog box options are sorted in descending `id' order.
5647 cbradney 197
                uint formatId;
4034 cbradney 198
                // The human-readable, translated name of this file format.
199
                QString trName;
200
                // A filter in the format used by QFileDialog that should be used to
201
                // select for this format.
202
                QString filter;
203
                // Regexp to match filenames for this format
204
                QRegExp nameMatch;
205
                // MIME type(s) that should be matched by this format.
206
                QStringList mimeTypes;
207
                // Can we load it?
208
                bool load;
209
                // Can we save it?
210
                bool save;
211
                // Priority of this format from 0 (lowest, tried last) to
212
                // 255 (highest, tried first). 64-128 recommended in general.
213
                // Priority controls the order options are displayed in when a file
214
                // of a given type is selected in a dialog, and controls the order
215
                // loaders are tried in when multiple plugins support the same file
216
                // type.
217
                unsigned short int priority;
218
                // For convenience, a pointer back to the plugin to use to open
219
                // this format.
9803 fschmid 220
                LoadSavePlugin * plug;
221
//              LoadSavePlugin * const plug;
4024 craig 222
};
223
 
224
 
225
 
3487 craig 226
#endif