1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <o3tl/any.hxx>
23 #include <unotools/misccfg.hxx>
24 #include <rtl/instance.hxx>
25 #include <unotools/configitem.hxx>
26 #include <tools/debug.hxx>
27 #include <com/sun/star/uno/Sequence.hxx>
28 #include <osl/mutex.hxx>
29 #include "itemholder1.hxx"
31 using namespace com::sun::star::uno
;
37 static std::weak_ptr
<SfxMiscCfg
> g_pOptions
;
39 class SfxMiscCfg
: public utl::ConfigItem
42 bool bPaperSize
; // printer warnings
43 bool bPaperOrientation
;
45 sal_Int32 nYear2000
; // two digit year representation
47 static css::uno::Sequence
<OUString
> GetPropertyNames();
50 virtual void ImplCommit() final override
;
54 virtual ~SfxMiscCfg( ) override
;
56 virtual void Notify( const css::uno::Sequence
<OUString
>& aPropertyNames
) override
;
58 bool IsNotFoundWarning() const {return bNotFound
;}
59 void SetNotFoundWarning( bool bSet
);
61 bool IsPaperSizeWarning() const {return bPaperSize
;}
62 void SetPaperSizeWarning(bool bSet
);
64 bool IsPaperOrientationWarning() const {return bPaperOrientation
;}
65 void SetPaperOrientationWarning( bool bSet
);
68 sal_Int32
GetYear2000() const { return nYear2000
; }
69 void SetYear2000( sal_Int32 nSet
);
73 SfxMiscCfg::SfxMiscCfg() :
74 ConfigItem( "Office.Common" ),
76 bPaperOrientation (false),
83 SfxMiscCfg::~SfxMiscCfg()
89 void SfxMiscCfg::SetNotFoundWarning( bool bSet
)
96 void SfxMiscCfg::SetPaperSizeWarning( bool bSet
)
98 if(bPaperSize
!= bSet
)
103 void SfxMiscCfg::SetPaperOrientationWarning( bool bSet
)
105 if(bPaperOrientation
!= bSet
)
107 bPaperOrientation
= bSet
;
110 void SfxMiscCfg::SetYear2000( sal_Int32 nSet
)
112 if(nYear2000
!= nSet
)
117 Sequence
<OUString
> SfxMiscCfg::GetPropertyNames()
121 OUString("Print/Warning/PaperSize"),
122 OUString("Print/Warning/PaperOrientation"),
123 OUString("Print/Warning/NotFound"),
124 OUString("DateFormat/TwoDigitYear")
128 void SfxMiscCfg::Load()
130 const Sequence
<OUString
>& rNames
= GetPropertyNames();
131 Sequence
<Any
> aValues
= GetProperties(rNames
);
132 EnableNotification(rNames
);
133 const Any
* pValues
= aValues
.getConstArray();
134 DBG_ASSERT(aValues
.getLength() == rNames
.getLength(), "GetProperties failed");
135 if(aValues
.getLength() == rNames
.getLength())
137 for(int nProp
= 0; nProp
< rNames
.getLength(); nProp
++)
139 if(pValues
[nProp
].hasValue())
143 case 0: bPaperSize
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break; //"Print/Warning/PaperSize",
144 case 1: bPaperOrientation
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break; //"Print/Warning/PaperOrientation",
145 case 2: bNotFound
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break; //"Print/Warning/NotFound",
146 case 3: pValues
[nProp
] >>= nYear2000
;break; //"DateFormat/TwoDigitYear",
153 void SfxMiscCfg::Notify( const css::uno::Sequence
<OUString
>& )
158 void SfxMiscCfg::ImplCommit()
160 const Sequence
<OUString
>& rNames
= GetPropertyNames();
161 Sequence
<Any
> aValues(rNames
.getLength());
162 Any
* pValues
= aValues
.getArray();
164 for(int nProp
= 0; nProp
< rNames
.getLength(); nProp
++)
168 case 0: pValues
[nProp
] <<= bPaperSize
;break; //"Print/Warning/PaperSize",
169 case 1: pValues
[nProp
] <<= bPaperOrientation
;break; //"Print/Warning/PaperOrientation",
170 case 2: pValues
[nProp
] <<= bNotFound
;break; //"Print/Warning/NotFound",
171 case 3: pValues
[nProp
] <<= nYear2000
;break; //"DateFormat/TwoDigitYear",
174 PutProperties(rNames
, aValues
);
179 class LocalSingleton
: public rtl::Static
< osl::Mutex
, LocalSingleton
>
186 // Global access, must be guarded (multithreading)
187 ::osl::MutexGuard
aGuard( LocalSingleton::get() );
188 m_pImpl
= g_pOptions
.lock();
191 m_pImpl
= std::make_shared
<SfxMiscCfg
>();
192 g_pOptions
= m_pImpl
;
193 ItemHolder1::holdConfigItem(EItem::MiscConfig
);
196 m_pImpl
->AddListener(this);
201 // Global access, must be guarded (multithreading)
202 ::osl::MutexGuard
aGuard( LocalSingleton::get() );
203 m_pImpl
->RemoveListener(this);
207 bool MiscCfg::IsNotFoundWarning() const
209 return m_pImpl
->IsNotFoundWarning();
212 void MiscCfg::SetNotFoundWarning( bool bSet
)
214 m_pImpl
->SetNotFoundWarning( bSet
);
217 bool MiscCfg::IsPaperSizeWarning() const
219 return m_pImpl
->IsPaperSizeWarning();
222 void MiscCfg::SetPaperSizeWarning(bool bSet
)
224 m_pImpl
->SetPaperSizeWarning( bSet
);
227 bool MiscCfg::IsPaperOrientationWarning() const
229 return m_pImpl
->IsPaperOrientationWarning();
232 void MiscCfg::SetPaperOrientationWarning( bool bSet
)
234 m_pImpl
->SetPaperOrientationWarning( bSet
);
237 sal_Int32
MiscCfg::GetYear2000() const
239 return m_pImpl
->GetYear2000();
242 void MiscCfg::SetYear2000( sal_Int32 nSet
)
244 m_pImpl
->SetYear2000( nSet
);
249 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */