LCOV - code coverage report
Current view: top level - sfx2/source/menu - thessubmenu.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 52 0.0 %
Date: 2012-08-25 Functions: 0 7 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 106 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : 
      21                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      22                 :            : #include <com/sun/star/linguistic2/XThesaurus.hpp>
      23                 :            : #include <com/sun/star/linguistic2/XMeaning.hpp>
      24                 :            : #include <com/sun/star/linguistic2/XLinguServiceManager.hpp>
      25                 :            : 
      26                 :            : #include <comphelper/processfactory.hxx>
      27                 :            : #include <svl/stritem.hxx>
      28                 :            : #include <tools/debug.hxx>
      29                 :            : #include <vcl/graph.hxx>
      30                 :            : #include <svtools/filter.hxx>
      31                 :            : 
      32                 :            : 
      33                 :            : #include <vector>
      34                 :            : 
      35                 :            : #include <sfx2/bindings.hxx>
      36                 :            : #include <sfx2/dispatch.hxx>
      37                 :            : #include <sfx2/viewsh.hxx>
      38                 :            : #include "thessubmenu.hxx"
      39                 :            : 
      40                 :            : using namespace ::com::sun::star;
      41                 :            : using ::rtl::OUString;
      42                 :            : 
      43                 :          0 : OUString SfxThesSubMenuHelper::GetText(
      44                 :            :     const String &rLookUpString,
      45                 :            :     xub_StrLen nDelimPos )
      46                 :            : {
      47         [ #  # ]:          0 :     return OUString( rLookUpString.Copy( 0, nDelimPos ) );
      48                 :            : }
      49                 :            : 
      50                 :            : 
      51                 :          0 : void SfxThesSubMenuHelper::GetLocale(
      52                 :            :     lang::Locale /*out */ &rLocale,
      53                 :            :     const String &rLookUpString,
      54                 :            :     xub_StrLen nDelimPos  )
      55                 :            : {
      56         [ #  # ]:          0 :     String aIsoLang( rLookUpString.Copy( nDelimPos + 1) );
      57         [ #  # ]:          0 :     const xub_StrLen nPos = aIsoLang.Search( '-' );
      58         [ #  # ]:          0 :     if (nPos != STRING_NOTFOUND)
      59                 :            :     {
      60 [ #  # ][ #  # ]:          0 :         rLocale.Language    = aIsoLang.Copy( 0, nPos );
                 [ #  # ]
      61 [ #  # ][ #  # ]:          0 :         rLocale.Country     = aIsoLang.Copy( nPos + 1 );
                 [ #  # ]
      62 [ #  # ][ #  # ]:          0 :         rLocale.Variant     = String::EmptyString();
      63         [ #  # ]:          0 :     }
      64                 :          0 : }
      65                 :            : 
      66                 :            : 
      67                 :          0 : SfxThesSubMenuHelper::SfxThesSubMenuHelper()
      68                 :            : {
      69                 :            :     try
      70                 :            :     {
      71 [ #  # ][ #  # ]:          0 :         uno::Reference< lang::XMultiServiceFactory >  xMSF( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
      72         [ #  # ]:          0 :         m_xLngMgr = uno::Reference< linguistic2::XLinguServiceManager >( xMSF->createInstance(
      73 [ #  # ][ #  # ]:          0 :                 OUString( "com.sun.star.linguistic2.LinguServiceManager" )), uno::UNO_QUERY_THROW );
                 [ #  # ]
      74 [ #  # ][ #  # ]:          0 :         m_xThesarus = m_xLngMgr->getThesaurus();
         [ #  # ][ #  # ]
      75                 :            :     }
      76         [ #  # ]:          0 :     catch (const uno::Exception &)
      77                 :            :     {
      78                 :            :         DBG_ASSERT( 0, "failed to get thesaurus" );
      79                 :            :     }
      80                 :          0 : }
      81                 :            : 
      82                 :            : 
      83                 :          0 : SfxThesSubMenuHelper::~SfxThesSubMenuHelper()
      84                 :            : {
      85                 :          0 : }
      86                 :            : 
      87                 :            : 
      88                 :          0 : bool SfxThesSubMenuHelper::IsSupportedLocale( const lang::Locale & rLocale ) const
      89                 :            : {
      90 [ #  # ][ #  # ]:          0 :     return m_xThesarus.is() && m_xThesarus->hasLocale( rLocale );
      91                 :            : }
      92                 :            : 
      93                 :            : 
      94                 :          0 : bool SfxThesSubMenuHelper::GetMeanings(
      95                 :            :     std::vector< OUString > & rSynonyms,
      96                 :            :     const OUString & rWord,
      97                 :            :     const lang::Locale & rLocale,
      98                 :            :     sal_Int16 nMaxSynonms )
      99                 :            : {
     100                 :          0 :     bool bHasMoreSynonyms = false;
     101                 :          0 :     rSynonyms.clear();
     102 [ #  # ][ #  # ]:          0 :     if (IsSupportedLocale( rLocale ) && !rWord.isEmpty() && nMaxSynonms > 0)
         [ #  # ][ #  # ]
     103                 :            :     {
     104                 :            :         try
     105                 :            :         {
     106                 :            :             // get all meannings
     107                 :            :             const uno::Sequence< uno::Reference< linguistic2::XMeaning > > aMeaningSeq(
     108 [ #  # ][ #  # ]:          0 :                     m_xThesarus->queryMeanings( rWord, rLocale, uno::Sequence< beans::PropertyValue >() ));
         [ #  # ][ #  # ]
     109                 :          0 :             const uno::Reference< linguistic2::XMeaning > *pxMeaning = aMeaningSeq.getConstArray();
     110                 :          0 :             const sal_Int32 nMeanings = aMeaningSeq.getLength();
     111                 :            : 
     112                 :            :             // iterate over all meanings until nMaxSynonms are found or all meanings are processed
     113                 :          0 :             sal_Int32 nCount = 0;
     114                 :          0 :             sal_Int32 i = 0;
     115 [ #  # ][ #  # ]:          0 :             for ( ;  i < nMeanings && nCount < nMaxSynonms;  ++i)
                 [ #  # ]
     116                 :            :             {
     117 [ #  # ][ #  # ]:          0 :                 const uno::Sequence< OUString > aSynonymSeq( pxMeaning[i]->querySynonyms() );
     118                 :          0 :                 const OUString *pSynonyms = aSynonymSeq.getConstArray();
     119                 :          0 :                 const sal_Int32 nSynonyms = aSynonymSeq.getLength();
     120                 :          0 :                 sal_Int32 k = 0;
     121 [ #  # ][ #  # ]:          0 :                 for ( ;  k < nSynonyms && nCount < nMaxSynonms;  ++k)
                 [ #  # ]
     122                 :            :                 {
     123         [ #  # ]:          0 :                     rSynonyms.push_back( pSynonyms[k] );
     124                 :          0 :                     ++nCount;
     125                 :            :                 }
     126                 :          0 :                 bHasMoreSynonyms = k < nSynonyms;    // any synonym from this meaning skipped?
     127         [ #  # ]:          0 :             }
     128                 :            : 
     129 [ #  # ][ #  # ]:          0 :             bHasMoreSynonyms |= i < nMeanings;   // any meaning skipped?
     130                 :            :         }
     131                 :          0 :         catch (const uno::Exception &)
     132                 :            :         {
     133                 :            :             DBG_ASSERT( 0, "failed to get synonyms" );
     134                 :            :         }
     135                 :            :     }
     136                 :          0 :     return bHasMoreSynonyms;
     137                 :            : }
     138                 :            : 
     139                 :            : 
     140                 :          0 : String SfxThesSubMenuHelper::GetThesImplName( const lang::Locale &rLocale ) const
     141                 :            : {
     142                 :          0 :     String aRes;
     143                 :            :     DBG_ASSERT( m_xLngMgr.is(), "LinguServiceManager missing" );
     144         [ #  # ]:          0 :     if (m_xLngMgr.is())
     145                 :            :     {
     146         [ #  # ]:          0 :         uno::Sequence< OUString > aServiceNames = m_xLngMgr->getConfiguredServices(
     147         [ #  # ]:          0 :                 OUString("com.sun.star.linguistic2.Thesaurus"), rLocale );
     148                 :            :         // there should be at most one thesaurus configured for each language
     149                 :            :         DBG_ASSERT( aServiceNames.getLength() <= 1, "more than one thesaurus found. Should not be possible" );
     150         [ #  # ]:          0 :         if (aServiceNames.getLength() == 1)
     151 [ #  # ][ #  # ]:          0 :             aRes = aServiceNames[0];
                 [ #  # ]
     152                 :            :     }
     153                 :          0 :     return aRes;
     154                 :            : }
     155                 :            : 
     156                 :            : 
     157                 :            : 
     158                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10