Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / sfx2 / source / appl / appcfg.cxx
blobc9495eea5d161af9bae0d285ba7215503e6ff38c
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 <memory>
21 #include <comphelper/sequence.hxx>
22 #include <osl/file.hxx>
24 #include <rtl/ustring.hxx>
25 #include <svl/itempool.hxx>
26 #include <svl/itemset.hxx>
27 #include <svl/aeitem.hxx>
28 #include <svl/slstitm.hxx>
29 #include <svl/stritem.hxx>
30 #include <svl/intitem.hxx>
31 #include <svl/eitem.hxx>
32 #include <svl/undo.hxx>
34 #include <sfx2/sfxsids.hrc>
36 #include <svl/isethint.hxx>
38 #include <officecfg/Inet.hxx>
39 #include <officecfg/Office/Common.hxx>
40 #include <unotools/saveopt.hxx>
41 #include <svtools/helpopt.hxx>
42 #include <unotools/securityoptions.hxx>
43 #include <unotools/pathoptions.hxx>
44 #include <svtools/miscopt.hxx>
45 #include <svtools/imgdef.hxx>
46 #include <vcl/toolbox.hxx>
47 #include <sal/log.hxx>
48 #include <vcl/idle.hxx>
50 #include <sfx2/app.hxx>
51 #include <sfx2/event.hxx>
52 #include <sfx2/viewfrm.hxx>
53 #include <sfx2/dispatch.hxx>
54 #include <sfx2/objsh.hxx>
55 #include <objshimp.hxx>
56 #include "shutdownicon.hxx"
58 using namespace ::com::sun::star::uno;
59 using namespace ::com::sun::star::util;
60 using namespace ::com::sun::star::beans;
62 namespace {
64 class SfxEventAsyncer_Impl : public SfxListener
66 SfxEventHint aHint;
67 std::unique_ptr<Idle> pIdle;
69 public:
71 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
72 explicit SfxEventAsyncer_Impl(const SfxEventHint& rHint);
73 DECL_LINK( IdleHdl, Timer*, void );
78 void SfxEventAsyncer_Impl::Notify( SfxBroadcaster&, const SfxHint& rHint )
80 if( rHint.GetId() == SfxHintId::Dying && pIdle->IsActive() )
82 pIdle->Stop();
83 delete this;
88 SfxEventAsyncer_Impl::SfxEventAsyncer_Impl( const SfxEventHint& rHint )
89 : aHint( rHint )
91 if( rHint.GetObjShell() )
92 StartListening( *rHint.GetObjShell() );
93 pIdle.reset( new Idle("SfxEventASyncer") );
94 pIdle->SetInvokeHandler( LINK(this, SfxEventAsyncer_Impl, IdleHdl) );
95 pIdle->SetPriority( TaskPriority::HIGH_IDLE );
96 pIdle->SetDebugName( "sfx::SfxEventAsyncer_Impl pIdle" );
97 pIdle->Start();
101 IMPL_LINK(SfxEventAsyncer_Impl, IdleHdl, Timer*, pAsyncIdle, void)
103 SfxObjectShellRef xRef( aHint.GetObjShell() );
104 pAsyncIdle->Stop();
105 SAL_INFO_IF(!xRef.is(), "sfx.appl", "SfxEvent: " << aHint.GetEventName());
106 SfxGetpApp()->Broadcast( aHint );
107 if ( xRef.is() )
108 xRef->Broadcast( aHint );
109 delete this;
113 void SfxApplication::GetOptions( SfxItemSet& rSet )
115 bool bRet = false;
116 SfxItemPool &rPool = GetPool();
118 const sal_uInt16 *pRanges = rSet.GetRanges();
119 SvtSaveOptions aSaveOptions;
120 SvtHelpOptions aHelpOptions;
121 SvtSecurityOptions aSecurityOptions;
122 SvtMiscOptions aMiscOptions;
124 while ( *pRanges )
126 for(sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich)
128 switch(nWhich)
130 case SID_ATTR_BUTTON_BIGSIZE :
132 if( rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_BUTTON_BIGSIZE ), aMiscOptions.AreCurrentSymbolsLarge() ) ) )
133 bRet = true;
134 break;
136 case SID_ATTR_BACKUP :
138 bRet = true;
139 if (!aSaveOptions.IsReadOnly(SvtSaveOptions::EOption::Backup))
140 if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_BACKUP ),aSaveOptions.IsBackup())))
141 bRet = false;
143 break;
144 case SID_ATTR_PRETTYPRINTING:
146 bRet = true;
147 if (!aSaveOptions.IsReadOnly(SvtSaveOptions::EOption::DoPrettyPrinting))
148 if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_PRETTYPRINTING ), aSaveOptions.IsPrettyPrinting())))
149 bRet = false;
151 break;
152 case SID_ATTR_WARNALIENFORMAT:
154 bRet = true;
155 if (!aSaveOptions.IsReadOnly(SvtSaveOptions::EOption::WarnAlienFormat))
156 if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_WARNALIENFORMAT ), aSaveOptions.IsWarnAlienFormat())))
157 bRet = false;
159 break;
160 case SID_ATTR_AUTOSAVE :
162 bRet = true;
163 if (!aSaveOptions.IsReadOnly(SvtSaveOptions::EOption::AutoSave))
164 if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_AUTOSAVE ), aSaveOptions.IsAutoSave())))
165 bRet = false;
167 break;
168 case SID_ATTR_AUTOSAVEPROMPT :
170 bRet = true;
171 if (!aSaveOptions.IsReadOnly(SvtSaveOptions::EOption::AutoSavePrompt))
172 if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_AUTOSAVEPROMPT ), aSaveOptions.IsAutoSavePrompt())))
173 bRet = false;
175 break;
176 case SID_ATTR_AUTOSAVEMINUTE :
178 bRet = true;
179 if (!aSaveOptions.IsReadOnly(SvtSaveOptions::EOption::AutoSaveTime))
180 if (!rSet.Put( SfxUInt16Item( rPool.GetWhich( SID_ATTR_AUTOSAVEMINUTE ), static_cast<sal_uInt16>(aSaveOptions.GetAutoSaveTime()))))
181 bRet = false;
183 break;
184 case SID_ATTR_USERAUTOSAVE :
186 bRet = true;
187 if (!aSaveOptions.IsReadOnly(SvtSaveOptions::EOption::UserAutoSave))
188 if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_USERAUTOSAVE ), aSaveOptions.IsUserAutoSave())))
189 bRet = false;
191 break;
192 case SID_ATTR_DOCINFO :
194 bRet = true;
195 if (!aSaveOptions.IsReadOnly(SvtSaveOptions::EOption::DocInfSave))
196 if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_DOCINFO ), aSaveOptions.IsDocInfoSave())))
197 bRet = false;
199 break;
200 case SID_ATTR_WORKINGSET :
202 bRet = true;
203 if (!aSaveOptions.IsReadOnly(SvtSaveOptions::EOption::SaveWorkingSet))
204 if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_WORKINGSET ), aSaveOptions.IsSaveWorkingSet())))
205 bRet = false;
207 break;
208 case SID_ATTR_SAVEDOCVIEW :
210 bRet = true;
211 if (!aSaveOptions.IsReadOnly(SvtSaveOptions::EOption::SaveDocView))
212 if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_SAVEDOCVIEW ), aSaveOptions.IsSaveDocView())))
213 bRet = false;
215 break;
216 case SID_ATTR_METRIC :
217 break;
218 case SID_HELPBALLOONS :
219 if(rSet.Put( SfxBoolItem ( rPool.GetWhich( SID_HELPBALLOONS ),
220 aHelpOptions.IsExtendedHelp() ) ) )
221 bRet = true;
222 break;
223 case SID_HELPTIPS :
224 if(rSet.Put( SfxBoolItem ( rPool.GetWhich( SID_HELPTIPS ),
225 aHelpOptions.IsHelpTips() ) ) )
226 bRet = true;
227 break;
228 case SID_HELP_STYLESHEET :
229 if(rSet.Put( SfxStringItem ( rPool.GetWhich( SID_HELP_STYLESHEET ),
230 aHelpOptions.GetHelpStyleSheet() ) ) )
231 bRet = true;
232 break;
233 case SID_ATTR_UNDO_COUNT :
234 if (rSet.Put(
235 SfxUInt16Item (
236 rPool.GetWhich(SID_ATTR_UNDO_COUNT),
237 officecfg::Office::Common::Undo::Steps::get())))
239 bRet = true;
241 break;
242 case SID_ATTR_QUICKLAUNCHER :
244 if ( ShutdownIcon::IsQuickstarterInstalled() )
246 if ( rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_QUICKLAUNCHER ),
247 ShutdownIcon::GetAutostart() ) ) )
248 bRet = true;
250 else
252 rSet.DisableItem( rPool.GetWhich( SID_ATTR_QUICKLAUNCHER ) );
253 bRet = true;
255 break;
257 case SID_SAVEREL_INET :
259 bRet = true;
260 if (!aSaveOptions.IsReadOnly(SvtSaveOptions::EOption::SaveRelInet))
261 if (!rSet.Put( SfxBoolItem ( rPool.GetWhich( SID_SAVEREL_INET ), aSaveOptions.IsSaveRelINet() )))
262 bRet = false;
264 break;
265 case SID_SAVEREL_FSYS :
267 bRet = true;
268 if (!aSaveOptions.IsReadOnly(SvtSaveOptions::EOption::SaveRelFsys))
269 if (!rSet.Put( SfxBoolItem ( rPool.GetWhich( SID_SAVEREL_FSYS ), aSaveOptions.IsSaveRelFSys() )))
270 bRet = false;
272 break;
273 case SID_BASIC_ENABLED :
275 bRet = true;
276 if (!aSecurityOptions.IsReadOnly(SvtSecurityOptions::EOption::BasicMode))
278 if ( !rSet.Put( SfxUInt16Item( rPool.GetWhich( SID_BASIC_ENABLED ), sal::static_int_cast< sal_uInt16 >(aSecurityOptions.GetBasicMode()))))
279 bRet = false;
282 break;
283 case SID_INET_EXE_PLUGIN :
285 bRet = true;
286 if (!aSecurityOptions.IsReadOnly(SvtSecurityOptions::EOption::ExecutePlugins))
288 if ( !rSet.Put( SfxBoolItem( SID_INET_EXE_PLUGIN, aSecurityOptions.IsExecutePlugins() ) ) )
289 bRet = false;
292 break;
293 case SID_MACRO_WARNING :
295 bRet = true;
296 if (!aSecurityOptions.IsReadOnly(SvtSecurityOptions::EOption::Warning))
298 if ( !rSet.Put( SfxBoolItem( SID_MACRO_WARNING, aSecurityOptions.IsWarningEnabled() ) ) )
299 bRet = false;
302 break;
303 case SID_MACRO_CONFIRMATION :
305 bRet = true;
306 if (!aSecurityOptions.IsReadOnly(SvtSecurityOptions::EOption::Confirmation))
308 if ( !rSet.Put( SfxBoolItem( SID_MACRO_CONFIRMATION, aSecurityOptions.IsConfirmationEnabled() ) ) )
309 bRet = false;
312 break;
313 case SID_SECURE_URL :
315 bRet = true;
316 if (!aSecurityOptions.IsReadOnly(SvtSecurityOptions::EOption::SecureUrls))
318 css::uno::Sequence< OUString > seqURLs = aSecurityOptions.GetSecureURLs();
319 auto aList = comphelper::sequenceToContainer<std::vector<OUString>>(seqURLs);
321 if( !rSet.Put( SfxStringListItem( rPool.GetWhich(SID_SECURE_URL), &aList ) ) )
322 bRet = false;
325 break;
326 case SID_INET_PROXY_TYPE :
327 if (rSet.Put(
328 SfxUInt16Item(
329 rPool.GetWhich(SID_INET_PROXY_TYPE),
330 (officecfg::Inet::Settings::ooInetProxyType::
331 get().value_or(0)))))
333 bRet = true;
335 break;
336 case SID_INET_HTTP_PROXY_NAME :
337 if (rSet.Put(
338 SfxStringItem(
339 rPool.GetWhich(SID_INET_HTTP_PROXY_NAME),
340 officecfg::Inet::Settings::ooInetHTTPProxyName::
341 get())))
343 bRet = true;
345 break;
346 case SID_INET_HTTP_PROXY_PORT :
347 if (rSet.Put(
348 SfxInt32Item(
349 rPool.GetWhich(SID_INET_HTTP_PROXY_PORT),
350 (officecfg::Inet::Settings::
351 ooInetHTTPProxyPort::get().value_or(0)))))
353 bRet = true;
355 break;
356 case SID_INET_FTP_PROXY_NAME :
357 if (rSet.Put(
358 SfxStringItem(
359 rPool.GetWhich(SID_INET_FTP_PROXY_NAME),
360 officecfg::Inet::Settings::ooInetFTPProxyName::
361 get())))
363 bRet = true;
365 break;
366 case SID_INET_FTP_PROXY_PORT :
367 if (rSet.Put(
368 SfxInt32Item(
369 rPool.GetWhich(SID_INET_FTP_PROXY_PORT),
370 (officecfg::Inet::Settings::ooInetFTPProxyPort::
371 get().value_or(0)))))
373 bRet = true;
375 break;
376 case SID_INET_NOPROXY :
377 if (rSet.Put(
378 SfxStringItem(
379 rPool.GetWhich( SID_INET_NOPROXY),
380 (officecfg::Inet::Settings::ooInetNoProxy::
381 get()))))
383 bRet = true;
385 break;
386 case SID_ATTR_PATHNAME :
388 SfxAllEnumItem aValues(rPool.GetWhich(SID_ATTR_PATHNAME));
389 SvtPathOptions aPathCfg;
390 for ( sal_uInt16 nProp = SvtPathOptions::PATH_ADDIN;
391 nProp <= SvtPathOptions::PATH_WORK; nProp++ )
393 OUString aValue;
394 switch ( nProp )
396 case SvtPathOptions::PATH_ADDIN: osl::FileBase::getFileURLFromSystemPath( aPathCfg.GetAddinPath(), aValue ); break;
397 case SvtPathOptions::PATH_AUTOCORRECT: aValue = aPathCfg.GetAutoCorrectPath(); break;
398 case SvtPathOptions::PATH_AUTOTEXT: aValue = aPathCfg.GetAutoTextPath(); break;
399 case SvtPathOptions::PATH_BACKUP: aValue = aPathCfg.GetBackupPath(); break;
400 case SvtPathOptions::PATH_BASIC: aValue = aPathCfg.GetBasicPath(); break;
401 case SvtPathOptions::PATH_BITMAP: aValue = aPathCfg.GetBitmapPath(); break;
402 case SvtPathOptions::PATH_CONFIG: aValue = aPathCfg.GetConfigPath(); break;
403 case SvtPathOptions::PATH_DICTIONARY: aValue = aPathCfg.GetDictionaryPath(); break;
404 case SvtPathOptions::PATH_FAVORITES: aValue = aPathCfg.GetFavoritesPath(); break;
405 case SvtPathOptions::PATH_FILTER: osl::FileBase::getFileURLFromSystemPath( aPathCfg.GetFilterPath(), aValue ); break;
406 case SvtPathOptions::PATH_GALLERY: aValue = aPathCfg.GetGalleryPath(); break;
407 case SvtPathOptions::PATH_GRAPHIC: aValue = aPathCfg.GetGraphicPath(); break;
408 case SvtPathOptions::PATH_HELP: osl::FileBase::getFileURLFromSystemPath( aPathCfg.GetHelpPath(), aValue ); break;
409 case SvtPathOptions::PATH_LINGUISTIC: aValue = aPathCfg.GetLinguisticPath(); break;
410 case SvtPathOptions::PATH_MODULE: osl::FileBase::getFileURLFromSystemPath( aPathCfg.GetModulePath(), aValue ); break;
411 case SvtPathOptions::PATH_PALETTE: aValue = aPathCfg.GetPalettePath(); break;
412 case SvtPathOptions::PATH_PLUGIN: osl::FileBase::getFileURLFromSystemPath( aPathCfg.GetPluginPath(), aValue ); break;
413 case SvtPathOptions::PATH_STORAGE: osl::FileBase::getFileURLFromSystemPath( aPathCfg.GetStoragePath(), aValue ); break;
414 case SvtPathOptions::PATH_TEMP: aValue = aPathCfg.GetTempPath(); break;
415 case SvtPathOptions::PATH_TEMPLATE: aValue = aPathCfg.GetTemplatePath(); break;
416 case SvtPathOptions::PATH_USERCONFIG: aValue = aPathCfg.GetUserConfigPath(); break;
417 case SvtPathOptions::PATH_WORK: aValue = aPathCfg.GetWorkPath(); break;
419 aValues.SetTextByPos( nProp, aValue );
422 if (rSet.Put(aValues))
423 bRet = true;
425 break;
427 default:
428 SAL_INFO( "sfx.appl", "W1:Wrong ID while getting Options!" );
429 break;
431 SAL_WARN_IF(!bRet, "sfx.appl", "Putting options failed!");
433 pRanges++;
437 // TODO/CLEANUP: Why two SetOptions Methods?
438 void SfxApplication::SetOptions_Impl( const SfxItemSet& rSet )
440 const SfxPoolItem *pItem = nullptr;
441 SfxItemPool &rPool = GetPool();
443 SvtSaveOptions aSaveOptions;
444 SvtHelpOptions aHelpOptions;
445 SvtSecurityOptions aSecurityOptions;
446 SvtMiscOptions aMiscOptions;
447 std::shared_ptr< comphelper::ConfigurationChanges > batch(
448 comphelper::ConfigurationChanges::create());
450 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_BUTTON_BIGSIZE), true, &pItem) )
452 DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) != nullptr, "BoolItem expected");
453 bool bBigSize = static_cast<const SfxBoolItem*>(pItem)->GetValue();
454 aMiscOptions.SetSymbolsSize(
455 sal::static_int_cast< sal_Int16 >(
456 bBigSize ? SFX_SYMBOLS_SIZE_LARGE : SFX_SYMBOLS_SIZE_SMALL ) );
457 SfxViewFrame* pCurrViewFrame = SfxViewFrame::GetFirst();
458 while ( pCurrViewFrame )
460 // update all "final" dispatchers
461 pCurrViewFrame->GetDispatcher()->Update_Impl(true);
462 pCurrViewFrame = SfxViewFrame::GetNext(*pCurrViewFrame);
466 // Backup
467 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_BACKUP), true, &pItem) )
469 DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) != nullptr, "BoolItem expected");
470 aSaveOptions.SetBackup( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
473 // PrettyPrinting
474 if ( SfxItemState::SET == rSet.GetItemState( rPool.GetWhich( SID_ATTR_PRETTYPRINTING ), true, &pItem ) )
476 DBG_ASSERT( dynamic_cast< const SfxBoolItem *>( pItem ) != nullptr, "BoolItem expected" );
477 aSaveOptions.SetPrettyPrinting( static_cast< const SfxBoolItem*> ( pItem )->GetValue() );
480 // WarnAlienFormat
481 if ( SfxItemState::SET == rSet.GetItemState( rPool.GetWhich( SID_ATTR_WARNALIENFORMAT ), true, &pItem ) )
483 DBG_ASSERT( dynamic_cast< const SfxBoolItem *>( pItem ) != nullptr, "BoolItem expected" );
484 aSaveOptions.SetWarnAlienFormat( static_cast< const SfxBoolItem*> ( pItem )->GetValue() );
487 // AutoSave
488 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_AUTOSAVE), true, &pItem))
490 DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) != nullptr, "BoolItem expected");
491 aSaveOptions.SetAutoSave( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
494 // AutoSave-Prompt
495 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_AUTOSAVEPROMPT), true, &pItem))
497 DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) != nullptr, "BoolItem expected");
498 aSaveOptions.SetAutoSavePrompt(static_cast<const SfxBoolItem *>(pItem)->GetValue());
501 // AutoSave-Time
502 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_AUTOSAVEMINUTE), true, &pItem))
504 DBG_ASSERT(dynamic_cast< const SfxUInt16Item *>( pItem ) != nullptr, "UInt16Item expected");
505 aSaveOptions.SetAutoSaveTime(static_cast<const SfxUInt16Item *>(pItem)->GetValue());
508 // UserAutoSave
509 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_USERAUTOSAVE), true, &pItem))
511 DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) != nullptr, "BoolItem expected");
512 aSaveOptions.SetUserAutoSave( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
515 // DocInfo
516 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_DOCINFO), true, &pItem))
518 DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) != nullptr, "BoolItem expected");
519 aSaveOptions.SetDocInfoSave(static_cast<const SfxBoolItem *>(pItem)->GetValue());
522 // Mark open Documents
523 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_WORKINGSET), true, &pItem))
525 DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) != nullptr, "BoolItem expected");
526 aSaveOptions.SetSaveWorkingSet(static_cast<const SfxBoolItem *>(pItem)->GetValue());
529 // Save window settings
530 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_SAVEDOCVIEW), true, &pItem))
532 DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) != nullptr, "BoolItem expected");
533 aSaveOptions.SetSaveDocView(static_cast<const SfxBoolItem *>(pItem)->GetValue());
536 // Metric
537 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_METRIC), true, &pItem))
539 DBG_ASSERT(dynamic_cast< const SfxUInt16Item *>( pItem ) != nullptr, "UInt16Item expected");
542 // HelpBalloons
543 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_HELPBALLOONS), true, &pItem))
545 DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) != nullptr, "BoolItem expected");
546 aHelpOptions.SetExtendedHelp(static_cast<const SfxBoolItem *>(pItem)->GetValue());
549 // HelpTips
550 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_HELPTIPS), true, &pItem))
552 DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) != nullptr, "BoolItem expected");
553 aHelpOptions.SetHelpTips( static_cast<const SfxBoolItem *>(pItem)->GetValue());
556 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_HELP_STYLESHEET ), true, &pItem))
558 DBG_ASSERT(dynamic_cast< const SfxStringItem *>( pItem ) != nullptr, "StringItem expected");
559 aHelpOptions.SetHelpStyleSheet( static_cast<const SfxStringItem *>(pItem)->GetValue() );
562 // SaveRelINet
563 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_SAVEREL_INET), true, &pItem))
565 DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) != nullptr, "BoolItem expected");
566 aSaveOptions.SetSaveRelINet(static_cast<const SfxBoolItem *>(pItem)->GetValue());
569 // SaveRelFSys
570 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_SAVEREL_FSYS), true, &pItem))
572 DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) != nullptr, "BoolItem expected");
573 aSaveOptions.SetSaveRelFSys(static_cast<const SfxBoolItem *>(pItem)->GetValue());
576 // Undo-Count
577 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_UNDO_COUNT), true, &pItem))
579 DBG_ASSERT(dynamic_cast< const SfxUInt16Item *>( pItem ) != nullptr, "UInt16Item expected");
580 sal_uInt16 nUndoCount = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
581 officecfg::Office::Common::Undo::Steps::set(nUndoCount, batch);
583 // To catch all Undo-Managers: Iterate over all Frames
584 for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst();
585 pFrame;
586 pFrame = SfxViewFrame::GetNext(*pFrame) )
588 // Get the Dispatcher of the Frames
589 SfxDispatcher *pDispat = pFrame->GetDispatcher();
590 pDispat->Flush();
592 // Iterate over all SfxShells on the Dispatchers Stack
593 sal_uInt16 nIdx = 0;
594 for ( SfxShell *pSh = pDispat->GetShell(nIdx);
595 pSh;
596 ++nIdx, pSh = pDispat->GetShell(nIdx) )
598 SfxUndoManager *pShUndoMgr = pSh->GetUndoManager();
599 if ( pShUndoMgr )
600 pShUndoMgr->SetMaxUndoActionCount( nUndoCount );
605 // Office autostart
606 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_QUICKLAUNCHER), true, &pItem))
608 DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) != nullptr, "BoolItem expected");
609 ShutdownIcon::SetAutostart( static_cast<const SfxBoolItem*>( pItem )->GetValue() );
612 // StarBasic Enable
613 if ( SfxItemState::SET == rSet.GetItemState(SID_BASIC_ENABLED, true, &pItem))
615 DBG_ASSERT(dynamic_cast< const SfxUInt16Item *>( pItem ) != nullptr, "SfxInt16Item expected");
616 aSecurityOptions.SetBasicMode( static_cast<EBasicSecurityMode>(static_cast<const SfxUInt16Item*>( pItem )->GetValue()) );
619 // Execute PlugIns
620 if ( SfxItemState::SET == rSet.GetItemState(SID_INET_EXE_PLUGIN, true, &pItem))
622 DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) != nullptr, "SfxBoolItem expected");
623 aSecurityOptions.SetExecutePlugins( static_cast<const SfxBoolItem *>( pItem )->GetValue() );
626 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_INET_PROXY_TYPE), true, &pItem))
628 DBG_ASSERT( dynamic_cast< const SfxUInt16Item *>( pItem ) != nullptr, "UInt16Item expected" );
629 officecfg::Inet::Settings::ooInetProxyType::set(
630 static_cast< SfxUInt16Item const * >(pItem)->GetValue(), batch);
633 if ( SfxItemState::SET == rSet.GetItemState( rPool.GetWhich( SID_INET_HTTP_PROXY_NAME ), true, &pItem ) )
635 DBG_ASSERT( dynamic_cast< const SfxStringItem *>( pItem ) != nullptr, "StringItem expected" );
636 officecfg::Inet::Settings::ooInetHTTPProxyName::set(
637 static_cast< SfxStringItem const * >(pItem)->GetValue(), batch);
639 if ( SfxItemState::SET == rSet.GetItemState( rPool.GetWhich( SID_INET_HTTP_PROXY_PORT ), true, &pItem ) )
641 DBG_ASSERT( dynamic_cast< const SfxInt32Item *>( pItem ) != nullptr, "Int32Item expected" );
642 officecfg::Inet::Settings::ooInetHTTPProxyPort::set(
643 static_cast< SfxInt32Item const * >(pItem)->GetValue(), batch);
645 if ( SfxItemState::SET == rSet.GetItemState( rPool.GetWhich( SID_INET_FTP_PROXY_NAME ), true, &pItem ) )
647 DBG_ASSERT( dynamic_cast< const SfxStringItem *>( pItem ) != nullptr, "StringItem expected" );
648 officecfg::Inet::Settings::ooInetFTPProxyName::set(
649 static_cast< SfxStringItem const * >(pItem)->GetValue(), batch);
651 if ( SfxItemState::SET == rSet.GetItemState( rPool.GetWhich( SID_INET_FTP_PROXY_PORT ), true, &pItem ) )
653 DBG_ASSERT( dynamic_cast< const SfxInt32Item *>( pItem ) != nullptr, "Int32Item expected" );
654 officecfg::Inet::Settings::ooInetFTPProxyPort::set(
655 static_cast< SfxInt32Item const * >(pItem)->GetValue(), batch);
657 if ( SfxItemState::SET == rSet.GetItemState(SID_INET_NOPROXY, true, &pItem))
659 DBG_ASSERT(dynamic_cast< const SfxStringItem *>( pItem ) != nullptr, "StringItem expected");
660 officecfg::Inet::Settings::ooInetNoProxy::set(
661 static_cast< SfxStringItem const * >(pItem)->GetValue(), batch);
664 // Secure-Referrer
665 if ( SfxItemState::SET == rSet.GetItemState(SID_SECURE_URL, true, &pItem))
667 DBG_ASSERT(dynamic_cast< const SfxStringListItem *>( pItem ) != nullptr, "StringListItem expected");
668 css::uno::Sequence< OUString > seqURLs;
669 static_cast<const SfxStringListItem*>(pItem)->GetStringList(seqURLs);
670 aSecurityOptions.SetSecureURLs( seqURLs );
673 if ( SfxItemState::SET == rSet.GetItemState(SID_MACRO_WARNING, true, &pItem))
675 DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) != nullptr, "SfxBoolItem expected");
676 aSecurityOptions.SetWarningEnabled( static_cast<const SfxBoolItem *>(pItem)->GetValue() );
678 if ( SfxItemState::SET == rSet.GetItemState(SID_MACRO_CONFIRMATION, true, &pItem))
680 DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) != nullptr, "SfxBoolItem expected");
681 aSecurityOptions.SetConfirmationEnabled( static_cast<const SfxBoolItem *>(pItem)->GetValue() );
684 // Store changed data
685 batch->commit();
689 void SfxApplication::SetOptions(const SfxItemSet &rSet)
691 SvtPathOptions aPathOptions;
693 // Data is saved in DocInfo and IniManager
694 const SfxPoolItem *pItem = nullptr;
695 SfxItemPool &rPool = GetPool();
697 SfxAllItemSet aSendSet( rSet );
699 // PathName
700 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_PATHNAME), true, &pItem))
702 DBG_ASSERT(dynamic_cast< const SfxAllEnumItem *>( pItem ) != nullptr, "AllEnumItem expected");
703 const SfxAllEnumItem* pEnumItem = static_cast<const SfxAllEnumItem *>(pItem);
704 sal_uInt32 nCount = pEnumItem->GetTextCount();
705 OUString aNoChangeStr( ' ' );
706 for( sal_uInt32 nPath=0; nPath<nCount; ++nPath )
708 const OUString& sValue = pEnumItem->GetTextByPos(static_cast<sal_uInt16>(nPath));
709 if ( sValue != aNoChangeStr )
711 switch( nPath )
713 case SvtPathOptions::PATH_ADDIN:
715 OUString aTmp;
716 if( osl::FileBase::getSystemPathFromFileURL( sValue, aTmp ) == osl::FileBase::E_None )
717 aPathOptions.SetAddinPath( aTmp );
718 break;
721 case SvtPathOptions::PATH_AUTOCORRECT: aPathOptions.SetAutoCorrectPath( sValue );break;
722 case SvtPathOptions::PATH_AUTOTEXT: aPathOptions.SetAutoTextPath( sValue );break;
723 case SvtPathOptions::PATH_BACKUP: aPathOptions.SetBackupPath( sValue );break;
724 case SvtPathOptions::PATH_BASIC: aPathOptions.SetBasicPath( sValue );break;
725 case SvtPathOptions::PATH_BITMAP: aPathOptions.SetBitmapPath( sValue );break;
726 case SvtPathOptions::PATH_CONFIG: aPathOptions.SetConfigPath( sValue );break;
727 case SvtPathOptions::PATH_DICTIONARY: aPathOptions.SetDictionaryPath( sValue );break;
728 case SvtPathOptions::PATH_FAVORITES: aPathOptions.SetFavoritesPath( sValue );break;
729 case SvtPathOptions::PATH_FILTER:
731 OUString aTmp;
732 if( osl::FileBase::getSystemPathFromFileURL( sValue, aTmp ) == osl::FileBase::E_None )
733 aPathOptions.SetFilterPath( aTmp );
734 break;
736 case SvtPathOptions::PATH_GALLERY: aPathOptions.SetGalleryPath( sValue );break;
737 case SvtPathOptions::PATH_GRAPHIC: aPathOptions.SetGraphicPath( sValue );break;
738 case SvtPathOptions::PATH_HELP:
740 OUString aTmp;
741 if( osl::FileBase::getSystemPathFromFileURL( sValue, aTmp ) == osl::FileBase::E_None )
742 aPathOptions.SetHelpPath( aTmp );
743 break;
746 case SvtPathOptions::PATH_LINGUISTIC: aPathOptions.SetLinguisticPath( sValue );break;
747 case SvtPathOptions::PATH_MODULE:
749 OUString aTmp;
750 if( osl::FileBase::getSystemPathFromFileURL( sValue, aTmp ) == osl::FileBase::E_None )
751 aPathOptions.SetModulePath( aTmp );
752 break;
755 case SvtPathOptions::PATH_PALETTE: aPathOptions.SetPalettePath( sValue );break;
756 case SvtPathOptions::PATH_PLUGIN:
758 OUString aTmp;
759 if( osl::FileBase::getSystemPathFromFileURL( sValue, aTmp ) == osl::FileBase::E_None )
760 aPathOptions.SetPluginPath( aTmp );
761 break;
764 case SvtPathOptions::PATH_STORAGE:
766 OUString aTmp;
767 if( osl::FileBase::getSystemPathFromFileURL( sValue, aTmp ) == osl::FileBase::E_None )
768 aPathOptions.SetStoragePath( aTmp );
769 break;
772 case SvtPathOptions::PATH_TEMP: aPathOptions.SetTempPath( sValue );break;
773 case SvtPathOptions::PATH_TEMPLATE: aPathOptions.SetTemplatePath( sValue );break;
774 case SvtPathOptions::PATH_USERCONFIG: aPathOptions.SetUserConfigPath( sValue );break;
775 case SvtPathOptions::PATH_WORK: aPathOptions.SetWorkPath( sValue );break;
776 default: SAL_WARN( "sfx.appl", "SfxApplication::SetOptions_Impl() Invalid path number found for set directories!" );
781 aSendSet.ClearItem( rPool.GetWhich( SID_ATTR_PATHNAME ) );
784 SetOptions_Impl( rSet );
786 // Undo-Count
787 Broadcast( SfxItemSetHint( rSet ) );
791 void SfxApplication::NotifyEvent( const SfxEventHint& rEventHint, bool bSynchron )
793 SfxObjectShell *pDoc = rEventHint.GetObjShell();
794 if ( pDoc && ( pDoc->IsPreview() || !pDoc->Get_Impl()->bInitialized ) )
795 return;
797 if ( bSynchron )
799 SAL_INFO_IF(!pDoc, "sfx.appl", "SfxEvent: " << rEventHint.GetEventName());
800 Broadcast(rEventHint);
801 if ( pDoc )
802 pDoc->Broadcast( rEventHint );
804 else
805 new SfxEventAsyncer_Impl( rEventHint );
808 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */