diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-04 21:29:47 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-05 05:02:29 +0200 |
commit | f3ff488fd4fb56f178ffbb7b3880dfafdd9d8e9c (patch) | |
tree | ad5d8b09e36457beaa906a393dce0a67c1686fb1 /unotools/source/config | |
parent | 48a3d6b85e3c2858c281d5f258fcf2120ca84265 (diff) |
loplugin:flatten in unotools
Change-Id: I2fad16061bca6dc3e57926863e7a3b71947a8ade
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100139
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'unotools/source/config')
-rw-r--r-- | unotools/source/config/configitem.cxx | 22 | ||||
-rw-r--r-- | unotools/source/config/defaultoptions.cxx | 130 | ||||
-rw-r--r-- | unotools/source/config/fontcfg.cxx | 124 | ||||
-rw-r--r-- | unotools/source/config/pathoptions.cxx | 62 | ||||
-rw-r--r-- | unotools/source/config/securityoptions.cxx | 74 |
5 files changed, 206 insertions, 206 deletions
diff --git a/unotools/source/config/configitem.cxx b/unotools/source/config/configitem.cxx index a6785079723a..60ded67dc837 100644 --- a/unotools/source/config/configitem.cxx +++ b/unotools/source/config/configitem.cxx @@ -537,19 +537,19 @@ bool ConfigItem::EnableNotification(const Sequence< OUString >& rNames, void ConfigItem::RemoveChangesListener() { Reference<XHierarchicalNameAccess> xHierarchyAccess = GetTree(); - if(xHierarchyAccess.is()) + if(!xHierarchyAccess.is()) + return; + + Reference<XChangesNotifier> xChgNot(xHierarchyAccess, UNO_QUERY); + if(xChgNot.is() && xChangeLstnr.is()) { - Reference<XChangesNotifier> xChgNot(xHierarchyAccess, UNO_QUERY); - if(xChgNot.is() && xChangeLstnr.is()) + try + { + xChgNot->removeChangesListener( xChangeLstnr ); + xChangeLstnr = nullptr; + } + catch (const Exception&) { - try - { - xChgNot->removeChangesListener( xChangeLstnr ); - xChangeLstnr = nullptr; - } - catch (const Exception&) - { - } } } } diff --git a/unotools/source/config/defaultoptions.cxx b/unotools/source/config/defaultoptions.cxx index de7c5a4b4dfd..72a3cc8ba090 100644 --- a/unotools/source/config/defaultoptions.cxx +++ b/unotools/source/config/defaultoptions.cxx @@ -233,89 +233,89 @@ SvtDefaultOptions_Impl::SvtDefaultOptions_Impl() : ConfigItem( "Office.Common/Pa EnableNotification( aNames ); const Any* pValues = aValues.getConstArray(); DBG_ASSERT( aValues.getLength() == aNames.getLength(), "GetProperties failed" ); - if ( aValues.getLength() == aNames.getLength() ) - { - SvtPathOptions aPathOpt; - OUString aTempStr; - OUStringBuffer aFullPathBuf; + if ( aValues.getLength() != aNames.getLength() ) + return; + + SvtPathOptions aPathOpt; + OUString aTempStr; + OUStringBuffer aFullPathBuf; - for ( int nProp = 0; nProp < aNames.getLength(); nProp++ ) + for ( int nProp = 0; nProp < aNames.getLength(); nProp++ ) + { + if ( pValues[nProp].hasValue() ) { - if ( pValues[nProp].hasValue() ) + switch ( pValues[nProp].getValueTypeClass() ) { - switch ( pValues[nProp].getValueTypeClass() ) + case css::uno::TypeClass_STRING : { - case css::uno::TypeClass_STRING : + // multi paths + if ( pValues[nProp] >>= aTempStr ) + aFullPathBuf = aPathOpt.SubstituteVariable( aTempStr ); + else { - // multi paths - if ( pValues[nProp] >>= aTempStr ) - aFullPathBuf = aPathOpt.SubstituteVariable( aTempStr ); - else - { - SAL_WARN( "unotools.config", "any operator >>= failed" ); - } - break; + SAL_WARN( "unotools.config", "any operator >>= failed" ); } + break; + } - case css::uno::TypeClass_SEQUENCE : + case css::uno::TypeClass_SEQUENCE : + { + // single paths + aFullPathBuf.setLength(0); + Sequence < OUString > aList; + if ( pValues[nProp] >>= aList ) { - // single paths - aFullPathBuf.setLength(0); - Sequence < OUString > aList; - if ( pValues[nProp] >>= aList ) + sal_Int32 nCount = aList.getLength(); + for ( sal_Int32 nPosition = 0; nPosition < nCount; ++nPosition ) { - sal_Int32 nCount = aList.getLength(); - for ( sal_Int32 nPosition = 0; nPosition < nCount; ++nPosition ) - { - aFullPathBuf.append(aPathOpt.SubstituteVariable( aList[ nPosition ] )); - if ( nPosition < nCount-1 ) - aFullPathBuf.append(";"); - } + aFullPathBuf.append(aPathOpt.SubstituteVariable( aList[ nPosition ] )); + if ( nPosition < nCount-1 ) + aFullPathBuf.append(";"); } - else - { - SAL_WARN( "unotools.config", "any operator >>= failed" ); - } - break; } - - default: + else { - SAL_WARN( "unotools.config", "Wrong any type" ); + SAL_WARN( "unotools.config", "any operator >>= failed" ); } + break; } - auto aFullPath = aFullPathBuf.makeStringAndClear(); - switch ( nProp ) + default: { - case DEFAULTPATH_ADDIN: m_aAddinPath = aFullPath; break; - case DEFAULTPATH_AUTOCORRECT: m_aAutoCorrectPath = aFullPath; break; - case DEFAULTPATH_AUTOTEXT: m_aAutoTextPath = aFullPath; break; - case DEFAULTPATH_BACKUP: m_aBackupPath = aFullPath; break; - case DEFAULTPATH_BASIC: m_aBasicPath = aFullPath; break; - case DEFAULTPATH_BITMAP: m_aBitmapPath = aFullPath; break; - case DEFAULTPATH_CONFIG: m_aConfigPath = aFullPath; break; - case DEFAULTPATH_DICTIONARY: m_aDictionaryPath = aFullPath; break; - case DEFAULTPATH_FAVORITES: m_aFavoritesPath = aFullPath; break; - case DEFAULTPATH_FILTER: m_aFilterPath = aFullPath; break; - case DEFAULTPATH_GALLERY: m_aGalleryPath = aFullPath; break; - case DEFAULTPATH_GRAPHIC: m_aGraphicPath = aFullPath; break; - case DEFAULTPATH_HELP: m_aHelpPath = aFullPath; break; - case DEFAULTPATH_LINGUISTIC: m_aLinguisticPath = aFullPath; break; - case DEFAULTPATH_MODULE: m_aModulePath = aFullPath; break; - case DEFAULTPATH_PALETTE: m_aPalettePath = aFullPath; break; - case DEFAULTPATH_PLUGIN: m_aPluginPath = aFullPath; break; - case DEFAULTPATH_TEMP: m_aTempPath = aFullPath; break; - case DEFAULTPATH_TEMPLATE: m_aTemplatePath = aFullPath; break; - case DEFAULTPATH_USERCONFIG: m_aUserConfigPath = aFullPath; break; - case DEFAULTPATH_WORK: m_aWorkPath = aFullPath; break; - case DEFAULTPATH_CLASSIFICATION: m_aClassificationPath = aFullPath;break; - case DEFAULTPATH_USERDICTIONARY: break; - - default: - SAL_WARN( "unotools.config", "invalid index to load a default path" ); + SAL_WARN( "unotools.config", "Wrong any type" ); } } + + auto aFullPath = aFullPathBuf.makeStringAndClear(); + switch ( nProp ) + { + case DEFAULTPATH_ADDIN: m_aAddinPath = aFullPath; break; + case DEFAULTPATH_AUTOCORRECT: m_aAutoCorrectPath = aFullPath; break; + case DEFAULTPATH_AUTOTEXT: m_aAutoTextPath = aFullPath; break; + case DEFAULTPATH_BACKUP: m_aBackupPath = aFullPath; break; + case DEFAULTPATH_BASIC: m_aBasicPath = aFullPath; break; + case DEFAULTPATH_BITMAP: m_aBitmapPath = aFullPath; break; + case DEFAULTPATH_CONFIG: m_aConfigPath = aFullPath; break; + case DEFAULTPATH_DICTIONARY: m_aDictionaryPath = aFullPath; break; + case DEFAULTPATH_FAVORITES: m_aFavoritesPath = aFullPath; break; + case DEFAULTPATH_FILTER: m_aFilterPath = aFullPath; break; + case DEFAULTPATH_GALLERY: m_aGalleryPath = aFullPath; break; + case DEFAULTPATH_GRAPHIC: m_aGraphicPath = aFullPath; break; + case DEFAULTPATH_HELP: m_aHelpPath = aFullPath; break; + case DEFAULTPATH_LINGUISTIC: m_aLinguisticPath = aFullPath; break; + case DEFAULTPATH_MODULE: m_aModulePath = aFullPath; break; + case DEFAULTPATH_PALETTE: m_aPalettePath = aFullPath; break; + case DEFAULTPATH_PLUGIN: m_aPluginPath = aFullPath; break; + case DEFAULTPATH_TEMP: m_aTempPath = aFullPath; break; + case DEFAULTPATH_TEMPLATE: m_aTemplatePath = aFullPath; break; + case DEFAULTPATH_USERCONFIG: m_aUserConfigPath = aFullPath; break; + case DEFAULTPATH_WORK: m_aWorkPath = aFullPath; break; + case DEFAULTPATH_CLASSIFICATION: m_aClassificationPath = aFullPath;break; + case DEFAULTPATH_USERDICTIONARY: break; + + default: + SAL_WARN( "unotools.config", "invalid index to load a default path" ); + } } } } diff --git a/unotools/source/config/fontcfg.cxx b/unotools/source/config/fontcfg.cxx index 9025562f89c0..8f7b4277549b 100644 --- a/unotools/source/config/fontcfg.cxx +++ b/unotools/source/config/fontcfg.cxx @@ -974,72 +974,72 @@ ImplFontAttrs FontSubstConfiguration::getSubstType( const css::uno::Reference< X void FontSubstConfiguration::readLocaleSubst( const OUString& rBcp47 ) const { std::unordered_map< OUString, LocaleSubst >::const_iterator it = m_aSubst.find( rBcp47 ); - if( it != m_aSubst.end() ) + if( it == m_aSubst.end() ) + return; + + if( it->second.bConfigRead ) + return; + + it->second.bConfigRead = true; + Reference< XNameAccess > xNode; + try { - if( ! it->second.bConfigRead ) - { - it->second.bConfigRead = true; - Reference< XNameAccess > xNode; - try - { - Any aAny = m_xConfigAccess->getByName( it->second.aConfigLocaleString ); - aAny >>= xNode; - } - catch (const NoSuchElementException&) - { - } - catch (const WrappedTargetException&) - { - } - if( xNode.is() ) - { - const Sequence< OUString > aFonts = xNode->getElementNames(); - int nFonts = aFonts.getLength(); - // improve performance, heap fragmentation - it->second.aSubstAttributes.reserve( nFonts ); - - // strings for subst retrieval, construct only once - OUString const aSubstFontsStr ( "SubstFonts" ); - OUString const aSubstFontsMSStr ( "SubstFontsMS" ); - OUString const aSubstWeightStr ( "FontWeight" ); - OUString const aSubstWidthStr ( "FontWidth" ); - OUString const aSubstTypeStr ( "FontType" ); - for( const OUString& rFontName : aFonts ) - { - Reference< XNameAccess > xFont; - try - { - Any aAny = xNode->getByName( rFontName ); - aAny >>= xFont; - } - catch (const NoSuchElementException&) - { - } - catch (const WrappedTargetException&) - { - } - if( ! xFont.is() ) - { - SAL_WARN("unotools.config", "did not get font attributes for " << rFontName); - continue; - } + Any aAny = m_xConfigAccess->getByName( it->second.aConfigLocaleString ); + aAny >>= xNode; + } + catch (const NoSuchElementException&) + { + } + catch (const WrappedTargetException&) + { + } + if( !xNode.is() ) + return; - FontNameAttr aAttr; - // read subst attributes from config - aAttr.Name = rFontName; - fillSubstVector( xFont, aSubstFontsStr, aAttr.Substitutions ); - fillSubstVector( xFont, aSubstFontsMSStr, aAttr.MSSubstitutions ); - aAttr.Weight = getSubstWeight( xFont, aSubstWeightStr ); - aAttr.Width = getSubstWidth( xFont, aSubstWidthStr ); - aAttr.Type = getSubstType( xFont, aSubstTypeStr ); - - // finally insert this entry - it->second.aSubstAttributes.push_back( aAttr ); - } - std::sort( it->second.aSubstAttributes.begin(), it->second.aSubstAttributes.end(), StrictStringSort() ); - } + const Sequence< OUString > aFonts = xNode->getElementNames(); + int nFonts = aFonts.getLength(); + // improve performance, heap fragmentation + it->second.aSubstAttributes.reserve( nFonts ); + + // strings for subst retrieval, construct only once + OUString const aSubstFontsStr ( "SubstFonts" ); + OUString const aSubstFontsMSStr ( "SubstFontsMS" ); + OUString const aSubstWeightStr ( "FontWeight" ); + OUString const aSubstWidthStr ( "FontWidth" ); + OUString const aSubstTypeStr ( "FontType" ); + for( const OUString& rFontName : aFonts ) + { + Reference< XNameAccess > xFont; + try + { + Any aAny = xNode->getByName( rFontName ); + aAny >>= xFont; + } + catch (const NoSuchElementException&) + { } + catch (const WrappedTargetException&) + { + } + if( ! xFont.is() ) + { + SAL_WARN("unotools.config", "did not get font attributes for " << rFontName); + continue; + } + + FontNameAttr aAttr; + // read subst attributes from config + aAttr.Name = rFontName; + fillSubstVector( xFont, aSubstFontsStr, aAttr.Substitutions ); + fillSubstVector( xFont, aSubstFontsMSStr, aAttr.MSSubstitutions ); + aAttr.Weight = getSubstWeight( xFont, aSubstWeightStr ); + aAttr.Width = getSubstWidth( xFont, aSubstWidthStr ); + aAttr.Type = getSubstType( xFont, aSubstTypeStr ); + + // finally insert this entry + it->second.aSubstAttributes.push_back( aAttr ); } + std::sort( it->second.aSubstAttributes.begin(), it->second.aSubstAttributes.end(), StrictStringSort() ); } const FontNameAttr* FontSubstConfiguration::getSubstInfo( const OUString& rFontName ) const diff --git a/unotools/source/config/pathoptions.cxx b/unotools/source/config/pathoptions.cxx index 1896f456a3a8..cb70189aa3dd 100644 --- a/unotools/source/config/pathoptions.cxx +++ b/unotools/source/config/pathoptions.cxx @@ -268,41 +268,41 @@ void SvtPathOptions_Impl::SetPath( SvtPathOptions::Paths ePath, const OUString& { ::osl::MutexGuard aGuard( m_aMutex ); - if ( ePath < SvtPathOptions::PATH_COUNT ) - { - OUString aResult; - OUString aNewValue; - Any a; - - switch ( ePath ) - { - case SvtPathOptions::PATH_ADDIN: - case SvtPathOptions::PATH_FILTER: - case SvtPathOptions::PATH_HELP: - case SvtPathOptions::PATH_MODULE: - case SvtPathOptions::PATH_PLUGIN: - case SvtPathOptions::PATH_STORAGE: - { - // These office paths have to be convert back to UCB-URL's - osl::FileBase::getFileURLFromSystemPath( rNewPath, aResult ); - aNewValue = aResult; - } - break; + if ( ePath >= SvtPathOptions::PATH_COUNT ) + return; - default: - aNewValue = rNewPath; - } + OUString aResult; + OUString aNewValue; + Any a; - // Resubstitution is done by the service itself using the substitution service - a <<= aNewValue; - try - { - m_xPathSettings->setFastPropertyValue( m_aMapEnumToPropHandle[ static_cast<sal_Int32>(ePath)], a ); - } - catch (const Exception&) + switch ( ePath ) + { + case SvtPathOptions::PATH_ADDIN: + case SvtPathOptions::PATH_FILTER: + case SvtPathOptions::PATH_HELP: + case SvtPathOptions::PATH_MODULE: + case SvtPathOptions::PATH_PLUGIN: + case SvtPathOptions::PATH_STORAGE: { - TOOLS_WARN_EXCEPTION("unotools.config", "SetPath"); + // These office paths have to be convert back to UCB-URL's + osl::FileBase::getFileURLFromSystemPath( rNewPath, aResult ); + aNewValue = aResult; } + break; + + default: + aNewValue = rNewPath; + } + + // Resubstitution is done by the service itself using the substitution service + a <<= aNewValue; + try + { + m_xPathSettings->setFastPropertyValue( m_aMapEnumToPropHandle[ static_cast<sal_Int32>(ePath)], a ); + } + catch (const Exception&) + { + TOOLS_WARN_EXCEPTION("unotools.config", "SetPath"); } } diff --git a/unotools/source/config/securityoptions.cxx b/unotools/source/config/securityoptions.cxx index d81517f255a0..36aa85b3ac8c 100644 --- a/unotools/source/config/securityoptions.cxx +++ b/unotools/source/config/securityoptions.cxx @@ -412,49 +412,49 @@ void SvtSecurityOptions_Impl::LoadAuthors() m_seqTrustedAuthors.realloc( 0 ); // first clear const Sequence< OUString > lAuthors = GetNodeNames( PROPERTYNAME_MACRO_TRUSTEDAUTHORS ); sal_Int32 c1 = lAuthors.getLength(); - if( c1 ) + if( !c1 ) + return; + + sal_Int32 c2 = c1 * 3; // 3 Properties inside Struct TrustedAuthor + Sequence< OUString > lAllAuthors( c2 ); + + sal_Int32 i2 = 0; + OUString aSep( "/" ); + for( const auto& rAuthor : lAuthors ) { - sal_Int32 c2 = c1 * 3; // 3 Properties inside Struct TrustedAuthor - Sequence< OUString > lAllAuthors( c2 ); + lAllAuthors[ i2 ] = PROPERTYNAME_MACRO_TRUSTEDAUTHORS + aSep + rAuthor + aSep + PROPERTYNAME_TRUSTEDAUTHOR_SUBJECTNAME; + ++i2; + lAllAuthors[ i2 ] = PROPERTYNAME_MACRO_TRUSTEDAUTHORS + aSep + rAuthor + aSep + PROPERTYNAME_TRUSTEDAUTHOR_SERIALNUMBER; + ++i2; + lAllAuthors[ i2 ] = PROPERTYNAME_MACRO_TRUSTEDAUTHORS + aSep + rAuthor + aSep + PROPERTYNAME_TRUSTEDAUTHOR_RAWDATA; + ++i2; + } - sal_Int32 i2 = 0; - OUString aSep( "/" ); - for( const auto& rAuthor : lAuthors ) - { - lAllAuthors[ i2 ] = PROPERTYNAME_MACRO_TRUSTEDAUTHORS + aSep + rAuthor + aSep + PROPERTYNAME_TRUSTEDAUTHOR_SUBJECTNAME; - ++i2; - lAllAuthors[ i2 ] = PROPERTYNAME_MACRO_TRUSTEDAUTHORS + aSep + rAuthor + aSep + PROPERTYNAME_TRUSTEDAUTHOR_SERIALNUMBER; - ++i2; - lAllAuthors[ i2 ] = PROPERTYNAME_MACRO_TRUSTEDAUTHORS + aSep + rAuthor + aSep + PROPERTYNAME_TRUSTEDAUTHOR_RAWDATA; - ++i2; - } + Sequence< Any > lValues = GetProperties( lAllAuthors ); + if( lValues.getLength() != c2 ) + return; - Sequence< Any > lValues = GetProperties( lAllAuthors ); - if( lValues.getLength() == c2 ) + std::vector< SvtSecurityOptions::Certificate > v; + SvtSecurityOptions::Certificate aCert( 3 ); + i2 = 0; + for( sal_Int32 i1 = 0; i1 < c1; ++i1 ) + { + lValues[ i2 ] >>= aCert[ 0 ]; + ++i2; + lValues[ i2 ] >>= aCert[ 1 ]; + ++i2; + lValues[ i2 ] >>= aCert[ 2 ]; + ++i2; + // Filter out TrustedAuthor entries with empty RawData, which + // would cause an unexpected std::bad_alloc in + // SecurityEnvironment_NssImpl::createCertificateFromAscii and + // have been observed in the wild (fdo#55019): + if( !aCert[ 2 ].isEmpty() ) { - std::vector< SvtSecurityOptions::Certificate > v; - SvtSecurityOptions::Certificate aCert( 3 ); - i2 = 0; - for( sal_Int32 i1 = 0; i1 < c1; ++i1 ) - { - lValues[ i2 ] >>= aCert[ 0 ]; - ++i2; - lValues[ i2 ] >>= aCert[ 1 ]; - ++i2; - lValues[ i2 ] >>= aCert[ 2 ]; - ++i2; - // Filter out TrustedAuthor entries with empty RawData, which - // would cause an unexpected std::bad_alloc in - // SecurityEnvironment_NssImpl::createCertificateFromAscii and - // have been observed in the wild (fdo#55019): - if( !aCert[ 2 ].isEmpty() ) - { - v.push_back( aCert ); - } - } - m_seqTrustedAuthors = comphelper::containerToSequence(v); + v.push_back( aCert ); } } + m_seqTrustedAuthors = comphelper::containerToSequence(v); } sal_Int32 SvtSecurityOptions_Impl::GetHandle( const OUString& rName ) |