LCOV - code coverage report
Current view: top level - linguistic/source - lngsvcmgr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 731 1067 68.5 %
Date: 2012-08-25 Functions: 51 71 71.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 768 2174 35.3 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <com/sun/star/deployment/ExtensionManager.hpp>
      31                 :            : #include <com/sun/star/registry/XRegistryKey.hpp>
      32                 :            : #include <com/sun/star/container/XContentEnumerationAccess.hpp>
      33                 :            : #include <com/sun/star/container/XEnumeration.hpp>
      34                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      35                 :            : #include <com/sun/star/linguistic2/XSupportedLocales.hpp>
      36                 :            : #include <com/sun/star/linguistic2/DictionaryListEventFlags.hpp>
      37                 :            : #include <com/sun/star/linguistic2/LinguServiceEventFlags.hpp>
      38                 :            : 
      39                 :            : #include <tools/solar.h>
      40                 :            : #include <unotools/lingucfg.hxx>
      41                 :            : #include <comphelper/processfactory.hxx>
      42                 :            : #include <i18npool/lang.h>
      43                 :            : #include <i18npool/mslangid.hxx>
      44                 :            : #include <cppuhelper/factory.hxx>
      45                 :            : #include <comphelper/extract.hxx>
      46                 :            : #include <rtl/logfile.hxx>
      47                 :            : 
      48                 :            : #include "lngsvcmgr.hxx"
      49                 :            : #include "lngopt.hxx"
      50                 :            : #include "linguistic/misc.hxx"
      51                 :            : #include "spelldsp.hxx"
      52                 :            : #include "hyphdsp.hxx"
      53                 :            : #include "thesdsp.hxx"
      54                 :            : #include "gciterator.hxx"
      55                 :            : 
      56                 :            : 
      57                 :            : using namespace com::sun::star;
      58                 :            : using namespace linguistic;
      59                 :            : using ::rtl::OUString;
      60                 :            : 
      61                 :            : // forward declarations
      62                 :            : uno::Sequence< OUString > static GetLangSvcList( const uno::Any &rVal );
      63                 :            : uno::Sequence< OUString > static GetLangSvc( const uno::Any &rVal );
      64                 :            : 
      65                 :            : 
      66                 :       9600 : static sal_Bool lcl_SeqHasString( const uno::Sequence< OUString > &rSeq, const OUString &rText )
      67                 :            : {
      68                 :       9600 :     sal_Bool bRes = sal_False;
      69                 :            : 
      70                 :       9600 :     sal_Int32 nLen = rSeq.getLength();
      71 [ -  + ][ -  + ]:       9600 :     if (nLen == 0 || rText.isEmpty())
                 [ +  - ]
      72                 :          0 :         return bRes;
      73                 :            : 
      74                 :       9600 :     const OUString *pSeq = rSeq.getConstArray();
      75 [ +  + ][ +  + ]:     214272 :     for (sal_Int32 i = 0;  i < nLen  &&  !bRes;  ++i)
                 [ +  + ]
      76                 :            :     {
      77         [ +  + ]:     204672 :         if (rText == pSeq[i])
      78                 :       9600 :             bRes = sal_True;
      79                 :            :     }
      80                 :       9600 :     return bRes;
      81                 :            : }
      82                 :            : 
      83                 :            : 
      84                 :        192 : static uno::Sequence< lang::Locale > GetAvailLocales(
      85                 :            :         const uno::Sequence< OUString > &rSvcImplNames )
      86                 :            : {
      87         [ +  - ]:        192 :     uno::Sequence< lang::Locale > aRes;
      88                 :            : 
      89         [ +  - ]:        192 :     uno::Reference< lang::XMultiServiceFactory >  xFac( comphelper::getProcessServiceFactory() );
      90                 :        192 :     sal_Int32 nNames = rSvcImplNames.getLength();
      91 [ +  - ][ +  - ]:        192 :     if (nNames  &&  xFac.is())
                 [ +  - ]
      92                 :            :     {
      93         [ +  - ]:        192 :         std::set< LanguageType > aLanguages;
      94                 :            : 
      95                 :            :         //! since we're going to create one-instance services we have to
      96                 :            :         //! supply their arguments even if we would not need them here...
      97         [ +  - ]:        192 :         uno::Sequence< uno::Any > aArgs(2);
      98 [ +  - ][ +  - ]:        192 :         aArgs.getArray()[0] <<= GetLinguProperties();
                 [ +  - ]
      99                 :            : 
     100                 :            :         // check all services for the supported languages and new
     101                 :            :         // languages to the result
     102                 :        192 :         const OUString *pImplNames = rSvcImplNames.getConstArray();
     103                 :            :         sal_Int32 i;
     104                 :            : 
     105         [ +  + ]:        384 :         for (i = 0;  i < nNames;  ++i)
     106                 :            :         {
     107                 :        192 :             uno::Reference< linguistic2::XSupportedLocales > xSuppLoc;
     108                 :            :             try
     109                 :            :             {
     110                 :            :                 xSuppLoc = uno::Reference< linguistic2::XSupportedLocales >(
     111 [ +  - ][ +  - ]:        192 :                         xFac->createInstanceWithArguments( pImplNames[i], aArgs ), uno::UNO_QUERY );
         [ +  - ][ #  # ]
                 [ +  - ]
     112                 :            :             }
     113         [ #  # ]:          0 :             catch (uno::Exception &)
     114                 :            :             {
     115                 :            :                 DBG_ASSERT( 0, "createInstanceWithArguments failed" );
     116                 :            :             }
     117                 :            : 
     118         [ +  - ]:        192 :             if (xSuppLoc.is())
     119                 :            :             {
     120 [ +  - ][ +  - ]:        192 :                 uno::Sequence< lang::Locale > aLoc( xSuppLoc->getLocales() );
     121                 :        192 :                 sal_Int32 nLoc = aLoc.getLength();
     122         [ +  + ]:       7392 :                 for (sal_Int32 k = 0;  k < nLoc;  ++k)
     123                 :            :                 {
     124                 :       7200 :                     const lang::Locale *pLoc = aLoc.getConstArray();
     125         [ +  - ]:       7200 :                     LanguageType nLang = LocaleToLanguage( pLoc[k] );
     126                 :            : 
     127                 :            :                     // language not already added?
     128 [ +  - ][ +  - ]:       7200 :                     if (aLanguages.find( nLang ) == aLanguages.end())
                 [ +  - ]
     129         [ +  - ]:       7200 :                         aLanguages.insert( nLang );
     130         [ +  - ]:        192 :                 }
     131                 :            :             }
     132                 :            :             else
     133                 :            :             {
     134                 :            :                 DBG_ASSERT( 0, "interface not supported by service" );
     135                 :            :             }
     136                 :        192 :         }
     137                 :            : 
     138                 :            :         // build return sequence
     139                 :        192 :         sal_Int32 nLanguages = static_cast< sal_Int32 >(aLanguages.size());
     140         [ +  - ]:        192 :         aRes.realloc( nLanguages );
     141         [ +  - ]:        192 :         lang::Locale *pRes = aRes.getArray();
     142                 :        192 :         std::set< LanguageType >::const_iterator aIt( aLanguages.begin() );
     143 [ +  - ][ +  + ]:       7392 :         for (i = 0;  aIt != aLanguages.end();  ++aIt, ++i)
                 [ +  - ]
     144                 :            :         {
     145         [ +  - ]:       7200 :             LanguageType nLang = *aIt;
     146         [ +  - ]:       7200 :             pRes[i] = CreateLocale( nLang );
     147         [ +  - ]:        192 :         }
     148                 :            :     }
     149                 :            : 
     150                 :        192 :     return aRes;
     151                 :            : }
     152                 :            : 
     153                 :            : 
     154         [ +  - ]:        192 : struct SvcInfo
     155                 :            : {
     156                 :            :     const OUString                  aSvcImplName;
     157                 :            :     const uno::Sequence< sal_Int16 >    aSuppLanguages;
     158                 :            : 
     159                 :        192 :     SvcInfo( const OUString &rSvcImplName,
     160                 :            :              const uno::Sequence< sal_Int16 >  &rSuppLanguages ) :
     161                 :            :         aSvcImplName    (rSvcImplName),
     162         [ +  - ]:        192 :         aSuppLanguages  (rSuppLanguages)
     163                 :            :     {
     164                 :        192 :     }
     165                 :            : 
     166                 :            :     sal_Bool    HasLanguage( sal_Int16 nLanguage ) const;
     167                 :            : };
     168                 :            : 
     169                 :            : 
     170                 :       9600 : sal_Bool SvcInfo::HasLanguage( sal_Int16 nLanguage ) const
     171                 :            : {
     172                 :       9600 :     sal_Int32 nCnt = aSuppLanguages.getLength();
     173                 :       9600 :     const sal_Int16 *pLang = aSuppLanguages.getConstArray();
     174                 :            :     sal_Int32 i;
     175                 :            : 
     176         [ +  - ]:     204672 :     for ( i = 0;  i < nCnt;  ++i)
     177                 :            :     {
     178         [ +  + ]:     204672 :         if (nLanguage == pLang[i])
     179                 :       9600 :             break;
     180                 :            :     }
     181                 :       9600 :     return i < nCnt;
     182                 :            : }
     183                 :            : 
     184 [ +  - ][ +  - ]:         84 : class LngSvcMgrListenerHelper :
                 [ -  + ]
     185                 :            :     public cppu::WeakImplHelper2
     186                 :            :     <
     187                 :            :         linguistic2::XLinguServiceEventListener,
     188                 :            :         linguistic2::XDictionaryListEventListener
     189                 :            :     >
     190                 :            : {
     191                 :            :     LngSvcMgr  &rMyManager;
     192                 :            : 
     193                 :            :     ::cppu::OInterfaceContainerHelper           aLngSvcMgrListeners;
     194                 :            :     ::cppu::OInterfaceContainerHelper           aLngSvcEvtBroadcasters;
     195                 :            :     uno::Reference< linguistic2::XDictionaryList >               xDicList;
     196                 :            : 
     197                 :            :     sal_Int16   nCombinedLngSvcEvt;
     198                 :            : 
     199                 :            :     // disallow copy-constructor and assignment-operator for now
     200                 :            :     LngSvcMgrListenerHelper(const LngSvcMgrListenerHelper &);
     201                 :            :     LngSvcMgrListenerHelper & operator = (const LngSvcMgrListenerHelper &);
     202                 :            : 
     203                 :            :     void    LaunchEvent( sal_Int16 nLngSvcEvtFlags );
     204                 :            : 
     205                 :            :     long Timeout();
     206                 :            : 
     207                 :            : public:
     208                 :            :     LngSvcMgrListenerHelper( LngSvcMgr &rLngSvcMgr,
     209                 :            :         const uno::Reference< linguistic2::XDictionaryList > &rxDicList );
     210                 :            : 
     211                 :            :     // lang::XEventListener
     212                 :            :     virtual void SAL_CALL
     213                 :            :         disposing( const lang::EventObject& rSource )
     214                 :            :             throw(uno::RuntimeException);
     215                 :            : 
     216                 :            :     // linguistic2::XLinguServiceEventListener
     217                 :            :     virtual void SAL_CALL
     218                 :            :         processLinguServiceEvent( const linguistic2::LinguServiceEvent& aLngSvcEvent )
     219                 :            :             throw(uno::RuntimeException);
     220                 :            : 
     221                 :            :     // linguistic2::XDictionaryListEventListener
     222                 :            :     virtual void SAL_CALL
     223                 :            :         processDictionaryListEvent(
     224                 :            :                 const linguistic2::DictionaryListEvent& rDicListEvent )
     225                 :            :             throw(uno::RuntimeException);
     226                 :            : 
     227                 :            :     inline  sal_Bool    AddLngSvcMgrListener(
     228                 :            :                         const uno::Reference< lang::XEventListener >& rxListener );
     229                 :            :     inline  sal_Bool    RemoveLngSvcMgrListener(
     230                 :            :                         const uno::Reference< lang::XEventListener >& rxListener );
     231                 :            :     void    DisposeAndClear( const lang::EventObject &rEvtObj );
     232                 :            :     sal_Bool    AddLngSvcEvtBroadcaster(
     233                 :            :                         const uno::Reference< linguistic2::XLinguServiceEventBroadcaster > &rxBroadcaster );
     234                 :            :     sal_Bool    RemoveLngSvcEvtBroadcaster(
     235                 :            :                         const uno::Reference< linguistic2::XLinguServiceEventBroadcaster > &rxBroadcaster );
     236                 :            : 
     237                 :            :     void    AddLngSvcEvt( sal_Int16 nLngSvcEvt );
     238                 :            : };
     239                 :            : 
     240                 :            : 
     241                 :         42 : LngSvcMgrListenerHelper::LngSvcMgrListenerHelper(
     242                 :            :         LngSvcMgr &rLngSvcMgr,
     243                 :            :         const uno::Reference< linguistic2::XDictionaryList > &rxDicList  ) :
     244                 :            :     rMyManager              ( rLngSvcMgr ),
     245         [ +  - ]:         42 :     aLngSvcMgrListeners     ( GetLinguMutex() ),
     246         [ +  - ]:         42 :     aLngSvcEvtBroadcasters  ( GetLinguMutex() ),
     247 [ +  - ][ +  - ]:        126 :     xDicList                ( rxDicList )
     248                 :            : {
     249         [ +  - ]:         42 :     if (xDicList.is())
     250                 :            :     {
     251         [ +  - ]:         42 :         xDicList->addDictionaryListEventListener(
     252 [ +  - ][ +  - ]:         42 :             (linguistic2::XDictionaryListEventListener *) this, sal_False );
     253                 :            :     }
     254                 :            : 
     255                 :         42 :     nCombinedLngSvcEvt = 0;
     256                 :         42 : }
     257                 :            : 
     258                 :            : 
     259                 :          0 : void SAL_CALL LngSvcMgrListenerHelper::disposing( const lang::EventObject& rSource )
     260                 :            :         throw(uno::RuntimeException)
     261                 :            : {
     262 [ #  # ][ #  # ]:          0 :     osl::MutexGuard aGuard( GetLinguMutex() );
     263                 :            : 
     264                 :          0 :     uno::Reference< uno::XInterface > xRef( rSource.Source );
     265         [ #  # ]:          0 :     if ( xRef.is() )
     266                 :            :     {
     267         [ #  # ]:          0 :         aLngSvcMgrListeners   .removeInterface( xRef );
     268         [ #  # ]:          0 :         aLngSvcEvtBroadcasters.removeInterface( xRef );
     269 [ #  # ][ #  # ]:          0 :         if (xDicList == xRef)
     270         [ #  # ]:          0 :             xDicList = 0;
     271         [ #  # ]:          0 :     }
     272                 :          0 : }
     273                 :            : 
     274                 :          2 : long LngSvcMgrListenerHelper::Timeout()
     275                 :            : {
     276 [ +  - ][ +  - ]:          2 :     osl::MutexGuard aGuard( GetLinguMutex() );
     277                 :            : 
     278                 :            :     {
     279                 :            :         // change event source to LinguServiceManager since the listeners
     280                 :            :         // probably do not know (and need not to know) about the specific
     281                 :            :         // SpellChecker's or Hyphenator's.
     282                 :            :         linguistic2::LinguServiceEvent aEvtObj(
     283 [ +  - ][ +  - ]:          2 :             static_cast<com::sun::star::linguistic2::XLinguServiceManager*>(&rMyManager), nCombinedLngSvcEvt );
     284                 :          2 :         nCombinedLngSvcEvt = 0;
     285                 :            : 
     286         [ +  - ]:          2 :         if (rMyManager.pSpellDsp)
     287         [ +  - ]:          2 :             rMyManager.pSpellDsp->FlushSpellCache();
     288                 :            : 
     289                 :            :         // pass event on to linguistic2::XLinguServiceEventListener's
     290         [ +  - ]:          2 :         cppu::OInterfaceIteratorHelper aIt( aLngSvcMgrListeners );
     291         [ -  + ]:          2 :         while (aIt.hasMoreElements())
     292                 :            :         {
     293 [ #  # ][ #  # ]:          0 :             uno::Reference< linguistic2::XLinguServiceEventListener > xRef( aIt.next(), uno::UNO_QUERY );
     294         [ #  # ]:          0 :             if (xRef.is())
     295 [ #  # ][ #  # ]:          0 :                 xRef->processLinguServiceEvent( aEvtObj );
     296 [ +  - ][ +  - ]:          2 :         }
     297                 :            :     }
     298         [ +  - ]:          2 :     return 0;
     299                 :            : }
     300                 :            : 
     301                 :            : 
     302                 :          2 : void LngSvcMgrListenerHelper::AddLngSvcEvt( sal_Int16 nLngSvcEvt )
     303                 :            : {
     304                 :          2 :     nCombinedLngSvcEvt |= nLngSvcEvt;
     305                 :          2 :     Timeout();
     306                 :          2 : }
     307                 :            : 
     308                 :            : 
     309                 :            : void SAL_CALL
     310                 :          0 :     LngSvcMgrListenerHelper::processLinguServiceEvent(
     311                 :            :             const linguistic2::LinguServiceEvent& rLngSvcEvent )
     312                 :            :         throw(uno::RuntimeException)
     313                 :            : {
     314 [ #  # ][ #  # ]:          0 :     osl::MutexGuard aGuard( GetLinguMutex() );
     315 [ #  # ][ #  # ]:          0 :     AddLngSvcEvt( rLngSvcEvent.nEvent );
     316                 :          0 : }
     317                 :            : 
     318                 :            : 
     319                 :            : void SAL_CALL
     320                 :          0 :     LngSvcMgrListenerHelper::processDictionaryListEvent(
     321                 :            :             const linguistic2::DictionaryListEvent& rDicListEvent )
     322                 :            :         throw(uno::RuntimeException)
     323                 :            : {
     324 [ #  # ][ #  # ]:          0 :     osl::MutexGuard aGuard( GetLinguMutex() );
     325                 :            : 
     326                 :          0 :     sal_Int16 nDlEvt = rDicListEvent.nCondensedEvent;
     327         [ #  # ]:          0 :     if (0 == nDlEvt)
     328                 :          0 :         return;
     329                 :            : 
     330                 :            :     // we do keep the original event source here though...
     331                 :            : 
     332                 :            :     // pass event on to linguistic2::XDictionaryListEventListener's
     333         [ #  # ]:          0 :     cppu::OInterfaceIteratorHelper aIt( aLngSvcMgrListeners );
     334         [ #  # ]:          0 :     while (aIt.hasMoreElements())
     335                 :            :     {
     336 [ #  # ][ #  # ]:          0 :         uno::Reference< linguistic2::XDictionaryListEventListener > xRef( aIt.next(), uno::UNO_QUERY );
     337         [ #  # ]:          0 :         if (xRef.is())
     338 [ #  # ][ #  # ]:          0 :             xRef->processDictionaryListEvent( rDicListEvent );
     339                 :          0 :     }
     340                 :            : 
     341                 :            :     // "translate" DictionaryList event into linguistic2::LinguServiceEvent
     342                 :          0 :     sal_Int16 nLngSvcEvt = 0;
     343                 :            :     sal_Int16 nSpellCorrectFlags =
     344                 :            :             linguistic2::DictionaryListEventFlags::ADD_NEG_ENTRY        |
     345                 :            :             linguistic2::DictionaryListEventFlags::DEL_POS_ENTRY        |
     346                 :            :             linguistic2::DictionaryListEventFlags::ACTIVATE_NEG_DIC |
     347                 :          0 :             linguistic2::DictionaryListEventFlags::DEACTIVATE_POS_DIC;
     348         [ #  # ]:          0 :     if (0 != (nDlEvt & nSpellCorrectFlags))
     349                 :          0 :         nLngSvcEvt |= linguistic2::LinguServiceEventFlags::SPELL_CORRECT_WORDS_AGAIN;
     350                 :            : 
     351                 :            :     sal_Int16 nSpellWrongFlags =
     352                 :            :             linguistic2::DictionaryListEventFlags::ADD_POS_ENTRY        |
     353                 :            :             linguistic2::DictionaryListEventFlags::DEL_NEG_ENTRY        |
     354                 :            :             linguistic2::DictionaryListEventFlags::ACTIVATE_POS_DIC |
     355                 :          0 :             linguistic2::DictionaryListEventFlags::DEACTIVATE_NEG_DIC;
     356         [ #  # ]:          0 :     if (0 != (nDlEvt & nSpellWrongFlags))
     357                 :          0 :         nLngSvcEvt |= linguistic2::LinguServiceEventFlags::SPELL_WRONG_WORDS_AGAIN;
     358                 :            : 
     359                 :            :     sal_Int16 nHyphenateFlags =
     360                 :            :             linguistic2::DictionaryListEventFlags::ADD_POS_ENTRY        |
     361                 :            :             linguistic2::DictionaryListEventFlags::DEL_POS_ENTRY        |
     362                 :            :             linguistic2::DictionaryListEventFlags::ACTIVATE_POS_DIC |
     363                 :          0 :             linguistic2::DictionaryListEventFlags::ACTIVATE_NEG_DIC;
     364         [ #  # ]:          0 :     if (0 != (nDlEvt & nHyphenateFlags))
     365                 :          0 :         nLngSvcEvt |= linguistic2::LinguServiceEventFlags::HYPHENATE_AGAIN;
     366                 :            : 
     367         [ #  # ]:          0 :     if (rMyManager.pSpellDsp)
     368         [ #  # ]:          0 :         rMyManager.pSpellDsp->FlushSpellCache();
     369         [ #  # ]:          0 :     if (nLngSvcEvt)
     370 [ #  # ][ #  # ]:          0 :         LaunchEvent( nLngSvcEvt );
         [ #  # ][ #  # ]
     371                 :            : }
     372                 :            : 
     373                 :            : 
     374                 :          0 : void LngSvcMgrListenerHelper::LaunchEvent( sal_Int16 nLngSvcEvtFlags )
     375                 :            : {
     376                 :            :     linguistic2::LinguServiceEvent aEvt(
     377 [ #  # ][ #  # ]:          0 :         static_cast<com::sun::star::linguistic2::XLinguServiceManager*>(&rMyManager), nLngSvcEvtFlags );
     378                 :            : 
     379                 :            :     // pass event on to linguistic2::XLinguServiceEventListener's
     380         [ #  # ]:          0 :     cppu::OInterfaceIteratorHelper aIt( aLngSvcMgrListeners );
     381         [ #  # ]:          0 :     while (aIt.hasMoreElements())
     382                 :            :     {
     383 [ #  # ][ #  # ]:          0 :         uno::Reference< linguistic2::XLinguServiceEventListener > xRef( aIt.next(), uno::UNO_QUERY );
     384         [ #  # ]:          0 :         if (xRef.is())
     385 [ #  # ][ #  # ]:          0 :             xRef->processLinguServiceEvent( aEvt );
     386 [ #  # ][ #  # ]:          0 :     }
     387                 :          0 : }
     388                 :            : 
     389                 :            : 
     390                 :         26 : inline sal_Bool LngSvcMgrListenerHelper::AddLngSvcMgrListener(
     391                 :            :         const uno::Reference< lang::XEventListener >& rxListener )
     392                 :            : {
     393                 :         26 :     aLngSvcMgrListeners.addInterface( rxListener );
     394                 :         26 :     return sal_True;
     395                 :            : }
     396                 :            : 
     397                 :            : 
     398                 :          0 : inline sal_Bool LngSvcMgrListenerHelper::RemoveLngSvcMgrListener(
     399                 :            :         const uno::Reference< lang::XEventListener >& rxListener )
     400                 :            : {
     401                 :          0 :     aLngSvcMgrListeners.removeInterface( rxListener );
     402                 :          0 :     return sal_True;
     403                 :            : }
     404                 :            : 
     405                 :            : 
     406                 :         42 : void LngSvcMgrListenerHelper::DisposeAndClear( const lang::EventObject &rEvtObj )
     407                 :            : {
     408                 :            :     // call "disposing" for all listeners and clear list
     409         [ +  - ]:         42 :     aLngSvcMgrListeners   .disposeAndClear( rEvtObj );
     410                 :            : 
     411                 :            :     // remove references to this object hold by the broadcasters
     412         [ +  - ]:         42 :     cppu::OInterfaceIteratorHelper aIt( aLngSvcEvtBroadcasters );
     413         [ +  + ]:         91 :     while (aIt.hasMoreElements())
     414                 :            :     {
     415 [ +  - ][ +  - ]:         49 :         uno::Reference< linguistic2::XLinguServiceEventBroadcaster > xRef( aIt.next(), uno::UNO_QUERY );
     416         [ +  - ]:         49 :         if (xRef.is())
     417         [ +  - ]:         49 :             RemoveLngSvcEvtBroadcaster( xRef );
     418                 :         49 :     }
     419                 :            : 
     420                 :            :     // remove refernce to this object hold by the dictionary-list
     421         [ +  - ]:         42 :     if (xDicList.is())
     422                 :            :     {
     423         [ +  - ]:         42 :         xDicList->removeDictionaryListEventListener(
     424 [ +  - ][ +  - ]:         42 :             (linguistic2::XDictionaryListEventListener *) this );
     425         [ +  - ]:         42 :         xDicList = 0;
     426         [ +  - ]:         42 :     }
     427                 :         42 : }
     428                 :            : 
     429                 :            : 
     430                 :         49 : sal_Bool LngSvcMgrListenerHelper::AddLngSvcEvtBroadcaster(
     431                 :            :         const uno::Reference< linguistic2::XLinguServiceEventBroadcaster > &rxBroadcaster )
     432                 :            : {
     433                 :         49 :     sal_Bool bRes = sal_False;
     434         [ +  - ]:         49 :     if (rxBroadcaster.is())
     435                 :            :     {
     436                 :         49 :         aLngSvcEvtBroadcasters.addInterface( rxBroadcaster );
     437                 :         49 :         rxBroadcaster->addLinguServiceEventListener(
     438         [ +  - ]:         49 :                 (linguistic2::XLinguServiceEventListener *) this );
     439                 :            :     }
     440                 :         49 :     return bRes;
     441                 :            : }
     442                 :            : 
     443                 :            : 
     444                 :         49 : sal_Bool LngSvcMgrListenerHelper::RemoveLngSvcEvtBroadcaster(
     445                 :            :         const uno::Reference< linguistic2::XLinguServiceEventBroadcaster > &rxBroadcaster )
     446                 :            : {
     447                 :         49 :     sal_Bool bRes = sal_False;
     448         [ +  - ]:         49 :     if (rxBroadcaster.is())
     449                 :            :     {
     450                 :         49 :         aLngSvcEvtBroadcasters.removeInterface( rxBroadcaster );
     451                 :         49 :         rxBroadcaster->removeLinguServiceEventListener(
     452         [ +  - ]:         49 :                 (linguistic2::XLinguServiceEventListener *) this );
     453                 :            :     }
     454                 :         49 :     return bRes;
     455                 :            : }
     456                 :            : 
     457                 :            : 
     458                 :            : 
     459                 :            : 
     460                 :         46 : LngSvcMgr::LngSvcMgr()
     461                 :            :     : utl::ConfigItem("Office.Linguistic")
     462 [ +  - ][ +  - ]:         46 :     , aEvtListeners(GetLinguMutex())
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     463                 :            : {
     464                 :         46 :     bDisposing = sal_False;
     465                 :            : 
     466                 :         46 :     pSpellDsp   = 0;
     467                 :         46 :     pGrammarDsp = 0;
     468                 :         46 :     pHyphDsp    = 0;
     469                 :         46 :     pThesDsp    = 0;
     470                 :            : 
     471                 :         46 :     pAvailSpellSvcs     = 0;
     472                 :         46 :     pAvailGrammarSvcs   = 0;
     473                 :         46 :     pAvailHyphSvcs      = 0;
     474                 :         46 :     pAvailThesSvcs      = 0;
     475                 :         46 :     pListenerHelper     = 0;
     476                 :            : 
     477                 :            :     // request notify events when properties (i.e. something in the subtree) changes
     478         [ +  - ]:         46 :     uno::Sequence< OUString > aNames(4);
     479         [ +  - ]:         46 :     OUString *pNames = aNames.getArray();
     480                 :         46 :     pNames[0] = "ServiceManager/SpellCheckerList";
     481                 :         46 :     pNames[1] = "ServiceManager/GrammarCheckerList";
     482                 :         46 :     pNames[2] = "ServiceManager/HyphenatorList";
     483                 :         46 :     pNames[3] = "ServiceManager/ThesaurusList";
     484         [ +  - ]:         46 :     EnableNotification( aNames );
     485                 :            : 
     486         [ +  - ]:         46 :     UpdateAll();
     487                 :            : 
     488         [ +  - ]:         46 :     aUpdateTimer.SetTimeout(500);
     489         [ +  - ]:         46 :     aUpdateTimer.SetTimeoutHdl(LINK(this, LngSvcMgr, updateAndBroadcast));
     490                 :            : 
     491                 :            :     // request to be notified if an extension has been added/removed
     492         [ +  - ]:         46 :     uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
     493                 :            : 
     494                 :         46 :     uno::Reference<deployment::XExtensionManager> xExtensionManager;
     495                 :            :     try {
     496 [ +  - ][ #  # ]:         46 :         xExtensionManager = deployment::ExtensionManager::get(xContext);
                 [ +  - ]
     497         [ #  # ]:          0 :     } catch ( const deployment::DeploymentException & ) {
     498                 :            :         SAL_WARN( "linguistic", "no extension manager - should fire on mobile only" );
     499                 :            :     }
     500         [ +  - ]:         46 :     if (xExtensionManager.is())
     501                 :            :     {
     502 [ +  - ][ +  - ]:         46 :         xMB = uno::Reference<util::XModifyBroadcaster>(xExtensionManager, uno::UNO_QUERY_THROW);
     503                 :            : 
     504         [ +  - ]:         46 :         uno::Reference<util::XModifyListener> xListener(this);
     505 [ +  - ][ +  - ]:         46 :         xMB->addModifyListener( xListener );
     506         [ +  - ]:         46 :     }
     507                 :         46 : }
     508                 :            : 
     509                 :            : // ::com::sun::star::util::XModifyListener
     510                 :          8 : void LngSvcMgr::modified(const lang::EventObject&)
     511                 :            :     throw(uno::RuntimeException)
     512                 :            : {
     513 [ +  - ][ +  - ]:          8 :     osl::MutexGuard aGuard(GetLinguMutex());
     514                 :            :     //assume that if an extension has been added/removed that
     515                 :            :     //it might be a dictionary extension, so drop our cache
     516                 :            : 
     517 [ -  + ][ #  # ]:          8 :     delete pAvailSpellSvcs;
     518                 :          8 :     pAvailSpellSvcs = NULL;
     519 [ -  + ][ #  # ]:          8 :     delete pAvailGrammarSvcs;
     520                 :          8 :     pAvailGrammarSvcs = NULL;
     521 [ -  + ][ #  # ]:          8 :     delete pAvailHyphSvcs;
     522                 :          8 :     pAvailHyphSvcs = NULL;
     523 [ -  + ][ #  # ]:          8 :     delete pAvailThesSvcs;
     524                 :          8 :     pAvailThesSvcs = NULL;
     525                 :            : 
     526                 :            :     //schedule in an update to execute in the main thread
     527 [ +  - ][ +  - ]:          8 :     aUpdateTimer.Start();
     528                 :          8 : }
     529                 :            : 
     530                 :            : //run update, and inform everyone that dictionaries (may) have changed, this
     531                 :            : //needs to be run in the main thread because
     532                 :            : //utl::ConfigChangeListener_Impl::changesOccurred grabs the SolarMutex and we
     533                 :            : //get notified that an extension was added from an extension manager thread
     534                 :          2 : IMPL_LINK_NOARG(LngSvcMgr, updateAndBroadcast)
     535                 :            : {
     536 [ +  - ][ +  - ]:          2 :     osl::MutexGuard aGuard( GetLinguMutex() );
     537                 :            : 
     538         [ +  - ]:          2 :     UpdateAll();
     539                 :            : 
     540         [ +  - ]:          2 :     if (pListenerHelper)
     541                 :            :     {
     542                 :            :         pListenerHelper->AddLngSvcEvt(
     543                 :            :                 linguistic2::LinguServiceEventFlags::SPELL_CORRECT_WORDS_AGAIN |
     544                 :            :                 linguistic2::LinguServiceEventFlags::SPELL_WRONG_WORDS_AGAIN |
     545                 :            :                 linguistic2::LinguServiceEventFlags::PROOFREAD_AGAIN |
     546         [ +  - ]:          2 :                 linguistic2::LinguServiceEventFlags::HYPHENATE_AGAIN );
     547                 :            :     }
     548                 :            : 
     549         [ +  - ]:          2 :     return 0;
     550                 :            : }
     551                 :            : 
     552                 :         92 : void LngSvcMgr::stopListening()
     553                 :            : {
     554 [ +  - ][ +  - ]:         92 :     osl::MutexGuard aGuard(GetLinguMutex());
     555                 :            : 
     556         [ +  + ]:         92 :     if (xMB.is())
     557                 :            :     {
     558                 :            :         try
     559                 :            :         {
     560         [ +  - ]:         46 :                 uno::Reference<util::XModifyListener>  xListener(this);
     561 [ +  - ][ -  + ]:         46 :                 xMB->removeModifyListener(xListener);
                 [ -  + ]
     562                 :            :         }
     563         [ +  - ]:         46 :         catch (const uno::Exception&)
     564                 :            :         {
     565                 :            :         }
     566                 :            : 
     567                 :         46 :         xMB.clear();
     568         [ +  - ]:         92 :     }
     569                 :         92 : }
     570                 :            : 
     571                 :         46 : void LngSvcMgr::disposing(const lang::EventObject&)
     572                 :            :     throw (uno::RuntimeException)
     573                 :            : {
     574                 :         46 :     stopListening();
     575                 :         46 : }
     576                 :            : 
     577 [ +  - ][ +  - ]:         46 : LngSvcMgr::~LngSvcMgr()
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     578                 :            : {
     579         [ +  - ]:         46 :     stopListening();
     580                 :            : 
     581                 :            :     // memory for pSpellDsp, pHyphDsp, pThesDsp, pListenerHelper
     582                 :            :     // will be freed in the destructor of the respective Reference's
     583                 :            :     // xSpellDsp, xGrammarDsp, xHyphDsp, xThesDsp
     584                 :            : 
     585 [ -  + ][ #  # ]:         46 :     delete pAvailSpellSvcs;
     586 [ -  + ][ #  # ]:         46 :     delete pAvailGrammarSvcs;
     587 [ -  + ][ #  # ]:         46 :     delete pAvailHyphSvcs;
     588 [ -  + ][ #  # ]:         46 :     delete pAvailThesSvcs;
     589         [ -  + ]:         92 : }
     590                 :            : 
     591                 :            : namespace
     592                 :            : {
     593                 :            :     using lang::Locale;
     594                 :            :     using uno::Any;
     595                 :            :     using uno::Sequence;
     596                 :            : 
     597                 :      24000 :     sal_Bool lcl_FindEntry( const OUString &rEntry, const Sequence< OUString > &rCfgSvcs )
     598                 :            :     {
     599                 :      24000 :         sal_Int32 nRes = -1;
     600                 :      24000 :         sal_Int32 nEntries = rCfgSvcs.getLength();
     601                 :      24000 :         const OUString *pEntry = rCfgSvcs.getConstArray();
     602 [ +  + ][ +  + ]:      87168 :         for (sal_Int32 i = 0;  i < nEntries && nRes == -1;  ++i)
                 [ +  + ]
     603                 :            :         {
     604         [ +  + ]:      63168 :             if (rEntry == pEntry[i])
     605                 :       7200 :                 nRes = i;
     606                 :            :         }
     607                 :      24000 :         return nRes != -1;
     608                 :            :     }
     609                 :            : 
     610                 :       7200 :     Sequence< OUString > lcl_GetLastFoundSvcs(
     611                 :            :             SvtLinguConfig &rCfg,
     612                 :            :             const OUString &rLastFoundList ,
     613                 :            :             const Locale &rAvailLocale )
     614                 :            :     {
     615         [ +  - ]:       7200 :         Sequence< OUString > aRes;
     616                 :            : 
     617                 :            :         OUString aCfgLocaleStr( MsLangId::convertLanguageToIsoString(
     618 [ +  - ][ +  - ]:       7200 :                                     LocaleToLanguage( rAvailLocale ) ) );
     619                 :            : 
     620         [ +  - ]:       7200 :         Sequence< OUString > aNodeNames( rCfg.GetNodeNames(rLastFoundList) );
     621         [ +  - ]:       7200 :         sal_Bool bFound = lcl_FindEntry( aCfgLocaleStr, aNodeNames);
     622                 :            : 
     623         [ +  + ]:       7200 :         if (bFound)
     624                 :            :         {
     625         [ +  - ]:       2400 :             Sequence< OUString > aNames(1);
     626         [ +  - ]:       2400 :             OUString &rNodeName = aNames.getArray()[0];
     627                 :       2400 :             rNodeName = rLastFoundList;
     628                 :       2400 :             rNodeName += OUString::valueOf( (sal_Unicode)'/' );
     629                 :       2400 :             rNodeName += aCfgLocaleStr;
     630         [ +  - ]:       2400 :             Sequence< Any > aValues( rCfg.GetProperties( aNames ) );
     631         [ +  - ]:       2400 :             if (aValues.getLength())
     632                 :            :             {
     633                 :            :                 OSL_ENSURE( aValues.getLength() == 1, "unexpected length of sequence" );
     634         [ +  - ]:       2400 :                 Sequence< OUString > aSvcImplNames;
     635 [ +  - ][ +  - ]:       2400 :                 if (aValues.getConstArray()[0] >>= aSvcImplNames)
     636         [ +  - ]:       2400 :                     aRes = aSvcImplNames;
     637                 :            :                 else
     638                 :            :                 {
     639                 :            :                     OSL_FAIL( "type mismatch" );
     640         [ +  - ]:       2400 :                 }
     641 [ +  - ][ +  - ]:       2400 :             }
     642                 :            :         }
     643                 :            : 
     644         [ +  - ]:       7200 :         return aRes;
     645                 :            :     }
     646                 :            : 
     647                 :       2400 :     Sequence< OUString > lcl_RemoveMissingEntries(
     648                 :            :             const Sequence< OUString > &rCfgSvcs,
     649                 :            :             const Sequence< OUString > &rAvailSvcs )
     650                 :            :     {
     651                 :       2400 :         Sequence< OUString > aRes( rCfgSvcs.getLength() );
     652         [ +  - ]:       2400 :         OUString *pRes = aRes.getArray();
     653                 :       2400 :         sal_Int32 nCnt = 0;
     654                 :            : 
     655                 :       2400 :         sal_Int32 nEntries = rCfgSvcs.getLength();
     656                 :       2400 :         const OUString *pEntry = rCfgSvcs.getConstArray();
     657         [ +  + ]:       4800 :         for (sal_Int32 i = 0;  i < nEntries;  ++i)
     658                 :            :         {
     659 [ +  - ][ +  - ]:       2400 :             if (!pEntry[i].isEmpty() && lcl_FindEntry( pEntry[i], rAvailSvcs ))
         [ +  - ][ +  - ]
     660                 :       2400 :                 pRes[ nCnt++ ] = pEntry[i];
     661                 :            :         }
     662                 :            : 
     663         [ +  - ]:       2400 :         aRes.realloc( nCnt );
     664                 :       2400 :         return aRes;
     665                 :            :     }
     666                 :            : 
     667                 :       7200 :     Sequence< OUString > lcl_GetNewEntries(
     668                 :            :             const Sequence< OUString > &rLastFoundSvcs,
     669                 :            :             const Sequence< OUString > &rAvailSvcs )
     670                 :            :     {
     671                 :       7200 :         sal_Int32 nLen = rAvailSvcs.getLength();
     672                 :       7200 :         Sequence< OUString > aRes( nLen );
     673         [ +  - ]:       7200 :         OUString *pRes = aRes.getArray();
     674                 :       7200 :         sal_Int32 nCnt = 0;
     675                 :            : 
     676                 :       7200 :         const OUString *pEntry = rAvailSvcs.getConstArray();
     677         [ +  + ]:      14400 :         for (sal_Int32 i = 0;  i < nLen;  ++i)
     678                 :            :         {
     679 [ +  - ][ +  - ]:       7200 :             if (!pEntry[i].isEmpty() && !lcl_FindEntry( pEntry[i], rLastFoundSvcs ))
         [ +  + ][ +  + ]
     680                 :       4800 :                 pRes[ nCnt++ ] = pEntry[i];
     681                 :            :         }
     682                 :            : 
     683         [ +  - ]:       7200 :         aRes.realloc( nCnt );
     684                 :       7200 :         return aRes;
     685                 :            :     }
     686                 :            : 
     687                 :       7200 :     Sequence< OUString > lcl_MergeSeq(
     688                 :            :             const Sequence< OUString > &rCfgSvcs,
     689                 :            :             const Sequence< OUString > &rNewSvcs )
     690                 :            :     {
     691                 :       7200 :         Sequence< OUString > aRes( rCfgSvcs.getLength() + rNewSvcs.getLength() );
     692         [ +  - ]:       7200 :         OUString *pRes = aRes.getArray();
     693                 :       7200 :         sal_Int32 nCnt = 0;
     694                 :            : 
     695         [ +  + ]:      21600 :         for (sal_Int32 k = 0;  k < 2;  ++k)
     696                 :            :         {
     697                 :            :             // add previously configuerd service first and append
     698                 :            :             // new found services at the end
     699         [ +  + ]:      14400 :             const Sequence< OUString > &rSeq = k == 0 ? rCfgSvcs : rNewSvcs;
     700                 :            : 
     701                 :      14400 :             sal_Int32 nLen = rSeq.getLength();
     702                 :      14400 :             const OUString *pEntry = rSeq.getConstArray();
     703         [ +  + ]:      21600 :             for (sal_Int32 i = 0;  i < nLen;  ++i)
     704                 :            :             {
     705 [ +  - ][ +  - ]:       7200 :                 if (!pEntry[i].isEmpty() && !lcl_FindEntry( pEntry[i], aRes ))
         [ +  - ][ +  - ]
     706                 :       7200 :                     pRes[ nCnt++ ] = pEntry[i];
     707                 :            :             }
     708                 :            :         }
     709                 :            : 
     710         [ +  - ]:       7200 :         aRes.realloc( nCnt );
     711                 :       7200 :         return aRes;
     712                 :            :     }
     713                 :            : }
     714                 :            : 
     715                 :         48 : void LngSvcMgr::UpdateAll()
     716                 :            : {
     717                 :            :     using beans::PropertyValue;
     718                 :            :     using lang::Locale;
     719                 :            :     using uno::Sequence;
     720                 :            : 
     721                 :            :     typedef OUString OUstring_t;
     722                 :            :     typedef Sequence< OUString > Sequence_OUString_t;
     723                 :            :     typedef std::map< OUstring_t, Sequence_OUString_t > list_entry_map_t;
     724                 :            : 
     725         [ +  - ]:         48 :     SvtLinguConfig aCfg;
     726                 :            : 
     727                 :         48 :     const int nNumServices = 4;
     728                 :         48 :     const sal_Char * apServices[nNumServices]       =  { SN_SPELLCHECKER, SN_GRAMMARCHECKER, SN_HYPHENATOR, SN_THESAURUS };
     729                 :         48 :     const sal_Char * apCurLists[nNumServices]       =  { "ServiceManager/SpellCheckerList",       "ServiceManager/GrammarCheckerList",       "ServiceManager/HyphenatorList",       "ServiceManager/ThesaurusList" };
     730                 :         48 :     const sal_Char * apLastFoundLists[nNumServices] =  { "ServiceManager/LastFoundSpellCheckers", "ServiceManager/LastFoundGrammarCheckers", "ServiceManager/LastFoundHyphenators", "ServiceManager/LastFoundThesauri" };
     731                 :            : 
     732                 :            :     // usage of indices as above: 0 = spell checker, 1 = grammar checker, 2 = hyphenator, 3 = thesaurus
     733         [ +  - ]:         48 :     std::vector< list_entry_map_t > aLastFoundSvcs(nNumServices);
     734         [ +  - ]:         48 :     std::vector< list_entry_map_t > aCurSvcs(nNumServices);
     735                 :            : 
     736         [ +  + ]:        240 :     for (int k = 0;  k < nNumServices;  ++k)
     737                 :            :     {
     738                 :        192 :         OUString aService( ::rtl::OUString::createFromAscii( apServices[k] ) );
     739                 :        192 :         OUString aActiveList( ::rtl::OUString::createFromAscii( apCurLists[k] ) );
     740                 :        192 :         OUString aLastFoundList( ::rtl::OUString::createFromAscii( apLastFoundLists[k] ) );
     741                 :            :         sal_Int32 i;
     742                 :            : 
     743                 :            :         //
     744                 :            :         // remove configured but not available language/services entries
     745                 :            :         //
     746         [ +  - ]:        192 :         Sequence< OUString > aNodeNames( aCfg.GetNodeNames( aActiveList ) );   // list of configured locales
     747                 :        192 :         sal_Int32 nNodeNames = aNodeNames.getLength();
     748                 :        192 :         const OUString *pNodeName = aNodeNames.getConstArray();
     749         [ +  + ]:       2592 :         for (i = 0;  i < nNodeNames;  ++i)
     750                 :            :         {
     751 [ +  - ][ +  - ]:       2400 :             Locale aLocale( CreateLocale( MsLangId::convertIsoStringToLanguage(pNodeName[i]) ) );
     752         [ +  - ]:       2400 :             Sequence< OUString > aCfgSvcs( getConfiguredServices( aService, aLocale ));
     753         [ +  - ]:       2400 :             Sequence< OUString > aAvailSvcs( getAvailableServices( aService, aLocale ));
     754                 :            : 
     755 [ +  - ][ +  - ]:       2400 :             aCfgSvcs = lcl_RemoveMissingEntries( aCfgSvcs, aAvailSvcs );
                 [ +  - ]
     756                 :            : 
     757 [ +  - ][ +  - ]:       2400 :             aCurSvcs[k][ pNodeName[i] ] = aCfgSvcs;
     758 [ +  - ][ +  - ]:       2400 :         }
     759                 :            : 
     760                 :            :         //
     761                 :            :         // add new available language/service entries
     762                 :            :         // and
     763                 :            :         // set last found services to currently available ones
     764                 :            :         //
     765         [ +  - ]:        192 :         Sequence< Locale > aAvailLocales( getAvailableLocales(aService) );
     766                 :        192 :         sal_Int32 nAvailLocales = aAvailLocales.getLength();
     767                 :        192 :         const Locale *pAvailLocale = aAvailLocales.getConstArray();
     768         [ +  + ]:       7392 :         for (i = 0;  i < nAvailLocales;  ++i)
     769                 :            :         {
     770                 :            :             OUString aCfgLocaleStr( MsLangId::convertLanguageToIsoString(
     771 [ +  - ][ +  - ]:       7200 :                                         LocaleToLanguage( pAvailLocale[i] ) ) );
     772                 :            : 
     773         [ +  - ]:       7200 :             Sequence< OUString > aAvailSvcs( getAvailableServices( aService, pAvailLocale[i] ));
     774                 :            : 
     775 [ +  - ][ +  - ]:       7200 :             aLastFoundSvcs[k][ aCfgLocaleStr ] = aAvailSvcs;
     776                 :            : 
     777                 :            :             Sequence< OUString > aLastSvcs(
     778         [ +  - ]:       7200 :                     lcl_GetLastFoundSvcs( aCfg, aLastFoundList , pAvailLocale[i] ));
     779                 :            :             Sequence< OUString > aNewSvcs =
     780         [ +  - ]:       7200 :                     lcl_GetNewEntries( aLastSvcs, aAvailSvcs );
     781                 :            : 
     782 [ +  - ][ +  - ]:       7200 :             Sequence< OUString > aCfgSvcs( aCurSvcs[k][ aCfgLocaleStr ] );
     783                 :            : 
     784                 :            :             // merge services list (previously configured to be listed first).
     785 [ +  - ][ +  - ]:       7200 :             aCfgSvcs = lcl_MergeSeq( aCfgSvcs, aNewSvcs );
                 [ +  - ]
     786                 :            : 
     787 [ +  - ][ +  - ]:       7200 :             aCurSvcs[k][ aCfgLocaleStr ] = aCfgSvcs;
     788 [ +  - ][ +  - ]:       7200 :         }
         [ +  - ][ +  - ]
     789 [ +  - ][ +  - ]:        192 :     }
     790                 :            : 
     791                 :            :     //
     792                 :            :     // write new data back to configuration
     793                 :            :     //
     794         [ +  + ]:        240 :     for (int k = 0;  k < nNumServices;  ++k)
     795                 :            :     {
     796         [ +  + ]:        576 :         for (int i = 0;  i < 2;  ++i)
     797                 :            :         {
     798         [ +  + ]:        384 :             const sal_Char *pSubNodeName = (i == 0) ? apCurLists[k] : apLastFoundLists[k];
     799                 :        384 :             OUString aSubNodeName( ::rtl::OUString::createFromAscii(pSubNodeName) );
     800                 :            : 
     801         [ +  + ]:        384 :             list_entry_map_t &rCurMap = (i == 0) ? aCurSvcs[k] : aLastFoundSvcs[k];
     802                 :        384 :             list_entry_map_t::const_iterator aIt( rCurMap.begin() );
     803                 :        384 :             sal_Int32 nVals = static_cast< sal_Int32 >( rCurMap.size() );
     804         [ +  - ]:        384 :             Sequence< PropertyValue > aNewValues( nVals );
     805         [ +  - ]:        384 :             PropertyValue *pNewValue = aNewValues.getArray();
     806         [ +  + ]:      14784 :             while (aIt != rCurMap.end())
     807                 :            :             {
     808                 :      14400 :                 OUString aCfgEntryName( aSubNodeName );
     809                 :      14400 :                 aCfgEntryName += OUString::valueOf( (sal_Unicode) '/' );
     810                 :      14400 :                 aCfgEntryName += (*aIt).first;
     811                 :            : 
     812                 :      14400 :                 pNewValue->Name  = aCfgEntryName;
     813         [ +  - ]:      14400 :                 pNewValue->Value <<= (*aIt).second;
     814                 :      14400 :                 ++pNewValue;
     815                 :      14400 :                 ++aIt;
     816                 :      14400 :             }
     817                 :            :             OSL_ENSURE( pNewValue - aNewValues.getArray() == nVals,
     818                 :            :                     "possible mismatch of sequence size and property number" );
     819                 :            : 
     820                 :            :             {
     821                 :            :                 // add new or replace existing entries.
     822 [ +  - ][ +  - ]:        384 :                 sal_Bool bRes = aCfg.ReplaceSetProperties( aSubNodeName, aNewValues );
                 [ +  - ]
     823                 :            :                 if (!bRes)
     824                 :            :                 {
     825                 :            : #if OSL_DEBUG_LEVEL > 1
     826                 :            :                     OSL_FAIL( "failed to set new configuration values" );
     827                 :            : #endif
     828                 :            :                 }
     829                 :            :             }
     830         [ +  - ]:        384 :         }
     831         [ +  - ]:         48 :     }
     832                 :            : 
     833                 :            :     //The new settings in the configuration get applied ! because we are
     834                 :            :     //listening to the configuration for changes of the relevant ! properties
     835                 :            :     //and Notify applies the new settings.
     836                 :         48 : }
     837                 :            : 
     838                 :        192 : void LngSvcMgr::Notify( const uno::Sequence< OUString > &rPropertyNames )
     839                 :            : {
     840                 :        192 :     const OUString aSpellCheckerList( "ServiceManager/SpellCheckerList" );
     841                 :        192 :     const OUString aGrammarCheckerList( "ServiceManager/GrammarCheckerList" );
     842                 :        192 :     const OUString aHyphenatorList( "ServiceManager/HyphenatorList" );
     843                 :        192 :     const OUString aThesaurusList( "ServiceManager/ThesaurusList" );
     844                 :            : 
     845         [ +  - ]:        192 :     const uno::Sequence< OUString > aSpellCheckerListEntries( GetNodeNames( aSpellCheckerList ) );
     846         [ +  - ]:        192 :     const uno::Sequence< OUString > aGrammarCheckerListEntries( GetNodeNames( aGrammarCheckerList ) );
     847         [ +  - ]:        192 :     const uno::Sequence< OUString > aHyphenatorListEntries( GetNodeNames( aHyphenatorList ) );
     848         [ +  - ]:        192 :     const uno::Sequence< OUString > aThesaurusListEntries( GetNodeNames( aThesaurusList ) );
     849                 :            : 
     850         [ +  - ]:        192 :     uno::Sequence< uno::Any > aValues;
     851         [ +  - ]:        192 :     uno::Sequence< OUString > aNames( 1 );
     852         [ +  - ]:        192 :     OUString *pNames = aNames.getArray();
     853                 :            : 
     854                 :        192 :     sal_Int32 nLen = rPropertyNames.getLength();
     855                 :        192 :     const OUString *pPropertyNames = rPropertyNames.getConstArray();
     856         [ +  + ]:       7392 :     for (sal_Int32 i = 0;  i < nLen;  ++i)
     857                 :            :     {
     858                 :            :         // property names look like
     859                 :            :         // "ServiceManager/ThesaurusList/de-CH"
     860                 :            : 
     861                 :       7200 :         const OUString &rName = pPropertyNames[i];
     862                 :            :         sal_Int32 nKeyStart;
     863                 :       7200 :         nKeyStart = rName.lastIndexOf( '/' );
     864                 :       7200 :         OUString aKeyText;
     865         [ +  - ]:       7200 :         if (nKeyStart != -1)
     866                 :       7200 :             aKeyText = rName.copy( nKeyStart + 1 );
     867                 :            :         DBG_ASSERT( !aKeyText.isEmpty(), "unexpected key (lang::Locale) string" );
     868         [ +  + ]:       7200 :         if (0 == rName.compareTo( aSpellCheckerList, aSpellCheckerList.getLength() ))
     869                 :            :         {
     870                 :            :             // delete old cached data, needs to be acquired new on demand
     871 [ +  + ][ +  - ]:       2064 :             delete pAvailSpellSvcs;     pAvailSpellSvcs = 0;
     872                 :            : 
     873                 :       2064 :             OUString aNode( aSpellCheckerList );
     874 [ +  - ][ +  - ]:       2064 :             if (lcl_SeqHasString( aSpellCheckerListEntries, aKeyText ))
     875                 :            :             {
     876                 :       2064 :                 OUString aPropName( aNode );
     877                 :       2064 :                 aPropName += OUString::valueOf( (sal_Unicode) '/' );
     878                 :       2064 :                 aPropName += aKeyText;
     879                 :       2064 :                 pNames[0] = aPropName;
     880 [ +  - ][ +  - ]:       2064 :                 aValues = /*aCfg.*/GetProperties( aNames );
                 [ +  - ]
     881         [ +  - ]:       2064 :                 uno::Sequence< OUString > aSvcImplNames;
     882         [ +  - ]:       2064 :                 if (aValues.getLength())
     883 [ +  - ][ +  - ]:       2064 :                     aSvcImplNames = GetLangSvcList( aValues.getConstArray()[0] );
                 [ +  - ]
     884                 :            : 
     885                 :       2064 :                 LanguageType nLang = LANGUAGE_NONE;
     886         [ +  - ]:       2064 :                 if (!aKeyText.isEmpty())
     887         [ +  - ]:       2064 :                     nLang = MsLangId::convertIsoStringToLanguage( aKeyText );
     888                 :            : 
     889         [ +  - ]:       2064 :                 GetSpellCheckerDsp_Impl( sal_False );     // don't set service list, it will be done below
     890 [ +  - ][ +  - ]:       2064 :                 pSpellDsp->SetServiceList( CreateLocale(nLang), aSvcImplNames );
                 [ +  - ]
     891                 :       2064 :             }
     892                 :            :         }
     893         [ +  + ]:       5136 :         else if (0 == rName.compareTo( aGrammarCheckerList, aGrammarCheckerList.getLength() ))
     894                 :            :         {
     895                 :            :             // delete old cached data, needs to be acquired new on demand
     896 [ +  + ][ +  - ]:        768 :             delete pAvailGrammarSvcs;      pAvailGrammarSvcs = 0;
     897                 :            : 
     898                 :        768 :             OUString aNode( aGrammarCheckerList );
     899 [ +  - ][ +  - ]:        768 :             if (lcl_SeqHasString( aGrammarCheckerListEntries, aKeyText ))
     900                 :            :             {
     901                 :        768 :                 OUString aPropName( aNode );
     902                 :        768 :                 aPropName += OUString::valueOf( (sal_Unicode) '/' );
     903                 :        768 :                 aPropName += aKeyText;
     904                 :        768 :                 pNames[0] = aPropName;
     905 [ +  - ][ +  - ]:        768 :                 aValues = /*aCfg.*/GetProperties( aNames );
                 [ +  - ]
     906         [ +  - ]:        768 :                 uno::Sequence< OUString > aSvcImplNames;
     907         [ +  - ]:        768 :                 if (aValues.getLength())
     908 [ +  - ][ +  - ]:        768 :                     aSvcImplNames = GetLangSvc( aValues.getConstArray()[0] );
                 [ +  - ]
     909                 :            : 
     910                 :        768 :                 LanguageType nLang = LANGUAGE_NONE;
     911         [ +  - ]:        768 :                 if (!aKeyText.isEmpty())
     912         [ +  - ]:        768 :                     nLang = MsLangId::convertIsoStringToLanguage( aKeyText );
     913                 :            : 
     914 [ +  - ][ +  - ]:        768 :                 if (SvtLinguConfig().HasGrammarChecker())
         [ +  - ][ +  - ]
     915                 :            :                 {
     916         [ +  - ]:        768 :                     GetGrammarCheckerDsp_Impl( sal_False );   // don't set service list, it will be done below
     917 [ +  - ][ +  - ]:        768 :                     pGrammarDsp->SetServiceList( CreateLocale(nLang), aSvcImplNames );
     918         [ +  - ]:        768 :                 }
     919                 :        768 :             }
     920                 :            :         }
     921         [ +  + ]:       4368 :         else if (0 == rName.compareTo( aHyphenatorList, aHyphenatorList.getLength() ))
     922                 :            :         {
     923                 :            :             // delete old cached data, needs to be acquired new on demand
     924 [ +  + ][ +  - ]:       2208 :             delete pAvailHyphSvcs;      pAvailHyphSvcs = 0;
     925                 :            : 
     926                 :       2208 :             OUString aNode( aHyphenatorList );
     927 [ +  - ][ +  - ]:       2208 :             if (lcl_SeqHasString( aHyphenatorListEntries, aKeyText ))
     928                 :            :             {
     929                 :       2208 :                 OUString aPropName( aNode );
     930                 :       2208 :                 aPropName += OUString::valueOf( (sal_Unicode) '/' );
     931                 :       2208 :                 aPropName += aKeyText;
     932                 :       2208 :                 pNames[0] = aPropName;
     933 [ +  - ][ +  - ]:       2208 :                 aValues = /*aCfg.*/GetProperties( aNames );
                 [ +  - ]
     934         [ +  - ]:       2208 :                 uno::Sequence< OUString > aSvcImplNames;
     935         [ +  - ]:       2208 :                 if (aValues.getLength())
     936 [ +  - ][ +  - ]:       2208 :                     aSvcImplNames = GetLangSvc( aValues.getConstArray()[0] );
                 [ +  - ]
     937                 :            : 
     938                 :       2208 :                 LanguageType nLang = LANGUAGE_NONE;
     939         [ +  - ]:       2208 :                 if (!aKeyText.isEmpty())
     940         [ +  - ]:       2208 :                     nLang = MsLangId::convertIsoStringToLanguage( aKeyText );
     941                 :            : 
     942         [ +  - ]:       2208 :                 GetHyphenatorDsp_Impl( sal_False );   // don't set service list, it will be done below
     943 [ +  - ][ +  - ]:       2208 :                 pHyphDsp->SetServiceList( CreateLocale(nLang), aSvcImplNames );
                 [ +  - ]
     944                 :       2208 :             }
     945                 :            :         }
     946         [ +  - ]:       2160 :         else if (0 == rName.compareTo( aThesaurusList, aThesaurusList.getLength() ))
     947                 :            :         {
     948                 :            :             // delete old cached data, needs to be acquired new on demand
     949 [ +  + ][ +  - ]:       2160 :             delete pAvailThesSvcs;      pAvailThesSvcs = 0;
     950                 :            : 
     951                 :       2160 :             OUString aNode( aThesaurusList );
     952 [ +  - ][ +  - ]:       2160 :             if (lcl_SeqHasString( aThesaurusListEntries, aKeyText ))
     953                 :            :             {
     954                 :       2160 :                 OUString aPropName( aNode );
     955                 :       2160 :                 aPropName += OUString::valueOf( (sal_Unicode) '/' );
     956                 :       2160 :                 aPropName += aKeyText;
     957                 :       2160 :                 pNames[0] = aPropName;
     958 [ +  - ][ +  - ]:       2160 :                 aValues = /*aCfg.*/GetProperties( aNames );
                 [ +  - ]
     959         [ +  - ]:       2160 :                 uno::Sequence< OUString > aSvcImplNames;
     960         [ +  - ]:       2160 :                 if (aValues.getLength())
     961 [ +  - ][ +  - ]:       2160 :                     aSvcImplNames = GetLangSvcList( aValues.getConstArray()[0] );
                 [ +  - ]
     962                 :            : 
     963                 :       2160 :                 LanguageType nLang = LANGUAGE_NONE;
     964         [ +  - ]:       2160 :                 if (!aKeyText.isEmpty())
     965         [ +  - ]:       2160 :                     nLang = MsLangId::convertIsoStringToLanguage( aKeyText );
     966                 :            : 
     967         [ +  - ]:       2160 :                 GetThesaurusDsp_Impl( sal_False );  // don't set service list, it will be done below
     968 [ +  - ][ +  - ]:       2160 :                 pThesDsp->SetServiceList( CreateLocale(nLang), aSvcImplNames );
                 [ +  - ]
     969                 :       2160 :             }
     970                 :            :         }
     971                 :            :         else
     972                 :            :         {
     973                 :            :             DBG_ASSERT( 0, "nofified for unexpected property" );
     974                 :            :         }
     975 [ +  - ][ +  - ]:       7392 :     }
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     976                 :        192 : }
     977                 :            : 
     978                 :            : 
     979                 :          0 : void LngSvcMgr::Commit()
     980                 :            : {
     981                 :            :     // everything necessary should have already been done by 'SaveCfgSvcs'
     982                 :            :     // called from within 'setConfiguredServices'.
     983                 :            :     // Also this class usually exits only when the Office i sbeing shutdown.
     984                 :          0 : }
     985                 :            : 
     986                 :            : 
     987                 :         42 : void LngSvcMgr::GetListenerHelper_Impl()
     988                 :            : {
     989         [ +  - ]:         42 :     if (!pListenerHelper)
     990                 :            :     {
     991         [ +  - ]:         42 :         pListenerHelper = new LngSvcMgrListenerHelper( *this, linguistic::GetDictionaryList() );
     992         [ +  - ]:         42 :         xListenerHelper = (linguistic2::XLinguServiceEventListener *) pListenerHelper;
     993                 :            :     }
     994                 :         42 : }
     995                 :            : 
     996                 :            : 
     997                 :       2064 : void LngSvcMgr::GetSpellCheckerDsp_Impl( sal_Bool bSetSvcList )
     998                 :            : {
     999         [ +  + ]:       2064 :     if (!pSpellDsp)
    1000                 :            :     {
    1001         [ +  - ]:         46 :         pSpellDsp   = new SpellCheckerDispatcher( *this );
    1002         [ +  - ]:         46 :         xSpellDsp   = pSpellDsp;
    1003         [ -  + ]:         46 :         if (bSetSvcList)
    1004                 :          0 :             SetCfgServiceLists( *pSpellDsp );
    1005                 :            :     }
    1006                 :       2064 : }
    1007                 :            : 
    1008                 :            : 
    1009                 :        768 : void LngSvcMgr::GetGrammarCheckerDsp_Impl( sal_Bool bSetSvcList  )
    1010                 :            : {
    1011 [ +  + ][ +  - ]:        768 :     if (!pGrammarDsp && SvtLinguConfig().HasGrammarChecker())
         [ +  - ][ +  - ]
                 [ +  + ]
           [ +  +  #  # ]
    1012                 :            :     {
    1013                 :            :         //! since the grammar checking iterator needs to be a one instance service
    1014                 :            :         //! we need to create it the correct way!
    1015                 :         46 :         uno::Reference< linguistic2::XProofreadingIterator > xGCI;
    1016                 :            :         try
    1017                 :            :         {
    1018                 :            :             uno::Reference< lang::XMultiServiceFactory > xMgr(
    1019 [ +  - ][ +  - ]:         46 :                     comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
    1020                 :            :             xGCI = uno::Reference< linguistic2::XProofreadingIterator >(
    1021 [ +  - ][ +  - ]:         46 :                     xMgr->createInstance( SN_GRAMMARCHECKINGITERATOR ), uno::UNO_QUERY_THROW );
         [ +  - ][ #  # ]
                 [ +  - ]
    1022                 :            :         }
    1023         [ #  # ]:          0 :         catch (uno::Exception &)
    1024                 :            :         {
    1025                 :            :         }
    1026                 :            :         DBG_ASSERT( xGCI.is(), "instantiating grammar checking iterator failed" );
    1027                 :            : 
    1028         [ +  - ]:         46 :         if (xGCI.is())
    1029                 :            :         {
    1030 [ +  - ][ -  + ]:         46 :             pGrammarDsp    = dynamic_cast< GrammarCheckingIterator * >(xGCI.get());
    1031         [ +  - ]:         46 :             xGrammarDsp    = xGCI;
    1032                 :            :             DBG_ASSERT( pGrammarDsp, "failed to get implementation" );
    1033         [ -  + ]:         46 :             if (bSetSvcList)
    1034         [ #  # ]:          0 :                 SetCfgServiceLists( *pGrammarDsp );
    1035                 :         46 :         }
    1036                 :            :     }
    1037                 :        768 : }
    1038                 :            : 
    1039                 :            : 
    1040                 :       2208 : void LngSvcMgr::GetHyphenatorDsp_Impl( sal_Bool bSetSvcList  )
    1041                 :            : {
    1042         [ +  + ]:       2208 :     if (!pHyphDsp)
    1043                 :            :     {
    1044         [ +  - ]:         46 :         pHyphDsp    = new HyphenatorDispatcher( *this );
    1045         [ +  - ]:         46 :         xHyphDsp    = pHyphDsp;
    1046         [ -  + ]:         46 :         if (bSetSvcList)
    1047                 :          0 :             SetCfgServiceLists( *pHyphDsp );
    1048                 :            :     }
    1049                 :       2208 : }
    1050                 :            : 
    1051                 :            : 
    1052                 :       2160 : void LngSvcMgr::GetThesaurusDsp_Impl( sal_Bool bSetSvcList  )
    1053                 :            : {
    1054         [ +  + ]:       2160 :     if (!pThesDsp)
    1055                 :            :     {
    1056         [ +  - ]:         46 :         pThesDsp    = new ThesaurusDispatcher;
    1057         [ +  - ]:         46 :         xThesDsp    = pThesDsp;
    1058         [ -  + ]:         46 :         if (bSetSvcList)
    1059                 :          0 :             SetCfgServiceLists( *pThesDsp );
    1060                 :            :     }
    1061                 :       2160 : }
    1062                 :            : 
    1063                 :            : 
    1064                 :       2800 : void LngSvcMgr::GetAvailableSpellSvcs_Impl()
    1065                 :            : {
    1066         [ +  + ]:       2800 :     if (!pAvailSpellSvcs)
    1067                 :            :     {
    1068 [ +  - ][ +  - ]:         48 :         pAvailSpellSvcs = new SvcInfoArray;
    1069                 :            : 
    1070         [ +  - ]:         48 :         uno::Reference< lang::XMultiServiceFactory >  xFac( comphelper::getProcessServiceFactory() );
    1071         [ +  - ]:         48 :         if (xFac.is())
    1072                 :            :         {
    1073         [ +  - ]:         48 :             uno::Reference< container::XContentEnumerationAccess > xEnumAccess( xFac, uno::UNO_QUERY );
    1074                 :         48 :             uno::Reference< container::XEnumeration > xEnum;
    1075         [ +  - ]:         48 :             if (xEnumAccess.is())
    1076 [ +  - ][ +  - ]:         48 :                 xEnum = xEnumAccess->createContentEnumeration( SN_SPELLCHECKER );
                 [ +  - ]
    1077                 :            : 
    1078         [ +  - ]:         48 :             if (xEnum.is())
    1079                 :            :             {
    1080 [ +  - ][ +  - ]:         96 :                 while (xEnum->hasMoreElements())
                 [ +  + ]
    1081                 :            :                 {
    1082 [ +  - ][ +  - ]:         48 :                     uno::Any aCurrent = xEnum->nextElement();
    1083                 :         48 :                     uno::Reference< lang::XSingleComponentFactory > xCompFactory;
    1084                 :         48 :                     uno::Reference< lang::XSingleServiceFactory > xFactory;
    1085                 :            : 
    1086                 :         48 :                     uno::Reference< linguistic2::XSpellChecker > xSvc;
    1087 [ -  + ][ #  # ]:         48 :                     if ( cppu::extractInterface( xCompFactory, aCurrent ) || ::cppu::extractInterface( xFactory, aCurrent ) )
         [ #  # ][ +  - ]
                 [ +  - ]
    1088                 :            :                     {
    1089                 :            :                         try
    1090                 :            :                         {
    1091                 :         48 :                             uno::Reference < uno::XComponentContext > xContext;
    1092         [ +  - ]:         48 :                             uno::Reference< beans::XPropertySet > xProps( xFac, uno::UNO_QUERY );
    1093                 :            : 
    1094 [ +  - ][ +  - ]:         48 :                             xProps->getPropertyValue( "DefaultContext" ) >>= xContext;
                 [ +  - ]
    1095 [ +  - ][ +  - ]:         48 :                             xSvc = uno::Reference< linguistic2::XSpellChecker >( ( xCompFactory.is() ? xCompFactory->createInstanceWithContext( xContext ) : xFactory->createInstance() ), uno::UNO_QUERY );
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ #  # ][ +  - ]
    1096                 :            :                         }
    1097         [ #  # ]:          0 :                         catch (const uno::Exception &)
    1098                 :            :                         {
    1099                 :            :                             DBG_ASSERT( 0, "createInstance failed" );
    1100                 :            :                         }
    1101                 :            :                     }
    1102                 :            : 
    1103         [ +  - ]:         48 :                     if (xSvc.is())
    1104                 :            :                     {
    1105                 :         48 :                         OUString            aImplName;
    1106         [ +  - ]:         48 :                         uno::Sequence< sal_Int16 >    aLanguages;
    1107         [ +  - ]:         48 :                         uno::Reference< XServiceInfo > xInfo( xSvc, uno::UNO_QUERY );
    1108         [ +  - ]:         48 :                         if (xInfo.is())
    1109 [ +  - ][ +  - ]:         48 :                             aImplName = xInfo->getImplementationName();
    1110                 :            :                         DBG_ASSERT( !aImplName.isEmpty(),
    1111                 :            :                                 "empty implementation name" );
    1112         [ +  - ]:         48 :                         uno::Reference< linguistic2::XSupportedLocales > xSuppLoc( xSvc, uno::UNO_QUERY );
    1113                 :            :                         DBG_ASSERT( xSuppLoc.is(), "interfaces not supported" );
    1114         [ +  - ]:         48 :                         if (xSuppLoc.is()) {
    1115 [ +  - ][ +  - ]:         48 :                             uno::Sequence<lang::Locale> aLocaleSequence(xSuppLoc->getLocales());
    1116 [ +  - ][ +  - ]:         48 :                             aLanguages = LocaleSeqToLangSeq( aLocaleSequence );
         [ +  - ][ +  - ]
    1117                 :            :                         }
    1118                 :            : 
    1119 [ +  - ][ +  - ]:         48 :                         pAvailSpellSvcs->push_back( new SvcInfo( aImplName, aLanguages ) );
         [ +  - ][ +  - ]
    1120                 :            :                     }
    1121                 :         48 :                 }
    1122                 :         48 :             }
    1123                 :         48 :         }
    1124                 :            :     }
    1125                 :       2800 : }
    1126                 :            : 
    1127                 :            : 
    1128                 :       1072 : void LngSvcMgr::GetAvailableGrammarSvcs_Impl()
    1129                 :            : {
    1130         [ +  + ]:       1072 :     if (!pAvailGrammarSvcs)
    1131                 :            :     {
    1132 [ +  - ][ +  - ]:         48 :         pAvailGrammarSvcs = new SvcInfoArray;
    1133                 :            : 
    1134         [ +  - ]:         48 :         uno::Reference< lang::XMultiServiceFactory >  xFac( comphelper::getProcessServiceFactory() );
    1135         [ +  - ]:         48 :         if (xFac.is())
    1136                 :            :         {
    1137         [ +  - ]:         48 :             uno::Reference< container::XContentEnumerationAccess > xEnumAccess( xFac, uno::UNO_QUERY );
    1138                 :         48 :             uno::Reference< container::XEnumeration > xEnum;
    1139         [ +  - ]:         48 :             if (xEnumAccess.is())
    1140 [ +  - ][ +  - ]:         48 :                 xEnum = xEnumAccess->createContentEnumeration( SN_GRAMMARCHECKER );
                 [ +  - ]
    1141                 :            : 
    1142         [ +  - ]:         48 :             if (xEnum.is())
    1143                 :            :             {
    1144 [ +  - ][ +  - ]:         96 :                 while (xEnum->hasMoreElements())
                 [ +  + ]
    1145                 :            :                 {
    1146 [ +  - ][ +  - ]:         48 :                     uno::Any aCurrent = xEnum->nextElement();
    1147                 :         48 :                     uno::Reference< lang::XSingleComponentFactory > xCompFactory;
    1148                 :         48 :                     uno::Reference< lang::XSingleServiceFactory > xFactory;
    1149                 :            : 
    1150                 :         48 :                     uno::Reference< linguistic2::XProofreader > xSvc;
    1151 [ -  + ][ #  # ]:         48 :                     if ( cppu::extractInterface( xCompFactory, aCurrent ) || ::cppu::extractInterface( xFactory, aCurrent ) )
         [ #  # ][ +  - ]
                 [ +  - ]
    1152                 :            :                     {
    1153                 :            :                         try
    1154                 :            :                         {
    1155                 :         48 :                             uno::Reference < uno::XComponentContext > xContext;
    1156         [ +  - ]:         48 :                             uno::Reference< beans::XPropertySet > xProps( xFac, uno::UNO_QUERY );
    1157                 :            : 
    1158 [ +  - ][ +  - ]:         48 :                             xProps->getPropertyValue( "DefaultContext" ) >>= xContext;
                 [ +  - ]
    1159 [ +  - ][ +  - ]:         48 :                             xSvc = uno::Reference< linguistic2::XProofreader >( ( xCompFactory.is() ? xCompFactory->createInstanceWithContext( xContext ) : xFactory->createInstance() ), uno::UNO_QUERY );
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ #  # ][ +  - ]
    1160                 :            :                         }
    1161         [ #  # ]:          0 :                         catch (const uno::Exception &)
    1162                 :            :                         {
    1163                 :            :                             DBG_ASSERT( 0, "createInstance failed" );
    1164                 :            :                         }
    1165                 :            :                     }
    1166                 :            : 
    1167         [ +  - ]:         48 :                     if (xSvc.is())
    1168                 :            :                     {
    1169                 :         48 :                         OUString            aImplName;
    1170         [ +  - ]:         48 :                         uno::Sequence< sal_Int16 >   aLanguages;
    1171         [ +  - ]:         48 :                         uno::Reference< XServiceInfo > xInfo( xSvc, uno::UNO_QUERY );
    1172         [ +  - ]:         48 :                         if (xInfo.is())
    1173 [ +  - ][ +  - ]:         48 :                             aImplName = xInfo->getImplementationName();
    1174                 :            :                         DBG_ASSERT( !aImplName.isEmpty(),
    1175                 :            :                                 "empty implementation name" );
    1176         [ +  - ]:         48 :                         uno::Reference< linguistic2::XSupportedLocales > xSuppLoc( xSvc, uno::UNO_QUERY );
    1177                 :            :                         DBG_ASSERT( xSuppLoc.is(), "interfaces not supported" );
    1178         [ +  - ]:         48 :                         if (xSuppLoc.is()) {
    1179 [ +  - ][ +  - ]:         48 :                             uno::Sequence<lang::Locale> aLocaleSequence(xSuppLoc->getLocales());
    1180 [ +  - ][ +  - ]:         48 :                             aLanguages = LocaleSeqToLangSeq( aLocaleSequence );
         [ +  - ][ +  - ]
    1181                 :            :                         }
    1182                 :            : 
    1183 [ +  - ][ +  - ]:         48 :                         pAvailGrammarSvcs->push_back( new SvcInfo( aImplName, aLanguages ) );
         [ +  - ][ +  - ]
    1184                 :            :                     }
    1185                 :         48 :                 }
    1186                 :         48 :             }
    1187                 :         48 :         }
    1188                 :            :     }
    1189                 :       1072 : }
    1190                 :            : 
    1191                 :            : 
    1192                 :       2992 : void LngSvcMgr::GetAvailableHyphSvcs_Impl()
    1193                 :            : {
    1194         [ +  + ]:       2992 :     if (!pAvailHyphSvcs)
    1195                 :            :     {
    1196 [ +  - ][ +  - ]:         48 :         pAvailHyphSvcs = new SvcInfoArray;
    1197         [ +  - ]:         48 :         uno::Reference< lang::XMultiServiceFactory >  xFac( comphelper::getProcessServiceFactory() );
    1198         [ +  - ]:         48 :         if (xFac.is())
    1199                 :            :         {
    1200         [ +  - ]:         48 :             uno::Reference< container::XContentEnumerationAccess > xEnumAccess( xFac, uno::UNO_QUERY );
    1201                 :         48 :             uno::Reference< container::XEnumeration > xEnum;
    1202         [ +  - ]:         48 :             if (xEnumAccess.is())
    1203 [ +  - ][ +  - ]:         48 :                 xEnum = xEnumAccess->createContentEnumeration( SN_HYPHENATOR );
                 [ +  - ]
    1204                 :            : 
    1205         [ +  - ]:         48 :             if (xEnum.is())
    1206                 :            :             {
    1207 [ +  - ][ +  - ]:         96 :                 while (xEnum->hasMoreElements())
                 [ +  + ]
    1208                 :            :                 {
    1209 [ +  - ][ +  - ]:         48 :                     uno::Any aCurrent = xEnum->nextElement();
    1210                 :         48 :                     uno::Reference< lang::XSingleComponentFactory > xCompFactory;
    1211                 :         48 :                     uno::Reference< lang::XSingleServiceFactory > xFactory;
    1212                 :            : 
    1213                 :         48 :                     uno::Reference< linguistic2::XHyphenator > xSvc;
    1214 [ -  + ][ #  # ]:         48 :                     if ( cppu::extractInterface( xCompFactory, aCurrent ) || ::cppu::extractInterface( xFactory, aCurrent ) )
         [ #  # ][ +  - ]
                 [ +  - ]
    1215                 :            :                     {
    1216                 :            :                         try
    1217                 :            :                         {
    1218                 :         48 :                             uno::Reference < uno::XComponentContext > xContext;
    1219         [ +  - ]:         48 :                             uno::Reference< beans::XPropertySet > xProps( xFac, uno::UNO_QUERY );
    1220                 :            : 
    1221 [ +  - ][ +  - ]:         48 :                             xProps->getPropertyValue( "DefaultContext" ) >>= xContext;
                 [ +  - ]
    1222 [ +  - ][ +  - ]:         48 :                             xSvc = uno::Reference< linguistic2::XHyphenator >( ( xCompFactory.is() ? xCompFactory->createInstanceWithContext( xContext ) : xFactory->createInstance() ), uno::UNO_QUERY );
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ #  # ][ +  - ]
    1223                 :            : 
    1224                 :            :                         }
    1225         [ #  # ]:          0 :                         catch (const uno::Exception &)
    1226                 :            :                         {
    1227                 :            :                             DBG_ASSERT( 0, "createInstance failed" );
    1228                 :            :                         }
    1229                 :            :                     }
    1230                 :            : 
    1231         [ +  - ]:         48 :                     if (xSvc.is())
    1232                 :            :                     {
    1233                 :         48 :                         OUString            aImplName;
    1234         [ +  - ]:         48 :                         uno::Sequence< sal_Int16 >    aLanguages;
    1235         [ +  - ]:         48 :                         uno::Reference< XServiceInfo > xInfo( xSvc, uno::UNO_QUERY );
    1236         [ +  - ]:         48 :                         if (xInfo.is())
    1237 [ +  - ][ +  - ]:         48 :                             aImplName = xInfo->getImplementationName();
    1238                 :            :                         DBG_ASSERT( !aImplName.isEmpty(),
    1239                 :            :                                 "empty implementation name" );
    1240         [ +  - ]:         48 :                         uno::Reference< linguistic2::XSupportedLocales > xSuppLoc( xSvc, uno::UNO_QUERY );
    1241                 :            :                         DBG_ASSERT( xSuppLoc.is(), "interfaces not supported" );
    1242         [ +  - ]:         48 :                         if (xSuppLoc.is()) {
    1243 [ +  - ][ +  - ]:         48 :                             uno::Sequence<lang::Locale> aLocaleSequence(xSuppLoc->getLocales());
    1244 [ +  - ][ +  - ]:         48 :                             aLanguages = LocaleSeqToLangSeq( aLocaleSequence );
         [ +  - ][ +  - ]
    1245                 :            :                         }
    1246                 :            : 
    1247 [ +  - ][ +  - ]:         48 :                         pAvailHyphSvcs->push_back( new SvcInfo( aImplName, aLanguages ) );
         [ +  - ][ +  - ]
    1248                 :            :                     }
    1249                 :         48 :                 }
    1250                 :         48 :             }
    1251                 :         48 :         }
    1252                 :            :     }
    1253                 :       2992 : }
    1254                 :            : 
    1255                 :            : 
    1256                 :       2928 : void LngSvcMgr::GetAvailableThesSvcs_Impl()
    1257                 :            : {
    1258         [ +  + ]:       2928 :     if (!pAvailThesSvcs)
    1259                 :            :     {
    1260 [ +  - ][ +  - ]:         48 :         pAvailThesSvcs = new SvcInfoArray;
    1261                 :            : 
    1262         [ +  - ]:         48 :         uno::Reference< lang::XMultiServiceFactory >  xFac( comphelper::getProcessServiceFactory() );
    1263         [ +  - ]:         48 :         if (xFac.is())
    1264                 :            :         {
    1265         [ +  - ]:         48 :             uno::Reference< container::XContentEnumerationAccess > xEnumAccess( xFac, uno::UNO_QUERY );
    1266                 :         48 :             uno::Reference< container::XEnumeration > xEnum;
    1267         [ +  - ]:         48 :             if (xEnumAccess.is())
    1268 [ +  - ][ +  - ]:         48 :                 xEnum = xEnumAccess->createContentEnumeration( SN_THESAURUS );
                 [ +  - ]
    1269                 :            : 
    1270         [ +  - ]:         48 :             if (xEnum.is())
    1271                 :            :             {
    1272 [ +  - ][ +  - ]:         96 :                 while (xEnum->hasMoreElements())
                 [ +  + ]
    1273                 :            :                 {
    1274 [ +  - ][ +  - ]:         48 :                     uno::Any aCurrent = xEnum->nextElement();
    1275                 :            : 
    1276                 :         48 :                     uno::Reference< lang::XSingleComponentFactory > xCompFactory;
    1277                 :         48 :                     uno::Reference< lang::XSingleServiceFactory > xFactory;
    1278                 :            : 
    1279                 :         48 :                     uno::Reference< linguistic2::XThesaurus > xSvc;
    1280 [ -  + ][ #  # ]:         48 :                     if ( cppu::extractInterface( xCompFactory, aCurrent ) || ::cppu::extractInterface( xFactory, aCurrent ) )
         [ #  # ][ +  - ]
                 [ +  - ]
    1281                 :            :                     {
    1282                 :            :                         try
    1283                 :            :                         {
    1284                 :         48 :                             uno::Reference < uno::XComponentContext > xContext;
    1285         [ +  - ]:         48 :                             uno::Reference< beans::XPropertySet > xProps( xFac, uno::UNO_QUERY );
    1286                 :            : 
    1287 [ +  - ][ +  - ]:         48 :                             xProps->getPropertyValue( "DefaultContext" ) >>= xContext;
                 [ +  - ]
    1288 [ +  - ][ +  - ]:         48 :                             xSvc = uno::Reference< linguistic2::XThesaurus >( ( xCompFactory.is() ? xCompFactory->createInstanceWithContext( xContext ) : xFactory->createInstance() ), uno::UNO_QUERY );
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ #  # ][ +  - ]
    1289                 :            :                         }
    1290         [ #  # ]:          0 :                         catch (const uno::Exception &)
    1291                 :            :                         {
    1292                 :            :                             DBG_ASSERT( 0, "createInstance failed" );
    1293                 :            :                         }
    1294                 :            :                     }
    1295                 :            : 
    1296         [ +  - ]:         48 :                     if (xSvc.is())
    1297                 :            :                     {
    1298                 :         48 :                         OUString            aImplName;
    1299         [ +  - ]:         48 :                         uno::Sequence< sal_Int16 >    aLanguages;
    1300         [ +  - ]:         48 :                         uno::Reference< XServiceInfo > xInfo( xSvc, uno::UNO_QUERY );
    1301         [ +  - ]:         48 :                         if (xInfo.is())
    1302 [ +  - ][ +  - ]:         48 :                             aImplName = xInfo->getImplementationName();
    1303                 :            :                         DBG_ASSERT( !aImplName.isEmpty(),
    1304                 :            :                                 "empty implementation name" );
    1305         [ +  - ]:         48 :                         uno::Reference< linguistic2::XSupportedLocales > xSuppLoc( xSvc, uno::UNO_QUERY );
    1306                 :            :                         DBG_ASSERT( xSuppLoc.is(), "interfaces not supported" );
    1307         [ +  - ]:         48 :                         if (xSuppLoc.is()) {
    1308 [ +  - ][ +  - ]:         48 :                             uno::Sequence<lang::Locale> aLocaleSequence(xSuppLoc->getLocales());
    1309 [ +  - ][ +  - ]:         48 :                             aLanguages = LocaleSeqToLangSeq( aLocaleSequence );
         [ +  - ][ +  - ]
    1310                 :            :                         }
    1311                 :            : 
    1312 [ +  - ][ +  - ]:         48 :                         pAvailThesSvcs->push_back( new SvcInfo( aImplName, aLanguages ) );
         [ +  - ][ +  - ]
    1313                 :            :                     }
    1314                 :         48 :                 }
    1315                 :         48 :             }
    1316                 :         48 :         }
    1317                 :            :     }
    1318                 :       2928 : }
    1319                 :            : 
    1320                 :            : 
    1321                 :          0 : void LngSvcMgr::SetCfgServiceLists( SpellCheckerDispatcher &rSpellDsp )
    1322                 :            : {
    1323                 :            :     RTL_LOGFILE_CONTEXT( aLog, "linguistic: LngSvcMgr::SetCfgServiceLists - Spell" );
    1324                 :            : 
    1325                 :          0 :     rtl::OUString aNode("ServiceManager/SpellCheckerList");
    1326         [ #  # ]:          0 :     uno::Sequence< OUString > aNames( /*aCfg.*/GetNodeNames( aNode ) );
    1327         [ #  # ]:          0 :     OUString *pNames = aNames.getArray();
    1328                 :          0 :     sal_Int32 nLen = aNames.getLength();
    1329                 :            : 
    1330                 :            :     // append path prefix need for 'GetProperties' call below
    1331         [ #  # ]:          0 :     String aPrefix( aNode );
    1332         [ #  # ]:          0 :     aPrefix.Append( (sal_Unicode) '/' );
    1333         [ #  # ]:          0 :     for (int i = 0;  i < nLen;  ++i)
    1334                 :            :     {
    1335         [ #  # ]:          0 :         OUString aTmp( aPrefix );
    1336                 :          0 :         aTmp += pNames[i];
    1337                 :          0 :         pNames[i] = aTmp;
    1338                 :          0 :     }
    1339                 :            : 
    1340         [ #  # ]:          0 :     uno::Sequence< uno::Any > aValues( /*aCfg.*/GetProperties( aNames ) );
    1341 [ #  # ][ #  # ]:          0 :     if (nLen  &&  nLen == aValues.getLength())
                 [ #  # ]
    1342                 :            :     {
    1343                 :          0 :         const uno::Any *pValues = aValues.getConstArray();
    1344         [ #  # ]:          0 :         for (sal_Int32 i = 0;  i < nLen;  ++i)
    1345                 :            :         {
    1346         [ #  # ]:          0 :             uno::Sequence< OUString > aSvcImplNames;
    1347 [ #  # ][ #  # ]:          0 :             if (pValues[i] >>= aSvcImplNames)
    1348                 :            :             {
    1349         [ #  # ]:          0 :                 String aLocaleStr( pNames[i] );
    1350         [ #  # ]:          0 :                 xub_StrLen nSeperatorPos = aLocaleStr.SearchBackward( sal_Unicode( '/' ) );
    1351 [ #  # ][ #  # ]:          0 :                 aLocaleStr = aLocaleStr.Copy( nSeperatorPos + 1 );
                 [ #  # ]
    1352 [ #  # ][ #  # ]:          0 :                 lang::Locale aLocale( CreateLocale( MsLangId::convertIsoStringToLanguage(aLocaleStr) ) );
                 [ #  # ]
    1353 [ #  # ][ #  # ]:          0 :                 rSpellDsp.SetServiceList( aLocale, aSvcImplNames );
    1354                 :            :             }
    1355         [ #  # ]:          0 :         }
    1356 [ #  # ][ #  # ]:          0 :     }
                 [ #  # ]
    1357                 :          0 : }
    1358                 :            : 
    1359                 :            : 
    1360                 :          0 : void LngSvcMgr::SetCfgServiceLists( GrammarCheckingIterator &rGrammarDsp )
    1361                 :            : {
    1362                 :            :     RTL_LOGFILE_CONTEXT( aLog, "linguistic: LngSvcMgr::SetCfgServiceLists - Grammar" );
    1363                 :            : 
    1364                 :          0 :     rtl::OUString aNode("ServiceManager/GrammarCheckerList");
    1365         [ #  # ]:          0 :     uno::Sequence< OUString > aNames( /*aCfg.*/GetNodeNames( aNode ) );
    1366         [ #  # ]:          0 :     OUString *pNames = aNames.getArray();
    1367                 :          0 :     sal_Int32 nLen = aNames.getLength();
    1368                 :            : 
    1369                 :            :     // append path prefix need for 'GetProperties' call below
    1370         [ #  # ]:          0 :     String aPrefix( aNode );
    1371         [ #  # ]:          0 :     aPrefix.Append( (sal_Unicode) '/' );
    1372         [ #  # ]:          0 :     for (int i = 0;  i < nLen;  ++i)
    1373                 :            :     {
    1374         [ #  # ]:          0 :         OUString aTmp( aPrefix );
    1375                 :          0 :         aTmp += pNames[i];
    1376                 :          0 :         pNames[i] = aTmp;
    1377                 :          0 :     }
    1378                 :            : 
    1379         [ #  # ]:          0 :     uno::Sequence< uno::Any > aValues( /*aCfg.*/GetProperties( aNames ) );
    1380 [ #  # ][ #  # ]:          0 :     if (nLen  &&  nLen == aValues.getLength())
                 [ #  # ]
    1381                 :            :     {
    1382                 :          0 :         const uno::Any *pValues = aValues.getConstArray();
    1383         [ #  # ]:          0 :         for (sal_Int32 i = 0;  i < nLen;  ++i)
    1384                 :            :         {
    1385         [ #  # ]:          0 :             uno::Sequence< OUString > aSvcImplNames;
    1386 [ #  # ][ #  # ]:          0 :             if (pValues[i] >>= aSvcImplNames)
    1387                 :            :             {
    1388                 :            :                 // there should only be one grammar checker in use per language...
    1389         [ #  # ]:          0 :                 if (aSvcImplNames.getLength() > 1)
    1390         [ #  # ]:          0 :                     aSvcImplNames.realloc(1);
    1391                 :            : 
    1392         [ #  # ]:          0 :                 String aLocaleStr( pNames[i] );
    1393         [ #  # ]:          0 :                 xub_StrLen nSeperatorPos = aLocaleStr.SearchBackward( sal_Unicode( '/' ) );
    1394 [ #  # ][ #  # ]:          0 :                 aLocaleStr = aLocaleStr.Copy( nSeperatorPos + 1 );
                 [ #  # ]
    1395 [ #  # ][ #  # ]:          0 :                 lang::Locale aLocale( CreateLocale( MsLangId::convertIsoStringToLanguage(aLocaleStr) ) );
                 [ #  # ]
    1396 [ #  # ][ #  # ]:          0 :                 rGrammarDsp.SetServiceList( aLocale, aSvcImplNames );
    1397                 :            :             }
    1398         [ #  # ]:          0 :         }
    1399 [ #  # ][ #  # ]:          0 :     }
                 [ #  # ]
    1400                 :          0 : }
    1401                 :            : 
    1402                 :            : 
    1403                 :          0 : void LngSvcMgr::SetCfgServiceLists( HyphenatorDispatcher &rHyphDsp )
    1404                 :            : {
    1405                 :            :     RTL_LOGFILE_CONTEXT( aLog, "linguistic: LngSvcMgr::SetCfgServiceLists - Hyph" );
    1406                 :            : 
    1407                 :          0 :     rtl::OUString aNode("ServiceManager/HyphenatorList");
    1408         [ #  # ]:          0 :     uno::Sequence< OUString > aNames( /*aCfg.*/GetNodeNames( aNode ) );
    1409         [ #  # ]:          0 :     OUString *pNames = aNames.getArray();
    1410                 :          0 :     sal_Int32 nLen = aNames.getLength();
    1411                 :            : 
    1412                 :            :     // append path prefix need for 'GetProperties' call below
    1413         [ #  # ]:          0 :     String aPrefix( aNode );
    1414         [ #  # ]:          0 :     aPrefix.Append( (sal_Unicode) '/' );
    1415         [ #  # ]:          0 :     for (int i = 0;  i < nLen;  ++i)
    1416                 :            :     {
    1417         [ #  # ]:          0 :         OUString aTmp( aPrefix );
    1418                 :          0 :         aTmp += pNames[i];
    1419                 :          0 :         pNames[i] = aTmp;
    1420                 :          0 :     }
    1421                 :            : 
    1422         [ #  # ]:          0 :     uno::Sequence< uno::Any > aValues( /*aCfg.*/GetProperties( aNames ) );
    1423 [ #  # ][ #  # ]:          0 :     if (nLen  &&  nLen == aValues.getLength())
                 [ #  # ]
    1424                 :            :     {
    1425                 :          0 :         const uno::Any *pValues = aValues.getConstArray();
    1426         [ #  # ]:          0 :         for (sal_Int32 i = 0;  i < nLen;  ++i)
    1427                 :            :         {
    1428         [ #  # ]:          0 :             uno::Sequence< OUString > aSvcImplNames;
    1429 [ #  # ][ #  # ]:          0 :             if (pValues[i] >>= aSvcImplNames)
    1430                 :            :             {
    1431                 :            :                 // there should only be one hyphenator in use per language...
    1432         [ #  # ]:          0 :                 if (aSvcImplNames.getLength() > 1)
    1433         [ #  # ]:          0 :                     aSvcImplNames.realloc(1);
    1434                 :            : 
    1435         [ #  # ]:          0 :                 String aLocaleStr( pNames[i] );
    1436         [ #  # ]:          0 :                 xub_StrLen nSeperatorPos = aLocaleStr.SearchBackward( sal_Unicode( '/' ) );
    1437 [ #  # ][ #  # ]:          0 :                 aLocaleStr = aLocaleStr.Copy( nSeperatorPos + 1 );
                 [ #  # ]
    1438 [ #  # ][ #  # ]:          0 :                 lang::Locale aLocale( CreateLocale( MsLangId::convertIsoStringToLanguage(aLocaleStr) ) );
                 [ #  # ]
    1439 [ #  # ][ #  # ]:          0 :                 rHyphDsp.SetServiceList( aLocale, aSvcImplNames );
    1440                 :            :             }
    1441         [ #  # ]:          0 :         }
    1442 [ #  # ][ #  # ]:          0 :     }
                 [ #  # ]
    1443                 :          0 : }
    1444                 :            : 
    1445                 :            : 
    1446                 :          0 : void LngSvcMgr::SetCfgServiceLists( ThesaurusDispatcher &rThesDsp )
    1447                 :            : {
    1448                 :            :     RTL_LOGFILE_CONTEXT( aLog, "linguistic: LngSvcMgr::SetCfgServiceLists - Thes" );
    1449                 :            : 
    1450                 :          0 :     rtl::OUString aNode("ServiceManager/ThesaurusList");
    1451         [ #  # ]:          0 :     uno::Sequence< OUString > aNames( /*aCfg.*/GetNodeNames( aNode ) );
    1452         [ #  # ]:          0 :     OUString *pNames = aNames.getArray();
    1453                 :          0 :     sal_Int32 nLen = aNames.getLength();
    1454                 :            : 
    1455                 :            :     // append path prefix need for 'GetProperties' call below
    1456         [ #  # ]:          0 :     String aPrefix( aNode );
    1457         [ #  # ]:          0 :     aPrefix.Append( (sal_Unicode) '/' );
    1458         [ #  # ]:          0 :     for (int i = 0;  i < nLen;  ++i)
    1459                 :            :     {
    1460         [ #  # ]:          0 :         OUString aTmp( aPrefix );
    1461                 :          0 :         aTmp += pNames[i];
    1462                 :          0 :         pNames[i] = aTmp;
    1463                 :          0 :     }
    1464                 :            : 
    1465         [ #  # ]:          0 :     uno::Sequence< uno::Any > aValues( /*aCfg.*/GetProperties( aNames ) );
    1466 [ #  # ][ #  # ]:          0 :     if (nLen  &&  nLen == aValues.getLength())
                 [ #  # ]
    1467                 :            :     {
    1468                 :          0 :         const uno::Any *pValues = aValues.getConstArray();
    1469         [ #  # ]:          0 :         for (sal_Int32 i = 0;  i < nLen;  ++i)
    1470                 :            :         {
    1471         [ #  # ]:          0 :             uno::Sequence< OUString > aSvcImplNames;
    1472 [ #  # ][ #  # ]:          0 :             if (pValues[i] >>= aSvcImplNames)
    1473                 :            :             {
    1474         [ #  # ]:          0 :                 String aLocaleStr( pNames[i] );
    1475         [ #  # ]:          0 :                 xub_StrLen nSeperatorPos = aLocaleStr.SearchBackward( sal_Unicode( '/' ) );
    1476 [ #  # ][ #  # ]:          0 :                 aLocaleStr = aLocaleStr.Copy( nSeperatorPos + 1 );
                 [ #  # ]
    1477 [ #  # ][ #  # ]:          0 :                 lang::Locale aLocale( CreateLocale( MsLangId::convertIsoStringToLanguage(aLocaleStr) ) );
                 [ #  # ]
    1478 [ #  # ][ #  # ]:          0 :                 rThesDsp.SetServiceList( aLocale, aSvcImplNames );
    1479                 :            :             }
    1480         [ #  # ]:          0 :         }
    1481 [ #  # ][ #  # ]:          0 :     }
                 [ #  # ]
    1482                 :          0 : }
    1483                 :            : 
    1484                 :            : 
    1485                 :            : uno::Reference< linguistic2::XSpellChecker > SAL_CALL
    1486                 :         41 :     LngSvcMgr::getSpellChecker()
    1487                 :            :         throw(uno::RuntimeException)
    1488                 :            : {
    1489 [ +  - ][ +  - ]:         41 :     osl::MutexGuard aGuard( GetLinguMutex() );
    1490                 :            : #if OSL_DEBUG_LEVEL > 1
    1491                 :            :     getAvailableLocales( SN_SPELLCHECKER );
    1492                 :            : #endif
    1493                 :            : 
    1494                 :         41 :     uno::Reference< linguistic2::XSpellChecker > xRes;
    1495         [ +  - ]:         41 :     if (!bDisposing)
    1496                 :            :     {
    1497         [ -  + ]:         41 :         if (!xSpellDsp.is())
    1498         [ #  # ]:          0 :             GetSpellCheckerDsp_Impl();
    1499         [ +  - ]:         41 :         xRes = xSpellDsp;
    1500                 :            :     }
    1501         [ +  - ]:         41 :     return xRes;
    1502                 :            : }
    1503                 :            : 
    1504                 :            : 
    1505                 :            : uno::Reference< linguistic2::XHyphenator > SAL_CALL
    1506                 :      24830 :     LngSvcMgr::getHyphenator()
    1507                 :            :         throw(uno::RuntimeException)
    1508                 :            : {
    1509 [ +  - ][ +  - ]:      24830 :     osl::MutexGuard aGuard( GetLinguMutex() );
    1510                 :            : #if OSL_DEBUG_LEVEL > 1
    1511                 :            :     getAvailableLocales( SN_HYPHENATOR );
    1512                 :            : #endif
    1513                 :            : 
    1514                 :      24830 :     uno::Reference< linguistic2::XHyphenator >   xRes;
    1515         [ +  - ]:      24830 :     if (!bDisposing)
    1516                 :            :     {
    1517         [ -  + ]:      24830 :         if (!xHyphDsp.is())
    1518         [ #  # ]:          0 :             GetHyphenatorDsp_Impl();
    1519         [ +  - ]:      24830 :         xRes = xHyphDsp;
    1520                 :            :     }
    1521         [ +  - ]:      24830 :     return xRes;
    1522                 :            : }
    1523                 :            : 
    1524                 :            : 
    1525                 :            : uno::Reference< linguistic2::XThesaurus > SAL_CALL
    1526                 :          0 :     LngSvcMgr::getThesaurus()
    1527                 :            :         throw(uno::RuntimeException)
    1528                 :            : {
    1529 [ #  # ][ #  # ]:          0 :     osl::MutexGuard aGuard( GetLinguMutex() );
    1530                 :            : #if OSL_DEBUG_LEVEL > 1
    1531                 :            :     getAvailableLocales( SN_THESAURUS );
    1532                 :            : #endif
    1533                 :            : 
    1534                 :          0 :     uno::Reference< linguistic2::XThesaurus >    xRes;
    1535         [ #  # ]:          0 :     if (!bDisposing)
    1536                 :            :     {
    1537         [ #  # ]:          0 :         if (!xThesDsp.is())
    1538         [ #  # ]:          0 :             GetThesaurusDsp_Impl();
    1539         [ #  # ]:          0 :         xRes = xThesDsp;
    1540                 :            :     }
    1541         [ #  # ]:          0 :     return xRes;
    1542                 :            : }
    1543                 :            : 
    1544                 :            : 
    1545                 :            : sal_Bool SAL_CALL
    1546                 :         26 :     LngSvcMgr::addLinguServiceManagerListener(
    1547                 :            :             const uno::Reference< lang::XEventListener >& xListener )
    1548                 :            :         throw(uno::RuntimeException)
    1549                 :            : {
    1550 [ +  - ][ +  - ]:         26 :     osl::MutexGuard aGuard( GetLinguMutex() );
    1551                 :            : 
    1552                 :         26 :     sal_Bool bRes = sal_False;
    1553 [ +  - ][ +  - ]:         26 :     if (!bDisposing  &&  xListener.is())
                 [ +  - ]
    1554                 :            :     {
    1555         [ +  + ]:         26 :         if (!pListenerHelper)
    1556         [ +  - ]:         24 :             GetListenerHelper_Impl();
    1557         [ +  - ]:         26 :         bRes = pListenerHelper->AddLngSvcMgrListener( xListener );
    1558                 :            :     }
    1559         [ +  - ]:         26 :     return bRes;
    1560                 :            : }
    1561                 :            : 
    1562                 :            : 
    1563                 :            : sal_Bool SAL_CALL
    1564                 :          0 :     LngSvcMgr::removeLinguServiceManagerListener(
    1565                 :            :             const uno::Reference< lang::XEventListener >& xListener )
    1566                 :            :         throw(uno::RuntimeException)
    1567                 :            : {
    1568 [ #  # ][ #  # ]:          0 :     osl::MutexGuard aGuard( GetLinguMutex() );
    1569                 :            : 
    1570                 :          0 :     sal_Bool bRes = sal_False;
    1571 [ #  # ][ #  # ]:          0 :     if (!bDisposing  &&  xListener.is())
                 [ #  # ]
    1572                 :            :     {
    1573                 :            :         DBG_ASSERT( pListenerHelper, "listener removed without being added" );
    1574         [ #  # ]:          0 :         if (!pListenerHelper)
    1575         [ #  # ]:          0 :             GetListenerHelper_Impl();
    1576         [ #  # ]:          0 :         bRes = pListenerHelper->RemoveLngSvcMgrListener( xListener );
    1577                 :            :     }
    1578         [ #  # ]:          0 :     return bRes;
    1579                 :            : }
    1580                 :            : 
    1581                 :            : 
    1582                 :            : uno::Sequence< OUString > SAL_CALL
    1583                 :       9792 :     LngSvcMgr::getAvailableServices(
    1584                 :            :             const OUString& rServiceName,
    1585                 :            :             const lang::Locale& rLocale )
    1586                 :            :         throw(uno::RuntimeException)
    1587                 :            : {
    1588 [ +  - ][ +  - ]:       9792 :     osl::MutexGuard aGuard( GetLinguMutex() );
    1589                 :            : 
    1590         [ +  - ]:       9792 :     uno::Sequence< OUString > aRes;
    1591                 :       9792 :     const SvcInfoArray *pInfoArray = 0;
    1592                 :            : 
    1593         [ +  + ]:       9792 :     if (0 == rServiceName.compareToAscii( SN_SPELLCHECKER ))
    1594                 :            :     {
    1595         [ +  - ]:       2800 :         GetAvailableSpellSvcs_Impl();
    1596                 :       2800 :         pInfoArray = pAvailSpellSvcs;
    1597                 :            :     }
    1598         [ +  + ]:       6992 :     else if (0 == rServiceName.compareToAscii( SN_GRAMMARCHECKER ))
    1599                 :            :     {
    1600         [ +  - ]:       1072 :         GetAvailableGrammarSvcs_Impl();
    1601                 :       1072 :         pInfoArray = pAvailGrammarSvcs;
    1602                 :            :     }
    1603         [ +  + ]:       5920 :     else if (0 == rServiceName.compareToAscii( SN_HYPHENATOR ))
    1604                 :            :     {
    1605         [ +  - ]:       2992 :         GetAvailableHyphSvcs_Impl();
    1606                 :       2992 :         pInfoArray = pAvailHyphSvcs;
    1607                 :            :     }
    1608         [ +  - ]:       2928 :     else if (0 == rServiceName.compareToAscii( SN_THESAURUS ))
    1609                 :            :     {
    1610         [ +  - ]:       2928 :         GetAvailableThesSvcs_Impl();
    1611                 :       2928 :         pInfoArray = pAvailThesSvcs;
    1612                 :            :     }
    1613                 :            : 
    1614         [ +  - ]:       9792 :     if (pInfoArray)
    1615                 :            :     {
    1616                 :            :         // resize to max number of entries
    1617                 :       9792 :         size_t nMaxCnt = pInfoArray->size();
    1618         [ +  - ]:       9792 :         aRes.realloc( nMaxCnt );
    1619         [ +  - ]:       9792 :         OUString *pImplName = aRes.getArray();
    1620                 :            : 
    1621                 :       9792 :         sal_uInt16 nCnt = 0;
    1622         [ +  - ]:       9792 :         LanguageType nLanguage = LocaleToLanguage( rLocale );
    1623         [ +  + ]:      19584 :         for (size_t i = 0;  i < nMaxCnt; ++i)
    1624                 :            :         {
    1625         [ +  - ]:       9792 :             const SvcInfo &rInfo = (*pInfoArray)[i];
    1626 [ +  + ][ +  - ]:      19392 :             if (LANGUAGE_NONE == nLanguage
                 [ +  - ]
    1627         [ +  - ]:       9600 :                 || rInfo.HasLanguage( nLanguage ))
    1628                 :            :             {
    1629                 :       9792 :                 pImplName[ nCnt++ ] = rInfo.aSvcImplName;
    1630                 :            :             }
    1631                 :            :         }
    1632                 :            : 
    1633                 :            :         // resize to actual number of entries
    1634         [ -  + ]:       9792 :         if (nCnt != nMaxCnt)
    1635         [ #  # ]:          0 :             aRes.realloc( nCnt );
    1636                 :            :     }
    1637                 :            : 
    1638         [ +  - ]:       9792 :     return aRes;
    1639                 :            : }
    1640                 :            : 
    1641                 :            : 
    1642                 :            : uno::Sequence< lang::Locale > SAL_CALL
    1643                 :        192 :     LngSvcMgr::getAvailableLocales(
    1644                 :            :             const OUString& rServiceName )
    1645                 :            :         throw(uno::RuntimeException)
    1646                 :            : {
    1647 [ +  - ][ +  - ]:        192 :     osl::MutexGuard aGuard( GetLinguMutex() );
    1648                 :            : 
    1649         [ +  - ]:        192 :     uno::Sequence< lang::Locale > aRes;
    1650                 :            : 
    1651                 :        192 :     uno::Sequence< lang::Locale >  *pAvailLocales     = NULL;
    1652         [ +  + ]:        192 :     if (0 == rServiceName.compareToAscii( SN_SPELLCHECKER ))
    1653                 :         48 :         pAvailLocales       = &aAvailSpellLocales;
    1654         [ +  + ]:        144 :     else if (0 == rServiceName.compareToAscii( SN_GRAMMARCHECKER ))
    1655                 :         48 :         pAvailLocales       = &aAvailGrammarLocales;
    1656         [ +  + ]:         96 :     else if (0 == rServiceName.compareToAscii( SN_HYPHENATOR ))
    1657                 :         48 :         pAvailLocales       = &aAvailHyphLocales;
    1658         [ +  - ]:         48 :     else if (0 == rServiceName.compareToAscii( SN_THESAURUS ))
    1659                 :         48 :         pAvailLocales       = &aAvailThesLocales;
    1660                 :            : 
    1661                 :            :     // Nowadays (with OOo lingu in SO) we want to know immediately about
    1662                 :            :     // new downloaded dictionaries and have them ready right away if the Tools/Options...
    1663                 :            :     // is used to activate them. Thus we can not rely anymore on buffered data.
    1664         [ +  - ]:        192 :     if (pAvailLocales)
    1665                 :            :     {
    1666 [ +  - ][ +  - ]:        192 :         *pAvailLocales = GetAvailLocales(getAvailableServices(rServiceName, lang::Locale()));
         [ +  - ][ +  - ]
                 [ +  - ]
    1667         [ +  - ]:        192 :         aRes = *pAvailLocales;
    1668                 :            :     }
    1669                 :            : 
    1670         [ +  - ]:        192 :     return aRes;
    1671                 :            : }
    1672                 :            : 
    1673                 :          0 : static sal_Bool IsEqSvcList( const uno::Sequence< OUString > &rList1,
    1674                 :            :                         const uno::Sequence< OUString > &rList2 )
    1675                 :            : {
    1676                 :            :     // returns sal_True iff both sequences are equal
    1677                 :            : 
    1678                 :          0 :     sal_Bool bRes = sal_False;
    1679                 :          0 :     sal_Int32 nLen = rList1.getLength();
    1680         [ #  # ]:          0 :     if (rList2.getLength() == nLen)
    1681                 :            :     {
    1682                 :          0 :         const OUString *pStr1 = rList1.getConstArray();
    1683                 :          0 :         const OUString *pStr2 = rList2.getConstArray();
    1684                 :          0 :         bRes = sal_True;
    1685 [ #  # ][ #  # ]:          0 :         for (sal_Int32 i = 0;  i < nLen  &&  bRes;  ++i)
                 [ #  # ]
    1686                 :            :         {
    1687         [ #  # ]:          0 :             if (*pStr1++ != *pStr2++)
    1688                 :          0 :                 bRes = sal_False;
    1689                 :            :         }
    1690                 :            :     }
    1691                 :          0 :     return bRes;
    1692                 :            : }
    1693                 :            : 
    1694                 :            : 
    1695                 :            : void SAL_CALL
    1696                 :          0 :     LngSvcMgr::setConfiguredServices(
    1697                 :            :             const OUString& rServiceName,
    1698                 :            :             const lang::Locale& rLocale,
    1699                 :            :             const uno::Sequence< OUString >& rServiceImplNames )
    1700                 :            :         throw(uno::RuntimeException)
    1701                 :            : {
    1702                 :            :     RTL_LOGFILE_CONTEXT( aLog, "linguistic: LngSvcMgr::setConfiguredServices" );
    1703                 :            : 
    1704 [ #  # ][ #  # ]:          0 :     osl::MutexGuard aGuard( GetLinguMutex() );
    1705                 :            : 
    1706                 :            : #if OSL_DEBUG_LEVEL > 1
    1707                 :            : #endif
    1708                 :            : 
    1709         [ #  # ]:          0 :     LanguageType nLanguage = LocaleToLanguage( rLocale );
    1710         [ #  # ]:          0 :     if (LANGUAGE_NONE != nLanguage)
    1711                 :            :     {
    1712         [ #  # ]:          0 :         if (0 == rServiceName.compareToAscii( SN_SPELLCHECKER ))
    1713                 :            :         {
    1714         [ #  # ]:          0 :             if (!xSpellDsp.is())
    1715         [ #  # ]:          0 :                 GetSpellCheckerDsp_Impl();
    1716                 :            :             sal_Bool bChanged = !IsEqSvcList( rServiceImplNames,
    1717 [ #  # ][ #  # ]:          0 :                                           pSpellDsp->GetServiceList( rLocale ) );
                 [ #  # ]
    1718         [ #  # ]:          0 :             if (bChanged)
    1719                 :            :             {
    1720         [ #  # ]:          0 :                 pSpellDsp->SetServiceList( rLocale, rServiceImplNames );
    1721 [ #  # ][ #  # ]:          0 :                 SaveCfgSvcs( rtl::OUString(SN_SPELLCHECKER) );
                 [ #  # ]
    1722                 :            : 
    1723 [ #  # ][ #  # ]:          0 :                 if (pListenerHelper  &&  bChanged)
    1724                 :            :                     pListenerHelper->AddLngSvcEvt(
    1725                 :            :                             linguistic2::LinguServiceEventFlags::SPELL_CORRECT_WORDS_AGAIN |
    1726         [ #  # ]:          0 :                             linguistic2::LinguServiceEventFlags::SPELL_WRONG_WORDS_AGAIN );
    1727                 :            :             }
    1728                 :            :         }
    1729         [ #  # ]:          0 :         else if (0 == rServiceName.compareToAscii( SN_GRAMMARCHECKER ))
    1730                 :            :         {
    1731         [ #  # ]:          0 :             if (!xGrammarDsp.is())
    1732         [ #  # ]:          0 :                 GetGrammarCheckerDsp_Impl();
    1733                 :            :             sal_Bool bChanged = !IsEqSvcList( rServiceImplNames,
    1734 [ #  # ][ #  # ]:          0 :                                           pGrammarDsp->GetServiceList( rLocale ) );
                 [ #  # ]
    1735         [ #  # ]:          0 :             if (bChanged)
    1736                 :            :             {
    1737         [ #  # ]:          0 :                 pGrammarDsp->SetServiceList( rLocale, rServiceImplNames );
    1738 [ #  # ][ #  # ]:          0 :                 SaveCfgSvcs( rtl::OUString(SN_GRAMMARCHECKER) );
                 [ #  # ]
    1739                 :            : 
    1740 [ #  # ][ #  # ]:          0 :                 if (pListenerHelper  &&  bChanged)
    1741                 :            :                     pListenerHelper->AddLngSvcEvt(
    1742         [ #  # ]:          0 :                             linguistic2::LinguServiceEventFlags::PROOFREAD_AGAIN );
    1743                 :            :             }
    1744                 :            :         }
    1745         [ #  # ]:          0 :         else if (0 == rServiceName.compareToAscii( SN_HYPHENATOR ))
    1746                 :            :         {
    1747         [ #  # ]:          0 :             if (!xHyphDsp.is())
    1748         [ #  # ]:          0 :                 GetHyphenatorDsp_Impl();
    1749                 :            :             sal_Bool bChanged = !IsEqSvcList( rServiceImplNames,
    1750 [ #  # ][ #  # ]:          0 :                                           pHyphDsp->GetServiceList( rLocale ) );
                 [ #  # ]
    1751         [ #  # ]:          0 :             if (bChanged)
    1752                 :            :             {
    1753         [ #  # ]:          0 :                 pHyphDsp->SetServiceList( rLocale, rServiceImplNames );
    1754 [ #  # ][ #  # ]:          0 :                 SaveCfgSvcs( rtl::OUString(SN_HYPHENATOR) );
                 [ #  # ]
    1755                 :            : 
    1756 [ #  # ][ #  # ]:          0 :                 if (pListenerHelper  &&  bChanged)
    1757                 :            :                     pListenerHelper->AddLngSvcEvt(
    1758         [ #  # ]:          0 :                             linguistic2::LinguServiceEventFlags::HYPHENATE_AGAIN );
    1759                 :            :             }
    1760                 :            :         }
    1761         [ #  # ]:          0 :         else if (0 == rServiceName.compareToAscii( SN_THESAURUS ))
    1762                 :            :         {
    1763         [ #  # ]:          0 :             if (!xThesDsp.is())
    1764         [ #  # ]:          0 :                 GetThesaurusDsp_Impl();
    1765                 :            :             sal_Bool bChanged = !IsEqSvcList( rServiceImplNames,
    1766 [ #  # ][ #  # ]:          0 :                                           pThesDsp->GetServiceList( rLocale ) );
                 [ #  # ]
    1767         [ #  # ]:          0 :             if (bChanged)
    1768                 :            :             {
    1769         [ #  # ]:          0 :                 pThesDsp->SetServiceList( rLocale, rServiceImplNames );
    1770 [ #  # ][ #  # ]:          0 :                 SaveCfgSvcs( rtl::OUString(SN_THESAURUS) );
                 [ #  # ]
    1771                 :            :             }
    1772                 :            :         }
    1773         [ #  # ]:          0 :     }
    1774                 :          0 : }
    1775                 :            : 
    1776                 :            : 
    1777                 :          0 : sal_Bool LngSvcMgr::SaveCfgSvcs( const String &rServiceName )
    1778                 :            : {
    1779                 :            :     RTL_LOGFILE_CONTEXT( aLog, "linguistic: LngSvcMgr::SaveCfgSvcs" );
    1780                 :            : 
    1781                 :          0 :     sal_Bool bRes = sal_False;
    1782                 :            : 
    1783                 :          0 :     LinguDispatcher *pDsp = 0;
    1784         [ #  # ]:          0 :     uno::Sequence< lang::Locale > aLocales;
    1785                 :            : 
    1786 [ #  # ][ #  # ]:          0 :     if (0 == rServiceName.CompareToAscii( SN_SPELLCHECKER ))
    1787                 :            :     {
    1788         [ #  # ]:          0 :         if (!pSpellDsp)
    1789         [ #  # ]:          0 :             GetSpellCheckerDsp_Impl();
    1790         [ #  # ]:          0 :         pDsp = pSpellDsp;
    1791 [ #  # ][ #  # ]:          0 :         aLocales = getAvailableLocales( SN_SPELLCHECKER );
                 [ #  # ]
    1792                 :            :     }
    1793 [ #  # ][ #  # ]:          0 :     else if (0 == rServiceName.CompareToAscii( SN_GRAMMARCHECKER ))
    1794                 :            :     {
    1795         [ #  # ]:          0 :         if (!pGrammarDsp)
    1796         [ #  # ]:          0 :             GetGrammarCheckerDsp_Impl();
    1797         [ #  # ]:          0 :         pDsp = pGrammarDsp;
    1798 [ #  # ][ #  # ]:          0 :         aLocales = getAvailableLocales( SN_GRAMMARCHECKER );
                 [ #  # ]
    1799                 :            :     }
    1800 [ #  # ][ #  # ]:          0 :     else if (0 == rServiceName.CompareToAscii( SN_HYPHENATOR ))
    1801                 :            :     {
    1802         [ #  # ]:          0 :         if (!pHyphDsp)
    1803         [ #  # ]:          0 :             GetHyphenatorDsp_Impl();
    1804         [ #  # ]:          0 :         pDsp = pHyphDsp;
    1805 [ #  # ][ #  # ]:          0 :         aLocales = getAvailableLocales( SN_HYPHENATOR );
                 [ #  # ]
    1806                 :            :     }
    1807 [ #  # ][ #  # ]:          0 :     else if (0 == rServiceName.CompareToAscii( SN_THESAURUS ))
    1808                 :            :     {
    1809         [ #  # ]:          0 :         if (!pThesDsp)
    1810         [ #  # ]:          0 :             GetThesaurusDsp_Impl();
    1811         [ #  # ]:          0 :         pDsp = pThesDsp;
    1812 [ #  # ][ #  # ]:          0 :         aLocales = getAvailableLocales( SN_THESAURUS );
                 [ #  # ]
    1813                 :            :     }
    1814                 :            : 
    1815 [ #  # ][ #  # ]:          0 :     if (pDsp  &&  aLocales.getLength())
                 [ #  # ]
    1816                 :            :     {
    1817                 :          0 :         sal_Int32 nLen = aLocales.getLength();
    1818                 :          0 :         const lang::Locale *pLocale = aLocales.getConstArray();
    1819                 :            : 
    1820         [ #  # ]:          0 :         uno::Sequence< beans::PropertyValue > aValues( nLen );
    1821         [ #  # ]:          0 :         beans::PropertyValue *pValues = aValues.getArray();
    1822                 :          0 :         beans::PropertyValue *pValue  = pValues;
    1823                 :            : 
    1824                 :            :         // get node name to be used
    1825                 :          0 :         const char *pNodeName = NULL;
    1826 [ #  # ][ #  # ]:          0 :         if (pDsp == pSpellDsp)
    1827                 :          0 :             pNodeName = "ServiceManager/SpellCheckerList";
    1828 [ #  # ][ #  # ]:          0 :         else if (pDsp == pGrammarDsp)
    1829                 :          0 :             pNodeName = "ServiceManager/GrammarCheckerList";
    1830 [ #  # ][ #  # ]:          0 :         else if (pDsp == pHyphDsp)
    1831                 :          0 :             pNodeName = "ServiceManager/HyphenatorList";
    1832 [ #  # ][ #  # ]:          0 :         else if (pDsp == pThesDsp)
    1833                 :          0 :             pNodeName = "ServiceManager/ThesaurusList";
    1834                 :            :         else
    1835                 :            :         {
    1836                 :            :             DBG_ASSERT( 0, "node name missing" );
    1837                 :            :         }
    1838                 :          0 :         OUString aNodeName( ::rtl::OUString::createFromAscii(pNodeName) );
    1839                 :            : 
    1840         [ #  # ]:          0 :         for (sal_Int32 i = 0;  i < nLen;  ++i)
    1841                 :            :         {
    1842         [ #  # ]:          0 :             uno::Sequence< OUString > aSvcImplNames;
    1843 [ #  # ][ #  # ]:          0 :             aSvcImplNames = pDsp->GetServiceList( pLocale[i] );
                 [ #  # ]
    1844                 :            : 
    1845                 :            : #if OSL_DEBUG_LEVEL > 1
    1846                 :            :             sal_Int32 nSvcs = aSvcImplNames.getLength();
    1847                 :            :             const OUString *pSvcImplName = aSvcImplNames.getConstArray();
    1848                 :            :             for (sal_Int32 j = 0;  j < nSvcs;  ++j)
    1849                 :            :             {
    1850                 :            :                 OUString aImplName( pSvcImplName[j] );
    1851                 :            :             }
    1852                 :            : #endif
    1853                 :            :             // build value to be written back to configuration
    1854                 :          0 :             uno::Any aCfgAny;
    1855 [ #  # ][ #  # ]:          0 :             if ((pDsp == pHyphDsp || pDsp == pGrammarDsp) && aSvcImplNames.getLength() > 1)
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1856         [ #  # ]:          0 :                 aSvcImplNames.realloc(1);   // there should be only one entry for hyphenators or grammar checkers (because they are not chained)
    1857         [ #  # ]:          0 :             aCfgAny <<= aSvcImplNames;
    1858                 :            :             DBG_ASSERT( aCfgAny.hasValue(), "missing value for 'Any' type" );
    1859                 :            : 
    1860                 :            :             OUString aCfgLocaleStr( MsLangId::convertLanguageToIsoString(
    1861 [ #  # ][ #  # ]:          0 :                                         LocaleToLanguage( pLocale[i] ) ) );
    1862                 :          0 :             pValue->Value = aCfgAny;
    1863                 :          0 :             pValue->Name  = aNodeName;
    1864                 :          0 :             pValue->Name += OUString::valueOf( (sal_Unicode) '/' );
    1865                 :          0 :             pValue->Name += aCfgLocaleStr;
    1866                 :          0 :             pValue++;
    1867         [ #  # ]:          0 :         }
    1868                 :            :         {
    1869                 :            :         RTL_LOGFILE_CONTEXT( aLog, "linguistic: LngSvcMgr::SaveCfgSvcs - ReplaceSetProperties" );
    1870                 :            :         // change, add new or replace existing entries.
    1871 [ #  # ][ #  # ]:          0 :         bRes |= /*aCfg.*/ReplaceSetProperties( aNodeName, aValues );
                 [ #  # ]
    1872         [ #  # ]:          0 :         }
    1873                 :            :     }
    1874                 :            : 
    1875         [ #  # ]:          0 :     return bRes;
    1876                 :            : }
    1877                 :            : 
    1878                 :            : 
    1879                 :       5632 : static uno::Sequence< OUString > GetLangSvcList( const uno::Any &rVal )
    1880                 :            : {
    1881                 :       5632 :     uno::Sequence< OUString > aRes;
    1882                 :            : 
    1883         [ +  - ]:       5632 :     if (rVal.hasValue())
    1884                 :            :     {
    1885         [ +  - ]:       5632 :         rVal >>= aRes;
    1886                 :            : #if OSL_DEBUG_LEVEL > 1
    1887                 :            :         sal_Int32 nSvcs = aRes.getLength();
    1888                 :            :         if (nSvcs)
    1889                 :            :         {
    1890                 :            :             const OUString *pSvcName = aRes.getConstArray();
    1891                 :            :             for (sal_Int32 j = 0;  j < nSvcs;  ++j)
    1892                 :            :             {
    1893                 :            :                 OUString aImplName( pSvcName[j] );
    1894                 :            :                 DBG_ASSERT( !aImplName.isEmpty(), "service impl-name missing" );
    1895                 :            :             }
    1896                 :            :         }
    1897                 :            : #endif
    1898                 :            :     }
    1899                 :            : 
    1900                 :       5632 :     return aRes;
    1901                 :            : }
    1902                 :            : 
    1903                 :            : 
    1904                 :       3968 : static uno::Sequence< OUString > GetLangSvc( const uno::Any &rVal )
    1905                 :            : {
    1906                 :       3968 :     uno::Sequence< OUString > aRes;
    1907         [ -  + ]:       3968 :     if (!rVal.hasValue())
    1908                 :          0 :         return aRes;
    1909                 :            : 
    1910                 :            :     // allowing for a sequence here as well (even though it should only
    1911                 :            :     // be a string) makes coding easier in other places since one needs
    1912                 :            :     // not make a special case for writing a string only and not a
    1913                 :            :     // sequence of strings.
    1914 [ +  - ][ +  - ]:       3968 :     if (rVal >>= aRes)
    1915                 :            :     {
    1916                 :            :         // but only the first string should be used.
    1917         [ -  + ]:       3968 :         if (aRes.getLength() > 1)
    1918         [ #  # ]:          0 :             aRes.realloc(1);
    1919                 :            :     }
    1920                 :            :     else
    1921                 :            :     {
    1922                 :          0 :         OUString aImplName;
    1923 [ #  # ][ #  # ]:          0 :         if ((rVal >>= aImplName) && !aImplName.isEmpty())
                 [ #  # ]
    1924                 :            :         {
    1925         [ #  # ]:          0 :             aRes.realloc(1);
    1926         [ #  # ]:          0 :             aRes.getArray()[0] = aImplName;
    1927                 :            :         }
    1928                 :            :         else
    1929                 :            :         {
    1930                 :            :             DBG_ASSERT( 0, "GetLangSvc: unexpected type encountered" );
    1931                 :          0 :         }
    1932                 :            :     }
    1933                 :            : 
    1934                 :       3968 :     return aRes;
    1935                 :            : }
    1936                 :            : 
    1937                 :            : 
    1938                 :            : 
    1939                 :            : uno::Sequence< OUString > SAL_CALL
    1940                 :       2400 :     LngSvcMgr::getConfiguredServices(
    1941                 :            :             const OUString& rServiceName,
    1942                 :            :             const lang::Locale& rLocale )
    1943                 :            :         throw(uno::RuntimeException)
    1944                 :            : {
    1945 [ +  - ][ +  - ]:       2400 :     osl::MutexGuard aGuard( GetLinguMutex() );
    1946                 :            : 
    1947         [ +  - ]:       2400 :     uno::Sequence< OUString > aSvcImplNames;
    1948                 :            : 
    1949         [ +  - ]:       2400 :     LanguageType nLanguage = LocaleToLanguage( rLocale );
    1950         [ +  - ]:       2400 :     OUString aCfgLocale( MsLangId::convertLanguageToIsoString( nLanguage ) );
    1951                 :            : 
    1952         [ +  - ]:       2400 :     uno::Sequence< uno::Any > aValues;
    1953         [ +  - ]:       2400 :     uno::Sequence< OUString > aNames( 1 );
    1954         [ +  - ]:       2400 :     OUString *pNames = aNames.getArray();
    1955         [ +  + ]:       2400 :     if ( 0 == rServiceName.compareToAscii( SN_SPELLCHECKER ) )
    1956                 :            :     {
    1957                 :        688 :         OUString aNode( "ServiceManager/SpellCheckerList");
    1958         [ +  - ]:        688 :         const uno::Sequence< OUString > aNodeEntries( GetNodeNames( aNode ) );
    1959 [ +  - ][ +  - ]:        688 :         if (lcl_SeqHasString( aNodeEntries, aCfgLocale ))
    1960                 :            :         {
    1961                 :        688 :             OUString aPropName( aNode );
    1962                 :        688 :             aPropName += OUString::valueOf( (sal_Unicode) '/' );
    1963                 :        688 :             aPropName += aCfgLocale;
    1964                 :        688 :             pNames[0] = aPropName;
    1965 [ +  - ][ +  - ]:        688 :             aValues = /*aCfg.*/GetProperties( aNames );
                 [ +  - ]
    1966         [ +  - ]:        688 :             if (aValues.getLength())
    1967 [ +  - ][ +  - ]:        688 :                 aSvcImplNames = GetLangSvcList( aValues.getConstArray()[0] );
                 [ +  - ]
    1968         [ +  - ]:        688 :         }
    1969                 :            :     }
    1970         [ +  + ]:       1712 :     else if ( 0 == rServiceName.compareToAscii( SN_GRAMMARCHECKER ) )
    1971                 :            :     {
    1972                 :        256 :         OUString aNode( "ServiceManager/GrammarCheckerList");
    1973         [ +  - ]:        256 :         const uno::Sequence< OUString > aNodeEntries( GetNodeNames( aNode ) );
    1974 [ +  - ][ +  - ]:        256 :         if (lcl_SeqHasString( aNodeEntries, aCfgLocale ))
    1975                 :            :         {
    1976                 :        256 :             OUString aPropName( aNode );
    1977                 :        256 :             aPropName += OUString::valueOf( (sal_Unicode) '/' );
    1978                 :        256 :             aPropName += aCfgLocale;
    1979                 :        256 :             pNames[0] = aPropName;
    1980 [ +  - ][ +  - ]:        256 :             aValues = /*aCfg.*/GetProperties( aNames );
                 [ +  - ]
    1981         [ +  - ]:        256 :             if (aValues.getLength())
    1982 [ +  - ][ +  - ]:        256 :                 aSvcImplNames = GetLangSvc( aValues.getConstArray()[0] );
                 [ +  - ]
    1983         [ +  - ]:        256 :         }
    1984                 :            :     }
    1985         [ +  + ]:       1456 :     else if ( 0 == rServiceName.compareToAscii( SN_HYPHENATOR ) )
    1986                 :            :     {
    1987                 :        736 :         OUString aNode( "ServiceManager/HyphenatorList");
    1988         [ +  - ]:        736 :         const uno::Sequence< OUString > aNodeEntries( GetNodeNames( aNode ) );
    1989 [ +  - ][ +  - ]:        736 :         if (lcl_SeqHasString( aNodeEntries, aCfgLocale ))
    1990                 :            :         {
    1991                 :        736 :             OUString aPropName( aNode );
    1992                 :        736 :             aPropName += OUString::valueOf( (sal_Unicode) '/' );
    1993                 :        736 :             aPropName += aCfgLocale;
    1994                 :        736 :             pNames[0] = aPropName;
    1995 [ +  - ][ +  - ]:        736 :             aValues = /*aCfg.*/GetProperties( aNames );
                 [ +  - ]
    1996         [ +  - ]:        736 :             if (aValues.getLength())
    1997 [ +  - ][ +  - ]:        736 :                 aSvcImplNames = GetLangSvc( aValues.getConstArray()[0] );
                 [ +  - ]
    1998         [ +  - ]:        736 :         }
    1999                 :            :     }
    2000         [ +  - ]:        720 :     else if ( 0 == rServiceName.compareToAscii( SN_THESAURUS ) )
    2001                 :            :     {
    2002                 :        720 :         OUString aNode( "ServiceManager/ThesaurusList");
    2003         [ +  - ]:        720 :         const uno::Sequence< OUString > aNodeEntries( GetNodeNames( aNode ) );
    2004 [ +  - ][ +  - ]:        720 :         if (lcl_SeqHasString( aNodeEntries, aCfgLocale ))
    2005                 :            :         {
    2006                 :        720 :             OUString aPropName( aNode );
    2007                 :        720 :             aPropName += OUString::valueOf( (sal_Unicode) '/' );
    2008                 :        720 :             aPropName += aCfgLocale;
    2009                 :        720 :             pNames[0] = aPropName;
    2010 [ +  - ][ +  - ]:        720 :             aValues = /*aCfg.*/GetProperties( aNames );
                 [ +  - ]
    2011         [ +  - ]:        720 :             if (aValues.getLength())
    2012 [ +  - ][ +  - ]:        720 :                 aSvcImplNames = GetLangSvcList( aValues.getConstArray()[0] );
                 [ +  - ]
    2013         [ +  - ]:        720 :         }
    2014                 :            :     }
    2015                 :            : 
    2016                 :            : #if OSL_DEBUG_LEVEL > 1
    2017                 :            :     const OUString *pImplNames = aSvcImplNames.getConstArray();
    2018                 :            :     (void) pImplNames;
    2019                 :            : #endif
    2020 [ +  - ][ +  - ]:       2400 :     return aSvcImplNames;
                 [ +  - ]
    2021                 :            : }
    2022                 :            : 
    2023                 :            : 
    2024                 :            : void SAL_CALL
    2025                 :         46 :     LngSvcMgr::dispose()
    2026                 :            :         throw(uno::RuntimeException)
    2027                 :            : {
    2028 [ +  - ][ +  - ]:         46 :     osl::MutexGuard aGuard( GetLinguMutex() );
    2029                 :            : 
    2030         [ +  - ]:         46 :     if (!bDisposing)
    2031                 :            :     {
    2032                 :         46 :         bDisposing = sal_True;
    2033                 :            : 
    2034                 :            :         // require listeners to release this object
    2035 [ +  - ][ +  - ]:         46 :         lang::EventObject aEvtObj( static_cast<XLinguServiceManager*>(this) );
    2036         [ +  - ]:         46 :         aEvtListeners.disposeAndClear( aEvtObj );
    2037                 :            : 
    2038         [ +  + ]:         46 :         if (pListenerHelper)
    2039 [ +  - ][ +  - ]:         46 :             pListenerHelper->DisposeAndClear( aEvtObj );
    2040         [ +  - ]:         46 :     }
    2041                 :         46 : }
    2042                 :            : 
    2043                 :            : 
    2044                 :            : void SAL_CALL
    2045                 :          0 :     LngSvcMgr::addEventListener(
    2046                 :            :             const uno::Reference< lang::XEventListener >& xListener )
    2047                 :            :         throw(uno::RuntimeException)
    2048                 :            : {
    2049 [ #  # ][ #  # ]:          0 :     osl::MutexGuard aGuard( GetLinguMutex() );
    2050                 :            : 
    2051 [ #  # ][ #  # ]:          0 :     if (!bDisposing  &&  xListener.is())
                 [ #  # ]
    2052                 :            :     {
    2053         [ #  # ]:          0 :         aEvtListeners.addInterface( xListener );
    2054         [ #  # ]:          0 :     }
    2055                 :          0 : }
    2056                 :            : 
    2057                 :            : 
    2058                 :            : void SAL_CALL
    2059                 :          0 :     LngSvcMgr::removeEventListener(
    2060                 :            :             const uno::Reference< lang::XEventListener >& xListener )
    2061                 :            :         throw(uno::RuntimeException)
    2062                 :            : {
    2063 [ #  # ][ #  # ]:          0 :     osl::MutexGuard aGuard( GetLinguMutex() );
    2064                 :            : 
    2065         [ #  # ]:          0 :     if (xListener.is())
    2066                 :            :     {
    2067         [ #  # ]:          0 :         aEvtListeners.removeInterface( xListener );
    2068         [ #  # ]:          0 :     }
    2069                 :          0 : }
    2070                 :            : 
    2071                 :            : 
    2072                 :         49 : sal_Bool LngSvcMgr::AddLngSvcEvtBroadcaster(
    2073                 :            :             const uno::Reference< linguistic2::XLinguServiceEventBroadcaster > &rxBroadcaster )
    2074                 :            : {
    2075                 :         49 :     sal_Bool bRes = sal_False;
    2076         [ +  - ]:         49 :     if (rxBroadcaster.is())
    2077                 :            :     {
    2078         [ +  + ]:         49 :         if (!pListenerHelper)
    2079                 :         18 :             GetListenerHelper_Impl();
    2080                 :         49 :         bRes = pListenerHelper->AddLngSvcEvtBroadcaster( rxBroadcaster );
    2081                 :            :     }
    2082                 :         49 :     return bRes;
    2083                 :            : }
    2084                 :            : 
    2085                 :            : 
    2086                 :            : OUString SAL_CALL
    2087                 :          0 :     LngSvcMgr::getImplementationName()
    2088                 :            :         throw(uno::RuntimeException)
    2089                 :            : {
    2090 [ #  # ][ #  # ]:          0 :     osl::MutexGuard aGuard( GetLinguMutex() );
    2091 [ #  # ][ #  # ]:          0 :     return getImplementationName_Static();
    2092                 :            : }
    2093                 :            : 
    2094                 :            : 
    2095                 :            : sal_Bool SAL_CALL
    2096                 :          0 :     LngSvcMgr::supportsService( const OUString& ServiceName )
    2097                 :            :         throw(uno::RuntimeException)
    2098                 :            : {
    2099 [ #  # ][ #  # ]:          0 :     osl::MutexGuard aGuard( GetLinguMutex() );
    2100                 :            : 
    2101         [ #  # ]:          0 :     uno::Sequence< OUString > aSNL = getSupportedServiceNames();
    2102                 :          0 :     const OUString * pArray = aSNL.getConstArray();
    2103         [ #  # ]:          0 :     for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
    2104         [ #  # ]:          0 :         if( pArray[i] == ServiceName )
    2105                 :          0 :             return sal_True;
    2106 [ #  # ][ #  # ]:          0 :     return sal_False;
    2107                 :            : }
    2108                 :            : 
    2109                 :            : 
    2110                 :            : uno::Sequence< OUString > SAL_CALL
    2111                 :          0 :     LngSvcMgr::getSupportedServiceNames()
    2112                 :            :         throw(uno::RuntimeException)
    2113                 :            : {
    2114 [ #  # ][ #  # ]:          0 :     osl::MutexGuard aGuard( GetLinguMutex() );
    2115         [ #  # ]:          0 :     return getSupportedServiceNames_Static();
    2116                 :            : }
    2117                 :            : 
    2118                 :            : 
    2119                 :         46 : uno::Sequence< OUString > LngSvcMgr::getSupportedServiceNames_Static()
    2120                 :            :         throw()
    2121                 :            : {
    2122 [ +  - ][ +  - ]:         46 :     osl::MutexGuard aGuard( GetLinguMutex() );
    2123                 :            : 
    2124         [ +  - ]:         46 :     uno::Sequence< OUString > aSNS( 1 );    // more than 1 service possible
    2125         [ +  - ]:         46 :     aSNS.getArray()[0] = SN_LINGU_SERVCICE_MANAGER;
    2126         [ +  - ]:         46 :     return aSNS;
    2127                 :            : }
    2128                 :            : 
    2129                 :            : 
    2130                 :         46 : uno::Reference< uno::XInterface > SAL_CALL LngSvcMgr_CreateInstance(
    2131                 :            :             const uno::Reference< lang::XMultiServiceFactory > & /*rSMgr*/ )
    2132                 :            :         throw(uno::Exception)
    2133                 :            : {
    2134 [ +  - ][ +  - ]:         46 :     uno::Reference< uno::XInterface > xService = (cppu::OWeakObject*) new LngSvcMgr;
    2135                 :         46 :     return xService;
    2136                 :            : }
    2137                 :            : 
    2138                 :        188 : void * SAL_CALL LngSvcMgr_getFactory(
    2139                 :            :             const sal_Char * pImplName,
    2140                 :            :             lang::XMultiServiceFactory * pServiceManager,
    2141                 :            :             void * /*pRegistryKey*/ )
    2142                 :            : {
    2143                 :            : 
    2144                 :        188 :     void * pRet = 0;
    2145         [ +  + ]:        188 :     if ( !LngSvcMgr::getImplementationName_Static().compareToAscii( pImplName ) )
    2146                 :            :     {
    2147                 :            :         uno::Reference< lang::XSingleServiceFactory > xFactory =
    2148                 :            :             cppu::createOneInstanceFactory(
    2149                 :            :                 pServiceManager,
    2150                 :            :                 LngSvcMgr::getImplementationName_Static(),
    2151                 :            :                 LngSvcMgr_CreateInstance,
    2152 [ +  - ][ +  - ]:         46 :                 LngSvcMgr::getSupportedServiceNames_Static());
         [ +  - ][ +  - ]
    2153                 :            :         // acquire, because we return an interface pointer instead of a reference
    2154         [ +  - ]:         46 :         xFactory->acquire();
    2155         [ +  - ]:         46 :         pRet = xFactory.get();
    2156                 :            :     }
    2157                 :        188 :     return pRet;
    2158                 :            : }
    2159                 :            : 
    2160                 :            : 
    2161                 :            : 
    2162                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10