Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

loadsaveplugin.h

Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #ifndef SCRIBUS_LOADSAVEPLUGIN_H
00008 #define SCRIBUS_LOADSAVEPLUGIN_H
00009 
00010 #include "scplugin.h"
00011 
00012 #include <QString>
00013 #include <QRegExp>
00014 #include <QIODevice>
00015 #include <QProgressBar>
00016 #include <QStringList>
00017 #include <QList>
00018 
00019 class FileFormat;
00020 //TODO REmove includes one day
00021 //class ScribusDoc;
00022 //class ScribusView;
00023 #include "scfonts.h"
00024 #include "scribusdoc.h"
00025 #include "scribusview.h"
00026 
00027 /*
00028  * @brief Superclass for all file import/export/load/save plugins
00029  *
00030  * This class provides the interface common to all file load/save/import/export
00031  * plugins. It provides the facilities for discovering what format(s) a plugin
00032  * supports, how they should be identified, etc.
00033  */
00034 class SCRIBUS_API LoadSavePlugin : public ScPlugin
00035 {
00036     Q_OBJECT
00037 
00038     public:
00039         // Construct a plugin instance.
00040         LoadSavePlugin();
00041         ~LoadSavePlugin();
00042 
00043         enum loadFlags
00044         {
00045             lfCreateDoc = 1,
00046             lfUseCurrentPage = 2,
00047             lfInsertPage = 4,
00048             lfInteractive = 8,
00049             lfScripted = 16
00050         };
00051 
00052         // Static functions:
00053 
00054         // Return a list of format descriptions suitable for use with
00055         // QFileDialog.  You can convert it to QString form with
00056         // fileDialogSaveFilter().join(";;")
00057         static const QStringList fileDialogLoadFilter();
00058 
00059         // Same deal but for save
00060         static const QStringList fileDialogSaveFilter();
00061 
00062         // Get the highest priority format of a given id, or 0 if
00063         // not found / not available.
00064         static const FileFormat * getFormatById(const int id);
00065 
00066         // Non-static members implemented by plugins:
00067         //
00068         // Load the requested format from the specified path.
00069         // Default implementation always reports failure.
00070         virtual bool loadFile(const QString & fileName, const FileFormat & fmt, int flags, int index = 0);
00071 
00072         // Save the requested format to the requested path.
00073         virtual bool saveFile(const QString & fileName, const FileFormat & fmt);
00074 
00075         // Return last file saved, this may be the last fileName argument passed to saveFile(),
00076         // a temporary file name or an empty string if last call to saveFile() could not create
00077         // a valid file
00078         virtual const QString& lastSavedFile(void);
00079 
00080         // Examine the passed file and test to see whether it appears to be
00081         // loadable with this plugin. This test must be quick and simple.
00082         // It need not verify a file, just confirm that it looks like a supported
00083         // file type (eg "XML doc with root element SCRIBUSXML and version 1.3.1").
00084         // All plugins must implement this method.
00085         virtual bool fileSupported(QIODevice* file, const QString & fileName=QString::null) const = 0;
00086         
00087         // Return a list of all formats supported by all currently loaded and
00088         // active plugins. This list is sorted in a very specific order:
00089         // First, by descending order of `id', then descending order of priority.
00090         static const QList<FileFormat> & supportedFormats();
00091         
00092         virtual void setupTargets(ScribusDoc *targetDoc, ScribusView* targetView, ScribusMainWindow* targetMW, QProgressBar* targetMWPRogressBar, SCFonts* targetAvailableFonts);
00093         virtual void getReplacedFontData(bool & getNewReplacement, QMap<QString,QString> &getReplacedFonts, QList<ScFace> &getDummyScFaces);
00094         virtual bool loadPage(const QString & fileName, int pageNumber, bool Mpage, QString renamedPageName=QString::null);
00095         virtual bool readStyles(const QString& fileName, ScribusDoc* doc, StyleSet<ParagraphStyle> &docParagraphStyles);
00096         virtual bool readCharStyles(const QString& fileName, ScribusDoc* doc, StyleSet<CharStyle> &docCharStyles);
00097         virtual bool readLineStyles(const QString& fileName, QMap<QString,multiLine> *Sty);
00098         virtual bool readColors(const QString& fileName, ColorList & colors);
00099         virtual bool readPageCount(const QString& fileName, int *num1, int *num2, QStringList & masterPageNames);
00100         
00101     protected:
00102 
00104         virtual bool checkFlags(int flags);
00105 
00107         void registerFormat(const FileFormat & fmt);
00108 
00110         void unregisterFormat(unsigned int id);
00111 
00113         void unregisterAll();
00114         
00115         ScribusDoc*        m_Doc;
00116         ScribusView*       m_View; //For 1.2.x loader at the moment
00117         ScribusMainWindow* m_ScMW; //For plugins when required
00118         QProgressBar*      m_mwProgressBar;
00119         SCFonts*           m_AvailableFonts;
00120         QString            m_lastSavedFile;
00121 
00122     private:
00123         // A list of all supported formats. This is maintained by plugins
00124         // using the protected `registerFormat(...)', `unregisterFormat(...)'
00125         // and `unregisterAll(...)' methods. This is sorted in a very specific
00126         // order - ascending ID, then descending priority.
00127         static QList<FileFormat> formats;
00128 
00129         // Return an iterator referencing the first format structure named `name'.
00130         // If specified, only return formats implmented by `plug'.
00131         // If `start' is specified, start searching at this iterator rather than the
00132         // start of the list.
00133         // The end iterator is returned if no match was found.
00134         // Note that due to the sort order maintained in `formats', the first
00135         // iterator returned by this method will always be to the highest
00136         // priority format of the required ID, and each subsequent call will
00137         // return the next lowest priority format.
00138         static QList<FileFormat>::iterator findFormat(unsigned int id,
00139                 LoadSavePlugin* plug = 0,
00140                 QList<FileFormat>::iterator it = formats.begin());
00141                 
00142         static QList<FileFormat>::iterator findFormat(const QString& extension,
00143                 LoadSavePlugin* plug = 0,
00144                 QList<FileFormat>::iterator it = formats.begin());
00145 
00146         // Print out a format list for debugging purposes
00147         static void printFormatList();
00148 
00149         // Base implementation for fileDialogLoadFilter and fileDialogSaveFilter
00150         static const QStringList getDialogFilter(bool forLoad);
00151 };
00152 
00153 
00154 
00155 // Info on each supported format. A plugin must register a
00156 // FileFormat structure for every format it knows how to load or
00157 // save. If it both loads and saves a given format, one structure must
00158 // be registered for load and one for save.
00159 // Plugins must unregister formats when being unloaded to ensure that
00160 // no attempt is made to load a file using a plugin that's no longer
00161 // available.
00162 //
00163 // This class also provides methods to ask the implementation to load / save a
00164 // file in this format.
00165 class SCRIBUS_API FileFormat
00166 {
00167     public:
00168         // Default ctor to make QValueList happy
00169         FileFormat() : load(false), save(false), plug(0) {}
00170         // Standard ctor that sets up a valid FileFormat
00171         FileFormat(LoadSavePlugin * plug) : load(false), save(false), plug(plug) {}
00172         // Load a file with this format
00173         bool loadFile(const QString & fileName, int flags, int index = 0) const;
00174         // Save a file with this format
00175         bool saveFile(const QString & fileName) const;
00176         // Get last saved file
00177         QString lastSavedFile(void) const;
00178         
00179         void setupTargets(ScribusDoc *targetDoc, ScribusView* targetView, ScribusMainWindow* targetMW, QProgressBar* targetMWPRogressBar, SCFonts* targetAvailableFonts) const;
00180         void getReplacedFontData(bool & getNewReplacement, QMap<QString,QString> &getReplacedFonts, QList<ScFace> &getDummyScFaces) const;
00181         bool loadPage(const QString & fileName, int pageNumber, bool Mpage, QString renamedPageName=QString::null) const;
00182         bool readStyles(const QString& fileName, ScribusDoc* doc, StyleSet<ParagraphStyle> &docParagraphStyles) const;
00183         bool readCharStyles(const QString& fileName, ScribusDoc* doc, StyleSet<CharStyle> &docCharStyles) const;
00184         bool readLineStyles(const QString& fileName, QMap<QString,multiLine> *Sty) const;
00185         bool readColors(const QString& fileName, ColorList & colors) const;
00186         bool readPageCount(const QString& fileName, int *num1, int *num2, QStringList & masterPageNames) const;
00187         //
00188         // Data members
00189         //
00190         // An integer ID code used to idenfify formats. Should be unique
00191         // across all FileFormat structures except where they implement
00192         // support for the same file format, eg sla 1.2.x, sla 1.3.x and
00193         // "new format" SLA should all have equal IDs (with different
00194         // priorities to control what order they're tried in when a user
00195         // tries to open a file).
00196         // Note that dialog box options are sorted in descending `id' order.
00197         uint formatId;
00198         // The human-readable, translated name of this file format.
00199         QString trName;
00200         // A filter in the format used by QFileDialog that should be used to
00201         // select for this format.
00202         QString filter;
00203         // Regexp to match filenames for this format
00204         QRegExp nameMatch;
00205         // MIME type(s) that should be matched by this format.
00206         QStringList mimeTypes;
00207         // Can we load it?
00208         bool load;
00209         // Can we save it?
00210         bool save;
00211         // Priority of this format from 0 (lowest, tried last) to
00212         // 255 (highest, tried first). 64-128 recommended in general.
00213         // Priority controls the order options are displayed in when a file
00214         // of a given type is selected in a dialog, and controls the order
00215         // loaders are tried in when multiple plugins support the same file
00216         // type.
00217         unsigned short int priority;
00218         // For convenience, a pointer back to the plugin to use to open
00219         // this format.
00220         LoadSavePlugin * plug;
00221 //      LoadSavePlugin * const plug;
00222 };
00223 
00224 
00225 
00226 #endif
Created with personalized Doxygen. This is documentation for GPL software Scribus - Open Source Desktop Publishing.