Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / unotools / source / config / saveopt.cxx
blob16186382a8b1ba17b891a0f508e47684642dce2c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <unotools/saveopt.hxx>
21 #include "rtl/instance.hxx"
22 #include <unotools/configmgr.hxx>
23 #include <unotools/configitem.hxx>
24 #include <tools/debug.hxx>
25 #include <com/sun/star/uno/Any.hxx>
26 #include <com/sun/star/uno/Sequence.hxx>
28 #include <osl/mutex.hxx>
29 #include <comphelper/configurationhelper.hxx>
30 #include <comphelper/processfactory.hxx>
31 #include <rtl/logfile.hxx>
32 #include "itemholder1.hxx"
34 using namespace utl;
35 using namespace com::sun::star::uno;
37 using ::rtl::OUString;
39 class SvtSaveOptions_Impl;
40 class SvtLoadOptions_Impl;
42 #define CFG_READONLY_DEFAULT sal_False
44 struct SvtLoadSaveOptions_Impl
46 SvtSaveOptions_Impl* pSaveOpt;
47 SvtLoadOptions_Impl* pLoadOpt;
50 static SvtLoadSaveOptions_Impl* pOptions = NULL;
51 static sal_Int32 nRefCount = 0;
53 class SvtSaveOptions_Impl : public utl::ConfigItem
55 sal_Int32 nAutoSaveTime;
56 sal_Bool bUseUserData,
57 bBackup,
58 bAutoSave,
59 bAutoSavePrompt,
60 bDocInfSave,
61 bSaveWorkingSet,
62 bSaveDocView,
63 bSaveRelINet,
64 bSaveRelFSys,
65 bSaveUnpacked,
66 bDoPrettyPrinting,
67 bWarnAlienFormat,
68 bLoadDocPrinter,
69 bUseSHA1InODF12,
70 bUseBlowfishInODF12;
72 SvtSaveOptions::ODFDefaultVersion eODFDefaultVersion;
74 sal_Bool bROAutoSaveTime,
75 bROUseUserData,
76 bROBackup,
77 bROAutoSave,
78 bROAutoSavePrompt,
79 bRODocInfSave,
80 bROSaveWorkingSet,
81 bROSaveDocView,
82 bROSaveRelINet,
83 bROSaveRelFSys,
84 bROSaveUnpacked,
85 bROWarnAlienFormat,
86 bRODoPrettyPrinting,
87 bROLoadDocPrinter,
88 bROODFDefaultVersion,
89 bROUseSHA1InODF12,
90 bROUseBlowfishInODF12;
92 public:
93 SvtSaveOptions_Impl();
94 ~SvtSaveOptions_Impl();
96 virtual void Notify( const com::sun::star::uno::Sequence< rtl::OUString >& aPropertyNames );
97 virtual void Commit();
99 sal_Int32 GetAutoSaveTime() const { return nAutoSaveTime; }
100 sal_Bool IsUseUserData() const { return bUseUserData; }
101 sal_Bool IsBackup() const { return bBackup; }
102 sal_Bool IsAutoSave() const { return bAutoSave; }
103 sal_Bool IsAutoSavePrompt() const { return bAutoSavePrompt; }
104 sal_Bool IsDocInfoSave() const { return bDocInfSave; }
105 sal_Bool IsSaveWorkingSet() const { return bSaveWorkingSet; }
106 sal_Bool IsSaveDocView() const { return bSaveDocView; }
107 sal_Bool IsSaveRelINet() const { return bSaveRelINet; }
108 sal_Bool IsSaveRelFSys() const { return bSaveRelFSys; }
109 sal_Bool IsSaveUnpacked() const { return bSaveUnpacked; }
110 sal_Bool IsPrettyPrintingEnabled( ) const { return bDoPrettyPrinting; }
111 sal_Bool IsWarnAlienFormat() const { return bWarnAlienFormat; }
112 sal_Bool IsLoadDocPrinter() const { return bLoadDocPrinter; }
113 sal_Bool IsUseSHA1InODF12() const { return bUseSHA1InODF12; }
114 sal_Bool IsUseBlowfishInODF12() const { return bUseBlowfishInODF12; }
116 SvtSaveOptions::ODFDefaultVersion
117 GetODFDefaultVersion() const { return eODFDefaultVersion; }
119 void SetAutoSaveTime( sal_Int32 n );
120 void SetUseUserData( sal_Bool b );
121 void SetBackup( sal_Bool b );
122 void SetAutoSave( sal_Bool b );
123 void SetAutoSavePrompt( sal_Bool b );
124 void SetDocInfoSave( sal_Bool b );
125 void SetSaveWorkingSet( sal_Bool b );
126 void SetSaveDocView( sal_Bool b );
127 void SetSaveRelINet( sal_Bool b );
128 void SetSaveRelFSys( sal_Bool b );
129 void EnablePrettyPrinting( sal_Bool _bDoPP );
130 void SetWarnAlienFormat( sal_Bool _bDoPP );
131 void SetLoadDocPrinter( sal_Bool bNew );
132 void SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion eNew );
134 sal_Bool IsReadOnly( SvtSaveOptions::EOption eOption ) const;
137 void SvtSaveOptions_Impl::SetAutoSaveTime( sal_Int32 n )
139 if (!bROAutoSaveTime && nAutoSaveTime!=n)
141 nAutoSaveTime = n;
142 SetModified();
143 Commit();
147 void SvtSaveOptions_Impl::SetUseUserData( sal_Bool b )
149 if (!bROUseUserData && bUseUserData!=b)
151 bUseUserData = b;
152 SetModified();
156 void SvtSaveOptions_Impl::SetBackup( sal_Bool b )
158 if (!bROBackup && bBackup!=b)
160 bBackup = b;
161 SetModified();
165 void SvtSaveOptions_Impl::SetAutoSave( sal_Bool b )
167 if (!bROAutoSave && bAutoSave!=b)
169 bAutoSave = b;
170 SetModified();
171 Commit();
175 void SvtSaveOptions_Impl::SetAutoSavePrompt( sal_Bool b )
177 if (!bROAutoSavePrompt && bAutoSavePrompt!=b)
179 bAutoSavePrompt = b;
180 SetModified();
184 void SvtSaveOptions_Impl::SetDocInfoSave(sal_Bool b)
186 if (!bRODocInfSave && bDocInfSave!=b)
188 bDocInfSave = b;
189 SetModified();
193 void SvtSaveOptions_Impl::SetSaveWorkingSet( sal_Bool b )
195 if (!bROSaveWorkingSet && bSaveWorkingSet!=b)
197 bSaveWorkingSet = b;
198 SetModified();
202 void SvtSaveOptions_Impl::SetSaveDocView( sal_Bool b )
204 if (!bROSaveDocView && bSaveDocView!=b)
206 bSaveDocView = b;
207 SetModified();
211 void SvtSaveOptions_Impl::SetSaveRelINet( sal_Bool b )
213 if (!bROSaveRelINet && bSaveRelINet!=b)
215 bSaveRelINet = b;
216 SetModified();
220 void SvtSaveOptions_Impl::SetSaveRelFSys( sal_Bool b )
222 if (!bROSaveRelFSys && bSaveRelFSys!=b)
224 bSaveRelFSys = b;
225 SetModified();
229 void SvtSaveOptions_Impl::EnablePrettyPrinting( sal_Bool _bDoPP )
231 if (!bRODoPrettyPrinting && bDoPrettyPrinting!=_bDoPP)
233 bDoPrettyPrinting = _bDoPP;
234 SetModified();
238 void SvtSaveOptions_Impl::SetWarnAlienFormat( sal_Bool _bDoPP )
240 if (!bROWarnAlienFormat && bWarnAlienFormat!=_bDoPP)
242 bWarnAlienFormat = _bDoPP;
243 SetModified();
247 void SvtSaveOptions_Impl::SetLoadDocPrinter( sal_Bool bNew )
249 if ( !bROLoadDocPrinter && bLoadDocPrinter != bNew )
251 bLoadDocPrinter = bNew;
252 SetModified();
256 void SvtSaveOptions_Impl::SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion eNew )
258 if ( !bROODFDefaultVersion && eODFDefaultVersion != eNew )
260 eODFDefaultVersion = eNew;
261 SetModified();
265 sal_Bool SvtSaveOptions_Impl::IsReadOnly( SvtSaveOptions::EOption eOption ) const
267 sal_Bool bReadOnly = CFG_READONLY_DEFAULT;
268 switch(eOption)
270 case SvtSaveOptions::E_AUTOSAVETIME :
271 bReadOnly = bROAutoSaveTime;
272 break;
273 case SvtSaveOptions::E_USEUSERDATA :
274 bReadOnly = bROUseUserData;
275 break;
276 case SvtSaveOptions::E_BACKUP :
277 bReadOnly = bROBackup;
278 break;
279 case SvtSaveOptions::E_AUTOSAVE :
280 bReadOnly = bROAutoSave;
281 break;
282 case SvtSaveOptions::E_AUTOSAVEPROMPT :
283 bReadOnly = bROAutoSavePrompt;
284 break;
285 case SvtSaveOptions::E_DOCINFSAVE :
286 bReadOnly = bRODocInfSave;
287 break;
288 case SvtSaveOptions::E_SAVEWORKINGSET :
289 bReadOnly = bROSaveWorkingSet;
290 break;
291 case SvtSaveOptions::E_SAVEDOCVIEW :
292 bReadOnly = bROSaveDocView;
293 break;
294 case SvtSaveOptions::E_SAVERELINET :
295 bReadOnly = bROSaveRelINet;
296 break;
297 case SvtSaveOptions::E_SAVERELFSYS :
298 bReadOnly = bROSaveRelFSys;
299 break;
300 case SvtSaveOptions::E_SAVEUNPACKED :
301 bReadOnly = bROSaveUnpacked;
302 break;
303 case SvtSaveOptions::E_DOPRETTYPRINTING :
304 bReadOnly = bRODoPrettyPrinting;
305 break;
306 case SvtSaveOptions::E_WARNALIENFORMAT :
307 bReadOnly = bROWarnAlienFormat;
308 break;
309 case SvtSaveOptions::E_LOADDOCPRINTER :
310 bReadOnly = bROLoadDocPrinter;
311 break;
312 case SvtSaveOptions::E_ODFDEFAULTVERSION :
313 bReadOnly = bROLoadDocPrinter;
314 break;
315 case SvtSaveOptions::E_USESHA1INODF12:
316 bReadOnly = bROUseSHA1InODF12;
317 break;
318 case SvtSaveOptions::E_USEBLOWFISHINODF12:
319 bReadOnly = bROUseBlowfishInODF12;
320 break;
322 return bReadOnly;
325 #define FORMAT 0
326 #define TIMEINTERVALL 1
327 #define USEUSERDATA 2
328 #define CREATEBACKUP 3
329 #define AUTOSAVE 4
330 #define PROMPT 5
331 #define EDITPROPERTY 6
332 #define SAVEVIEWINFO 7
333 #define UNPACKED 8
334 #define PRETTYPRINTING 9
335 #define WARNALIENFORMAT 10
336 #define LOADDOCPRINTER 11
337 #define FILESYSTEM 12
338 #define INTERNET 13
339 #define SAVEWORKINGSET 14
340 #define ODFDEFAULTVERSION 15
341 #define USESHA1INODF12 16
342 #define USEBLOWFISHINODF12 17
344 Sequence< OUString > GetPropertyNames()
346 static const char* aPropNames[] =
348 "Graphic/Format",
349 "Document/AutoSaveTimeIntervall",
350 "Document/UseUserData",
351 "Document/CreateBackup",
352 "Document/AutoSave",
353 "Document/AutoSavePrompt",
354 "Document/EditProperty",
355 "Document/ViewInfo",
356 "Document/Unpacked",
357 "Document/PrettyPrinting",
358 "Document/WarnAlienFormat",
359 "Document/LoadPrinter",
360 "URL/FileSystem",
361 "URL/Internet",
362 "WorkingSet",
363 "ODF/DefaultVersion",
364 "ODF/UseSHA1InODF12",
365 "ODF/UseBlowfishInODF12"
368 const int nCount = sizeof( aPropNames ) / sizeof( const char* );
369 Sequence< OUString > aNames( nCount );
370 OUString* pNames = aNames.getArray();
371 for ( int i = 0; i < nCount; i++ )
372 pNames[i] = OUString::createFromAscii( aPropNames[i] );
374 return aNames;
377 // -----------------------------------------------------------------------
379 SvtSaveOptions_Impl::SvtSaveOptions_Impl()
380 : ConfigItem( OUString("Office.Common/Save") )
381 , nAutoSaveTime( 0 )
382 , bUseUserData( sal_False )
383 , bBackup( sal_False )
384 , bAutoSave( sal_False )
385 , bAutoSavePrompt( sal_False )
386 , bDocInfSave( sal_False )
387 , bSaveWorkingSet( sal_False )
388 , bSaveDocView( sal_False )
389 , bSaveRelINet( sal_False )
390 , bSaveRelFSys( sal_False )
391 , bSaveUnpacked( sal_False )
392 , bDoPrettyPrinting( sal_False )
393 , bWarnAlienFormat( sal_True )
394 , bLoadDocPrinter( sal_True )
395 , bUseSHA1InODF12( sal_False )
396 , bUseBlowfishInODF12( sal_False )
397 , eODFDefaultVersion( SvtSaveOptions::ODFVER_LATEST )
398 , bROAutoSaveTime( CFG_READONLY_DEFAULT )
399 , bROUseUserData( CFG_READONLY_DEFAULT )
400 , bROBackup( CFG_READONLY_DEFAULT )
401 , bROAutoSave( CFG_READONLY_DEFAULT )
402 , bROAutoSavePrompt( CFG_READONLY_DEFAULT )
403 , bRODocInfSave( CFG_READONLY_DEFAULT )
404 , bROSaveWorkingSet( CFG_READONLY_DEFAULT )
405 , bROSaveDocView( CFG_READONLY_DEFAULT )
406 , bROSaveRelINet( CFG_READONLY_DEFAULT )
407 , bROSaveRelFSys( CFG_READONLY_DEFAULT )
408 , bROSaveUnpacked( CFG_READONLY_DEFAULT )
409 , bROWarnAlienFormat( CFG_READONLY_DEFAULT )
410 , bRODoPrettyPrinting( CFG_READONLY_DEFAULT )
411 , bROLoadDocPrinter( CFG_READONLY_DEFAULT )
412 , bROODFDefaultVersion( CFG_READONLY_DEFAULT )
413 , bROUseSHA1InODF12( CFG_READONLY_DEFAULT )
414 , bROUseBlowfishInODF12( CFG_READONLY_DEFAULT )
416 Sequence< OUString > aNames = GetPropertyNames();
417 Sequence< Any > aValues = GetProperties( aNames );
418 Sequence< sal_Bool > aROStates = GetReadOnlyStates( aNames );
419 EnableNotification( aNames );
420 const Any* pValues = aValues.getConstArray();
421 const sal_Bool* pROStates = aROStates.getConstArray();
422 DBG_ASSERT( aValues.getLength() == aNames.getLength(), "GetProperties failed" );
423 DBG_ASSERT( aROStates.getLength() == aNames.getLength(), "GetReadOnlyStates failed" );
424 if ( aValues.getLength() == aNames.getLength() && aROStates.getLength() == aNames.getLength() )
426 for ( int nProp = 0; nProp < aNames.getLength(); nProp++ )
428 if ( pValues[nProp].hasValue() )
430 sal_Int32 nTemp = 0;
431 switch ( nProp )
433 case FORMAT:
434 // not supported anymore
435 break;
437 case TIMEINTERVALL :
438 if ( pValues[nProp] >>= nTemp )
439 nAutoSaveTime = nTemp;
440 else {
441 OSL_FAIL( "Wrong Type!" );
443 bROAutoSaveTime = pROStates[nProp];
444 break;
446 case ODFDEFAULTVERSION :
448 sal_Int16 nTmp = 0;
449 if ( pValues[nProp] >>= nTmp )
451 if( nTmp == 3 )
452 eODFDefaultVersion = SvtSaveOptions::ODFVER_LATEST;
453 else
454 eODFDefaultVersion = SvtSaveOptions::ODFDefaultVersion( nTmp );
456 else {
457 SAL_WARN( "unotools.config", "SvtSaveOptions_Impl::SvtSaveOptions_Impl(): Wrong Type!" );
459 bROODFDefaultVersion = pROStates[nProp];
460 break;
463 default:
465 sal_Bool bTemp = sal_Bool();
466 if ( pValues[nProp] >>= bTemp )
468 switch ( nProp )
470 case USEUSERDATA :
471 bUseUserData = bTemp;
472 bROUseUserData = pROStates[nProp];
473 break;
474 case CREATEBACKUP :
475 bBackup = bTemp;
476 bROBackup = pROStates[nProp];
477 break;
478 case AUTOSAVE :
479 bAutoSave = bTemp;
480 bROAutoSave = pROStates[nProp];
481 break;
482 case PROMPT :
483 bAutoSavePrompt = bTemp;
484 bROAutoSavePrompt = pROStates[nProp];
485 break;
486 case EDITPROPERTY :
487 bDocInfSave = bTemp;
488 bRODocInfSave = pROStates[nProp];
489 break;
490 case SAVEWORKINGSET :
491 bSaveWorkingSet = bTemp;
492 bROSaveWorkingSet = pROStates[nProp];
493 break;
494 case SAVEVIEWINFO :
495 bSaveDocView = bTemp;
496 bROSaveDocView = pROStates[nProp];
497 break;
498 case FILESYSTEM :
499 bSaveRelFSys = bTemp;
500 bROSaveRelFSys = pROStates[nProp];
501 break;
502 case INTERNET :
503 bSaveRelINet = bTemp;
504 bROSaveRelINet = pROStates[nProp];
505 break;
506 case UNPACKED :
507 bSaveUnpacked = bTemp;
508 bROSaveUnpacked = pROStates[nProp];
509 break;
511 case PRETTYPRINTING:
512 bDoPrettyPrinting = bTemp;
513 bRODoPrettyPrinting = pROStates[nProp];
514 break;
516 case WARNALIENFORMAT:
517 bWarnAlienFormat = bTemp;
518 bROWarnAlienFormat = pROStates[nProp];
519 break;
521 case LOADDOCPRINTER:
522 bLoadDocPrinter = bTemp;
523 bROLoadDocPrinter = pROStates[nProp];
524 break;
526 case USESHA1INODF12:
527 bUseSHA1InODF12 = bTemp;
528 bROUseSHA1InODF12 = pROStates[nProp];
529 break;
531 case USEBLOWFISHINODF12:
532 bUseBlowfishInODF12 = bTemp;
533 bROUseBlowfishInODF12 = pROStates[nProp];
534 break;
536 default :
537 SAL_WARN( "unotools.config", "invalid index to load a path" );
540 else
542 OSL_FAIL( "Wrong Type!" );
552 css::uno::Reference< css::uno::XInterface > xCFG = ::comphelper::ConfigurationHelper::openConfig(
553 ::comphelper::getProcessComponentContext(),
554 ::rtl::OUString("org.openoffice.Office.Recovery"),
555 ::comphelper::ConfigurationHelper::E_READONLY);
557 ::comphelper::ConfigurationHelper::readRelativeKey(
558 xCFG,
559 ::rtl::OUString("AutoSave"),
560 ::rtl::OUString("Enabled")) >>= bAutoSave;
562 ::comphelper::ConfigurationHelper::readRelativeKey(
563 xCFG,
564 ::rtl::OUString("AutoSave"),
565 ::rtl::OUString("TimeIntervall")) >>= nAutoSaveTime;
567 catch(const css::uno::Exception&)
568 { OSL_FAIL("Could not find needed informations for AutoSave feature."); }
571 SvtSaveOptions_Impl::~SvtSaveOptions_Impl()
574 void SvtSaveOptions_Impl::Commit()
576 Sequence< OUString > aOrgNames = GetPropertyNames();
577 OUString* pOrgNames = aOrgNames.getArray();
578 sal_Int32 nOrgCount = aOrgNames.getLength();
580 Sequence< OUString > aNames( nOrgCount );
581 Sequence< Any > aValues( nOrgCount );
582 OUString* pNames = aNames.getArray();
583 Any* pValues = aValues.getArray();
584 sal_Int32 nRealCount = 0;
586 for (sal_Int32 i=0; i<nOrgCount; ++i)
588 switch (i)
590 case FORMAT:
591 // not supported anymore
592 break;
593 case TIMEINTERVALL :
594 if (!bROAutoSaveTime)
596 pValues[nRealCount] <<= nAutoSaveTime;
597 pNames[nRealCount] = pOrgNames[i];
598 ++nRealCount;
600 break;
601 case USEUSERDATA :
602 if (!bROUseUserData)
604 pValues[nRealCount] <<= bUseUserData;
605 pNames[nRealCount] = pOrgNames[i];
606 ++nRealCount;
608 break;
609 case CREATEBACKUP :
610 if (!bROBackup)
612 pValues[nRealCount] <<= bBackup;
613 pNames[nRealCount] = pOrgNames[i];
614 ++nRealCount;
616 break;
617 case AUTOSAVE :
618 if (!bROAutoSave)
620 pValues[nRealCount] <<= bAutoSave;
621 pNames[nRealCount] = pOrgNames[i];
622 ++nRealCount;
624 break;
625 case PROMPT :
626 if (!bROAutoSavePrompt)
628 pValues[nRealCount] <<= bAutoSavePrompt;
629 pNames[nRealCount] = pOrgNames[i];
630 ++nRealCount;
632 break;
633 case EDITPROPERTY :
634 if (!bRODocInfSave)
636 pValues[nRealCount] <<= bDocInfSave;
637 pNames[nRealCount] = pOrgNames[i];
638 ++nRealCount;
640 break;
641 case SAVEWORKINGSET :
642 if (!bROSaveWorkingSet)
644 pValues[nRealCount] <<= bSaveWorkingSet;
645 pNames[nRealCount] = pOrgNames[i];
646 ++nRealCount;
648 break;
649 case SAVEVIEWINFO :
650 if (!bROSaveDocView)
652 pValues[nRealCount] <<= bSaveDocView;
653 pNames[nRealCount] = pOrgNames[i];
654 ++nRealCount;
656 break;
657 case FILESYSTEM :
658 if (!bROSaveRelFSys)
660 pValues[nRealCount] <<= bSaveRelFSys;
661 pNames[nRealCount] = pOrgNames[i];
662 ++nRealCount;
664 break;
665 case INTERNET :
666 if (!bROSaveRelINet)
668 pValues[nRealCount] <<= bSaveRelINet;
669 pNames[nRealCount] = pOrgNames[i];
670 ++nRealCount;
672 break;
673 case UNPACKED :
674 if (!bROSaveUnpacked)
676 pValues[nRealCount] <<= bSaveUnpacked;
677 pNames[nRealCount] = pOrgNames[i];
678 ++nRealCount;
680 break;
681 case PRETTYPRINTING:
682 if (!bRODoPrettyPrinting)
684 pValues[nRealCount] <<= bDoPrettyPrinting;
685 pNames[nRealCount] = pOrgNames[i];
686 ++nRealCount;
688 break;
689 case WARNALIENFORMAT:
690 if (!bROWarnAlienFormat)
692 pValues[nRealCount] <<= bWarnAlienFormat;
693 pNames[nRealCount] = pOrgNames[i];
694 ++nRealCount;
696 break;
697 case LOADDOCPRINTER:
698 if (!bROLoadDocPrinter)
700 pValues[nRealCount] <<= bLoadDocPrinter;
701 pNames[nRealCount] = pOrgNames[i];
702 ++nRealCount;
704 break;
705 case ODFDEFAULTVERSION:
706 if (!bROODFDefaultVersion)
708 pValues[nRealCount] <<= (eODFDefaultVersion == SvtSaveOptions::ODFVER_LATEST) ? sal_Int16( 3 ) : sal_Int16( eODFDefaultVersion );
709 pNames[nRealCount] = pOrgNames[i];
710 ++nRealCount;
712 break;
713 case USESHA1INODF12:
714 if (!bROUseSHA1InODF12)
716 pValues[nRealCount] <<= bUseSHA1InODF12;
717 pNames[nRealCount] = pOrgNames[i];
718 ++nRealCount;
720 break;
721 case USEBLOWFISHINODF12:
722 if (!bROUseBlowfishInODF12)
724 pValues[nRealCount] <<= bUseBlowfishInODF12;
725 pNames[nRealCount] = pOrgNames[i];
726 ++nRealCount;
728 break;
730 default:
731 SAL_WARN( "unotools.config", "invalid index to save a path" );
735 aNames.realloc(nRealCount);
736 aValues.realloc(nRealCount);
737 PutProperties( aNames, aValues );
739 css::uno::Reference< css::uno::XInterface > xCFG = ::comphelper::ConfigurationHelper::openConfig(
740 ::comphelper::getProcessComponentContext(),
741 ::rtl::OUString("org.openoffice.Office.Recovery"),
742 ::comphelper::ConfigurationHelper::E_STANDARD);
744 ::comphelper::ConfigurationHelper::writeRelativeKey(
745 xCFG,
746 ::rtl::OUString("AutoSave"),
747 ::rtl::OUString("TimeIntervall"),
748 css::uno::makeAny(nAutoSaveTime));
750 ::comphelper::ConfigurationHelper::writeRelativeKey(
751 xCFG,
752 ::rtl::OUString("AutoSave"),
753 ::rtl::OUString("Enabled"),
754 css::uno::makeAny(bAutoSave));
756 ::comphelper::ConfigurationHelper::flush(xCFG);
759 // -----------------------------------------------------------------------
761 void SvtSaveOptions_Impl::Notify( const Sequence<rtl::OUString>& )
766 class SvtLoadOptions_Impl : public utl::ConfigItem
769 sal_Bool bLoadUserDefinedSettings;
771 public:
772 SvtLoadOptions_Impl();
773 ~SvtLoadOptions_Impl();
775 virtual void Notify( const com::sun::star::uno::Sequence< rtl::OUString >& aPropertyNames );
776 virtual void Commit();
778 void SetLoadUserSettings(sal_Bool b){bLoadUserDefinedSettings = b; SetModified();}
779 sal_Bool IsLoadUserSettings() const {return bLoadUserDefinedSettings;}
781 // -----------------------------------------------------------------------
782 const sal_Char cUserDefinedSettings[] = "UserDefinedSettings";
784 SvtLoadOptions_Impl::SvtLoadOptions_Impl()
785 : ConfigItem( OUString("Office.Common/Load") )
786 , bLoadUserDefinedSettings( sal_False )
788 Sequence< OUString > aNames(1);
789 aNames[0] = OUString::createFromAscii(cUserDefinedSettings);
790 Sequence< Any > aValues = GetProperties( aNames );
791 EnableNotification( aNames );
792 const Any* pValues = aValues.getConstArray();
793 DBG_ASSERT( aValues.getLength() == aNames.getLength(), "GetProperties failed" );
794 if (pValues[0].getValueTypeClass() == ::com::sun::star::uno::TypeClass_BOOLEAN)
795 bLoadUserDefinedSettings = *(sal_Bool *)pValues[0].getValue();
797 // -----------------------------------------------------------------------
798 SvtLoadOptions_Impl::~SvtLoadOptions_Impl()
801 // -----------------------------------------------------------------------
802 void SvtLoadOptions_Impl::Commit()
804 Sequence< OUString > aNames(1);
805 aNames[0] = OUString::createFromAscii(cUserDefinedSettings);
806 Sequence< Any > aValues( 1 );
807 aValues[0].setValue(&bLoadUserDefinedSettings, ::getBooleanCppuType());
808 PutProperties( aNames, aValues );
810 // -----------------------------------------------------------------------
811 void SvtLoadOptions_Impl::Notify( const Sequence<rtl::OUString>& )
813 SAL_WARN( "unotools.config", "properties have been changed" );
815 // -----------------------------------------------------------------------
817 namespace
819 class LocalSingleton : public rtl::Static< osl::Mutex, LocalSingleton >
824 // -----------------------------------------------------------------------
825 SvtSaveOptions::SvtSaveOptions()
827 // Global access, must be guarded (multithreading)
828 ::osl::MutexGuard aGuard( LocalSingleton::get() );
829 if ( !pOptions )
831 RTL_LOGFILE_CONTEXT(aLog, "unotools ( ??? ) ::SvtSaveOptions_Impl::ctor()");
832 pOptions = new SvtLoadSaveOptions_Impl;
833 pOptions->pSaveOpt = new SvtSaveOptions_Impl;
834 pOptions->pLoadOpt = new SvtLoadOptions_Impl;
836 ItemHolder1::holdConfigItem(E_SAVEOPTIONS);
838 ++nRefCount;
839 pImp = pOptions;
842 // -----------------------------------------------------------------------
844 SvtSaveOptions::~SvtSaveOptions()
846 // Global access, must be guarded (multithreading)
847 ::osl::MutexGuard aGuard( LocalSingleton::get() );
848 if ( !--nRefCount )
850 if ( pOptions->pSaveOpt->IsModified() )
851 pOptions->pSaveOpt->Commit();
852 if ( pOptions->pLoadOpt->IsModified() )
853 pOptions->pLoadOpt->Commit();
855 DELETEZ( pOptions->pLoadOpt );
856 DELETEZ( pOptions->pSaveOpt );
857 DELETEZ( pOptions );
861 void SvtSaveOptions::SetAutoSaveTime( sal_Int32 n )
863 pImp->pSaveOpt->SetAutoSaveTime( n );
866 sal_Int32 SvtSaveOptions::GetAutoSaveTime() const
868 return pImp->pSaveOpt->GetAutoSaveTime();
871 void SvtSaveOptions::SetUseUserData( sal_Bool b )
873 pImp->pSaveOpt->SetUseUserData( b );
876 sal_Bool SvtSaveOptions::IsUseUserData() const
878 return pImp->pSaveOpt->IsUseUserData();
881 void SvtSaveOptions::SetBackup( sal_Bool b )
883 pImp->pSaveOpt->SetBackup( b );
886 sal_Bool SvtSaveOptions::IsBackup() const
888 return pImp->pSaveOpt->IsBackup();
891 void SvtSaveOptions::SetAutoSave( sal_Bool b )
893 pImp->pSaveOpt->SetAutoSave( b );
896 sal_Bool SvtSaveOptions::IsAutoSave() const
898 return pImp->pSaveOpt->IsAutoSave();
901 void SvtSaveOptions::SetAutoSavePrompt( sal_Bool b )
903 pImp->pSaveOpt->SetAutoSavePrompt( b );
906 sal_Bool SvtSaveOptions::IsAutoSavePrompt() const
908 return pImp->pSaveOpt->IsAutoSavePrompt();
911 void SvtSaveOptions::SetDocInfoSave(sal_Bool b)
913 pImp->pSaveOpt->SetDocInfoSave( b );
916 sal_Bool SvtSaveOptions::IsDocInfoSave() const
918 return pImp->pSaveOpt->IsDocInfoSave();
921 void SvtSaveOptions::SetSaveWorkingSet( sal_Bool b )
923 pImp->pSaveOpt->SetSaveWorkingSet( b );
926 sal_Bool SvtSaveOptions::IsSaveWorkingSet() const
928 return pImp->pSaveOpt->IsSaveWorkingSet();
931 void SvtSaveOptions::SetSaveDocView( sal_Bool b )
933 pImp->pSaveOpt->SetSaveDocView( b );
936 sal_Bool SvtSaveOptions::IsSaveDocView() const
938 return pImp->pSaveOpt->IsSaveDocView();
941 void SvtSaveOptions::SetSaveRelINet( sal_Bool b )
943 pImp->pSaveOpt->SetSaveRelINet( b );
946 sal_Bool SvtSaveOptions::IsSaveRelINet() const
948 return pImp->pSaveOpt->IsSaveRelINet();
951 void SvtSaveOptions::SetSaveRelFSys( sal_Bool b )
953 pImp->pSaveOpt->SetSaveRelFSys( b );
956 sal_Bool SvtSaveOptions::IsSaveRelFSys() const
958 return pImp->pSaveOpt->IsSaveRelFSys();
961 sal_Bool SvtSaveOptions::IsSaveUnpacked() const
963 return pImp->pSaveOpt->IsSaveUnpacked();
966 void SvtSaveOptions::SetLoadUserSettings(sal_Bool b)
968 pImp->pLoadOpt->SetLoadUserSettings(b);
971 sal_Bool SvtSaveOptions::IsLoadUserSettings() const
973 return pImp->pLoadOpt->IsLoadUserSettings();
976 void SvtSaveOptions::SetPrettyPrinting( sal_Bool _bEnable )
978 pImp->pSaveOpt->EnablePrettyPrinting( _bEnable );
981 sal_Bool SvtSaveOptions::IsPrettyPrinting() const
983 return pImp->pSaveOpt->IsPrettyPrintingEnabled();
986 void SvtSaveOptions::SetWarnAlienFormat( sal_Bool _bEnable )
988 pImp->pSaveOpt->SetWarnAlienFormat( _bEnable );
991 sal_Bool SvtSaveOptions::IsWarnAlienFormat() const
993 return pImp->pSaveOpt->IsWarnAlienFormat();
996 void SvtSaveOptions::SetLoadDocumentPrinter( sal_Bool _bEnable )
998 pImp->pSaveOpt->SetLoadDocPrinter( _bEnable );
1001 sal_Bool SvtSaveOptions::IsLoadDocumentPrinter() const
1003 return pImp->pSaveOpt->IsLoadDocPrinter();
1006 void SvtSaveOptions::SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion eVersion )
1008 pImp->pSaveOpt->SetODFDefaultVersion( eVersion );
1011 SvtSaveOptions::ODFDefaultVersion SvtSaveOptions::GetODFDefaultVersion() const
1013 return pImp->pSaveOpt->GetODFDefaultVersion();
1016 sal_Bool SvtSaveOptions::IsUseSHA1InODF12() const
1018 return pImp->pSaveOpt->IsUseSHA1InODF12();
1021 sal_Bool SvtSaveOptions::IsUseBlowfishInODF12() const
1023 return pImp->pSaveOpt->IsUseBlowfishInODF12();
1026 sal_Bool SvtSaveOptions::IsReadOnly( SvtSaveOptions::EOption eOption ) const
1028 return pImp->pSaveOpt->IsReadOnly(eOption);
1031 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */