LCOV - code coverage report
Current view: top level - unotools/source/config - localisationoptions.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 49 73 67.1 %
Date: 2014-04-11 Functions: 12 14 85.7 %
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             : #include <unotools/localisationoptions.hxx>
      21             : #include <unotools/configmgr.hxx>
      22             : #include <unotools/configitem.hxx>
      23             : #include <tools/debug.hxx>
      24             : #include <com/sun/star/uno/Any.hxx>
      25             : #include <com/sun/star/uno/Sequence.hxx>
      26             : 
      27             : #include "itemholder1.hxx"
      28             : 
      29             : using namespace ::utl;
      30             : using namespace ::rtl;
      31             : using namespace ::osl;
      32             : using namespace ::com::sun::star::uno;
      33             : 
      34             : #define ROOTNODE_LOCALISATION           OUString("Office.Common/View/Localisation")
      35             : #define DEFAULT_AUTOMNEMONIC            false
      36             : #define DEFAULT_DIALOGSCALE             0
      37             : 
      38             : #define PROPERTYNAME_AUTOMNEMONIC       OUString("AutoMnemonic")
      39             : #define PROPERTYNAME_DIALOGSCALE        OUString("DialogScale")
      40             : 
      41             : #define PROPERTYHANDLE_AUTOMNEMONIC     0
      42             : #define PROPERTYHANDLE_DIALOGSCALE      1
      43             : 
      44             : #define PROPERTYCOUNT                   2
      45             : 
      46             : class SvtLocalisationOptions_Impl : public ConfigItem
      47             : {
      48             :     public:
      49             : 
      50             :          SvtLocalisationOptions_Impl();
      51             :         virtual ~SvtLocalisationOptions_Impl();
      52             : 
      53             :         /*-****************************************************************************************************
      54             :             @short      called for notify of configmanager
      55             :             @descr      These method is called from the ConfigManager before application ends or from the
      56             :                          PropertyChangeListener if the sub tree broadcasts changes. You must update your
      57             :                         internal values.
      58             : 
      59             :             @seealso    baseclass ConfigItem
      60             : 
      61             :             @param      "seqPropertyNames" is the list of properties which should be updated.
      62             :         *//*-*****************************************************************************************************/
      63             : 
      64             :         virtual void Notify( const Sequence< OUString >& seqPropertyNames ) SAL_OVERRIDE;
      65             : 
      66             :         /*-****************************************************************************************************
      67             :             @short      write changes to configuration
      68             :             @descr      These method writes the changed values into the sub tree
      69             :                         and should always called in our destructor to guarantee consistency of config data.
      70             : 
      71             :             @seealso    baseclass ConfigItem
      72             :         *//*-*****************************************************************************************************/
      73             : 
      74             :         virtual void Commit() SAL_OVERRIDE;
      75             : 
      76             :         /*-****************************************************************************************************
      77             :             @short      access method to get internal values
      78             :             @descr      These method give us a chance to regulate acces to our internal values.
      79             :                         It's not used in the moment - but it's possible for the feature!
      80             :         *//*-*****************************************************************************************************/
      81             : 
      82             :         bool    IsAutoMnemonic  (                   ) const;
      83             :         sal_Int32   GetDialogScale  (                   ) const;
      84             : 
      85             :     private:
      86             : 
      87             :         /*-****************************************************************************************************
      88             :             @short      return list of key names of our configuration management which represent oue module tree
      89             :             @descr      These methods return a static const list of key names. We need it to get needed values from our
      90             :                         configuration management.
      91             :             @return     A list of needed configuration keys is returned.
      92             :         *//*-*****************************************************************************************************/
      93             : 
      94             :         static Sequence< OUString > GetPropertyNames();
      95             : 
      96             :     private:
      97             : 
      98             :         bool    m_bAutoMnemonic;
      99             :         sal_Int32   m_nDialogScale;
     100             : };
     101             : 
     102             : //  constructor
     103             : 
     104         143 : SvtLocalisationOptions_Impl::SvtLocalisationOptions_Impl()
     105             :     // Init baseclasses first
     106             :     :   ConfigItem          ( ROOTNODE_LOCALISATION )
     107             :     // Init member then.
     108             :     ,   m_bAutoMnemonic     ( DEFAULT_AUTOMNEMONIC  )
     109         143 :     ,   m_nDialogScale      ( DEFAULT_DIALOGSCALE   )
     110             : {
     111             :     // Use our static list of configuration keys to get his values.
     112         143 :     Sequence< OUString >    seqNames    = GetPropertyNames  (           );
     113         286 :     Sequence< Any >         seqValues   = GetProperties     ( seqNames  );
     114             : 
     115             :     // Safe impossible cases.
     116             :     // We need values from ALL configuration keys.
     117             :     // Follow assignment use order of values in relation to our list of key names!
     118             :     DBG_ASSERT( !(seqNames.getLength()!=seqValues.getLength()), "SvtLocalisationOptions_Impl::SvtLocalisationOptions_Impl()\nI miss some values of configuration keys!\n" );
     119             : 
     120             :     // Copy values from list in right order to our internal member.
     121         143 :     sal_Int32 nPropertyCount = seqValues.getLength();
     122         429 :     for( sal_Int32 nProperty=0; nProperty<nPropertyCount; ++nProperty )
     123             :     {
     124         286 :         if (!seqValues[nProperty].hasValue())
     125           0 :             continue;
     126         286 :         switch( nProperty )
     127             :         {
     128             :             case PROPERTYHANDLE_AUTOMNEMONIC    :   {
     129             :                                                         DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtLocalisationOptions_Impl::SvtLocalisationOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Localisation\\AutoMnemonic\"?" );
     130         143 :                                                         seqValues[nProperty] >>= m_bAutoMnemonic;
     131             :                                                     }
     132         143 :                                                     break;
     133             : 
     134             :             case PROPERTYHANDLE_DIALOGSCALE     :   {
     135             :                                                         DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_LONG), "SvtLocalisationOptions_Impl::SvtLocalisationOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Localisation\\DialogScale\"?" );
     136         143 :                                                         seqValues[nProperty] >>= m_nDialogScale;
     137             :                                                     }
     138         143 :                                                     break;
     139             :         }
     140             :     }
     141             : 
     142             :     // Enable notification mechanism of our baseclass.
     143             :     // We need it to get information about changes outside these class on our used configuration keys!
     144         286 :     EnableNotification( seqNames );
     145         143 : }
     146             : 
     147             : //  destructor
     148             : 
     149         426 : SvtLocalisationOptions_Impl::~SvtLocalisationOptions_Impl()
     150             : {
     151             :     // We must save our current values .. if user forget it!
     152         142 :     if( IsModified() )
     153             :     {
     154           0 :         Commit();
     155             :     }
     156         284 : }
     157             : 
     158             : //  public method
     159             : 
     160           0 : void SvtLocalisationOptions_Impl::Notify( const Sequence< OUString >& seqPropertyNames )
     161             : {
     162             :     // Use given list of updated properties to get his values from configuration directly!
     163           0 :     Sequence< Any > seqValues = GetProperties( seqPropertyNames );
     164             :     // Safe impossible cases.
     165             :     // We need values from ALL notified configuration keys.
     166             :     DBG_ASSERT( !(seqPropertyNames.getLength()!=seqValues.getLength()), "SvtLocalisationOptions_Impl::Notify()\nI miss some values of configuration keys!\n" );
     167             :     // Step over list of property names and get right value from coreesponding value list to set it on internal members!
     168           0 :     sal_Int32 nCount = seqPropertyNames.getLength();
     169           0 :     for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
     170             :     {
     171           0 :         if( seqPropertyNames[nProperty] == PROPERTYNAME_AUTOMNEMONIC )
     172             :         {
     173             :             DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtLocalisationOptions_Impl::SvtLocalisationOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Localisation\\AutoMnemonic\"?" );
     174           0 :             seqValues[nProperty] >>= m_bAutoMnemonic;
     175             :         }
     176             :         else
     177           0 :         if( seqPropertyNames[nProperty] == PROPERTYNAME_DIALOGSCALE )
     178             :         {
     179             :             DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_LONG), "SvtLocalisationOptions_Impl::SvtLocalisationOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Localisation\\DialogScale\"?" );
     180           0 :             seqValues[nProperty] >>= m_nDialogScale;
     181             :         }
     182             :         #if OSL_DEBUG_LEVEL > 1
     183             :         else DBG_ASSERT( sal_False, "SvtLocalisationOptions_Impl::Notify()\nUnknown property detected ... I can't handle these!\n" );
     184             :         #endif
     185             :     }
     186             : 
     187           0 :     NotifyListeners(0);
     188           0 : }
     189             : 
     190             : //  public method
     191             : 
     192           0 : void SvtLocalisationOptions_Impl::Commit()
     193             : {
     194             :     // Get names of supported properties, create a list for values and copy current values to it.
     195           0 :     Sequence< OUString >    seqNames    = GetPropertyNames  ();
     196           0 :     sal_Int32               nCount      = seqNames.getLength();
     197           0 :     Sequence< Any >         seqValues   ( nCount );
     198           0 :     for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
     199             :     {
     200           0 :         switch( nProperty )
     201             :         {
     202             :             case PROPERTYHANDLE_AUTOMNEMONIC    :   {
     203           0 :                                                         seqValues[nProperty] <<= m_bAutoMnemonic;
     204             :                                                     }
     205           0 :                                                     break;
     206             : 
     207             :             case PROPERTYHANDLE_DIALOGSCALE     :   {
     208           0 :                                                         seqValues[nProperty] <<= m_nDialogScale;
     209             :                                                     }
     210           0 :                                                     break;
     211             :         }
     212             :     }
     213             :     // Set properties in configuration.
     214           0 :     PutProperties( seqNames, seqValues );
     215           0 : }
     216             : 
     217             : //  public method
     218             : 
     219         143 : bool SvtLocalisationOptions_Impl::IsAutoMnemonic() const
     220             : {
     221         143 :     return m_bAutoMnemonic;
     222             : }
     223             : 
     224             : //  public method
     225             : 
     226         143 : sal_Int32 SvtLocalisationOptions_Impl::GetDialogScale() const
     227             : {
     228         143 :     return m_nDialogScale;
     229             : }
     230             : 
     231         143 : Sequence< OUString > SvtLocalisationOptions_Impl::GetPropertyNames()
     232             : {
     233             :     // Build static list of configuration key names.
     234             :     const OUString aProperties[] =
     235             :     {
     236             :         PROPERTYNAME_AUTOMNEMONIC   ,
     237             :         PROPERTYNAME_DIALOGSCALE    ,
     238         429 :     };
     239             :     // Initialize return sequence with these list ...
     240         143 :     Sequence< OUString > seqPropertyNames(aProperties, PROPERTYCOUNT);
     241             :     // ... and return it.
     242         429 :     return seqPropertyNames;
     243             : }
     244             : 
     245             : //  initialize static member
     246             : //  DON'T DO IT IN YOUR HEADER!
     247             : //  see definition for further information
     248             : 
     249             : SvtLocalisationOptions_Impl*    SvtLocalisationOptions::m_pDataContainer    = NULL;
     250             : sal_Int32                       SvtLocalisationOptions::m_nRefCount         = 0;
     251             : 
     252             : //  constructor
     253             : 
     254         286 : SvtLocalisationOptions::SvtLocalisationOptions()
     255             : {
     256             :     // Global access, must be guarded (multithreading!).
     257         286 :     MutexGuard aGuard( GetOwnStaticMutex() );
     258             :     // Increase our refcount ...
     259         286 :     ++m_nRefCount;
     260             :     // ... and initialize our data container only if it not already exist!
     261         286 :     if( m_pDataContainer == NULL )
     262             :     {
     263         143 :         m_pDataContainer = new SvtLocalisationOptions_Impl;
     264             : 
     265         143 :         ItemHolder1::holdConfigItem(E_LOCALISATIONOPTIONS);
     266         286 :     }
     267         286 : }
     268             : 
     269             : //  destructor
     270             : 
     271         712 : SvtLocalisationOptions::~SvtLocalisationOptions()
     272             : {
     273             :     // Global access, must be guarded (multithreading!)
     274         285 :     MutexGuard aGuard( GetOwnStaticMutex() );
     275             :     // Decrease our refcount.
     276         285 :     --m_nRefCount;
     277             :     // If last instance was deleted ...
     278             :     // we must destroy our static data container!
     279         285 :     if( m_nRefCount <= 0 )
     280             :     {
     281         142 :         delete m_pDataContainer;
     282         142 :         m_pDataContainer = NULL;
     283         285 :     }
     284         427 : }
     285             : 
     286             : //  public method
     287             : 
     288         143 : bool SvtLocalisationOptions::IsAutoMnemonic() const
     289             : {
     290         143 :     MutexGuard aGuard( GetOwnStaticMutex() );
     291         143 :     return m_pDataContainer->IsAutoMnemonic();
     292             : }
     293             : 
     294             : //  public method
     295             : 
     296         143 : sal_Int32 SvtLocalisationOptions::GetDialogScale() const
     297             : {
     298         143 :     MutexGuard aGuard( GetOwnStaticMutex() );
     299         143 :     return m_pDataContainer->GetDialogScale();
     300             : }
     301             : 
     302             : namespace
     303             : {
     304             :     class theLocalisationOptionsMutex : public rtl::Static<osl::Mutex, theLocalisationOptionsMutex>{};
     305             : }
     306             : 
     307             : //  private method
     308             : 
     309         857 : Mutex& SvtLocalisationOptions::GetOwnStaticMutex()
     310             : {
     311         857 :     return theLocalisationOptionsMutex::get();
     312             : }
     313             : 
     314             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10