Back to index

scribus-ng  1.3.4.dfsg+svn20071115
pdfoptionsio.cpp
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 #include "pdfoptionsio.h"
00008 #include "scribusstructs.h"
00009 
00010 #include "qapplication.h"
00011 
00012 const int PDFOptionsIO::formatVersion = 1300;
00013 
00014 PDFOptionsIO::PDFOptionsIO(PDFOptions& opts) :
00015        m_doc(),
00016        m_root(),
00017        m_includePasswords(false),
00018        m_error()
00019 {
00020        this->m_opts = &opts;
00021 }
00022 
00023 // writeTo(QString) is implemented separately to writeTo(QTextStream)
00024 // because we don't want to clobber the output file until we know the
00025 // data has been generated ok, and we can't avoid clobbering the file
00026 // to create a QTextStream().
00027 bool PDFOptionsIO::writeTo(QString outFileName, bool includePasswords)
00028 {
00029        m_includePasswords = includePasswords;
00030        QString xml(buildXMLString());
00031        if (xml.isNull())
00032               return false;
00033        QFile f(outFileName);
00034        if (!f.open(IO_WriteOnly|IO_Truncate))
00035        {
00036               m_error = QObject::tr("Could not open output file %1")
00037                      .arg(qApp->translate("QFile",f.errorString()));
00038               return false;
00039        }
00040        QTextStream ts(&f);
00041        ts.setEncoding(QTextStream::UnicodeUTF8);
00042        ts << xml;
00043        m_includePasswords = false; // just to be paranoid
00044        m_error = QString::null;
00045        return true;
00046 }
00047 
00048 bool PDFOptionsIO::writeTo(QIODevice& outDevice, bool includePasswords)
00049 {
00050        m_includePasswords = includePasswords;
00051        if (!outDevice.isWritable())
00052        {
00053               m_error = QObject::tr("Output stream not writeable");
00054               return false;
00055        }
00056        QString xml = buildXMLString();
00057        if (xml.isNull())
00058               return false;
00059        QTextStream ts(&outDevice);
00060        ts.setEncoding(QTextStream::UnicodeUTF8);
00061        ts << xml;
00062        m_includePasswords = false; // just to be paranoid
00063        m_error = QString::null;
00064        return true;
00065 }
00066 
00067 // Construct and return an XML string representing the settings
00068 QString PDFOptionsIO::buildXMLString()
00069 {
00070        // Verify to make sure our settings are sane
00071        QString vrfyError;
00072        // Make sure the options are sane
00073        PDFOptions::VerifyResults vr = m_opts->verify(&vrfyError);
00074        if (vr != PDFOptions::Verify_NoError)
00075        {
00076               m_error = QObject::tr("Verification of settings failed: %1").arg(vrfyError);
00077               return QString::null;
00078        }
00079        // Build the document. Initial implementation uses QDom.
00080        m_doc = QDomDocument();
00081        m_root = m_doc.createElement("ScribusPDFOptions");
00082        m_root.setAttribute("version", formatVersion);
00083        m_doc.appendChild(m_root);
00084        // Fill the guts of the document
00085        buildSettings();
00086        // We're done - return a string containing the document XML
00087        QString xml = m_doc.toString();
00088        xml.prepend(
00089               "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
00090               "<!DOCTYPE ScribusPDFOptions SYSTEM 'scribuspdfoptions.dtd'>\n"
00091               );
00092        return xml;
00093 }
00094 
00095 // Build up the stored settings into the passed DOM objects
00096 void PDFOptionsIO::buildSettings()
00097 {
00098        addElem(m_root, "firstUse", m_opts->firstUse);
00099        addElem(m_root, "thumbnails", m_opts->Thumbnails);
00100        addElem(m_root, "articles", m_opts->Articles);
00101        addElem(m_root, "useLayers", m_opts->useLayers);
00102        addElem(m_root, "compress", m_opts->Compress);
00103        addElem(m_root, "compressMethod", m_opts->CompressMethod);
00104        addElem(m_root, "quality", m_opts->Quality);
00105        addElem(m_root, "recalcPic", m_opts->RecalcPic);
00106        addElem(m_root, "bookmarks", m_opts->Bookmarks);
00107        addElem(m_root, "picRes", m_opts->PicRes);
00108        QString pdfVersString;
00109        switch (m_opts->Version)
00110        {
00111               case PDFOptions::PDFVersion_X3:
00112                      pdfVersString = "X3";
00113                      break;
00114               default:
00115                      pdfVersString = QString::number(m_opts->Version);
00116                      break;
00117        }
00118        addElem(m_root, "pdfVersion", pdfVersString);
00119        addElem(m_root, "resolution", m_opts->Resolution);
00120        addElem(m_root, "binding", m_opts->Binding);
00121        addList(m_root, "embedFonts", m_opts->EmbedList);
00122        addList(m_root, "subsetFonts", m_opts->SubsetList);
00123        addElem(m_root, "mirrorH", m_opts->MirrorH);
00124        addElem(m_root, "mirrorV", m_opts->MirrorV);
00125        addElem(m_root, "rotateDegrees", m_opts->RotateDeg);
00126        addElem(m_root, "presentMode", m_opts->PresentMode);
00127        addPresentationData();
00128        addElem(m_root, "filename", m_opts->Datei);
00129        addElem(m_root, "isGrayscale", m_opts->isGrayscale);
00130        addElem(m_root, "useRGB", m_opts->UseRGB);
00131        addElem(m_root, "useProfiles", m_opts->UseProfiles);
00132        addElem(m_root, "useProfiles2", m_opts->UseProfiles2);
00133        addElem(m_root, "useLPI", m_opts->UseLPI);
00134        addElem(m_root, "useSpotColors", m_opts->UseSpotColors);
00135        addElem(m_root, "doOverprint", m_opts->doOverprint);
00136        addElem(m_root, "doMultiFile", m_opts->doMultiFile);
00137        addLPISettings();
00138        addElem(m_root, "solidProf", m_opts->SolidProf);
00139        addElem(m_root, "sComp", m_opts->SComp);
00140        addElem(m_root, "imageProf", m_opts->ImageProf);
00141        addElem(m_root, "embeddedI", m_opts->EmbeddedI);
00142        addElem(m_root, "intent2", m_opts->Intent2);
00143        addElem(m_root, "printProf", m_opts->PrintProf);
00144        addElem(m_root, "info", m_opts->Info);
00145        addElem(m_root, "intent", m_opts->Intent);
00146        addElem(m_root, "bleedTop", m_opts->bleeds.Top);
00147        addElem(m_root, "bleedLeft", m_opts->bleeds.Left);
00148        addElem(m_root, "bleedRight", m_opts->bleeds.Right);
00149        addElem(m_root, "bleedBottom", m_opts->bleeds.Bottom);
00150        addElem(m_root, "encrypt", m_opts->Encrypt);
00151        addElem(m_root, "passOwner", m_includePasswords ? m_opts->PassOwner : "");
00152        addElem(m_root, "passUser", m_includePasswords ? m_opts->PassUser : "");
00153        addElem(m_root, "permissions", m_opts->Permissions);
00154 }
00155 
00156 // Convenience functions to add a single-attribute element
00157 // of a particular type to the tree at a given point.
00158 
00159 void PDFOptionsIO::addElem(QDomElement& addTo, QString name, bool value)
00160 {
00161        QDomElement elem = m_doc.createElement(name);
00162        elem.setAttribute("value", value ? "true" : "false" );
00163        addTo.appendChild(elem);
00164 }
00165 
00166 void PDFOptionsIO::addElem(QDomElement& addTo, QString name, QString value)
00167 {
00168        QDomElement elem = m_doc.createElement(name);
00169        elem.setAttribute("value",value);
00170        addTo.appendChild(elem);
00171 }
00172 
00173 void PDFOptionsIO::addElem(QDomElement& addTo, QString name, int value)
00174 {
00175        QDomElement elem = m_doc.createElement(name);
00176        elem.setAttribute("value",value);
00177        addTo.appendChild(elem);
00178 }
00179 
00180 void PDFOptionsIO::addElem(QDomElement& addTo, QString name, double value)
00181 {
00182        QDomElement elem = m_doc.createElement(name);
00183        elem.setAttribute("value",value);
00184        addTo.appendChild(elem);
00185 }
00186 
00187 // Save a QValueList<String> or QStringList as a list of
00188 // <item value=""> elements
00189 void PDFOptionsIO::addList(QDomElement& addTo, QString name, QValueList<QString>& value)
00190 {
00191        // List base element has no attributes, only children
00192        QDomElement listbase = m_doc.createElement(name);
00193        addTo.appendChild(listbase);
00194        QValueList<QString>::iterator it;
00195        for (it = value.begin(); it != value.end(); ++it)
00196               addElem(listbase, "item", *(it));
00197 }
00198 
00199 // save PDFOptions::PresentVals
00200 void PDFOptionsIO::addPresentationData()
00201 {
00202        // PDFOptions::PresentVals is a QValueList<PDFPresentationData>
00203        //
00204        // XML structure will be like this:
00205        // <presentationSettings>
00206        //   <presentationSettingsEntry>
00207        //     <pageEffectDuration value="0"/>
00208        //     <pageViewDuration value="0"/>
00209        //     <effectType value="0"/>
00210        //     <dm value="0"/>
00211        //     <m value="0"/>
00212        //     <di value="0"/>
00213        //   </presentationSettingsEntry>
00214        //   <presentationSettingsEntry>
00215        //     ...
00216        //   </presentationSettingsEntry>
00217        //   ...
00218        // </presentationSettings>
00219        QDomElement presentationSettings = m_doc.createElement("presentationSettings");
00220        m_root.appendChild(presentationSettings);
00221        QValueList<PDFPresentationData>::iterator it;
00222        for (it = m_opts->PresentVals.begin(); it != m_opts->PresentVals.end(); ++it)
00223        {
00224               // Settings entry has no attributes, only children
00225               QDomElement psEntry = m_doc.createElement("presentationSettingsEntry");
00226               presentationSettings.appendChild(psEntry);
00227               // Children:
00228               addElem(psEntry, "pageEffectDuration", (*it).pageEffectDuration);
00229               addElem(psEntry, "pageViewDuration", (*it).pageViewDuration);
00230               addElem(psEntry, "effectType", (*it).effectType);
00231               addElem(psEntry, "dm", (*it).Dm);
00232               addElem(psEntry, "m", (*it).M);
00233               addElem(psEntry, "di", (*it).Di);
00234        }
00235 }
00236 
00237 // Save PDFOptions::LPISettings
00238 void PDFOptionsIO::addLPISettings()
00239 {
00240        // PDFOptions::LPISettings is a QMap<QString,LPIData>
00241        //
00242        // XML structure will be like this:
00243        // <lpiSettings>
00244        //   <lpiSettingsEntry name="blah">
00245        //     <frequency value="0">
00246        //     <angle value="0">
00247        //     <spotFunc value="0">
00248        //   </lpiSettingsEntry>
00249        //   <lpiSettingsEntry name="blah2">
00250        //     ...
00251        //   </lpiSettingsEntry>
00252        //   ...
00253        // </lpiSettings>
00254        QDomElement lpiSettings = m_doc.createElement("lpiSettings");
00255        m_root.appendChild(lpiSettings);
00256        QMap<QString,LPIData>::iterator it;
00257        for (it = m_opts->LPISettings.begin(); it != m_opts->LPISettings.end(); ++it)
00258        {
00259               // Settings entry has no attributes, only children
00260               QDomElement lpiEntry = m_doc.createElement("lpiSettingsEntry");
00261               lpiEntry.setAttribute("name", it.key());
00262               lpiSettings.appendChild(lpiEntry);
00263               // Children:
00264               addElem(lpiEntry, "frequency", (*it).Frequency);
00265               addElem(lpiEntry, "angle", (*it).Angle);
00266               addElem(lpiEntry, "spotFunc", (*it).SpotFunc);
00267        }
00268 
00269 }
00270 
00271 // overload of bool readFrom(QTextStream& inStream)
00272 bool PDFOptionsIO::readFrom(QString inFileName)
00273 {
00274        QFile f(inFileName);
00275        if (!f.open(IO_ReadOnly))
00276        {
00277               m_error = QObject::tr("Could not open input file %1")
00278                      .arg(qApp->translate("QFile",f.errorString()));
00279               return false;
00280        }
00281        return readFrom(f);
00282 }
00283 
00284 bool PDFOptionsIO::readFrom(QIODevice& inDevice)
00285 {
00286        if (!inDevice.isReadable())
00287               return false;
00288        QString domError;
00289        int errorLine, errorColumn;
00290        if (!m_doc.setContent(&inDevice, &domError, &errorLine, &errorColumn))
00291        {
00292               m_error = QObject::tr("Unable to read settings XML:")
00293                      .arg(QObject::tr("%1 (line %2 col %3)", "Load PDF settings")
00294                             .arg(domError).arg(errorLine).arg(errorColumn)
00295                      );
00296               return false;
00297        }
00298        if (!readSettings())
00299               // m_error should already be set
00300               return false;
00301        m_error = QString::null;
00302        return true;
00303 }
00304 
00305 // Helper for readFrom(...) to read settings from the DOM
00306 bool PDFOptionsIO::readSettings()
00307 {
00308        // Get the root element
00309        m_root = m_doc.documentElement();
00310        if (m_root.isNull())
00311        {
00312               m_error = QObject::tr("Unable to read settings XML: %1")
00313                      .arg(QObject::tr("null root node", "Load PDF settings"));
00314        }
00315        // and start processing elements
00316        if (!readElem(m_root, "firstUse", &m_opts->firstUse))
00317               return false;
00318        if (!readElem(m_root, "thumbnails", &m_opts->Thumbnails))
00319               return false;
00320        if (!readElem(m_root, "articles", &m_opts->Articles))
00321               return false;
00322        if (!readElem(m_root, "useLayers", &m_opts->useLayers))
00323               return false;
00324        if (!readElem(m_root, "compress", &m_opts->Compress))
00325               return false;
00326        if (!readElem(m_root, "compressMethod", &m_opts->CompressMethod))
00327               return false;
00328        if (!readElem(m_root, "quality", &m_opts->Quality))
00329               return false;
00330        if (!readElem(m_root, "recalcPic", &m_opts->RecalcPic))
00331               return false;
00332        if (!readElem(m_root, "bookmarks", &m_opts->Bookmarks))
00333               return false;
00334        if (!readElem(m_root, "picRes", &m_opts->PicRes))
00335               return false;
00336        readPDFVersion();
00337        if (!readElem(m_root, "resolution", &m_opts->Resolution))
00338               return false;
00339        if (!readElem(m_root, "binding", &m_opts->Binding))
00340               return false;
00341        if (!readList(m_root, "embedFonts", &m_opts->EmbedList))
00342               return false;
00343        if (!readList(m_root, "subsetFonts", &m_opts->SubsetList))
00344               return false;
00345        if (!readElem(m_root, "mirrorH", &m_opts->MirrorH))
00346               return false;
00347        if (!readElem(m_root, "mirrorV", &m_opts->MirrorV))
00348               return false;
00349        if (!readElem(m_root, "rotateDegrees", &m_opts->RotateDeg))
00350               return false;
00351        if (!readElem(m_root, "presentMode", &m_opts->PresentMode))
00352               return false;
00353        if (!readPresentationData())
00354               return false;
00355        if (!readElem(m_root, "filename", &m_opts->Datei))
00356               return false;
00357        if (!readElem(m_root, "isGrayscale", &m_opts->isGrayscale))
00358               return false;
00359        if (!readElem(m_root, "useRGB", &m_opts->UseRGB))
00360               return false;
00361        if (!readElem(m_root, "useProfiles", &m_opts->UseProfiles))
00362               return false;
00363        if (!readElem(m_root, "useProfiles2", &m_opts->UseProfiles2))
00364               return false;
00365        if (!readElem(m_root, "useLPI", &m_opts->UseLPI))
00366               return false;
00367        if (!readElem(m_root, "useSpotColors", &m_opts->UseSpotColors))
00368               return false;
00369        if (!readElem(m_root, "doOverprint", &m_opts->doOverprint))
00370               return false;
00371        if (!readElem(m_root, "doMultiFile", &m_opts->doMultiFile))
00372               return false;
00373        if (!readLPISettings())
00374               return false;
00375        if (!readElem(m_root, "solidProf", &m_opts->SolidProf))
00376               return false;
00377        if (!readElem(m_root, "sComp", &m_opts->SComp))
00378               return false;
00379        if (!readElem(m_root, "imageProf", &m_opts->ImageProf))
00380               return false;
00381        if (!readElem(m_root, "embeddedI", &m_opts->EmbeddedI))
00382               return false;
00383        if (!readElem(m_root, "intent2", &m_opts->Intent2))
00384               return false;
00385        if (!readElem(m_root, "printProf", &m_opts->PrintProf))
00386               return false;
00387        if (!readElem(m_root, "info", &m_opts->Info))
00388               return false;
00389        if (!readElem(m_root, "intent", &m_opts->Intent))
00390               return false;
00391        if (!readElem(m_root, "bleedTop", &m_opts->bleeds.Top))
00392               return false;
00393        if (!readElem(m_root, "bleedLeft", &m_opts->bleeds.Left))
00394               return false;
00395        if (!readElem(m_root, "bleedRight", &m_opts->bleeds.Right))
00396               return false;
00397        if (!readElem(m_root, "bleedBottom", &m_opts->bleeds.Bottom))
00398               return false;
00399        if (!readElem(m_root, "encrypt", &m_opts->Encrypt))
00400               return false;
00401        if (!readElem(m_root, "passOwner", &m_opts->PassOwner))
00402               return false;
00403        if (!readElem(m_root, "passUser", &m_opts->PassUser))
00404               return false;
00405        if (!readElem(m_root, "permissions", &m_opts->Permissions))
00406               return false;
00407        return true;
00408 }
00409 
00410 bool PDFOptionsIO::readPDFVersion()
00411 {
00412        QString pdfVersString;
00413        if (!readElem(m_root, "pdfVersion", &pdfVersString))
00414               return false;
00415        if (pdfVersString == "X3")
00416        {
00417               m_opts->Version = PDFOptions::PDFVersion_X3;
00418               return true;
00419        }
00420        else if (pdfVersString == "13")
00421        {
00422               m_opts->Version = PDFOptions::PDFVersion_13;
00423               return true;
00424        }
00425        else if (pdfVersString == "14")
00426        {
00427               m_opts->Version = PDFOptions::PDFVersion_14;
00428               return true;
00429        }
00430        else if (pdfVersString == "15")
00431        {
00432               m_opts->Version = PDFOptions::PDFVersion_15;
00433               return true;
00434        }
00435        else
00436        {
00437               m_error = QObject::tr("Unable to read settings XML:")
00438                      .arg(QObject::tr("<pdfVersion> invalid", "Load PDF settings"));
00439               return false;
00440        }
00441 }
00442 
00443 // returns a null node on failure
00444 QDomNode PDFOptionsIO::getUniqueNode(QDomElement& parent, QString name)
00445 {
00446        QDomNodeList nodes = parent.elementsByTagName(name);
00447        if (nodes.count() != 1)
00448        {
00449               m_error = QObject::tr("Unable to read settings XML:")
00450                      .arg(QObject::tr("found %1 <%2> nodes, need 1.", "Load PDF settings")
00451                             .arg(nodes.count()).arg(name)
00452                      );
00453               return QDomNode();
00454        }
00455        return nodes.item(0);
00456 }
00457 
00458 // Return the node as a QDomElement iff it is a QDomElement with
00459 // a `value' attribute; otherwise return a null element.
00460 QDomElement PDFOptionsIO::getValueElement(QDomNode& node, QString name, bool isValue)
00461 {
00462        if (node.isNull())
00463        {
00464               m_error = QObject::tr("Unable to read settings XML:")
00465                      .arg(QObject::tr("unexpected null <%2> node", "Load PDF settings")
00466                             .arg(name)
00467                      );
00468               return QDomNode().toElement();
00469        }
00470        if (!node.isElement())
00471        {
00472               m_error = QObject::tr("Unable to read settings XML:")
00473                      .arg(QObject::tr("node <%1> not an element", "Load PDF settings")
00474                             .arg(name)
00475                      );
00476               return QDomNode().toElement();
00477        }
00478        QDomElement elem = node.toElement();
00479        if (elem.tagName() != name)
00480        {
00481               m_error = QObject::tr("Unable to read settings XML:")
00482                      .arg(QString("Internal error: element named <%1> not expected <%2>")
00483                                    .arg(elem.tagName()).arg(name)
00484                      );
00485               return QDomNode().toElement();
00486        }
00487        if (isValue)
00488        {
00489               // We need to check that it has a `value' attribute
00490               if (!elem.hasAttribute("value"))
00491               {
00492                      m_error = QObject::tr("Unable to read settings XML:")
00493                             .arg(QObject::tr("element <%1> lacks `value' attribute", "Load PDF settings")
00494                                    .arg(name)
00495                             );
00496                      return QDomNode().toElement();
00497               }
00498        }
00499        return elem;
00500 }
00501 
00502 bool PDFOptionsIO::readElem(QDomElement& parent, QString name, bool* value)
00503 {
00504        QDomNode node = getUniqueNode(parent, name);
00505        QDomElement elem = getValueElement(node, name);
00506        if (elem.isNull())
00507               return false;
00508        QString elementText = elem.attribute("value");
00509        if (elementText == "true")
00510        {
00511               (*value) = true;
00512               return true;
00513        }
00514        else if (elementText == "false")
00515        {
00516               (*value) = false;
00517               return true;
00518        }
00519        else
00520        {
00521               m_error = QObject::tr("Unable to read settings XML:")
00522                      .arg(QObject::tr("element <%1> value must be `true' or `false'", "Load PDF settings")
00523                             .arg(name)
00524                      );
00525               return false;
00526        }
00527 }
00528 
00529 bool PDFOptionsIO::readElem(QDomElement& parent, QString name, int* value)
00530 {
00531        QDomNode node = getUniqueNode(parent, name);
00532        QDomElement elem = getValueElement(node, name);
00533        if (elem.isNull())
00534               return false;
00535        bool ok = false;
00536        int result = elem.attribute("value").toInt(&ok);
00537        if (ok)
00538               (*value) = result;
00539        return ok;
00540 }
00541 
00542 bool PDFOptionsIO::readElem(QDomElement& parent, QString name, double* value)
00543 {
00544        QDomNode node = getUniqueNode(parent, name);
00545        QDomElement elem = getValueElement(node, name);
00546        if (elem.isNull())
00547               return false;
00548        bool ok = false;
00549        double result = elem.attribute("value").toDouble(&ok);
00550        if (ok)
00551               (*value) = result;
00552        return ok;
00553 }
00554 
00555 bool PDFOptionsIO::readElem(QDomElement& parent, QString name, QString* value)
00556 {
00557        QDomNode node = getUniqueNode(parent, name);
00558        QDomElement elem = getValueElement(node, name);
00559        if (elem.isNull())
00560               return false;
00561        QString result = elem.attribute("value");
00562        bool ok = !result.isNull();
00563        if (ok)
00564               (*value) = result;
00565        return ok;
00566 }
00567 
00568 // Read a stringlist saved as a list of child <item value=""> elements
00569 bool PDFOptionsIO::readList(QDomElement& parent, QString name, QValueList<QString>* value)
00570 {
00571        QDomNode basenode = getUniqueNode(parent, name);
00572        QDomElement listbase = getValueElement(basenode, name, false);
00573        if (listbase.isNull())
00574               return false;
00575        QValueList<QString> list;
00576        for (QDomNode node = listbase.firstChild(); !node.isNull(); node = node.nextSibling())
00577        {
00578               QDomElement elem = getValueElement(node, "item");
00579               if (elem.isNull())
00580                      return false;
00581               list.append(elem.attribute("value"));
00582        }
00583        (*value) = list;
00584        return true;
00585 }
00586 
00587 bool PDFOptionsIO::readPresentationData()
00588 {
00589        // XML structure will be like this:
00590        // <presentationSettings>
00591        //   <presentationSettingsEntry>
00592        //     <pageEffectDuration value="0"/>
00593        //     <pageViewDuration value="0"/>
00594        //     <effectType value="0"/>
00595        //     <dm value="0"/>
00596        //     <m value="0"/>
00597        //     <di value="0"/>
00598        //   </presentationSettingsEntry>
00599        //   <presentationSettingsEntry>
00600        //     ...
00601        //   </presentationSettingsEntry>
00602        //   ...
00603        // </presentationSettings>
00604        QDomNode basenode = getUniqueNode(m_root, "presentationSettings");
00605        QDomElement pSettings = getValueElement(basenode, "presentationSettings", false);
00606        if (pSettings.isNull())
00607               return false;
00608        QValueList<PDFPresentationData> pList;
00609        for (QDomNode node = pSettings.firstChild(); !node.isNull(); node = node.nextSibling())
00610        {
00611               QDomElement elem = getValueElement(basenode, "presentationSettingsEntry", false);
00612               if (elem.isNull())
00613                      return false;
00614               PDFPresentationData pres;
00615               if (!readElem(elem, "pageEffectDuration", &pres.pageEffectDuration))
00616                      return false;
00617               if (!readElem(elem, "pageViewDuration", &pres.pageViewDuration))
00618                      return false;
00619               if (!readElem(elem, "effectType", &pres.effectType))
00620                      return false;
00621               if (!readElem(elem, "dm", &pres.Dm))
00622                      return false;
00623               if (!readElem(elem, "m", &pres.M))
00624                      return false;
00625               if (!readElem(elem, "di", &pres.Di))
00626                      return false;
00627               pList.append(pres);
00628        }
00629        return true;
00630 }
00631 
00632 bool PDFOptionsIO::readLPISettings()
00633 {
00634        // XML structure will be like this:
00635        // <lpiSettings>
00636        //   <lpiSettingsEntry name="blah">
00637        //     <frequency value="0">
00638        //     <angle value="0">
00639        //     <spotFunc value="0">
00640        //   </lpiSettingsEntry>
00641        //   <lpiSettingsEntry name="blah2">
00642        //     ...
00643        //   </lpiSettingsEntry>
00644        //   ...
00645        // </lpiSettings>
00646        QDomNode basenode = getUniqueNode(m_root, "lpiSettings");
00647        QDomElement lpiSettings = getValueElement(basenode, "lpiSettings", false);
00648        if (lpiSettings.isNull())
00649               return false;
00650        QMap<QString,LPIData> lpiMap;
00651        for (QDomNode node = lpiSettings.firstChild(); !node.isNull(); node = node.nextSibling())
00652        {
00653               QDomElement elem = getValueElement(basenode, "lpiSettingsEntry", false);
00654               if (elem.isNull())
00655                      return false;
00656               QString name (elem.attribute("name"));
00657               if (name.isNull())
00658               {
00659                      m_error = QObject::tr("Unable to read settings XML:")
00660                             .arg(QObject::tr("element <lpiSettingsEntry> lacks `name' attribute", "Load PDF settings")
00661                                    .arg(name)
00662                             );
00663                      return false;
00664               }
00665               LPIData lpi;
00666               if (!readElem(elem, "frequency", &lpi.Frequency))
00667                      return false;
00668               if (!readElem(elem, "angle", &lpi.Angle))
00669                      return false;
00670               if (!readElem(elem, "spotFunc", &lpi.SpotFunc))
00671                      return false;
00672               lpiMap[name] = lpi;
00673        }
00674        return true;
00675 }
00676 
00677 const QString& PDFOptionsIO::lastError() const
00678 {
00679        return m_error;
00680 }