loplugin:flatten in linguistic

Change-Id: I5dc83e3f3697ccd6a482c799af267587a77563c3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91799
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2020-04-07 13:11:35 +02:00
parent 6a2d03e7c7
commit e411063329
7 changed files with 536 additions and 536 deletions
+13 -13
View File
@@ -228,21 +228,21 @@ void ConvDicXMLEntryTextContext_Impl::startFastElement(
sal_Int32 /*Element*/,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& rxAttrList )
{
if ( rxAttrList.is() )
{
sax_fastparser::FastAttributeList *pAttribList =
sax_fastparser::FastAttributeList::castToFastAttributeList( rxAttrList );
if ( !rxAttrList.is() )
return;
for (auto &aIter : *pAttribList)
sax_fastparser::FastAttributeList *pAttribList =
sax_fastparser::FastAttributeList::castToFastAttributeList( rxAttrList );
for (auto &aIter : *pAttribList)
{
switch (aIter.getToken())
{
switch (aIter.getToken())
{
case XML_NAMESPACE_TCD | XML_LEFT_TEXT:
aLeftText = aIter.toString();
break;
default:
;
}
case XML_NAMESPACE_TCD | XML_LEFT_TEXT:
aLeftText = aIter.toString();
break;
default:
;
}
}
}
+19 -19
View File
@@ -764,31 +764,31 @@ void SAL_CALL DictionaryNeo::setActive( sal_Bool bActivate )
{
MutexGuard aGuard( GetLinguMutex() );
if (bIsActive != bool(bActivate))
if (bIsActive == bool(bActivate))
return;
bIsActive = bActivate;
sal_Int16 nEvent = bIsActive ?
DictionaryEventFlags::ACTIVATE_DIC : DictionaryEventFlags::DEACTIVATE_DIC;
// remove entries from memory if dictionary is deactivated
if (!bIsActive)
{
bIsActive = bActivate;
sal_Int16 nEvent = bIsActive ?
DictionaryEventFlags::ACTIVATE_DIC : DictionaryEventFlags::DEACTIVATE_DIC;
bool bIsEmpty = aEntries.empty();
// remove entries from memory if dictionary is deactivated
if (!bIsActive)
// save entries first if necessary
if (bIsModified && hasLocation() && !isReadonly())
{
bool bIsEmpty = aEntries.empty();
store();
// save entries first if necessary
if (bIsModified && hasLocation() && !isReadonly())
{
store();
aEntries.clear();
bNeedEntries = !bIsEmpty;
}
DBG_ASSERT( !bIsModified || !hasLocation() || isReadonly(),
"lng : dictionary is still modified" );
aEntries.clear();
bNeedEntries = !bIsEmpty;
}
launchEvent(nEvent, nullptr);
DBG_ASSERT( !bIsModified || !hasLocation() || isReadonly(),
"lng : dictionary is still modified" );
}
launchEvent(nEvent, nullptr);
}
sal_Bool SAL_CALL DictionaryNeo::isActive( )
+60 -60
View File
@@ -522,46 +522,46 @@ void SAL_CALL
{
osl::MutexGuard aGuard( GetLinguMutex() );
if (!bDisposing)
if (bDisposing)
return;
bDisposing = true;
EventObject aEvtObj( static_cast<XDictionaryList *>(this) );
aEvtListeners.disposeAndClear( aEvtObj );
if (mxDicEvtLstnrHelper.is())
mxDicEvtLstnrHelper->DisposeAndClear( aEvtObj );
//! avoid creation of dictionaries if not already done
if ( !aDicList.empty() )
{
bDisposing = true;
EventObject aEvtObj( static_cast<XDictionaryList *>(this) );
aEvtListeners.disposeAndClear( aEvtObj );
if (mxDicEvtLstnrHelper.is())
mxDicEvtLstnrHelper->DisposeAndClear( aEvtObj );
//! avoid creation of dictionaries if not already done
if ( !aDicList.empty() )
DictionaryVec_t& rDicList = GetOrCreateDicList();
size_t nCount = rDicList.size();
for (size_t i = 0; i < nCount; i++)
{
DictionaryVec_t& rDicList = GetOrCreateDicList();
size_t nCount = rDicList.size();
for (size_t i = 0; i < nCount; i++)
uno::Reference< XDictionary > xDic( rDicList[i], UNO_QUERY );
// save (modified) dictionaries
uno::Reference< frame::XStorable > xStor( xDic , UNO_QUERY );
if (xStor.is())
{
uno::Reference< XDictionary > xDic( rDicList[i], UNO_QUERY );
// save (modified) dictionaries
uno::Reference< frame::XStorable > xStor( xDic , UNO_QUERY );
if (xStor.is())
try
{
if (!xStor->isReadonly() && xStor->hasLocation())
xStor->store();
}
catch(Exception &)
{
try
{
if (!xStor->isReadonly() && xStor->hasLocation())
xStor->store();
}
catch(Exception &)
{
}
}
// release references to (members of) this object hold by
// dictionaries
if (xDic.is())
xDic->removeDictionaryEventListener( mxDicEvtLstnrHelper.get() );
}
// release references to (members of) this object hold by
// dictionaries
if (xDic.is())
xDic->removeDictionaryEventListener( mxDicEvtLstnrHelper.get() );
}
mxDicEvtLstnrHelper.clear();
}
mxDicEvtLstnrHelper.clear();
}
void SAL_CALL
@@ -639,25 +639,25 @@ void DicList::SaveDics()
{
// save dics only if they have already been used/created.
//! don't create them just for the purpose of saving them !
if ( !aDicList.empty() )
if ( aDicList.empty() )
return;
// save (modified) dictionaries
DictionaryVec_t& rDicList = GetOrCreateDicList();
size_t nCount = rDicList.size();
for (size_t i = 0; i < nCount; i++)
{
// save (modified) dictionaries
DictionaryVec_t& rDicList = GetOrCreateDicList();
size_t nCount = rDicList.size();
for (size_t i = 0; i < nCount; i++)
uno::Reference< frame::XStorable > xStor( rDicList[i], UNO_QUERY );
if (xStor.is())
{
// save (modified) dictionaries
uno::Reference< frame::XStorable > xStor( rDicList[i], UNO_QUERY );
if (xStor.is())
try
{
if (!xStor->isReadonly() && xStor->hasLocation())
xStor->store();
}
catch(Exception &)
{
try
{
if (!xStor->isReadonly() && xStor->hasLocation())
xStor->store();
}
catch(Exception &)
{
}
}
}
}
@@ -745,21 +745,21 @@ static void AddInternal(
const uno::Reference<XDictionary> &rDic,
const OUString& rNew )
{
if (rDic.is())
{
//! TL TODO: word iterator should be used to break up the text
OUString aDelim("!\"#$%&'()*+,-/:;<=>?[]\\_^`{|}~\t \n");
OSL_ENSURE(aDelim.indexOf(u'.') == -1,
"ensure no '.'");
if (!rDic.is())
return;
OUString aToken;
sal_Int32 nPos = 0;
while (-1 != (nPos = lcl_GetToken( aToken, rNew, nPos, aDelim )))
//! TL TODO: word iterator should be used to break up the text
OUString aDelim("!\"#$%&'()*+,-/:;<=>?[]\\_^`{|}~\t \n");
OSL_ENSURE(aDelim.indexOf(u'.') == -1,
"ensure no '.'");
OUString aToken;
sal_Int32 nPos = 0;
while (-1 != (nPos = lcl_GetToken( aToken, rNew, nPos, aDelim )))
{
if( !aToken.isEmpty() && !IsNumeric( aToken ) )
{
if( !aToken.isEmpty() && !IsNumeric( aToken ) )
{
rDic->add( aToken, false, OUString() );
}
rDic->add( aToken, false, OUString() );
}
}
}
+34 -34
View File
@@ -354,24 +354,24 @@ void GrammarCheckingIterator::AddEntry(
// we may not need/have a xFlatParaIterator (e.g. if checkGrammarAtPos was called)
// but we always need a xFlatPara...
uno::Reference< text::XFlatParagraph > xPara( xFlatPara );
if (xPara.is())
{
FPEntry aNewFPEntry;
aNewFPEntry.m_xParaIterator = xFlatParaIterator;
aNewFPEntry.m_xPara = xFlatPara;
aNewFPEntry.m_aDocId = rDocId;
aNewFPEntry.m_nStartIndex = nStartIndex;
aNewFPEntry.m_bAutomatic = bAutomatic;
if (!xPara.is())
return;
// add new entry to the end of this queue
::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() );
if (!m_thread)
m_thread = osl_createThread( lcl_workerfunc, this );
m_aFPEntriesQueue.push_back( aNewFPEntry );
FPEntry aNewFPEntry;
aNewFPEntry.m_xParaIterator = xFlatParaIterator;
aNewFPEntry.m_xPara = xFlatPara;
aNewFPEntry.m_aDocId = rDocId;
aNewFPEntry.m_nStartIndex = nStartIndex;
aNewFPEntry.m_bAutomatic = bAutomatic;
// wake up the thread in order to do grammar checking
m_aWakeUpThread.set();
}
// add new entry to the end of this queue
::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() );
if (!m_thread)
m_thread = osl_createThread( lcl_workerfunc, this );
m_aFPEntriesQueue.push_back( aNewFPEntry );
// wake up the thread in order to do grammar checking
m_aWakeUpThread.set();
}
@@ -922,25 +922,25 @@ sal_Bool SAL_CALL GrammarCheckingIterator::isProofreading(
void SAL_CALL GrammarCheckingIterator::processLinguServiceEvent(
const linguistic2::LinguServiceEvent& rLngSvcEvent )
{
if (rLngSvcEvent.nEvent == linguistic2::LinguServiceEventFlags::PROOFREAD_AGAIN)
if (rLngSvcEvent.nEvent != linguistic2::LinguServiceEventFlags::PROOFREAD_AGAIN)
return;
try
{
try
{
uno::Reference< uno::XInterface > xThis( static_cast< OWeakObject * >(this) );
linguistic2::LinguServiceEvent aEvent( xThis, linguistic2::LinguServiceEventFlags::PROOFREAD_AGAIN );
m_aNotifyListeners.notifyEach(
&linguistic2::XLinguServiceEventListener::processLinguServiceEvent,
aEvent);
}
catch (uno::RuntimeException &)
{
throw;
}
catch (const ::uno::Exception &)
{
// ignore
TOOLS_WARN_EXCEPTION("linguistic", "processLinguServiceEvent");
}
uno::Reference< uno::XInterface > xThis( static_cast< OWeakObject * >(this) );
linguistic2::LinguServiceEvent aEvent( xThis, linguistic2::LinguServiceEventFlags::PROOFREAD_AGAIN );
m_aNotifyListeners.notifyEach(
&linguistic2::XLinguServiceEventListener::processLinguServiceEvent,
aEvent);
}
catch (uno::RuntimeException &)
{
throw;
}
catch (const ::uno::Exception &)
{
// ignore
TOOLS_WARN_EXCEPTION("linguistic", "processLinguServiceEvent");
}
}
+12 -12
View File
@@ -149,19 +149,19 @@ void SAL_CALL FlushListener::processDictionaryListEvent(
{
MutexGuard aGuard( GetLinguMutex() );
if (rDicListEvent.Source == xDicList)
{
sal_Int16 nEvt = rDicListEvent.nCondensedEvent;
sal_Int16 const nFlushFlags =
DictionaryListEventFlags::ADD_NEG_ENTRY |
DictionaryListEventFlags::DEL_POS_ENTRY |
DictionaryListEventFlags::ACTIVATE_NEG_DIC |
DictionaryListEventFlags::DEACTIVATE_POS_DIC;
bool bFlush = 0 != (nEvt & nFlushFlags);
if (rDicListEvent.Source != xDicList)
return;
if (bFlush)
mrSpellCache.Flush();
}
sal_Int16 nEvt = rDicListEvent.nCondensedEvent;
sal_Int16 const nFlushFlags =
DictionaryListEventFlags::ADD_NEG_ENTRY |
DictionaryListEventFlags::DEL_POS_ENTRY |
DictionaryListEventFlags::ACTIVATE_NEG_DIC |
DictionaryListEventFlags::DEACTIVATE_POS_DIC;
bool bFlush = 0 != (nEvt & nFlushFlags);
if (bFlush)
mrSpellCache.Flush();
}
+82 -82
View File
@@ -108,29 +108,29 @@ void PropertyChgHelper::SetDefaultValues()
void PropertyChgHelper::GetCurrentValues()
{
const auto& rPropNames = GetPropNames();
if (GetPropSet().is() && rPropNames.hasElements())
if (!(GetPropSet().is() && rPropNames.hasElements()))
return;
for (const OUString& rPropName : rPropNames)
{
for (const OUString& rPropName : rPropNames)
bool *pbVal = nullptr,
*pbResVal = nullptr;
if ( rPropName == UPN_IS_IGNORE_CONTROL_CHARACTERS )
{
bool *pbVal = nullptr,
*pbResVal = nullptr;
pbVal = &bIsIgnoreControlCharacters;
pbResVal = &bResIsIgnoreControlCharacters;
}
else if ( rPropName == UPN_IS_USE_DICTIONARY_LIST )
{
pbVal = &bIsUseDictionaryList;
pbResVal = &bResIsUseDictionaryList;
}
if ( rPropName == UPN_IS_IGNORE_CONTROL_CHARACTERS )
{
pbVal = &bIsIgnoreControlCharacters;
pbResVal = &bResIsIgnoreControlCharacters;
}
else if ( rPropName == UPN_IS_USE_DICTIONARY_LIST )
{
pbVal = &bIsUseDictionaryList;
pbResVal = &bResIsUseDictionaryList;
}
if (pbVal && pbResVal)
{
GetPropSet()->getPropertyValue( rPropName ) >>= *pbVal;
*pbResVal = *pbVal;
}
if (pbVal && pbResVal)
{
GetPropSet()->getPropertyValue( rPropName ) >>= *pbVal;
*pbResVal = *pbVal;
}
}
}
@@ -358,34 +358,34 @@ void PropertyHelper_Spell::GetCurrentValues()
PropertyChgHelper::GetCurrentValues();
const auto& rPropNames = GetPropNames();
if (GetPropSet().is() && rPropNames.hasElements())
if (!(GetPropSet().is() && rPropNames.hasElements()))
return;
for (const OUString& rPropName : rPropNames)
{
for (const OUString& rPropName : rPropNames)
bool *pbVal = nullptr,
*pbResVal = nullptr;
if ( rPropName == UPN_IS_SPELL_UPPER_CASE )
{
bool *pbVal = nullptr,
*pbResVal = nullptr;
pbVal = &bIsSpellUpperCase;
pbResVal = &bResIsSpellUpperCase;
}
else if ( rPropName == UPN_IS_SPELL_WITH_DIGITS )
{
pbVal = &bIsSpellWithDigits;
pbResVal = &bResIsSpellWithDigits;
}
else if ( rPropName == UPN_IS_SPELL_CAPITALIZATION )
{
pbVal = &bIsSpellCapitalization;
pbResVal = &bResIsSpellCapitalization;
}
if ( rPropName == UPN_IS_SPELL_UPPER_CASE )
{
pbVal = &bIsSpellUpperCase;
pbResVal = &bResIsSpellUpperCase;
}
else if ( rPropName == UPN_IS_SPELL_WITH_DIGITS )
{
pbVal = &bIsSpellWithDigits;
pbResVal = &bResIsSpellWithDigits;
}
else if ( rPropName == UPN_IS_SPELL_CAPITALIZATION )
{
pbVal = &bIsSpellCapitalization;
pbResVal = &bResIsSpellCapitalization;
}
if (pbVal && pbResVal)
{
GetPropSet()->getPropertyValue( rPropName ) >>= *pbVal;
*pbResVal = *pbVal;
}
if (pbVal && pbResVal)
{
GetPropSet()->getPropertyValue( rPropName ) >>= *pbVal;
*pbResVal = *pbVal;
}
}
}
@@ -531,46 +531,46 @@ void PropertyHelper_Hyphen::GetCurrentValues()
PropertyChgHelper::GetCurrentValues();
const auto& rPropNames = GetPropNames();
if (GetPropSet().is() && rPropNames.hasElements())
if (!(GetPropSet().is() && rPropNames.hasElements()))
return;
for (const OUString& rPropName : rPropNames)
{
for (const OUString& rPropName : rPropNames)
sal_Int16 *pnVal = nullptr,
*pnResVal = nullptr;
bool *pbVal = nullptr;
bool *pbResVal = nullptr;
if ( rPropName == UPN_HYPH_MIN_LEADING )
{
sal_Int16 *pnVal = nullptr,
*pnResVal = nullptr;
bool *pbVal = nullptr;
bool *pbResVal = nullptr;
pnVal = &nHyphMinLeading;
pnResVal = &nResHyphMinLeading;
}
else if ( rPropName == UPN_HYPH_MIN_TRAILING )
{
pnVal = &nHyphMinTrailing;
pnResVal = &nResHyphMinTrailing;
}
else if ( rPropName == UPN_HYPH_MIN_WORD_LENGTH )
{
pnVal = &nHyphMinWordLength;
pnResVal = &nResHyphMinWordLength;
}
else if ( rPropName == UPN_HYPH_NO_CAPS )
{
pbVal = &bNoHyphenateCaps;
pbResVal = &bResNoHyphenateCaps;
}
if ( rPropName == UPN_HYPH_MIN_LEADING )
{
pnVal = &nHyphMinLeading;
pnResVal = &nResHyphMinLeading;
}
else if ( rPropName == UPN_HYPH_MIN_TRAILING )
{
pnVal = &nHyphMinTrailing;
pnResVal = &nResHyphMinTrailing;
}
else if ( rPropName == UPN_HYPH_MIN_WORD_LENGTH )
{
pnVal = &nHyphMinWordLength;
pnResVal = &nResHyphMinWordLength;
}
else if ( rPropName == UPN_HYPH_NO_CAPS )
{
pbVal = &bNoHyphenateCaps;
pbResVal = &bResNoHyphenateCaps;
}
if (pnVal && pnResVal)
{
GetPropSet()->getPropertyValue( rPropName ) >>= *pnVal;
*pnResVal = *pnVal;
}
else if (pbVal && pbResVal)
{
GetPropSet()->getPropertyValue( rPropName ) >>= *pbVal;
*pbResVal = *pbVal;
}
if (pnVal && pnResVal)
{
GetPropSet()->getPropertyValue( rPropName ) >>= *pnVal;
*pnResVal = *pnVal;
}
else if (pbVal && pbResVal)
{
GetPropSet()->getPropertyValue( rPropName ) >>= *pbVal;
*pbResVal = *pbVal;
}
}
}
+316 -316
View File
@@ -480,19 +480,19 @@ void LngSvcMgr::stopListening()
{
osl::MutexGuard aGuard(GetLinguMutex());
if (xMB.is())
{
try
{
uno::Reference<util::XModifyListener> xListener(this);
xMB->removeModifyListener(xListener);
}
catch (const uno::Exception&)
{
}
if (!xMB.is())
return;
xMB.clear();
try
{
uno::Reference<util::XModifyListener> xListener(this);
xMB->removeModifyListener(xListener);
}
catch (const uno::Exception&)
{
}
xMB.clear();
}
void LngSvcMgr::disposing(const lang::EventObject&)
@@ -873,27 +873,27 @@ void LngSvcMgr::GetSpellCheckerDsp_Impl( bool bSetSvcList )
void LngSvcMgr::GetGrammarCheckerDsp_Impl( bool bSetSvcList )
{
if (!mxGrammarDsp.is() && SvtLinguConfig().HasGrammarChecker())
{
//! since the grammar checking iterator needs to be a one instance service
//! we need to create it the correct way!
uno::Reference< linguistic2::XProofreadingIterator > xGCI;
try
{
xGCI = linguistic2::ProofreadingIterator::create( comphelper::getProcessComponentContext() );
}
catch (const uno::Exception &)
{
}
SAL_WARN_IF( !xGCI.is(), "linguistic", "instantiating grammar checking iterator failed" );
if (!(!mxGrammarDsp.is() && SvtLinguConfig().HasGrammarChecker()))
return;
if (xGCI.is())
{
mxGrammarDsp = dynamic_cast< GrammarCheckingIterator * >(xGCI.get());
SAL_WARN_IF( mxGrammarDsp == nullptr, "linguistic", "failed to get implementation" );
if (bSetSvcList && mxGrammarDsp.is())
SetCfgServiceLists( *mxGrammarDsp );
}
//! since the grammar checking iterator needs to be a one instance service
//! we need to create it the correct way!
uno::Reference< linguistic2::XProofreadingIterator > xGCI;
try
{
xGCI = linguistic2::ProofreadingIterator::create( comphelper::getProcessComponentContext() );
}
catch (const uno::Exception &)
{
}
SAL_WARN_IF( !xGCI.is(), "linguistic", "instantiating grammar checking iterator failed" );
if (xGCI.is())
{
mxGrammarDsp = dynamic_cast< GrammarCheckingIterator * >(xGCI.get());
SAL_WARN_IF( mxGrammarDsp == nullptr, "linguistic", "failed to get implementation" );
if (bSetSvcList && mxGrammarDsp.is())
SetCfgServiceLists( *mxGrammarDsp );
}
}
@@ -922,57 +922,57 @@ void LngSvcMgr::GetThesaurusDsp_Impl( bool bSetSvcList )
void LngSvcMgr::GetAvailableSpellSvcs_Impl()
{
if (!pAvailSpellSvcs)
if (pAvailSpellSvcs)
return;
pAvailSpellSvcs.reset(new SvcInfoArray);
uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
uno::Reference< container::XContentEnumerationAccess > xEnumAccess( xContext->getServiceManager(), uno::UNO_QUERY );
uno::Reference< container::XEnumeration > xEnum;
if (xEnumAccess.is())
xEnum = xEnumAccess->createContentEnumeration( SN_SPELLCHECKER );
if (!xEnum.is())
return;
while (xEnum->hasMoreElements())
{
pAvailSpellSvcs.reset(new SvcInfoArray);
uno::Any aCurrent = xEnum->nextElement();
uno::Reference< lang::XSingleComponentFactory > xCompFactory;
uno::Reference< lang::XSingleServiceFactory > xFactory;
uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
uno::Reference< container::XContentEnumerationAccess > xEnumAccess( xContext->getServiceManager(), uno::UNO_QUERY );
uno::Reference< container::XEnumeration > xEnum;
if (xEnumAccess.is())
xEnum = xEnumAccess->createContentEnumeration( SN_SPELLCHECKER );
if (xEnum.is())
uno::Reference< linguistic2::XSpellChecker > xSvc;
xCompFactory.set(aCurrent, css::uno::UNO_QUERY);
if (!xCompFactory.is())
{
while (xEnum->hasMoreElements())
xFactory.set(aCurrent, css::uno::UNO_QUERY);
}
if ( xCompFactory.is() || xFactory.is() )
{
try
{
uno::Any aCurrent = xEnum->nextElement();
uno::Reference< lang::XSingleComponentFactory > xCompFactory;
uno::Reference< lang::XSingleServiceFactory > xFactory;
uno::Reference< linguistic2::XSpellChecker > xSvc;
xCompFactory.set(aCurrent, css::uno::UNO_QUERY);
if (!xCompFactory.is())
{
xFactory.set(aCurrent, css::uno::UNO_QUERY);
}
if ( xCompFactory.is() || xFactory.is() )
{
try
{
xSvc.set( ( xCompFactory.is() ? xCompFactory->createInstanceWithContext( xContext ) : xFactory->createInstance() ), uno::UNO_QUERY );
}
catch (const uno::Exception &)
{
SAL_WARN( "linguistic", "createInstance failed" );
}
}
if (xSvc.is())
{
OUString aImplName;
std::vector< LanguageType > aLanguages;
uno::Reference< XServiceInfo > xInfo( xSvc, uno::UNO_QUERY );
if (xInfo.is())
aImplName = xInfo->getImplementationName();
SAL_WARN_IF( aImplName.isEmpty(), "linguistic", "empty implementation name" );
uno::Sequence<lang::Locale> aLocaleSequence(xSvc->getLocales());
aLanguages = LocaleSeqToLangVec( aLocaleSequence );
pAvailSpellSvcs->push_back( std::make_unique<SvcInfo>( aImplName, aLanguages ) );
}
xSvc.set( ( xCompFactory.is() ? xCompFactory->createInstanceWithContext( xContext ) : xFactory->createInstance() ), uno::UNO_QUERY );
}
catch (const uno::Exception &)
{
SAL_WARN( "linguistic", "createInstance failed" );
}
}
if (xSvc.is())
{
OUString aImplName;
std::vector< LanguageType > aLanguages;
uno::Reference< XServiceInfo > xInfo( xSvc, uno::UNO_QUERY );
if (xInfo.is())
aImplName = xInfo->getImplementationName();
SAL_WARN_IF( aImplName.isEmpty(), "linguistic", "empty implementation name" );
uno::Sequence<lang::Locale> aLocaleSequence(xSvc->getLocales());
aLanguages = LocaleSeqToLangVec( aLocaleSequence );
pAvailSpellSvcs->push_back( std::make_unique<SvcInfo>( aImplName, aLanguages ) );
}
}
}
@@ -980,57 +980,57 @@ void LngSvcMgr::GetAvailableSpellSvcs_Impl()
void LngSvcMgr::GetAvailableGrammarSvcs_Impl()
{
if (!pAvailGrammarSvcs)
if (pAvailGrammarSvcs)
return;
pAvailGrammarSvcs.reset(new SvcInfoArray);
uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
uno::Reference< container::XContentEnumerationAccess > xEnumAccess( xContext->getServiceManager(), uno::UNO_QUERY );
uno::Reference< container::XEnumeration > xEnum;
if (xEnumAccess.is())
xEnum = xEnumAccess->createContentEnumeration( SN_GRAMMARCHECKER );
if (!xEnum.is())
return;
while (xEnum->hasMoreElements())
{
pAvailGrammarSvcs.reset(new SvcInfoArray);
uno::Any aCurrent = xEnum->nextElement();
uno::Reference< lang::XSingleComponentFactory > xCompFactory;
uno::Reference< lang::XSingleServiceFactory > xFactory;
uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
uno::Reference< container::XContentEnumerationAccess > xEnumAccess( xContext->getServiceManager(), uno::UNO_QUERY );
uno::Reference< container::XEnumeration > xEnum;
if (xEnumAccess.is())
xEnum = xEnumAccess->createContentEnumeration( SN_GRAMMARCHECKER );
if (xEnum.is())
uno::Reference< linguistic2::XProofreader > xSvc;
xCompFactory.set(aCurrent, css::uno::UNO_QUERY);
if (!xCompFactory.is())
{
while (xEnum->hasMoreElements())
xFactory.set(aCurrent, css::uno::UNO_QUERY);
}
if ( xCompFactory.is() || xFactory.is() )
{
try
{
uno::Any aCurrent = xEnum->nextElement();
uno::Reference< lang::XSingleComponentFactory > xCompFactory;
uno::Reference< lang::XSingleServiceFactory > xFactory;
uno::Reference< linguistic2::XProofreader > xSvc;
xCompFactory.set(aCurrent, css::uno::UNO_QUERY);
if (!xCompFactory.is())
{
xFactory.set(aCurrent, css::uno::UNO_QUERY);
}
if ( xCompFactory.is() || xFactory.is() )
{
try
{
xSvc.set( ( xCompFactory.is() ? xCompFactory->createInstanceWithContext( xContext ) : xFactory->createInstance() ), uno::UNO_QUERY );
}
catch (const uno::Exception &)
{
SAL_WARN( "linguistic", "createInstance failed" );
}
}
if (xSvc.is() && pAvailGrammarSvcs)
{
OUString aImplName;
std::vector< LanguageType > aLanguages;
uno::Reference< XServiceInfo > xInfo( xSvc, uno::UNO_QUERY );
if (xInfo.is())
aImplName = xInfo->getImplementationName();
SAL_WARN_IF( aImplName.isEmpty(), "linguistic", "empty implementation name" );
uno::Sequence<lang::Locale> aLocaleSequence(xSvc->getLocales());
aLanguages = LocaleSeqToLangVec( aLocaleSequence );
pAvailGrammarSvcs->push_back( std::make_unique<SvcInfo>( aImplName, aLanguages ) );
}
xSvc.set( ( xCompFactory.is() ? xCompFactory->createInstanceWithContext( xContext ) : xFactory->createInstance() ), uno::UNO_QUERY );
}
catch (const uno::Exception &)
{
SAL_WARN( "linguistic", "createInstance failed" );
}
}
if (xSvc.is() && pAvailGrammarSvcs)
{
OUString aImplName;
std::vector< LanguageType > aLanguages;
uno::Reference< XServiceInfo > xInfo( xSvc, uno::UNO_QUERY );
if (xInfo.is())
aImplName = xInfo->getImplementationName();
SAL_WARN_IF( aImplName.isEmpty(), "linguistic", "empty implementation name" );
uno::Sequence<lang::Locale> aLocaleSequence(xSvc->getLocales());
aLanguages = LocaleSeqToLangVec( aLocaleSequence );
pAvailGrammarSvcs->push_back( std::make_unique<SvcInfo>( aImplName, aLanguages ) );
}
}
}
@@ -1038,54 +1038,54 @@ void LngSvcMgr::GetAvailableGrammarSvcs_Impl()
void LngSvcMgr::GetAvailableHyphSvcs_Impl()
{
if (!pAvailHyphSvcs)
if (pAvailHyphSvcs)
return;
pAvailHyphSvcs.reset(new SvcInfoArray);
uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
uno::Reference< container::XContentEnumerationAccess > xEnumAccess( xContext->getServiceManager(), uno::UNO_QUERY );
uno::Reference< container::XEnumeration > xEnum;
if (xEnumAccess.is())
xEnum = xEnumAccess->createContentEnumeration( SN_HYPHENATOR );
if (!xEnum.is())
return;
while (xEnum->hasMoreElements())
{
pAvailHyphSvcs.reset(new SvcInfoArray);
uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
uno::Any aCurrent = xEnum->nextElement();
uno::Reference< lang::XSingleComponentFactory > xCompFactory;
uno::Reference< lang::XSingleServiceFactory > xFactory;
uno::Reference< container::XContentEnumerationAccess > xEnumAccess( xContext->getServiceManager(), uno::UNO_QUERY );
uno::Reference< container::XEnumeration > xEnum;
if (xEnumAccess.is())
xEnum = xEnumAccess->createContentEnumeration( SN_HYPHENATOR );
if (xEnum.is())
uno::Reference< linguistic2::XHyphenator > xSvc;
xCompFactory.set(aCurrent, css::uno::UNO_QUERY);
if (!xCompFactory.is())
{
while (xEnum->hasMoreElements())
xFactory.set(aCurrent, css::uno::UNO_QUERY);
}
if ( xCompFactory.is() || xFactory.is() )
{
try
{
uno::Any aCurrent = xEnum->nextElement();
uno::Reference< lang::XSingleComponentFactory > xCompFactory;
uno::Reference< lang::XSingleServiceFactory > xFactory;
uno::Reference< linguistic2::XHyphenator > xSvc;
xCompFactory.set(aCurrent, css::uno::UNO_QUERY);
if (!xCompFactory.is())
{
xFactory.set(aCurrent, css::uno::UNO_QUERY);
}
if ( xCompFactory.is() || xFactory.is() )
{
try
{
xSvc.set( ( xCompFactory.is() ? xCompFactory->createInstanceWithContext( xContext ) : xFactory->createInstance() ), uno::UNO_QUERY );
}
catch (const uno::Exception &)
{
SAL_WARN( "linguistic", "createInstance failed" );
}
}
if (xSvc.is())
{
OUString aImplName;
std::vector< LanguageType > aLanguages;
uno::Reference< XServiceInfo > xInfo( xSvc, uno::UNO_QUERY );
if (xInfo.is())
aImplName = xInfo->getImplementationName();
SAL_WARN_IF( aImplName.isEmpty(), "linguistic", "empty implementation name" );
uno::Sequence<lang::Locale> aLocaleSequence(xSvc->getLocales());
aLanguages = LocaleSeqToLangVec( aLocaleSequence );
pAvailHyphSvcs->push_back( std::make_unique<SvcInfo>( aImplName, aLanguages ) );
}
xSvc.set( ( xCompFactory.is() ? xCompFactory->createInstanceWithContext( xContext ) : xFactory->createInstance() ), uno::UNO_QUERY );
}
catch (const uno::Exception &)
{
SAL_WARN( "linguistic", "createInstance failed" );
}
}
if (xSvc.is())
{
OUString aImplName;
std::vector< LanguageType > aLanguages;
uno::Reference< XServiceInfo > xInfo( xSvc, uno::UNO_QUERY );
if (xInfo.is())
aImplName = xInfo->getImplementationName();
SAL_WARN_IF( aImplName.isEmpty(), "linguistic", "empty implementation name" );
uno::Sequence<lang::Locale> aLocaleSequence(xSvc->getLocales());
aLanguages = LocaleSeqToLangVec( aLocaleSequence );
pAvailHyphSvcs->push_back( std::make_unique<SvcInfo>( aImplName, aLanguages ) );
}
}
}
@@ -1093,56 +1093,56 @@ void LngSvcMgr::GetAvailableHyphSvcs_Impl()
void LngSvcMgr::GetAvailableThesSvcs_Impl()
{
if (!pAvailThesSvcs)
if (pAvailThesSvcs)
return;
pAvailThesSvcs.reset(new SvcInfoArray);
uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
uno::Reference< container::XContentEnumerationAccess > xEnumAccess( xContext->getServiceManager(), uno::UNO_QUERY );
uno::Reference< container::XEnumeration > xEnum;
if (xEnumAccess.is())
xEnum = xEnumAccess->createContentEnumeration( SN_THESAURUS );
if (!xEnum.is())
return;
while (xEnum->hasMoreElements())
{
pAvailThesSvcs.reset(new SvcInfoArray);
uno::Any aCurrent = xEnum->nextElement();
uno::Reference< lang::XSingleComponentFactory > xCompFactory;
uno::Reference< lang::XSingleServiceFactory > xFactory;
uno::Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
uno::Reference< container::XContentEnumerationAccess > xEnumAccess( xContext->getServiceManager(), uno::UNO_QUERY );
uno::Reference< container::XEnumeration > xEnum;
if (xEnumAccess.is())
xEnum = xEnumAccess->createContentEnumeration( SN_THESAURUS );
if (xEnum.is())
uno::Reference< linguistic2::XThesaurus > xSvc;
xCompFactory.set(aCurrent, css::uno::UNO_QUERY);
if (!xCompFactory.is())
{
while (xEnum->hasMoreElements())
xFactory.set(aCurrent, css::uno::UNO_QUERY);
}
if ( xCompFactory.is() || xFactory.is() )
{
try
{
uno::Any aCurrent = xEnum->nextElement();
uno::Reference< lang::XSingleComponentFactory > xCompFactory;
uno::Reference< lang::XSingleServiceFactory > xFactory;
uno::Reference< linguistic2::XThesaurus > xSvc;
xCompFactory.set(aCurrent, css::uno::UNO_QUERY);
if (!xCompFactory.is())
{
xFactory.set(aCurrent, css::uno::UNO_QUERY);
}
if ( xCompFactory.is() || xFactory.is() )
{
try
{
xSvc.set( ( xCompFactory.is() ? xCompFactory->createInstanceWithContext( xContext ) : xFactory->createInstance() ), uno::UNO_QUERY );
}
catch (const uno::Exception &)
{
SAL_WARN( "linguistic", "createInstance failed" );
}
}
if (xSvc.is())
{
OUString aImplName;
std::vector< LanguageType > aLanguages;
uno::Reference< XServiceInfo > xInfo( xSvc, uno::UNO_QUERY );
if (xInfo.is())
aImplName = xInfo->getImplementationName();
SAL_WARN_IF( aImplName.isEmpty(), "linguistic", "empty implementation name" );
uno::Sequence<lang::Locale> aLocaleSequence(xSvc->getLocales());
aLanguages = LocaleSeqToLangVec( aLocaleSequence );
pAvailThesSvcs->push_back( std::make_unique<SvcInfo>( aImplName, aLanguages ) );
}
xSvc.set( ( xCompFactory.is() ? xCompFactory->createInstanceWithContext( xContext ) : xFactory->createInstance() ), uno::UNO_QUERY );
}
catch (const uno::Exception &)
{
SAL_WARN( "linguistic", "createInstance failed" );
}
}
if (xSvc.is())
{
OUString aImplName;
std::vector< LanguageType > aLanguages;
uno::Reference< XServiceInfo > xInfo( xSvc, uno::UNO_QUERY );
if (xInfo.is())
aImplName = xInfo->getImplementationName();
SAL_WARN_IF( aImplName.isEmpty(), "linguistic", "empty implementation name" );
uno::Sequence<lang::Locale> aLocaleSequence(xSvc->getLocales());
aLanguages = LocaleSeqToLangVec( aLocaleSequence );
pAvailThesSvcs->push_back( std::make_unique<SvcInfo>( aImplName, aLanguages ) );
}
}
}
@@ -1163,19 +1163,19 @@ void LngSvcMgr::SetCfgServiceLists( SpellCheckerDispatcher &rSpellDsp )
}
const uno::Sequence< uno::Any > aValues( /*aCfg.*/GetProperties( aNames ) );
if (aNames.hasElements() && aNames.getLength() == aValues.getLength())
if (!(aNames.hasElements() && aNames.getLength() == aValues.getLength()))
return;
const OUString *pNames = aNames.getConstArray();
for (const uno::Any& rValue : aValues)
{
const OUString *pNames = aNames.getConstArray();
for (const uno::Any& rValue : aValues)
uno::Sequence< OUString > aSvcImplNames;
if (rValue >>= aSvcImplNames)
{
uno::Sequence< OUString > aSvcImplNames;
if (rValue >>= aSvcImplNames)
{
OUString aLocaleStr( *pNames++ );
sal_Int32 nSeparatorPos = aLocaleStr.lastIndexOf( '/' );
aLocaleStr = aLocaleStr.copy( nSeparatorPos + 1 );
rSpellDsp.SetServiceList( LanguageTag::convertToLocale(aLocaleStr), aSvcImplNames );
}
OUString aLocaleStr( *pNames++ );
sal_Int32 nSeparatorPos = aLocaleStr.lastIndexOf( '/' );
aLocaleStr = aLocaleStr.copy( nSeparatorPos + 1 );
rSpellDsp.SetServiceList( LanguageTag::convertToLocale(aLocaleStr), aSvcImplNames );
}
}
}
@@ -1196,23 +1196,23 @@ void LngSvcMgr::SetCfgServiceLists( GrammarCheckingIterator &rGrammarDsp )
}
const uno::Sequence< uno::Any > aValues( /*aCfg.*/GetProperties( aNames ) );
if (aNames.hasElements() && aNames.getLength() == aValues.getLength())
{
const OUString *pNames = aNames.getConstArray();
for (const uno::Any& rValue : aValues)
{
uno::Sequence< OUString > aSvcImplNames;
if (rValue >>= aSvcImplNames)
{
// there should only be one grammar checker in use per language...
if (aSvcImplNames.getLength() > 1)
aSvcImplNames.realloc(1);
if (!(aNames.hasElements() && aNames.getLength() == aValues.getLength()))
return;
OUString aLocaleStr( *pNames++ );
sal_Int32 nSeparatorPos = aLocaleStr.lastIndexOf( '/' );
aLocaleStr = aLocaleStr.copy( nSeparatorPos + 1 );
rGrammarDsp.SetServiceList( LanguageTag::convertToLocale(aLocaleStr), aSvcImplNames );
}
const OUString *pNames = aNames.getConstArray();
for (const uno::Any& rValue : aValues)
{
uno::Sequence< OUString > aSvcImplNames;
if (rValue >>= aSvcImplNames)
{
// there should only be one grammar checker in use per language...
if (aSvcImplNames.getLength() > 1)
aSvcImplNames.realloc(1);
OUString aLocaleStr( *pNames++ );
sal_Int32 nSeparatorPos = aLocaleStr.lastIndexOf( '/' );
aLocaleStr = aLocaleStr.copy( nSeparatorPos + 1 );
rGrammarDsp.SetServiceList( LanguageTag::convertToLocale(aLocaleStr), aSvcImplNames );
}
}
}
@@ -1233,23 +1233,23 @@ void LngSvcMgr::SetCfgServiceLists( HyphenatorDispatcher &rHyphDsp )
}
const uno::Sequence< uno::Any > aValues( /*aCfg.*/GetProperties( aNames ) );
if (aNames.hasElements() && aNames.getLength() == aValues.getLength())
{
const OUString *pNames = aNames.getConstArray();
for (const uno::Any& rValue : aValues)
{
uno::Sequence< OUString > aSvcImplNames;
if (rValue >>= aSvcImplNames)
{
// there should only be one hyphenator in use per language...
if (aSvcImplNames.getLength() > 1)
aSvcImplNames.realloc(1);
if (!(aNames.hasElements() && aNames.getLength() == aValues.getLength()))
return;
OUString aLocaleStr( *pNames++ );
sal_Int32 nSeparatorPos = aLocaleStr.lastIndexOf( '/' );
aLocaleStr = aLocaleStr.copy( nSeparatorPos + 1 );
rHyphDsp.SetServiceList( LanguageTag::convertToLocale(aLocaleStr), aSvcImplNames );
}
const OUString *pNames = aNames.getConstArray();
for (const uno::Any& rValue : aValues)
{
uno::Sequence< OUString > aSvcImplNames;
if (rValue >>= aSvcImplNames)
{
// there should only be one hyphenator in use per language...
if (aSvcImplNames.getLength() > 1)
aSvcImplNames.realloc(1);
OUString aLocaleStr( *pNames++ );
sal_Int32 nSeparatorPos = aLocaleStr.lastIndexOf( '/' );
aLocaleStr = aLocaleStr.copy( nSeparatorPos + 1 );
rHyphDsp.SetServiceList( LanguageTag::convertToLocale(aLocaleStr), aSvcImplNames );
}
}
}
@@ -1270,19 +1270,19 @@ void LngSvcMgr::SetCfgServiceLists( ThesaurusDispatcher &rThesDsp )
}
const uno::Sequence< uno::Any > aValues( /*aCfg.*/GetProperties( aNames ) );
if (aNames.hasElements() && aNames.getLength() == aValues.getLength())
if (!(aNames.hasElements() && aNames.getLength() == aValues.getLength()))
return;
const OUString *pNames = aNames.getConstArray();
for (const uno::Any& rValue : aValues)
{
const OUString *pNames = aNames.getConstArray();
for (const uno::Any& rValue : aValues)
uno::Sequence< OUString > aSvcImplNames;
if (rValue >>= aSvcImplNames)
{
uno::Sequence< OUString > aSvcImplNames;
if (rValue >>= aSvcImplNames)
{
OUString aLocaleStr( *pNames++ );
sal_Int32 nSeparatorPos = aLocaleStr.lastIndexOf( '/' );
aLocaleStr = aLocaleStr.copy( nSeparatorPos + 1 );
rThesDsp.SetServiceList( LanguageTag::convertToLocale(aLocaleStr), aSvcImplNames );
}
OUString aLocaleStr( *pNames++ );
sal_Int32 nSeparatorPos = aLocaleStr.lastIndexOf( '/' );
aLocaleStr = aLocaleStr.copy( nSeparatorPos + 1 );
rThesDsp.SetServiceList( LanguageTag::convertToLocale(aLocaleStr), aSvcImplNames );
}
}
}
@@ -1479,68 +1479,68 @@ void SAL_CALL
osl::MutexGuard aGuard( GetLinguMutex() );
LanguageType nLanguage = LinguLocaleToLanguage( rLocale );
if (!LinguIsUnspecified( nLanguage))
if (LinguIsUnspecified( nLanguage))
return;
if (rServiceName == SN_SPELLCHECKER)
{
if (rServiceName == SN_SPELLCHECKER)
if (!mxSpellDsp.is())
GetSpellCheckerDsp_Impl();
bool bChanged = !IsEqSvcList( rServiceImplNames,
mxSpellDsp->GetServiceList( rLocale ) );
if (bChanged)
{
if (!mxSpellDsp.is())
GetSpellCheckerDsp_Impl();
bool bChanged = !IsEqSvcList( rServiceImplNames,
mxSpellDsp->GetServiceList( rLocale ) );
if (bChanged)
{
mxSpellDsp->SetServiceList( rLocale, rServiceImplNames );
SaveCfgSvcs( SN_SPELLCHECKER );
mxSpellDsp->SetServiceList( rLocale, rServiceImplNames );
SaveCfgSvcs( SN_SPELLCHECKER );
if (mxListenerHelper)
mxListenerHelper->AddLngSvcEvt(
linguistic2::LinguServiceEventFlags::SPELL_CORRECT_WORDS_AGAIN |
linguistic2::LinguServiceEventFlags::SPELL_WRONG_WORDS_AGAIN );
}
if (mxListenerHelper)
mxListenerHelper->AddLngSvcEvt(
linguistic2::LinguServiceEventFlags::SPELL_CORRECT_WORDS_AGAIN |
linguistic2::LinguServiceEventFlags::SPELL_WRONG_WORDS_AGAIN );
}
else if (rServiceName == SN_GRAMMARCHECKER)
}
else if (rServiceName == SN_GRAMMARCHECKER)
{
if (!mxGrammarDsp.is())
GetGrammarCheckerDsp_Impl();
bool bChanged = !IsEqSvcList( rServiceImplNames,
mxGrammarDsp->GetServiceList( rLocale ) );
if (bChanged)
{
if (!mxGrammarDsp.is())
GetGrammarCheckerDsp_Impl();
bool bChanged = !IsEqSvcList( rServiceImplNames,
mxGrammarDsp->GetServiceList( rLocale ) );
if (bChanged)
{
mxGrammarDsp->SetServiceList( rLocale, rServiceImplNames );
SaveCfgSvcs( SN_GRAMMARCHECKER );
mxGrammarDsp->SetServiceList( rLocale, rServiceImplNames );
SaveCfgSvcs( SN_GRAMMARCHECKER );
if (mxListenerHelper)
mxListenerHelper->AddLngSvcEvt(
linguistic2::LinguServiceEventFlags::PROOFREAD_AGAIN );
}
if (mxListenerHelper)
mxListenerHelper->AddLngSvcEvt(
linguistic2::LinguServiceEventFlags::PROOFREAD_AGAIN );
}
else if (rServiceName == SN_HYPHENATOR)
}
else if (rServiceName == SN_HYPHENATOR)
{
if (!mxHyphDsp.is())
GetHyphenatorDsp_Impl();
bool bChanged = !IsEqSvcList( rServiceImplNames,
mxHyphDsp->GetServiceList( rLocale ) );
if (bChanged)
{
if (!mxHyphDsp.is())
GetHyphenatorDsp_Impl();
bool bChanged = !IsEqSvcList( rServiceImplNames,
mxHyphDsp->GetServiceList( rLocale ) );
if (bChanged)
{
mxHyphDsp->SetServiceList( rLocale, rServiceImplNames );
SaveCfgSvcs( SN_HYPHENATOR );
mxHyphDsp->SetServiceList( rLocale, rServiceImplNames );
SaveCfgSvcs( SN_HYPHENATOR );
if (mxListenerHelper)
mxListenerHelper->AddLngSvcEvt(
linguistic2::LinguServiceEventFlags::HYPHENATE_AGAIN );
}
if (mxListenerHelper)
mxListenerHelper->AddLngSvcEvt(
linguistic2::LinguServiceEventFlags::HYPHENATE_AGAIN );
}
else if (rServiceName == SN_THESAURUS)
}
else if (rServiceName == SN_THESAURUS)
{
if (!mxThesDsp.is())
GetThesaurusDsp_Impl();
bool bChanged = !IsEqSvcList( rServiceImplNames,
mxThesDsp->GetServiceList( rLocale ) );
if (bChanged)
{
if (!mxThesDsp.is())
GetThesaurusDsp_Impl();
bool bChanged = !IsEqSvcList( rServiceImplNames,
mxThesDsp->GetServiceList( rLocale ) );
if (bChanged)
{
mxThesDsp->SetServiceList( rLocale, rServiceImplNames );
SaveCfgSvcs( SN_THESAURUS );
}
mxThesDsp->SetServiceList( rLocale, rServiceImplNames );
SaveCfgSvcs( SN_THESAURUS );
}
}
}