home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / KoOasisSettings.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-30  |  6.6 KB  |  180 lines

  1. /* This file is part of the KDE project
  2.    Copyright (C) 2004 Laurent Montel <montel@kde.org>
  3.                       David Faure <faure@kde.org>
  4.  
  5.    This library is free software; you can redistribute it and/or
  6.    modify it under the terms of the GNU Library General Public
  7.    License as published by the Free Software Foundation; either
  8.    version 2 of the License, or (at your option) any later version.
  9.  
  10.    This library is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.    Library General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU Library General Public License
  16.    along with this library; see the file COPYING.LIB.  If not, write to
  17.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.  * Boston, MA 02110-1301, USA.
  19. */
  20.  
  21.  
  22. #ifndef KOOASISSETTINGS_H
  23. #define KOOASISSETTINGS_H
  24.  
  25. #include <qdom.h>
  26. #include <koffice_export.h>
  27.  
  28. /**
  29.  * @brief Parse settings.xml file.
  30.  *
  31.  * This class helps parsing the settings.xml file of an OASIS document.
  32.  *
  33.  * For reference, the structure of settings.xml looks like:
  34.  * <pre>
  35.  *   \<office:settings\>
  36.  *      \<config:config-item-set config:name="configure-settings"\>
  37.  *      ....
  38.  *      \</config:config-item-set\>
  39.  *      \<config:config-item-set config:name="view-settings"\>
  40.  *         \<config:config-item-map-indexed config:name="Views"\>
  41.  *           \<config:config-item-map-entry\>
  42.  *             \<config:config-item config:name="SnapLinesDrawing" config:type="string"\>value\</config:config-item\>
  43.  *               ....
  44.  *                \<config:config-item-map-named config:name="Tables"\>
  45.  *                  \<config:config-item-map-entry config:name="Sheet1"\>
  46.  *                    \<config:config-item config:name="CursorPositionX"\>
  47.  *                    ......
  48.  *                  \</config:config-item-map-entry\>
  49.  *                  \<config:config-item-map-entry config:name="Sheet2"\>
  50.  *                  ....
  51.  *                  \</config:config-item-map-entry\>
  52.  *                \</config:config-item-map-named\>
  53.  *           .....
  54.  *           \</config:config-item-map-entry\>
  55.  *         \</config:config-item-map-indexed\>
  56.  *         \<config:config-item-map-indexed config:name="Interface"\>
  57.  *         .......
  58.  *         \</config:config-item-map-indexed\>
  59.  *      \</config:config-item-set\>
  60.  *   \</office:settings\>
  61.  * </pre>
  62.  * Basically, an item-set is a set of named \<config-item\>s and/or maps.
  63.  * There are two kinds of maps (by-index or by-name), and entries in the
  64.  * maps contain \<config-item\>s too, or nested maps.
  65.  *
  66.  * The API of KoOasisSettings allows the caller to look for a given item-set
  67.  * or item-map once, and then lookup multiple items inside it.
  68.  * It also allows "drilling down" inside the tree in case of nesting.
  69.  */
  70. class KOFFICECORE_EXPORT KoOasisSettings
  71. {
  72. public:
  73.     /**
  74.      * Normal KoOasisSettings constructor, for an OASIS settings.xml
  75.      */
  76.     explicit KoOasisSettings( const QDomDocument& doc );
  77.  
  78.     /**
  79.      * KoOasisSettings constructor for an OpenOffice-1.1 file
  80.      */
  81.     KoOasisSettings( const QDomDocument& doc, const char* officeNSURI, const char* configNSURI );
  82.  
  83.     class Items;
  84.  
  85.     /**
  86.      * Returns the toplevel item-set named @p itemSetName.
  87.      * If not found, the returned items instance is null.
  88.      */
  89.     Items itemSet( const QString& itemSetName ) const;
  90.  
  91.     class IndexedMap;
  92.     class NamedMap;
  93.     /// Represents a collection of items (config-item or maps).
  94.     class KOFFICECORE_EXPORT Items
  95.     {
  96.         friend class KoOasisSettings;
  97.         friend class IndexedMap;
  98.         friend class NamedMap;
  99.         Items( const QDomElement& elem, const KoOasisSettings* settings )
  100.             : m_element( elem ), m_settings( settings ) {}
  101.     public:
  102.         bool isNull() const { return m_element.isNull(); }
  103.  
  104.         /**
  105.          * Look for the config-item-map-indexed named @p itemMapName and return it.
  106.          *
  107.          * An indexed map is an array (or sequence), i.e. items are supposed to
  108.          * be retrieved by index. This is useful for e.g. "view 0", "view 1" etc.
  109.          */
  110.         IndexedMap indexedMap( const QString& itemMapName ) const;
  111.  
  112.         /**
  113.          * Look for the config-item-map-named named @p mapItemName and return it.
  114.          *
  115.          * A named map is a map where items are retrieved by entry name, @see selectItemMapEntry
  116.          * @return false if no such map was found
  117.          */
  118.         NamedMap namedMap( const QString& itemMapName ) const;
  119.  
  120.         int parseConfigItemInt( const QString& configName, int defValue = 0 ) const;
  121.         double parseConfigItemDouble( const QString& configName, double defValue = 0 ) const;
  122.         QString parseConfigItemString( const QString& configName, const QString& defValue = QString::null ) const;
  123.         bool parseConfigItemBool( const QString& configName, bool defValue = false ) const;
  124.         short parseConfigItemShort( const QString& configName, short defValue = 0 ) const;
  125.         long parseConfigItemLong( const QString& configName, long defValue = 0 ) const;
  126.     private:
  127.         /// @internal
  128.         QString findConfigItem( const QString& item, bool* ok ) const;
  129.         /// @internal
  130.         QString findConfigItem( const QDomElement& element, const QString& item, bool* ok ) const;
  131.  
  132.         QDomElement m_element;
  133.         const KoOasisSettings* m_settings;
  134.     };
  135.  
  136.     /// Internal base class for IndexedMap and NamedMap
  137.     class Map
  138.     {
  139.     public:
  140.         bool isNull() const { return m_element.isNull(); }
  141.     protected:
  142.         Map( const QDomElement& elem, const KoOasisSettings* settings )
  143.             : m_element( elem ), m_settings( settings ) {}
  144.         const QDomElement m_element;
  145.         const KoOasisSettings* m_settings;
  146.     };
  147.  
  148.     class KOFFICECORE_EXPORT IndexedMap : public Map
  149.     {
  150.         friend class Items;
  151.         IndexedMap( const QDomElement& elem, const KoOasisSettings* settings )
  152.             : Map( elem, settings ) {}
  153.     public:
  154.         /// Returns an entry in an indexed map
  155.         Items entry( int entryIndex ) const;
  156.     };
  157.  
  158.     class KOFFICECORE_EXPORT NamedMap : public Map
  159.     {
  160.         friend class Items;
  161.         NamedMap( const QDomElement& elem, const KoOasisSettings* settings )
  162.             : Map( elem, settings ) {}
  163.     public:
  164.         /// Returns an entry in a named map
  165.         Items entry( const QString& entryName ) const;
  166.     };
  167.  
  168. private:
  169.     friend class Items;
  170.     friend class IndexedMap;
  171.     friend class NamedMap;
  172.     const QDomElement m_settingsElement;
  173.     const char* m_configNSURI;
  174.  
  175.     class Private;
  176.     Private* d;
  177. };
  178.  
  179. #endif
  180.