Warning, file /office/calligra/libs/odf/KoOasisSettings.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002    Copyright (C) 2004 Laurent Montel <montel@kde.org>
0003                       David Faure <faure@kde.org>
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 
0010    This library is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this library; see the file COPYING.LIB.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019 */
0020 
0021 
0022 #ifndef KOOASISSETTINGS_H
0023 #define KOOASISSETTINGS_H
0024 
0025 #include <QDomDocument>
0026 #include "koodf_export.h"
0027 #include "KoXmlReader.h"
0028 
0029 /**
0030  * @brief Parse settings.xml file.
0031  *
0032  * This class helps parsing the settings.xml file of an OASIS document.
0033  *
0034  * For reference, the structure of settings.xml looks like:
0035  * <pre>
0036  *   \<office:settings\>
0037  *      \<config:config-item-set config:name="configure-settings"\>
0038  *      ....
0039  *      \</config:config-item-set\>
0040  *      \<config:config-item-set config:name="view-settings"\>
0041  *         \<config:config-item-map-indexed config:name="Views"\>
0042  *           \<config:config-item-map-entry\>
0043  *             \<config:config-item config:name="SnapLinesDrawing" config:type="string"\>value\</config:config-item\>
0044  *               ....
0045  *                \<config:config-item-map-named config:name="Tables"\>
0046  *                  \<config:config-item-map-entry config:name="Sheet1"\>
0047  *                    \<config:config-item config:name="CursorPositionX"\>
0048  *                    ......
0049  *                  \</config:config-item-map-entry\>
0050  *                  \<config:config-item-map-entry config:name="Sheet2"\>
0051  *                  ....
0052  *                  \</config:config-item-map-entry\>
0053  *                \</config:config-item-map-named\>
0054  *           .....
0055  *           \</config:config-item-map-entry\>
0056  *         \</config:config-item-map-indexed\>
0057  *         \<config:config-item-map-indexed config:name="Interface"\>
0058  *         .......
0059  *         \</config:config-item-map-indexed\>
0060  *      \</config:config-item-set\>
0061  *   \</office:settings\>
0062  * </pre>
0063  * Basically, an item-set is a set of named \<config-item\>s and/or maps.
0064  * There are two kinds of maps (by-index or by-name), and entries in the
0065  * maps contain \<config-item\>s too, or nested maps.
0066  *
0067  * The API of KoOasisSettings allows the caller to look for a given item-set
0068  * or item-map once, and then lookup multiple items inside it.
0069  * It also allows "drilling down" inside the tree in case of nesting.
0070  */
0071 class KOODF_EXPORT KoOasisSettings
0072 {
0073 public:
0074     /**
0075      * Normal KoOasisSettings constructor, for an OASIS settings.xml
0076      */
0077     explicit KoOasisSettings(const KoXmlDocument &doc);
0078 
0079     /**
0080      * KoOasisSettings constructor for an OpenOffice-1.1 file
0081      */
0082     KoOasisSettings(const KoXmlDocument &doc, const char *officeNsUri, const char *configNsUri);
0083 
0084     ~KoOasisSettings();
0085 
0086     class Items;
0087     /**
0088      * Returns the toplevel item-set named @p itemSetName.
0089      * If not found, the returned items instance is null.
0090      */
0091     Items itemSet(const QString &itemSetName) const;
0092 
0093     class IndexedMap;
0094     class NamedMap;
0095     /// Represents a collection of items (config-item or maps).
0096     class KOODF_EXPORT Items
0097     {
0098         friend class KoOasisSettings;
0099         friend class IndexedMap;
0100         friend class NamedMap;
0101         Items(const KoXmlElement& elem, const KoOasisSettings* settings)
0102                 : m_element(elem), m_settings(settings) {}
0103     public:
0104         bool isNull() const {
0105             return m_element.isNull();
0106         }
0107 
0108         /**
0109          * Look for the config-item-map-indexed named @p itemMapName and return it.
0110          *
0111          * An indexed map is an array (or sequence), i.e. items are supposed to
0112          * be retrieved by index. This is useful for e.g. "view 0", "view 1" etc.
0113          */
0114         IndexedMap indexedMap(const QString &itemMapName) const;
0115 
0116         /**
0117          * Look for the config-item-map-named named @p mapItemName and return it.
0118          *
0119          * A named map is a map where items are retrieved by entry name, @see selectItemMapEntry
0120          * @return false if no such map was found
0121          */
0122         NamedMap namedMap(const QString &itemMapName) const;
0123 
0124         int parseConfigItemInt(const QString &configName, int defaultValue = 0) const;
0125         qreal parseConfigItemDouble(const QString &configName, qreal defaultValue = 0) const;
0126         QString parseConfigItemString(const QString &configName, const QString &defaultValue = QString()) const;
0127         bool parseConfigItemBool(const QString &configName, bool defaultValue = false) const;
0128         short parseConfigItemShort(const QString &configName, short defaultValue = 0) const;
0129         long parseConfigItemLong(const QString &configName, long defaultValue = 0) const;
0130     private:
0131         /// @internal
0132         QString findConfigItem(const QString &item, bool *ok) const;
0133         /// @internal
0134         QString findConfigItem(const KoXmlElement &element, const QString &item, bool *ok) const;
0135 
0136         KoXmlElement m_element;
0137         const KoOasisSettings* m_settings;
0138     };
0139 
0140     /// Internal base class for IndexedMap and NamedMap
0141     class Map
0142     {
0143     public:
0144         bool isNull() const {
0145             return m_element.isNull();
0146         }
0147     protected:
0148         Map(const KoXmlElement &elem, const KoOasisSettings *settings)
0149                 : m_element(elem), m_settings(settings) {}
0150         const KoXmlElement m_element;
0151         const KoOasisSettings *m_settings;
0152     };
0153 
0154     class KOODF_EXPORT IndexedMap : public Map
0155     {
0156         friend class Items;
0157         IndexedMap(const KoXmlElement& elem, const KoOasisSettings* settings)
0158                 : Map(elem, settings) {}
0159       public:
0160         /// Returns an entry in an indexed map
0161         Items entry(int entryIndex) const;
0162     };
0163 
0164     class KOODF_EXPORT NamedMap : public Map
0165     {
0166         friend class Items;
0167         NamedMap(const KoXmlElement &elem, const KoOasisSettings *settings)
0168                 : Map(elem, settings) {}
0169       public:
0170         /// Returns an entry in a named map
0171         Items entry(const QString& entryName) const;
0172     };
0173 
0174 private:
0175     friend class Items;
0176     friend class IndexedMap;
0177     friend class NamedMap;
0178     const KoXmlElement m_settingsElement;
0179     const QString m_configNsUri;
0180 
0181     class Private;
0182     Private * const d;
0183 };
0184 
0185 #endif