Subversion Repositories Scribus

Rev

Rev 2044 | Rev 2046 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2036 craig 1
#include "pdfoptionsio.h"
2
#include "scribusstructs.h"
3
 
2042 craig 4
#include "qapplication.h"
5
 
2036 craig 6
const int PDFOptionsIO::formatVersion = 1300;
7
 
8
PDFOptionsIO::PDFOptionsIO(PDFOptions& opts) :
2043 craig 9
        m_doc(),
2038 craig 10
        m_root(),
11
        m_includePasswords(false),
12
        m_error()
2036 craig 13
{
2038 craig 14
        this->m_opts = &opts;
2036 craig 15
}
16
 
17
// writeTo(QString) is implemented separately to writeTo(QTextStream)
18
// because we don't want to clobber the output file until we know the
19
// data has been generated ok, and we can't avoid clobbering the file
20
// to create a QTextStream().
2038 craig 21
bool PDFOptionsIO::writeTo(QString outFileName, bool includePasswords)
2036 craig 22
{
2038 craig 23
        m_includePasswords = includePasswords;
2036 craig 24
        QString xml = buildXMLString();
25
        if (xml == QString::null)
26
                return false;
27
        QFile f(outFileName);
28
        if (!f.open(IO_WriteOnly|IO_Truncate))
29
        {
2043 craig 30
                m_error = QObject::tr("Couldn't open output file %1")
2042 craig 31
                        .arg(qApp->translate("QFile",f.errorString()));
2036 craig 32
                return false;
33
        }
34
        QTextStream ts(&f);
35
        ts.setEncoding(QTextStream::UnicodeUTF8);
36
        ts << xml;
2038 craig 37
        m_includePasswords = false; // just to be paranoid
38
        m_error = QString::null;
2036 craig 39
        return true;
40
}
41
 
2043 craig 42
bool PDFOptionsIO::writeTo(QIODevice& outDevice, bool includePasswords)
2036 craig 43
{
2038 craig 44
        m_includePasswords = includePasswords;
2043 craig 45
        if (!outDevice.isWritable())
2036 craig 46
        {
2038 craig 47
                m_error = QObject::tr("Output stream not writeable");
2036 craig 48
                return false;
49
        }
50
        QString xml = buildXMLString();
51
        if (xml == QString::null)
52
                return false;
2043 craig 53
        QTextStream ts(&outDevice);
54
        ts.setEncoding(QTextStream::UnicodeUTF8);
55
        ts << xml;
2038 craig 56
        m_includePasswords = false; // just to be paranoid
57
        m_error = QString::null;
2036 craig 58
        return true;
59
}
60
 
61
// Construct and return an XML string representing the settings
62
QString PDFOptionsIO::buildXMLString()
63
{
64
        // Verify to make sure our settings are sane
65
        QString vrfyError;
2043 craig 66
        // Initialise the DOM. We don't re-use any existing one in case
2038 craig 67
        PDFOptions::VerifyResults vr = m_opts->verify(&vrfyError);
2036 craig 68
        if (vr != PDFOptions::Verify_NoError)
69
        {
2038 craig 70
                m_error = QObject::tr("Verification of settings failed: %1").arg(vrfyError);
2036 craig 71
                return QString::null;
72
        }
73
        // Build the document. Initial implementation uses QDom.
2038 craig 74
        m_root = m_doc.createElement("ScribusPDFOptions");
75
        m_root.setAttribute("version", formatVersion);
76
        m_doc.appendChild(m_root);
2036 craig 77
        // Fill the guts of the document
78
        buildSettings();
79
        // We're done - return a string containing the document XML
2038 craig 80
        QString xml = m_doc.toString();
2036 craig 81
        xml.prepend("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
82
        return xml;
83
}
84
 
85
// Build up the stored settings into the passed DOM objects
86
void PDFOptionsIO::buildSettings()
87
{
2038 craig 88
        addElem(m_root, "thumbnails", m_opts->Thumbnails);
89
        addElem(m_root, "articles", m_opts->Articles);
90
        addElem(m_root, "useLayers", m_opts->useLayers);
91
        addElem(m_root, "compress", m_opts->Compress);
92
        addElem(m_root, "compressMethod", m_opts->CompressMethod);
93
        addElem(m_root, "quality", m_opts->Quality);
94
        addElem(m_root, "recalcPic", m_opts->RecalcPic);
95
        addElem(m_root, "bookmarks", m_opts->Bookmarks);
96
        addElem(m_root, "picRes", m_opts->PicRes);
2036 craig 97
        QString pdfVersString;
2038 craig 98
        switch (m_opts->Version)
2036 craig 99
        {
100
                case PDFOptions::PDFVersion_X3:
101
                        pdfVersString = "X3";
102
                        break;
103
                default:
2038 craig 104
                        pdfVersString = QString::number(m_opts->Version);
2036 craig 105
                        break;
106
        }
2038 craig 107
        addElem(m_root, "pdfVersion", pdfVersString);
108
        addElem(m_root, "resolution", m_opts->Resolution);
109
        addElem(m_root, "binding", m_opts->Binding);
110
        addList(m_root, "embedFonts", m_opts->EmbedList);
111
        addList(m_root, "subsetFonts", m_opts->SubsetList);
112
        addElem(m_root, "mirrorH", m_opts->MirrorH);
113
        addElem(m_root, "mirrorV", m_opts->MirrorV);
114
        addElem(m_root, "rotateDegrees", m_opts->RotateDeg);
115
        addElem(m_root, "presentMode", m_opts->PresentMode);
2036 craig 116
        addPresentationData();
2038 craig 117
        addElem(m_root, "filename", m_opts->Datei);
118
        addElem(m_root, "isGrayscale", m_opts->isGrayscale);
119
        addElem(m_root, "useRGB", m_opts->UseRGB);
120
        addElem(m_root, "useProfiles", m_opts->UseProfiles);
121
        addElem(m_root, "useProfiles2", m_opts->UseProfiles2);
122
        addElem(m_root, "useLPI", m_opts->UseLPI);
2036 craig 123
        addLPISettings();
2038 craig 124
        addElem(m_root, "solidProf", m_opts->SolidProf);
125
        addElem(m_root, "sComp", m_opts->SComp);
126
        addElem(m_root, "imageProf", m_opts->ImageProf);
127
        addElem(m_root, "embeddedI", m_opts->EmbeddedI);
128
        addElem(m_root, "intent2", m_opts->Intent2);
129
        addElem(m_root, "printProf", m_opts->PrintProf);
130
        addElem(m_root, "info", m_opts->Info);
131
        addElem(m_root, "intent", m_opts->Intent);
132
        addElem(m_root, "bleedTop", m_opts->BleedTop);
133
        addElem(m_root, "bleedLeft", m_opts->BleedLeft);
134
        addElem(m_root, "bleedRight", m_opts->BleedRight);
135
        addElem(m_root, "bleedBottom", m_opts->BleedBottom);
136
        addElem(m_root, "encrypt", m_opts->Encrypt);
137
        addElem(m_root, "passOwner", m_includePasswords ? m_opts->PassOwner : "");
138
        addElem(m_root, "passUser", m_includePasswords ? m_opts->PassUser : "");
139
        addElem(m_root, "permissions", m_opts->Permissions);
2036 craig 140
}
141
 
142
// Convenience functions to add a single-attribute element
143
// of a particular type to the tree at a given point.
144
 
145
void PDFOptionsIO::addElem(QDomElement& addTo, QString name, bool value)
146
{
2038 craig 147
        QDomElement elem = m_doc.createElement(name);
2036 craig 148
        elem.setAttribute("value",value);
149
        addTo.appendChild(elem);
150
}
151
 
152
void PDFOptionsIO::addElem(QDomElement& addTo, QString name, QString value)
153
{
2038 craig 154
        QDomElement elem = m_doc.createElement(name);
2036 craig 155
        elem.setAttribute("value",value);
156
        addTo.appendChild(elem);
157
}
158
 
159
void PDFOptionsIO::addElem(QDomElement& addTo, QString name, int value)
160
{
2038 craig 161
        QDomElement elem = m_doc.createElement(name);
2036 craig 162
        elem.setAttribute("value",value);
163
        addTo.appendChild(elem);
164
}
165
 
166
void PDFOptionsIO::addElem(QDomElement& addTo, QString name, double value)
167
{
2038 craig 168
        QDomElement elem = m_doc.createElement(name);
2036 craig 169
        elem.setAttribute("value",value);
170
        addTo.appendChild(elem);
171
}
172
 
173
// Save a QValueList<String> or QStringList as a list of
174
// <item value=""> elements
175
void PDFOptionsIO::addList(QDomElement& addTo, QString name, QValueList<QString>& value)
176
{
177
        // List base element has no attributes, only children
2038 craig 178
        QDomElement listbase = m_doc.createElement(name);
2036 craig 179
        addTo.appendChild(listbase);
180
        QValueList<QString>::iterator it;
181
        for (it = value.begin(); it != value.end(); ++it)
182
                addElem(listbase, "item", *(it));
183
}
184
 
185
// save PDFOptions::PresentVals
186
void PDFOptionsIO::addPresentationData()
187
{
188
        // PDFOptions::PresentVals is a QValueList<PDFPresentationData>
189
        //
190
        // XML structure will be like this:
191
        // <presentationSettings>
192
        //   <presentationSettingsEntry>
193
        //     <pageEffectDuration value="0"/>
194
        //     <pageViewDuration value="0"/>
195
        //     <effectType value="0"/>
196
        //     <dm value="0"/>
197
        //     <m value="0"/>
198
        //     <di value="0"/>
199
        //   </presentationSettingsEntry>
200
        //   <presentationSettingsEntry>
201
        //     ...
202
        //   </presentationSettingsEntry>
203
        //   ...
204
        // </presentationSettings>
2038 craig 205
        QDomElement presentationSettings = m_doc.createElement("presentationSettings");
206
        m_root.appendChild(presentationSettings);
2036 craig 207
        QValueList<PDFPresentationData>::iterator it;
2038 craig 208
        for (it = m_opts->PresentVals.begin(); it != m_opts->PresentVals.end(); ++it)
2036 craig 209
        {
210
                // Settings entry has no attributes, only children
2038 craig 211
                QDomElement psEntry = m_doc.createElement("presentationSettingsEntry");
2036 craig 212
                presentationSettings.appendChild(psEntry);
213
                // Children:
214
                addElem(psEntry, "pageEffectDuration", (*it).pageEffectDuration);
215
                addElem(psEntry, "pageViewDuration", (*it).pageViewDuration);
216
                addElem(psEntry, "effectType", (*it).effectType);
217
                addElem(psEntry, "dm", (*it).Dm);
218
                addElem(psEntry, "m", (*it).M);
219
                addElem(psEntry, "di", (*it).Di);
220
        }
221
}
222
 
223
// Save PDFOptions::LPISettings
224
void PDFOptionsIO::addLPISettings()
225
{
226
        // PDFOptions::LPISettings is a QMap<QString,LPIData>
227
        //
228
        // XML structure will be like this:
229
        // <lpiSettings>
230
        //   <lpiSettingsEntry name="blah">
231
        //     <frequency value="0">
232
        //     <angle value="0">
233
        //     <spotFunc value="0">
234
        //   </lpiSettingsEntry>
235
        //   <lpiSettingsEntry name="blah2">
236
        //     ...
237
        //   </lpiSettingsEntry>
238
        //   ...
239
        // </lpiSettings>
2038 craig 240
        QDomElement lpiSettings = m_doc.createElement("lpiSettings");
241
        m_root.appendChild(lpiSettings);
2036 craig 242
        QMap<QString,LPIData>::iterator it;
2038 craig 243
        for (it = m_opts->LPISettings.begin(); it != m_opts->LPISettings.end(); ++it)
2036 craig 244
        {
245
                // Settings entry has no attributes, only children
2038 craig 246
                QDomElement lpiEntry = m_doc.createElement("lpiSettingsEntry");
2036 craig 247
                lpiEntry.setAttribute("name", it.key());
248
                lpiSettings.appendChild(lpiEntry);
249
                // Children:
250
                addElem(lpiEntry, "frequency", (*it).Frequency);
251
                addElem(lpiEntry, "angle", (*it).Angle);
252
                addElem(lpiEntry, "spotFunc", (*it).SpotFunc);
253
        }
254
 
255
}
256
 
2042 craig 257
// overload of bool readFrom(QTextStream& inStream)
258
bool PDFOptionsIO::readFrom(QString inFileName)
259
{
260
        QFile f(inFileName);
261
        if (!f.open(IO_ReadOnly))
262
        {
2043 craig 263
                m_error = QObject::tr("Couldn't open input file %1")
2042 craig 264
                        .arg(qApp->translate("QFile",f.errorString()));
265
                return false;
266
        }
2043 craig 267
        return readFrom(f);
2042 craig 268
}
269
 
2043 craig 270
bool PDFOptionsIO::readFrom(QIODevice& inDevice)
2036 craig 271
{
2043 craig 272
        if (!inDevice.isReadable())
2036 craig 273
                return false;
2043 craig 274
        QString domError;
275
        int errorLine, errorColumn;
276
        if (!m_doc.setContent(&inDevice, &domError, &errorLine, &errorColumn))
277
        {
278
                m_error = QObject::tr("Unable to read settings XML:")
279
                        .arg(QObject::tr("%1 (line %2 col %3)", "Load PDF settings")
280
                                .arg(domError).arg(errorLine).arg(errorColumn)
281
                        );
282
                return false;
283
        }
284
        if (!readSettings())
285
                // m_error should already be set
286
                return false;
287
        m_error = QString::null;
288
        return true;
2036 craig 289
}
290
 
2043 craig 291
// Helper for readFrom(...) to read settings from the DOM
292
bool PDFOptionsIO::readSettings()
293
{
294
        // Get the root element
295
        m_root = m_doc.documentElement();
296
        if (m_root.isNull())
297
        {
298
                m_error = QObject::tr("Unable to read settings XML: %1")
299
                        .arg(QObject::tr("null root node", "Load PDF settings"));
300
        }
301
        // and start processing elements
2044 craig 302
        if (!readElem(m_root, "thumbnails", &m_opts->Thumbnails))
2043 craig 303
                return false;
2045 craig 304
        if (!readElem(m_root, "articles", &m_opts->Articles))
305
                return false;
306
        if (!readElem(m_root, "useLayers", &m_opts->useLayers))
307
                return false;
308
        if (!readElem(m_root, "compress", &m_opts->Compress))
309
                return false;
310
        if (!readElem(m_root, "compressMethod", &m_opts->CompressMethod))
311
                return false;
312
        if (!readElem(m_root, "quality", &m_opts->Quality))
313
                return false;
314
        if (!readElem(m_root, "recalcPic", &m_opts->RecalcPic))
315
                return false;
316
        if (!readElem(m_root, "bookmarks", &m_opts->Bookmarks))
317
                return false;
318
        if (!readElem(m_root, "picRes", &m_opts->PicRes))
319
                return false;
320
        readPDFVersion();
321
        if (!readElem(m_root, "resolution", &m_opts->Resolution))
322
                return false;
323
        if (!readElem(m_root, "binding", &m_opts->Binding))
324
                return false;
325
        if (!readList(m_root, "embedFonts", &m_opts->EmbedList))
326
                return false;
327
        if (!readList(m_root, "subsetFonts", &m_opts->SubsetList))
328
                return false;
329
        if (!readElem(m_root, "mirrorH", &m_opts->MirrorH))
330
                return false;
331
        if (!readElem(m_root, "mirrorV", &m_opts->MirrorV))
332
                return false;
333
        if (!readElem(m_root, "rotateDegrees", &m_opts->RotateDeg))
334
                return false;
335
        if (!readElem(m_root, "presentMode", &m_opts->PresentMode))
336
                return false;
337
        if (!readPresentationData())
338
                return false;
339
        if (!readElem(m_root, "filename", &m_opts->Datei))
340
                return false;
341
        if (!readElem(m_root, "isGrayscale", &m_opts->isGrayscale))
342
                return false;
343
        if (!readElem(m_root, "useRGB", &m_opts->UseRGB))
344
                return false;
345
        if (!readElem(m_root, "useProfiles", &m_opts->UseProfiles))
346
                return false;
347
        if (!readElem(m_root, "useProfiles2", &m_opts->UseProfiles2))
348
                return false;
349
        if (!readElem(m_root, "useLPI", &m_opts->UseLPI))
350
                return false;
351
        if (!readLPISettings())
352
                return false;
353
        if (!readElem(m_root, "solidProf", &m_opts->SolidProf))
354
                return false;
355
        if (!readElem(m_root, "sComp", &m_opts->SComp))
356
                return false;
357
        if (!readElem(m_root, "imageProf", &m_opts->ImageProf))
358
                return false;
359
        if (!readElem(m_root, "embeddedI", &m_opts->EmbeddedI))
360
                return false;
361
        if (!readElem(m_root, "intent2", &m_opts->Intent2))
362
                return false;
363
        if (!readElem(m_root, "printProf", &m_opts->PrintProf))
364
                return false;
365
        if (!readElem(m_root, "info", &m_opts->Info))
366
                return false;
367
        if (!readElem(m_root, "intent", &m_opts->Intent))
368
                return false;
369
        if (!readElem(m_root, "bleedTop", &m_opts->BleedTop))
370
                return false;
371
        if (!readElem(m_root, "bleedLeft", &m_opts->BleedLeft))
372
                return false;
373
        if (!readElem(m_root, "bleedRight", &m_opts->BleedRight))
374
                return false;
375
        if (!readElem(m_root, "bleedBottom", &m_opts->BleedBottom))
376
                return false;
377
        if (!readElem(m_root, "encrypt", &m_opts->Encrypt))
378
                return false;
379
        if (!readElem(m_root, "passOwner", &m_opts->PassOwner))
380
                return false;
381
        if (!readElem(m_root, "passUser", &m_opts->PassUser))
382
                return false;
383
        if (!readElem(m_root, "permissions", &m_opts->Permissions))
384
                return false;
2043 craig 385
        return true;
386
}
387
 
2045 craig 388
bool PDFOptionsIO::readPDFVersion()
389
{
390
        QString pdfVersString;
391
        if (!readElem(m_root, "pdfVersion", &pdfVersString))
392
                return false;
393
        if (pdfVersString == "X3")
394
        {
395
                m_opts->Version = PDFOptions::PDFVersion_X3;
396
                return true;
397
        }
398
        else if (pdfVersString == "13")
399
        {
400
                m_opts->Version = PDFOptions::PDFVersion_13;
401
                return true;
402
        }
403
        else if (pdfVersString == "14")
404
        {
405
                m_opts->Version = PDFOptions::PDFVersion_14;
406
                return true;
407
        }
408
        else if (pdfVersString == "15")
409
        {
410
                m_opts->Version = PDFOptions::PDFVersion_15;
411
                return true;
412
        }
413
        else
414
        {
415
                m_error = QObject::tr("Unable to read settings XML:")
416
                        .arg(QObject::tr("<pdfVersion> invalid", "Load PDF settings"));
417
                return false;
418
        }
419
}
420
 
2043 craig 421
// returns a null node on failure
2045 craig 422
QDomNode PDFOptionsIO::getUniqueNode(QDomElement& parent, QString name)
2043 craig 423
{
424
        QDomNodeList nodes = parent.elementsByTagName(name);
425
        if (nodes.count() != 1)
426
        {
427
                m_error = QObject::tr("Unable to read settings XML:")
428
                        .arg(QObject::tr("found %1 <%2> nodes, need 1.", "Load PDF settings")
429
                                .arg(nodes.count()).arg(name)
430
                        );
2045 craig 431
                return QDomNode();
2043 craig 432
        }
2045 craig 433
        return nodes.item(0);
434
}
435
 
436
// Return the node as a QDomElement iff it is a QDomElement with
437
// a `value' attribute; otherwise return a null element.
438
QDomElement PDFOptionsIO::getValueElement(QDomNode& node, QString name, bool isValue)
439
{
2043 craig 440
        if (node.isNull())
441
        {
442
                m_error = QObject::tr("Unable to read settings XML:")
443
                        .arg(QObject::tr("unexpected null <%2> node", "Load PDF settings")
444
                                .arg(name)
445
                        );
446
                return QDomNode().toElement();
447
        }
448
        if (!node.isElement())
449
        {
450
                m_error = QObject::tr("Unable to read settings XML:")
451
                        .arg(QObject::tr("node <%1> not an element", "Load PDF settings")
452
                                .arg(name)
453
                        );
454
                return QDomNode().toElement();
455
        }
456
        QDomElement elem = node.toElement();
2045 craig 457
        if (elem.tagName() != name)
2043 craig 458
        {
2045 craig 459
                m_error = QObject::tr("Unable to read settings XML:")
460
                        .arg(QString("Internal error: element named <%1> not expected <%2>")
461
                                        .arg(elem.tagName()).arg(name)
462
                        );
463
                return QDomNode().toElement();
464
        }
465
        if (isValue)
466
        {
2043 craig 467
                // We need to check that it has a `value' attribute
468
                if (!elem.hasAttribute("value"))
469
                {
470
                        m_error = QObject::tr("Unable to read settings XML:")
471
                                .arg(QObject::tr("element <%1> lacks `value' attribute", "Load PDF settings")
472
                                        .arg(name)
473
                                );
474
                        return QDomNode().toElement();
475
                }
476
        }
477
        return elem;
478
}
479
 
2044 craig 480
bool PDFOptionsIO::readElem(QDomElement& parent, QString name, bool* value)
2043 craig 481
{
2045 craig 482
        QDomNode node = getUniqueNode(parent, name);
483
        QDomElement elem = getValueElement(node, name);
2043 craig 484
        if (elem.isNull())
485
                return false;
486
        QString elementText = elem.attribute("value");
487
        if (elementText == "true")
488
        {
489
                (*value) = true;
490
                return true;
491
        }
492
        else if (elementText == "false")
493
        {
494
                (*value) = false;
495
                return true;
496
        }
497
        else
498
        {
499
                m_error = QObject::tr("Unable to read settings XML:")
500
                        .arg(QObject::tr("element <%1> value must be `true' or `false'", "Load PDF settings")
501
                                .arg(name)
502
                        );
503
                return false;
504
        }
505
}
506
 
2044 craig 507
bool PDFOptionsIO::readElem(QDomElement& parent, QString name, int* value)
508
{
2045 craig 509
        QDomNode node = getUniqueNode(parent, name);
510
        QDomElement elem = getValueElement(node, name);
2044 craig 511
        if (elem.isNull())
512
                return false;
513
        bool ok = false;
514
        int result = elem.attribute("value").toInt(&ok);
515
        if (ok)
516
                (*value) = result;
517
        return ok;
518
}
519
 
520
bool PDFOptionsIO::readElem(QDomElement& parent, QString name, double* value)
521
{
2045 craig 522
        QDomNode node = getUniqueNode(parent, name);
523
        QDomElement elem = getValueElement(node, name);
2044 craig 524
        if (elem.isNull())
525
                return false;
526
        bool ok = false;
527
        double result = elem.attribute("value").toDouble(&ok);
528
        if (ok)
529
                (*value) = result;
530
        return ok;
531
}
532
 
533
bool PDFOptionsIO::readElem(QDomElement& parent, QString name, QString* value)
534
{
2045 craig 535
        QDomNode node = getUniqueNode(parent, name);
536
        QDomElement elem = getValueElement(node, name);
2044 craig 537
        if (elem.isNull())
538
                return false;
539
        QString result = elem.attribute("value");
540
        bool ok = result != QString::null;
541
        if (ok)
542
                (*value) = result;
543
        return ok;
544
}
545
 
2045 craig 546
// Read a stringlist saved as a list of child <item value=""> elements
547
bool PDFOptionsIO::readList(QDomElement& parent, QString name, QValueList<QString>* value)
548
{
549
        QDomNode basenode = getUniqueNode(parent, name);
550
        QDomElement listbase = getValueElement(basenode, name, false);
551
        if (listbase.isNull())
552
                return false;
553
        QValueList<QString> list;
554
        for (QDomNode node = listbase.firstChild(); !node.isNull(); node = node.nextSibling())
555
        {
556
                QDomElement elem = getValueElement(node, "item");
557
                if (elem.isNull())
558
                        return false;
559
                list.append(elem.attribute("value"));
560
        }
561
        (*value) = list;
562
        return true;
563
}
564
 
565
bool PDFOptionsIO::readPresentationData()
566
{
567
        // XML structure will be like this:
568
        // <presentationSettings>
569
        //   <presentationSettingsEntry>
570
        //     <pageEffectDuration value="0"/>
571
        //     <pageViewDuration value="0"/>
572
        //     <effectType value="0"/>
573
        //     <dm value="0"/>
574
        //     <m value="0"/>
575
        //     <di value="0"/>
576
        //   </presentationSettingsEntry>
577
        //   <presentationSettingsEntry>
578
        //     ...
579
        //   </presentationSettingsEntry>
580
        //   ...
581
        // </presentationSettings>
582
        QDomNode basenode = getUniqueNode(m_root, "presentationSettings");
583
        QDomElement pSettings = getValueElement(basenode, "presentationSettings", false);
584
        if (pSettings.isNull())
585
                return false;
586
        QValueList<PDFPresentationData> pList;
587
        for (QDomNode node = pSettings.firstChild(); !node.isNull(); node = node.nextSibling())
588
        {
589
                QDomElement elem = getValueElement(basenode, "presentationSettingsEntry", false);
590
                if (elem.isNull())
591
                        return false;
592
                PDFPresentationData pres;
593
                if (!readElem(elem, "pageEffectDuration", &pres.pageEffectDuration))
594
                        return false;
595
                if (!readElem(elem, "pageViewDuration", &pres.pageViewDuration))
596
                        return false;
597
                if (!readElem(elem, "effectType", &pres.effectType))
598
                        return false;
599
                if (!readElem(elem, "dm", &pres.Dm))
600
                        return false;
601
                if (!readElem(elem, "m", &pres.M))
602
                        return false;
603
                if (!readElem(elem, "di", &pres.Di))
604
                        return false;
605
                pList.append(pres);
606
        }
607
        return true;
608
}
609
 
610
bool PDFOptionsIO::readLPISettings()
611
{
612
        // XML structure will be like this:
613
        // <lpiSettings>
614
        //   <lpiSettingsEntry name="blah">
615
        //     <frequency value="0">
616
        //     <angle value="0">
617
        //     <spotFunc value="0">
618
        //   </lpiSettingsEntry>
619
        //   <lpiSettingsEntry name="blah2">
620
        //     ...
621
        //   </lpiSettingsEntry>
622
        //   ...
623
        // </lpiSettings>
624
        QDomNode basenode = getUniqueNode(m_root, "lpiSettings");
625
        QDomElement lpiSettings = getValueElement(basenode, "lpiSettings", false);
626
        if (lpiSettings.isNull())
627
                return false;
628
        QMap<QString,LPIData> lpiMap;
629
        for (QDomNode node = lpiSettings.firstChild(); !node.isNull(); node = node.nextSibling())
630
        {
631
                QDomElement elem = getValueElement(basenode, "lpiSettingsEntry", false);
632
                if (elem.isNull())
633
                        return false;
634
                QString name = elem.attribute("name");
635
                if (name == QString::null)
636
                {
637
                        m_error = QObject::tr("Unable to read settings XML:")
638
                                .arg(QObject::tr("element <lpiSettingsEntry> lacks `name' attribute", "Load PDF settings")
639
                                        .arg(name)
640
                                );
641
                        return false;
642
                }
643
                LPIData lpi;
644
                if (!readElem(elem, "frequency", &lpi.Frequency))
645
                        return false;
646
                if (!readElem(elem, "angle", &lpi.Angle))
647
                        return false;
648
                if (!readElem(elem, "spotFunc", &lpi.SpotFunc))
649
                        return false;
650
                lpiMap[name] = lpi;
651
        }
652
        return true;
653
}
654
 
2036 craig 655
const QString& PDFOptionsIO::lastError() const
656
{
2038 craig 657
        return m_error;
2036 craig 658
}