Back to index

scribus-ng  1.3.4.dfsg+svn20071115
pdfoptionsio.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 PDFOPTIONSIO_H
00008 #define PDFOPTIONSIO_H
00009 
00010 #include "scribusapi.h"
00011 #include "pdfoptions.h"
00012 #include "qdom.h"
00013 
00046 class SCRIBUS_API PDFOptionsIO
00047 {
00048 public:
00052        PDFOptionsIO(PDFOptions& opts);
00053 
00063        bool writeTo(QIODevice& outDevice, bool includePasswords = false);
00064        bool writeTo(QString outFileName, bool includePasswords = false);
00065 
00077        bool readFrom(QIODevice& inStream);
00078        bool readFrom(QString inFileName);
00079 
00084        const QString& lastError() const;
00085 
00086 protected:
00087        // Build and return an XML representation of the settings.
00088        // QString::null is returned on failure, in which case
00089        // the error string is set.
00090        QString buildXMLString();
00091 
00092        // Populate the current DOM tree with the settings from the
00093        // current PDFOptions instance.
00094        void buildSettings();
00095 
00096        // Helper functions. Add elements under the root element
00097        // with a single attribute "value=" set to the passed value.
00098        void addElem(QDomElement& addTo, QString name, bool value);
00099        void addElem(QDomElement& addTo, QString name, QString value);
00100        void addElem(QDomElement& addTo, QString name, int value);
00101        void addElem(QDomElement& addTo, QString name, double value);
00102        void addList(QDomElement& addTo, QString name, QValueList<QString>& value);
00103 
00104        // Helper: add the PresentVals data to the document
00105        void addPresentationData();
00106        // Helper: Add the LPI settings to the document
00107        void addLPISettings();
00108 
00109        // Helper: set the `opts' members from the current DOM tree
00110        bool readSettings();
00111 
00112        // Helper functions. Read various single elements into variables
00113        // All of these return true for success. On failure, the passed
00114        // value pointer is undefined.
00115        bool readElem(QDomElement& parent, QString name, bool* value);
00116        bool readElem(QDomElement& parent, QString name, int* value);
00117        bool readElem(QDomElement& parent, QString name, double* value);
00118        bool readElem(QDomElement& parent, QString name, QString* value);
00119        bool readList(QDomElement& parent, QString name, QValueList<QString>* value);
00120 
00121        bool readPDFVersion();
00122        bool readPresentationData();
00123        bool readLPISettings();
00124 
00125        // Returns the named node under `parent' iff it's unique
00126        QDomNode getUniqueNode(QDomElement& parent, QString name);
00127 
00128        // Return a QDomElement corresponding to the passed node, ensuring it's a
00129        // valid element, the only one of its name under `parent', it has name
00130        // `name', and (by default) has a `value' attribute.
00131        QDomElement getValueElement(QDomNode& node, QString name, bool isValue = true);
00132 
00133        // The QDomDocument used by the class for all its XML work
00134        QDomDocument m_doc;
00135        // The root element
00136        QDomElement m_root;
00137        // The PDFOptions instance we're operating on
00138        PDFOptions* m_opts;
00139        // Whether to save passwords when writing out settings
00140        bool m_includePasswords;
00141 
00142        // Version, of the form Mmpr: Major, minor, patch, revision
00143        // eg 1300 - 1.3.0r0
00144        static const int formatVersion;
00145 
00146        // Error explanation if a function fails
00147        // For user only, do not depend on particular values of this.
00148        QString m_error;
00149 };
00150 
00151 #endif