LCOV - code coverage report
Current view: top level - unotools/source/config - internaloptions.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 63 70 90.0 %
Date: 2012-08-25 Functions: 15 18 83.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 56 116 48.3 %

           Branch data     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 <deque>
      21                 :            : 
      22                 :            : #include <unotools/internaloptions.hxx>
      23                 :            : #include <unotools/configmgr.hxx>
      24                 :            : #include <unotools/configitem.hxx>
      25                 :            : #include <tools/debug.hxx>
      26                 :            : #include <com/sun/star/uno/Any.hxx>
      27                 :            : #include <com/sun/star/uno/Sequence.hxx>
      28                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      29                 :            : 
      30                 :            : #include <rtl/logfile.hxx>
      31                 :            : #include "itemholder1.hxx"
      32                 :            : 
      33                 :            : //_________________________________________________________________________________________________________________
      34                 :            : //  namespaces
      35                 :            : //_________________________________________________________________________________________________________________
      36                 :            : 
      37                 :            : using namespace ::utl                   ;
      38                 :            : using namespace ::rtl                   ;
      39                 :            : using namespace ::osl                   ;
      40                 :            : using namespace ::std                   ;
      41                 :            : using namespace ::com::sun::star::uno   ;
      42                 :            : using namespace ::com::sun::star::beans ;
      43                 :            : 
      44                 :            : #define ROOTNODE_INTERNAL                   OUString(RTL_CONSTASCII_USTRINGPARAM("Office.Common/Internal"   ))
      45                 :            : #define DEFAULT_SLOTCFG                     sal_False
      46                 :            : #define DEFAULT_SENDCRASHMAIL               sal_False
      47                 :            : #define DEFAULT_USEMAILUI                   sal_True
      48                 :            : #define DEFAULT_CURRENTTEMPURL              OUString(RTL_CONSTASCII_USTRINGPARAM(""))
      49                 :            : 
      50                 :            : #define FIXPROPERTYNAME_SLOTCFG             OUString(RTL_CONSTASCII_USTRINGPARAM("Slot"                     ))
      51                 :            : #define FIXPROPERTYNAME_SENDCRASHMAIL       OUString(RTL_CONSTASCII_USTRINGPARAM("SendCrashMail"            ))
      52                 :            : #define FIXPROPERTYNAME_USEMAILUI           OUString(RTL_CONSTASCII_USTRINGPARAM("UseMailUI"                ))
      53                 :            : #define FIXPROPERTYNAME_CURRENTTEMPURL      OUString(RTL_CONSTASCII_USTRINGPARAM("CurrentTempURL"           ))
      54                 :            : 
      55                 :            : #define FIXPROPERTYHANDLE_SLOTCFG           0
      56                 :            : #define FIXPROPERTYHANDLE_SENDCRASHMAIL     1
      57                 :            : #define FIXPROPERTYHANDLE_USEMAILUI         2
      58                 :            : #define FIXPROPERTYHANDLE_CURRENTTEMPURL    3
      59                 :            : 
      60                 :            : class SvtInternalOptions_Impl : public ConfigItem
      61                 :            : {
      62                 :            :     //-------------------------------------------------------------------------------------------------------------
      63                 :            :     //  private member
      64                 :            :     //-------------------------------------------------------------------------------------------------------------
      65                 :            : 
      66                 :            :     private:
      67                 :            : 
      68                 :            :         sal_Bool                m_bRemoveMenuEntryClose;
      69                 :            :         sal_Bool                m_bRemoveMenuEntryBackToWebtop;
      70                 :            :         sal_Bool                m_bRemoveMenuEntryNewWebtop;
      71                 :            :         sal_Bool                m_bRemoveMenuEntryLogout;
      72                 :            :         sal_Bool                m_bSlotCFG          ;   /// cache "Slot" of Internal section
      73                 :            :         sal_Bool                m_bSendCrashMail    ;   /// cache "SendCrashMail" of Internal section
      74                 :            :         sal_Bool                m_bUseMailUI;
      75                 :            :         OUString                m_aCurrentTempURL   ;
      76                 :            :     //-------------------------------------------------------------------------------------------------------------
      77                 :            :     //  public methods
      78                 :            :     //-------------------------------------------------------------------------------------------------------------
      79                 :            : 
      80                 :            :     public:
      81                 :            : 
      82                 :            :         //---------------------------------------------------------------------------------------------------------
      83                 :            :         //  constructor / destructor
      84                 :            :         //---------------------------------------------------------------------------------------------------------
      85                 :            : 
      86                 :            :          SvtInternalOptions_Impl();
      87                 :            :         ~SvtInternalOptions_Impl();
      88                 :            : 
      89                 :            :         //---------------------------------------------------------------------------------------------------------
      90                 :            :         //  overloaded methods of baseclass
      91                 :            :         //---------------------------------------------------------------------------------------------------------
      92                 :            : 
      93                 :            :         /*-****************************************************************************************************//**
      94                 :            :             @short      called for notify of configmanager
      95                 :            :             @descr      These method is called from the ConfigManager before application ends or from the
      96                 :            :                          PropertyChangeListener if the sub tree broadcasts changes. You must update your
      97                 :            :                         internal values.
      98                 :            : 
      99                 :            :             @seealso    baseclass ConfigItem
     100                 :            : 
     101                 :            :             @param      "seqPropertyNames" is the list of properties which should be updated.
     102                 :            :             @return     -
     103                 :            : 
     104                 :            :             @onerror    -
     105                 :            :         *//*-*****************************************************************************************************/
     106                 :            : 
     107                 :          0 :         virtual void Notify( const Sequence< OUString >& )
     108                 :            :         {
     109                 :            :             DBG_ASSERT( sal_False, "SvtInternalOptions::Notify()\nNot used yet ... but called!?\n" );
     110                 :          0 :         }
     111                 :            : 
     112                 :            :         /*-****************************************************************************************************//**
     113                 :            :             @short      write changes to configuration
     114                 :            :             @descr      These method writes the changed values into the sub tree
     115                 :            :                         and should always called in our destructor to guarantee consistency of config data.
     116                 :            : 
     117                 :            :             @seealso    baseclass ConfigItem
     118                 :            : 
     119                 :            :             @param      -
     120                 :            :             @return     -
     121                 :            : 
     122                 :            :             @onerror    -
     123                 :            :         *//*-*****************************************************************************************************/
     124                 :            : 
     125                 :            :         virtual void Commit();
     126                 :            : 
     127                 :            :         //---------------------------------------------------------------------------------------------------------
     128                 :            :         //  public interface
     129                 :            :         //---------------------------------------------------------------------------------------------------------
     130                 :            : 
     131                 :            :         /*-****************************************************************************************************//**
     132                 :            :             @short      access method to get internal values
     133                 :            :             @descr      These method give us a chance to regulate acces to ouer internal values.
     134                 :            :                         It's not used in the moment - but it's possible for the feature!
     135                 :            : 
     136                 :            :             @seealso    -
     137                 :            : 
     138                 :            :             @param      -
     139                 :            :             @return     -
     140                 :            : 
     141                 :            :             @onerror    -
     142                 :            :         *//*-*****************************************************************************************************/
     143                 :            : 
     144                 :            :         sal_Bool    IsRemoveMenuEntryClose() const { return m_bRemoveMenuEntryClose; }
     145                 :            :         sal_Bool    IsRemoveMenuEntryBackToWebtop() const { return m_bRemoveMenuEntryBackToWebtop; }
     146                 :            :         sal_Bool    IsRemoveMenuEntryNewWebtop() const { return m_bRemoveMenuEntryNewWebtop; }
     147                 :            :         sal_Bool    IsRemoveMenuEntryLogout() const { return m_bRemoveMenuEntryLogout; }
     148                 :        233 :         sal_Bool    SlotCFGEnabled      () const { return m_bSlotCFG; }
     149                 :            :         sal_Bool    CrashMailEnabled    () const { return m_bSendCrashMail; }
     150                 :          0 :         sal_Bool    MailUIEnabled       () const { return m_bUseMailUI; }
     151                 :            : 
     152                 :        158 :         OUString    GetCurrentTempURL() const { return m_aCurrentTempURL; }
     153                 :            :         void        SetCurrentTempURL( const OUString& aNewCurrentTempURL );
     154                 :            :     //-------------------------------------------------------------------------------------------------------------
     155                 :            :     //  private methods
     156                 :            :     //-------------------------------------------------------------------------------------------------------------
     157                 :            : 
     158                 :            :     private:
     159                 :            : 
     160                 :            :         /*-****************************************************************************************************//**
     161                 :            :             @short      return list of fix key names of ouer configuration management which represent oue module tree
     162                 :            :             @descr      These methods return a static const list of key names. We need it to get needed values from our
     163                 :            :                         configuration management. We return well known key names only - because the "UserData" node
     164                 :            :                         is handled in a special way!
     165                 :            : 
     166                 :            :             @seealso    -
     167                 :            : 
     168                 :            :             @param      -
     169                 :            :             @return     A list of needed configuration keys is returned.
     170                 :            : 
     171                 :            :             @onerror    -
     172                 :            :         *//*-*****************************************************************************************************/
     173                 :            : 
     174                 :            :         Sequence< OUString > impl_GetPropertyNames();
     175                 :            : };
     176                 :            : 
     177                 :            : //*****************************************************************************************************************
     178                 :            : //  constructor
     179                 :            : //*****************************************************************************************************************
     180                 :        233 : SvtInternalOptions_Impl::SvtInternalOptions_Impl()
     181                 :            :     // Init baseclasses first
     182                 :            :     :   ConfigItem          ( ROOTNODE_INTERNAL, CONFIG_MODE_IMMEDIATE_UPDATE )
     183                 :            :     // Init member then.
     184                 :            :     , m_bRemoveMenuEntryClose(sal_False)
     185                 :            :     , m_bRemoveMenuEntryBackToWebtop(sal_False)
     186                 :            :     , m_bRemoveMenuEntryNewWebtop(sal_False)
     187                 :            :     , m_bRemoveMenuEntryLogout(sal_False)
     188                 :            :     , m_bSlotCFG(DEFAULT_SLOTCFG)
     189                 :            :     , m_bSendCrashMail(DEFAULT_SENDCRASHMAIL)
     190                 :            :     , m_bUseMailUI(DEFAULT_USEMAILUI)
     191 [ +  - ][ +  - ]:        233 :     , m_aCurrentTempURL(DEFAULT_CURRENTTEMPURL)
     192                 :            : {
     193                 :            :     // Use our list of configuration keys to get his values.
     194                 :            :     // structure of internal section: (first 2 entries are fixed - all other are member of a set!)
     195                 :            :     //      "Slot"
     196                 :            :     //      "SendCrashMail"
     197                 :            :     //      "RecoveryList/r1/URL"
     198                 :            :     //      "RecoveryList/r1/Filter"
     199                 :            :     //      "RecoveryList/r1/TempName"
     200                 :            :     //      "RecoveryList/r2/URL"
     201                 :            :     //      "RecoveryList/r2/Filter"
     202                 :            :     //      "RecoveryList/r2/TempName"
     203                 :            :     //      "RecoveryList/.."
     204         [ +  - ]:        233 :     Sequence< OUString >    seqNames    = impl_GetPropertyNames()   ;
     205         [ +  - ]:        233 :     Sequence< Any >         seqValues   = GetProperties( seqNames ) ;
     206                 :            : 
     207                 :            :     // Safe impossible cases.
     208                 :            :     // We need values from ALL configuration keys.
     209                 :            :     // Follow assignment use order of values in relation to our list of key names!
     210                 :            :     DBG_ASSERT( !(seqNames.getLength()!=seqValues.getLength()), "SvtInternalOptions_Impl::SvtInternalOptions_Impl()\nI miss some values of configuration keys!\n" );
     211                 :            : 
     212                 :            :     // Read fixed values first!
     213                 :            :     DBG_ASSERT(!seqValues[FIXPROPERTYHANDLE_SLOTCFG].hasValue() || (seqValues[FIXPROPERTYHANDLE_SLOTCFG].getValueTypeClass() == TypeClass_BOOLEAN), "SvtInternalOptions_Impl::SvtInternalOptions_Impl()\nWho has changed the value type of \"Office.Common\\Internal\\Slot\"?");
     214                 :            :     DBG_ASSERT(!seqValues[FIXPROPERTYHANDLE_SENDCRASHMAIL].hasValue() || !(seqValues[FIXPROPERTYHANDLE_SENDCRASHMAIL].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtInternalOptions_Impl::SvtInternalOptions_Impl()\nWho has changed the value type of \"Office.Common\\Internal\\SendCrashMail\"?");
     215         [ +  - ]:        233 :     seqValues[FIXPROPERTYHANDLE_SLOTCFG] >>= m_bSlotCFG;
     216         [ +  - ]:        233 :     seqValues[FIXPROPERTYHANDLE_SENDCRASHMAIL] >>= m_bSendCrashMail;
     217         [ +  - ]:        233 :     seqValues[FIXPROPERTYHANDLE_USEMAILUI] >>= m_bUseMailUI;
     218 [ +  - ][ +  - ]:        233 :     seqValues[FIXPROPERTYHANDLE_CURRENTTEMPURL] >>= m_aCurrentTempURL;
                 [ +  - ]
     219                 :        233 : }
     220                 :            : 
     221                 :            : //*****************************************************************************************************************
     222                 :            : //  destructor
     223                 :            : //*****************************************************************************************************************
     224                 :        233 : SvtInternalOptions_Impl::~SvtInternalOptions_Impl()
     225                 :            : {
     226 [ +  - ][ -  + ]:        233 :     if( IsModified() == sal_True )
     227                 :            :     {
     228         [ #  # ]:          0 :         Commit();
     229                 :            :     }
     230         [ -  + ]:        466 : }
     231                 :            : 
     232                 :            : //*****************************************************************************************************************
     233                 :            : //  public method
     234                 :            : //*****************************************************************************************************************
     235                 :        632 : void SvtInternalOptions_Impl::Commit()
     236                 :            : {
     237                 :            :     // We have to write our current temp URL
     238         [ +  - ]:        632 :     Sequence< OUString > aNames( 1 );
     239         [ +  - ]:        632 :     OUString* pNames = aNames.getArray();
     240         [ +  - ]:        632 :     Sequence< Any > aValues( 1 );
     241         [ +  - ]:        632 :     Any* pValues = aValues.getArray();
     242                 :            : 
     243         [ +  - ]:        632 :     pNames[0] = FIXPROPERTYNAME_CURRENTTEMPURL;
     244         [ +  - ]:        632 :     pValues[0] <<= m_aCurrentTempURL;
     245                 :            : 
     246 [ +  - ][ +  - ]:        632 :     PutProperties( aNames, aValues );
                 [ +  - ]
     247                 :        632 : }
     248                 :            : 
     249                 :            : //*****************************************************************************************************************
     250                 :            : //  public method
     251                 :            : //*****************************************************************************************************************
     252                 :        316 : void SvtInternalOptions_Impl::SetCurrentTempURL( const OUString& aNewCurrentTempURL )
     253                 :            : {
     254                 :        316 :     m_aCurrentTempURL = aNewCurrentTempURL;
     255                 :        316 :     SetModified();
     256                 :        316 :     Commit();
     257                 :        316 : }
     258                 :            : 
     259                 :            : //*****************************************************************************************************************
     260                 :            : //  private method
     261                 :            : //*****************************************************************************************************************
     262                 :        233 : Sequence< OUString > SvtInternalOptions_Impl::impl_GetPropertyNames()
     263                 :            : {
     264                 :        233 :     Sequence< OUString > seqProperties(4);
     265                 :            : 
     266                 :            :     // Add names of fix properties to list.
     267 [ +  - ][ +  - ]:        233 :     seqProperties[FIXPROPERTYHANDLE_SLOTCFG         ]   =   FIXPROPERTYNAME_SLOTCFG         ;
     268 [ +  - ][ +  - ]:        233 :     seqProperties[FIXPROPERTYHANDLE_SENDCRASHMAIL   ]   =   FIXPROPERTYNAME_SENDCRASHMAIL   ;
     269 [ +  - ][ +  - ]:        233 :     seqProperties[FIXPROPERTYHANDLE_USEMAILUI       ]   =   FIXPROPERTYNAME_USEMAILUI       ;
     270 [ +  - ][ +  - ]:        233 :     seqProperties[FIXPROPERTYHANDLE_CURRENTTEMPURL  ]   =   FIXPROPERTYNAME_CURRENTTEMPURL  ;
     271                 :            :     // Return result.
     272                 :        233 :     return seqProperties;
     273                 :            : }
     274                 :            : 
     275                 :            : //*****************************************************************************************************************
     276                 :            : //  initialize static member
     277                 :            : //  DON'T DO IT IN YOUR HEADER!
     278                 :            : //  see definition for further informations
     279                 :            : //*****************************************************************************************************************
     280                 :            : SvtInternalOptions_Impl*    SvtInternalOptions::m_pDataContainer    = NULL  ;
     281                 :            : sal_Int32                   SvtInternalOptions::m_nRefCount         = 0     ;
     282                 :            : 
     283                 :            : //*****************************************************************************************************************
     284                 :            : //  constructor
     285                 :            : //*****************************************************************************************************************
     286                 :        878 : SvtInternalOptions::SvtInternalOptions()
     287                 :            : {
     288                 :            :     // Global access, must be guarded (multithreading!).
     289 [ +  - ][ +  - ]:        878 :     MutexGuard aGuard( GetOwnStaticMutex() );
     290                 :            :     // Increase ouer refcount ...
     291                 :        878 :     ++m_nRefCount;
     292                 :            :     // ... and initialize ouer data container only if it not already!
     293         [ +  + ]:        878 :     if( m_pDataContainer == NULL )
     294                 :            :     {
     295                 :            :         RTL_LOGFILE_CONTEXT(aLog, "unotools ( ??? ) ::SvtInternalOptions_Impl::ctor()");
     296 [ +  - ][ +  - ]:        233 :         m_pDataContainer = new SvtInternalOptions_Impl();
     297                 :            : 
     298         [ +  - ]:        233 :         ItemHolder1::holdConfigItem(E_INTERNALOPTIONS);
     299         [ +  - ]:        878 :      }
     300                 :        878 : }
     301                 :            : 
     302                 :            : //*****************************************************************************************************************
     303                 :            : //  destructor
     304                 :            : //*****************************************************************************************************************
     305                 :        878 : SvtInternalOptions::~SvtInternalOptions()
     306                 :            : {
     307                 :            :     // Global access, must be guarded (multithreading!)
     308 [ +  - ][ +  - ]:        878 :     MutexGuard aGuard( GetOwnStaticMutex() );
     309                 :            :     // Decrease ouer refcount.
     310                 :        878 :     --m_nRefCount;
     311                 :            :     // If last instance was deleted ...
     312                 :            :     // we must destroy ouer static data container!
     313         [ +  + ]:        878 :     if( m_nRefCount <= 0 )
     314                 :            :     {
     315 [ +  - ][ +  - ]:        233 :         delete m_pDataContainer;
     316                 :        233 :         m_pDataContainer = NULL;
     317         [ +  - ]:        878 :     }
     318         [ -  + ]:       1111 : }
     319                 :            : 
     320                 :            : //*****************************************************************************************************************
     321                 :            : //  public method
     322                 :            : //*****************************************************************************************************************
     323                 :        233 : sal_Bool SvtInternalOptions::SlotCFGEnabled() const
     324                 :            : {
     325 [ +  - ][ +  - ]:        233 :     MutexGuard aGuard( GetOwnStaticMutex() );
     326         [ +  - ]:        233 :     return m_pDataContainer->SlotCFGEnabled();
     327                 :            : }
     328                 :            : 
     329                 :            : //*****************************************************************************************************************
     330                 :            : //  public method
     331                 :            : //*****************************************************************************************************************
     332                 :          0 : sal_Bool SvtInternalOptions::MailUIEnabled() const
     333                 :            : {
     334 [ #  # ][ #  # ]:          0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     335         [ #  # ]:          0 :     return m_pDataContainer->MailUIEnabled();
     336                 :            : }
     337                 :            : 
     338                 :        158 : OUString SvtInternalOptions::GetCurrentTempURL() const
     339                 :            : {
     340 [ +  - ][ +  - ]:        158 :     MutexGuard aGuard( GetOwnStaticMutex() );
     341         [ +  - ]:        158 :     return m_pDataContainer->GetCurrentTempURL();
     342                 :            : }
     343                 :            : 
     344                 :        316 : void SvtInternalOptions::SetCurrentTempURL( const OUString& aNewCurrentTempURL )
     345                 :            : {
     346 [ +  - ][ +  - ]:        316 :     MutexGuard aGuard( GetOwnStaticMutex() );
     347 [ +  - ][ +  - ]:        316 :     m_pDataContainer->SetCurrentTempURL( aNewCurrentTempURL );
     348                 :        316 : }
     349                 :            : 
     350                 :            : namespace
     351                 :            : {
     352                 :            :     class theInternalOptionsMutex : public rtl::Static<osl::Mutex, theInternalOptionsMutex>{};
     353                 :            : }
     354                 :            : 
     355                 :            : //*****************************************************************************************************************
     356                 :            : //  private method
     357                 :            : //*****************************************************************************************************************
     358                 :       2463 : Mutex& SvtInternalOptions::GetOwnStaticMutex()
     359                 :            : {
     360                 :       2463 :     return theInternalOptionsMutex::get();
     361                 :            : }
     362                 :            : 
     363                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10