update dev300-m58
[ooovba.git] / svtools / source / config / saveopt.cxx
blob6874098d74701d9038a579e27ef3f6775ce79427
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_012 )
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 )
477 eODFDefaultVersion = SvtSaveOptions::ODFDefaultVersion( nTmp );
478 else {
479 DBG_ERRORFILE( "SvtSaveOptions_Impl::SvtSaveOptions_Impl(): Wrong Type!" );
481 bROAutoSaveTime = pROStates[nProp];
482 break;
485 default:
487 sal_Bool bTemp = sal_Bool();
488 if ( pValues[nProp] >>= bTemp )
490 switch ( nProp )
492 case USEUSERDATA :
493 bUseUserData = bTemp;
494 bROUseUserData = pROStates[nProp];
495 break;
496 case CREATEBACKUP :
497 bBackup = bTemp;
498 bROBackup = pROStates[nProp];
499 break;
500 case AUTOSAVE :
501 bAutoSave = bTemp;
502 bROAutoSave = pROStates[nProp];
503 break;
504 case PROMPT :
505 bAutoSavePrompt = bTemp;
506 bROAutoSavePrompt = pROStates[nProp];
507 break;
508 case EDITPROPERTY :
509 bDocInfSave = bTemp;
510 bRODocInfSave = pROStates[nProp];
511 break;
512 case SAVEWORKINGSET :
513 bSaveWorkingSet = bTemp;
514 bROSaveWorkingSet = pROStates[nProp];
515 break;
516 case SAVEDOCWINS :
517 bSaveDocWins = bTemp;
518 bROSaveDocWins = pROStates[nProp];
519 break;
520 case SAVEVIEWINFO :
521 bSaveDocView = bTemp;
522 bROSaveDocView = pROStates[nProp];
523 break;
524 case FILESYSTEM :
525 bSaveRelFSys = bTemp;
526 bROSaveRelFSys = pROStates[nProp];
527 break;
528 case INTERNET :
529 bSaveRelINet = bTemp;
530 bROSaveRelINet = pROStates[nProp];
531 break;
532 case UNPACKED :
533 bSaveUnpacked = bTemp;
534 bROSaveUnpacked = pROStates[nProp];
535 break;
537 case PRETTYPRINTING:
538 bDoPrettyPrinting = bTemp;
539 bRODoPrettyPrinting = pROStates[nProp];
540 break;
542 case WARNALIENFORMAT:
543 bWarnAlienFormat = bTemp;
544 bROWarnAlienFormat = pROStates[nProp];
545 break;
547 case LOADDOCPRINTER:
548 bLoadDocPrinter = bTemp;
549 bROLoadDocPrinter = pROStates[nProp];
550 break;
552 default :
553 DBG_ERRORFILE( "invalid index to load a path" );
556 else
558 DBG_ERROR( "Wrong Type!" );
568 css::uno::Reference< css::uno::XInterface > xCFG = ::comphelper::ConfigurationHelper::openConfig(
569 ::utl::getProcessServiceFactory(),
570 ::rtl::OUString::createFromAscii("org.openoffice.Office.Recovery"),
571 ::comphelper::ConfigurationHelper::E_READONLY);
573 ::comphelper::ConfigurationHelper::readRelativeKey(
574 xCFG,
575 ::rtl::OUString::createFromAscii("AutoSave"),
576 ::rtl::OUString::createFromAscii("Enabled")) >>= bAutoSave;
578 ::comphelper::ConfigurationHelper::readRelativeKey(
579 xCFG,
580 ::rtl::OUString::createFromAscii("AutoSave"),
581 ::rtl::OUString::createFromAscii("TimeIntervall")) >>= nAutoSaveTime;
583 catch(const css::uno::Exception&)
584 { DBG_ERROR("Could not find needed informations for AutoSave feature."); }
587 SvtSaveOptions_Impl::~SvtSaveOptions_Impl()
590 void SvtSaveOptions_Impl::Commit()
592 Sequence< OUString > aOrgNames = GetPropertyNames();
593 OUString* pOrgNames = aOrgNames.getArray();
594 sal_Int32 nOrgCount = aOrgNames.getLength();
596 Sequence< OUString > aNames( nOrgCount );
597 Sequence< Any > aValues( nOrgCount );
598 OUString* pNames = aNames.getArray();
599 Any* pValues = aValues.getArray();
600 sal_Int32 nRealCount = 0;
602 for (sal_Int32 i=0; i<nOrgCount; ++i)
604 switch (i)
606 case FORMAT:
607 // not supported anymore
608 break;
609 case TIMEINTERVALL :
610 if (!bROAutoSaveTime)
612 pValues[nRealCount] <<= nAutoSaveTime;
613 pNames[nRealCount] = pOrgNames[i];
614 ++nRealCount;
616 break;
617 case USEUSERDATA :
618 if (!bROUseUserData)
620 pValues[nRealCount] <<= bUseUserData;
621 pNames[nRealCount] = pOrgNames[i];
622 ++nRealCount;
624 break;
625 case CREATEBACKUP :
626 if (!bROBackup)
628 pValues[nRealCount] <<= bBackup;
629 pNames[nRealCount] = pOrgNames[i];
630 ++nRealCount;
632 break;
633 case AUTOSAVE :
634 if (!bROAutoSave)
636 pValues[nRealCount] <<= bAutoSave;
637 pNames[nRealCount] = pOrgNames[i];
638 ++nRealCount;
640 break;
641 case PROMPT :
642 if (!bROAutoSavePrompt)
644 pValues[nRealCount] <<= bAutoSavePrompt;
645 pNames[nRealCount] = pOrgNames[i];
646 ++nRealCount;
648 break;
649 case EDITPROPERTY :
650 if (!bRODocInfSave)
652 pValues[nRealCount] <<= bDocInfSave;
653 pNames[nRealCount] = pOrgNames[i];
654 ++nRealCount;
656 break;
657 case SAVEWORKINGSET :
658 if (!bROSaveWorkingSet)
660 pValues[nRealCount] <<= bSaveWorkingSet;
661 pNames[nRealCount] = pOrgNames[i];
662 ++nRealCount;
664 break;
665 case SAVEDOCWINS :
666 if (!bROSaveDocWins)
668 pValues[nRealCount] <<= bSaveDocWins;
669 pNames[nRealCount] = pOrgNames[i];
670 ++nRealCount;
672 break;
673 case SAVEVIEWINFO :
674 if (!bROSaveDocView)
676 pValues[nRealCount] <<= bSaveDocView;
677 pNames[nRealCount] = pOrgNames[i];
678 ++nRealCount;
680 break;
681 case FILESYSTEM :
682 if (!bROSaveRelFSys)
684 pValues[nRealCount] <<= bSaveRelFSys;
685 pNames[nRealCount] = pOrgNames[i];
686 ++nRealCount;
688 break;
689 case INTERNET :
690 if (!bROSaveRelINet)
692 pValues[nRealCount] <<= bSaveRelINet;
693 pNames[nRealCount] = pOrgNames[i];
694 ++nRealCount;
696 break;
697 case UNPACKED :
698 if (!bROSaveUnpacked)
700 pValues[nRealCount] <<= bSaveUnpacked;
701 pNames[nRealCount] = pOrgNames[i];
702 ++nRealCount;
704 break;
705 case PRETTYPRINTING:
706 if (!bRODoPrettyPrinting)
708 pValues[nRealCount] <<= bDoPrettyPrinting;
709 pNames[nRealCount] = pOrgNames[i];
710 ++nRealCount;
712 break;
713 case WARNALIENFORMAT:
714 if (!bROWarnAlienFormat)
716 pValues[nRealCount] <<= bWarnAlienFormat;
717 pNames[nRealCount] = pOrgNames[i];
718 ++nRealCount;
720 break;
721 case LOADDOCPRINTER:
722 if (!bROLoadDocPrinter)
724 pValues[nRealCount] <<= bLoadDocPrinter;
725 pNames[nRealCount] = pOrgNames[i];
726 ++nRealCount;
728 break;
729 case ODFDEFAULTVERSION:
730 if (!bROODFDefaultVersion)
732 pValues[nRealCount] <<= sal_Int16( eODFDefaultVersion );
733 pNames[nRealCount] = pOrgNames[i];
734 ++nRealCount;
736 break;
737 default:
738 DBG_ERRORFILE( "invalid index to save a path" );
742 aNames.realloc(nRealCount);
743 aValues.realloc(nRealCount);
744 PutProperties( aNames, aValues );
746 css::uno::Reference< css::uno::XInterface > xCFG = ::comphelper::ConfigurationHelper::openConfig(
747 ::utl::getProcessServiceFactory(),
748 ::rtl::OUString::createFromAscii("org.openoffice.Office.Recovery"),
749 ::comphelper::ConfigurationHelper::E_STANDARD);
751 ::comphelper::ConfigurationHelper::writeRelativeKey(
752 xCFG,
753 ::rtl::OUString::createFromAscii("AutoSave"),
754 ::rtl::OUString::createFromAscii("TimeIntervall"),
755 css::uno::makeAny(nAutoSaveTime));
757 ::comphelper::ConfigurationHelper::writeRelativeKey(
758 xCFG,
759 ::rtl::OUString::createFromAscii("AutoSave"),
760 ::rtl::OUString::createFromAscii("Enabled"),
761 css::uno::makeAny(bAutoSave));
763 ::comphelper::ConfigurationHelper::flush(xCFG);
766 // -----------------------------------------------------------------------
768 void SvtSaveOptions_Impl::Notify( const Sequence<rtl::OUString>& )
773 class SvtLoadOptions_Impl : public utl::ConfigItem
776 sal_Bool bLoadUserDefinedSettings;
778 public:
779 SvtLoadOptions_Impl();
780 ~SvtLoadOptions_Impl();
782 virtual void Notify( const com::sun::star::uno::Sequence< rtl::OUString >& aPropertyNames );
783 virtual void Commit();
785 void SetLoadUserSettings(sal_Bool b){bLoadUserDefinedSettings = b; SetModified();}
786 sal_Bool IsLoadUserSettings() const {return bLoadUserDefinedSettings;}
788 // -----------------------------------------------------------------------
789 const sal_Char cUserDefinedSettings[] = "UserDefinedSettings";
791 SvtLoadOptions_Impl::SvtLoadOptions_Impl()
792 : ConfigItem( OUString::createFromAscii("Office.Common/Load") )
793 , bLoadUserDefinedSettings( sal_False )
795 Sequence< OUString > aNames(1);
796 aNames[0] = OUString::createFromAscii(cUserDefinedSettings);
797 Sequence< Any > aValues = GetProperties( aNames );
798 EnableNotification( aNames );
799 const Any* pValues = aValues.getConstArray();
800 DBG_ASSERT( aValues.getLength() == aNames.getLength(), "GetProperties failed" );
801 if (pValues[0].getValueTypeClass() == ::com::sun::star::uno::TypeClass_BOOLEAN)
802 bLoadUserDefinedSettings = *(sal_Bool *)pValues[0].getValue();
804 // -----------------------------------------------------------------------
805 SvtLoadOptions_Impl::~SvtLoadOptions_Impl()
808 // -----------------------------------------------------------------------
809 void SvtLoadOptions_Impl::Commit()
811 Sequence< OUString > aNames(1);
812 aNames[0] = OUString::createFromAscii(cUserDefinedSettings);
813 Sequence< Any > aValues( 1 );
814 aValues[0].setValue(&bLoadUserDefinedSettings, ::getBooleanCppuType());
815 PutProperties( aNames, aValues );
817 // -----------------------------------------------------------------------
818 void SvtLoadOptions_Impl::Notify( const Sequence<rtl::OUString>& )
820 DBG_ERRORFILE( "properties have been changed" );
822 // -----------------------------------------------------------------------
824 namespace
826 class LocalSingleton : public rtl::Static< osl::Mutex, LocalSingleton >
831 // -----------------------------------------------------------------------
832 SvtSaveOptions::SvtSaveOptions()
834 // Global access, must be guarded (multithreading)
835 ::osl::MutexGuard aGuard( LocalSingleton::get() );
836 if ( !pOptions )
838 RTL_LOGFILE_CONTEXT(aLog, "svtools ( ??? ) ::SvtSaveOptions_Impl::ctor()");
839 pOptions = new SvtLoadSaveOptions_Impl;
840 pOptions->pSaveOpt = new SvtSaveOptions_Impl;
841 pOptions->pLoadOpt = new SvtLoadOptions_Impl;
843 ItemHolder1::holdConfigItem(E_SAVEOPTIONS);
845 ++nRefCount;
846 pImp = pOptions;
849 // -----------------------------------------------------------------------
851 SvtSaveOptions::~SvtSaveOptions()
853 // Global access, must be guarded (multithreading)
854 ::osl::MutexGuard aGuard( LocalSingleton::get() );
855 if ( !--nRefCount )
857 if ( pOptions->pSaveOpt->IsModified() )
858 pOptions->pSaveOpt->Commit();
859 if ( pOptions->pLoadOpt->IsModified() )
860 pOptions->pLoadOpt->Commit();
862 DELETEZ( pOptions->pLoadOpt );
863 DELETEZ( pOptions->pSaveOpt );
864 DELETEZ( pOptions );
868 void SvtSaveOptions::SetAutoSaveTime( sal_Int32 n )
870 pImp->pSaveOpt->SetAutoSaveTime( n );
873 sal_Int32 SvtSaveOptions::GetAutoSaveTime() const
875 return pImp->pSaveOpt->GetAutoSaveTime();
878 void SvtSaveOptions::SetUseUserData( sal_Bool b )
880 pImp->pSaveOpt->SetUseUserData( b );
883 sal_Bool SvtSaveOptions::IsUseUserData() const
885 return pImp->pSaveOpt->IsUseUserData();
888 void SvtSaveOptions::SetBackup( sal_Bool b )
890 pImp->pSaveOpt->SetBackup( b );
893 sal_Bool SvtSaveOptions::IsBackup() const
895 return pImp->pSaveOpt->IsBackup();
898 void SvtSaveOptions::SetAutoSave( sal_Bool b )
900 pImp->pSaveOpt->SetAutoSave( b );
903 sal_Bool SvtSaveOptions::IsAutoSave() const
905 return pImp->pSaveOpt->IsAutoSave();
908 void SvtSaveOptions::SetAutoSavePrompt( sal_Bool b )
910 pImp->pSaveOpt->SetAutoSavePrompt( b );
913 sal_Bool SvtSaveOptions::IsAutoSavePrompt() const
915 return pImp->pSaveOpt->IsAutoSavePrompt();
918 void SvtSaveOptions::SetDocInfoSave(sal_Bool b)
920 pImp->pSaveOpt->SetDocInfoSave( b );
923 sal_Bool SvtSaveOptions::IsDocInfoSave() const
925 return pImp->pSaveOpt->IsDocInfoSave();
928 void SvtSaveOptions::SetSaveWorkingSet( sal_Bool b )
930 pImp->pSaveOpt->SetSaveWorkingSet( b );
933 sal_Bool SvtSaveOptions::IsSaveWorkingSet() const
935 return pImp->pSaveOpt->IsSaveWorkingSet();
938 void SvtSaveOptions::SetSaveDocWins( sal_Bool b )
940 pImp->pSaveOpt->SetSaveDocWins( b );
943 sal_Bool SvtSaveOptions::IsSaveDocWins() const
945 return pImp->pSaveOpt->IsSaveDocWins();
948 void SvtSaveOptions::SetSaveDocView( sal_Bool b )
950 pImp->pSaveOpt->SetSaveDocView( b );
953 sal_Bool SvtSaveOptions::IsSaveDocView() const
955 return pImp->pSaveOpt->IsSaveDocView();
958 void SvtSaveOptions::SetSaveRelINet( sal_Bool b )
960 pImp->pSaveOpt->SetSaveRelINet( b );
963 sal_Bool SvtSaveOptions::IsSaveRelINet() const
965 return pImp->pSaveOpt->IsSaveRelINet();
968 void SvtSaveOptions::SetSaveRelFSys( sal_Bool b )
970 pImp->pSaveOpt->SetSaveRelFSys( b );
973 sal_Bool SvtSaveOptions::IsSaveRelFSys() const
975 return pImp->pSaveOpt->IsSaveRelFSys();
978 void SvtSaveOptions::SetSaveUnpacked( sal_Bool b )
980 pImp->pSaveOpt->SetSaveUnpacked( b );
983 sal_Bool SvtSaveOptions::IsSaveUnpacked() const
985 return pImp->pSaveOpt->IsSaveUnpacked();
988 void SvtSaveOptions::SetLoadUserSettings(sal_Bool b)
990 pImp->pLoadOpt->SetLoadUserSettings(b);
993 sal_Bool SvtSaveOptions::IsLoadUserSettings() const
995 return pImp->pLoadOpt->IsLoadUserSettings();
998 void SvtSaveOptions::SetPrettyPrinting( sal_Bool _bEnable )
1000 pImp->pSaveOpt->EnablePrettyPrinting( _bEnable );
1003 sal_Bool SvtSaveOptions::IsPrettyPrinting() const
1005 return pImp->pSaveOpt->IsPrettyPrintingEnabled();
1008 void SvtSaveOptions::SetWarnAlienFormat( sal_Bool _bEnable )
1010 pImp->pSaveOpt->SetWarnAlienFormat( _bEnable );
1013 sal_Bool SvtSaveOptions::IsWarnAlienFormat() const
1015 return pImp->pSaveOpt->IsWarnAlienFormat();
1018 void SvtSaveOptions::SetLoadDocumentPrinter( sal_Bool _bEnable )
1020 pImp->pSaveOpt->SetLoadDocPrinter( _bEnable );
1023 sal_Bool SvtSaveOptions::IsLoadDocumentPrinter() const
1025 return pImp->pSaveOpt->IsLoadDocPrinter();
1028 void SvtSaveOptions::SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion eVersion )
1030 pImp->pSaveOpt->SetODFDefaultVersion( eVersion );
1033 SvtSaveOptions::ODFDefaultVersion SvtSaveOptions::GetODFDefaultVersion() const
1035 return pImp->pSaveOpt->GetODFDefaultVersion();
1038 sal_Bool SvtSaveOptions::IsReadOnly( SvtSaveOptions::EOption eOption ) const
1040 return pImp->pSaveOpt->IsReadOnly(eOption);