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 <tools/shl.hxx>
21 : #include <svl/eitem.hxx>
22 : #include <svl/intitem.hxx>
23 : #define _SVX_OPTSAVE_CXX
24 :
25 : #include "optsave.hrc"
26 : #include <cuires.hrc>
27 :
28 : #include "optsave.hxx"
29 : #include <dialmgr.hxx>
30 : #include <comphelper/processfactory.hxx>
31 : #include <unotools/moduleoptions.hxx>
32 : #include <unotools/saveopt.hxx>
33 : #include <comphelper/sequenceasvector.hxx>
34 : #include <comphelper/sequenceashashmap.hxx>
35 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36 : #include <com/sun/star/container/XNameContainer.hpp>
37 : #include <com/sun/star/container/XContainerQuery.hpp>
38 : #include <com/sun/star/container/XEnumeration.hpp>
39 : #include <com/sun/star/beans/PropertyValue.hpp>
40 : #include <com/sun/star/util/XFlushable.hpp>
41 : #include <sfx2/docfilt.hxx>
42 : #include <svtools/stdctrl.hxx>
43 : #include <vcl/fixed.hxx>
44 : #include <unotools/configitem.hxx>
45 : #include <unotools/optionsdlg.hxx>
46 :
47 : #include <vcl/msgbox.hxx>
48 :
49 : using namespace com::sun::star::uno;
50 : using namespace com::sun::star::util;
51 : using namespace com::sun::star::lang;
52 : using namespace com::sun::star::beans;
53 : using namespace com::sun::star::container;
54 : using namespace comphelper;
55 :
56 : #define C2S(cChar) String( RTL_CONSTASCII_USTRINGPARAM(cChar) )
57 : #define CFG_PAGE_AND_GROUP C2S("General"), C2S("LoadSave")
58 : // !! you have to update these index, if you changed the list of the child windows !!
59 : #define WININDEX_AUTOSAVE ((sal_uInt16)6)
60 : #define WININDEX_SAVEURL_RELFSYS ((sal_uInt16)9)
61 :
62 : // ----------------------------------------------------------------------
63 :
64 : struct SvxSaveTabPage_Impl
65 : {
66 : Reference< XNameContainer > xFact;
67 : Sequence< OUString > aFilterArr[APP_COUNT];
68 : Sequence< sal_Bool > aAlienArr[APP_COUNT];
69 : Sequence< sal_Bool > aODFArr[APP_COUNT];
70 : Sequence< OUString > aUIFilterArr[APP_COUNT];
71 : OUString aDefaultArr[APP_COUNT];
72 : sal_Bool aDefaultReadonlyArr[APP_COUNT];
73 : sal_Bool bInitialized;
74 :
75 : SvxSaveTabPage_Impl();
76 : ~SvxSaveTabPage_Impl();
77 : };
78 :
79 0 : SvxSaveTabPage_Impl::SvxSaveTabPage_Impl() : bInitialized( sal_False )
80 : {
81 0 : }
82 :
83 0 : SvxSaveTabPage_Impl::~SvxSaveTabPage_Impl()
84 : {
85 0 : }
86 :
87 : // class SvxSaveTabPage --------------------------------------------------
88 :
89 0 : SfxSaveTabPage::SfxSaveTabPage( Window* pParent, const SfxItemSet& rCoreSet ) :
90 :
91 0 : SfxTabPage( pParent, CUI_RES( RID_SFXPAGE_SAVE ), rCoreSet ),
92 :
93 0 : aLoadFL ( this, CUI_RES( LB_LOAD ) ),
94 0 : aLoadUserSettingsCB ( this, CUI_RES( CB_LOAD_SETTINGS ) ),
95 0 : aLoadDocPrinterCB ( this, CUI_RES( CB_LOAD_DOCPRINTER ) ),
96 :
97 0 : aSaveFL ( this, CUI_RES( GB_SAVE ) ),
98 0 : aDocInfoCB ( this, CUI_RES( BTN_DOCINFO ) ),
99 0 : aBackupFI ( this, CUI_RES( FI_BACKUP ) ),
100 0 : aBackupCB ( this, CUI_RES( BTN_BACKUP ) ),
101 0 : aAutoSaveCB ( this, CUI_RES( BTN_AUTOSAVE ) ),
102 0 : aAutoSaveEdit ( this, CUI_RES( ED_AUTOSAVE ) ),
103 0 : aMinuteFT ( this, CUI_RES( FT_MINUTE ) ),
104 0 : aRelativeFsysCB ( this, CUI_RES( BTN_RELATIVE_FSYS ) ),
105 0 : aRelativeInetCB ( this, CUI_RES( BTN_RELATIVE_INET ) ),
106 :
107 0 : aDefaultFormatFL ( this, CUI_RES( FL_FILTER ) ),
108 0 : aODFVersionFT ( this, CUI_RES( FT_ODF_VERSION ) ),
109 0 : aODFVersionLB ( this, CUI_RES( LB_ODF_VERSION ) ),
110 0 : aSizeOptimizationCB ( this, CUI_RES( BTN_NOPRETTYPRINTING ) ),
111 0 : aWarnAlienFormatCB ( this, CUI_RES( BTN_WARNALIENFORMAT ) ),
112 0 : aDocTypeFT ( this, CUI_RES( FT_APP ) ),
113 0 : aDocTypeLB ( this, CUI_RES( LB_APP ) ),
114 0 : aSaveAsFT ( this, CUI_RES( FT_FILTER ) ),
115 0 : aSaveAsFI ( this, CUI_RES( FI_FILTER ) ),
116 0 : aSaveAsLB ( this, CUI_RES( LB_FILTER ) ),
117 0 : aODFWarningFI ( this, CUI_RES( FI_ODF_WARNING ) ),
118 0 : aODFWarningFT ( this, CUI_RES( FT_WARN ) ),
119 :
120 0 : pImpl ( new SvxSaveTabPage_Impl )
121 :
122 : {
123 0 : aODFWarningFI.SetImage( Image( CUI_RES( IMG_ODF_WARNING )));
124 :
125 0 : FreeResource();
126 :
127 0 : Link aLink = LINK( this, SfxSaveTabPage, AutoClickHdl_Impl );
128 0 : aAutoSaveCB.SetClickHdl( aLink );
129 0 : aAutoSaveEdit.SetMaxTextLen( 2 );
130 :
131 0 : SvtModuleOptions aModuleOpt;
132 0 : if ( !aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SMATH ) )
133 : {
134 0 : aSaveAsLB.RemoveEntry(aSaveAsLB.GetEntryPos( (void*) APP_MATH ));
135 0 : aDocTypeLB.RemoveEntry(aDocTypeLB.GetEntryPos( (void*) APP_MATH ));
136 : }
137 : else
138 : {
139 0 : pImpl->aDefaultArr[APP_MATH] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_MATH);
140 0 : pImpl->aDefaultReadonlyArr[APP_MATH] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::E_MATH);
141 : }
142 :
143 0 : if ( !aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SDRAW ) )
144 : {
145 0 : aSaveAsLB.RemoveEntry(aSaveAsLB.GetEntryPos( (void*) APP_DRAW ));
146 0 : aDocTypeLB.RemoveEntry(aDocTypeLB.GetEntryPos( (void*) APP_DRAW ));
147 : }
148 : else
149 : {
150 0 : pImpl->aDefaultArr[APP_DRAW] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_DRAW);
151 0 : pImpl->aDefaultReadonlyArr[APP_DRAW] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::E_DRAW);
152 : }
153 :
154 0 : if ( !aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
155 : {
156 0 : aSaveAsLB.RemoveEntry(aSaveAsLB.GetEntryPos( (void*) APP_IMPRESS ));
157 0 : aDocTypeLB.RemoveEntry(aDocTypeLB.GetEntryPos( (void*) APP_IMPRESS ));
158 : }
159 : else
160 : {
161 0 : pImpl->aDefaultArr[APP_IMPRESS] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_IMPRESS);
162 0 : pImpl->aDefaultReadonlyArr[APP_IMPRESS] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::E_IMPRESS);
163 : }
164 :
165 0 : if ( !aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
166 : {
167 0 : aSaveAsLB.RemoveEntry(aSaveAsLB.GetEntryPos( (void*) APP_CALC ));
168 0 : aDocTypeLB.RemoveEntry(aDocTypeLB.GetEntryPos( (void*) APP_CALC ));
169 : }
170 : else
171 : {
172 0 : pImpl->aDefaultArr[APP_CALC] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_CALC);
173 0 : pImpl->aDefaultReadonlyArr[APP_CALC] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::E_CALC);
174 : }
175 :
176 0 : if ( !aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
177 : {
178 0 : aSaveAsLB.RemoveEntry(aSaveAsLB.GetEntryPos( (void*) APP_WRITER ));
179 0 : aSaveAsLB.RemoveEntry(aSaveAsLB.GetEntryPos( (void*) APP_WRITER_WEB ));
180 0 : aSaveAsLB.RemoveEntry(aSaveAsLB.GetEntryPos( (void*) APP_WRITER_GLOBAL ));
181 0 : aDocTypeLB.RemoveEntry(aDocTypeLB.GetEntryPos( (void*) APP_WRITER ));
182 0 : aDocTypeLB.RemoveEntry(aDocTypeLB.GetEntryPos( (void*) APP_WRITER_WEB ));
183 0 : aDocTypeLB.RemoveEntry(aDocTypeLB.GetEntryPos( (void*) APP_WRITER_GLOBAL ));
184 : }
185 : else
186 : {
187 0 : pImpl->aDefaultArr[APP_WRITER] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_WRITER);
188 0 : pImpl->aDefaultArr[APP_WRITER_WEB] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_WRITERWEB);
189 0 : pImpl->aDefaultArr[APP_WRITER_GLOBAL] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_WRITERGLOBAL);
190 0 : pImpl->aDefaultReadonlyArr[APP_WRITER] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::E_WRITER);
191 0 : pImpl->aDefaultReadonlyArr[APP_WRITER_WEB] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::E_WRITERWEB);
192 0 : pImpl->aDefaultReadonlyArr[APP_WRITER_GLOBAL] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::E_WRITERGLOBAL);
193 : }
194 :
195 0 : aLink = LINK( this, SfxSaveTabPage, ODFVersionHdl_Impl );
196 0 : aODFVersionLB.SetSelectHdl( aLink );
197 0 : aLink = LINK( this, SfxSaveTabPage, FilterHdl_Impl );
198 0 : aDocTypeLB.SetSelectHdl( aLink );
199 0 : aSaveAsLB.SetSelectHdl( aLink );
200 :
201 0 : DetectHiddenControls();
202 0 : }
203 :
204 : // -----------------------------------------------------------------------
205 :
206 0 : SfxSaveTabPage::~SfxSaveTabPage()
207 : {
208 0 : delete pImpl;
209 0 : }
210 :
211 : // -----------------------------------------------------------------------
212 :
213 0 : SfxTabPage* SfxSaveTabPage::Create( Window* pParent,
214 : const SfxItemSet& rAttrSet )
215 : {
216 0 : return ( new SfxSaveTabPage( pParent, rAttrSet ) );
217 : }
218 :
219 : // -----------------------------------------------------------------------
220 0 : void SfxSaveTabPage::DetectHiddenControls()
221 : {
222 0 : long nDelta = 0;
223 : // the index of the first child window which perhaps have to move upwards
224 0 : sal_uInt16 nWinIndex = WININDEX_SAVEURL_RELFSYS;
225 0 : SvtOptionsDialogOptions aOptionsDlgOpt;
226 :
227 0 : if ( aOptionsDlgOpt.IsOptionHidden( C2S("Backup"), CFG_PAGE_AND_GROUP ) )
228 : {
229 : // hide controls of "Backup"
230 0 : aBackupFI.Hide();
231 0 : aBackupCB.Hide();
232 : // the other controls have to move upwards the height of checkbox + space
233 0 : nDelta = aAutoSaveCB.GetPosPixel().Y() - aBackupCB.GetPosPixel().Y();
234 : }
235 :
236 0 : if ( aOptionsDlgOpt.IsOptionHidden( C2S("AutoSave"), CFG_PAGE_AND_GROUP ) )
237 : {
238 : // hide controls of "AutoSave"
239 0 : aAutoSaveCB.Hide();
240 0 : aAutoSaveEdit.Hide();
241 0 : aMinuteFT.Hide();
242 : // the other controls have to move upwards the height of checkbox + space
243 0 : nDelta += aRelativeFsysCB.GetPosPixel().Y() - aAutoSaveCB.GetPosPixel().Y();
244 : }
245 0 : else if ( nDelta > 0 )
246 : // the "AutoSave" controls have to move upwards too
247 0 : nWinIndex = WININDEX_AUTOSAVE;
248 :
249 0 : if ( nDelta > 0 )
250 : {
251 0 : sal_uInt16 i, nChildCount = GetChildCount();
252 0 : for ( i = nWinIndex; i < nChildCount; ++i )
253 : {
254 0 : Window* pWin = GetChild(i);
255 0 : Point aPos = pWin->GetPosPixel();
256 0 : aPos.Y() -= nDelta;
257 0 : pWin->SetPosPixel( aPos );
258 : }
259 0 : }
260 0 : }
261 : // -----------------------------------------------------------------------
262 0 : sal_Bool SfxSaveTabPage::FillItemSet( SfxItemSet& rSet )
263 : {
264 0 : sal_Bool bModified = sal_False;
265 0 : SvtSaveOptions aSaveOpt;
266 0 : if(aLoadUserSettingsCB.IsChecked() != aLoadUserSettingsCB.GetSavedValue())
267 : {
268 0 : aSaveOpt.SetLoadUserSettings(aLoadUserSettingsCB.IsChecked());
269 : }
270 :
271 0 : if ( aLoadDocPrinterCB.IsChecked() != aLoadDocPrinterCB.GetSavedValue() )
272 0 : aSaveOpt.SetLoadDocumentPrinter( aLoadDocPrinterCB.IsChecked() );
273 :
274 0 : if ( aODFVersionLB.GetSelectEntryPos() != aODFVersionLB.GetSavedValue() )
275 : {
276 0 : long nVersion = long( aODFVersionLB.GetEntryData( aODFVersionLB.GetSelectEntryPos() ) );
277 0 : aSaveOpt.SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion( nVersion ) );
278 : }
279 :
280 0 : if ( aDocInfoCB.IsChecked() != aDocInfoCB.GetSavedValue() )
281 : {
282 0 : rSet.Put( SfxBoolItem( GetWhich( SID_ATTR_DOCINFO ),
283 0 : aDocInfoCB.IsChecked() ) );
284 0 : bModified |= sal_True;
285 : }
286 :
287 0 : if ( aBackupCB.IsEnabled() && aBackupCB.IsChecked() != aBackupCB.GetSavedValue() )
288 : {
289 0 : rSet.Put( SfxBoolItem( GetWhich( SID_ATTR_BACKUP ),
290 0 : aBackupCB.IsChecked() ) );
291 0 : bModified |= sal_True;
292 : }
293 :
294 0 : if ( aSizeOptimizationCB.IsChecked() != aSizeOptimizationCB.GetSavedValue() )
295 : {
296 0 : rSet.Put( SfxBoolItem( GetWhich( SID_ATTR_PRETTYPRINTING ), !aSizeOptimizationCB.IsChecked() ) );
297 0 : bModified |= sal_True;
298 : }
299 :
300 0 : if ( aAutoSaveCB.IsChecked() != aAutoSaveCB.GetSavedValue() )
301 : {
302 0 : rSet.Put( SfxBoolItem( GetWhich( SID_ATTR_AUTOSAVE ),
303 0 : aAutoSaveCB.IsChecked() ) );
304 0 : bModified |= sal_True;
305 : }
306 0 : if ( aWarnAlienFormatCB.IsChecked() != aWarnAlienFormatCB.GetSavedValue() )
307 : {
308 0 : rSet.Put( SfxBoolItem( GetWhich( SID_ATTR_WARNALIENFORMAT ),
309 0 : aWarnAlienFormatCB.IsChecked() ) );
310 0 : bModified |= sal_True;
311 : }
312 :
313 0 : if ( aAutoSaveEdit.GetText() != aAutoSaveEdit.GetSavedValue() )
314 : {
315 0 : rSet.Put( SfxUInt16Item( GetWhich( SID_ATTR_AUTOSAVEMINUTE ),
316 0 : (sal_uInt16)aAutoSaveEdit.GetValue() ) );
317 0 : bModified |= sal_True;
318 : }
319 : // save relatively
320 0 : if ( aRelativeFsysCB.IsChecked() != aRelativeFsysCB.GetSavedValue() )
321 : {
322 0 : rSet.Put( SfxBoolItem( GetWhich( SID_SAVEREL_FSYS ),
323 0 : aRelativeFsysCB.IsChecked() ) );
324 0 : bModified |= sal_True;
325 : }
326 :
327 0 : if ( aRelativeInetCB.IsChecked() != aRelativeInetCB.GetSavedValue() )
328 : {
329 0 : rSet.Put( SfxBoolItem( GetWhich( SID_SAVEREL_INET ),
330 0 : aRelativeInetCB.IsChecked() ) );
331 0 : bModified |= sal_True;
332 : }
333 :
334 0 : SvtModuleOptions aModuleOpt;
335 0 : if(!pImpl->aDefaultArr[APP_MATH].isEmpty() &&
336 0 : pImpl->aDefaultArr[APP_MATH] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_MATH))
337 0 : aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::E_MATH, pImpl->aDefaultArr[APP_MATH]);
338 :
339 0 : if( !pImpl->aDefaultArr[APP_DRAW].isEmpty() &&
340 0 : pImpl->aDefaultArr[APP_DRAW] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_DRAW))
341 0 : aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::E_DRAW, pImpl->aDefaultArr[APP_DRAW]);
342 :
343 0 : if(!pImpl->aDefaultArr[APP_IMPRESS].isEmpty() &&
344 0 : pImpl->aDefaultArr[APP_IMPRESS] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_IMPRESS))
345 0 : aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::E_IMPRESS, pImpl->aDefaultArr[APP_IMPRESS]);
346 :
347 0 : if(!pImpl->aDefaultArr[APP_CALC].isEmpty() &&
348 0 : pImpl->aDefaultArr[APP_CALC] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_CALC))
349 0 : aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::E_CALC, pImpl->aDefaultArr[APP_CALC]);
350 :
351 0 : if(!pImpl->aDefaultArr[APP_WRITER].isEmpty() &&
352 0 : pImpl->aDefaultArr[APP_WRITER] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_WRITER))
353 0 : aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::E_WRITER, pImpl->aDefaultArr[APP_WRITER]);
354 :
355 0 : if(!pImpl->aDefaultArr[APP_WRITER_WEB].isEmpty() &&
356 0 : pImpl->aDefaultArr[APP_WRITER_WEB] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_WRITERWEB))
357 0 : aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::E_WRITERWEB, pImpl->aDefaultArr[APP_WRITER_WEB]);
358 :
359 0 : if(!pImpl->aDefaultArr[APP_WRITER_GLOBAL].isEmpty() &&
360 0 : pImpl->aDefaultArr[APP_WRITER_GLOBAL] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_WRITERGLOBAL))
361 0 : aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::E_WRITERGLOBAL, pImpl->aDefaultArr[APP_WRITER_GLOBAL]);
362 :
363 0 : return bModified;
364 : }
365 :
366 : // -----------------------------------------------------------------------
367 :
368 0 : sal_Bool isODFFormat( OUString sFilter )
369 : {
370 : static const char* aODFFormats[] =
371 : {
372 : "writer8",
373 : "writer8_template",
374 : "writerglobal8",
375 : "writerglobal8_writer",
376 : "calc8",
377 : "calc8_template",
378 : "draw8",
379 : "draw8_template",
380 : "impress8",
381 : "impress8_template",
382 : "impress8_draw",
383 : "chart8",
384 : "math8",
385 : NULL
386 : };
387 :
388 0 : sal_Bool bRet = sal_False;
389 0 : int i = 0;
390 0 : while ( aODFFormats[i] != NULL )
391 : {
392 0 : if ( sFilter.equalsAscii( aODFFormats[i++] ) )
393 : {
394 0 : bRet = sal_True;
395 0 : break;
396 : }
397 : }
398 :
399 0 : return bRet;
400 : }
401 :
402 0 : void SfxSaveTabPage::Reset( const SfxItemSet& )
403 : {
404 0 : SvtSaveOptions aSaveOpt;
405 0 : aLoadUserSettingsCB.Check(aSaveOpt.IsLoadUserSettings());
406 0 : aLoadUserSettingsCB.SaveValue();
407 0 : aLoadDocPrinterCB.Check( aSaveOpt.IsLoadDocumentPrinter() );
408 0 : aLoadDocPrinterCB.SaveValue();
409 :
410 0 : if ( !pImpl->bInitialized )
411 : {
412 : try
413 : {
414 0 : Reference< XMultiServiceFactory > xMSF = comphelper::getProcessServiceFactory();
415 : pImpl->xFact = Reference<XNameContainer>(
416 0 : xMSF->createInstance("com.sun.star.document.FilterFactory"), UNO_QUERY);
417 :
418 : DBG_ASSERT(pImpl->xFact.is(), "service com.sun.star.document.FilterFactory unavailable");
419 0 : Reference< XContainerQuery > xQuery(pImpl->xFact, UNO_QUERY);
420 0 : if(xQuery.is())
421 : {
422 0 : for(sal_uInt16 n = 0; n < aDocTypeLB.GetEntryCount(); n++)
423 : {
424 0 : long nData = (long) aDocTypeLB.GetEntryData(n);
425 0 : OUString sCommand;
426 0 : sCommand = "matchByDocumentService=%1:iflags=";
427 0 : sCommand += String::CreateFromInt32(SFX_FILTER_IMPORT|SFX_FILTER_EXPORT);
428 0 : sCommand += ":eflags=";
429 0 : sCommand += String::CreateFromInt32(SFX_FILTER_NOTINFILEDLG);
430 0 : sCommand += ":default_first";
431 0 : String sReplace;
432 0 : switch(nData)
433 : {
434 0 : case APP_WRITER : sReplace = "com.sun.star.text.TextDocument"; break;
435 0 : case APP_WRITER_WEB : sReplace = "com.sun.star.text.WebDocument"; break;
436 0 : case APP_WRITER_GLOBAL : sReplace = "com.sun.star.text.GlobalDocument"; break;
437 0 : case APP_CALC : sReplace = "com.sun.star.sheet.SpreadsheetDocument";break;
438 0 : case APP_IMPRESS : sReplace = "com.sun.star.presentation.PresentationDocument";break;
439 0 : case APP_DRAW : sReplace = "com.sun.star.drawing.DrawingDocument";break;
440 0 : case APP_MATH : sReplace = "com.sun.star.formula.FormulaProperties";break;
441 : default: OSL_FAIL("illegal user data");
442 : }
443 0 : String sTmp(sCommand);
444 0 : sTmp.SearchAndReplaceAscii("%1", sReplace);
445 0 : sCommand = sTmp;
446 0 : Reference< XEnumeration > xList = xQuery->createSubSetEnumerationByQuery(sCommand);
447 0 : SequenceAsVector< OUString > lList;
448 0 : SequenceAsVector< sal_Bool > lAlienList;
449 0 : SequenceAsVector< sal_Bool > lODFList;
450 0 : while(xList->hasMoreElements())
451 : {
452 0 : SequenceAsHashMap aFilter(xList->nextElement());
453 0 : OUString sFilter = aFilter.getUnpackedValueOrDefault(OUString(RTL_CONSTASCII_USTRINGPARAM("Name")),OUString());
454 0 : if (!sFilter.isEmpty())
455 : {
456 0 : sal_Int32 nFlags = aFilter.getUnpackedValueOrDefault(OUString(RTL_CONSTASCII_USTRINGPARAM("Flags")),sal_Int32());
457 0 : lList.push_back(sFilter);
458 0 : lAlienList.push_back(0 != (nFlags & SFX_FILTER_ALIEN));
459 0 : lODFList.push_back( isODFFormat( sFilter ) );
460 : }
461 0 : }
462 0 : pImpl->aFilterArr[nData] = lList.getAsConstList();
463 0 : pImpl->aAlienArr[nData] = lAlienList.getAsConstList();
464 0 : pImpl->aODFArr[nData] = lODFList.getAsConstList();
465 0 : }
466 : }
467 0 : aDocTypeLB.SelectEntryPos(0);
468 0 : FilterHdl_Impl(&aDocTypeLB);
469 : }
470 0 : catch(Exception& e)
471 : {
472 : (void) e;
473 : OSL_FAIL(
474 : rtl::OUStringToOString(
475 : (rtl::OUString(
476 : RTL_CONSTASCII_USTRINGPARAM(
477 : "exception in FilterFactory access: ")) +
478 : e.Message),
479 : RTL_TEXTENCODING_UTF8).
480 : getStr());
481 : }
482 :
483 0 : pImpl->bInitialized = sal_True;
484 : }
485 :
486 0 : aDocInfoCB.Check(aSaveOpt.IsDocInfoSave());
487 :
488 0 : aBackupCB.Check(aSaveOpt.IsBackup());
489 0 : sal_Bool bBackupRO = aSaveOpt.IsReadOnly(SvtSaveOptions::E_BACKUP);
490 0 : aBackupCB.Enable(!bBackupRO);
491 0 : aBackupFI.Show(bBackupRO);
492 :
493 0 : aAutoSaveCB.Check(aSaveOpt.IsAutoSave());
494 0 : aWarnAlienFormatCB.Check(aSaveOpt.IsWarnAlienFormat());
495 0 : aWarnAlienFormatCB.Enable(!aSaveOpt.IsReadOnly(SvtSaveOptions::E_WARNALIENFORMAT));
496 :
497 : // the pretty printing
498 0 : aSizeOptimizationCB.Check( !aSaveOpt.IsPrettyPrinting());
499 :
500 0 : aAutoSaveEdit.SetValue( aSaveOpt.GetAutoSaveTime() );
501 :
502 : // save relatively
503 0 : aRelativeFsysCB.Check( aSaveOpt.IsSaveRelFSys() );
504 :
505 0 : aRelativeInetCB.Check( aSaveOpt.IsSaveRelINet() );
506 :
507 0 : void* pDefaultVersion = (void*)long( aSaveOpt.GetODFDefaultVersion() );
508 0 : aODFVersionLB.SelectEntryPos( aODFVersionLB.GetEntryPos( pDefaultVersion ) );
509 :
510 0 : AutoClickHdl_Impl( &aAutoSaveCB );
511 0 : ODFVersionHdl_Impl( &aODFVersionLB );
512 :
513 0 : aDocInfoCB.SaveValue();
514 0 : aBackupCB.SaveValue();
515 0 : aWarnAlienFormatCB.SaveValue();
516 0 : aSizeOptimizationCB.SaveValue();
517 0 : aAutoSaveCB.SaveValue();
518 0 : aAutoSaveEdit.SaveValue();
519 :
520 0 : aRelativeFsysCB.SaveValue();
521 0 : aRelativeInetCB.SaveValue();
522 0 : aODFVersionLB.SaveValue();
523 0 : }
524 :
525 : // -----------------------------------------------------------------------
526 :
527 0 : IMPL_LINK( SfxSaveTabPage, AutoClickHdl_Impl, CheckBox *, pBox )
528 : {
529 0 : if ( pBox == &aAutoSaveCB )
530 : {
531 0 : if ( aAutoSaveCB.IsChecked() )
532 : {
533 0 : aAutoSaveEdit.Enable();
534 0 : aMinuteFT.Enable();
535 : }
536 : else
537 : {
538 0 : aAutoSaveEdit.Disable();
539 0 : aMinuteFT.Disable();
540 : }
541 : }
542 0 : return 0;
543 : }
544 :
545 0 : static OUString lcl_ExtracUIName(const Sequence<PropertyValue> rProperties)
546 : {
547 0 : OUString sRet;
548 0 : const PropertyValue* pProperties = rProperties.getConstArray();
549 0 : for(int nProp = 0; nProp < rProperties.getLength(); nProp++)
550 : {
551 0 : if(!pProperties[nProp].Name.compareToAscii("UIName"))
552 : {
553 0 : pProperties[nProp].Value >>= sRet;
554 0 : break;
555 : }
556 0 : else if(!pProperties[nProp].Name.compareToAscii("Name"))
557 : {
558 0 : pProperties[nProp].Value >>= sRet;
559 : }
560 : }
561 0 : return sRet;
562 : }
563 :
564 0 : IMPL_LINK( SfxSaveTabPage, FilterHdl_Impl, ListBox *, pBox )
565 : {
566 0 : sal_uInt16 nCurPos = aDocTypeLB.GetSelectEntryPos();
567 :
568 0 : long nData = -1;
569 0 : if(nCurPos < APP_COUNT)
570 0 : nData = (long) aDocTypeLB.GetEntryData(nCurPos);
571 :
572 0 : if ( nData >= 0 && nData < APP_COUNT )
573 : {
574 0 : if(&aDocTypeLB == pBox)
575 : {
576 0 : aSaveAsLB.Clear();
577 0 : const OUString* pFilters = pImpl->aFilterArr[nData].getConstArray();
578 0 : if(!pImpl->aUIFilterArr[nData].getLength())
579 : {
580 0 : pImpl->aUIFilterArr[nData].realloc(pImpl->aFilterArr[nData].getLength());
581 0 : OUString* pUIFilters = pImpl->aUIFilterArr[nData].getArray();
582 0 : for(int nFilter = 0; nFilter < pImpl->aFilterArr[nData].getLength(); nFilter++)
583 : {
584 0 : Any aProps = pImpl->xFact->getByName(pFilters[nFilter]);
585 0 : Sequence<PropertyValue> aProperties;
586 0 : aProps >>= aProperties;
587 0 : pUIFilters[nFilter] = lcl_ExtracUIName(aProperties);
588 0 : }
589 : }
590 0 : const OUString* pUIFilters = pImpl->aUIFilterArr[nData].getConstArray();
591 0 : OUString sSelect;
592 0 : for(int i = 0; i < pImpl->aUIFilterArr[nData].getLength(); i++)
593 : {
594 0 : sal_uInt16 nEntryPos = aSaveAsLB.InsertEntry(pUIFilters[i]);
595 0 : if ( pImpl->aODFArr[nData][i] )
596 0 : aSaveAsLB.SetEntryData( nEntryPos, (void*)pImpl );
597 0 : if(pFilters[i] == pImpl->aDefaultArr[nData])
598 0 : sSelect = pUIFilters[i];
599 : }
600 0 : if(!sSelect.isEmpty())
601 0 : aSaveAsLB.SelectEntry(sSelect);
602 0 : aSaveAsFI.Show(pImpl->aDefaultReadonlyArr[nData]);
603 0 : aSaveAsFT.Enable(!pImpl->aDefaultReadonlyArr[nData]);
604 0 : aSaveAsLB.Enable(!pImpl->aDefaultReadonlyArr[nData]);
605 : }
606 : else
607 : {
608 0 : OUString sSelect = pBox->GetSelectEntry();
609 0 : const OUString* pFilters = pImpl->aFilterArr[nData].getConstArray();
610 0 : OUString* pUIFilters = pImpl->aUIFilterArr[nData].getArray();
611 0 : for(int i = 0; i < pImpl->aUIFilterArr[nData].getLength(); i++)
612 0 : if(pUIFilters[i] == sSelect)
613 : {
614 0 : sSelect = pFilters[i];
615 0 : break;
616 : }
617 :
618 0 : pImpl->aDefaultArr[nData] = sSelect;
619 : }
620 : }
621 :
622 0 : ODFVersionHdl_Impl( &aSaveAsLB );
623 0 : return 0;
624 : };
625 :
626 0 : IMPL_LINK_NOARG(SfxSaveTabPage, ODFVersionHdl_Impl)
627 : {
628 0 : long nVersion = long( aODFVersionLB.GetEntryData( aODFVersionLB.GetSelectEntryPos() ) );
629 0 : bool bShown = SvtSaveOptions::ODFDefaultVersion( nVersion ) != SvtSaveOptions::ODFVER_LATEST;
630 0 : if ( bShown )
631 : {
632 0 : bool bHasODFFormat = false;
633 0 : sal_uInt16 i = 0, nCount = aSaveAsLB.GetEntryCount();
634 0 : for ( ; i < nCount; ++ i )
635 : {
636 0 : if ( aSaveAsLB.GetEntryData(i) != NULL )
637 : {
638 0 : bHasODFFormat = true;
639 0 : break;
640 : }
641 : }
642 :
643 0 : bShown = !bHasODFFormat
644 0 : || ( aSaveAsLB.GetEntryData( aSaveAsLB.GetSelectEntryPos() ) != NULL );
645 : }
646 :
647 0 : aODFWarningFI.Show( bShown );
648 0 : aODFWarningFT.Show( bShown );
649 :
650 0 : return 0;
651 3 : }
652 :
653 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|