LCOV - code coverage report
Current view: top level - sfx2/source/menu - thessubmenu.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 42 0.0 %
Date: 2014-04-11 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 <vcl/graphicfilter.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             : 
      42           0 : OUString SfxThesSubMenuHelper::GetText(
      43             :     const OUString &rLookUpString,
      44             :     sal_Int32 nDelimPos )
      45             : {
      46           0 :     return rLookUpString.copy( 0, nDelimPos );
      47             : }
      48             : 
      49             : 
      50           0 : void SfxThesSubMenuHelper::GetLocale(
      51             :     lang::Locale /*out */ &rLocale,
      52             :     const OUString &rLookUpString,
      53             :     sal_Int32 nDelimPos  )
      54             : {
      55           0 :     OUString aIsoLang( rLookUpString.copy( nDelimPos + 1) );
      56           0 :     rLocale = LanguageTag::convertToLocale( aIsoLang);
      57           0 : }
      58             : 
      59             : 
      60           0 : SfxThesSubMenuHelper::SfxThesSubMenuHelper():
      61             :     m_xLngMgr(
      62             :         linguistic2::LinguServiceManager::create(
      63             :             comphelper::getProcessComponentContext())),
      64           0 :     m_xThesarus(m_xLngMgr->getThesaurus())
      65             : {
      66           0 : }
      67             : 
      68             : 
      69           0 : SfxThesSubMenuHelper::~SfxThesSubMenuHelper()
      70             : {
      71           0 : }
      72             : 
      73             : 
      74           0 : bool SfxThesSubMenuHelper::IsSupportedLocale( const lang::Locale & rLocale ) const
      75             : {
      76           0 :     return m_xThesarus.is() && m_xThesarus->hasLocale( rLocale );
      77             : }
      78             : 
      79             : 
      80           0 : bool SfxThesSubMenuHelper::GetMeanings(
      81             :     std::vector< OUString > & rSynonyms,
      82             :     const OUString & rWord,
      83             :     const lang::Locale & rLocale,
      84             :     sal_Int16 nMaxSynonms )
      85             : {
      86           0 :     bool bHasMoreSynonyms = false;
      87           0 :     rSynonyms.clear();
      88           0 :     if (IsSupportedLocale( rLocale ) && !rWord.isEmpty() && nMaxSynonms > 0)
      89             :     {
      90             :         try
      91             :         {
      92             :             // get all meannings
      93             :             const uno::Sequence< uno::Reference< linguistic2::XMeaning > > aMeaningSeq(
      94           0 :                     m_xThesarus->queryMeanings( rWord, rLocale, uno::Sequence< beans::PropertyValue >() ));
      95           0 :             const uno::Reference< linguistic2::XMeaning > *pxMeaning = aMeaningSeq.getConstArray();
      96           0 :             const sal_Int32 nMeanings = aMeaningSeq.getLength();
      97             : 
      98             :             // iterate over all meanings until nMaxSynonms are found or all meanings are processed
      99           0 :             sal_Int32 nCount = 0;
     100           0 :             sal_Int32 i = 0;
     101           0 :             for ( ;  i < nMeanings && nCount < nMaxSynonms;  ++i)
     102             :             {
     103           0 :                 const uno::Sequence< OUString > aSynonymSeq( pxMeaning[i]->querySynonyms() );
     104           0 :                 const OUString *pSynonyms = aSynonymSeq.getConstArray();
     105           0 :                 const sal_Int32 nSynonyms = aSynonymSeq.getLength();
     106           0 :                 sal_Int32 k = 0;
     107           0 :                 for ( ;  k < nSynonyms && nCount < nMaxSynonms;  ++k)
     108             :                 {
     109           0 :                     rSynonyms.push_back( pSynonyms[k] );
     110           0 :                     ++nCount;
     111             :                 }
     112           0 :                 bHasMoreSynonyms = k < nSynonyms;    // any synonym from this meaning skipped?
     113           0 :             }
     114             : 
     115           0 :             bHasMoreSynonyms |= i < nMeanings;   // any meaning skipped?
     116             :         }
     117           0 :         catch (const uno::Exception &)
     118             :         {
     119             :             DBG_ASSERT( false, "failed to get synonyms" );
     120             :         }
     121             :     }
     122           0 :     return bHasMoreSynonyms;
     123             : }
     124             : 
     125             : 
     126           0 : OUString SfxThesSubMenuHelper::GetThesImplName( const lang::Locale &rLocale ) const
     127             : {
     128           0 :     OUString aRes;
     129           0 :     uno::Sequence< OUString > aServiceNames = m_xLngMgr->getConfiguredServices(
     130           0 :             OUString("com.sun.star.linguistic2.Thesaurus"), rLocale );
     131             :     // there should be at most one thesaurus configured for each language
     132             :     DBG_ASSERT( aServiceNames.getLength() <= 1, "more than one thesaurus found. Should not be possible" );
     133           0 :     if (aServiceNames.getLength() == 1)
     134           0 :         aRes = aServiceNames[0];
     135           0 :     return aRes;
     136             : }
     137             : 
     138             : 
     139             : 
     140             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10