LCOV - code coverage report
Current view: top level - include/unotools - configitem.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 4 4 100.0 %
Date: 2015-06-13 12:38:46 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_UNOTOOLS_CONFIGITEM_HXX
      21             : #define INCLUDED_UNOTOOLS_CONFIGITEM_HXX
      22             : 
      23             : #include <sal/types.h>
      24             : #include <rtl/ustring.hxx>
      25             : #include <com/sun/star/uno/Sequence.h>
      26             : #include <com/sun/star/uno/Reference.h>
      27             : #include <unotools/unotoolsdllapi.h>
      28             : #include <unotools/options.hxx>
      29             : #include <o3tl/typed_flags_set.hxx>
      30             : 
      31             : namespace com{ namespace sun{ namespace star{
      32             :     namespace uno{
      33             :         class Any;
      34             :     }
      35             :     namespace beans{
      36             :         struct PropertyValue;
      37             :     }
      38             :     namespace container{
      39             :         class XHierarchicalNameAccess;
      40             :     }
      41             :     namespace util{
      42             :         class XChangesListener;
      43             :     }
      44             : }}}
      45             : 
      46             : enum class ConfigItemMode
      47             : {
      48             :     ImmediateUpdate    = 0x00,
      49             :     DelayedUpdate      = 0x01,
      50             :     AllLocales         = 0x02,
      51             :     ReleaseTree        = 0x04,
      52             : };
      53             : namespace o3tl
      54             : {
      55             :     template<> struct typed_flags<ConfigItemMode> : is_typed_flags<ConfigItemMode, 0x07> {};
      56             : }
      57             : 
      58             : namespace utl
      59             : {
      60             : 
      61             :     enum  ConfigNameFormat
      62             :     {
      63             :         CONFIG_NAME_PLAINTEXT_NAME, // unescaped local node name, for user display etc.
      64             :         CONFIG_NAME_LOCAL_NAME,     // local node name, for use in XNameAccess etc. ("Item", "Q & A")
      65             :         CONFIG_NAME_LOCAL_PATH,     // one-level relative path, for use when building paths etc.  ("Item", "Typ['Q &amp; A']")
      66             :         CONFIG_NAME_FULL_PATH,       // full absolute path. ("/org.openoffice.Sample/Group/Item", "/org.openoffice.Sample/Set/Typ['Q &amp; A']")
      67             : 
      68             :         CONFIG_NAME_DEFAULT = CONFIG_NAME_LOCAL_PATH // default format
      69             :     };
      70             : 
      71             :     class ConfigChangeListener_Impl;
      72             :     class ConfigManager;
      73             : 
      74             :     class UNOTOOLS_DLLPUBLIC ConfigItem : public ConfigurationBroadcaster
      75             :     {
      76             :             friend class ConfigChangeListener_Impl;
      77             :             friend class ConfigManager;
      78             : 
      79             :             const OUString              sSubTree;
      80             :             com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess>
      81             :                                         m_xHierarchyAccess;
      82             :             com::sun::star::uno::Reference< com::sun::star::util::XChangesListener >
      83             :                                         xChangeLstnr;
      84             :             ConfigItemMode              m_nMode;
      85             :             bool                        m_bIsModified;
      86             :             bool                        m_bEnableInternalNotification;
      87             :             sal_Int16                   m_nInValueChange;
      88             : 
      89             :             void                    RemoveChangesListener();
      90             :             void                    CallNotify(
      91             :                                 const com::sun::star::uno::Sequence<OUString>& aPropertyNames);
      92             : 
      93             :             // In special mode ALL_LOCALES we must support reading/writing of localized cfg entries as Sequence< PropertyValue >.
      94             :             // These methods are helper to convert given lists of names and Any-values.
      95             :             // format:  PropertyValue.Name  = <locale as ISO string>
      96             :             //          PropertyValue.Value = <value; type depends from cfg entry!>
      97             :             // e.g.
      98             :             //          LOCALIZED NODE
      99             :             //          "UIName"
     100             :             //                      LOCALE      VALUE
     101             :             //                      "de"        "Mein Name"
     102             :             //                      "en-US"     "my name"
     103             :             void impl_packLocalizedProperties   (   const   com::sun::star::uno::Sequence< OUString >&                  lInNames    ,
     104             :                                                     const   com::sun::star::uno::Sequence< com::sun::star::uno::Any >&  lInValues   ,
     105             :                                                             com::sun::star::uno::Sequence< com::sun::star::uno::Any >&  lOutValues  );
     106             :             void impl_unpackLocalizedProperties (   const   com::sun::star::uno::Sequence< OUString >&                  lInNames    ,
     107             :                                                     const   com::sun::star::uno::Sequence< com::sun::star::uno::Any >&  lInValues   ,
     108             :                                                             com::sun::star::uno::Sequence< OUString >&                  lOutNames   ,
     109             :                                                             com::sun::star::uno::Sequence< com::sun::star::uno::Any >&  lOutValues  );
     110             : 
     111             :             com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess>
     112             :                                         GetTree();
     113             :             /** writes the changed values into the sub tree.
     114             :                 Private and only called from non-virtual public Commit().  */
     115             :             virtual void            ImplCommit() = 0;
     116             : 
     117             :         protected:
     118             :             explicit ConfigItem(const OUString &rSubTree,
     119             :                         ConfigItemMode nMode = ConfigItemMode::DelayedUpdate);
     120             : 
     121             :             void                    SetModified  (); // mark item as modified
     122             :             void                    ClearModified(); // reset state after commit!
     123             : 
     124             :             com::sun::star::uno::Sequence< com::sun::star::uno::Any>
     125             :                                     GetProperties(const com::sun::star::uno::Sequence< OUString >& rNames);
     126             : 
     127             :             com::sun::star::uno::Sequence< sal_Bool >
     128             :                                     GetReadOnlyStates(const com::sun::star::uno::Sequence< OUString >& rNames);
     129             : 
     130             :             bool                PutProperties(
     131             :                                         const com::sun::star::uno::Sequence< OUString >& rNames,
     132             :                                         const com::sun::star::uno::Sequence< com::sun::star::uno::Any>& rValues);
     133             : 
     134             :             /** enables notifications about changes on selected sub nodes/values
     135             : 
     136             :                 Before calling this method a second time for a possibly changed node/value set,
     137             :                 you must disable the current notifications by calling DisableNotification.
     138             : 
     139             :                 @see Notify
     140             :                 @see DisableNotification
     141             :             */
     142             :             bool                EnableNotification(const com::sun::star::uno::Sequence< OUString >& rNames,
     143             :                                         bool bEnableInternalNotification = false);
     144             :             /** disables notifications about changes on sub nodes/values, which previosly had
     145             :                 been enabled with EnableNotification
     146             :                 @see Notify
     147             :                 @see EnableNotification
     148             :             */
     149             :             void                    DisableNotification();
     150             :             bool                IsInternalNotification()const {return IsInValueChange();}
     151             : 
     152             :             //returns all members of a node in a specific format
     153             :             com::sun::star::uno::Sequence< OUString >
     154             :                                     GetNodeNames(const OUString& rNode);
     155             :             //returns all members of a node in a specific format
     156             :             com::sun::star::uno::Sequence< OUString >
     157             :                                     GetNodeNames(const OUString& rNode, ConfigNameFormat eFormat);
     158             :             // remove all members of a set
     159             :             bool                ClearNodeSet(const OUString& rNode);
     160             :             // remove selected members of a set
     161             :             bool                ClearNodeElements(const OUString& rNode,
     162             :                                         com::sun::star::uno::Sequence< OUString >& rElements);
     163             :             // change or add members to a set
     164             :             bool                SetSetProperties(const OUString& rNode, const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& rValues);
     165             :             // remove, change or add members of a set
     166             :             bool                ReplaceSetProperties(const OUString& rNode, const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& rValues);
     167             :             // add a new node without setting any properties
     168             :             bool                AddNode(const OUString& rNode, const OUString& rNewNode);
     169             : 
     170             :         public:
     171             :             virtual ~ConfigItem();
     172             : 
     173             :             /** is called from the ConfigManager before application ends of from the
     174             :                 PropertyChangeListener if the sub tree broadcasts changes. */
     175             :             virtual void            Notify( const com::sun::star::uno::Sequence<OUString>& aPropertyNames)=0;
     176             : 
     177       25964 :             const OUString&         GetSubTreeName() const {return sSubTree;}
     178             : 
     179    53574135 :             bool IsModified() const { return m_bIsModified;}
     180             : 
     181             :             void                    Commit();
     182             : 
     183        3483 :             bool IsInValueChange() const { return m_nInValueChange > 0;}
     184             : 
     185       25964 :             ConfigItemMode GetMode() const { return m_nMode;}
     186             :     };
     187             : }//namespace utl
     188             : #endif // INCLUDED_UNOTOOLS_CONFIGITEM_HXX
     189             : 
     190             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11