xref: /trunk/main/unotools/source/config/saveopt.cxx (revision b5088357)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_unotools.hxx"
26 
27 #ifndef GCC
28 #endif
29 
30 #include <unotools/saveopt.hxx>
31 #include "rtl/instance.hxx"
32 #include <unotools/configmgr.hxx>
33 #include <unotools/configitem.hxx>
34 #include <tools/debug.hxx>
35 #include <com/sun/star/uno/Any.hxx>
36 #include <com/sun/star/uno/Sequence.hxx>
37 
38 #include <osl/mutex.hxx>
39 #include <comphelper/configurationhelper.hxx>
40 #include <unotools/processfactory.hxx>
41 #include <rtl/logfile.hxx>
42 #include "itemholder1.hxx"
43 
44 using namespace utl;
45 using namespace rtl;
46 using namespace com::sun::star::uno;
47 namespace css = ::com::sun::star;
48 
49 class SvtSaveOptions_Impl;
50 class SvtLoadOptions_Impl;
51 
52 #define CFG_READONLY_DEFAULT    sal_False
53 
54 struct SvtLoadSaveOptions_Impl
55 {
56     SvtSaveOptions_Impl* pSaveOpt;
57     SvtLoadOptions_Impl* pLoadOpt;
58 };
59 
60 static SvtLoadSaveOptions_Impl* pOptions = NULL;
61 static sal_Int32           nRefCount = 0;
62 
63 class SvtSaveOptions_Impl : public utl::ConfigItem
64 {
65     sal_Int32                           nAutoSaveTime;
66     sal_Bool                            bUseUserData,
67                                         bBackup,
68                                         bAutoSave,
69                                         bAutoSavePrompt,
70                                         bDocInfSave,
71                                         bSaveWorkingSet,
72                                         bSaveDocView,
73                                         bSaveRelINet,
74                                         bSaveRelFSys,
75 										bSaveUnpacked,
76                                         bDoPrettyPrinting,
77                                         bWarnAlienFormat,
78                                         bLoadDocPrinter,
79                                         bUseSHA1InODF12,
80                                         bUseBlowfishInODF12;
81 
82     SvtSaveOptions::ODFDefaultVersion   eODFDefaultVersion;
83 
84     sal_Bool                            bROAutoSaveTime,
85                                         bROUseUserData,
86                                         bROBackup,
87                                         bROAutoSave,
88                                         bROAutoSavePrompt,
89                                         bRODocInfSave,
90                                         bROSaveWorkingSet,
91                                         bROSaveDocView,
92                                         bROSaveRelINet,
93                                         bROSaveRelFSys,
94                                         bROSaveUnpacked,
95                                         bROWarnAlienFormat,
96                                         bRODoPrettyPrinting,
97                                         bROLoadDocPrinter,
98                                         bROODFDefaultVersion,
99                                         bROUseSHA1InODF12,
100                                         bROUseBlowfishInODF12;
101 
102 public:
103                             SvtSaveOptions_Impl();
104                             ~SvtSaveOptions_Impl();
105 
106     virtual void            Notify( const com::sun::star::uno::Sequence< rtl::OUString >& aPropertyNames );
107     virtual void            Commit();
108 
GetAutoSaveTime() const109     sal_Int32               GetAutoSaveTime() const             { return nAutoSaveTime; }
IsUseUserData() const110     sal_Bool                    IsUseUserData() const               { return bUseUserData; }
IsBackup() const111     sal_Bool                    IsBackup() const                    { return bBackup; }
IsAutoSave() const112     sal_Bool                    IsAutoSave() const                  { return bAutoSave; }
IsAutoSavePrompt() const113     sal_Bool                    IsAutoSavePrompt() const            { return bAutoSavePrompt; }
IsDocInfoSave() const114     sal_Bool                    IsDocInfoSave() const               { return bDocInfSave; }
IsSaveWorkingSet() const115     sal_Bool                    IsSaveWorkingSet() const            { return bSaveWorkingSet;         }
IsSaveDocView() const116     sal_Bool                    IsSaveDocView() const               { return bSaveDocView; }
IsSaveRelINet() const117     sal_Bool                    IsSaveRelINet() const               { return bSaveRelINet; }
IsSaveRelFSys() const118     sal_Bool                    IsSaveRelFSys() const               { return bSaveRelFSys; }
IsSaveUnpacked() const119     sal_Bool                    IsSaveUnpacked() const              { return bSaveUnpacked; }
IsPrettyPrintingEnabled() const120     sal_Bool                IsPrettyPrintingEnabled( ) const    { return bDoPrettyPrinting; }
IsWarnAlienFormat() const121     sal_Bool                IsWarnAlienFormat() const           { return bWarnAlienFormat; }
IsLoadDocPrinter() const122     sal_Bool                IsLoadDocPrinter() const            { return bLoadDocPrinter; }
IsUseSHA1InODF12() const123     sal_Bool                IsUseSHA1InODF12() const            { return bUseSHA1InODF12; }
IsUseBlowfishInODF12() const124     sal_Bool                IsUseBlowfishInODF12() const        { return bUseBlowfishInODF12; }
125 
126     SvtSaveOptions::ODFDefaultVersion
GetODFDefaultVersion() const127                             GetODFDefaultVersion() const        { return eODFDefaultVersion; }
128 
129     void                    SetAutoSaveTime( sal_Int32 n );
130     void                    SetUseUserData( sal_Bool b );
131     void                    SetBackup( sal_Bool b );
132     void                    SetAutoSave( sal_Bool b );
133     void                    SetAutoSavePrompt( sal_Bool b );
134     void                    SetDocInfoSave( sal_Bool b );
135     void                    SetSaveWorkingSet( sal_Bool b );
136     void                    SetSaveDocView( sal_Bool b );
137     void                    SetSaveRelINet( sal_Bool b );
138     void                    SetSaveRelFSys( sal_Bool b );
139     void                    SetSaveUnpacked( sal_Bool b );
140     void                    EnablePrettyPrinting( sal_Bool _bDoPP );
141     void                    SetWarnAlienFormat( sal_Bool _bDoPP );
142     void                    SetLoadDocPrinter( sal_Bool bNew );
143     void                    SetUseSHA1InODF12( sal_Bool bUse );
144     void                    SetUseBlowfishInODF12( sal_Bool bUse );
145     void                    SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion eNew );
146 
147     sal_Bool                IsReadOnly( SvtSaveOptions::EOption eOption ) const;
148 };
149 
SetAutoSaveTime(sal_Int32 n)150 void SvtSaveOptions_Impl::SetAutoSaveTime( sal_Int32 n )
151 {
152     if (!bROAutoSaveTime && nAutoSaveTime!=n)
153     {
154         nAutoSaveTime = n;
155         SetModified();
156         Commit();
157     }
158 }
159 
SetUseUserData(sal_Bool b)160 void SvtSaveOptions_Impl::SetUseUserData( sal_Bool b )
161 {
162     if (!bROUseUserData && bUseUserData!=b)
163     {
164         bUseUserData = b;
165         SetModified();
166     }
167 }
168 
SetBackup(sal_Bool b)169 void SvtSaveOptions_Impl::SetBackup( sal_Bool b )
170 {
171     if (!bROBackup && bBackup!=b)
172     {
173         bBackup = b;
174         SetModified();
175     }
176 }
177 
SetAutoSave(sal_Bool b)178 void SvtSaveOptions_Impl::SetAutoSave( sal_Bool b )
179 {
180     if (!bROAutoSave && bAutoSave!=b)
181     {
182         bAutoSave = b;
183         SetModified();
184         Commit();
185     }
186 }
187 
SetAutoSavePrompt(sal_Bool b)188 void SvtSaveOptions_Impl::SetAutoSavePrompt( sal_Bool b )
189 {
190     if (!bROAutoSavePrompt && bAutoSavePrompt!=b)
191     {
192         bAutoSavePrompt = b;
193         SetModified();
194     }
195 }
196 
SetDocInfoSave(sal_Bool b)197 void SvtSaveOptions_Impl::SetDocInfoSave(sal_Bool b)
198 {
199     if (!bRODocInfSave && bDocInfSave!=b)
200     {
201         bDocInfSave = b;
202         SetModified();
203     }
204 }
205 
SetSaveWorkingSet(sal_Bool b)206 void SvtSaveOptions_Impl::SetSaveWorkingSet( sal_Bool b )
207 {
208     if (!bROSaveWorkingSet && bSaveWorkingSet!=b)
209     {
210         bSaveWorkingSet = b;
211         SetModified();
212     }
213 }
214 
SetSaveDocView(sal_Bool b)215 void SvtSaveOptions_Impl::SetSaveDocView( sal_Bool b )
216 {
217     if (!bROSaveDocView && bSaveDocView!=b)
218     {
219         bSaveDocView = b;
220         SetModified();
221     }
222 }
223 
SetSaveRelINet(sal_Bool b)224 void SvtSaveOptions_Impl::SetSaveRelINet( sal_Bool b )
225 {
226     if (!bROSaveRelINet && bSaveRelINet!=b)
227     {
228         bSaveRelINet = b;
229         SetModified();
230     }
231 }
232 
SetSaveRelFSys(sal_Bool b)233 void SvtSaveOptions_Impl::SetSaveRelFSys( sal_Bool b )
234 {
235     if (!bROSaveRelFSys && bSaveRelFSys!=b)
236     {
237         bSaveRelFSys = b;
238         SetModified();
239     }
240 }
241 
SetSaveUnpacked(sal_Bool b)242 void SvtSaveOptions_Impl::SetSaveUnpacked( sal_Bool b )
243 {
244     if (!bROSaveUnpacked && bSaveUnpacked!=b)
245     {
246         bSaveUnpacked = b;
247         SetModified();
248     }
249 }
250 
EnablePrettyPrinting(sal_Bool _bDoPP)251 void SvtSaveOptions_Impl::EnablePrettyPrinting( sal_Bool _bDoPP )
252 {
253     if (!bRODoPrettyPrinting && bDoPrettyPrinting!=_bDoPP)
254     {
255         bDoPrettyPrinting = _bDoPP;
256         SetModified();
257     }
258 }
259 
SetWarnAlienFormat(sal_Bool _bDoPP)260 void SvtSaveOptions_Impl::SetWarnAlienFormat( sal_Bool _bDoPP )
261 {
262     if (!bROWarnAlienFormat && bWarnAlienFormat!=_bDoPP)
263     {
264         bWarnAlienFormat = _bDoPP;
265         SetModified();
266     }
267 }
268 
SetLoadDocPrinter(sal_Bool bNew)269 void SvtSaveOptions_Impl::SetLoadDocPrinter( sal_Bool bNew )
270 {
271     if ( !bROLoadDocPrinter && bLoadDocPrinter != bNew )
272     {
273         bLoadDocPrinter = bNew;
274         SetModified();
275     }
276 }
277 
SetODFDefaultVersion(SvtSaveOptions::ODFDefaultVersion eNew)278 void SvtSaveOptions_Impl::SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion eNew )
279 {
280     if ( !bROODFDefaultVersion && eODFDefaultVersion != eNew )
281     {
282         eODFDefaultVersion = eNew;
283         SetModified();
284     }
285 }
286 
SetUseSHA1InODF12(sal_Bool bUse)287 void SvtSaveOptions_Impl::SetUseSHA1InODF12( sal_Bool bUse )
288 {
289     if ( !bROUseSHA1InODF12 && bUseSHA1InODF12 != bUse )
290     {
291         bUseSHA1InODF12 = bUse;
292         SetModified();
293     }
294 }
295 
SetUseBlowfishInODF12(sal_Bool bUse)296 void SvtSaveOptions_Impl::SetUseBlowfishInODF12( sal_Bool bUse )
297 {
298     if ( !bROUseBlowfishInODF12 && bUseBlowfishInODF12 != bUse )
299     {
300         bUseBlowfishInODF12 = bUse;
301         SetModified();
302     }
303 }
304 
IsReadOnly(SvtSaveOptions::EOption eOption) const305 sal_Bool SvtSaveOptions_Impl::IsReadOnly( SvtSaveOptions::EOption eOption ) const
306 {
307     sal_Bool bReadOnly = CFG_READONLY_DEFAULT;
308     switch(eOption)
309     {
310         case SvtSaveOptions::E_AUTOSAVETIME :
311             bReadOnly = bROAutoSaveTime;
312             break;
313         case SvtSaveOptions::E_USEUSERDATA :
314             bReadOnly = bROUseUserData;
315             break;
316         case SvtSaveOptions::E_BACKUP :
317             bReadOnly = bROBackup;
318             break;
319         case SvtSaveOptions::E_AUTOSAVE :
320             bReadOnly = bROAutoSave;
321             break;
322         case SvtSaveOptions::E_AUTOSAVEPROMPT :
323             bReadOnly = bROAutoSavePrompt;
324             break;
325         case SvtSaveOptions::E_DOCINFSAVE :
326             bReadOnly = bRODocInfSave;
327             break;
328         case SvtSaveOptions::E_SAVEWORKINGSET :
329             bReadOnly = bROSaveWorkingSet;
330             break;
331         case SvtSaveOptions::E_SAVEDOCVIEW :
332             bReadOnly = bROSaveDocView;
333             break;
334         case SvtSaveOptions::E_SAVERELINET :
335             bReadOnly = bROSaveRelINet;
336             break;
337         case SvtSaveOptions::E_SAVERELFSYS :
338             bReadOnly = bROSaveRelFSys;
339             break;
340         case SvtSaveOptions::E_SAVEUNPACKED :
341             bReadOnly = bROSaveUnpacked;
342             break;
343         case SvtSaveOptions::E_DOPRETTYPRINTING :
344             bReadOnly = bRODoPrettyPrinting;
345             break;
346         case SvtSaveOptions::E_WARNALIENFORMAT :
347             bReadOnly = bROWarnAlienFormat;
348             break;
349         case SvtSaveOptions::E_LOADDOCPRINTER :
350             bReadOnly = bROLoadDocPrinter;
351             break;
352         case SvtSaveOptions::E_ODFDEFAULTVERSION :
353             bReadOnly = bROLoadDocPrinter;
354             break;
355         case SvtSaveOptions::E_USESHA1INODF12:
356             bReadOnly = bROUseSHA1InODF12;
357             break;
358         case SvtSaveOptions::E_USEBLOWFISHINODF12:
359             bReadOnly = bROUseBlowfishInODF12;
360             break;
361     }
362     return bReadOnly;
363 }
364 
365 #define FORMAT              0
366 #define TIMEINTERVALL       1
367 #define USEUSERDATA         2
368 #define CREATEBACKUP        3
369 #define AUTOSAVE            4
370 #define PROMPT              5
371 #define EDITPROPERTY        6
372 #define SAVEVIEWINFO        7
373 #define UNPACKED            8
374 #define PRETTYPRINTING      9
375 #define WARNALIENFORMAT     10
376 #define LOADDOCPRINTER      11
377 #define FILESYSTEM          12
378 #define INTERNET            13
379 #define SAVEWORKINGSET      14
380 #define ODFDEFAULTVERSION   15
381 #define USESHA1INODF12      16
382 #define USEBLOWFISHINODF12  17
383 
GetPropertyNames()384 Sequence< OUString > GetPropertyNames()
385 {
386 	static const char* aPropNames[] =
387 	{
388         "Graphic/Format",
389         "Document/AutoSaveTimeIntervall",
390         "Document/UseUserData",
391         "Document/CreateBackup",
392         "Document/AutoSave",
393         "Document/AutoSavePrompt",
394         "Document/EditProperty",
395         "Document/ViewInfo",
396 		"Document/Unpacked",
397 		"Document/PrettyPrinting",
398         "Document/WarnAlienFormat",
399         "Document/LoadPrinter",
400         "URL/FileSystem",
401         "URL/Internet",
402         "WorkingSet",
403         "ODF/DefaultVersion",
404         "ODF/UseSHA1InODF12",
405         "ODF/UseBlowfishInODF12"
406 	};
407 
408     const int nCount = sizeof( aPropNames ) / sizeof( const char* );
409 	Sequence< OUString > aNames( nCount );
410 	OUString* pNames = aNames.getArray();
411 	for ( int i = 0; i < nCount; i++ )
412 		pNames[i] = OUString::createFromAscii( aPropNames[i] );
413 
414 	return aNames;
415 }
416 
417 // -----------------------------------------------------------------------
418 
SvtSaveOptions_Impl()419 SvtSaveOptions_Impl::SvtSaveOptions_Impl()
420     : ConfigItem( OUString::createFromAscii("Office.Common/Save") )
421     , nAutoSaveTime( 0 )
422     , bUseUserData( sal_False )
423     , bBackup( sal_False )
424     , bAutoSave( sal_False )
425     , bAutoSavePrompt( sal_False )
426     , bDocInfSave( sal_False )
427     , bSaveWorkingSet( sal_False )
428     , bSaveDocView( sal_False )
429     , bSaveRelINet( sal_False )
430     , bSaveRelFSys( sal_False )
431 	, bSaveUnpacked( sal_False )
432 	, bDoPrettyPrinting( sal_False )
433     , bWarnAlienFormat( sal_True )
434     , bLoadDocPrinter( sal_True )
435     , bUseSHA1InODF12( sal_False )
436     , bUseBlowfishInODF12( sal_False )
437     , eODFDefaultVersion( SvtSaveOptions::ODFVER_LATEST )
438     , bROAutoSaveTime( CFG_READONLY_DEFAULT )
439     , bROUseUserData( CFG_READONLY_DEFAULT )
440     , bROBackup( CFG_READONLY_DEFAULT )
441     , bROAutoSave( CFG_READONLY_DEFAULT )
442     , bROAutoSavePrompt( CFG_READONLY_DEFAULT )
443     , bRODocInfSave( CFG_READONLY_DEFAULT )
444     , bROSaveWorkingSet( CFG_READONLY_DEFAULT )
445     , bROSaveDocView( CFG_READONLY_DEFAULT )
446     , bROSaveRelINet( CFG_READONLY_DEFAULT )
447     , bROSaveRelFSys( CFG_READONLY_DEFAULT )
448     , bROSaveUnpacked( CFG_READONLY_DEFAULT )
449     , bROWarnAlienFormat( CFG_READONLY_DEFAULT )
450     , bRODoPrettyPrinting( CFG_READONLY_DEFAULT )
451     , bROLoadDocPrinter( CFG_READONLY_DEFAULT )
452     , bROODFDefaultVersion( CFG_READONLY_DEFAULT )
453     , bROUseSHA1InODF12( CFG_READONLY_DEFAULT )
454     , bROUseBlowfishInODF12( CFG_READONLY_DEFAULT )
455 {
456 	Sequence< OUString > aNames = GetPropertyNames();
457 	Sequence< Any > aValues = GetProperties( aNames );
458     Sequence< sal_Bool > aROStates = GetReadOnlyStates( aNames );
459 	EnableNotification( aNames );
460 	const Any* pValues = aValues.getConstArray();
461     const sal_Bool* pROStates = aROStates.getConstArray();
462     DBG_ASSERT( aValues.getLength() == aNames.getLength(), "GetProperties failed" );
463     DBG_ASSERT( aROStates.getLength() == aNames.getLength(), "GetReadOnlyStates failed" );
464     if ( aValues.getLength() == aNames.getLength() && aROStates.getLength() == aNames.getLength() )
465 	{
466 		for ( int nProp = 0; nProp < aNames.getLength(); nProp++ )
467 		{
468 			DBG_ASSERT( pValues[nProp].hasValue(), "property value missing" );
469 			if ( pValues[nProp].hasValue() )
470 			{
471                 sal_Int32 nTemp = 0;
472 				switch ( nProp )
473 				{
474                     case FORMAT:
475                         // not supported anymore
476                         break;
477 
478                     case TIMEINTERVALL :
479                         if ( pValues[nProp] >>= nTemp )
480                             nAutoSaveTime = nTemp;
481                         else {
482                             DBG_ERROR( "Wrong Type!" );
483                         };
484                         bROAutoSaveTime = pROStates[nProp];
485                         break;
486 
487                     case ODFDEFAULTVERSION :
488                     {
489                         sal_Int16 nTmp = 0;
490                         if ( pValues[nProp] >>= nTmp )
491                         {
492                             if( nTmp == 3 )
493                                 eODFDefaultVersion = SvtSaveOptions::ODFVER_LATEST;
494                             else
495                                 eODFDefaultVersion = SvtSaveOptions::ODFDefaultVersion( nTmp );
496                         }
497                         else {
498                             DBG_ERRORFILE( "SvtSaveOptions_Impl::SvtSaveOptions_Impl(): Wrong Type!" );
499                         };
500                         bROODFDefaultVersion = pROStates[nProp];
501                         break;
502                     }
503 
504 					default:
505                     {
506                         sal_Bool bTemp = sal_Bool();
507                         if ( pValues[nProp] >>= bTemp )
508                         {
509                             switch ( nProp )
510                             {
511                                 case USEUSERDATA :
512                                     bUseUserData = bTemp;
513                                     bROUseUserData = pROStates[nProp];
514                                     break;
515                                 case CREATEBACKUP :
516                                     bBackup = bTemp;
517                                     bROBackup = pROStates[nProp];
518                                     break;
519                                 case AUTOSAVE :
520                                     bAutoSave = bTemp;
521                                     bROAutoSave = pROStates[nProp];
522                                     break;
523                                 case PROMPT :
524                                     bAutoSavePrompt = bTemp;
525                                     bROAutoSavePrompt = pROStates[nProp];
526                                     break;
527                                 case EDITPROPERTY :
528                                     bDocInfSave = bTemp;
529                                     bRODocInfSave = pROStates[nProp];
530                                     break;
531                                 case SAVEWORKINGSET :
532                                     bSaveWorkingSet = bTemp;
533                                     bROSaveWorkingSet = pROStates[nProp];
534                                     break;
535                                 case SAVEVIEWINFO :
536                                     bSaveDocView = bTemp;
537                                     bROSaveDocView = pROStates[nProp];
538                                     break;
539                                 case FILESYSTEM :
540                                     bSaveRelFSys = bTemp;
541                                     bROSaveRelFSys = pROStates[nProp];
542                                     break;
543                                 case INTERNET :
544                                     bSaveRelINet = bTemp;
545                                     bROSaveRelINet = pROStates[nProp];
546                                     break;
547                                 case UNPACKED :
548                                     bSaveUnpacked = bTemp;
549                                     bROSaveUnpacked = pROStates[nProp];
550                                     break;
551 
552                                 case PRETTYPRINTING:
553                                     bDoPrettyPrinting = bTemp;
554                                     bRODoPrettyPrinting = pROStates[nProp];
555                                     break;
556 
557                                 case WARNALIENFORMAT:
558                                     bWarnAlienFormat = bTemp;
559                                     bROWarnAlienFormat = pROStates[nProp];
560                                     break;
561 
562                                 case LOADDOCPRINTER:
563                                     bLoadDocPrinter = bTemp;
564                                     bROLoadDocPrinter = pROStates[nProp];
565                                     break;
566 
567                                 case USESHA1INODF12:
568                                     bUseSHA1InODF12 = bTemp;
569                                     bROUseSHA1InODF12 = pROStates[nProp];
570                                     break;
571 
572                                 case USEBLOWFISHINODF12:
573                                     bUseBlowfishInODF12 = bTemp;
574                                     bROUseBlowfishInODF12 = pROStates[nProp];
575                                     break;
576 
577                                 default :
578                                     DBG_ERRORFILE( "invalid index to load a path" );
579                             }
580                         }
581                         else
582 						{
583                             DBG_ERROR( "Wrong Type!" );
584 						}
585                     }
586 				}
587 			}
588 		}
589 	}
590 
591     try
592     {
593     css::uno::Reference< css::uno::XInterface > xCFG = ::comphelper::ConfigurationHelper::openConfig(
594         ::utl::getProcessServiceFactory(),
595         ::rtl::OUString::createFromAscii("org.openoffice.Office.Recovery"),
596         ::comphelper::ConfigurationHelper::E_READONLY);
597 
598     ::comphelper::ConfigurationHelper::readRelativeKey(
599         xCFG,
600         ::rtl::OUString::createFromAscii("AutoSave"),
601         ::rtl::OUString::createFromAscii("Enabled")) >>= bAutoSave;
602 
603     ::comphelper::ConfigurationHelper::readRelativeKey(
604         xCFG,
605         ::rtl::OUString::createFromAscii("AutoSave"),
606         ::rtl::OUString::createFromAscii("TimeIntervall")) >>= nAutoSaveTime;
607     }
608     catch(const css::uno::Exception&)
609         { DBG_ERROR("Could not find needed informations for AutoSave feature."); }
610 }
611 
~SvtSaveOptions_Impl()612 SvtSaveOptions_Impl::~SvtSaveOptions_Impl()
613 {}
614 
Commit()615 void SvtSaveOptions_Impl::Commit()
616 {
617     Sequence< OUString > aOrgNames = GetPropertyNames();
618     OUString* pOrgNames = aOrgNames.getArray();
619     sal_Int32 nOrgCount = aOrgNames.getLength();
620 
621     Sequence< OUString > aNames( nOrgCount );
622     Sequence< Any > aValues( nOrgCount );
623     OUString* pNames = aNames.getArray();
624     Any* pValues = aValues.getArray();
625     sal_Int32 nRealCount = 0;
626 
627     for (sal_Int32 i=0; i<nOrgCount; ++i)
628 	{
629         switch (i)
630         {
631             case FORMAT:
632                 // not supported anymore
633                 break;
634             case TIMEINTERVALL :
635                 if (!bROAutoSaveTime)
636                 {
637                     pValues[nRealCount] <<= nAutoSaveTime;
638                     pNames[nRealCount] = pOrgNames[i];
639                     ++nRealCount;
640                 }
641                 break;
642             case USEUSERDATA :
643                 if (!bROUseUserData)
644                 {
645                     pValues[nRealCount] <<= bUseUserData;
646                     pNames[nRealCount] = pOrgNames[i];
647                     ++nRealCount;
648                 }
649                 break;
650             case CREATEBACKUP :
651                 if (!bROBackup)
652                 {
653                     pValues[nRealCount] <<= bBackup;
654                     pNames[nRealCount] = pOrgNames[i];
655                     ++nRealCount;
656                 }
657                 break;
658             case AUTOSAVE :
659                 if (!bROAutoSave)
660                 {
661                     pValues[nRealCount] <<= bAutoSave;
662                     pNames[nRealCount] = pOrgNames[i];
663                     ++nRealCount;
664                 }
665                 break;
666             case PROMPT :
667                 if (!bROAutoSavePrompt)
668                 {
669                     pValues[nRealCount] <<= bAutoSavePrompt;
670                     pNames[nRealCount] = pOrgNames[i];
671                     ++nRealCount;
672                 }
673                 break;
674             case EDITPROPERTY :
675                 if (!bRODocInfSave)
676                 {
677                     pValues[nRealCount] <<= bDocInfSave;
678                     pNames[nRealCount] = pOrgNames[i];
679                     ++nRealCount;
680                 }
681                 break;
682             case SAVEWORKINGSET :
683                 if (!bROSaveWorkingSet)
684                 {
685                     pValues[nRealCount] <<= bSaveWorkingSet;
686                     pNames[nRealCount] = pOrgNames[i];
687                     ++nRealCount;
688                 }
689                 break;
690             case SAVEVIEWINFO :
691                 if (!bROSaveDocView)
692                 {
693                     pValues[nRealCount] <<= bSaveDocView;
694                     pNames[nRealCount] = pOrgNames[i];
695                     ++nRealCount;
696                 }
697                 break;
698             case FILESYSTEM :
699                 if (!bROSaveRelFSys)
700                 {
701                     pValues[nRealCount] <<= bSaveRelFSys;
702                     pNames[nRealCount] = pOrgNames[i];
703                     ++nRealCount;
704                 }
705                 break;
706             case INTERNET :
707                 if (!bROSaveRelINet)
708                 {
709                     pValues[nRealCount] <<= bSaveRelINet;
710                     pNames[nRealCount] = pOrgNames[i];
711                     ++nRealCount;
712                 }
713                 break;
714             case UNPACKED :
715                 if (!bROSaveUnpacked)
716                 {
717                     pValues[nRealCount] <<= bSaveUnpacked;
718                     pNames[nRealCount] = pOrgNames[i];
719                     ++nRealCount;
720                 }
721                 break;
722             case PRETTYPRINTING:
723                 if (!bRODoPrettyPrinting)
724                 {
725                     pValues[nRealCount] <<= bDoPrettyPrinting;
726                     pNames[nRealCount] = pOrgNames[i];
727                     ++nRealCount;
728                 }
729                 break;
730             case WARNALIENFORMAT:
731                 if (!bROWarnAlienFormat)
732                 {
733                     pValues[nRealCount] <<= bWarnAlienFormat;
734                     pNames[nRealCount] = pOrgNames[i];
735                     ++nRealCount;
736                 }
737                 break;
738             case LOADDOCPRINTER:
739                 if (!bROLoadDocPrinter)
740                 {
741                     pValues[nRealCount] <<= bLoadDocPrinter;
742                     pNames[nRealCount] = pOrgNames[i];
743                     ++nRealCount;
744                 }
745                 break;
746             case ODFDEFAULTVERSION:
747                 if (!bROODFDefaultVersion)
748                 {
749                     pValues[nRealCount] <<= (eODFDefaultVersion == SvtSaveOptions::ODFVER_LATEST) ? sal_Int16( 3 ) : sal_Int16( eODFDefaultVersion );
750                     pNames[nRealCount] = pOrgNames[i];
751                     ++nRealCount;
752                 }
753                 break;
754             case USESHA1INODF12:
755                 if (!bROUseSHA1InODF12)
756                 {
757                     pValues[nRealCount] <<= bUseSHA1InODF12;
758                     pNames[nRealCount] = pOrgNames[i];
759                     ++nRealCount;
760                 }
761                 break;
762             case USEBLOWFISHINODF12:
763                 if (!bROUseBlowfishInODF12)
764                 {
765                     pValues[nRealCount] <<= bUseBlowfishInODF12;
766                     pNames[nRealCount] = pOrgNames[i];
767                     ++nRealCount;
768                 }
769                 break;
770 
771             default:
772                 DBG_ERRORFILE( "invalid index to save a path" );
773         }
774 	}
775 
776     aNames.realloc(nRealCount);
777     aValues.realloc(nRealCount);
778 	PutProperties( aNames, aValues );
779 
780     css::uno::Reference< css::uno::XInterface > xCFG = ::comphelper::ConfigurationHelper::openConfig(
781         ::utl::getProcessServiceFactory(),
782         ::rtl::OUString::createFromAscii("org.openoffice.Office.Recovery"),
783         ::comphelper::ConfigurationHelper::E_STANDARD);
784 
785     ::comphelper::ConfigurationHelper::writeRelativeKey(
786         xCFG,
787         ::rtl::OUString::createFromAscii("AutoSave"),
788         ::rtl::OUString::createFromAscii("TimeIntervall"),
789         css::uno::makeAny(nAutoSaveTime));
790 
791     ::comphelper::ConfigurationHelper::writeRelativeKey(
792         xCFG,
793         ::rtl::OUString::createFromAscii("AutoSave"),
794         ::rtl::OUString::createFromAscii("Enabled"),
795         css::uno::makeAny(bAutoSave));
796 
797     ::comphelper::ConfigurationHelper::flush(xCFG);
798 }
799 
800 // -----------------------------------------------------------------------
801 
Notify(const Sequence<rtl::OUString> &)802 void SvtSaveOptions_Impl::Notify( const Sequence<rtl::OUString>& )
803 {
804 }
805 
806 
807 class SvtLoadOptions_Impl : public utl::ConfigItem
808 {
809 
810     sal_Bool                            bLoadUserDefinedSettings;
811 
812 public:
813                             SvtLoadOptions_Impl();
814                             ~SvtLoadOptions_Impl();
815 
816     virtual void            Notify( const com::sun::star::uno::Sequence< rtl::OUString >& aPropertyNames );
817     virtual void            Commit();
818 
SetLoadUserSettings(sal_Bool b)819     void                    SetLoadUserSettings(sal_Bool b){bLoadUserDefinedSettings = b; SetModified();}
IsLoadUserSettings() const820     sal_Bool                IsLoadUserSettings() const {return bLoadUserDefinedSettings;}
821 };
822 // -----------------------------------------------------------------------
823 const sal_Char cUserDefinedSettings[] = "UserDefinedSettings";
824 
SvtLoadOptions_Impl()825 SvtLoadOptions_Impl::SvtLoadOptions_Impl()
826     : ConfigItem( OUString::createFromAscii("Office.Common/Load") )
827     , bLoadUserDefinedSettings( sal_False )
828 {
829     Sequence< OUString > aNames(1);
830     aNames[0] = OUString::createFromAscii(cUserDefinedSettings);
831     Sequence< Any > aValues = GetProperties( aNames );
832 	EnableNotification( aNames );
833 	const Any* pValues = aValues.getConstArray();
834 	DBG_ASSERT( aValues.getLength() == aNames.getLength(), "GetProperties failed" );
835     if (pValues[0].getValueTypeClass() == ::com::sun::star::uno::TypeClass_BOOLEAN)
836          bLoadUserDefinedSettings = *(sal_Bool *)pValues[0].getValue();
837 }
838 // -----------------------------------------------------------------------
~SvtLoadOptions_Impl()839 SvtLoadOptions_Impl::~SvtLoadOptions_Impl()
840 {
841 }
842 // -----------------------------------------------------------------------
Commit()843 void SvtLoadOptions_Impl::Commit()
844 {
845     Sequence< OUString > aNames(1);
846     aNames[0] = OUString::createFromAscii(cUserDefinedSettings);
847     Sequence< Any > aValues( 1 );
848     aValues[0].setValue(&bLoadUserDefinedSettings, ::getBooleanCppuType());
849     PutProperties( aNames, aValues );
850 }
851 // -----------------------------------------------------------------------
Notify(const Sequence<rtl::OUString> &)852 void SvtLoadOptions_Impl::Notify( const Sequence<rtl::OUString>& )
853 {
854 	DBG_ERRORFILE( "properties have been changed" );
855 }
856 // -----------------------------------------------------------------------
857 
858 namespace
859 {
860     class LocalSingleton : public rtl::Static< osl::Mutex, LocalSingleton >
861     {
862     };
863 }
864 
865 // -----------------------------------------------------------------------
SvtSaveOptions()866 SvtSaveOptions::SvtSaveOptions()
867 {
868     // Global access, must be guarded (multithreading)
869     ::osl::MutexGuard aGuard( LocalSingleton::get() );
870     if ( !pOptions )
871     {
872         RTL_LOGFILE_CONTEXT(aLog, "unotools ( ??? ) ::SvtSaveOptions_Impl::ctor()");
873         pOptions = new SvtLoadSaveOptions_Impl;
874         pOptions->pSaveOpt = new SvtSaveOptions_Impl;
875         pOptions->pLoadOpt = new SvtLoadOptions_Impl;
876 
877         ItemHolder1::holdConfigItem(E_SAVEOPTIONS);
878    }
879    ++nRefCount;
880     pImp = pOptions;
881 }
882 
883 // -----------------------------------------------------------------------
884 
~SvtSaveOptions()885 SvtSaveOptions::~SvtSaveOptions()
886 {
887     // Global access, must be guarded (multithreading)
888     ::osl::MutexGuard aGuard( LocalSingleton::get() );
889     if ( !--nRefCount )
890 	{
891         if ( pOptions->pSaveOpt->IsModified() )
892             pOptions->pSaveOpt->Commit();
893         if ( pOptions->pLoadOpt->IsModified() )
894             pOptions->pLoadOpt->Commit();
895 
896         DELETEZ( pOptions->pLoadOpt );
897         DELETEZ( pOptions->pSaveOpt );
898         DELETEZ( pOptions );
899 	}
900 }
901 
SetAutoSaveTime(sal_Int32 n)902 void SvtSaveOptions::SetAutoSaveTime( sal_Int32 n )
903 {
904     pImp->pSaveOpt->SetAutoSaveTime( n );
905 }
906 
GetAutoSaveTime() const907 sal_Int32 SvtSaveOptions::GetAutoSaveTime() const
908 {
909     return pImp->pSaveOpt->GetAutoSaveTime();
910 }
911 
SetUseUserData(sal_Bool b)912 void SvtSaveOptions::SetUseUserData( sal_Bool b )
913 {
914     pImp->pSaveOpt->SetUseUserData( b );
915 }
916 
IsUseUserData() const917 sal_Bool SvtSaveOptions::IsUseUserData() const
918 {
919     return pImp->pSaveOpt->IsUseUserData();
920 }
921 
SetBackup(sal_Bool b)922 void SvtSaveOptions::SetBackup( sal_Bool b )
923 {
924     pImp->pSaveOpt->SetBackup( b );
925 }
926 
IsBackup() const927 sal_Bool SvtSaveOptions::IsBackup() const
928 {
929     return pImp->pSaveOpt->IsBackup();
930 }
931 
SetAutoSave(sal_Bool b)932 void SvtSaveOptions::SetAutoSave( sal_Bool b )
933 {
934     pImp->pSaveOpt->SetAutoSave( b );
935 }
936 
IsAutoSave() const937 sal_Bool SvtSaveOptions::IsAutoSave() const
938 {
939     return pImp->pSaveOpt->IsAutoSave();
940 }
941 
SetAutoSavePrompt(sal_Bool b)942 void SvtSaveOptions::SetAutoSavePrompt( sal_Bool b )
943 {
944     pImp->pSaveOpt->SetAutoSavePrompt( b );
945 }
946 
IsAutoSavePrompt() const947 sal_Bool SvtSaveOptions::IsAutoSavePrompt() const
948 {
949     return pImp->pSaveOpt->IsAutoSavePrompt();
950 }
951 
SetDocInfoSave(sal_Bool b)952 void SvtSaveOptions::SetDocInfoSave(sal_Bool b)
953 {
954     pImp->pSaveOpt->SetDocInfoSave( b );
955 }
956 
IsDocInfoSave() const957 sal_Bool SvtSaveOptions::IsDocInfoSave() const
958 {
959     return pImp->pSaveOpt->IsDocInfoSave();
960 }
961 
SetSaveWorkingSet(sal_Bool b)962 void SvtSaveOptions::SetSaveWorkingSet( sal_Bool b )
963 {
964     pImp->pSaveOpt->SetSaveWorkingSet( b );
965 }
966 
IsSaveWorkingSet() const967 sal_Bool SvtSaveOptions::IsSaveWorkingSet() const
968 {
969     return pImp->pSaveOpt->IsSaveWorkingSet();
970 }
971 
SetSaveDocView(sal_Bool b)972 void SvtSaveOptions::SetSaveDocView( sal_Bool b )
973 {
974     pImp->pSaveOpt->SetSaveDocView( b );
975 }
976 
IsSaveDocView() const977 sal_Bool SvtSaveOptions::IsSaveDocView() const
978 {
979     return pImp->pSaveOpt->IsSaveDocView();
980 }
981 
SetSaveRelINet(sal_Bool b)982 void SvtSaveOptions::SetSaveRelINet( sal_Bool b )
983 {
984     pImp->pSaveOpt->SetSaveRelINet( b );
985 }
986 
IsSaveRelINet() const987 sal_Bool SvtSaveOptions::IsSaveRelINet() const
988 {
989     return pImp->pSaveOpt->IsSaveRelINet();
990 }
991 
SetSaveRelFSys(sal_Bool b)992 void SvtSaveOptions::SetSaveRelFSys( sal_Bool b )
993 {
994     pImp->pSaveOpt->SetSaveRelFSys( b );
995 }
996 
IsSaveRelFSys() const997 sal_Bool SvtSaveOptions::IsSaveRelFSys() const
998 {
999     return pImp->pSaveOpt->IsSaveRelFSys();
1000 }
1001 
SetSaveUnpacked(sal_Bool b)1002 void SvtSaveOptions::SetSaveUnpacked( sal_Bool b )
1003 {
1004     pImp->pSaveOpt->SetSaveUnpacked( b );
1005 }
1006 
IsSaveUnpacked() const1007 sal_Bool SvtSaveOptions::IsSaveUnpacked() const
1008 {
1009     return pImp->pSaveOpt->IsSaveUnpacked();
1010 }
1011 
SetLoadUserSettings(sal_Bool b)1012 void SvtSaveOptions::SetLoadUserSettings(sal_Bool b)
1013 {
1014     pImp->pLoadOpt->SetLoadUserSettings(b);
1015 }
1016 
IsLoadUserSettings() const1017 sal_Bool   SvtSaveOptions::IsLoadUserSettings() const
1018 {
1019     return pImp->pLoadOpt->IsLoadUserSettings();
1020 }
1021 
SetPrettyPrinting(sal_Bool _bEnable)1022 void SvtSaveOptions::SetPrettyPrinting( sal_Bool _bEnable )
1023 {
1024     pImp->pSaveOpt->EnablePrettyPrinting( _bEnable );
1025 }
1026 
IsPrettyPrinting() const1027 sal_Bool SvtSaveOptions::IsPrettyPrinting() const
1028 {
1029     return pImp->pSaveOpt->IsPrettyPrintingEnabled();
1030 }
1031 
SetWarnAlienFormat(sal_Bool _bEnable)1032 void SvtSaveOptions::SetWarnAlienFormat( sal_Bool _bEnable )
1033 {
1034     pImp->pSaveOpt->SetWarnAlienFormat( _bEnable );
1035 }
1036 
IsWarnAlienFormat() const1037 sal_Bool SvtSaveOptions::IsWarnAlienFormat() const
1038 {
1039     return pImp->pSaveOpt->IsWarnAlienFormat();
1040 }
1041 
SetLoadDocumentPrinter(sal_Bool _bEnable)1042 void SvtSaveOptions::SetLoadDocumentPrinter( sal_Bool _bEnable )
1043 {
1044     pImp->pSaveOpt->SetLoadDocPrinter( _bEnable );
1045 }
1046 
IsLoadDocumentPrinter() const1047 sal_Bool SvtSaveOptions::IsLoadDocumentPrinter() const
1048 {
1049     return pImp->pSaveOpt->IsLoadDocPrinter();
1050 }
1051 
SetODFDefaultVersion(SvtSaveOptions::ODFDefaultVersion eVersion)1052 void SvtSaveOptions::SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion eVersion )
1053 {
1054     pImp->pSaveOpt->SetODFDefaultVersion( eVersion );
1055 }
1056 
GetODFDefaultVersion() const1057 SvtSaveOptions::ODFDefaultVersion SvtSaveOptions::GetODFDefaultVersion() const
1058 {
1059     return pImp->pSaveOpt->GetODFDefaultVersion();
1060 }
1061 
SetUseSHA1InODF12(sal_Bool bUse)1062 void SvtSaveOptions::SetUseSHA1InODF12( sal_Bool bUse )
1063 {
1064     pImp->pSaveOpt->SetUseSHA1InODF12( bUse );
1065 }
1066 
IsUseSHA1InODF12() const1067 sal_Bool SvtSaveOptions::IsUseSHA1InODF12() const
1068 {
1069     return pImp->pSaveOpt->IsUseSHA1InODF12();
1070 }
1071 
SetUseBlowfishInODF12(sal_Bool bUse)1072 void SvtSaveOptions::SetUseBlowfishInODF12( sal_Bool bUse )
1073 {
1074     pImp->pSaveOpt->SetUseBlowfishInODF12( bUse );
1075 }
1076 
IsUseBlowfishInODF12() const1077 sal_Bool SvtSaveOptions::IsUseBlowfishInODF12() const
1078 {
1079     return pImp->pSaveOpt->IsUseBlowfishInODF12();
1080 }
1081 
IsReadOnly(SvtSaveOptions::EOption eOption) const1082 sal_Bool SvtSaveOptions::IsReadOnly( SvtSaveOptions::EOption eOption ) const
1083 {
1084     return pImp->pSaveOpt->IsReadOnly(eOption);
1085 }
1086 
1087