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

Generated by: LCOV version 1.10