bump product version to 4.1.6.2
[LibreOffice.git] / unotools / source / config / misccfg.cxx
blob569c9f475295296aa5e2b487be84532259e66d84
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include <unotools/misccfg.hxx>
22 #include "rtl/instance.hxx"
23 #include <unotools/configmgr.hxx>
24 #include <unotools/configitem.hxx>
25 #include <tools/debug.hxx>
26 #include <com/sun/star/uno/Any.hxx>
27 #include <com/sun/star/uno/Sequence.hxx>
28 #include <osl/mutex.hxx>
29 #include <rtl/logfile.hxx>
30 #include "itemholder1.hxx"
32 using namespace com::sun::star::uno;
35 namespace utl
38 static SfxMiscCfg* pOptions = NULL;
39 static sal_Int32 nRefCount = 0;
41 class SfxMiscCfg : public utl::ConfigItem
43 sal_Bool bPaperSize; // printer warnings
44 sal_Bool bPaperOrientation;
45 sal_Bool bNotFound;
46 sal_Int32 nYear2000; // two digit year representation
48 const com::sun::star::uno::Sequence<OUString> GetPropertyNames();
49 void Load();
51 public:
52 SfxMiscCfg( );
53 ~SfxMiscCfg( );
55 virtual void Notify( const com::sun::star::uno::Sequence<OUString>& aPropertyNames);
56 virtual void Commit();
58 sal_Bool IsNotFoundWarning() const {return bNotFound;}
59 void SetNotFoundWarning( sal_Bool bSet);
61 sal_Bool IsPaperSizeWarning() const {return bPaperSize;}
62 void SetPaperSizeWarning(sal_Bool bSet);
64 sal_Bool IsPaperOrientationWarning() const {return bPaperOrientation;}
65 void SetPaperOrientationWarning( sal_Bool bSet);
67 // 0 ... 99
68 sal_Int32 GetYear2000() const { return nYear2000; }
69 void SetYear2000( sal_Int32 nSet );
73 SfxMiscCfg::SfxMiscCfg() :
74 ConfigItem(OUString("Office.Common") ),
75 bPaperSize(sal_False),
76 bPaperOrientation (sal_False),
77 bNotFound (sal_False),
78 nYear2000( 1930 )
80 RTL_LOGFILE_CONTEXT(aLog, "svl SfxMiscCfg::SfxMiscCfg()");
82 Load();
85 SfxMiscCfg::~SfxMiscCfg()
89 void SfxMiscCfg::SetNotFoundWarning( sal_Bool bSet)
91 if(bNotFound != bSet)
92 SetModified();
93 bNotFound = bSet;
96 void SfxMiscCfg::SetPaperSizeWarning( sal_Bool bSet)
98 if(bPaperSize != bSet)
99 SetModified();
100 bPaperSize = bSet;
103 void SfxMiscCfg::SetPaperOrientationWarning( sal_Bool bSet)
105 if(bPaperOrientation != bSet)
106 SetModified();
107 bPaperOrientation = bSet;
110 void SfxMiscCfg::SetYear2000( sal_Int32 nSet )
112 if(nYear2000 != nSet)
113 SetModified();
114 nYear2000 = nSet;
117 const Sequence<OUString> SfxMiscCfg::GetPropertyNames()
119 const OUString pProperties[] =
121 OUString("Print/Warning/PaperSize"),
122 OUString("Print/Warning/PaperOrientation"),
123 OUString("Print/Warning/NotFound"),
124 OUString("DateFormat/TwoDigitYear")
126 const Sequence< OUString > seqPropertyNames( pProperties, 4 );
127 return seqPropertyNames;
130 void SfxMiscCfg::Load()
132 const Sequence<OUString>& rNames = GetPropertyNames();
133 Sequence<Any> aValues = GetProperties(rNames);
134 EnableNotification(rNames);
135 const Any* pValues = aValues.getConstArray();
136 DBG_ASSERT(aValues.getLength() == rNames.getLength(), "GetProperties failed");
137 if(aValues.getLength() == rNames.getLength())
139 for(int nProp = 0; nProp < rNames.getLength(); nProp++)
141 if(pValues[nProp].hasValue())
143 switch(nProp)
145 case 0: bPaperSize = *(sal_Bool*)pValues[nProp].getValue(); break; //"Print/Warning/PaperSize",
146 case 1: bPaperOrientation = *(sal_Bool*)pValues[nProp].getValue(); break; //"Print/Warning/PaperOrientation",
147 case 2: bNotFound = *(sal_Bool*)pValues[nProp].getValue() ; break; //"Print/Warning/NotFound",
148 case 3: pValues[nProp] >>= nYear2000;break; //"DateFormat/TwoDigitYear",
155 void SfxMiscCfg::Notify( const com::sun::star::uno::Sequence<OUString>& )
157 Load();
160 void SfxMiscCfg::Commit()
162 const Sequence<OUString>& rNames = GetPropertyNames();
163 Sequence<Any> aValues(rNames.getLength());
164 Any* pValues = aValues.getArray();
166 const Type& rType = ::getBooleanCppuType();
167 for(int nProp = 0; nProp < rNames.getLength(); nProp++)
169 switch(nProp)
171 case 0: pValues[nProp].setValue(&bPaperSize, rType);break; //"Print/Warning/PaperSize",
172 case 1: pValues[nProp].setValue(&bPaperOrientation, rType);break; //"Print/Warning/PaperOrientation",
173 case 2: pValues[nProp].setValue(&bNotFound, rType);break; //"Print/Warning/NotFound",
174 case 3: pValues[nProp] <<= nYear2000;break; //"DateFormat/TwoDigitYear",
177 PutProperties(rNames, aValues);
179 // -----------------------------------------------------------------------
180 namespace
182 class LocalSingleton : public rtl::Static< osl::Mutex, LocalSingleton >
187 MiscCfg::MiscCfg( )
189 // Global access, must be guarded (multithreading)
190 ::osl::MutexGuard aGuard( LocalSingleton::get() );
191 if ( !pOptions )
193 RTL_LOGFILE_CONTEXT(aLog, "unotools ( ??? ) SfxMiscCfg::ctor()");
194 pOptions = new SfxMiscCfg;
196 ItemHolder1::holdConfigItem(E_MISCCFG);
199 ++nRefCount;
200 pImpl = pOptions;
201 pImpl->AddListener(this);
204 MiscCfg::~MiscCfg( )
206 // Global access, must be guarded (multithreading)
207 ::osl::MutexGuard aGuard( LocalSingleton::get() );
208 pImpl->RemoveListener(this);
209 if ( !--nRefCount )
211 if ( pOptions->IsModified() )
212 pOptions->Commit();
213 DELETEZ( pOptions );
217 sal_Bool MiscCfg::IsNotFoundWarning() const
219 return pImpl->IsNotFoundWarning();
222 void MiscCfg::SetNotFoundWarning( sal_Bool bSet)
224 pImpl->SetNotFoundWarning( bSet );
227 sal_Bool MiscCfg::IsPaperSizeWarning() const
229 return pImpl->IsPaperSizeWarning();
232 void MiscCfg::SetPaperSizeWarning(sal_Bool bSet)
234 pImpl->SetPaperSizeWarning( bSet );
237 sal_Bool MiscCfg::IsPaperOrientationWarning() const
239 return pImpl->IsPaperOrientationWarning();
242 void MiscCfg::SetPaperOrientationWarning( sal_Bool bSet)
244 pImpl->SetPaperOrientationWarning( bSet );
247 sal_Int32 MiscCfg::GetYear2000() const
249 return pImpl->GetYear2000();
252 void MiscCfg::SetYear2000( sal_Int32 nSet )
254 pImpl->SetYear2000( nSet );
259 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */