tdf#144694 In direct SQL dialog, activate options 'Run SQL command
[LibreOffice.git] / cui / source / options / optsave.cxx
blobeffa144bd761c860c00954ecfaaf6d43004030fd
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 <sal/config.h>
22 #include <string_view>
24 #include <o3tl/string_view.hxx>
25 #include <svl/eitem.hxx>
26 #include <svl/intitem.hxx>
27 #include <dialmgr.hxx>
28 #include "optsave.hxx"
29 #include <strings.hrc>
30 #include <treeopt.hxx>
31 #include <officecfg/Office/Common.hxx>
32 #include <comphelper/processfactory.hxx>
33 #include <unotools/moduleoptions.hxx>
34 #include <unotools/saveopt.hxx>
35 #include <comphelper/sequenceashashmap.hxx>
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <com/sun/star/container/XNameContainer.hpp>
38 #include <com/sun/star/container/XContainerQuery.hpp>
39 #include <com/sun/star/container/XEnumeration.hpp>
40 #include <com/sun/star/beans/PropertyValue.hpp>
41 #include <sfx2/sfxsids.hrc>
42 #include <sfx2/docfilt.hxx>
43 #include <osl/diagnose.h>
44 #include <comphelper/diagnose_ex.hxx>
45 #include <officecfg/Office/Recovery.hxx>
46 #include <unotools/confignode.hxx>
48 #include <sfx2/fcontnr.hxx>
50 using namespace com::sun::star::uno;
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;
57 struct SvxSaveTabPage_Impl
59 Reference< XNameContainer > xFact;
60 std::vector< OUString > aFilterArr[APP_COUNT];
61 std::vector< bool > aODFArr[APP_COUNT];
62 std::vector< OUString > aUIFilterArr[APP_COUNT];
63 OUString aDefaultArr[APP_COUNT];
64 bool aDefaultReadonlyArr[APP_COUNT];
65 bool bInitialized;
67 SvxSaveTabPage_Impl();
70 SvxSaveTabPage_Impl::SvxSaveTabPage_Impl() : bInitialized( false )
74 // class SvxSaveTabPage --------------------------------------------------
76 SvxSaveTabPage::SvxSaveTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreSet)
77 : SfxTabPage( pPage, pController, u"cui/ui/optsavepage.ui"_ustr, u"OptSavePage"_ustr, &rCoreSet )
78 , pImpl(new SvxSaveTabPage_Impl)
79 , m_xLoadViewPosAnyUserCB(m_xBuilder->weld_check_button(u"load_anyuser"_ustr))
80 , m_xLoadViewPosAnyUserImg(m_xBuilder->weld_widget(u"lockload_anyuser"_ustr))
81 , m_xLoadUserSettingsCB(m_xBuilder->weld_check_button(u"load_settings"_ustr))
82 , m_xLoadUserSettingsImg(m_xBuilder->weld_widget(u"lockload_settings"_ustr))
83 , m_xLoadDocPrinterCB(m_xBuilder->weld_check_button(u"load_docprinter"_ustr))
84 , m_xLoadDocPrinterImg(m_xBuilder->weld_widget(u"lockload_docprinter"_ustr))
85 , m_xDocInfoCB(m_xBuilder->weld_check_button(u"docinfo"_ustr))
86 , m_xDocInfoImg(m_xBuilder->weld_widget(u"lockdocinfo"_ustr))
87 , m_xBackupCB(m_xBuilder->weld_check_button(u"backup"_ustr))
88 , m_xBackupImg(m_xBuilder->weld_widget(u"lockbackup"_ustr))
89 , m_xBackupIntoDocumentFolderCB(m_xBuilder->weld_check_button(u"backupintodocumentfolder"_ustr))
90 , m_xBackupIntoDocumentFolderImg(m_xBuilder->weld_widget(u"lockbackupintodoc"_ustr))
91 , m_xAutoSaveCB(m_xBuilder->weld_check_button(u"autosave"_ustr))
92 , m_xAutoSaveImg(m_xBuilder->weld_widget(u"lockautosave"_ustr))
93 , m_xAutoSaveEdit(m_xBuilder->weld_spin_button(u"autosave_spin"_ustr))
94 , m_xMinuteFT(m_xBuilder->weld_label(u"autosave_mins"_ustr))
95 , m_xUserAutoSaveCB(m_xBuilder->weld_check_button(u"userautosave"_ustr))
96 , m_xUserAutoSaveImg(m_xBuilder->weld_widget(u"lockuserautosave"_ustr))
97 , m_xRelativeFsysCB(m_xBuilder->weld_check_button(u"relative_fsys"_ustr))
98 , m_xRelativeFsysImg(m_xBuilder->weld_widget(u"lockrelative_fsys"_ustr))
99 , m_xRelativeInetCB(m_xBuilder->weld_check_button(u"relative_inet"_ustr))
100 , m_xRelativeInetImg(m_xBuilder->weld_widget(u"lockrelative_inet"_ustr))
101 , m_xODFVersionLB(m_xBuilder->weld_combo_box(u"odfversion"_ustr))
102 , m_xODFVersionFT(m_xBuilder->weld_label(u"label5"_ustr))
103 , m_xODFVersionImg(m_xBuilder->weld_widget(u"lockodfversion"_ustr))
104 , m_xWarnAlienFormatCB(m_xBuilder->weld_check_button(u"warnalienformat"_ustr))
105 , m_xWarnAlienFormatImg(m_xBuilder->weld_widget(u"lockwarnalienformat"_ustr))
106 , m_xDocTypeLB(m_xBuilder->weld_combo_box(u"doctype"_ustr))
107 , m_xSaveAsFT(m_xBuilder->weld_label(u"saveas_label"_ustr))
108 , m_xSaveAsLB(m_xBuilder->weld_combo_box(u"saveas"_ustr))
109 , m_xODFWarningFI(m_xBuilder->weld_widget(u"odfwarning_image"_ustr))
110 , m_xODFWarningFT(m_xBuilder->weld_label(u"odfwarning_label"_ustr))
112 m_xAutoSaveEdit->set_max_length(2);
113 m_xBackupIntoDocumentFolderCB->set_accessible_description(CuiResId(RID_CUISTR_A11Y_DESC_BACKUP));
115 m_xODFVersionLB->set_id(0, OUString::number(SvtSaveOptions::ODFVER_011)); // 1.0/1.1
116 m_xODFVersionLB->set_id(1, OUString::number(SvtSaveOptions::ODFVER_012)); // 1.2
117 m_xODFVersionLB->set_id(2, OUString::number(SvtSaveOptions::ODFVER_012_EXT_COMPAT)); // 1.2 Extended (compatibility mode)
118 m_xODFVersionLB->set_id(3, OUString::number(SvtSaveOptions::ODFVER_012_EXTENDED)); // 1.2 Extended
119 m_xODFVersionLB->set_id(4, OUString::number(SvtSaveOptions::ODFVER_013)); // 1.3
120 m_xODFVersionLB->set_id(5, OUString::number(SvtSaveOptions::ODFVER_013_EXTENDED)); // 1.3 Extended
121 m_xODFVersionLB->set_id(6, OUString::number(SvtSaveOptions::ODFVER_014)); // 1.4
122 m_xODFVersionLB->set_id(7, OUString::number(SvtSaveOptions::ODFVER_LATEST)); // 1.4 Extended (recommended)
124 auto aFilterClassesNode = utl::OConfigurationTreeRoot::createWithComponentContext(
125 comphelper::getProcessComponentContext(),
126 u"org.openoffice.Office.UI/FilterClassification/GlobalFilters/Classes"_ustr,
128 utl::OConfigurationTreeRoot::CM_READONLY
131 m_xDocTypeLB->append(OUString::number(APP_WRITER), aFilterClassesNode.getNodeValue(u"com.sun.star.text.TextDocument/DisplayName"_ustr).get<OUString>());
132 m_xDocTypeLB->append(OUString::number(APP_WRITER_WEB), aFilterClassesNode.getNodeValue(u"com.sun.star.text.WebDocument/DisplayName"_ustr).get<OUString>());
133 m_xDocTypeLB->append(OUString::number(APP_WRITER_GLOBAL), aFilterClassesNode.getNodeValue(u"com.sun.star.text.GlobalDocument/DisplayName"_ustr).get<OUString>());
134 m_xDocTypeLB->append(OUString::number(APP_CALC), aFilterClassesNode.getNodeValue(u"com.sun.star.sheet.SpreadsheetDocument/DisplayName"_ustr).get<OUString>());
135 m_xDocTypeLB->append(OUString::number(APP_IMPRESS), aFilterClassesNode.getNodeValue(u"com.sun.star.presentation.PresentationDocument/DisplayName"_ustr).get<OUString>());
136 m_xDocTypeLB->append(OUString::number(APP_DRAW), aFilterClassesNode.getNodeValue(u"com.sun.star.drawing.DrawingDocument/DisplayName"_ustr).get<OUString>());
137 m_xDocTypeLB->append(OUString::number(APP_MATH), aFilterClassesNode.getNodeValue(u"com.sun.star.formula.FormulaProperties/DisplayName"_ustr).get<OUString>());
139 m_xAutoSaveCB->connect_toggled( LINK( this, SvxSaveTabPage, AutoClickHdl_Impl ) );
140 m_xBackupCB->connect_toggled(LINK(this, SvxSaveTabPage, BackupClickHdl_Impl));
142 SvtModuleOptions aModuleOpt;
143 if (!aModuleOpt.IsMathInstalled())
145 m_xSaveAsLB->remove_id(OUString::number(APP_MATH));
146 m_xDocTypeLB->remove_id(OUString::number(APP_MATH));
148 else
150 pImpl->aDefaultArr[APP_MATH] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::EFactory::MATH);
151 pImpl->aDefaultReadonlyArr[APP_MATH] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::EFactory::MATH);
154 if (!aModuleOpt.IsDrawInstalled())
156 m_xSaveAsLB->remove_id(OUString::number(APP_DRAW));
157 m_xDocTypeLB->remove_id(OUString::number(APP_DRAW));
159 else
161 pImpl->aDefaultArr[APP_DRAW] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::EFactory::DRAW);
162 pImpl->aDefaultReadonlyArr[APP_DRAW] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::EFactory::DRAW);
165 if (!aModuleOpt.IsImpressInstalled())
167 m_xSaveAsLB->remove_id(OUString::number(APP_IMPRESS));
168 m_xDocTypeLB->remove_id(OUString::number(APP_IMPRESS));
170 else
172 pImpl->aDefaultArr[APP_IMPRESS] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::EFactory::IMPRESS);
173 pImpl->aDefaultReadonlyArr[APP_IMPRESS] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::EFactory::IMPRESS);
176 if (!aModuleOpt.IsCalcInstalled())
178 m_xSaveAsLB->remove_id(OUString::number(APP_CALC));
179 m_xDocTypeLB->remove_id(OUString::number(APP_CALC));
181 else
183 pImpl->aDefaultArr[APP_CALC] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::EFactory::CALC);
184 pImpl->aDefaultReadonlyArr[APP_CALC] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::EFactory::CALC);
187 if (!aModuleOpt.IsWriterInstalled())
189 m_xSaveAsLB->remove_id(OUString::number(APP_WRITER));
190 m_xSaveAsLB->remove_id(OUString::number(APP_WRITER_WEB));
191 m_xSaveAsLB->remove_id(OUString::number(APP_WRITER_GLOBAL));
192 m_xDocTypeLB->remove_id(OUString::number(APP_WRITER));
193 m_xDocTypeLB->remove_id(OUString::number(APP_WRITER_WEB));
194 m_xDocTypeLB->remove_id(OUString::number(APP_WRITER_GLOBAL));
196 else
198 pImpl->aDefaultArr[APP_WRITER] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::EFactory::WRITER);
199 pImpl->aDefaultArr[APP_WRITER_WEB] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::EFactory::WRITERWEB);
200 pImpl->aDefaultArr[APP_WRITER_GLOBAL] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::EFactory::WRITERGLOBAL);
201 pImpl->aDefaultReadonlyArr[APP_WRITER] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::EFactory::WRITER);
202 pImpl->aDefaultReadonlyArr[APP_WRITER_WEB] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::EFactory::WRITERWEB);
203 pImpl->aDefaultReadonlyArr[APP_WRITER_GLOBAL] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::EFactory::WRITERGLOBAL);
206 Link<weld::ComboBox&,void> aLink = LINK( this, SvxSaveTabPage, ODFVersionHdl_Impl );
207 m_xODFVersionLB->connect_changed( aLink );
208 aLink = LINK( this, SvxSaveTabPage, FilterHdl_Impl );
209 m_xDocTypeLB->connect_changed( aLink );
210 m_xSaveAsLB->connect_changed( aLink );
213 SvxSaveTabPage::~SvxSaveTabPage()
217 std::unique_ptr<SfxTabPage> SvxSaveTabPage::Create(weld::Container* pPage, weld::DialogController* pController,
218 const SfxItemSet* rAttrSet)
220 return std::make_unique<SvxSaveTabPage>(pPage, pController, *rAttrSet);
223 OUString SvxSaveTabPage::GetAllStrings()
225 OUString sAllStrings;
226 OUString labels[] = { u"label1"_ustr, u"label2"_ustr, u"autosave_mins"_ustr, u"label3"_ustr,
227 u"label5"_ustr, u"label6"_ustr, u"saveas_label"_ustr, u"odfwarning_label"_ustr };
229 for (const auto& label : labels)
231 if (const auto pString = m_xBuilder->weld_label(label))
232 sAllStrings += pString->get_label() + " ";
235 OUString checkButton[]
236 = { u"load_settings"_ustr, u"load_docprinter"_ustr, u"load_anyuser"_ustr, u"autosave"_ustr,
237 u"userautosave"_ustr, u"docinfo"_ustr, u"backup"_ustr, u"backupintodocumentfolder"_ustr,
238 u"relative_fsys"_ustr, u"relative_inet"_ustr, u"warnalienformat"_ustr };
240 for (const auto& check : checkButton)
242 if (const auto pString = m_xBuilder->weld_check_button(check))
243 sAllStrings += pString->get_label() + " ";
246 return sAllStrings.replaceAll("_", "");
249 bool SvxSaveTabPage::FillItemSet( SfxItemSet* rSet )
251 auto xChanges = comphelper::ConfigurationChanges::create();
252 bool bModified = false;
253 if (m_xLoadViewPosAnyUserCB->get_state_changed_from_saved())
255 officecfg::Office::Common::Load::ViewPositionForAnyUser::set(m_xLoadViewPosAnyUserCB->get_active(), xChanges);
257 if(m_xLoadUserSettingsCB->get_state_changed_from_saved())
258 officecfg::Office::Common::Load::UserDefinedSettings::set(m_xLoadUserSettingsCB->get_active(), xChanges);
260 if ( m_xLoadDocPrinterCB->get_state_changed_from_saved() )
261 officecfg::Office::Common::Save::Document::LoadPrinter::set(m_xLoadDocPrinterCB->get_active(), xChanges);
263 if ( m_xODFVersionLB->get_value_changed_from_saved() )
265 sal_Int32 nVersion = m_xODFVersionLB->get_active_id().toInt32();
266 SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion( nVersion ), xChanges );
269 if ( m_xDocInfoCB->get_state_changed_from_saved() )
271 rSet->Put( SfxBoolItem( SID_ATTR_DOCINFO,
272 m_xDocInfoCB->get_active() ) );
273 bModified = true;
276 if ( m_xBackupCB->get_sensitive() && m_xBackupCB->get_state_changed_from_saved() )
278 rSet->Put( SfxBoolItem( SID_ATTR_BACKUP, m_xBackupCB->get_active() ) );
279 bModified = true;
282 if (m_xBackupIntoDocumentFolderCB->get_sensitive()
283 && m_xBackupIntoDocumentFolderCB->get_state_changed_from_saved())
285 rSet->Put(
286 SfxBoolItem(SID_ATTR_BACKUP_BESIDE_ORIGINAL, m_xBackupIntoDocumentFolderCB->get_active()));
287 bModified = true;
290 if ( m_xAutoSaveCB->get_state_changed_from_saved() )
292 rSet->Put( SfxBoolItem( SID_ATTR_AUTOSAVE,
293 m_xAutoSaveCB->get_active() ) );
294 bModified = true;
296 if ( m_xWarnAlienFormatCB->get_state_changed_from_saved() )
298 rSet->Put( SfxBoolItem( SID_ATTR_WARNALIENFORMAT,
299 m_xWarnAlienFormatCB->get_active() ) );
300 bModified = true;
303 if ( m_xAutoSaveEdit->get_value_changed_from_saved() )
305 rSet->Put( SfxUInt16Item( SID_ATTR_AUTOSAVEMINUTE,
306 static_cast<sal_uInt16>(m_xAutoSaveEdit->get_value()) ) );
307 bModified = true;
310 if ( m_xUserAutoSaveCB->get_state_changed_from_saved() )
312 rSet->Put( SfxBoolItem( SID_ATTR_USERAUTOSAVE,
313 m_xUserAutoSaveCB->get_active() ) );
314 bModified = true;
316 // save relatively
317 if ( m_xRelativeFsysCB->get_state_changed_from_saved() )
319 rSet->Put( SfxBoolItem( SID_SAVEREL_FSYS,
320 m_xRelativeFsysCB->get_active() ) );
321 bModified = true;
324 if ( m_xRelativeInetCB->get_state_changed_from_saved() )
326 rSet->Put( SfxBoolItem( SID_SAVEREL_INET,
327 m_xRelativeInetCB->get_active() ) );
328 bModified = true;
331 SvtModuleOptions aModuleOpt;
332 if(!pImpl->aDefaultArr[APP_MATH].isEmpty() &&
333 pImpl->aDefaultArr[APP_MATH] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::EFactory::MATH))
334 aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::EFactory::MATH, pImpl->aDefaultArr[APP_MATH]);
336 if( !pImpl->aDefaultArr[APP_DRAW].isEmpty() &&
337 pImpl->aDefaultArr[APP_DRAW] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::EFactory::DRAW))
338 aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::EFactory::DRAW, pImpl->aDefaultArr[APP_DRAW]);
340 if(!pImpl->aDefaultArr[APP_IMPRESS].isEmpty() &&
341 pImpl->aDefaultArr[APP_IMPRESS] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::EFactory::IMPRESS))
342 aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::EFactory::IMPRESS, pImpl->aDefaultArr[APP_IMPRESS]);
344 if(!pImpl->aDefaultArr[APP_CALC].isEmpty() &&
345 pImpl->aDefaultArr[APP_CALC] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::EFactory::CALC))
346 aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::EFactory::CALC, pImpl->aDefaultArr[APP_CALC]);
348 if(!pImpl->aDefaultArr[APP_WRITER].isEmpty() &&
349 pImpl->aDefaultArr[APP_WRITER] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::EFactory::WRITER))
350 aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::EFactory::WRITER, pImpl->aDefaultArr[APP_WRITER]);
352 if(!pImpl->aDefaultArr[APP_WRITER_WEB].isEmpty() &&
353 pImpl->aDefaultArr[APP_WRITER_WEB] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::EFactory::WRITERWEB))
354 aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::EFactory::WRITERWEB, pImpl->aDefaultArr[APP_WRITER_WEB]);
356 if(!pImpl->aDefaultArr[APP_WRITER_GLOBAL].isEmpty() &&
357 pImpl->aDefaultArr[APP_WRITER_GLOBAL] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::EFactory::WRITERGLOBAL))
358 aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::EFactory::WRITERGLOBAL, pImpl->aDefaultArr[APP_WRITER_GLOBAL]);
360 xChanges->commit();
361 return bModified;
364 static bool isODFFormat( std::u16string_view sFilter )
366 static const char* aODFFormats[] =
368 "writer8",
369 "writer8_template",
370 "writerglobal8",
371 "writerglobal8_writer",
372 "calc8",
373 "calc8_template",
374 "draw8",
375 "draw8_template",
376 "impress8",
377 "impress8_template",
378 "impress8_draw",
379 "chart8",
380 "math8",
381 nullptr
384 bool bRet = false;
385 int i = 0;
386 while ( aODFFormats[i] != nullptr )
388 if ( o3tl::equalsAscii( sFilter, aODFFormats[i++] ) )
390 bRet = true;
391 break;
395 return bRet;
398 void SvxSaveTabPage::Reset( const SfxItemSet* )
400 m_xLoadViewPosAnyUserCB->set_active(officecfg::Office::Common::Load::ViewPositionForAnyUser::get());
401 m_xLoadViewPosAnyUserCB->save_state();
402 m_xLoadViewPosAnyUserCB->set_sensitive(!officecfg::Office::Common::Load::ViewPositionForAnyUser::isReadOnly());
403 m_xLoadViewPosAnyUserImg->set_visible(officecfg::Office::Common::Load::ViewPositionForAnyUser::isReadOnly());
405 m_xLoadUserSettingsCB->set_active(officecfg::Office::Common::Load::UserDefinedSettings::get());
406 m_xLoadUserSettingsCB->save_state();
407 m_xLoadUserSettingsCB->set_sensitive(!officecfg::Office::Common::Load::UserDefinedSettings::isReadOnly());
408 m_xLoadUserSettingsImg->set_visible(officecfg::Office::Common::Load::UserDefinedSettings::isReadOnly());
410 m_xLoadDocPrinterCB->set_active( officecfg::Office::Common::Save::Document::LoadPrinter::get() );
411 m_xLoadDocPrinterCB->save_state();
412 m_xLoadDocPrinterCB->set_sensitive(!officecfg::Office::Common::Save::Document::LoadPrinter::isReadOnly());
413 m_xLoadDocPrinterImg->set_visible(officecfg::Office::Common::Save::Document::LoadPrinter::isReadOnly());
415 if ( !pImpl->bInitialized )
419 Reference< XMultiServiceFactory > xMSF = comphelper::getProcessServiceFactory();
420 pImpl->xFact.set(xMSF->createInstance(u"com.sun.star.document.FilterFactory"_ustr), UNO_QUERY);
422 DBG_ASSERT(pImpl->xFact.is(), "service com.sun.star.document.FilterFactory unavailable");
423 Reference< XContainerQuery > xQuery(pImpl->xFact, UNO_QUERY);
424 if(xQuery.is())
426 for (sal_Int32 n = 0, nEntryCount = m_xDocTypeLB->get_count(); n < nEntryCount; ++n)
428 unsigned int nData = m_xDocTypeLB->get_id(n).toUInt32();
429 OUString sCommand = "getSortedFilterList():module=%1:iflags=" +
430 OUString::number(static_cast<int>(SfxFilterFlags::IMPORT|SfxFilterFlags::EXPORT)) +
431 ":eflags=" +
432 OUString::number(static_cast<int>(SfxFilterFlags::NOTINFILEDLG));
433 OUString sReplace;
434 switch(nData)
436 case APP_WRITER : sReplace = "com.sun.star.text.TextDocument"; break;
437 case APP_WRITER_WEB : sReplace = "com.sun.star.text.WebDocument"; break;
438 case APP_WRITER_GLOBAL : sReplace = "com.sun.star.text.GlobalDocument"; break;
439 case APP_CALC : sReplace = "com.sun.star.sheet.SpreadsheetDocument";break;
440 case APP_IMPRESS : sReplace = "com.sun.star.presentation.PresentationDocument";break;
441 case APP_DRAW : sReplace = "com.sun.star.drawing.DrawingDocument";break;
442 case APP_MATH : sReplace = "com.sun.star.formula.FormulaProperties";break;
443 default: SAL_WARN("cui.options", "illegal user data");
445 sCommand = sCommand.replaceFirst("%1", sReplace);
446 Reference< XEnumeration > xList = xQuery->createSubSetEnumerationByQuery(sCommand);
447 std::vector< OUString > lList;
448 std::vector<bool> lODFList;
449 while(xList->hasMoreElements())
451 SequenceAsHashMap aFilter(xList->nextElement());
452 OUString sFilter = aFilter.getUnpackedValueOrDefault(u"Name"_ustr,OUString());
453 if (!sFilter.isEmpty())
455 lList.push_back(sFilter);
456 lODFList.push_back( isODFFormat( sFilter ) );
459 pImpl->aFilterArr[nData] = std::move(lList);
460 pImpl->aODFArr[nData] = std::move(lODFList);
463 OUString sModule = OfaTreeOptionsDialog::getCurrentFactory_Impl(GetFrame());
464 sal_Int32 docId = 0;
465 if (sModule == "com.sun.star.text.TextDocument")
466 docId = APP_WRITER;
467 else if (sModule == "com.sun.star.text.WebDocument")
468 docId = APP_WRITER_WEB;
469 else if (sModule == "com.sun.star.text.GlobalDocument")
470 docId = APP_WRITER_GLOBAL;
471 else if (sModule == "com.sun.star.sheet.SpreadsheetDocument")
472 docId = APP_CALC;
473 else if (sModule == "com.sun.star.presentation.PresentationDocument")
474 docId = APP_IMPRESS;
475 else if (sModule == "com.sun.star.drawing.DrawingDocument")
476 docId = APP_DRAW;
477 else if (sModule == "com.sun.star.formula.FormulaProperties")
478 docId = APP_MATH;
479 m_xDocTypeLB->set_active_id(OUString::number(docId));
480 FilterHdl_Impl(*m_xDocTypeLB);
482 catch(Exception const &)
484 TOOLS_WARN_EXCEPTION( "cui.options", "exception in FilterFactory access" );
487 pImpl->bInitialized = true;
490 m_xDocInfoCB->set_active(officecfg::Office::Common::Save::Document::EditProperty::get());
491 m_xDocInfoCB->set_sensitive(!officecfg::Office::Common::Save::Document::EditProperty::isReadOnly());
492 m_xDocInfoImg->set_visible(officecfg::Office::Common::Save::Document::EditProperty::isReadOnly());
494 m_xBackupCB->set_active(officecfg::Office::Common::Save::Document::CreateBackup::get());
495 m_xBackupCB->set_sensitive(!officecfg::Office::Common::Save::Document::CreateBackup::isReadOnly());
496 m_xBackupImg->set_visible(officecfg::Office::Common::Save::Document::CreateBackup::isReadOnly());
498 m_xBackupIntoDocumentFolderCB->set_active(
499 officecfg::Office::Common::Save::Document::BackupIntoDocumentFolder::get());
500 m_xBackupIntoDocumentFolderCB->set_sensitive(
501 !officecfg::Office::Common::Save::Document::BackupIntoDocumentFolder::isReadOnly()
502 && m_xBackupCB->get_active());
503 m_xBackupIntoDocumentFolderImg->set_visible(
504 officecfg::Office::Common::Save::Document::BackupIntoDocumentFolder::isReadOnly());
506 m_xAutoSaveCB->set_active(officecfg::Office::Recovery::AutoSave::Enabled::get());
507 m_xAutoSaveCB->set_sensitive(!officecfg::Office::Recovery::AutoSave::Enabled::isReadOnly());
508 m_xAutoSaveImg->set_visible(officecfg::Office::Recovery::AutoSave::Enabled::isReadOnly());
510 m_xUserAutoSaveCB->set_active(officecfg::Office::Recovery::AutoSave::UserAutoSaveEnabled::get());
511 m_xUserAutoSaveCB->set_sensitive(!officecfg::Office::Recovery::AutoSave::UserAutoSaveEnabled::isReadOnly());
512 m_xUserAutoSaveImg->set_visible(officecfg::Office::Recovery::AutoSave::UserAutoSaveEnabled::isReadOnly());
514 m_xWarnAlienFormatCB->set_active(officecfg::Office::Common::Save::Document::WarnAlienFormat::get());
515 m_xWarnAlienFormatCB->set_sensitive(!officecfg::Office::Common::Save::Document::WarnAlienFormat::isReadOnly());
516 m_xWarnAlienFormatImg->set_visible(officecfg::Office::Common::Save::Document::WarnAlienFormat::isReadOnly());
518 m_xAutoSaveEdit->set_value(officecfg::Office::Recovery::AutoSave::TimeIntervall::get());
519 m_xAutoSaveEdit->set_sensitive(!officecfg::Office::Recovery::AutoSave::TimeIntervall::isReadOnly());
521 // save relatively
522 m_xRelativeFsysCB->set_active(officecfg::Office::Common::Save::URL::FileSystem::get());
523 m_xRelativeFsysCB->set_sensitive(!officecfg::Office::Common::Save::URL::FileSystem::isReadOnly());
524 m_xRelativeFsysImg->set_visible(officecfg::Office::Common::Save::URL::FileSystem::isReadOnly());
526 m_xRelativeInetCB->set_active(officecfg::Office::Common::Save::URL::Internet::get());
527 m_xRelativeInetCB->set_sensitive(!officecfg::Office::Common::Save::URL::Internet::isReadOnly());
528 m_xRelativeInetImg->set_visible(officecfg::Office::Common::Save::URL::Internet::isReadOnly());
530 sal_Int32 nDefaultVersion = GetODFDefaultVersion();
531 m_xODFVersionLB->set_active_id(OUString::number(nDefaultVersion));
532 m_xODFVersionLB->set_sensitive(!officecfg::Office::Common::Save::ODF::DefaultVersion::isReadOnly());
533 m_xODFVersionFT->set_sensitive(!officecfg::Office::Common::Save::ODF::DefaultVersion::isReadOnly());
534 m_xODFVersionImg->set_visible(officecfg::Office::Common::Save::ODF::DefaultVersion::isReadOnly());
536 AutoClickHdl_Impl(*m_xAutoSaveCB);
537 ODFVersionHdl_Impl(*m_xODFVersionLB);
539 m_xDocInfoCB->save_state();
540 m_xBackupCB->save_state();
541 m_xBackupIntoDocumentFolderCB->save_state();
542 m_xWarnAlienFormatCB->save_state();
543 m_xAutoSaveCB->save_state();
544 m_xAutoSaveEdit->save_value();
546 m_xUserAutoSaveCB->save_state();
548 m_xRelativeFsysCB->save_state();
549 m_xRelativeInetCB->save_state();
550 m_xODFVersionLB->save_value();
553 IMPL_LINK(SvxSaveTabPage, AutoClickHdl_Impl, weld::Toggleable&, rBox, void)
555 if (&rBox != m_xAutoSaveCB.get())
556 return;
558 if (m_xAutoSaveCB->get_active())
560 m_xAutoSaveEdit->set_sensitive(!officecfg::Office::Recovery::AutoSave::Enabled::isReadOnly());
561 m_xMinuteFT->set_sensitive(!officecfg::Office::Recovery::AutoSave::Enabled::isReadOnly());
562 m_xUserAutoSaveCB->set_sensitive(!officecfg::Office::Recovery::AutoSave::UserAutoSaveEnabled::isReadOnly());
564 else
566 m_xAutoSaveEdit->set_sensitive(false);
567 m_xMinuteFT->set_sensitive(false);
568 m_xUserAutoSaveCB->set_sensitive(false);
572 IMPL_LINK_NOARG(SvxSaveTabPage, BackupClickHdl_Impl, weld::Toggleable&, void)
574 m_xBackupIntoDocumentFolderCB->set_sensitive(m_xBackupCB->get_active() &&
575 !officecfg::Office::Common::Save::Document::BackupIntoDocumentFolder::isReadOnly());
578 static OUString lcl_ExtracUIName(const Sequence<PropertyValue> &rProperties, std::u16string_view rExtension)
580 OUString sName;
581 for (auto& propVal : rProperties)
583 const OUString &rName = propVal.Name;
584 if (rName == "UIName")
586 OUString sUIName;
587 if ((propVal.Value >>= sUIName) && sUIName.getLength())
589 if (!rExtension.empty())
590 sUIName += OUString::Concat(" (") + rExtension + ")";
591 return sUIName;
594 else if (rName == "Name")
596 propVal.Value >>= sName;
600 OSL_ENSURE( false, "Filter without UIName!" );
602 return sName;
605 IMPL_LINK( SvxSaveTabPage, FilterHdl_Impl, weld::ComboBox&, rBox, void )
607 const int nCurPos = m_xDocTypeLB->get_active();
609 int nData = -1;
610 if (nCurPos < APP_COUNT)
611 nData = m_xDocTypeLB->get_id(nCurPos).toInt32();
613 if ( nData >= 0 && nData < APP_COUNT )
615 if(m_xDocTypeLB.get() == &rBox)
617 m_xSaveAsLB->clear();
618 auto & rFilters = pImpl->aFilterArr[nData];
619 if(pImpl->aUIFilterArr[nData].empty())
621 pImpl->aUIFilterArr[nData].resize(pImpl->aFilterArr[nData].size());
622 auto & rUIFilters = pImpl->aUIFilterArr[nData];
623 for(size_t nFilter = 0; nFilter < pImpl->aFilterArr[nData].size(); nFilter++)
625 Any aProps = pImpl->xFact->getByName(rFilters[nFilter]);
626 // get the extension of the filter
627 OUString extension;
628 SfxFilterMatcher matcher;
629 std::shared_ptr<const SfxFilter> pFilter = matcher.GetFilter4FilterName(rFilters[nFilter]);
630 if (pFilter)
632 extension = pFilter->GetWildcard().getGlob().getToken(0, ';');
634 Sequence<PropertyValue> aProperties;
635 aProps >>= aProperties;
636 rUIFilters[nFilter] = lcl_ExtracUIName(aProperties, extension);
639 auto const & rUIFilters = pImpl->aUIFilterArr[nData];
640 OUString sSelect;
641 for(size_t i = 0; i < pImpl->aUIFilterArr[nData].size(); i++)
643 OUString sId;
644 if (pImpl->aODFArr[nData][i])
645 sId = weld::toId(pImpl.get());
646 m_xSaveAsLB->append(sId, rUIFilters[i]);
647 if (rFilters[i] == pImpl->aDefaultArr[nData])
648 sSelect = rUIFilters[i];
650 if (!sSelect.isEmpty())
652 m_xSaveAsLB->set_active_text(sSelect);
655 m_xSaveAsFT->set_sensitive(!pImpl->aDefaultReadonlyArr[nData]);
656 m_xSaveAsLB->set_sensitive(!pImpl->aDefaultReadonlyArr[nData]);
658 else
660 OUString sSelect = rBox.get_active_text();
661 auto const & rFilters = pImpl->aFilterArr[nData];
662 auto const & rUIFilters = pImpl->aUIFilterArr[nData];
663 for(size_t i = 0; i < pImpl->aUIFilterArr[nData].size(); i++)
664 if(rUIFilters[i] == sSelect)
666 sSelect = rFilters[i];
667 break;
670 pImpl->aDefaultArr[nData] = sSelect;
674 ODFVersionHdl_Impl( *m_xSaveAsLB );
677 IMPL_LINK_NOARG(SvxSaveTabPage, ODFVersionHdl_Impl, weld::ComboBox&, void)
679 sal_Int32 nVersion = m_xODFVersionLB->get_active_id().toInt32();
680 bool bShown = SvtSaveOptions::ODFDefaultVersion(nVersion) != SvtSaveOptions::ODFVER_LATEST;
681 if ( bShown )
683 bool bHasODFFormat = false;
684 const int nCount = m_xSaveAsLB->get_count();
685 for (int i = 0; i < nCount; ++i )
687 if ( m_xSaveAsLB->get_id(i).toInt64() != 0 )
689 bHasODFFormat = true;
690 break;
694 bShown = !bHasODFFormat
695 || ( m_xSaveAsLB->get_active_id().toInt64() != 0);
698 m_xODFWarningFI->set_visible(bShown);
699 m_xODFWarningFT->set_visible(bShown);
702 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */