xref: /aoo42x/main/cui/source/options/optsave.cxx (revision 972a6c96)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_cui.hxx"
26 
27 // include ---------------------------------------------------------------
28 #include <tools/shl.hxx>
29 #include <svl/eitem.hxx>
30 #include <svl/intitem.hxx>
31 #define _SVX_OPTSAVE_CXX
32 
33 #include "optsave.hrc"
34 #include <cuires.hrc>
35 
36 #include "optsave.hxx"
37 #include <dialmgr.hxx>
38 #include <comphelper/processfactory.hxx>
39 #include <comphelper/sequenceasvector.hxx>
40 #include <comphelper/sequenceashashmap.hxx>
41 #include <unotools/moduleoptions.hxx>
42 #include <unotools/saveopt.hxx>
43 #include <comphelper/sequenceasvector.hxx>
44 #include <comphelper/sequenceashashmap.hxx>
45 #include <com/sun/star/container/XContainerQuery.hpp>
46 #include <com/sun/star/container/XEnumeration.hpp>
47 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
48 #include <com/sun/star/container/XNameContainer.hpp>
49 #include <com/sun/star/container/XContainerQuery.hpp>
50 #include <com/sun/star/container/XEnumeration.hpp>
51 #include <com/sun/star/beans/PropertyValue.hpp>
52 #include <com/sun/star/util/XFlushable.hpp>
53 #include <sfx2/docfilt.hxx>
54 #include <svtools/stdctrl.hxx>
55 #include <vcl/fixed.hxx>
56 #include <vcl/msgbox.hxx>
57 #include <unotools/configitem.hxx>
58 #include <unotools/optionsdlg.hxx>
59 
60 #include <vcl/msgbox.hxx>
61 
62 using namespace com::sun::star::uno;
63 using namespace com::sun::star::util;
64 using namespace com::sun::star::lang;
65 using namespace com::sun::star::beans;
66 using namespace com::sun::star::container;
67 using namespace comphelper;
68 using rtl::OUString;
69 
70 #define C2U(cChar)                  OUString::createFromAscii(cChar)
71 #define C2S(cChar)                  String( RTL_CONSTASCII_STRINGPARAM(cChar) )
72 #define CFG_PAGE_AND_GROUP          C2S("General"), C2S("LoadSave")
73 // !! you have to update these index, if you changed the list of the child windows !!
74 #define WININDEX_AUTOSAVE           ((sal_uInt16)6)
75 #define WININDEX_SAVEURL_RELFSYS    ((sal_uInt16)9)
76 
77 // ----------------------------------------------------------------------
78 #ifdef FILTER_WARNING_ENABLED
79 class SvxAlienFilterWarningConfig_Impl : public utl::ConfigItem
80 {
81     sal_Bool bWarning;
82     com::sun::star::uno::Sequence< OUString > aPropNames;
83 
84 	public:
85         SvxAlienFilterWarningConfig_Impl();
86         ~SvxAlienFilterWarningConfig_Impl();
87 
88 	virtual void			Commit();
89 
ResetWarning()90     void                    ResetWarning()
91                             {
92                                 if(bWarning)
93                                 {
94                                     bWarning = sal_False;
95                                     ConfigItem::SetModified();
96                                 }
97 
98                             }
IsWarning() const99     sal_Bool                IsWarning()const{return bWarning;}
100 };
101 // ----------------------------------------------------------------------
SvxAlienFilterWarningConfig_Impl()102 SvxAlienFilterWarningConfig_Impl::SvxAlienFilterWarningConfig_Impl() :
103     ConfigItem(C2U("TypeDetection.Misc/Defaults"),
104         CONFIG_MODE_IMMEDIATE_UPDATE),
105     aPropNames(1),
106     bWarning(sal_True)
107 {
108     aPropNames.getArray()[0] = C2U("ShowAlienFilterWarning");
109     Sequence<Any> aValues = GetProperties(aPropNames);
110 	const Any* pValues = aValues.getConstArray();
111 	DBG_ASSERT(aValues.getLength() == aPropNames.getLength(), "GetProperties failed");
112     if(aValues.getLength() == aPropNames.getLength() &&
113         pValues[0].hasValue() &&
114             pValues[0].getValueType() == ::getBooleanCppuType())
115         bWarning = *(sal_Bool*)pValues[0].getValue();
116 }
117 // ----------------------------------------------------------------------
~SvxAlienFilterWarningConfig_Impl()118 SvxAlienFilterWarningConfig_Impl::~SvxAlienFilterWarningConfig_Impl()
119 {
120     if(IsModified())
121         Commit();
122 }
123 // ----------------------------------------------------------------------
Commit()124 void SvxAlienFilterWarningConfig_Impl::Commit()
125 {
126 	Sequence<Any> aValues(aPropNames.getLength());
127 	Any* pValues = aValues.getArray();
128     pValues[0].setValue(&bWarning, ::getBooleanCppuType());
129 	PutProperties(aPropNames, aValues);
130 }
131 #endif // FILTER_WARNING_ENABLED
132 // ----------------------------------------------------------------------
133 // ----------------------------------------------------------------------
134 
135 struct SvxSaveTabPage_Impl
136 {
137     Reference< XNameContainer > xFact;
138     Sequence< OUString >        aFilterArr[APP_COUNT];
139     Sequence< sal_Bool >        aAlienArr[APP_COUNT];
140     Sequence< sal_Bool >        aODFArr[APP_COUNT];
141     Sequence< OUString >        aUIFilterArr[APP_COUNT];
142     OUString                    aDefaultArr[APP_COUNT];
143     sal_Bool                    aDefaultReadonlyArr[APP_COUNT];
144     sal_Bool                    bInitialized;
145 
146     SvxSaveTabPage_Impl();
147 	~SvxSaveTabPage_Impl();
148 };
149 
SvxSaveTabPage_Impl()150 SvxSaveTabPage_Impl::SvxSaveTabPage_Impl() : bInitialized( sal_False )
151 {
152 }
153 
~SvxSaveTabPage_Impl()154 SvxSaveTabPage_Impl::~SvxSaveTabPage_Impl()
155 {
156 }
157 
158 // class SvxSaveTabPage --------------------------------------------------
159 
SfxSaveTabPage(Window * pParent,const SfxItemSet & rCoreSet)160 SfxSaveTabPage::SfxSaveTabPage( Window* pParent, const SfxItemSet& rCoreSet ) :
161 
162 	SfxTabPage( pParent, CUI_RES( RID_SFXPAGE_SAVE ), rCoreSet ),
163 
164     aLoadFL             ( this, CUI_RES( LB_LOAD ) ),
165     aLoadUserSettingsCB ( this, CUI_RES( CB_LOAD_SETTINGS ) ),
166     aLoadDocPrinterCB   ( this, CUI_RES( CB_LOAD_DOCPRINTER ) ),
167 
168     aSaveFL             ( this, CUI_RES( GB_SAVE ) ),
169     aDocInfoCB          ( this, CUI_RES( BTN_DOCINFO ) ),
170     aBackupFI           ( this, CUI_RES( FI_BACKUP ) ),
171     aBackupCB           ( this, CUI_RES( BTN_BACKUP ) ),
172     aAutoSaveCB         ( this, CUI_RES( BTN_AUTOSAVE ) ),
173 	aAutoSaveEdit		( this,	CUI_RES( ED_AUTOSAVE ) ),
174     aMinuteFT           ( this, CUI_RES( FT_MINUTE ) ),
175     aRelativeFsysCB     ( this, CUI_RES( BTN_RELATIVE_FSYS ) ),
176     aRelativeInetCB     ( this, CUI_RES( BTN_RELATIVE_INET ) ),
177 
178     aDefaultFormatFL    ( this, CUI_RES( FL_FILTER ) ),
179     aODFVersionFT       ( this, CUI_RES( FT_ODF_VERSION ) ),
180     aODFVersionLB       ( this, CUI_RES( LB_ODF_VERSION ) ),
181     aODFEncryptionCB    ( this, CUI_RES( BTN_ODFENCRYPTION ) ),
182     aSizeOptimizationCB ( this, CUI_RES( BTN_NOPRETTYPRINTING ) ),
183     aWarnAlienFormatCB  ( this, CUI_RES( BTN_WARNALIENFORMAT ) ),
184     aDocTypeFT          ( this, CUI_RES( FT_APP ) ),
185     aDocTypeLB          ( this, CUI_RES( LB_APP ) ),
186     aSaveAsFT           ( this, CUI_RES( FT_FILTER ) ),
187     aSaveAsFI           ( this, CUI_RES( FI_FILTER ) ),
188     aSaveAsLB           ( this, CUI_RES( LB_FILTER ) ),
189     aODFWarningFI       ( this, CUI_RES( FI_ODF_WARNING ) ),
190     aODFWarningFT       ( this, CUI_RES( FT_WARN ) ),
191 
192     pImpl               ( new SvxSaveTabPage_Impl )
193 
194 {
195     sal_Bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
196     aODFWarningFI.SetImage(
197         Image( CUI_RES( bHighContrast ? IMG_ODF_WARNING_HC : IMG_ODF_WARNING ) ) );
198 
199     FreeResource();
200 
201     Link aLink = LINK( this, SfxSaveTabPage, AutoClickHdl_Impl );
202     aAutoSaveCB.SetClickHdl( aLink );
203 	aAutoSaveEdit.SetMaxTextLen( 2 );
204 
205     SvtModuleOptions aModuleOpt;
206     if ( !aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SMATH ) )
207     {
208         aSaveAsLB.RemoveEntry(aSaveAsLB.GetEntryPos( (void*) APP_MATH ));
209         aDocTypeLB.RemoveEntry(aDocTypeLB.GetEntryPos( (void*) APP_MATH ));
210     }
211     else
212     {
213         pImpl->aDefaultArr[APP_MATH] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_MATH);
214         pImpl->aDefaultReadonlyArr[APP_MATH] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::E_MATH);
215     }
216 
217     if ( !aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SDRAW ) )
218     {
219         aSaveAsLB.RemoveEntry(aSaveAsLB.GetEntryPos( (void*) APP_DRAW ));
220         aDocTypeLB.RemoveEntry(aDocTypeLB.GetEntryPos( (void*) APP_DRAW ));
221     }
222     else
223     {
224         pImpl->aDefaultArr[APP_DRAW] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_DRAW);
225         pImpl->aDefaultReadonlyArr[APP_DRAW] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::E_DRAW);
226     }
227 
228     if ( !aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
229     {
230         aSaveAsLB.RemoveEntry(aSaveAsLB.GetEntryPos( (void*) APP_IMPRESS ));
231         aDocTypeLB.RemoveEntry(aDocTypeLB.GetEntryPos( (void*) APP_IMPRESS ));
232     }
233     else
234     {
235         pImpl->aDefaultArr[APP_IMPRESS] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_IMPRESS);
236         pImpl->aDefaultReadonlyArr[APP_IMPRESS] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::E_IMPRESS);
237     }
238 
239     if ( !aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
240     {
241         aSaveAsLB.RemoveEntry(aSaveAsLB.GetEntryPos( (void*) APP_CALC ));
242         aDocTypeLB.RemoveEntry(aDocTypeLB.GetEntryPos( (void*) APP_CALC ));
243     }
244     else
245     {
246         pImpl->aDefaultArr[APP_CALC] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_CALC);
247         pImpl->aDefaultReadonlyArr[APP_CALC] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::E_CALC);
248     }
249 
250     if ( !aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
251     {
252         aSaveAsLB.RemoveEntry(aSaveAsLB.GetEntryPos( (void*) APP_WRITER ));
253         aSaveAsLB.RemoveEntry(aSaveAsLB.GetEntryPos( (void*) APP_WRITER_WEB ));
254         aSaveAsLB.RemoveEntry(aSaveAsLB.GetEntryPos( (void*) APP_WRITER_GLOBAL ));
255         aDocTypeLB.RemoveEntry(aDocTypeLB.GetEntryPos( (void*) APP_WRITER ));
256         aDocTypeLB.RemoveEntry(aDocTypeLB.GetEntryPos( (void*) APP_WRITER_WEB ));
257         aDocTypeLB.RemoveEntry(aDocTypeLB.GetEntryPos( (void*) APP_WRITER_GLOBAL ));
258     }
259     else
260     {
261         pImpl->aDefaultArr[APP_WRITER] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_WRITER);
262         pImpl->aDefaultArr[APP_WRITER_WEB] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_WRITERWEB);
263         pImpl->aDefaultArr[APP_WRITER_GLOBAL] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_WRITERGLOBAL);
264         pImpl->aDefaultReadonlyArr[APP_WRITER] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::E_WRITER);
265         pImpl->aDefaultReadonlyArr[APP_WRITER_WEB] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::E_WRITERWEB);
266         pImpl->aDefaultReadonlyArr[APP_WRITER_GLOBAL] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::E_WRITERGLOBAL);
267     }
268 
269     aLink = LINK( this, SfxSaveTabPage, ODFVersionHdl_Impl );
270     aODFVersionLB.SetSelectHdl( aLink );
271     aLink = LINK( this, SfxSaveTabPage, FilterHdl_Impl );
272     aDocTypeLB.SetSelectHdl( aLink );
273     aSaveAsLB.SetSelectHdl( aLink );
274 
275     DetectHiddenControls();
276 }
277 
278 // -----------------------------------------------------------------------
279 
~SfxSaveTabPage()280 SfxSaveTabPage::~SfxSaveTabPage()
281 {
282     delete pImpl;
283 }
284 
285 // -----------------------------------------------------------------------
286 
Create(Window * pParent,const SfxItemSet & rAttrSet)287 SfxTabPage*	SfxSaveTabPage::Create( Window* pParent,
288 									const SfxItemSet& rAttrSet )
289 {
290 	return ( new SfxSaveTabPage( pParent, rAttrSet ) );
291 }
292 
293 // -----------------------------------------------------------------------
AcceptFilter(sal_uInt16 nPos)294 bool SfxSaveTabPage::AcceptFilter( sal_uInt16 nPos )
295 {
296     const OUString* pFilters = pImpl->aFilterArr[nPos].getConstArray();
297     sal_Bool bAlien = sal_False, bODF = sal_False;
298     OUString* pUIFilters = pImpl->aUIFilterArr[nPos].getArray();
299     OUString sUIName;
300     for(int nFilter = 0; nFilter < pImpl->aFilterArr[nPos].getLength(); nFilter++)
301     {
302         if( pImpl->aDefaultArr[nPos] == pFilters[nFilter] )
303         {
304             bAlien = pImpl->aAlienArr[nPos][nFilter];
305             bODF = pImpl->aODFArr[nPos][nFilter];
306             sUIName = pUIFilters[nFilter];;
307             break;
308         }
309     }
310     bool bSet = true;
311     return bSet;
312 }
313 // -----------------------------------------------------------------------
DetectHiddenControls()314 void SfxSaveTabPage::DetectHiddenControls()
315 {
316     long nDelta = 0;
317     // the index of the first child window which perhaps have to move upwards
318     sal_uInt16 nWinIndex = WININDEX_SAVEURL_RELFSYS;
319     SvtOptionsDialogOptions aOptionsDlgOpt;
320 
321     if ( aOptionsDlgOpt.IsOptionHidden( C2S("Backup"), CFG_PAGE_AND_GROUP ) )
322     {
323         // hide controls of "Backup"
324         aBackupFI.Hide();
325         aBackupCB.Hide();
326         // the other controls have to move upwards the height of checkbox + space
327         nDelta = aAutoSaveCB.GetPosPixel().Y() - aBackupCB.GetPosPixel().Y();
328     }
329 
330     if ( aOptionsDlgOpt.IsOptionHidden( C2S("AutoSave"), CFG_PAGE_AND_GROUP ) )
331     {
332         // hide controls of "AutoSave"
333         aAutoSaveCB.Hide();
334         aAutoSaveEdit.Hide();
335         aMinuteFT.Hide();
336         // the other controls have to move upwards the height of checkbox + space
337         nDelta += aRelativeFsysCB.GetPosPixel().Y() - aAutoSaveCB.GetPosPixel().Y();
338     }
339     else if ( nDelta > 0 )
340         // the "AutoSave" controls have to move upwards too
341         nWinIndex = WININDEX_AUTOSAVE;
342 
343     if ( nDelta > 0 )
344     {
345         sal_uInt16 i, nChildCount = GetChildCount();
346         for ( i = nWinIndex; i < nChildCount; ++i )
347         {
348             Window* pWin = GetChild(i);
349             Point aPos = pWin->GetPosPixel();
350             aPos.Y() -= nDelta;
351             pWin->SetPosPixel( aPos );
352         }
353     }
354 }
355 // -----------------------------------------------------------------------
FillItemSet(SfxItemSet & rSet)356 sal_Bool SfxSaveTabPage::FillItemSet( SfxItemSet& rSet )
357 {
358     sal_Bool bModified = sal_False;
359     SvtSaveOptions aSaveOpt;
360     if(aLoadUserSettingsCB.IsChecked() != aLoadUserSettingsCB.GetSavedValue())
361     {
362         aSaveOpt.SetLoadUserSettings(aLoadUserSettingsCB.IsChecked());
363     }
364 
365     if ( aLoadDocPrinterCB.IsChecked() != aLoadDocPrinterCB.GetSavedValue() )
366         aSaveOpt.SetLoadDocumentPrinter( aLoadDocPrinterCB.IsChecked() );
367 
368     if ( aODFVersionLB.GetSelectEntryPos() != aODFVersionLB.GetSavedValue() )
369     {
370         long nVersion = long( aODFVersionLB.GetEntryData( aODFVersionLB.GetSelectEntryPos() ) );
371         aSaveOpt.SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion( nVersion ) );
372     }
373 
374     if ( aDocInfoCB.IsChecked() != aDocInfoCB.GetSavedValue() )
375 	{
376 		rSet.Put( SfxBoolItem( GetWhich( SID_ATTR_DOCINFO ),
377                                aDocInfoCB.IsChecked() ) );
378 		bModified |= sal_True;
379 	}
380 
381     if ( aBackupCB.IsEnabled() && aBackupCB.IsChecked() != aBackupCB.GetSavedValue() )
382 	{
383 		rSet.Put( SfxBoolItem( GetWhich( SID_ATTR_BACKUP ),
384                                aBackupCB.IsChecked() ) );
385 		bModified |= sal_True;
386 	}
387 
388     if ( aODFEncryptionCB.IsChecked() != aODFEncryptionCB.GetSavedValue() )
389 	{
390         rSet.Put( SfxBoolItem( GetWhich( SID_ATTR_ODFENCRYPTION ), aODFEncryptionCB.IsChecked() ) );
391 		bModified |= sal_True;
392 	}
393 
394     if ( aSizeOptimizationCB.IsChecked() != aSizeOptimizationCB.GetSavedValue() )
395 	{
396         rSet.Put( SfxBoolItem( GetWhich( SID_ATTR_PRETTYPRINTING ), !aSizeOptimizationCB.IsChecked() ) );
397 		bModified |= sal_True;
398 	}
399 
400     if ( aAutoSaveCB.IsChecked() != aAutoSaveCB.GetSavedValue() )
401 	{
402 		rSet.Put( SfxBoolItem( GetWhich( SID_ATTR_AUTOSAVE ),
403                                aAutoSaveCB.IsChecked() ) );
404 		bModified |= sal_True;
405 	}
406     if ( aWarnAlienFormatCB.IsChecked() != aWarnAlienFormatCB.GetSavedValue() )
407 	{
408         rSet.Put( SfxBoolItem( GetWhich( SID_ATTR_WARNALIENFORMAT ),
409                                aWarnAlienFormatCB.IsChecked() ) );
410 		bModified |= sal_True;
411 	}
412 
413 	if ( aAutoSaveEdit.GetText() != aAutoSaveEdit.GetSavedValue() )
414 	{
415 		rSet.Put( SfxUInt16Item( GetWhich( SID_ATTR_AUTOSAVEMINUTE ),
416 								 (sal_uInt16)aAutoSaveEdit.GetValue() ) );
417 		bModified |= sal_True;
418 	}
419 	// relativ speichern
420     if ( aRelativeFsysCB.IsChecked() != aRelativeFsysCB.GetSavedValue() )
421 	{
422 		rSet.Put( SfxBoolItem( GetWhich( SID_SAVEREL_FSYS ),
423                                aRelativeFsysCB.IsChecked() ) );
424 		bModified |= sal_True;
425 	}
426 
427     if ( aRelativeInetCB.IsChecked() != aRelativeInetCB.GetSavedValue() )
428 	{
429 		rSet.Put( SfxBoolItem( GetWhich( SID_SAVEREL_INET ),
430                                aRelativeInetCB.IsChecked() ) );
431 		bModified |= sal_True;
432 	}
433 
434     SvtModuleOptions aModuleOpt;
435     if(pImpl->aDefaultArr[APP_MATH].getLength() &&
436             pImpl->aDefaultArr[APP_MATH] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_MATH) &&
437             AcceptFilter( APP_MATH ))
438         aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::E_MATH, pImpl->aDefaultArr[APP_MATH]);
439 
440     if( pImpl->aDefaultArr[APP_DRAW].getLength() &&
441             pImpl->aDefaultArr[APP_DRAW] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_DRAW) &&
442             AcceptFilter( APP_DRAW ))
443             aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::E_DRAW, pImpl->aDefaultArr[APP_DRAW]);
444 
445     if(pImpl->aDefaultArr[APP_IMPRESS].getLength() &&
446             pImpl->aDefaultArr[APP_IMPRESS] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_IMPRESS)&&
447             AcceptFilter( APP_IMPRESS ))
448         aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::E_IMPRESS, pImpl->aDefaultArr[APP_IMPRESS]);
449 
450     if(pImpl->aDefaultArr[APP_CALC].getLength() &&
451             pImpl->aDefaultArr[APP_CALC] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_CALC)&&
452             AcceptFilter( APP_CALC ))
453         aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::E_CALC, pImpl->aDefaultArr[APP_CALC]);
454 
455     if(pImpl->aDefaultArr[APP_WRITER].getLength() &&
456             pImpl->aDefaultArr[APP_WRITER] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_WRITER)&&
457             AcceptFilter( APP_WRITER))
458         aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::E_WRITER, pImpl->aDefaultArr[APP_WRITER]);
459 
460     if(pImpl->aDefaultArr[APP_WRITER_WEB].getLength() &&
461             pImpl->aDefaultArr[APP_WRITER_WEB] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_WRITERWEB)&&
462             AcceptFilter( APP_WRITER_WEB ))
463         aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::E_WRITERWEB, pImpl->aDefaultArr[APP_WRITER_WEB]);
464 
465 	if(pImpl->aDefaultArr[APP_WRITER_GLOBAL].getLength() &&
466             pImpl->aDefaultArr[APP_WRITER_GLOBAL] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_WRITERGLOBAL)&&
467             AcceptFilter( APP_WRITER_GLOBAL ))
468         aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::E_WRITERGLOBAL, pImpl->aDefaultArr[APP_WRITER_GLOBAL]);
469 
470 	return bModified;
471 }
472 
473 // -----------------------------------------------------------------------
474 
isODFFormat(OUString sFilter)475 sal_Bool isODFFormat( OUString sFilter )
476 {
477     static const char* aODFFormats[] =
478     {
479         "writer8",
480         "writer8_template",
481         "writerglobal8",
482         "writerglobal8_writer",
483         "calc8",
484         "calc8_template",
485         "draw8",
486         "draw8_template",
487         "impress8",
488         "impress8_template",
489         "impress8_draw",
490         "chart8",
491         "math8",
492         NULL
493     };
494 
495     sal_Bool bRet = sal_False;
496     int i = 0;
497     while ( aODFFormats[i] != NULL )
498     {
499         if ( sFilter.equalsAscii( aODFFormats[i++] ) )
500         {
501             bRet = sal_True;
502             break;
503         }
504     }
505 
506     return bRet;
507 }
508 
Reset(const SfxItemSet &)509 void SfxSaveTabPage::Reset( const SfxItemSet& )
510 {
511     SvtSaveOptions aSaveOpt;
512     aLoadUserSettingsCB.Check(aSaveOpt.IsLoadUserSettings());
513     aLoadUserSettingsCB.SaveValue();
514     aLoadDocPrinterCB.Check( aSaveOpt.IsLoadDocumentPrinter() );
515     aLoadDocPrinterCB.SaveValue();
516 
517     if ( !pImpl->bInitialized )
518     {
519         try
520         {
521             Reference< XMultiServiceFactory > xMSF = comphelper::getProcessServiceFactory();
522             pImpl->xFact = Reference<XNameContainer>(
523                     xMSF->createInstance(C2U("com.sun.star.document.FilterFactory")), UNO_QUERY);
524 
525             DBG_ASSERT(pImpl->xFact.is(), "service com.sun.star.document.FilterFactory unavailable");
526             Reference< XContainerQuery > xQuery(pImpl->xFact, UNO_QUERY);
527             if(xQuery.is())
528             {
529                 for(sal_uInt16 n = 0; n < aDocTypeLB.GetEntryCount(); n++)
530                 {
531                     long nData = (long) aDocTypeLB.GetEntryData(n);
532                     OUString sCommand;
533                     sCommand = C2U("matchByDocumentService=%1:iflags=");
534                     sCommand += String::CreateFromInt32(SFX_FILTER_IMPORT|SFX_FILTER_EXPORT);
535                     sCommand += C2U(":eflags=");
536                     sCommand += String::CreateFromInt32(SFX_FILTER_NOTINFILEDLG);
537                     sCommand += C2U(":default_first");
538                     String sReplace;
539                     switch(nData)
540                     {
541                         case  APP_WRITER     	: sReplace = C2U("com.sun.star.text.TextDocument");  break;
542                         case  APP_WRITER_WEB 	: sReplace = C2U("com.sun.star.text.WebDocument");   break;
543                         case  APP_WRITER_GLOBAL : sReplace = C2U("com.sun.star.text.GlobalDocument");   break;
544                         case  APP_CALC       	: sReplace = C2U("com.sun.star.sheet.SpreadsheetDocument");break;
545                         case  APP_IMPRESS    	: sReplace = C2U("com.sun.star.presentation.PresentationDocument");break;
546                         case  APP_DRAW       	: sReplace = C2U("com.sun.star.drawing.DrawingDocument");break;
547                         case  APP_MATH       	: sReplace = C2U("com.sun.star.formula.FormulaProperties");break;
548                         default: DBG_ERROR("illegal user data");
549                     }
550                     String sTmp(sCommand);
551                     sTmp.SearchAndReplaceAscii("%1", sReplace);
552                     sCommand = sTmp;
553                     Reference< XEnumeration > xList = xQuery->createSubSetEnumerationByQuery(sCommand);
554                     SequenceAsVector< OUString > lList;
555                     SequenceAsVector< sal_Bool > lAlienList;
556                     SequenceAsVector< sal_Bool > lODFList;
557                     while(xList->hasMoreElements())
558                     {
559                         SequenceAsHashMap aFilter(xList->nextElement());
560                         OUString sFilter = aFilter.getUnpackedValueOrDefault(OUString::createFromAscii("Name"),OUString());
561                         if (sFilter.getLength())
562                         {
563                             sal_Int32 nFlags = aFilter.getUnpackedValueOrDefault(OUString::createFromAscii("Flags"),sal_Int32());
564                             lList.push_back(sFilter);
565                             lAlienList.push_back(0 != (nFlags & SFX_FILTER_ALIEN));
566                             lODFList.push_back( isODFFormat( sFilter ) );
567                         }
568                     }
569                     pImpl->aFilterArr[nData] = lList.getAsConstList();
570                     pImpl->aAlienArr[nData] = lAlienList.getAsConstList();
571                     pImpl->aODFArr[nData] = lODFList.getAsConstList();
572                 }
573             }
574             aDocTypeLB.SelectEntryPos(0);
575             FilterHdl_Impl(&aDocTypeLB);
576         }
577         catch(Exception& e)
578         {
579             (void) e;
580             DBG_ERROR(
581                 rtl::OUStringToOString(
582                     (rtl::OUString(
583                         RTL_CONSTASCII_USTRINGPARAM(
584                             "exception in FilterFactory access: ")) +
585                      e.Message),
586                     RTL_TEXTENCODING_UTF8).
587                 getStr());
588         }
589 
590 		pImpl->bInitialized = sal_True;
591     }
592 
593     aDocInfoCB.Check(aSaveOpt.IsDocInfoSave());
594 //    aDocInfoCB.Enable(!aSaveOpt.IsReadOnly(SvtSaveOptions::E_DOCINFSAVE));
595 
596     aBackupCB.Check(aSaveOpt.IsBackup());
597     sal_Bool bBackupRO = aSaveOpt.IsReadOnly(SvtSaveOptions::E_BACKUP);
598     aBackupCB.Enable(!bBackupRO);
599     aBackupFI.Show(bBackupRO);
600 
601     aAutoSaveCB.Check(aSaveOpt.IsAutoSave());
602     aWarnAlienFormatCB.Check(aSaveOpt.IsWarnAlienFormat());
603     aWarnAlienFormatCB.Enable(!aSaveOpt.IsReadOnly(SvtSaveOptions::E_WARNALIENFORMAT));
604 //    aAutoSaveCB.Enable(!aSaveOpt.IsReadOnly(SvtSaveOptions::E_AUTOSAVE));
605 
606     // ODF encryption
607     aODFEncryptionCB.Check( !aSaveOpt.IsUseSHA1InODF12());
608 
609 	// the pretty printing
610     aSizeOptimizationCB.Check( !aSaveOpt.IsPrettyPrinting());
611 //    aSizeOptimizationCB.Enable(!aSaveOpt.IsReadOnly(SvtSaveOptions::E_DOPRETTYPRINTING ));
612 
613 
614     aAutoSaveEdit.SetValue( aSaveOpt.GetAutoSaveTime() );
615 //    aAutoSaveEdit.Enable(!aSaveOpt.IsReadOnly(SvtSaveOptions::E_AUTOSAVETIME));
616 
617     // relativ speichern
618     aRelativeFsysCB.Check( aSaveOpt.IsSaveRelFSys() );
619 //    aRelativeFsysCB.Enable(!aSaveOpt.IsReadOnly(SvtSaveOptions::E_SAVERELFSYS));
620 
621     aRelativeInetCB.Check( aSaveOpt.IsSaveRelINet() );
622 //    aRelativeInetCB.Enable(!aSaveOpt.IsReadOnly(SvtSaveOptions::E_SAVERELINET));
623 
624     void* pDefaultVersion = (void*)long( aSaveOpt.GetODFDefaultVersion() );
625     aODFVersionLB.SelectEntryPos( aODFVersionLB.GetEntryPos( pDefaultVersion ) );
626 
627     AutoClickHdl_Impl( &aAutoSaveCB );
628     ODFVersionHdl_Impl( &aODFVersionLB );
629 
630     aDocInfoCB.SaveValue();
631     aBackupCB.SaveValue();
632     aWarnAlienFormatCB.SaveValue();
633     aODFEncryptionCB.SaveValue();
634     aSizeOptimizationCB.SaveValue();
635     aAutoSaveCB.SaveValue();
636 	aAutoSaveEdit.SaveValue();
637 //	aAutoSavePromptBtn.SaveValue();
638 
639     aRelativeFsysCB.SaveValue();
640     aRelativeInetCB.SaveValue();
641     aODFVersionLB.SaveValue();
642 }
643 
644 // -----------------------------------------------------------------------
645 
IMPL_LINK(SfxSaveTabPage,AutoClickHdl_Impl,CheckBox *,pBox)646 IMPL_LINK( SfxSaveTabPage, AutoClickHdl_Impl, CheckBox *, pBox )
647 {
648     if ( pBox == &aAutoSaveCB )
649 	{
650         if ( aAutoSaveCB.IsChecked() )
651 		{
652 			aAutoSaveEdit.Enable();
653             aMinuteFT.Enable();
654 //			aAutoSavePromptBtn.Enable();
655 			aAutoSaveEdit.GrabFocus();
656 		}
657 		else
658 		{
659 			aAutoSaveEdit.Disable();
660             aMinuteFT.Disable();
661 //			aAutoSavePromptBtn.Disable();
662 		}
663 	}
664 	return 0;
665 }
666 /* -----------------------------05.04.01 13:10--------------------------------
667 
668  ---------------------------------------------------------------------------*/
lcl_ExtracUIName(const Sequence<PropertyValue> & rProperties)669 OUString lcl_ExtracUIName(const Sequence<PropertyValue> &rProperties)
670 {
671     OUString sName;
672     const PropertyValue* pPropVal = rProperties.getConstArray();
673     const PropertyValue* const pEnd = pPropVal + rProperties.getLength();
674     for( ; pPropVal != pEnd; pPropVal++ )
675     {
676         const OUString &rName = pPropVal->Name;
677         if( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "UIName" ) ) )
678         {
679             OUString sUIName;
680             if ( ( pPropVal->Value >>= sUIName ) && sUIName.getLength() )
681                 return sUIName;
682         }
683         else if( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Name" ) ) )
684         {
685             pPropVal->Value >>= sName;
686         }
687     }
688 
689     OSL_ENSURE( false, "Filter without UIName!" );
690 
691     return sName;
692 }
693 /* -----------------------------05.04.01 13:37--------------------------------
694 
695  ---------------------------------------------------------------------------*/
IMPL_LINK(SfxSaveTabPage,FilterHdl_Impl,ListBox *,pBox)696 IMPL_LINK( SfxSaveTabPage, FilterHdl_Impl, ListBox *, pBox )
697 {
698     sal_uInt16 nCurPos = aDocTypeLB.GetSelectEntryPos();
699 
700     long nData = -1;
701     if(nCurPos < APP_COUNT)
702         nData = (long) aDocTypeLB.GetEntryData(nCurPos);
703 
704     if ( nData >= 0 && nData < APP_COUNT )
705     {
706         if(&aDocTypeLB == pBox)
707         {
708             aSaveAsLB.Clear();
709             const OUString* pFilters = pImpl->aFilterArr[nData].getConstArray();
710             if(!pImpl->aUIFilterArr[nData].getLength())
711             {
712                 pImpl->aUIFilterArr[nData].realloc(pImpl->aFilterArr[nData].getLength());
713                 OUString* pUIFilters = pImpl->aUIFilterArr[nData].getArray();
714                 for(int nFilter = 0; nFilter < pImpl->aFilterArr[nData].getLength(); nFilter++)
715                 {
716                     Any aProps = pImpl->xFact->getByName(pFilters[nFilter]);
717                     Sequence<PropertyValue> aProperties;
718                     aProps >>= aProperties;
719                     pUIFilters[nFilter] = lcl_ExtracUIName(aProperties);
720                 }
721             }
722             const OUString* pUIFilters = pImpl->aUIFilterArr[nData].getConstArray();
723             OUString sSelect;
724             for(int i = 0; i < pImpl->aUIFilterArr[nData].getLength(); i++)
725             {
726                 sal_uInt16 nEntryPos = aSaveAsLB.InsertEntry(pUIFilters[i]);
727                 if ( pImpl->aODFArr[nData][i] )
728                     aSaveAsLB.SetEntryData( nEntryPos, (void*)pImpl );
729                 if(pFilters[i] == pImpl->aDefaultArr[nData])
730                     sSelect = pUIFilters[i];
731             }
732             if(sSelect.getLength())
733                 aSaveAsLB.SelectEntry(sSelect);
734             aSaveAsFI.Show(pImpl->aDefaultReadonlyArr[nData]);
735             aSaveAsFT.Enable(!pImpl->aDefaultReadonlyArr[nData]);
736             aSaveAsLB.Enable(!pImpl->aDefaultReadonlyArr[nData]);
737         }
738         else
739         {
740             OUString sSelect = pBox->GetSelectEntry();
741             const OUString* pFilters = pImpl->aFilterArr[nData].getConstArray();
742             OUString* pUIFilters = pImpl->aUIFilterArr[nData].getArray();
743             for(int i = 0; i < pImpl->aUIFilterArr[nData].getLength(); i++)
744                 if(pUIFilters[i] == sSelect)
745                 {
746                     sSelect = pFilters[i];
747                     break;
748                 }
749 
750             pImpl->aDefaultArr[nData] = sSelect;
751         }
752     }
753 
754     ODFVersionHdl_Impl( &aSaveAsLB );
755     return 0;
756 };
757 
IMPL_LINK(SfxSaveTabPage,ODFVersionHdl_Impl,ListBox *,EMPTYARG)758 IMPL_LINK( SfxSaveTabPage, ODFVersionHdl_Impl, ListBox *, EMPTYARG )
759 {
760     long nVersion = long( aODFVersionLB.GetEntryData( aODFVersionLB.GetSelectEntryPos() ) );
761     bool bShown = SvtSaveOptions::ODFDefaultVersion( nVersion ) != SvtSaveOptions::ODFVER_LATEST;
762     if ( bShown )
763     {
764         bool bHasODFFormat = false;
765         sal_uInt16 i = 0, nCount = aSaveAsLB.GetEntryCount();
766         for ( ; i < nCount; ++ i )
767         {
768             if ( aSaveAsLB.GetEntryData(i) != NULL )
769             {
770                 bHasODFFormat = true;
771                 break;
772             }
773         }
774 
775         bShown = !bHasODFFormat
776                 || ( aSaveAsLB.GetEntryData( aSaveAsLB.GetSelectEntryPos() ) != NULL );
777     }
778 
779     aODFWarningFI.Show( bShown );
780     aODFWarningFT.Show( bShown );
781 
782     return 0;
783 }
784 
785