LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/menu - thessubmenu.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 47 0.0 %
Date: 2012-12-27 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include <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/LinguServiceManager.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             :     m_xLngMgr(
      69             :         linguistic2::LinguServiceManager::create(
      70             :             comphelper::getProcessComponentContext())),
      71           0 :     m_xThesarus(m_xLngMgr->getThesaurus())
      72             : {
      73           0 : }
      74             : 
      75             : 
      76           0 : SfxThesSubMenuHelper::~SfxThesSubMenuHelper()
      77             : {
      78           0 : }
      79             : 
      80             : 
      81           0 : bool SfxThesSubMenuHelper::IsSupportedLocale( const lang::Locale & rLocale ) const
      82             : {
      83           0 :     return m_xThesarus.is() && m_xThesarus->hasLocale( rLocale );
      84             : }
      85             : 
      86             : 
      87           0 : bool SfxThesSubMenuHelper::GetMeanings(
      88             :     std::vector< OUString > & rSynonyms,
      89             :     const OUString & rWord,
      90             :     const lang::Locale & rLocale,
      91             :     sal_Int16 nMaxSynonms )
      92             : {
      93           0 :     bool bHasMoreSynonyms = false;
      94           0 :     rSynonyms.clear();
      95           0 :     if (IsSupportedLocale( rLocale ) && !rWord.isEmpty() && nMaxSynonms > 0)
      96             :     {
      97             :         try
      98             :         {
      99             :             // get all meannings
     100             :             const uno::Sequence< uno::Reference< linguistic2::XMeaning > > aMeaningSeq(
     101           0 :                     m_xThesarus->queryMeanings( rWord, rLocale, uno::Sequence< beans::PropertyValue >() ));
     102           0 :             const uno::Reference< linguistic2::XMeaning > *pxMeaning = aMeaningSeq.getConstArray();
     103           0 :             const sal_Int32 nMeanings = aMeaningSeq.getLength();
     104             : 
     105             :             // iterate over all meanings until nMaxSynonms are found or all meanings are processed
     106           0 :             sal_Int32 nCount = 0;
     107           0 :             sal_Int32 i = 0;
     108           0 :             for ( ;  i < nMeanings && nCount < nMaxSynonms;  ++i)
     109             :             {
     110           0 :                 const uno::Sequence< OUString > aSynonymSeq( pxMeaning[i]->querySynonyms() );
     111           0 :                 const OUString *pSynonyms = aSynonymSeq.getConstArray();
     112           0 :                 const sal_Int32 nSynonyms = aSynonymSeq.getLength();
     113           0 :                 sal_Int32 k = 0;
     114           0 :                 for ( ;  k < nSynonyms && nCount < nMaxSynonms;  ++k)
     115             :                 {
     116           0 :                     rSynonyms.push_back( pSynonyms[k] );
     117           0 :                     ++nCount;
     118             :                 }
     119           0 :                 bHasMoreSynonyms = k < nSynonyms;    // any synonym from this meaning skipped?
     120           0 :             }
     121             : 
     122           0 :             bHasMoreSynonyms |= i < nMeanings;   // any meaning skipped?
     123             :         }
     124           0 :         catch (const uno::Exception &)
     125             :         {
     126             :             DBG_ASSERT( 0, "failed to get synonyms" );
     127             :         }
     128             :     }
     129           0 :     return bHasMoreSynonyms;
     130             : }
     131             : 
     132             : 
     133           0 : String SfxThesSubMenuHelper::GetThesImplName( const lang::Locale &rLocale ) const
     134             : {
     135           0 :     String aRes;
     136           0 :     uno::Sequence< OUString > aServiceNames = m_xLngMgr->getConfiguredServices(
     137           0 :             OUString("com.sun.star.linguistic2.Thesaurus"), rLocale );
     138             :     // there should be at most one thesaurus configured for each language
     139             :     DBG_ASSERT( aServiceNames.getLength() <= 1, "more than one thesaurus found. Should not be possible" );
     140           0 :     if (aServiceNames.getLength() == 1)
     141           0 :         aRes = aServiceNames[0];
     142           0 :     return aRes;
     143             : }
     144             : 
     145             : 
     146             : 
     147             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10