Update ooo320-m1
[ooovba.git] / svtools / source / config / saveopt.cxx
blob45c24530e467b9087134b36cfe82805a2eec2d79
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: saveopt.cxx,v $
10 * $Revision: 1.36 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #ifndef GCC
35 #endif
37 #include <svtools/saveopt.hxx>
38 #include "rtl/instance.hxx"
39 #include <unotools/configmgr.hxx>
40 #include <unotools/configitem.hxx>
41 #include <tools/debug.hxx>
42 #include <com/sun/star/uno/Any.hxx>
43 #include <com/sun/star/uno/Sequence.hxx>
45 #include <osl/mutex.hxx>
46 #include <comphelper/configurationhelper.hxx>
47 #include <unotools/processfactory.hxx>
48 #include <rtl/logfile.hxx>
49 #include "itemholder1.hxx"
51 using namespace utl;
52 using namespace rtl;
53 using namespace com::sun::star::uno;
54 namespace css = ::com::sun::star;
56 class SvtSaveOptions_Impl;
57 class SvtLoadOptions_Impl;
59 #define CFG_READONLY_DEFAULT sal_False
61 struct SvtLoadSaveOptions_Impl
63 SvtSaveOptions_Impl* pSaveOpt;
64 SvtLoadOptions_Impl* pLoadOpt;
67 static SvtLoadSaveOptions_Impl* pOptions = NULL;
68 static sal_Int32 nRefCount = 0;
70 class SvtSaveOptions_Impl : public utl::ConfigItem
72 sal_Int32 nAutoSaveTime;
73 sal_Bool bUseUserData,
74 bBackup,
75 bAutoSave,
76 bAutoSavePrompt,
77 bDocInfSave,
78 bSaveWorkingSet,
79 bSaveDocWins,
80 bSaveDocView,
81 bSaveRelINet,
82 bSaveRelFSys,
83 bSaveUnpacked,
84 bDoPrettyPrinting,
85 bWarnAlienFormat,
86 bLoadDocPrinter;
88 sal_Bool bROAutoSaveTime,
89 bROUseUserData,
90 bROBackup,
91 bROAutoSave,
92 bROAutoSavePrompt,
93 bRODocInfSave,
94 bROSaveWorkingSet,
95 bROSaveDocWins,
96 bROSaveDocView,
97 bROSaveRelINet,
98 bROSaveRelFSys,
99 bROSaveUnpacked,
100 bROWarnAlienFormat,
101 bRODoPrettyPrinting,
102 bROLoadDocPrinter,
103 bROODFDefaultVersion;
105 SvtSaveOptions::ODFDefaultVersion eODFDefaultVersion;
107 public:
108 SvtSaveOptions_Impl();
109 ~SvtSaveOptions_Impl();
111 virtual void Notify( const com::sun::star::uno::Sequence< rtl::OUString >& aPropertyNames );
112 virtual void Commit();
114 sal_Int32 GetAutoSaveTime() const { return nAutoSaveTime; }
115 BOOL IsUseUserData() const { return bUseUserData; }
116 BOOL IsBackup() const { return bBackup; }
117 BOOL IsAutoSave() const { return bAutoSave; }
118 BOOL IsAutoSavePrompt() const { return bAutoSavePrompt; }
119 BOOL IsDocInfoSave() const { return bDocInfSave; }
120 BOOL IsSaveWorkingSet() const { return bSaveWorkingSet; }
121 BOOL IsSaveDocWins() const { return bSaveDocWins; }
122 BOOL IsSaveDocView() const { return bSaveDocView; }
123 BOOL IsSaveRelINet() const { return bSaveRelINet; }
124 BOOL IsSaveRelFSys() const { return bSaveRelFSys; }
125 BOOL IsSaveUnpacked() const { return bSaveUnpacked; }
126 sal_Bool IsPrettyPrintingEnabled( ) const { return bDoPrettyPrinting; }
127 sal_Bool IsWarnAlienFormat() const { return bWarnAlienFormat; }
128 sal_Bool IsLoadDocPrinter() const { return bLoadDocPrinter; }
129 SvtSaveOptions::ODFDefaultVersion
130 GetODFDefaultVersion() const { return eODFDefaultVersion; }
132 void SetAutoSaveTime( sal_Int32 n );
133 void SetUseUserData( BOOL b );
134 void SetBackup( BOOL b );
135 void SetAutoSave( BOOL b );
136 void SetAutoSavePrompt( BOOL b );
137 void SetDocInfoSave( BOOL b );
138 void SetSaveWorkingSet( BOOL b );
139 void SetSaveDocWins( BOOL b );
140 void SetSaveDocView( BOOL b );
141 void SetSaveRelINet( BOOL b );
142 void SetSaveRelFSys( BOOL b );
143 void SetSaveUnpacked( BOOL b );
144 void EnablePrettyPrinting( sal_Bool _bDoPP );
145 void SetWarnAlienFormat( sal_Bool _bDoPP );
146 void SetLoadDocPrinter( sal_Bool bNew );
147 void SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion eNew );
149 sal_Bool IsReadOnly( SvtSaveOptions::EOption eOption ) const;
152 void SvtSaveOptions_Impl::SetAutoSaveTime( sal_Int32 n )
154 if (!bROAutoSaveTime && nAutoSaveTime!=n)
156 nAutoSaveTime = n;
157 SetModified();
158 Commit();
162 void SvtSaveOptions_Impl::SetUseUserData( BOOL b )
164 if (!bROUseUserData && bUseUserData!=b)
166 bUseUserData = b;
167 SetModified();
171 void SvtSaveOptions_Impl::SetBackup( BOOL b )
173 if (!bROBackup && bBackup!=b)
175 bBackup = b;
176 SetModified();
180 void SvtSaveOptions_Impl::SetAutoSave( BOOL b )
182 if (!bROAutoSave && bAutoSave!=b)
184 bAutoSave = b;
185 SetModified();
186 Commit();
190 void SvtSaveOptions_Impl::SetAutoSavePrompt( BOOL b )
192 if (!bROAutoSavePrompt && bAutoSavePrompt!=b)
194 bAutoSavePrompt = b;
195 SetModified();
199 void SvtSaveOptions_Impl::SetDocInfoSave(BOOL b)
201 if (!bRODocInfSave && bDocInfSave!=b)
203 bDocInfSave = b;
204 SetModified();
208 void SvtSaveOptions_Impl::SetSaveWorkingSet( BOOL b )
210 if (!bROSaveWorkingSet && bSaveWorkingSet!=b)
212 bSaveWorkingSet = b;
213 SetModified();
217 void SvtSaveOptions_Impl::SetSaveDocWins( BOOL b )
219 if (!bROSaveDocWins && bSaveDocWins!=b)
221 bSaveDocWins = b;
222 SetModified();
226 void SvtSaveOptions_Impl::SetSaveDocView( BOOL b )
228 if (!bROSaveDocView && bSaveDocView!=b)
230 bSaveDocView = b;
231 SetModified();
235 void SvtSaveOptions_Impl::SetSaveRelINet( BOOL b )
237 if (!bROSaveRelINet && bSaveRelINet!=b)
239 bSaveRelINet = b;
240 SetModified();
244 void SvtSaveOptions_Impl::SetSaveRelFSys( BOOL b )
246 if (!bROSaveRelFSys && bSaveRelFSys!=b)
248 bSaveRelFSys = b;
249 SetModified();
253 void SvtSaveOptions_Impl::SetSaveUnpacked( BOOL b )
255 if (!bROSaveUnpacked && bSaveUnpacked!=b)
257 bSaveUnpacked = b;
258 SetModified();
262 void SvtSaveOptions_Impl::EnablePrettyPrinting( sal_Bool _bDoPP )
264 if (!bRODoPrettyPrinting && bDoPrettyPrinting!=_bDoPP)
266 bDoPrettyPrinting = _bDoPP;
267 SetModified();
271 void SvtSaveOptions_Impl::SetWarnAlienFormat( sal_Bool _bDoPP )
273 if (!bROWarnAlienFormat && bWarnAlienFormat!=_bDoPP)
275 bWarnAlienFormat = _bDoPP;
276 SetModified();
280 void SvtSaveOptions_Impl::SetLoadDocPrinter( sal_Bool bNew )
282 if ( !bROLoadDocPrinter && bLoadDocPrinter != bNew )
284 bLoadDocPrinter = bNew;
285 SetModified();
289 void SvtSaveOptions_Impl::SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion eNew )
291 if ( !bROODFDefaultVersion && eODFDefaultVersion != eNew )
293 eODFDefaultVersion = eNew;
294 SetModified();
298 sal_Bool SvtSaveOptions_Impl::IsReadOnly( SvtSaveOptions::EOption eOption ) const
300 sal_Bool bReadOnly = CFG_READONLY_DEFAULT;
301 switch(eOption)
303 case SvtSaveOptions::E_AUTOSAVETIME :
304 bReadOnly = bROAutoSaveTime;
305 break;
306 case SvtSaveOptions::E_USEUSERDATA :
307 bReadOnly = bROUseUserData;
308 break;
309 case SvtSaveOptions::E_BACKUP :
310 bReadOnly = bROBackup;
311 break;
312 case SvtSaveOptions::E_AUTOSAVE :
313 bReadOnly = bROAutoSave;
314 break;
315 case SvtSaveOptions::E_AUTOSAVEPROMPT :
316 bReadOnly = bROAutoSavePrompt;
317 break;
318 case SvtSaveOptions::E_DOCINFSAVE :
319 bReadOnly = bRODocInfSave;
320 break;
321 case SvtSaveOptions::E_SAVEWORKINGSET :
322 bReadOnly = bROSaveWorkingSet;
323 break;
324 case SvtSaveOptions::E_SAVEDOCWINS :
325 bReadOnly = bROSaveDocWins;
326 break;
327 case SvtSaveOptions::E_SAVEDOCVIEW :
328 bReadOnly = bROSaveDocView;
329 break;
330 case SvtSaveOptions::E_SAVERELINET :
331 bReadOnly = bROSaveRelINet;
332 break;
333 case SvtSaveOptions::E_SAVERELFSYS :
334 bReadOnly = bROSaveRelFSys;
335 break;
336 case SvtSaveOptions::E_SAVEUNPACKED :
337 bReadOnly = bROSaveUnpacked;
338 break;
339 case SvtSaveOptions::E_DOPRETTYPRINTING :
340 bReadOnly = bRODoPrettyPrinting;
341 break;
342 case SvtSaveOptions::E_WARNALIENFORMAT :
343 bReadOnly = bROWarnAlienFormat;
344 break;
345 case SvtSaveOptions::E_LOADDOCPRINTER :
346 bReadOnly = bROLoadDocPrinter;
347 break;
348 case SvtSaveOptions::E_ODFDEFAULTVERSION :
349 bReadOnly = bROLoadDocPrinter;
350 break;
352 return bReadOnly;
355 #define FORMAT 0
356 #define TIMEINTERVALL 1
357 #define USEUSERDATA 2
358 #define CREATEBACKUP 3
359 #define AUTOSAVE 4
360 #define PROMPT 5
361 #define EDITPROPERTY 6
362 #define SAVEDOCWINS 7
363 #define SAVEVIEWINFO 8
364 #define UNPACKED 9
365 #define PRETTYPRINTING 10
366 #define WARNALIENFORMAT 11
367 #define LOADDOCPRINTER 12
368 #define FILESYSTEM 13
369 #define INTERNET 14
370 #define SAVEWORKINGSET 15
371 #define ODFDEFAULTVERSION 16
373 Sequence< OUString > GetPropertyNames()
375 static const char* aPropNames[] =
377 "Graphic/Format",
378 "Document/AutoSaveTimeIntervall",
379 "Document/UseUserData",
380 "Document/CreateBackup",
381 "Document/AutoSave",
382 "Document/AutoSavePrompt",
383 "Document/EditProperty",
384 "Document/DocumentWindows",
385 "Document/ViewInfo",
386 "Document/Unpacked",
387 "Document/PrettyPrinting",
388 "Document/WarnAlienFormat",
389 "Document/LoadPrinter",
390 "URL/FileSystem",
391 "URL/Internet",
392 "WorkingSet",
393 "ODF/DefaultVersion"
396 const int nCount = sizeof( aPropNames ) / sizeof( const char* );
397 Sequence< OUString > aNames( nCount );
398 OUString* pNames = aNames.getArray();
399 for ( int i = 0; i < nCount; i++ )
400 pNames[i] = OUString::createFromAscii( aPropNames[i] );
402 return aNames;
405 // -----------------------------------------------------------------------
407 SvtSaveOptions_Impl::SvtSaveOptions_Impl()
408 : ConfigItem( OUString::createFromAscii("Office.Common/Save") )
409 , nAutoSaveTime( 0 )
410 , bUseUserData( sal_False )
411 , bBackup( sal_False )
412 , bAutoSave( sal_False )
413 , bAutoSavePrompt( sal_False )
414 , bDocInfSave( sal_False )
415 , bSaveWorkingSet( sal_False )
416 , bSaveDocWins( sal_False )
417 , bSaveDocView( sal_False )
418 , bSaveRelINet( sal_False )
419 , bSaveRelFSys( sal_False )
420 , bSaveUnpacked( sal_False )
421 , bDoPrettyPrinting( sal_False )
422 , bWarnAlienFormat( sal_True )
423 , bLoadDocPrinter( sal_True )
424 , bROAutoSaveTime( CFG_READONLY_DEFAULT )
425 , bROUseUserData( CFG_READONLY_DEFAULT )
426 , bROBackup( CFG_READONLY_DEFAULT )
427 , bROAutoSave( CFG_READONLY_DEFAULT )
428 , bROAutoSavePrompt( CFG_READONLY_DEFAULT )
429 , bRODocInfSave( CFG_READONLY_DEFAULT )
430 , bROSaveWorkingSet( CFG_READONLY_DEFAULT )
431 , bROSaveDocWins( CFG_READONLY_DEFAULT )
432 , bROSaveDocView( CFG_READONLY_DEFAULT )
433 , bROSaveRelINet( CFG_READONLY_DEFAULT )
434 , bROSaveRelFSys( CFG_READONLY_DEFAULT )
435 , bROSaveUnpacked( CFG_READONLY_DEFAULT )
436 , bROWarnAlienFormat( CFG_READONLY_DEFAULT )
437 , bRODoPrettyPrinting( CFG_READONLY_DEFAULT )
438 , bROLoadDocPrinter( CFG_READONLY_DEFAULT )
439 , bROODFDefaultVersion( CFG_READONLY_DEFAULT )
440 , eODFDefaultVersion( SvtSaveOptions::ODFVER_LATEST )
442 Sequence< OUString > aNames = GetPropertyNames();
443 Sequence< Any > aValues = GetProperties( aNames );
444 Sequence< sal_Bool > aROStates = GetReadOnlyStates( aNames );
445 EnableNotification( aNames );
446 const Any* pValues = aValues.getConstArray();
447 const sal_Bool* pROStates = aROStates.getConstArray();
448 DBG_ASSERT( aValues.getLength() == aNames.getLength(), "GetProperties failed" );
449 DBG_ASSERT( aROStates.getLength() == aNames.getLength(), "GetReadOnlyStates failed" );
450 if ( aValues.getLength() == aNames.getLength() && aROStates.getLength() == aNames.getLength() )
452 for ( int nProp = 0; nProp < aNames.getLength(); nProp++ )
454 DBG_ASSERT( pValues[nProp].hasValue(), "property value missing" );
455 if ( pValues[nProp].hasValue() )
457 sal_Int32 nTemp = 0;
458 switch ( nProp )
460 case FORMAT:
461 // not supported anymore
462 break;
464 case TIMEINTERVALL :
465 if ( pValues[nProp] >>= nTemp )
466 nAutoSaveTime = nTemp;
467 else {
468 DBG_ERROR( "Wrong Type!" );
470 bROAutoSaveTime = pROStates[nProp];
471 break;
473 case ODFDEFAULTVERSION :
475 sal_Int16 nTmp = 0;
476 if ( pValues[nProp] >>= nTmp )
478 if( nTmp == 3 )
479 eODFDefaultVersion = SvtSaveOptions::ODFVER_LATEST;
480 else
481 eODFDefaultVersion = SvtSaveOptions::ODFDefaultVersion( nTmp );
483 else {
484 DBG_ERRORFILE( "SvtSaveOptions_Impl::SvtSaveOptions_Impl(): Wrong Type!" );
486 bROODFDefaultVersion = pROStates[nProp];
487 break;
490 default:
492 sal_Bool bTemp = sal_Bool();
493 if ( pValues[nProp] >>= bTemp )
495 switch ( nProp )
497 case USEUSERDATA :
498 bUseUserData = bTemp;
499 bROUseUserData = pROStates[nProp];
500 break;
501 case CREATEBACKUP :
502 bBackup = bTemp;
503 bROBackup = pROStates[nProp];
504 break;
505 case AUTOSAVE :
506 bAutoSave = bTemp;
507 bROAutoSave = pROStates[nProp];
508 break;
509 case PROMPT :
510 bAutoSavePrompt = bTemp;
511 bROAutoSavePrompt = pROStates[nProp];
512 break;
513 case EDITPROPERTY :
514 bDocInfSave = bTemp;
515 bRODocInfSave = pROStates[nProp];
516 break;
517 case SAVEWORKINGSET :
518 bSaveWorkingSet = bTemp;
519 bROSaveWorkingSet = pROStates[nProp];
520 break;
521 case SAVEDOCWINS :
522 bSaveDocWins = bTemp;
523 bROSaveDocWins = pROStates[nProp];
524 break;
525 case SAVEVIEWINFO :
526 bSaveDocView = bTemp;
527 bROSaveDocView = pROStates[nProp];
528 break;
529 case FILESYSTEM :
530 bSaveRelFSys = bTemp;
531 bROSaveRelFSys = pROStates[nProp];
532 break;
533 case INTERNET :
534 bSaveRelINet = bTemp;
535 bROSaveRelINet = pROStates[nProp];
536 break;
537 case UNPACKED :
538 bSaveUnpacked = bTemp;
539 bROSaveUnpacked = pROStates[nProp];
540 break;
542 case PRETTYPRINTING:
543 bDoPrettyPrinting = bTemp;
544 bRODoPrettyPrinting = pROStates[nProp];
545 break;
547 case WARNALIENFORMAT:
548 bWarnAlienFormat = bTemp;
549 bROWarnAlienFormat = pROStates[nProp];
550 break;
552 case LOADDOCPRINTER:
553 bLoadDocPrinter = bTemp;
554 bROLoadDocPrinter = pROStates[nProp];
555 break;
557 default :
558 DBG_ERRORFILE( "invalid index to load a path" );
561 else
563 DBG_ERROR( "Wrong Type!" );
573 css::uno::Reference< css::uno::XInterface > xCFG = ::comphelper::ConfigurationHelper::openConfig(
574 ::utl::getProcessServiceFactory(),
575 ::rtl::OUString::createFromAscii("org.openoffice.Office.Recovery"),
576 ::comphelper::ConfigurationHelper::E_READONLY);
578 ::comphelper::ConfigurationHelper::readRelativeKey(
579 xCFG,
580 ::rtl::OUString::createFromAscii("AutoSave"),
581 ::rtl::OUString::createFromAscii("Enabled")) >>= bAutoSave;
583 ::comphelper::ConfigurationHelper::readRelativeKey(
584 xCFG,
585 ::rtl::OUString::createFromAscii("AutoSave"),
586 ::rtl::OUString::createFromAscii("TimeIntervall")) >>= nAutoSaveTime;
588 catch(const css::uno::Exception&)
589 { DBG_ERROR("Could not find needed informations for AutoSave feature."); }
592 SvtSaveOptions_Impl::~SvtSaveOptions_Impl()
595 void SvtSaveOptions_Impl::Commit()
597 Sequence< OUString > aOrgNames = GetPropertyNames();
598 OUString* pOrgNames = aOrgNames.getArray();
599 sal_Int32 nOrgCount = aOrgNames.getLength();
601 Sequence< OUString > aNames( nOrgCount );
602 Sequence< Any > aValues( nOrgCount );
603 OUString* pNames = aNames.getArray();
604 Any* pValues = aValues.getArray();
605 sal_Int32 nRealCount = 0;
607 for (sal_Int32 i=0; i<nOrgCount; ++i)
609 switch (i)
611 case FORMAT:
612 // not supported anymore
613 break;
614 case TIMEINTERVALL :
615 if (!bROAutoSaveTime)
617 pValues[nRealCount] <<= nAutoSaveTime;
618 pNames[nRealCount] = pOrgNames[i];
619 ++nRealCount;
621 break;
622 case USEUSERDATA :
623 if (!bROUseUserData)
625 pValues[nRealCount] <<= bUseUserData;
626 pNames[nRealCount] = pOrgNames[i];
627 ++nRealCount;
629 break;
630 case CREATEBACKUP :
631 if (!bROBackup)
633 pValues[nRealCount] <<= bBackup;
634 pNames[nRealCount] = pOrgNames[i];
635 ++nRealCount;
637 break;
638 case AUTOSAVE :
639 if (!bROAutoSave)
641 pValues[nRealCount] <<= bAutoSave;
642 pNames[nRealCount] = pOrgNames[i];
643 ++nRealCount;
645 break;
646 case PROMPT :
647 if (!bROAutoSavePrompt)
649 pValues[nRealCount] <<= bAutoSavePrompt;
650 pNames[nRealCount] = pOrgNames[i];
651 ++nRealCount;
653 break;
654 case EDITPROPERTY :
655 if (!bRODocInfSave)
657 pValues[nRealCount] <<= bDocInfSave;
658 pNames[nRealCount] = pOrgNames[i];
659 ++nRealCount;
661 break;
662 case SAVEWORKINGSET :
663 if (!bROSaveWorkingSet)
665 pValues[nRealCount] <<= bSaveWorkingSet;
666 pNames[nRealCount] = pOrgNames[i];
667 ++nRealCount;
669 break;
670 case SAVEDOCWINS :
671 if (!bROSaveDocWins)
673 pValues[nRealCount] <<= bSaveDocWins;
674 pNames[nRealCount] = pOrgNames[i];
675 ++nRealCount;
677 break;
678 case SAVEVIEWINFO :
679 if (!bROSaveDocView)
681 pValues[nRealCount] <<= bSaveDocView;
682 pNames[nRealCount] = pOrgNames[i];
683 ++nRealCount;
685 break;
686 case FILESYSTEM :
687 if (!bROSaveRelFSys)
689 pValues[nRealCount] <<= bSaveRelFSys;
690 pNames[nRealCount] = pOrgNames[i];
691 ++nRealCount;
693 break;
694 case INTERNET :
695 if (!bROSaveRelINet)
697 pValues[nRealCount] <<= bSaveRelINet;
698 pNames[nRealCount] = pOrgNames[i];
699 ++nRealCount;
701 break;
702 case UNPACKED :
703 if (!bROSaveUnpacked)
705 pValues[nRealCount] <<= bSaveUnpacked;
706 pNames[nRealCount] = pOrgNames[i];
707 ++nRealCount;
709 break;
710 case PRETTYPRINTING:
711 if (!bRODoPrettyPrinting)
713 pValues[nRealCount] <<= bDoPrettyPrinting;
714 pNames[nRealCount] = pOrgNames[i];
715 ++nRealCount;
717 break;
718 case WARNALIENFORMAT:
719 if (!bROWarnAlienFormat)
721 pValues[nRealCount] <<= bWarnAlienFormat;
722 pNames[nRealCount] = pOrgNames[i];
723 ++nRealCount;
725 break;
726 case LOADDOCPRINTER:
727 if (!bROLoadDocPrinter)
729 pValues[nRealCount] <<= bLoadDocPrinter;
730 pNames[nRealCount] = pOrgNames[i];
731 ++nRealCount;
733 break;
734 case ODFDEFAULTVERSION:
735 if (!bROODFDefaultVersion)
737 pValues[nRealCount] <<= (eODFDefaultVersion == SvtSaveOptions::ODFVER_LATEST) ? sal_Int16( 3 ) : sal_Int16( eODFDefaultVersion );
738 pNames[nRealCount] = pOrgNames[i];
739 ++nRealCount;
741 break;
742 default:
743 DBG_ERRORFILE( "invalid index to save a path" );
747 aNames.realloc(nRealCount);
748 aValues.realloc(nRealCount);
749 PutProperties( aNames, aValues );
751 css::uno::Reference< css::uno::XInterface > xCFG = ::comphelper::ConfigurationHelper::openConfig(
752 ::utl::getProcessServiceFactory(),
753 ::rtl::OUString::createFromAscii("org.openoffice.Office.Recovery"),
754 ::comphelper::ConfigurationHelper::E_STANDARD);
756 ::comphelper::ConfigurationHelper::writeRelativeKey(
757 xCFG,
758 ::rtl::OUString::createFromAscii("AutoSave"),
759 ::rtl::OUString::createFromAscii("TimeIntervall"),
760 css::uno::makeAny(nAutoSaveTime));
762 ::comphelper::ConfigurationHelper::writeRelativeKey(
763 xCFG,
764 ::rtl::OUString::createFromAscii("AutoSave"),
765 ::rtl::OUString::createFromAscii("Enabled"),
766 css::uno::makeAny(bAutoSave));
768 ::comphelper::ConfigurationHelper::flush(xCFG);
771 // -----------------------------------------------------------------------
773 void SvtSaveOptions_Impl::Notify( const Sequence<rtl::OUString>& )
778 class SvtLoadOptions_Impl : public utl::ConfigItem
781 sal_Bool bLoadUserDefinedSettings;
783 public:
784 SvtLoadOptions_Impl();
785 ~SvtLoadOptions_Impl();
787 virtual void Notify( const com::sun::star::uno::Sequence< rtl::OUString >& aPropertyNames );
788 virtual void Commit();
790 void SetLoadUserSettings(sal_Bool b){bLoadUserDefinedSettings = b; SetModified();}
791 sal_Bool IsLoadUserSettings() const {return bLoadUserDefinedSettings;}
793 // -----------------------------------------------------------------------
794 const sal_Char cUserDefinedSettings[] = "UserDefinedSettings";
796 SvtLoadOptions_Impl::SvtLoadOptions_Impl()
797 : ConfigItem( OUString::createFromAscii("Office.Common/Load") )
798 , bLoadUserDefinedSettings( sal_False )
800 Sequence< OUString > aNames(1);
801 aNames[0] = OUString::createFromAscii(cUserDefinedSettings);
802 Sequence< Any > aValues = GetProperties( aNames );
803 EnableNotification( aNames );
804 const Any* pValues = aValues.getConstArray();
805 DBG_ASSERT( aValues.getLength() == aNames.getLength(), "GetProperties failed" );
806 if (pValues[0].getValueTypeClass() == ::com::sun::star::uno::TypeClass_BOOLEAN)
807 bLoadUserDefinedSettings = *(sal_Bool *)pValues[0].getValue();
809 // -----------------------------------------------------------------------
810 SvtLoadOptions_Impl::~SvtLoadOptions_Impl()
813 // -----------------------------------------------------------------------
814 void SvtLoadOptions_Impl::Commit()
816 Sequence< OUString > aNames(1);
817 aNames[0] = OUString::createFromAscii(cUserDefinedSettings);
818 Sequence< Any > aValues( 1 );
819 aValues[0].setValue(&bLoadUserDefinedSettings, ::getBooleanCppuType());
820 PutProperties( aNames, aValues );
822 // -----------------------------------------------------------------------
823 void SvtLoadOptions_Impl::Notify( const Sequence<rtl::OUString>& )
825 DBG_ERRORFILE( "properties have been changed" );
827 // -----------------------------------------------------------------------
829 namespace
831 class LocalSingleton : public rtl::Static< osl::Mutex, LocalSingleton >
836 // -----------------------------------------------------------------------
837 SvtSaveOptions::SvtSaveOptions()
839 // Global access, must be guarded (multithreading)
840 ::osl::MutexGuard aGuard( LocalSingleton::get() );
841 if ( !pOptions )
843 RTL_LOGFILE_CONTEXT(aLog, "svtools ( ??? ) ::SvtSaveOptions_Impl::ctor()");
844 pOptions = new SvtLoadSaveOptions_Impl;
845 pOptions->pSaveOpt = new SvtSaveOptions_Impl;
846 pOptions->pLoadOpt = new SvtLoadOptions_Impl;
848 ItemHolder1::holdConfigItem(E_SAVEOPTIONS);
850 ++nRefCount;
851 pImp = pOptions;
854 // -----------------------------------------------------------------------
856 SvtSaveOptions::~SvtSaveOptions()
858 // Global access, must be guarded (multithreading)
859 ::osl::MutexGuard aGuard( LocalSingleton::get() );
860 if ( !--nRefCount )
862 if ( pOptions->pSaveOpt->IsModified() )
863 pOptions->pSaveOpt->Commit();
864 if ( pOptions->pLoadOpt->IsModified() )
865 pOptions->pLoadOpt->Commit();
867 DELETEZ( pOptions->pLoadOpt );
868 DELETEZ( pOptions->pSaveOpt );
869 DELETEZ( pOptions );
873 void SvtSaveOptions::SetAutoSaveTime( sal_Int32 n )
875 pImp->pSaveOpt->SetAutoSaveTime( n );
878 sal_Int32 SvtSaveOptions::GetAutoSaveTime() const
880 return pImp->pSaveOpt->GetAutoSaveTime();
883 void SvtSaveOptions::SetUseUserData( sal_Bool b )
885 pImp->pSaveOpt->SetUseUserData( b );
888 sal_Bool SvtSaveOptions::IsUseUserData() const
890 return pImp->pSaveOpt->IsUseUserData();
893 void SvtSaveOptions::SetBackup( sal_Bool b )
895 pImp->pSaveOpt->SetBackup( b );
898 sal_Bool SvtSaveOptions::IsBackup() const
900 return pImp->pSaveOpt->IsBackup();
903 void SvtSaveOptions::SetAutoSave( sal_Bool b )
905 pImp->pSaveOpt->SetAutoSave( b );
908 sal_Bool SvtSaveOptions::IsAutoSave() const
910 return pImp->pSaveOpt->IsAutoSave();
913 void SvtSaveOptions::SetAutoSavePrompt( sal_Bool b )
915 pImp->pSaveOpt->SetAutoSavePrompt( b );
918 sal_Bool SvtSaveOptions::IsAutoSavePrompt() const
920 return pImp->pSaveOpt->IsAutoSavePrompt();
923 void SvtSaveOptions::SetDocInfoSave(sal_Bool b)
925 pImp->pSaveOpt->SetDocInfoSave( b );
928 sal_Bool SvtSaveOptions::IsDocInfoSave() const
930 return pImp->pSaveOpt->IsDocInfoSave();
933 void SvtSaveOptions::SetSaveWorkingSet( sal_Bool b )
935 pImp->pSaveOpt->SetSaveWorkingSet( b );
938 sal_Bool SvtSaveOptions::IsSaveWorkingSet() const
940 return pImp->pSaveOpt->IsSaveWorkingSet();
943 void SvtSaveOptions::SetSaveDocWins( sal_Bool b )
945 pImp->pSaveOpt->SetSaveDocWins( b );
948 sal_Bool SvtSaveOptions::IsSaveDocWins() const
950 return pImp->pSaveOpt->IsSaveDocWins();
953 void SvtSaveOptions::SetSaveDocView( sal_Bool b )
955 pImp->pSaveOpt->SetSaveDocView( b );
958 sal_Bool SvtSaveOptions::IsSaveDocView() const
960 return pImp->pSaveOpt->IsSaveDocView();
963 void SvtSaveOptions::SetSaveRelINet( sal_Bool b )
965 pImp->pSaveOpt->SetSaveRelINet( b );
968 sal_Bool SvtSaveOptions::IsSaveRelINet() const
970 return pImp->pSaveOpt->IsSaveRelINet();
973 void SvtSaveOptions::SetSaveRelFSys( sal_Bool b )
975 pImp->pSaveOpt->SetSaveRelFSys( b );
978 sal_Bool SvtSaveOptions::IsSaveRelFSys() const
980 return pImp->pSaveOpt->IsSaveRelFSys();
983 void SvtSaveOptions::SetSaveUnpacked( sal_Bool b )
985 pImp->pSaveOpt->SetSaveUnpacked( b );
988 sal_Bool SvtSaveOptions::IsSaveUnpacked() const
990 return pImp->pSaveOpt->IsSaveUnpacked();
993 void SvtSaveOptions::SetLoadUserSettings(sal_Bool b)
995 pImp->pLoadOpt->SetLoadUserSettings(b);
998 sal_Bool SvtSaveOptions::IsLoadUserSettings() const
1000 return pImp->pLoadOpt->IsLoadUserSettings();
1003 void SvtSaveOptions::SetPrettyPrinting( sal_Bool _bEnable )
1005 pImp->pSaveOpt->EnablePrettyPrinting( _bEnable );
1008 sal_Bool SvtSaveOptions::IsPrettyPrinting() const
1010 return pImp->pSaveOpt->IsPrettyPrintingEnabled();
1013 void SvtSaveOptions::SetWarnAlienFormat( sal_Bool _bEnable )
1015 pImp->pSaveOpt->SetWarnAlienFormat( _bEnable );
1018 sal_Bool SvtSaveOptions::IsWarnAlienFormat() const
1020 return pImp->pSaveOpt->IsWarnAlienFormat();
1023 void SvtSaveOptions::SetLoadDocumentPrinter( sal_Bool _bEnable )
1025 pImp->pSaveOpt->SetLoadDocPrinter( _bEnable );
1028 sal_Bool SvtSaveOptions::IsLoadDocumentPrinter() const
1030 return pImp->pSaveOpt->IsLoadDocPrinter();
1033 void SvtSaveOptions::SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion eVersion )
1035 pImp->pSaveOpt->SetODFDefaultVersion( eVersion );
1038 SvtSaveOptions::ODFDefaultVersion SvtSaveOptions::GetODFDefaultVersion() const
1040 return pImp->pSaveOpt->GetODFDefaultVersion();
1043 sal_Bool SvtSaveOptions::IsReadOnly( SvtSaveOptions::EOption eOption ) const
1045 return pImp->pSaveOpt->IsReadOnly(eOption);