Branch libreoffice-5-0-4
[LibreOffice.git] / sfx2 / source / appl / appcfg.cxx
blobf7b541433c4b4dd18f38d17fb52efe2fe010b378
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 <com/sun/star/uno/Reference.hxx>
21 #include <com/sun/star/frame/XDesktop.hpp>
22 #include <com/sun/star/util/XURLTransformer.hpp>
23 #include <com/sun/star/beans/PropertyValue.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/util/XFlushable.hpp>
27 #include <stdlib.h>
28 #include <vcl/msgbox.hxx>
29 #include <rtl/ustring.hxx>
30 #include <svl/itempool.hxx>
31 #include <svl/aeitem.hxx>
32 #include <svl/slstitm.hxx>
33 #include <svl/stritem.hxx>
34 #include <svl/intitem.hxx>
35 #include <svl/eitem.hxx>
36 #include <svl/szitem.hxx>
37 #include <svl/undo.hxx>
39 #include <sfx2/sfxsids.hrc>
40 #include <sot/exchange.hxx>
42 #include <svl/isethint.hxx>
44 #include <officecfg/Inet.hxx>
45 #include <officecfg/Office/Common.hxx>
46 #include <unotools/configmgr.hxx>
47 #include <tools/urlobj.hxx>
48 #include <unotools/saveopt.hxx>
49 #include <svtools/helpopt.hxx>
50 #include <unotools/securityoptions.hxx>
51 #include <unotools/pathoptions.hxx>
52 #include <svtools/miscopt.hxx>
53 #include <vcl/toolbox.hxx>
54 #include <unotools/localfilehelper.hxx>
55 #include <rtl/strbuf.hxx>
56 #include <rtl/ustrbuf.hxx>
57 #include <vcl/idle.hxx>
59 #include <sfx2/app.hxx>
60 #include <sfx2/docfile.hxx>
61 #include <sfx2/viewfrm.hxx>
62 #include <sfx2/sfxhelp.hxx>
63 #include "sfxtypes.hxx"
64 #include <sfx2/dispatch.hxx>
65 #include <sfx2/objsh.hxx>
66 #include "objshimp.hxx"
67 #include <sfx2/viewsh.hxx>
68 #include <sfx2/request.hxx>
69 #include <sfx2/evntconf.hxx>
70 #include "appdata.hxx"
71 #include "workwin.hxx"
72 #include "helper.hxx"
73 #include "app.hrc"
74 #include <sfx2/sfxresid.hxx>
75 #include "shutdownicon.hxx"
77 using namespace ::com::sun::star::uno;
78 using namespace ::com::sun::star::util;
79 using namespace ::com::sun::star::frame;
80 using namespace ::com::sun::star::beans;
84 class SfxEventAsyncer_Impl : public SfxListener
86 SfxEventHint aHint;
87 Idle* pIdle;
89 public:
91 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) SAL_OVERRIDE;
92 SfxEventAsyncer_Impl( const SfxEventHint& rHint );
93 virtual ~SfxEventAsyncer_Impl();
94 DECL_LINK_TYPED( IdleHdl, Idle*, void );
99 void SfxEventAsyncer_Impl::Notify( SfxBroadcaster&, const SfxHint& rHint )
101 const SfxSimpleHint* pHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
102 if( pHint && pHint->GetId() == SFX_HINT_DYING && pIdle->IsActive() )
104 pIdle->Stop();
105 delete this;
111 SfxEventAsyncer_Impl::SfxEventAsyncer_Impl( const SfxEventHint& rHint )
112 : aHint( rHint )
114 if( rHint.GetObjShell() )
115 StartListening( *rHint.GetObjShell() );
116 pIdle = new Idle;
117 pIdle->SetIdleHdl( LINK(this, SfxEventAsyncer_Impl, IdleHdl) );
118 pIdle->SetPriority( SchedulerPriority::HIGHEST );
119 pIdle->Start();
124 SfxEventAsyncer_Impl::~SfxEventAsyncer_Impl()
126 delete pIdle;
131 IMPL_LINK_TYPED(SfxEventAsyncer_Impl, IdleHdl, Idle*, pAsyncIdle, void)
133 SfxObjectShellRef xRef( aHint.GetObjShell() );
134 pAsyncIdle->Stop();
135 #ifdef DBG_UTIL
136 if (!xRef.Is())
138 OStringBuffer aTmp("SfxEvent: ");
139 aTmp.append(OUStringToOString(aHint.GetEventName(), RTL_TEXTENCODING_UTF8));
140 OSL_TRACE( "%s", aTmp.getStr() );
142 #endif
143 SfxGetpApp()->Broadcast( aHint );
144 if ( xRef.Is() )
145 xRef->Broadcast( aHint );
146 delete this;
152 bool SfxApplication::GetOptions( SfxItemSet& rSet )
154 bool bRet = false;
155 SfxItemPool &rPool = GetPool();
157 const sal_uInt16 *pRanges = rSet.GetRanges();
158 SvtSaveOptions aSaveOptions;
159 SvtHelpOptions aHelpOptions;
160 SvtSecurityOptions aSecurityOptions;
161 SvtMiscOptions aMiscOptions;
163 while ( *pRanges )
165 for(sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich)
167 switch(nWhich)
169 case SID_ATTR_BUTTON_OUTSTYLE3D :
170 if(rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_BUTTON_OUTSTYLE3D ),
171 aMiscOptions.GetToolboxStyle() != TOOLBOX_STYLE_FLAT)))
172 bRet = true;
173 break;
174 case SID_ATTR_BUTTON_BIGSIZE :
176 if( rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_BUTTON_BIGSIZE ), aMiscOptions.AreCurrentSymbolsLarge() ) ) )
177 bRet = true;
178 break;
180 case SID_ATTR_BACKUP :
182 bRet = true;
183 if (!aSaveOptions.IsReadOnly(SvtSaveOptions::E_BACKUP))
184 if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_BACKUP ),aSaveOptions.IsBackup())))
185 bRet = false;
187 break;
188 case SID_ATTR_PRETTYPRINTING:
190 bRet = true;
191 if (!aSaveOptions.IsReadOnly(SvtSaveOptions::E_DOPRETTYPRINTING))
192 if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_PRETTYPRINTING ), aSaveOptions.IsPrettyPrinting())))
193 bRet = false;
195 break;
196 case SID_ATTR_WARNALIENFORMAT:
198 bRet = true;
199 if (!aSaveOptions.IsReadOnly(SvtSaveOptions::E_WARNALIENFORMAT))
200 if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_WARNALIENFORMAT ), aSaveOptions.IsWarnAlienFormat())))
201 bRet = false;
203 break;
204 case SID_ATTR_AUTOSAVE :
206 bRet = true;
207 if (!aSaveOptions.IsReadOnly(SvtSaveOptions::E_AUTOSAVE))
208 if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_AUTOSAVE ), aSaveOptions.IsAutoSave())))
209 bRet = false;
211 break;
212 case SID_ATTR_AUTOSAVEPROMPT :
214 bRet = true;
215 if (!aSaveOptions.IsReadOnly(SvtSaveOptions::E_AUTOSAVEPROMPT))
216 if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_AUTOSAVEPROMPT ), aSaveOptions.IsAutoSavePrompt())))
217 bRet = false;
219 break;
220 case SID_ATTR_AUTOSAVEMINUTE :
222 bRet = true;
223 if (!aSaveOptions.IsReadOnly(SvtSaveOptions::E_AUTOSAVETIME))
224 if (!rSet.Put( SfxUInt16Item( rPool.GetWhich( SID_ATTR_AUTOSAVEMINUTE ), (sal_uInt16)aSaveOptions.GetAutoSaveTime())))
225 bRet = false;
227 break;
228 case SID_ATTR_USERAUTOSAVE :
230 bRet = true;
231 if (!aSaveOptions.IsReadOnly(SvtSaveOptions::E_USERAUTOSAVE))
232 if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_USERAUTOSAVE ), aSaveOptions.IsUserAutoSave())))
233 bRet = false;
235 break;
236 case SID_ATTR_DOCINFO :
238 bRet = true;
239 if (!aSaveOptions.IsReadOnly(SvtSaveOptions::E_DOCINFSAVE))
240 if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_DOCINFO ), aSaveOptions.IsDocInfoSave())))
241 bRet = false;
243 break;
244 case SID_ATTR_WORKINGSET :
246 bRet = true;
247 if (!aSaveOptions.IsReadOnly(SvtSaveOptions::E_SAVEWORKINGSET))
248 if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_WORKINGSET ), aSaveOptions.IsSaveWorkingSet())))
249 bRet = false;
251 break;
252 case SID_ATTR_SAVEDOCVIEW :
254 bRet = true;
255 if (!aSaveOptions.IsReadOnly(SvtSaveOptions::E_SAVEDOCVIEW))
256 if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_SAVEDOCVIEW ), aSaveOptions.IsSaveDocView())))
257 bRet = false;
259 break;
260 case SID_ATTR_METRIC :
261 break;
262 case SID_HELPBALLOONS :
263 if(rSet.Put( SfxBoolItem ( rPool.GetWhich( SID_HELPBALLOONS ),
264 aHelpOptions.IsExtendedHelp() ) ) )
265 bRet = true;
266 break;
267 case SID_HELPTIPS :
268 if(rSet.Put( SfxBoolItem ( rPool.GetWhich( SID_HELPTIPS ),
269 aHelpOptions.IsHelpTips() ) ) )
270 bRet = true;
271 break;
272 case SID_ATTR_WELCOMESCREEN :
273 if(rSet.Put( SfxBoolItem ( rPool.GetWhich( SID_ATTR_WELCOMESCREEN ),
274 aHelpOptions.IsWelcomeScreen() ) ) )
275 bRet = true;
276 break;
277 case SID_HELP_STYLESHEET :
278 if(rSet.Put( SfxStringItem ( rPool.GetWhich( SID_HELP_STYLESHEET ),
279 aHelpOptions.GetHelpStyleSheet() ) ) )
280 bRet = true;
281 break;
282 case SID_ATTR_UNDO_COUNT :
283 if (rSet.Put(
284 SfxUInt16Item (
285 rPool.GetWhich(SID_ATTR_UNDO_COUNT),
286 officecfg::Office::Common::Undo::Steps::get())))
288 bRet = true;
290 break;
291 case SID_ATTR_QUICKLAUNCHER :
293 if ( ShutdownIcon::IsQuickstarterInstalled() )
295 if ( rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_QUICKLAUNCHER ),
296 ShutdownIcon::GetAutostart() ) ) )
297 bRet = true;
299 else
301 rSet.DisableItem( rPool.GetWhich( SID_ATTR_QUICKLAUNCHER ) );
302 bRet = true;
304 break;
306 case SID_SAVEREL_INET :
308 bRet = true;
309 if (!aSaveOptions.IsReadOnly(SvtSaveOptions::E_SAVERELINET))
310 if (!rSet.Put( SfxBoolItem ( rPool.GetWhich( SID_SAVEREL_INET ), aSaveOptions.IsSaveRelINet() )))
311 bRet = false;
313 break;
314 case SID_SAVEREL_FSYS :
316 bRet = true;
317 if (!aSaveOptions.IsReadOnly(SvtSaveOptions::E_SAVERELFSYS))
318 if (!rSet.Put( SfxBoolItem ( rPool.GetWhich( SID_SAVEREL_FSYS ), aSaveOptions.IsSaveRelFSys() )))
319 bRet = false;
321 break;
322 case SID_BASIC_ENABLED :
324 bRet = true;
325 if (!aSecurityOptions.IsReadOnly(SvtSecurityOptions::E_BASICMODE))
327 if ( !rSet.Put( SfxUInt16Item( rPool.GetWhich( SID_BASIC_ENABLED ), sal::static_int_cast< sal_uInt16 >(aSecurityOptions.GetBasicMode()))))
328 bRet = false;
331 break;
332 case SID_INET_EXE_PLUGIN :
334 bRet = true;
335 if (!aSecurityOptions.IsReadOnly(SvtSecurityOptions::E_EXECUTEPLUGINS))
337 if ( !rSet.Put( SfxBoolItem( SID_INET_EXE_PLUGIN, aSecurityOptions.IsExecutePlugins() ) ) )
338 bRet = false;
341 break;
342 case SID_MACRO_WARNING :
344 bRet = true;
345 if (!aSecurityOptions.IsReadOnly(SvtSecurityOptions::E_WARNING))
347 if ( !rSet.Put( SfxBoolItem( SID_MACRO_WARNING, aSecurityOptions.IsWarningEnabled() ) ) )
348 bRet = false;
351 break;
352 case SID_MACRO_CONFIRMATION :
354 bRet = true;
355 if (!aSecurityOptions.IsReadOnly(SvtSecurityOptions::E_CONFIRMATION))
357 if ( !rSet.Put( SfxBoolItem( SID_MACRO_CONFIRMATION, aSecurityOptions.IsConfirmationEnabled() ) ) )
358 bRet = false;
361 break;
362 case SID_SECURE_URL :
364 bRet = true;
365 if (!aSecurityOptions.IsReadOnly(SvtSecurityOptions::E_SECUREURLS))
367 ::com::sun::star::uno::Sequence< OUString > seqURLs = aSecurityOptions.GetSecureURLs();
368 std::vector<OUString> aList;
369 sal_uInt32 nCount = seqURLs.getLength();
370 for( sal_uInt32 nURL=0; nURL<nCount; ++nURL )
371 aList.push_back(seqURLs[nURL]);
373 if( !rSet.Put( SfxStringListItem( rPool.GetWhich(SID_SECURE_URL), &aList ) ) )
374 bRet = false;
377 break;
378 case SID_INET_PROXY_TYPE :
379 if (rSet.Put(
380 SfxUInt16Item(
381 rPool.GetWhich(SID_INET_PROXY_TYPE),
382 (officecfg::Inet::Settings::ooInetProxyType::
383 get().get_value_or(0)))))
385 bRet = true;
387 break;
388 case SID_INET_HTTP_PROXY_NAME :
389 if (rSet.Put(
390 SfxStringItem(
391 rPool.GetWhich(SID_INET_HTTP_PROXY_NAME),
392 officecfg::Inet::Settings::ooInetHTTPProxyName::
393 get())))
395 bRet = true;
397 break;
398 case SID_INET_HTTP_PROXY_PORT :
399 if (rSet.Put(
400 SfxInt32Item(
401 rPool.GetWhich(SID_INET_HTTP_PROXY_PORT),
402 (officecfg::Inet::Settings::
403 ooInetHTTPProxyPort::get().get_value_or(0)))))
405 bRet = true;
407 break;
408 case SID_INET_FTP_PROXY_NAME :
409 if (rSet.Put(
410 SfxStringItem(
411 rPool.GetWhich(SID_INET_FTP_PROXY_NAME),
412 officecfg::Inet::Settings::ooInetFTPProxyName::
413 get())))
415 bRet = true;
417 break;
418 case SID_INET_FTP_PROXY_PORT :
419 if (rSet.Put(
420 SfxInt32Item(
421 rPool.GetWhich(SID_INET_FTP_PROXY_PORT),
422 (officecfg::Inet::Settings::ooInetFTPProxyPort::
423 get().get_value_or(0)))))
425 bRet = true;
427 break;
428 case SID_INET_NOPROXY :
429 if (rSet.Put(
430 SfxStringItem(
431 rPool.GetWhich( SID_INET_NOPROXY),
432 (officecfg::Inet::Settings::ooInetNoProxy::
433 get()))))
435 bRet = true;
437 break;
438 case SID_ATTR_PATHNAME :
439 case SID_ATTR_PATHGROUP :
441 SfxAllEnumItem aNames(rPool.GetWhich(SID_ATTR_PATHGROUP));
442 SfxAllEnumItem aValues(rPool.GetWhich(SID_ATTR_PATHNAME));
443 SvtPathOptions aPathCfg;
444 for ( sal_uInt16 nProp = SvtPathOptions::PATH_ADDIN;
445 nProp <= SvtPathOptions::PATH_WORK; nProp++ )
447 aNames.InsertValue( nProp, SfxResId(CONFIG_PATH_START + nProp).toString() );
448 OUString aValue;
449 switch ( nProp )
451 case SvtPathOptions::PATH_ADDIN: ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aPathCfg.GetAddinPath(), aValue ); break;
452 case SvtPathOptions::PATH_AUTOCORRECT: aValue = aPathCfg.GetAutoCorrectPath(); break;
453 case SvtPathOptions::PATH_AUTOTEXT: aValue = aPathCfg.GetAutoTextPath(); break;
454 case SvtPathOptions::PATH_BACKUP: aValue = aPathCfg.GetBackupPath(); break;
455 case SvtPathOptions::PATH_BASIC: aValue = aPathCfg.GetBasicPath(); break;
456 case SvtPathOptions::PATH_BITMAP: aValue = aPathCfg.GetBitmapPath(); break;
457 case SvtPathOptions::PATH_CONFIG: aValue = aPathCfg.GetConfigPath(); break;
458 case SvtPathOptions::PATH_DICTIONARY: aValue = aPathCfg.GetDictionaryPath(); break;
459 case SvtPathOptions::PATH_FAVORITES: aValue = aPathCfg.GetFavoritesPath(); break;
460 case SvtPathOptions::PATH_FILTER: ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aPathCfg.GetFilterPath(), aValue ); break;
461 case SvtPathOptions::PATH_GALLERY: aValue = aPathCfg.GetGalleryPath(); break;
462 case SvtPathOptions::PATH_GRAPHIC: aValue = aPathCfg.GetGraphicPath(); break;
463 case SvtPathOptions::PATH_HELP: ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aPathCfg.GetHelpPath(), aValue ); break;
464 case SvtPathOptions::PATH_LINGUISTIC: aValue = aPathCfg.GetLinguisticPath(); break;
465 case SvtPathOptions::PATH_MODULE: ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aPathCfg.GetModulePath(), aValue ); break;
466 case SvtPathOptions::PATH_PALETTE: aValue = aPathCfg.GetPalettePath(); break;
467 case SvtPathOptions::PATH_PLUGIN: ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aPathCfg.GetPluginPath(), aValue ); break;
468 case SvtPathOptions::PATH_STORAGE: ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aPathCfg.GetStoragePath(), aValue ); break;
469 case SvtPathOptions::PATH_TEMP: aValue = aPathCfg.GetTempPath(); break;
470 case SvtPathOptions::PATH_TEMPLATE: aValue = aPathCfg.GetTemplatePath(); break;
471 case SvtPathOptions::PATH_USERCONFIG: aValue = aPathCfg.GetUserConfigPath(); break;
472 case SvtPathOptions::PATH_WORK: aValue = aPathCfg.GetWorkPath(); break;
474 aValues.InsertValue( nProp, aValue );
477 if ( rSet.Put(aNames) || rSet.Put(aValues) )
478 bRet = true;
480 break;
482 default:
483 DBG_WARNING( "W1:Wrong ID while getting Options!" );
484 break;
486 #ifdef DBG_UTIL
487 if ( !bRet )
488 OSL_FAIL( "Putting options failed!" );
489 #endif
491 pRanges++;
494 return bRet;
497 // TODO/CLEANUP: Why two SetOptions Methods?
498 void SfxApplication::SetOptions_Impl( const SfxItemSet& rSet )
500 const SfxPoolItem *pItem = 0;
501 SfxItemPool &rPool = GetPool();
503 SvtSaveOptions aSaveOptions;
504 SvtHelpOptions aHelpOptions;
505 SvtSecurityOptions aSecurityOptions;
506 SvtMiscOptions aMiscOptions;
507 std::shared_ptr< comphelper::ConfigurationChanges > batch(
508 comphelper::ConfigurationChanges::create());
509 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_BUTTON_OUTSTYLE3D), true, &pItem) )
511 DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
512 sal_uInt16 nOutStyle =
513 static_cast<const SfxBoolItem *>(pItem)->GetValue() ? 0 : TOOLBOX_STYLE_FLAT;
514 aMiscOptions.SetToolboxStyle( nOutStyle );
517 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_BUTTON_BIGSIZE), true, &pItem) )
519 DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
520 bool bBigSize = static_cast<const SfxBoolItem*>(pItem)->GetValue();
521 aMiscOptions.SetSymbolsSize(
522 sal::static_int_cast< sal_Int16 >(
523 bBigSize ? SFX_SYMBOLS_SIZE_LARGE : SFX_SYMBOLS_SIZE_SMALL ) );
524 SfxViewFrame* pCurrViewFrame = SfxViewFrame::GetFirst();
525 while ( pCurrViewFrame )
527 // update all "final" dispatchers
528 if ( !pCurrViewFrame->GetActiveChildFrame_Impl() )
529 pCurrViewFrame->GetDispatcher()->Update_Impl(true);
530 pCurrViewFrame = SfxViewFrame::GetNext(*pCurrViewFrame);
534 // Backup
535 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_BACKUP), true, &pItem) )
537 DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
538 aSaveOptions.SetBackup( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
541 // PrettyPrinting
542 if ( SfxItemState::SET == rSet.GetItemState( rPool.GetWhich( SID_ATTR_PRETTYPRINTING ), true, &pItem ) )
544 DBG_ASSERT( pItem->ISA( SfxBoolItem ), "BoolItem expected" );
545 aSaveOptions.SetPrettyPrinting( static_cast< const SfxBoolItem*> ( pItem )->GetValue() );
548 // WarnAlienFormat
549 if ( SfxItemState::SET == rSet.GetItemState( rPool.GetWhich( SID_ATTR_WARNALIENFORMAT ), true, &pItem ) )
551 DBG_ASSERT( pItem->ISA( SfxBoolItem ), "BoolItem expected" );
552 aSaveOptions.SetWarnAlienFormat( static_cast< const SfxBoolItem*> ( pItem )->GetValue() );
555 // AutoSave
556 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_AUTOSAVE), true, &pItem))
558 DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
559 aSaveOptions.SetAutoSave( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
562 // AutoSave-Propt
563 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_AUTOSAVEPROMPT), true, &pItem))
565 DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
566 aSaveOptions.SetAutoSavePrompt(static_cast<const SfxBoolItem *>(pItem)->GetValue());
569 // AutoSave-Time
570 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_AUTOSAVEMINUTE), true, &pItem))
572 DBG_ASSERT(pItem->ISA(SfxUInt16Item), "UInt16Item expected");
573 aSaveOptions.SetAutoSaveTime(static_cast<const SfxUInt16Item *>(pItem)->GetValue());
576 // UserAutoSave
577 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_USERAUTOSAVE), true, &pItem))
579 DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
580 aSaveOptions.SetUserAutoSave( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
583 // DocInfo
584 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_DOCINFO), true, &pItem))
586 DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
587 aSaveOptions.SetDocInfoSave(static_cast<const SfxBoolItem *>(pItem)->GetValue());
590 // Mark open Documents
591 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_WORKINGSET), true, &pItem))
593 DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
594 aSaveOptions.SetSaveWorkingSet(static_cast<const SfxBoolItem *>(pItem)->GetValue());
597 // Save window settings
598 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_SAVEDOCVIEW), true, &pItem))
600 DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
601 aSaveOptions.SetSaveDocView(static_cast<const SfxBoolItem *>(pItem)->GetValue());
604 // Metric
605 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_METRIC), true, &pItem))
607 DBG_ASSERT(pItem->ISA(SfxUInt16Item), "UInt16Item expected");
610 // HelpBalloons
611 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_HELPBALLOONS), true, &pItem))
613 DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
614 aHelpOptions.SetExtendedHelp(static_cast<const SfxBoolItem *>(pItem)->GetValue());
617 // HelpTips
618 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_HELPTIPS), true, &pItem))
620 DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
621 aHelpOptions.SetHelpTips( static_cast<const SfxBoolItem *>(pItem)->GetValue());
624 // WelcomeScreen
625 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_WELCOMESCREEN ), true, &pItem))
627 DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
628 aHelpOptions.SetWelcomeScreen( static_cast<const SfxBoolItem *>(pItem)->GetValue() );
631 // WelcomeScreen
632 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_WELCOMESCREEN_RESET ), true, &pItem))
634 DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
635 bool bReset = static_cast<const SfxBoolItem *>(pItem)->GetValue();
636 if ( bReset )
638 OSL_FAIL( "Not implemented, may be EOL!" );
641 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_HELP_STYLESHEET ), true, &pItem))
643 DBG_ASSERT(pItem->ISA(SfxStringItem), "StringItem expected");
644 aHelpOptions.SetHelpStyleSheet( static_cast<const SfxStringItem *>(pItem)->GetValue() );
647 // SaveRelINet
648 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_SAVEREL_INET), true, &pItem))
650 DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
651 aSaveOptions.SetSaveRelINet(static_cast<const SfxBoolItem *>(pItem)->GetValue());
654 // SaveRelFSys
655 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_SAVEREL_FSYS), true, &pItem))
657 DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
658 aSaveOptions.SetSaveRelFSys(static_cast<const SfxBoolItem *>(pItem)->GetValue());
661 // Undo-Count
662 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_UNDO_COUNT), true, &pItem))
664 DBG_ASSERT(pItem->ISA(SfxUInt16Item), "UInt16Item expected");
665 sal_uInt16 nUndoCount = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
666 officecfg::Office::Common::Undo::Steps::set(nUndoCount, batch);
668 // To catch all Undo-Managers: Iterate over all Frames
669 for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst();
670 pFrame;
671 pFrame = SfxViewFrame::GetNext(*pFrame) )
673 // Get the Dispatcher of the Frames
674 SfxDispatcher *pDispat = pFrame->GetDispatcher();
675 pDispat->Flush();
677 // Iterate over all SfxShells on the Dispatchers Stack
678 sal_uInt16 nIdx = 0;
679 for ( SfxShell *pSh = pDispat->GetShell(nIdx);
680 pSh;
681 ++nIdx, pSh = pDispat->GetShell(nIdx) )
683 ::svl::IUndoManager *pShUndoMgr = pSh->GetUndoManager();
684 if ( pShUndoMgr )
685 pShUndoMgr->SetMaxUndoActionCount( nUndoCount );
690 // Office autostart
691 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_QUICKLAUNCHER), true, &pItem))
693 DBG_ASSERT(pItem->ISA(SfxBoolItem), "BoolItem expected");
694 ShutdownIcon::SetAutostart( static_cast<const SfxBoolItem*>( pItem )->GetValue() );
697 // StarBasic Enable
698 if ( SfxItemState::SET == rSet.GetItemState(SID_BASIC_ENABLED, true, &pItem))
700 DBG_ASSERT(pItem->ISA(SfxUInt16Item), "SfxInt16Item expected");
701 aSecurityOptions.SetBasicMode( (EBasicSecurityMode)static_cast<const SfxUInt16Item*>( pItem )->GetValue() );
704 // Execute PlugIns
705 if ( SfxItemState::SET == rSet.GetItemState(SID_INET_EXE_PLUGIN, true, &pItem))
707 DBG_ASSERT(pItem->ISA(SfxBoolItem), "SfxBoolItem expected");
708 aSecurityOptions.SetExecutePlugins( static_cast<const SfxBoolItem *>( pItem )->GetValue() );
711 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_INET_PROXY_TYPE), true, &pItem))
713 DBG_ASSERT( pItem->ISA(SfxUInt16Item), "UInt16Item expected" );
714 officecfg::Inet::Settings::ooInetProxyType::set(
715 static_cast< SfxUInt16Item const * >(pItem)->GetValue(), batch);
718 if ( SfxItemState::SET == rSet.GetItemState( rPool.GetWhich( SID_INET_HTTP_PROXY_NAME ), true, &pItem ) )
720 DBG_ASSERT( pItem->ISA(SfxStringItem), "StringItem expected" );
721 officecfg::Inet::Settings::ooInetHTTPProxyName::set(
722 static_cast< SfxStringItem const * >(pItem)->GetValue(), batch);
724 if ( SfxItemState::SET == rSet.GetItemState( rPool.GetWhich( SID_INET_HTTP_PROXY_PORT ), true, &pItem ) )
726 DBG_ASSERT( pItem->ISA(SfxInt32Item), "Int32Item expected" );
727 officecfg::Inet::Settings::ooInetHTTPProxyPort::set(
728 static_cast< SfxInt32Item const * >(pItem)->GetValue(), batch);
730 if ( SfxItemState::SET == rSet.GetItemState( rPool.GetWhich( SID_INET_FTP_PROXY_NAME ), true, &pItem ) )
732 DBG_ASSERT( pItem->ISA(SfxStringItem), "StringItem expected" );
733 officecfg::Inet::Settings::ooInetFTPProxyName::set(
734 static_cast< SfxStringItem const * >(pItem)->GetValue(), batch);
736 if ( SfxItemState::SET == rSet.GetItemState( rPool.GetWhich( SID_INET_FTP_PROXY_PORT ), true, &pItem ) )
738 DBG_ASSERT( pItem->ISA(SfxInt32Item), "Int32Item expected" );
739 officecfg::Inet::Settings::ooInetFTPProxyPort::set(
740 static_cast< SfxInt32Item const * >(pItem)->GetValue(), batch);
742 if ( SfxItemState::SET == rSet.GetItemState(SID_INET_NOPROXY, true, &pItem))
744 DBG_ASSERT(pItem->ISA(SfxStringItem), "StringItem expected");
745 officecfg::Inet::Settings::ooInetNoProxy::set(
746 static_cast< SfxStringItem const * >(pItem)->GetValue(), batch);
749 // Secure-Referers
750 if ( SfxItemState::SET == rSet.GetItemState(SID_SECURE_URL, true, &pItem))
752 DBG_ASSERT(pItem->ISA(SfxStringListItem), "StringListItem expected");
753 ::com::sun::star::uno::Sequence< OUString > seqURLs;
754 static_cast<const SfxStringListItem*>(pItem)->GetStringList(seqURLs);
755 aSecurityOptions.SetSecureURLs( seqURLs );
758 if ( SfxItemState::SET == rSet.GetItemState(SID_MACRO_WARNING, true, &pItem))
760 DBG_ASSERT(pItem->ISA(SfxBoolItem), "SfxBoolItem expected");
761 aSecurityOptions.SetWarningEnabled( static_cast<const SfxBoolItem *>(pItem)->GetValue() );
763 if ( SfxItemState::SET == rSet.GetItemState(SID_MACRO_CONFIRMATION, true, &pItem))
765 DBG_ASSERT(pItem->ISA(SfxBoolItem), "SfxBoolItem expected");
766 aSecurityOptions.SetConfirmationEnabled( static_cast<const SfxBoolItem *>(pItem)->GetValue() );
769 // Store changed data
770 batch->commit();
774 void SfxApplication::SetOptions(const SfxItemSet &rSet)
776 SvtPathOptions aPathOptions;
778 // Data is saved in DocInfo and IniManager
779 const SfxPoolItem *pItem = 0;
780 SfxItemPool &rPool = GetPool();
782 SfxAllItemSet aSendSet( rSet );
784 // PathName
785 if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_PATHNAME), true, &pItem))
787 DBG_ASSERT(pItem->ISA(SfxAllEnumItem), "AllEnumItem expected");
788 const SfxAllEnumItem* pEnumItem = static_cast<const SfxAllEnumItem *>(pItem);
789 sal_uInt32 nCount = pEnumItem->GetValueCount();
790 OUString aNoChangeStr( ' ' );
791 for( sal_uInt32 nPath=0; nPath<nCount; ++nPath )
793 OUString sValue = pEnumItem->GetValueTextByPos((sal_uInt16)nPath);
794 if ( sValue != aNoChangeStr )
796 switch( nPath )
798 case SvtPathOptions::PATH_ADDIN:
800 OUString aTmp;
801 if( ::utl::LocalFileHelper::ConvertURLToPhysicalName( sValue, aTmp ) )
802 aPathOptions.SetAddinPath( aTmp );
803 break;
806 case SvtPathOptions::PATH_AUTOCORRECT: aPathOptions.SetAutoCorrectPath( sValue );break;
807 case SvtPathOptions::PATH_AUTOTEXT: aPathOptions.SetAutoTextPath( sValue );break;
808 case SvtPathOptions::PATH_BACKUP: aPathOptions.SetBackupPath( sValue );break;
809 case SvtPathOptions::PATH_BASIC: aPathOptions.SetBasicPath( sValue );break;
810 case SvtPathOptions::PATH_BITMAP: aPathOptions.SetBitmapPath( sValue );break;
811 case SvtPathOptions::PATH_CONFIG: aPathOptions.SetConfigPath( sValue );break;
812 case SvtPathOptions::PATH_DICTIONARY: aPathOptions.SetDictionaryPath( sValue );break;
813 case SvtPathOptions::PATH_FAVORITES: aPathOptions.SetFavoritesPath( sValue );break;
814 case SvtPathOptions::PATH_FILTER:
816 OUString aTmp;
817 if( ::utl::LocalFileHelper::ConvertURLToPhysicalName( sValue, aTmp ) )
818 aPathOptions.SetFilterPath( aTmp );
819 break;
821 case SvtPathOptions::PATH_GALLERY: aPathOptions.SetGalleryPath( sValue );break;
822 case SvtPathOptions::PATH_GRAPHIC: aPathOptions.SetGraphicPath( sValue );break;
823 case SvtPathOptions::PATH_HELP:
825 OUString aTmp;
826 if( ::utl::LocalFileHelper::ConvertURLToPhysicalName( sValue, aTmp ) )
827 aPathOptions.SetHelpPath( aTmp );
828 break;
831 case SvtPathOptions::PATH_LINGUISTIC: aPathOptions.SetLinguisticPath( sValue );break;
832 case SvtPathOptions::PATH_MODULE:
834 OUString aTmp;
835 if( ::utl::LocalFileHelper::ConvertURLToPhysicalName( sValue, aTmp ) )
836 aPathOptions.SetModulePath( aTmp );
837 break;
840 case SvtPathOptions::PATH_PALETTE: aPathOptions.SetPalettePath( sValue );break;
841 case SvtPathOptions::PATH_PLUGIN:
843 OUString aTmp;
844 if( ::utl::LocalFileHelper::ConvertURLToPhysicalName( sValue, aTmp ) )
845 aPathOptions.SetPluginPath( aTmp );
846 break;
849 case SvtPathOptions::PATH_STORAGE:
851 OUString aTmp;
852 if( ::utl::LocalFileHelper::ConvertURLToPhysicalName( sValue, aTmp ) )
853 aPathOptions.SetStoragePath( aTmp );
854 break;
857 case SvtPathOptions::PATH_TEMP: aPathOptions.SetTempPath( sValue );break;
858 case SvtPathOptions::PATH_TEMPLATE: aPathOptions.SetTemplatePath( sValue );break;
859 case SvtPathOptions::PATH_USERCONFIG: aPathOptions.SetUserConfigPath( sValue );break;
860 case SvtPathOptions::PATH_WORK: aPathOptions.SetWorkPath( sValue );break;
861 default: SAL_WARN( "sfx.appl", "SfxApplication::SetOptions_Impl() Invalid path number found for set directories!" );
866 aSendSet.ClearItem( rPool.GetWhich( SID_ATTR_PATHNAME ) );
869 SetOptions_Impl( rSet );
871 // Undo-Count
872 Broadcast( SfxItemSetHint( rSet ) );
876 void SfxApplication::NotifyEvent( const SfxEventHint& rEventHint, bool bSynchron )
878 SfxObjectShell *pDoc = rEventHint.GetObjShell();
879 if ( pDoc && ( pDoc->IsPreview() || !pDoc->Get_Impl()->bInitialized ) )
880 return;
882 if ( bSynchron )
884 #ifdef DBG_UTIL
885 if (!pDoc)
887 OStringBuffer aTmp("SfxEvent: ");
888 aTmp.append(OUStringToOString(rEventHint.GetEventName(), RTL_TEXTENCODING_UTF8));
889 OSL_TRACE( "%s", aTmp.getStr() );
891 #endif
892 Broadcast(rEventHint);
893 if ( pDoc )
894 pDoc->Broadcast( rEventHint );
896 else
897 new SfxEventAsyncer_Impl( rEventHint );
900 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */