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