Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <unotools/misccfg.hxx>
21 : #include "rtl/instance.hxx"
22 : #include <unotools/configmgr.hxx>
23 : #include <unotools/configitem.hxx>
24 : #include <tools/debug.hxx>
25 : #include <com/sun/star/uno/Any.hxx>
26 : #include <com/sun/star/uno/Sequence.hxx>
27 : #include <osl/mutex.hxx>
28 : #include "itemholder1.hxx"
29 :
30 : using namespace com::sun::star::uno;
31 :
32 : namespace utl
33 : {
34 :
35 : static SfxMiscCfg* pOptions = NULL;
36 : static sal_Int32 nRefCount = 0;
37 :
38 : class SfxMiscCfg : public utl::ConfigItem
39 : {
40 : bool bPaperSize; // printer warnings
41 : bool bPaperOrientation;
42 : bool bNotFound;
43 : sal_Int32 nYear2000; // two digit year representation
44 :
45 : const com::sun::star::uno::Sequence<OUString> GetPropertyNames();
46 : void Load();
47 :
48 : public:
49 : SfxMiscCfg( );
50 : virtual ~SfxMiscCfg( );
51 :
52 : virtual void Notify( const com::sun::star::uno::Sequence<OUString>& aPropertyNames) SAL_OVERRIDE;
53 : virtual void Commit() SAL_OVERRIDE;
54 :
55 0 : bool IsNotFoundWarning() const {return bNotFound;}
56 : void SetNotFoundWarning( bool bSet);
57 :
58 0 : bool IsPaperSizeWarning() const {return bPaperSize;}
59 : void SetPaperSizeWarning(bool bSet);
60 :
61 0 : bool IsPaperOrientationWarning() const {return bPaperOrientation;}
62 : void SetPaperOrientationWarning( bool bSet);
63 :
64 : // 0 ... 99
65 0 : sal_Int32 GetYear2000() const { return nYear2000; }
66 : void SetYear2000( sal_Int32 nSet );
67 :
68 : };
69 :
70 0 : SfxMiscCfg::SfxMiscCfg() :
71 : ConfigItem(OUString("Office.Common") ),
72 : bPaperSize(false),
73 : bPaperOrientation (false),
74 : bNotFound (false),
75 0 : nYear2000( 1930 )
76 : {
77 0 : Load();
78 0 : }
79 :
80 0 : SfxMiscCfg::~SfxMiscCfg()
81 : {
82 0 : }
83 :
84 0 : void SfxMiscCfg::SetNotFoundWarning( bool bSet)
85 : {
86 0 : if(bNotFound != bSet)
87 0 : SetModified();
88 0 : bNotFound = bSet;
89 0 : }
90 :
91 0 : void SfxMiscCfg::SetPaperSizeWarning( bool bSet)
92 : {
93 0 : if(bPaperSize != bSet)
94 0 : SetModified();
95 0 : bPaperSize = bSet;
96 0 : }
97 :
98 0 : void SfxMiscCfg::SetPaperOrientationWarning( bool bSet)
99 : {
100 0 : if(bPaperOrientation != bSet)
101 0 : SetModified();
102 0 : bPaperOrientation = bSet;
103 0 : }
104 :
105 0 : void SfxMiscCfg::SetYear2000( sal_Int32 nSet )
106 : {
107 0 : if(nYear2000 != nSet)
108 0 : SetModified();
109 0 : nYear2000 = nSet;
110 0 : }
111 :
112 0 : const Sequence<OUString> SfxMiscCfg::GetPropertyNames()
113 : {
114 : const OUString pProperties[] =
115 : {
116 : OUString("Print/Warning/PaperSize"),
117 : OUString("Print/Warning/PaperOrientation"),
118 : OUString("Print/Warning/NotFound"),
119 : OUString("DateFormat/TwoDigitYear")
120 0 : };
121 0 : const Sequence< OUString > seqPropertyNames( pProperties, 4 );
122 0 : return seqPropertyNames;
123 : }
124 :
125 0 : void SfxMiscCfg::Load()
126 : {
127 0 : const Sequence<OUString>& rNames = GetPropertyNames();
128 0 : Sequence<Any> aValues = GetProperties(rNames);
129 0 : EnableNotification(rNames);
130 0 : const Any* pValues = aValues.getConstArray();
131 : DBG_ASSERT(aValues.getLength() == rNames.getLength(), "GetProperties failed");
132 0 : if(aValues.getLength() == rNames.getLength())
133 : {
134 0 : for(int nProp = 0; nProp < rNames.getLength(); nProp++)
135 : {
136 0 : if(pValues[nProp].hasValue())
137 : {
138 0 : switch(nProp)
139 : {
140 0 : case 0: bPaperSize = *(sal_Bool*)pValues[nProp].getValue(); break; //"Print/Warning/PaperSize",
141 0 : case 1: bPaperOrientation = *(sal_Bool*)pValues[nProp].getValue(); break; //"Print/Warning/PaperOrientation",
142 0 : case 2: bNotFound = *(sal_Bool*)pValues[nProp].getValue(); break; //"Print/Warning/NotFound",
143 0 : case 3: pValues[nProp] >>= nYear2000;break; //"DateFormat/TwoDigitYear",
144 : }
145 : }
146 : }
147 0 : }
148 0 : }
149 :
150 0 : void SfxMiscCfg::Notify( const com::sun::star::uno::Sequence<OUString>& )
151 : {
152 0 : Load();
153 0 : }
154 :
155 0 : void SfxMiscCfg::Commit()
156 : {
157 0 : const Sequence<OUString>& rNames = GetPropertyNames();
158 0 : Sequence<Any> aValues(rNames.getLength());
159 0 : Any* pValues = aValues.getArray();
160 :
161 0 : const Type& rType = ::getBooleanCppuType();
162 0 : for(int nProp = 0; nProp < rNames.getLength(); nProp++)
163 : {
164 0 : switch(nProp)
165 : {
166 0 : case 0: pValues[nProp].setValue(&bPaperSize, rType);break; //"Print/Warning/PaperSize",
167 0 : case 1: pValues[nProp].setValue(&bPaperOrientation, rType);break; //"Print/Warning/PaperOrientation",
168 0 : case 2: pValues[nProp].setValue(&bNotFound, rType);break; //"Print/Warning/NotFound",
169 0 : case 3: pValues[nProp] <<= nYear2000;break; //"DateFormat/TwoDigitYear",
170 : }
171 : }
172 0 : PutProperties(rNames, aValues);
173 0 : }
174 :
175 : namespace
176 : {
177 : class LocalSingleton : public rtl::Static< osl::Mutex, LocalSingleton >
178 : {
179 : };
180 : }
181 :
182 0 : MiscCfg::MiscCfg( )
183 : {
184 : // Global access, must be guarded (multithreading)
185 0 : ::osl::MutexGuard aGuard( LocalSingleton::get() );
186 0 : if ( !pOptions )
187 : {
188 0 : pOptions = new SfxMiscCfg;
189 :
190 0 : ItemHolder1::holdConfigItem(E_MISCCFG);
191 : }
192 :
193 0 : ++nRefCount;
194 0 : pImpl = pOptions;
195 0 : pImpl->AddListener(this);
196 0 : }
197 :
198 0 : MiscCfg::~MiscCfg( )
199 : {
200 : // Global access, must be guarded (multithreading)
201 0 : ::osl::MutexGuard aGuard( LocalSingleton::get() );
202 0 : pImpl->RemoveListener(this);
203 0 : if ( !--nRefCount )
204 : {
205 0 : if ( pOptions->IsModified() )
206 0 : pOptions->Commit();
207 0 : DELETEZ( pOptions );
208 0 : }
209 0 : }
210 :
211 0 : bool MiscCfg::IsNotFoundWarning() const
212 : {
213 0 : return pImpl->IsNotFoundWarning();
214 : }
215 :
216 0 : void MiscCfg::SetNotFoundWarning( bool bSet)
217 : {
218 0 : pImpl->SetNotFoundWarning( bSet );
219 0 : }
220 :
221 0 : bool MiscCfg::IsPaperSizeWarning() const
222 : {
223 0 : return pImpl->IsPaperSizeWarning();
224 : }
225 :
226 0 : void MiscCfg::SetPaperSizeWarning(bool bSet)
227 : {
228 0 : pImpl->SetPaperSizeWarning( bSet );
229 0 : }
230 :
231 0 : bool MiscCfg::IsPaperOrientationWarning() const
232 : {
233 0 : return pImpl->IsPaperOrientationWarning();
234 : }
235 :
236 0 : void MiscCfg::SetPaperOrientationWarning( bool bSet)
237 : {
238 0 : pImpl->SetPaperOrientationWarning( bSet );
239 0 : }
240 :
241 0 : sal_Int32 MiscCfg::GetYear2000() const
242 : {
243 0 : return pImpl->GetYear2000();
244 : }
245 :
246 0 : void MiscCfg::SetYear2000( sal_Int32 nSet )
247 : {
248 0 : pImpl->SetYear2000( nSet );
249 0 : }
250 :
251 : }
252 :
253 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|