LCOV - code coverage report
Current view: top level - libreoffice/svtools/source/config - helpopt.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 127 290 43.8 %
Date: 2012-12-27 Functions: 20 43 46.5 %
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 <svtools/helpopt.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             : #include <vcl/help.hxx>
      28             : #include <osl/mutex.hxx>
      29             : #include <comphelper/stl_types.hxx>
      30             : 
      31             : #include <rtl/logfile.hxx>
      32             : #include "itemholder2.hxx"
      33             : 
      34             : using namespace utl;
      35             : using namespace com::sun::star::uno;
      36             : using namespace com::sun::star;
      37             : 
      38             : using ::rtl::OUString;
      39             : 
      40             : static SvtHelpOptions_Impl* pOptions = NULL;
      41             : static sal_Int32           nRefCount = 0;
      42             : 
      43             : #define EXTENDEDHELP        0
      44             : #define HELPTIPS            1
      45             : #define AGENT_ENABLED       2
      46             : #define AGENT_TIMEOUT       3
      47             : #define AGENT_RETRYLIMIT    4
      48             : #define LOCALE              5
      49             : #define SYSTEM              6
      50             : #define STYLESHEET          7
      51             : 
      52          38 : class SvtHelpOptions_Impl : public utl::ConfigItem
      53             : {
      54             :     sal_Int32       nHelpAgentTimeoutPeriod;
      55             :     sal_Int32       nHelpAgentRetryLimit;
      56             :     sal_Bool        bExtendedHelp;
      57             :     sal_Bool        bHelpTips;
      58             :     sal_Bool        bHelpAgentEnabled;
      59             :     sal_Bool        bWelcomeScreen;
      60             :     String          aLocale;
      61             :     String          aSystem;
      62             :     String          sHelpStyleSheet;
      63             : 
      64             :     DECLARE_STL_USTRINGACCESS_MAP( sal_Int32, MapString2Int );
      65             :     MapString2Int   aURLIgnoreCounters;
      66             :     ::osl::Mutex    aIgnoreCounterSafety;
      67             : 
      68             :     Sequence< OUString > GetPropertyNames();
      69             : 
      70             : public:
      71             :                     SvtHelpOptions_Impl();
      72             : 
      73             :     virtual void    Notify( const com::sun::star::uno::Sequence< rtl::OUString >& aPropertyNames );
      74             :     void            Load( const ::com::sun::star::uno::Sequence< ::rtl::OUString>& aPropertyNames);
      75             :     virtual void    Commit();
      76             : 
      77           0 :     void            SetExtendedHelp( sal_Bool b )           { bExtendedHelp= b; SetModified(); }
      78          38 :     sal_Bool        IsExtendedHelp() const                  { return bExtendedHelp; }
      79           0 :     void            SetHelpTips( sal_Bool b )               { bHelpTips = b; SetModified(); }
      80          76 :     sal_Bool        IsHelpTips() const                      { return bHelpTips; }
      81             : 
      82           0 :     void            SetHelpAgentEnabled( sal_Bool b )       { bHelpAgentEnabled = b; SetModified(); }
      83         143 :     sal_Bool        IsHelpAgentEnabled() const              { return bHelpAgentEnabled; }
      84           0 :     void            SetHelpAgentTimeoutPeriod( sal_Int32 _nSeconds )    { nHelpAgentTimeoutPeriod = _nSeconds; SetModified(); }
      85           0 :     sal_Int32       GetHelpAgentTimeoutPeriod( ) const      { return nHelpAgentTimeoutPeriod; }
      86             :     void            SetHelpAgentRetryLimit( sal_Int32 _nTrials )        { nHelpAgentRetryLimit = _nTrials; SetModified(); }
      87             :     sal_Int32       GetHelpAgentRetryLimit( ) const         { return nHelpAgentRetryLimit; }
      88             : 
      89             :     void            resetAgentIgnoreURLCounter();
      90             : 
      91           0 :     void            SetWelcomeScreen( sal_Bool b )          { bWelcomeScreen = b; SetModified(); }
      92           0 :     sal_Bool        IsWelcomeScreen() const                 { return bWelcomeScreen; }
      93             :     String          GetLocale() const                       { return aLocale; }
      94          19 :     String          GetSystem() const                       { return aSystem; }
      95             : 
      96           0 :     const String&   GetHelpStyleSheet()const{return sHelpStyleSheet;}
      97           0 :     void            SetHelpStyleSheet(const String& rStyleSheet){sHelpStyleSheet = rStyleSheet; SetModified();}
      98             : 
      99             :     static ::osl::Mutex & getInitMutex();
     100             : 
     101             : protected:
     102             :     void    implLoadURLCounters();
     103             :     void    implSaveURLCounters();
     104             :     // to be called with aIgnoreCounterSafety locked
     105             :     void    implGetURLCounters( Sequence< ::rtl::OUString >& _rNodeNames, Sequence< Any >& _rURLs, Sequence< Any >& _rCounter );
     106             : };
     107             : 
     108          38 : Sequence< OUString > SvtHelpOptions_Impl::GetPropertyNames()
     109             : {
     110             :     static const char* aPropNames[] =
     111             :     {
     112             :         "ExtendedTip",
     113             :         "Tip",
     114             :         "HelpAgent/Enabled",
     115             :         "HelpAgent/Timeout",
     116             :         "HelpAgent/RetryLimit",
     117             :         "Locale",
     118             :         "System",
     119             :         "HelpStyleSheet",
     120             : //      "HowTo/Show"
     121             :     };
     122             : 
     123          38 :     const int nCount = sizeof( aPropNames ) / sizeof( const char* );
     124          38 :     Sequence< OUString > aNames( nCount );
     125          38 :     OUString* pNames = aNames.getArray();
     126         342 :     for ( int i = 0; i < nCount; i++ )
     127         304 :         pNames[i] = OUString::createFromAscii( aPropNames[i] );
     128             : 
     129          38 :     return aNames;
     130             : }
     131             : 
     132         476 : ::osl::Mutex & SvtHelpOptions_Impl::getInitMutex()
     133             : {
     134             :     static ::osl::Mutex *pMutex = 0;
     135             : 
     136         476 :     if( ! pMutex )
     137             :     {
     138          19 :         ::osl::MutexGuard guard( ::osl::Mutex::getGlobalMutex() );
     139          19 :         if( ! pMutex )
     140             :         {
     141          19 :             static ::osl::Mutex mutex;
     142          19 :             pMutex = &mutex;
     143          19 :         }
     144             :     }
     145         476 :     return *pMutex;
     146             : }
     147             : 
     148             : 
     149             : // -----------------------------------------------------------------------
     150             : 
     151          19 : SvtHelpOptions_Impl::SvtHelpOptions_Impl()
     152             :     : ConfigItem( OUString( RTL_CONSTASCII_USTRINGPARAM( "Office.Common/Help" )) )
     153             :     , bExtendedHelp( sal_False )
     154             :     , bHelpTips( sal_True )
     155             :     , bHelpAgentEnabled( sal_False )
     156          19 :     , bWelcomeScreen( sal_False )
     157             : {
     158          19 :     Sequence< OUString > aNames = GetPropertyNames();
     159          19 :     Load( aNames );
     160          19 :     EnableNotification( aNames );
     161          19 :     implLoadURLCounters();
     162          19 : }
     163             : 
     164             : // -----------------------------------------------------------------------
     165          57 : static int lcl_MapPropertyName( const ::rtl::OUString rCompare,
     166             :                 const uno::Sequence< ::rtl::OUString>& aInternalPropertyNames)
     167             : {
     168         114 :     for(int nProp = 0; nProp < aInternalPropertyNames.getLength(); ++nProp)
     169             :     {
     170         114 :         if( aInternalPropertyNames[nProp] == rCompare )
     171          57 :             return nProp;
     172             :     }
     173           0 :     return -1;
     174             : }
     175             : 
     176          19 : void  SvtHelpOptions_Impl::Load(const uno::Sequence< ::rtl::OUString>& rPropertyNames)
     177             : {
     178          19 :     const uno::Sequence< ::rtl::OUString> aInternalPropertyNames( GetPropertyNames());
     179          19 :     Sequence< Any > aValues = GetProperties( rPropertyNames );
     180          19 :     const Any* pValues = aValues.getConstArray();
     181             :     DBG_ASSERT( aValues.getLength() == rPropertyNames.getLength(), "GetProperties failed" );
     182          19 :     if ( aValues.getLength() == rPropertyNames.getLength() )
     183             :     {
     184         171 :         for ( int nProp = 0; nProp < rPropertyNames.getLength(); nProp++ )
     185             :         {
     186             : #if OSL_DEBUG_LEVEL > 1
     187             :             DBG_ASSERT( pValues[nProp].hasValue(), "property value missing" );
     188             : #endif
     189         152 :             if ( pValues[nProp].hasValue() )
     190             :             {
     191         152 :                 sal_Bool bTmp = sal_Bool();
     192         152 :                 ::rtl::OUString aTmpStr;
     193         152 :                 sal_Int32 nTmpInt = 0;
     194         152 :                 if ( pValues[nProp] >>= bTmp )
     195             :                 {
     196          57 :                     switch ( lcl_MapPropertyName(rPropertyNames[nProp], aInternalPropertyNames) )
     197             :                     {
     198             :                         case EXTENDEDHELP :
     199          19 :                             bExtendedHelp = bTmp;
     200          19 :                             break;
     201             :                         case HELPTIPS :
     202          19 :                             bHelpTips = bTmp;
     203          19 :                             break;
     204             :                         case AGENT_ENABLED :
     205          19 :                             bHelpAgentEnabled = bTmp;
     206          19 :                             break;
     207             :                         default:
     208             :                             SAL_WARN( "svtools.config", "Wrong Member!" );
     209           0 :                             break;
     210             :                     }
     211             :                 }
     212          95 :                 else if ( pValues[nProp] >>= aTmpStr )
     213             :                 {
     214          57 :                     switch ( nProp )
     215             :                     {
     216             :                         case LOCALE:
     217          19 :                             aLocale = aTmpStr;
     218          19 :                             break;
     219             : 
     220             :                         case SYSTEM:
     221          19 :                             aSystem = aTmpStr;
     222          19 :                             break;
     223             :                         case STYLESHEET :
     224          19 :                             sHelpStyleSheet = aTmpStr;
     225          19 :                         break;
     226             :                         default:
     227             :                             SAL_WARN( "svtools.config", "Wrong Member!" );
     228           0 :                             break;
     229             :                     }
     230             :                 }
     231          38 :                 else if ( pValues[nProp] >>= nTmpInt )
     232             :                 {
     233          38 :                     switch ( nProp )
     234             :                     {
     235             :                         case AGENT_TIMEOUT:
     236          19 :                             nHelpAgentTimeoutPeriod = nTmpInt;
     237          19 :                             break;
     238             : 
     239             :                         case AGENT_RETRYLIMIT:
     240          19 :                             nHelpAgentRetryLimit = nTmpInt;
     241          19 :                             break;
     242             : 
     243             :                         default:
     244             :                             SAL_WARN( "svtools.config", "Wrong Member!" );
     245           0 :                             break;
     246             :                     }
     247             :                 }
     248             :                 else
     249             :                 {
     250             :                     SAL_WARN( "svtools.config", "Wrong Type!" );
     251         152 :                 }
     252             :             }
     253             :         }
     254          19 :         if ( IsHelpTips() != Help::IsQuickHelpEnabled() )
     255          19 :             IsHelpTips() ? Help::EnableQuickHelp() : Help::DisableQuickHelp();
     256          19 :         if ( IsExtendedHelp() != Help::IsBalloonHelpEnabled() )
     257           0 :             IsExtendedHelp() ? Help::EnableBalloonHelp() : Help::DisableBalloonHelp();
     258          19 :     }
     259          19 : }
     260             : 
     261             : // -----------------------------------------------------------------------
     262             : 
     263          19 : void SvtHelpOptions_Impl::implGetURLCounters( Sequence< ::rtl::OUString >& _rNodeNames, Sequence< Any >& _rURLs, Sequence< Any >& _rCounters )
     264             : {
     265             :     // the ignore counters for the help agent URLs
     266          19 :     const ::rtl::OUString sIgnoreListNodePath( RTL_CONSTASCII_USTRINGPARAM( "HelpAgent/IgnoreList" ));
     267          19 :     const ::rtl::OUString sPathSeparator(      RTL_CONSTASCII_USTRINGPARAM( "/" ));
     268          19 :     const ::rtl::OUString sURLLocalPath(       RTL_CONSTASCII_USTRINGPARAM( "/Name" ));
     269          19 :     const ::rtl::OUString sCounterLocalPath(   RTL_CONSTASCII_USTRINGPARAM( "/Counter" ));
     270             : 
     271             :     // get the names of all the nodes containing ignore counters
     272             :     // collect the node names we have to ask
     273             :     // first get the node names of all children of HelpAgent/IgnoreList
     274          19 :     _rNodeNames = GetNodeNames(sIgnoreListNodePath);
     275          19 :     const ::rtl::OUString* pIgnoredURLsNodes = _rNodeNames.getConstArray();
     276          19 :     const ::rtl::OUString* pIgnoredURLsNodesEnd = pIgnoredURLsNodes + _rNodeNames.getLength();
     277             : 
     278             :     // then assemble the two lists (of node paths) for the URLs and the counters
     279          19 :     Sequence< ::rtl::OUString > aIgnoredURLs(_rNodeNames.getLength());
     280          19 :     Sequence< ::rtl::OUString > aIgnoredURLsCounter(_rNodeNames.getLength());
     281          19 :     ::rtl::OUString* pIgnoredURLs = aIgnoredURLs.getArray();
     282          19 :     ::rtl::OUString* pIgnoredURLsCounter = aIgnoredURLsCounter.getArray();
     283          19 :     for (;pIgnoredURLsNodes != pIgnoredURLsNodesEnd; ++pIgnoredURLsNodes, ++pIgnoredURLs, ++pIgnoredURLsCounter)
     284             :     {
     285           0 :         ::rtl::OUString sLocalURLAccess = sIgnoreListNodePath;
     286           0 :         sLocalURLAccess += sPathSeparator;
     287           0 :         sLocalURLAccess += *pIgnoredURLsNodes;
     288             : 
     289             :         // the path to the URL of this specific entry
     290           0 :         *pIgnoredURLs = sLocalURLAccess;
     291           0 :         *pIgnoredURLs += sURLLocalPath;
     292             : 
     293             :         // the path of the counter for that URL
     294           0 :         *pIgnoredURLsCounter = sLocalURLAccess;
     295           0 :         *pIgnoredURLsCounter += sCounterLocalPath;
     296           0 :     }
     297             : 
     298             :     // now collect the values
     299          19 :     _rURLs = GetProperties(aIgnoredURLs);
     300          19 :     _rCounters = GetProperties(aIgnoredURLsCounter);
     301             : 
     302          19 :     sal_Int32 nURLs = _rURLs.getLength();
     303          19 :     sal_Int32 nCounters = _rCounters.getLength();
     304             :     DBG_ASSERT(nURLs == nCounters, "SvtHelpOptions_Impl::implGetURLCounters: inconsistence while retrieving the visited URLs!");
     305             : 
     306             :     // normalize in case something went wrong
     307          19 :     sal_Int32 nKnownURLs = nURLs < nCounters ? nURLs : nCounters;
     308          19 :     if (nURLs < nCounters)
     309             :     {
     310           0 :         _rCounters.realloc(nKnownURLs);
     311           0 :         _rNodeNames.realloc(nKnownURLs);
     312             :     }
     313          19 :     else if (nURLs > nCounters)
     314             :     {
     315           0 :         _rURLs.realloc(nKnownURLs);
     316           0 :         _rNodeNames.realloc(nKnownURLs);
     317          19 :     }
     318          19 : }
     319             : 
     320             : // -----------------------------------------------------------------------
     321             : 
     322           0 : void SvtHelpOptions_Impl::implSaveURLCounters()
     323             : {
     324           0 :     ::osl::MutexGuard aGuard(aIgnoreCounterSafety);
     325             : 
     326           0 :     const ::rtl::OUString sIgnoreListNodePath( RTL_CONSTASCII_USTRINGPARAM( "HelpAgent/IgnoreList" ));
     327           0 :     const ::rtl::OUString sPathSeparator(      RTL_CONSTASCII_USTRINGPARAM( "/" ));
     328           0 :     const ::rtl::OUString sURLLocalPath(       RTL_CONSTASCII_USTRINGPARAM( "/Name" ));
     329           0 :     const ::rtl::OUString sCounterLocalPath(   RTL_CONSTASCII_USTRINGPARAM( "/Counter" ));
     330             : 
     331             :     // get the current URL/counter pairs (as they're persistent at the moment)
     332           0 :     Sequence< ::rtl::OUString > aNodeNames;
     333           0 :     Sequence< Any >             aURLs;
     334           0 :     Sequence< Any >             aCounters;
     335             : 
     336           0 :     implGetURLCounters(aNodeNames, aURLs, aCounters);
     337           0 :     sal_Int32 nKnownURLs = aURLs.getLength();
     338             : 
     339           0 :     const ::rtl::OUString* pNodeNames   = aNodeNames.getConstArray();
     340           0 :     const Any* pURLs                    = aURLs.getConstArray();
     341           0 :     const Any* pCounters                = aCounters.getConstArray();
     342             : 
     343             :     // check which of them must be deleted/modified
     344           0 :     Sequence< ::rtl::OUString >     aDeleteFromConfig(nKnownURLs);  // names of nodes to be deleted
     345           0 :     ::rtl::OUString*                pDeleteFromConfig = aDeleteFromConfig.getArray();
     346           0 :     ::std::set< ::rtl::OUString >   aAlreadyPresent;    // URLs currently persistent
     347             : 
     348             :     // for modifying already existent nodes
     349           0 :     Sequence< ::rtl::OUString > aNewCounterNodePaths(nKnownURLs);
     350           0 :     Sequence< Any >             aNewCounterValues(nKnownURLs);
     351           0 :     ::rtl::OUString*            pNewCounterNodePaths = aNewCounterNodePaths.getArray();
     352           0 :     Any*                        pNewCounterValues = aNewCounterValues.getArray();
     353             : 
     354             :     // temporaries needed inside the loop
     355           0 :     ::rtl::OUString sCurrentURL, sCurrentURLNodeName;
     356             : 
     357           0 :     for (sal_Int32 i=0; i<nKnownURLs; ++i, ++pNodeNames, ++pURLs, ++pCounters)
     358             :     {
     359           0 :         if (!((*pURLs) >>= sCurrentURL))
     360           0 :             continue;
     361             : 
     362           0 :         ConstMapString2IntIterator aThisURLNewCounter = aURLIgnoreCounters.find(sCurrentURL);
     363           0 :         if (aURLIgnoreCounters.end() == aThisURLNewCounter)
     364             :         {   // we do not know anything about this URL anymore.
     365             :             // -> have to removed it from the configuration later on
     366           0 :             *pDeleteFromConfig = *pNodeNames;
     367           0 :             ++pDeleteFromConfig;
     368             :         }
     369             :         else
     370             :         {   // we know this URL
     371           0 :             sCurrentURLNodeName = sIgnoreListNodePath;
     372           0 :             sCurrentURLNodeName += sPathSeparator;
     373           0 :             sCurrentURLNodeName += *pNodeNames;
     374             : 
     375             :             // -> remember this (so we don't need to add a new node for this URL later on)
     376           0 :             aAlreadyPresent.insert(sCurrentURL);
     377             : 
     378           0 :             sal_Int32 nThisURLPersistentCounter = 0;
     379           0 :             (*pCounters) >>= nThisURLPersistentCounter;
     380             : 
     381           0 :             if (aThisURLNewCounter->second != nThisURLPersistentCounter)
     382             :             {   // the counter changed
     383             :                 // -> remember the path and the new counter for the adjustment below
     384           0 :                 *pNewCounterNodePaths = sCurrentURLNodeName;
     385           0 :                 *pNewCounterNodePaths += sCounterLocalPath;
     386           0 :                 ++pNewCounterNodePaths;
     387             : 
     388           0 :                 (*pNewCounterValues) <<= aThisURLNewCounter->second;
     389           0 :                 ++pNewCounterValues;
     390             :             }
     391             :         }
     392             :     }
     393             : 
     394             :     // delete the nodes which are flagged so ...
     395           0 :     aDeleteFromConfig.realloc(pDeleteFromConfig - aDeleteFromConfig.getArray());
     396           0 :     if (0 != aDeleteFromConfig.getLength())
     397             :     {
     398           0 :         ClearNodeElements(sIgnoreListNodePath, aDeleteFromConfig);
     399             :     }
     400             : 
     401             :     // modify the nodes which need to be
     402           0 :     aNewCounterNodePaths.realloc(pNewCounterNodePaths - aNewCounterNodePaths.getArray());
     403           0 :     aNewCounterValues.realloc(pNewCounterValues - aNewCounterValues.getArray());
     404           0 :     if (0 != aNewCounterNodePaths.getLength())
     405             :     {
     406           0 :         PutProperties(aNewCounterNodePaths, aNewCounterValues);
     407             :     }
     408             : 
     409             :     // and for the new ones ...
     410           0 :     ::rtl::OUString sNewNodeName;
     411           0 :     Sequence< ::rtl::OUString > aNewCounterDataNodeNames(2);
     412           0 :     Sequence< Any >             aNewCounterDataValues(2);
     413           0 :     const ::rtl::OUString sNodeNameBase( RTL_CONSTASCII_USTRINGPARAM( "URL" ));
     414           0 :     for (   ConstMapString2IntIterator aCollectNew = aURLIgnoreCounters.begin();
     415           0 :             aCollectNew != aURLIgnoreCounters.end();
     416             :             ++aCollectNew
     417             :         )
     418             :     {
     419           0 :         if (aAlreadyPresent.end() == aAlreadyPresent.find(aCollectNew->first))
     420             :         {   // this URL is not persistent, yet
     421             :             // -> add a new node
     422           0 :             sNewNodeName = sNodeNameBase;
     423           0 :             if (!getUniqueSetElementName(sIgnoreListNodePath, sNewNodeName))
     424             :             {
     425             :                 SAL_WARN( "svtools.config", "SvtHelpOptions_Impl::implSaveURLCounters: could not get a free name!" );
     426           0 :                 continue;
     427             :             }
     428           0 :             AddNode(sIgnoreListNodePath, sNewNodeName);
     429             : 
     430             :             // and set the URL/counter pair
     431           0 :             aNewCounterDataNodeNames[0] = sIgnoreListNodePath;
     432           0 :             aNewCounterDataNodeNames[0] += sPathSeparator;
     433           0 :             aNewCounterDataNodeNames[0] += sNewNodeName;
     434           0 :             aNewCounterDataNodeNames[0] += sURLLocalPath;
     435           0 :             aNewCounterDataValues[0]    <<= aCollectNew->first;
     436             : 
     437           0 :             aNewCounterDataNodeNames[1] = sIgnoreListNodePath;
     438           0 :             aNewCounterDataNodeNames[1] += sPathSeparator;
     439           0 :             aNewCounterDataNodeNames[1] += sNewNodeName;
     440           0 :             aNewCounterDataNodeNames[1] += sCounterLocalPath;
     441           0 :             aNewCounterDataValues[1]    <<= aCollectNew->second;
     442             : 
     443           0 :             PutProperties(aNewCounterDataNodeNames, aNewCounterDataValues);
     444             :         }
     445           0 :     }
     446           0 : }
     447             : 
     448             : // -----------------------------------------------------------------------
     449             : 
     450          19 : void SvtHelpOptions_Impl::implLoadURLCounters()
     451             : {
     452          19 :     ::osl::MutexGuard aGuard(aIgnoreCounterSafety);
     453             : 
     454          19 :     Sequence< ::rtl::OUString > aNodeNames;
     455          19 :     Sequence< Any >             aURLs;
     456          19 :     Sequence< Any >             aCounters;
     457             : 
     458          19 :     implGetURLCounters(aNodeNames, aURLs, aCounters);
     459          19 :     sal_Int32 nKnownURLs = aURLs.getLength();
     460             : 
     461          19 :     const Any* pURLs = aURLs.getConstArray();
     462          19 :     const Any* pCounters = aCounters.getConstArray();
     463             : 
     464          19 :     ::rtl::OUString sCurrentURL;
     465             :     sal_Int32 nCurrentCounter;
     466          19 :     for (sal_Int32 i=0; i<nKnownURLs; ++i, ++pURLs, ++pCounters)
     467             :     {
     468           0 :         (*pURLs) >>= sCurrentURL;
     469           0 :         nCurrentCounter = 0;
     470           0 :         (*pCounters) >>= nCurrentCounter;
     471           0 :         aURLIgnoreCounters[sCurrentURL] = nCurrentCounter;
     472          19 :     }
     473          19 : }
     474             : 
     475             : // -----------------------------------------------------------------------
     476             : 
     477           0 : void SvtHelpOptions_Impl::Commit()
     478             : {
     479           0 :     Sequence< OUString > aNames = GetPropertyNames();
     480           0 :     Sequence< Any > aValues( aNames.getLength() );
     481           0 :     Any* pValues = aValues.getArray();
     482           0 :     for ( int nProp = 0; nProp < aNames.getLength(); nProp++ )
     483             :     {
     484           0 :         switch ( nProp )
     485             :         {
     486             :             case EXTENDEDHELP :
     487           0 :                 pValues[nProp] <<= bExtendedHelp;
     488           0 :                 break;
     489             : 
     490             :             case HELPTIPS :
     491           0 :                 pValues[nProp] <<= bHelpTips;
     492           0 :                 break;
     493             : 
     494             :             case AGENT_ENABLED :
     495           0 :                 pValues[nProp] <<= bHelpAgentEnabled;
     496           0 :                 break;
     497             : 
     498             :             case AGENT_TIMEOUT:
     499           0 :                 pValues[nProp] <<= nHelpAgentTimeoutPeriod;
     500           0 :                 break;
     501             : 
     502             :             case AGENT_RETRYLIMIT:
     503           0 :                 pValues[nProp] <<= nHelpAgentRetryLimit;
     504           0 :                 break;
     505             : 
     506             :             case LOCALE:
     507           0 :                 pValues[nProp] <<= ::rtl::OUString(aLocale);
     508           0 :                 break;
     509             : 
     510             :             case SYSTEM:
     511           0 :                 pValues[nProp] <<= ::rtl::OUString(aSystem);
     512           0 :                 break;
     513             :             case STYLESHEET :
     514           0 :                 pValues[nProp] <<= ::rtl::OUString(sHelpStyleSheet);
     515           0 :             break;
     516             : 
     517             :         }
     518             :     }
     519             : 
     520           0 :     PutProperties( aNames, aValues );
     521             : 
     522           0 :     implSaveURLCounters();
     523           0 : }
     524             : 
     525             : // -----------------------------------------------------------------------
     526             : 
     527           0 : void SvtHelpOptions_Impl::Notify( const Sequence<rtl::OUString>& aPropertyNames )
     528             : {
     529           0 :     Load( aPropertyNames );
     530           0 : }
     531             : 
     532         238 : SvtHelpOptions::SvtHelpOptions()
     533             : {
     534             :     // Global access, must be guarded (multithreading)
     535         238 :     ::osl::MutexGuard aGuard( SvtHelpOptions_Impl::getInitMutex() );
     536         238 :     ++nRefCount;
     537         238 :     if ( !pOptions )
     538             :     {
     539             :         RTL_LOGFILE_CONTEXT(aLog, "svtools ( ??? ) ::SvtHelpOptions_Impl::ctor()");
     540          19 :         pOptions = new SvtHelpOptions_Impl;
     541             : 
     542          19 :         svtools::ItemHolder2::holdConfigItem(E_HELPOPTIONS);
     543             :     }
     544         238 :     pImp = pOptions;
     545         238 : }
     546             : 
     547             : // -----------------------------------------------------------------------
     548             : 
     549           0 : void SvtHelpOptions_Impl::resetAgentIgnoreURLCounter()
     550             : {
     551           0 :     ::osl::MutexGuard aGuard(aIgnoreCounterSafety);
     552           0 :     aURLIgnoreCounters.clear();
     553           0 :     SetModified();
     554           0 : }
     555             : 
     556             : // -----------------------------------------------------------------------
     557             : 
     558         495 : SvtHelpOptions::~SvtHelpOptions()
     559             : {
     560             :     // Global access, must be guarded (multithreading)
     561         238 :     ::osl::MutexGuard aGuard( SvtHelpOptions_Impl::getInitMutex() );
     562         238 :     if ( !--nRefCount )
     563             :     {
     564          19 :         if ( pOptions->IsModified() )
     565           0 :             pOptions->Commit();
     566          19 :         DELETEZ( pOptions );
     567         238 :     }
     568         257 : }
     569             : 
     570           0 : void SvtHelpOptions::SetExtendedHelp( sal_Bool b )
     571             : {
     572           0 :     pImp->SetExtendedHelp( b );
     573           0 : }
     574             : 
     575          19 : sal_Bool SvtHelpOptions::IsExtendedHelp() const
     576             : {
     577          19 :     return pImp->IsExtendedHelp();
     578             : }
     579             : 
     580           0 : void SvtHelpOptions::SetHelpTips( sal_Bool b )
     581             : {
     582           0 :     pImp->SetHelpTips( b );
     583           0 : }
     584             : 
     585          38 : sal_Bool SvtHelpOptions::IsHelpTips() const
     586             : {
     587          38 :     return pImp->IsHelpTips();
     588             : }
     589             : 
     590             : // -----------------------------------------------------------------------
     591             : 
     592           0 : void SvtHelpOptions::SetHelpAgentTimeoutPeriod( sal_Int32 _nSeconds )
     593             : {
     594           0 :     pImp->SetHelpAgentTimeoutPeriod( _nSeconds );
     595           0 : }
     596             : 
     597             : // -----------------------------------------------------------------------
     598             : 
     599           0 : sal_Int32 SvtHelpOptions::GetHelpAgentTimeoutPeriod( ) const
     600             : {
     601           0 :     return pImp->GetHelpAgentTimeoutPeriod( );
     602             : }
     603             : 
     604             : // -----------------------------------------------------------------------
     605             : 
     606           0 : void SvtHelpOptions::SetHelpAgentAutoStartMode( sal_Bool b )
     607             : {
     608           0 :     pImp->SetHelpAgentEnabled( b );
     609           0 : }
     610             : 
     611             : // -----------------------------------------------------------------------
     612             : 
     613         143 : sal_Bool SvtHelpOptions::IsHelpAgentAutoStartMode() const
     614             : {
     615         143 :     return pImp->IsHelpAgentEnabled();
     616             : }
     617             : 
     618             : // -----------------------------------------------------------------------
     619             : 
     620           0 : void SvtHelpOptions::resetAgentIgnoreURLCounter()
     621             : {
     622           0 :     pImp->resetAgentIgnoreURLCounter();
     623           0 : }
     624             : 
     625             : // -----------------------------------------------------------------------
     626             : 
     627           0 : void SvtHelpOptions::SetWelcomeScreen( sal_Bool b )
     628             : {
     629           0 :     pImp->SetWelcomeScreen( b );
     630           0 : }
     631             : 
     632           0 : sal_Bool SvtHelpOptions::IsWelcomeScreen() const
     633             : {
     634           0 :     return pImp->IsWelcomeScreen();
     635             : }
     636             : 
     637          19 : String SvtHelpOptions::GetSystem() const
     638             : {
     639          19 :     return pImp->GetSystem();
     640             : }
     641             : 
     642           0 : const String&   SvtHelpOptions::GetHelpStyleSheet()const
     643             : {
     644           0 :     return pImp->GetHelpStyleSheet();
     645             : }
     646             : 
     647           0 : void  SvtHelpOptions::SetHelpStyleSheet(const String& rStyleSheet)
     648             : {
     649           0 :     pImp->SetHelpStyleSheet(rStyleSheet);
     650           0 : }
     651             : 
     652             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10