Scribus
Open source desktop publishing at your fingertips
pdfoptionsio.h
Go to the documentation of this file.
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 */
7 #ifndef PDFOPTIONSIO_H
8 #define PDFOPTIONSIO_H
9 
10 #include <QDomElement>
11 #include <QList>
12 
13 #include "pdfoptions.h"
14 #include "scribusapi.h"
15 
48 class SCRIBUS_API PDFOptionsIO
49 {
50 public:
54  PDFOptionsIO(PDFOptions& opts);
55 
65  bool writeTo(QIODevice& outDevice, bool includePasswords = false);
66  bool writeTo(QString outFileName, bool includePasswords = false);
67 
79  bool readFrom(QIODevice& inStream);
80  bool readFrom(QString inFileName);
81 
86  const QString& lastError() const;
87 
88 protected:
89  // Build and return an XML representation of the settings.
90  // QString::null is returned on failure, in which case
91  // the error string is set.
92  QString buildXMLString();
93 
94  // Populate the current DOM tree with the settings from the
95  // current PDFOptions instance.
96  void buildSettings();
97 
98  // Helper functions. Add elements under the root element
99  // with a single attribute "value=" set to the passed value.
100  void addElem(QDomElement& addTo, QString name, bool value);
101  void addElem(QDomElement& addTo, QString name, QString value);
102  void addElem(QDomElement& addTo, QString name, int value);
103  void addElem(QDomElement& addTo, QString name, double value);
104  void addList(QDomElement& addTo, QString name, QList<QString>& value);
105 
106  // Helper: add the PresentVals data to the document
107  void addPresentationData();
108  // Helper: Add the LPI settings to the document
109  void addLPISettings();
110 
111  // Helper: set the `opts' members from the current DOM tree
112  bool readSettings();
113 
114  // Helper functions. Read various single elements into variables
115  // All of these return true for success. On failure, the passed
116  // value pointer is undefined.
117  bool readElem(QDomElement& parent, QString name, bool* value);
118  bool readElem(QDomElement& parent, QString name, int* value);
119  bool readElem(QDomElement& parent, QString name, double* value);
120  bool readElem(QDomElement& parent, QString name, QString* value);
121  bool readList(QDomElement& parent, QString name, QList<QString>* value);
122 
123  bool readPDFVersion();
124  bool readPDFFontEmbeddingMode();
125  bool readPresentationData();
126  bool readLPISettings();
127 
128  // Returns the named node under `parent' iff it's unique
129  QDomNode getUniqueNode(QDomElement& parent, QString name);
130 
131  // Return a QDomElement corresponding to the passed node, ensuring it's a
132  // valid element, the only one of its name under `parent', it has name
133  // `name', and (by default) has a `value' attribute.
134  QDomElement getValueElement(QDomNode& node, QString name, bool isValue = true);
135 
136  // The QDomDocument used by the class for all its XML work
137  QDomDocument m_doc;
138  // The root element
139  QDomElement m_root;
140  // The PDFOptions instance we're operating on
141  PDFOptions* m_opts;
142  // Whether to save passwords when writing out settings
143  bool m_includePasswords;
144 
145  // Version, of the form Mmpr: Major, minor, patch, revision
146  // eg 1300 - 1.3.0r0
147  static const int formatVersion;
148 
149  // Error explanation if a function fails
150  // For user only, do not depend on particular values of this.
151  QString m_error;
152 };
153 
154 #endif
Helper class for reading/writing PDFOptions.
Definition: pdfoptionsio.h:48
PDF Options struture. Capable of verifying its self, but otherwise largely a dumb struct...
Definition: pdfoptions.h:37
Defines class PDFOptions, used for loading/saving/passing around PDF options.