diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-07-24 16:56:15 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-07-25 20:05:30 +0200 |
commit | 134f40136a9bea265d8f2fedfdb41a1e65d81b49 (patch) | |
tree | d00db8e5b8cc954440228b8815631aa937effdca /unotools | |
parent | 28993c0a8d8628c650b661767fd8ab2228c507d9 (diff) |
use officecfg to retrieve OdfDefaultVersion
Change-Id: Id54b98d978965e7ce304b83d5eff7d6c844a41d5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119474
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'unotools')
-rw-r--r-- | unotools/source/config/saveopt.cxx | 298 |
1 files changed, 36 insertions, 262 deletions
diff --git a/unotools/source/config/saveopt.cxx b/unotools/source/config/saveopt.cxx index aa7e875e1d97..6bac9ea28d04 100644 --- a/unotools/source/config/saveopt.cxx +++ b/unotools/source/config/saveopt.cxx @@ -21,7 +21,6 @@ #include <sal/log.hxx> #include <unotools/saveopt.hxx> -#include <rtl/instance.hxx> #include <unotools/configmgr.hxx> #include <unotools/configitem.hxx> #include <tools/debug.hxx> @@ -36,292 +35,67 @@ using namespace utl; using namespace com::sun::star::uno; -namespace { - -class SvtSaveOptions_Impl; -class SvtLoadOptions_Impl; - -} - -#define CFG_READONLY_DEFAULT false - -struct SvtLoadSaveOptions_Impl -{ - std::unique_ptr<SvtSaveOptions_Impl> pSaveOpt; -}; - -static std::unique_ptr<SvtLoadSaveOptions_Impl> pOptions; -static sal_Int32 nRefCount = 0; - -namespace { - -class SvtSaveOptions_Impl : public utl::ConfigItem -{ - sal_Int32 nAutoSaveTime; - bool bAutoSave; - - SvtSaveOptions::ODFDefaultVersion eODFDefaultVersion; - - bool bROODFDefaultVersion; - - virtual void ImplCommit() override; - -public: - SvtSaveOptions_Impl(); - - virtual void Notify( const css::uno::Sequence< OUString >& aPropertyNames ) override; - - SvtSaveOptions::ODFDefaultVersion - GetODFDefaultVersion() const { return eODFDefaultVersion; } - - void SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion eNew ); - - bool IsReadOnly( SvtSaveOptions::EOption eOption ) const; -}; - -} - -void SvtSaveOptions_Impl::SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion eNew ) +void SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion eVersion, const std::shared_ptr<comphelper::ConfigurationChanges>& xChanges ) { - if ( !bROODFDefaultVersion && eODFDefaultVersion != eNew ) - { - eODFDefaultVersion = eNew; - SetModified(); - } + sal_Int16 nTmp = (eVersion == SvtSaveOptions::ODFVER_LATEST) ? sal_Int16( 3 ) : sal_Int16( eVersion ); + officecfg::Office::Common::Save::ODF::DefaultVersion::set(nTmp, xChanges); } -bool SvtSaveOptions_Impl::IsReadOnly( SvtSaveOptions::EOption eOption ) const +void SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion eVersion ) { - bool bReadOnly = CFG_READONLY_DEFAULT; - switch(eOption) - { - case SvtSaveOptions::EOption::OdfDefaultVersion : - bReadOnly = bROODFDefaultVersion; - break; - } - return bReadOnly; + auto xChanges = comphelper::ConfigurationChanges::create(); + SetODFDefaultVersion(eVersion, xChanges); + xChanges->commit(); } -#define FORMAT 0 -#define ODFDEFAULTVERSION 1 - -static Sequence< OUString > GetPropertyNames() +SvtSaveOptions::ODFDefaultVersion GetODFDefaultVersion() { - static const char* aPropNames[] = - { - "Graphic/Format", - "ODF/DefaultVersion" - }; - - const int nCount = SAL_N_ELEMENTS( aPropNames ); - Sequence< OUString > aNames( nCount ); - OUString* pNames = aNames.getArray(); - for ( int i = 0; i < nCount; i++ ) - pNames[i] = OUString::createFromAscii( aPropNames[i] ); - - return aNames; -} - -SvtSaveOptions_Impl::SvtSaveOptions_Impl() - : ConfigItem( "Office.Common/Save" ) - , nAutoSaveTime( 0 ) - , eODFDefaultVersion( SvtSaveOptions::ODFVER_LATEST ) - , bROODFDefaultVersion( CFG_READONLY_DEFAULT ) -{ - Sequence< OUString > aNames = GetPropertyNames(); - Sequence< Any > aValues = GetProperties( aNames ); - Sequence< sal_Bool > aROStates = GetReadOnlyStates( aNames ); - EnableNotification( aNames ); - const Any* pValues = aValues.getConstArray(); - const sal_Bool* pROStates = aROStates.getConstArray(); - DBG_ASSERT( aValues.getLength() == aNames.getLength(), "GetProperties failed" ); - DBG_ASSERT( aROStates.getLength() == aNames.getLength(), "GetReadOnlyStates failed" ); - if ( aValues.getLength() == aNames.getLength() && aROStates.getLength() == aNames.getLength() ) - { - for ( int nProp = 0; nProp < aNames.getLength(); nProp++ ) - { - if ( pValues[nProp].hasValue() ) - { - switch ( nProp ) - { - case FORMAT: - // not supported anymore - break; - - case ODFDEFAULTVERSION : - { - sal_Int16 nTmp = 0; - if ( pValues[nProp] >>= nTmp ) - { - if( nTmp == 3 ) - eODFDefaultVersion = SvtSaveOptions::ODFVER_LATEST; - else - eODFDefaultVersion = SvtSaveOptions::ODFDefaultVersion( nTmp ); - } - else { - SAL_WARN( "unotools.config", "SvtSaveOptions_Impl::SvtSaveOptions_Impl(): Wrong Type!" ); - }; - bROODFDefaultVersion = pROStates[nProp]; - break; - } - - default: - OSL_FAIL( "Wrong Type!" ); - } - } - } - } - - if (!utl::ConfigManager::IsFuzzing()) - { - bAutoSave = officecfg::Office::Recovery::AutoSave::Enabled::get(); - nAutoSaveTime = officecfg::Office::Recovery::AutoSave::TimeIntervall::get(); - } + SvtSaveOptions::ODFDefaultVersion nRet; + sal_Int16 nTmp = officecfg::Office::Common::Save::ODF::DefaultVersion::get(); + if( nTmp == 3 ) + nRet = SvtSaveOptions::ODFVER_LATEST; else - { - bAutoSave = false; - nAutoSaveTime = 0; - } -} - -void SvtSaveOptions_Impl::ImplCommit() -{ - Sequence< OUString > aOrgNames = GetPropertyNames(); - OUString* pOrgNames = aOrgNames.getArray(); - sal_Int32 nOrgCount = aOrgNames.getLength(); - - Sequence< OUString > aNames( nOrgCount ); - Sequence< Any > aValues( nOrgCount ); - OUString* pNames = aNames.getArray(); - Any* pValues = aValues.getArray(); - sal_Int32 nRealCount = 0; - - for (sal_Int32 i=0; i<nOrgCount; ++i) - { - switch (i) - { - case FORMAT: - // not supported anymore - break; - case ODFDEFAULTVERSION: - if (!bROODFDefaultVersion) - { - pValues[nRealCount] <<= (eODFDefaultVersion == SvtSaveOptions::ODFVER_LATEST) ? sal_Int16( 3 ) : sal_Int16( eODFDefaultVersion ); - pNames[nRealCount] = pOrgNames[i]; - ++nRealCount; - } - break; - - default: - SAL_WARN( "unotools.config", "invalid index to save a path" ); - } - } - - aNames.realloc(nRealCount); - aValues.realloc(nRealCount); - PutProperties( aNames, aValues ); - - std::shared_ptr< comphelper::ConfigurationChanges > batch( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Recovery::AutoSave::TimeIntervall::set(nAutoSaveTime, batch); - officecfg::Office::Recovery::AutoSave::Enabled::set(bAutoSave, batch); - batch->commit(); -} - -void SvtSaveOptions_Impl::Notify( const Sequence<OUString>& ) -{ -} - -namespace -{ - class LocalSingleton : public rtl::Static< osl::Mutex, LocalSingleton > - { - }; -} - -SvtSaveOptions::SvtSaveOptions() -{ - // Global access, must be guarded (multithreading) - ::osl::MutexGuard aGuard( LocalSingleton::get() ); - if ( !pOptions ) - { - pOptions.reset(new SvtLoadSaveOptions_Impl); - pOptions->pSaveOpt.reset(new SvtSaveOptions_Impl); - } - ++nRefCount; - pImp = pOptions.get(); -} - -SvtSaveOptions::~SvtSaveOptions() -{ - // Global access, must be guarded (multithreading) - ::osl::MutexGuard aGuard( LocalSingleton::get() ); - if ( !--nRefCount ) - { - if ( pOptions->pSaveOpt->IsModified() ) - pOptions->pSaveOpt->Commit(); - - pOptions.reset(); - } -} - -void SvtSaveOptions::SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion eVersion ) -{ - pImp->pSaveOpt->SetODFDefaultVersion( eVersion ); -} - -SvtSaveOptions::ODFDefaultVersion SvtSaveOptions::GetODFDefaultVersion() const -{ - auto const nRet = pImp->pSaveOpt->GetODFDefaultVersion(); - SAL_WARN_IF(nRet == ODFVER_UNKNOWN, "unotools.config", "DefaultVersion is ODFVER_UNKNOWN?"); - return (nRet == ODFVER_UNKNOWN) ? ODFVER_LATEST : nRet; + nRet = SvtSaveOptions::ODFDefaultVersion( nTmp ); + SAL_WARN_IF(nRet == SvtSaveOptions::ODFVER_UNKNOWN, "unotools.config", "DefaultVersion is ODFVER_UNKNOWN?"); + return (nRet == SvtSaveOptions::ODFVER_UNKNOWN) ? SvtSaveOptions::ODFVER_LATEST : nRet; } SvtSaveOptions::ODFSaneDefaultVersion GetODFSaneDefaultVersion() { + SvtSaveOptions::ODFDefaultVersion nRet; sal_Int16 nTmp = officecfg::Office::Common::Save::ODF::DefaultVersion::get(); - SvtSaveOptions::ODFDefaultVersion eODFDefaultVersion; if( nTmp == 3 ) - eODFDefaultVersion = SvtSaveOptions::ODFVER_LATEST; + nRet = SvtSaveOptions::ODFVER_LATEST; else - eODFDefaultVersion = SvtSaveOptions::ODFDefaultVersion( nTmp ); - return SvtSaveOptions::GetODFSaneDefaultVersion(eODFDefaultVersion); -} + nRet = SvtSaveOptions::ODFDefaultVersion( nTmp ); -SvtSaveOptions::ODFSaneDefaultVersion SvtSaveOptions::GetODFSaneDefaultVersion() const -{ - return GetODFSaneDefaultVersion(pImp->pSaveOpt->GetODFDefaultVersion()); + return GetODFSaneDefaultVersion(nRet); } -SvtSaveOptions::ODFSaneDefaultVersion SvtSaveOptions::GetODFSaneDefaultVersion(ODFDefaultVersion eODFDefaultVersion) +SvtSaveOptions::ODFSaneDefaultVersion GetODFSaneDefaultVersion(SvtSaveOptions::ODFDefaultVersion eODFDefaultVersion) { switch (eODFDefaultVersion) { default: assert(!"map new ODFDefaultVersion to ODFSaneDefaultVersion"); break; - case ODFVER_UNKNOWN: - case ODFVER_LATEST: - return ODFSVER_LATEST_EXTENDED; - case ODFVER_010: - return ODFSVER_010; - case ODFVER_011: - return ODFSVER_011; - case ODFVER_012: - return ODFSVER_012; - case ODFVER_012_EXT_COMPAT: - return ODFSVER_012_EXT_COMPAT; - case ODFVER_012_EXTENDED: - return ODFSVER_012_EXTENDED; - case ODFVER_013: - return ODFSVER_013; + case SvtSaveOptions::ODFVER_UNKNOWN: + case SvtSaveOptions::ODFVER_LATEST: + return SvtSaveOptions::ODFSVER_LATEST_EXTENDED; + case SvtSaveOptions::ODFVER_010: + return SvtSaveOptions::ODFSVER_010; + case SvtSaveOptions::ODFVER_011: + return SvtSaveOptions::ODFSVER_011; + case SvtSaveOptions::ODFVER_012: + return SvtSaveOptions::ODFSVER_012; + case SvtSaveOptions::ODFVER_012_EXT_COMPAT: + return SvtSaveOptions::ODFSVER_012_EXT_COMPAT; + case SvtSaveOptions::ODFVER_012_EXTENDED: + return SvtSaveOptions::ODFSVER_012_EXTENDED; + case SvtSaveOptions::ODFVER_013: + return SvtSaveOptions::ODFSVER_013; } - return ODFSVER_LATEST_EXTENDED; -} - -bool SvtSaveOptions::IsReadOnly( SvtSaveOptions::EOption eOption ) const -{ - return pImp->pSaveOpt->IsReadOnly(eOption); + return SvtSaveOptions::ODFSVER_LATEST_EXTENDED; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |