update emoji autocorrect entries from po-files
[LibreOffice.git] / unotools / source / config / printwarningoptions.cxx
blob166e845f1711ae7c8900d24836e5a0e9caac2636
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 .
20 #include <unotools/printwarningoptions.hxx>
21 #include <unotools/configmgr.hxx>
22 #include <unotools/configitem.hxx>
23 #include <tools/debug.hxx>
24 #include <com/sun/star/uno/Any.hxx>
25 #include <com/sun/star/uno/Sequence.hxx>
27 #include "itemholder1.hxx"
29 // namespaces
31 using namespace ::utl;
32 using namespace ::osl;
33 using namespace ::com::sun::star::uno;
35 #define ROOTNODE_START OUString("Office.Common/Print")
37 #define PROPERTYNAME_PAPERSIZE OUString("Warning/PaperSize")
38 #define PROPERTYNAME_PAPERORIENTATION OUString("Warning/PaperOrientation")
39 #define PROPERTYNAME_NOTFOUND OUString("Warning/NotFound")
40 #define PROPERTYNAME_TRANSPARENCY OUString("Warning/Transparency")
41 #define PROPERTYNAME_PRINTINGMODIFIESDOCUMENT OUString("PrintingModifiesDocument")
43 #define PROPERTYHANDLE_PAPERSIZE 0
44 #define PROPERTYHANDLE_PAPERORIENTATION 1
45 #define PROPERTYHANDLE_NOTFOUND 2
46 #define PROPERTYHANDLE_TRANSPARENCY 3
47 #define PROPERTYHDL_PRINTINGMODIFIESDOCUMENT 4
49 #define PROPERTYCOUNT 5
51 class SvtPrintWarningOptions_Impl : public ConfigItem
53 public:
55 // constructor / destructor
57 SvtPrintWarningOptions_Impl();
58 virtual ~SvtPrintWarningOptions_Impl();
60 // override methods of baseclass
62 virtual void Notify( const com::sun::star::uno::Sequence< OUString >& aPropertyNames ) SAL_OVERRIDE;
64 // public interface
66 bool IsPaperSize() const { return m_bPaperSize; }
67 bool IsPaperOrientation() const { return m_bPaperOrientation; }
68 bool IsTransparency() const { return m_bTransparency; }
69 bool IsModifyDocumentOnPrintingAllowed() const { return m_bModifyDocumentOnPrintingAllowed; }
71 void SetPaperSize( bool bState ) { m_bPaperSize = bState; SetModified(); }
72 void SetPaperOrientation( bool bState ) { m_bPaperOrientation = bState; SetModified(); }
73 void SetTransparency( bool bState ) { m_bTransparency = bState; SetModified(); }
74 void SetModifyDocumentOnPrintingAllowed( bool bState ) { m_bModifyDocumentOnPrintingAllowed = bState; SetModified(); }
76 // private methods
78 private:
80 virtual void ImplCommit() SAL_OVERRIDE;
82 static Sequence< OUString > impl_GetPropertyNames();
84 // private member
86 private:
88 bool m_bPaperSize;
89 bool m_bPaperOrientation;
90 bool m_bNotFound;
91 bool m_bTransparency;
92 bool m_bModifyDocumentOnPrintingAllowed;
95 // constructor
97 SvtPrintWarningOptions_Impl::SvtPrintWarningOptions_Impl() :
98 ConfigItem( ROOTNODE_START ),
99 m_bPaperSize( false ),
100 m_bPaperOrientation( false ),
101 m_bNotFound( false ),
102 m_bTransparency( true ),
103 m_bModifyDocumentOnPrintingAllowed( true )
105 Sequence< OUString > seqNames( impl_GetPropertyNames() );
106 Sequence< Any > seqValues( GetProperties( seqNames ) );
108 DBG_ASSERT( !(seqNames.getLength()!=seqValues.getLength()), "SvtPrintWarningOptions_Impl::SvtPrintWarningOptions_Impl()\nI miss some values of configuration keys!\n" );
110 // Copy values from list in right order to our internal member.
111 sal_Int32 nPropertyCount = seqValues.getLength();
112 sal_Int32 nProperty = 0;
114 for( nProperty=0; nProperty<nPropertyCount; ++nProperty )
116 DBG_ASSERT( seqValues[nProperty].hasValue(), "SvtPrintWarningOptions_Impl::SvtPrintWarningOptions_Impl()\nInvalid property value for property detected!\n" );
118 switch( nProperty )
120 case PROPERTYHANDLE_PAPERSIZE:
122 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
123 seqValues[nProperty] >>= m_bPaperSize;
125 break;
127 case PROPERTYHANDLE_PAPERORIENTATION:
129 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
130 seqValues[nProperty] >>= m_bPaperOrientation;
132 break;
134 case PROPERTYHANDLE_NOTFOUND:
136 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
137 seqValues[nProperty] >>= m_bNotFound;
139 break;
141 case PROPERTYHANDLE_TRANSPARENCY:
143 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
144 seqValues[nProperty] >>= m_bTransparency;
146 break;
147 case PROPERTYHDL_PRINTINGMODIFIESDOCUMENT:
149 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
150 seqValues[nProperty] >>= m_bModifyDocumentOnPrintingAllowed;
152 break;
158 // destructor
160 SvtPrintWarningOptions_Impl::~SvtPrintWarningOptions_Impl()
162 assert(!IsModified()); // should have been committed
165 // Commit
167 void SvtPrintWarningOptions_Impl::ImplCommit()
169 Sequence< OUString > aSeqNames( impl_GetPropertyNames() );
170 Sequence< Any > aSeqValues( aSeqNames.getLength() );
172 for( sal_Int32 nProperty = 0, nCount = aSeqNames.getLength(); nProperty < nCount; ++nProperty )
174 switch( nProperty )
176 case PROPERTYHANDLE_PAPERSIZE:
177 aSeqValues[nProperty] <<= m_bPaperSize;
178 break;
180 case PROPERTYHANDLE_PAPERORIENTATION:
181 aSeqValues[nProperty] <<= m_bPaperOrientation;
182 break;
184 case PROPERTYHANDLE_NOTFOUND:
185 aSeqValues[nProperty] <<= m_bNotFound;
186 break;
188 case PROPERTYHANDLE_TRANSPARENCY:
189 aSeqValues[nProperty] <<= m_bTransparency;
190 break;
191 case PROPERTYHDL_PRINTINGMODIFIESDOCUMENT:
192 aSeqValues[nProperty] <<= m_bModifyDocumentOnPrintingAllowed;
193 break;
197 PutProperties( aSeqNames, aSeqValues );
200 void SvtPrintWarningOptions_Impl::Notify( const Sequence< OUString >& )
204 // private method
206 Sequence< OUString > SvtPrintWarningOptions_Impl::impl_GetPropertyNames()
208 // Build list of configuration key names.
209 const OUString pProperties[] =
211 PROPERTYNAME_PAPERSIZE,
212 PROPERTYNAME_PAPERORIENTATION,
213 PROPERTYNAME_NOTFOUND,
214 PROPERTYNAME_TRANSPARENCY,
215 PROPERTYNAME_PRINTINGMODIFIESDOCUMENT
218 // Initialize return sequence with these list ...
219 const Sequence< OUString > seqPropertyNames( pProperties, PROPERTYCOUNT );
221 return seqPropertyNames;
224 // initialize static member
225 // DON'T DO IT IN YOUR HEADER!
226 // see definition for further information
228 SvtPrintWarningOptions_Impl* SvtPrintWarningOptions::m_pDataContainer = NULL;
229 sal_Int32 SvtPrintWarningOptions::m_nRefCount = 0;
231 // constructor
233 SvtPrintWarningOptions::SvtPrintWarningOptions()
235 // Global access, must be guarded (multithreading!).
236 MutexGuard aGuard( GetOwnStaticMutex() );
237 // Increase our refcount ...
238 ++m_nRefCount;
239 // ... and initialize our data container only if it not already!
240 if( m_pDataContainer == NULL )
242 m_pDataContainer = new SvtPrintWarningOptions_Impl();
243 ItemHolder1::holdConfigItem(E_PRINTWARNINGOPTIONS);
247 // destructor
249 SvtPrintWarningOptions::~SvtPrintWarningOptions()
251 // Global access, must be guarded (multithreading!)
252 MutexGuard aGuard( GetOwnStaticMutex() );
253 // Decrease our refcount.
254 --m_nRefCount;
255 // If last instance was deleted ...
256 // we must destroy our static data container!
257 if( m_nRefCount <= 0 )
259 delete m_pDataContainer;
260 m_pDataContainer = NULL;
264 // public method
266 bool SvtPrintWarningOptions::IsPaperSize() const
268 MutexGuard aGuard( GetOwnStaticMutex() );
269 return m_pDataContainer->IsPaperSize();
272 // public method
274 bool SvtPrintWarningOptions::IsPaperOrientation() const
276 MutexGuard aGuard( GetOwnStaticMutex() );
277 return m_pDataContainer->IsPaperOrientation();
280 // public method
282 bool SvtPrintWarningOptions::IsTransparency() const
284 MutexGuard aGuard( GetOwnStaticMutex() );
285 return m_pDataContainer->IsTransparency();
288 // public method
290 void SvtPrintWarningOptions::SetPaperSize( bool bState )
292 MutexGuard aGuard( GetOwnStaticMutex() );
293 m_pDataContainer->SetPaperSize( bState );
296 // public method
298 void SvtPrintWarningOptions::SetPaperOrientation( bool bState )
300 MutexGuard aGuard( GetOwnStaticMutex() );
301 m_pDataContainer->SetPaperOrientation( bState );
304 // public method
306 void SvtPrintWarningOptions::SetTransparency( bool bState )
308 MutexGuard aGuard( GetOwnStaticMutex() );
309 m_pDataContainer->SetTransparency( bState );
312 bool SvtPrintWarningOptions::IsModifyDocumentOnPrintingAllowed() const
314 MutexGuard aGuard( GetOwnStaticMutex() );
315 return m_pDataContainer->IsModifyDocumentOnPrintingAllowed();
318 void SvtPrintWarningOptions::SetModifyDocumentOnPrintingAllowed( bool bState )
320 MutexGuard aGuard( GetOwnStaticMutex() );
321 m_pDataContainer->SetModifyDocumentOnPrintingAllowed( bState );
324 namespace
326 class thePrintWarningOptionsMutex : public rtl::Static<osl::Mutex, thePrintWarningOptionsMutex>{};
329 // private method
331 Mutex& SvtPrintWarningOptions::GetOwnStaticMutex()
333 return thePrintWarningOptionsMutex::get();
336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */