summaryrefslogtreecommitdiff
path: root/svtools
diff options
context:
space:
mode:
authorXisco Fauli <anistenis@gmail.com>2016-06-15 01:56:58 +0200
committerNoel Grandin <noelgrandin@gmail.com>2016-06-17 09:33:05 +0000
commit81071d8a877c5883b871a2699955ab3ef62b0bee (patch)
tree7f9ba40f149dc93ff09f3bbf9a394ef81fa24018 /svtools
parent63db3a2bf78225b9304d08397c9c53316a3c9d4a (diff)
tdf#89329: use shared_ptr for pImpl in helpopt
Change-Id: I9d3fa64405f70cfa942935eaae6cc520f172d70d Reviewed-on: https://gerrit.libreoffice.org/26281 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'svtools')
-rw-r--r--svtools/source/config/helpopt.cxx56
1 files changed, 27 insertions, 29 deletions
diff --git a/svtools/source/config/helpopt.cxx b/svtools/source/config/helpopt.cxx
index 94edac0a1b1b..ca6b9c0ea2e4 100644
--- a/svtools/source/config/helpopt.cxx
+++ b/svtools/source/config/helpopt.cxx
@@ -36,9 +36,10 @@ using namespace utl;
using namespace com::sun::star::uno;
using namespace com::sun::star;
-
-static SvtHelpOptions_Impl* pOptions = nullptr;
-static sal_Int32 nRefCount = 0;
+namespace {
+ //global
+ std::weak_ptr<SvtHelpOptions_Impl> g_pHelpOptions;
+}
enum class HelpProperty
{
@@ -60,10 +61,11 @@ class SvtHelpOptions_Impl : public utl::ConfigItem
static Sequence< OUString > GetPropertyNames();
- virtual void ImplCommit() override;
+ virtual void ImplCommit() SAL_FINAL override;
public:
SvtHelpOptions_Impl();
+ ~SvtHelpOptions_Impl();
virtual void Notify( const css::uno::Sequence< OUString >& aPropertyNames ) override;
void Load( const css::uno::Sequence< OUString>& aPropertyNames);
@@ -119,7 +121,6 @@ Sequence< OUString > SvtHelpOptions_Impl::GetPropertyNames()
return *pMutex;
}
-
SvtHelpOptions_Impl::SvtHelpOptions_Impl()
: ConfigItem( OUString( "Office.Common/Help" ) )
, bExtendedHelp( false )
@@ -131,6 +132,11 @@ SvtHelpOptions_Impl::SvtHelpOptions_Impl()
EnableNotification( aNames );
}
+SvtHelpOptions_Impl::~SvtHelpOptions_Impl()
+{
+ if ( IsModified() )
+ Commit();
+}
static int lcl_MapPropertyName( const OUString& rCompare,
const uno::Sequence< OUString>& aInternalPropertyNames)
@@ -211,7 +217,6 @@ void SvtHelpOptions_Impl::Load(const uno::Sequence< OUString>& rPropertyNames)
}
}
-
void SvtHelpOptions_Impl::ImplCommit()
{
Sequence< OUString > aNames = GetPropertyNames();
@@ -246,7 +251,6 @@ void SvtHelpOptions_Impl::ImplCommit()
PutProperties( aNames, aValues );
}
-
void SvtHelpOptions_Impl::Notify( const Sequence<OUString>& aPropertyNames )
{
Load( aPropertyNames );
@@ -256,73 +260,67 @@ SvtHelpOptions::SvtHelpOptions()
{
// Global access, must be guarded (multithreading)
::osl::MutexGuard aGuard( SvtHelpOptions_Impl::getInitMutex() );
- ++nRefCount;
- if ( !pOptions )
- {
- pOptions = new SvtHelpOptions_Impl;
+ pImpl = g_pHelpOptions.lock();
+ if ( !pImpl )
+ {
+ pImpl = std::make_shared<SvtHelpOptions_Impl>();
+ g_pHelpOptions = pImpl;
svtools::ItemHolder2::holdConfigItem(E_HELPOPTIONS);
}
- pImp = pOptions;
}
-
SvtHelpOptions::~SvtHelpOptions()
{
// Global access, must be guarded (multithreading)
::osl::MutexGuard aGuard( SvtHelpOptions_Impl::getInitMutex() );
- if ( !--nRefCount )
- {
- if ( pOptions->IsModified() )
- pOptions->Commit();
- DELETEZ( pOptions );
- }
+
+ pImpl.reset();
}
void SvtHelpOptions::SetExtendedHelp( bool b )
{
- pImp->SetExtendedHelp( b );
+ pImpl->SetExtendedHelp( b );
}
bool SvtHelpOptions::IsExtendedHelp() const
{
- return pImp->IsExtendedHelp();
+ return pImpl->IsExtendedHelp();
}
void SvtHelpOptions::SetHelpTips( bool b )
{
- pImp->SetHelpTips( b );
+ pImpl->SetHelpTips( b );
}
bool SvtHelpOptions::IsHelpTips() const
{
- return pImp->IsHelpTips();
+ return pImpl->IsHelpTips();
}
-
void SvtHelpOptions::SetWelcomeScreen( bool b )
{
- pImp->SetWelcomeScreen( b );
+ pImpl->SetWelcomeScreen( b );
}
bool SvtHelpOptions::IsWelcomeScreen() const
{
- return pImp->IsWelcomeScreen();
+ return pImpl->IsWelcomeScreen();
}
OUString SvtHelpOptions::GetSystem() const
{
- return pImp->GetSystem();
+ return pImpl->GetSystem();
}
const OUString& SvtHelpOptions::GetHelpStyleSheet()const
{
- return pImp->GetHelpStyleSheet();
+ return pImpl->GetHelpStyleSheet();
}
void SvtHelpOptions::SetHelpStyleSheet(const OUString& rStyleSheet)
{
- pImp->SetHelpStyleSheet(rStyleSheet);
+ pImpl->SetHelpStyleSheet(rStyleSheet);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */