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 <memory>
21 #include <comphelper/sequence.hxx>
22 #include <osl/file.hxx>
23 
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>
33 
34 #include <sfx2/sfxsids.hrc>
35 
36 #include <svl/isethint.hxx>
37 
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 <sal/log.hxx>
47 #include <vcl/idle.hxx>
48 
49 #include <sfx2/app.hxx>
50 #include <sfx2/event.hxx>
51 #include <sfx2/viewfrm.hxx>
52 #include <sfx2/dispatch.hxx>
53 #include <sfx2/objsh.hxx>
54 #include <objshimp.hxx>
55 #include "shutdownicon.hxx"
56 
57 using namespace ::com::sun::star::uno;
58 using namespace ::com::sun::star::util;
59 using namespace ::com::sun::star::beans;
60 
61 namespace {
62 
63 class SfxEventAsyncer_Impl : public SfxListener
64 {
65     SfxEventHint           aHint;
66     std::unique_ptr<Idle>  pIdle;
67 
68 public:
69 
70     virtual void        Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
71     explicit SfxEventAsyncer_Impl(const SfxEventHint& rHint);
72     DECL_LINK( IdleHdl, Timer*, void );
73 };
74 
75 }
76 
Notify(SfxBroadcaster &,const SfxHint & rHint)77 void SfxEventAsyncer_Impl::Notify( SfxBroadcaster&, const SfxHint& rHint )
78 {
79     if( rHint.GetId() == SfxHintId::Dying && pIdle->IsActive() )
80     {
81         pIdle->Stop();
82         delete this;
83     }
84 }
85 
86 
SfxEventAsyncer_Impl(const SfxEventHint & rHint)87 SfxEventAsyncer_Impl::SfxEventAsyncer_Impl( const SfxEventHint& rHint )
88  : aHint( rHint )
89 {
90     if( rHint.GetObjShell() )
91         StartListening( *rHint.GetObjShell() );
92     pIdle.reset( new Idle("SfxEventASyncer") );
93     pIdle->SetInvokeHandler( LINK(this, SfxEventAsyncer_Impl, IdleHdl) );
94     pIdle->SetPriority( TaskPriority::HIGH_IDLE );
95     pIdle->SetDebugName( "sfx::SfxEventAsyncer_Impl pIdle" );
96     pIdle->Start();
97 }
98 
99 
IMPL_LINK(SfxEventAsyncer_Impl,IdleHdl,Timer *,pAsyncIdle,void)100 IMPL_LINK(SfxEventAsyncer_Impl, IdleHdl, Timer*, pAsyncIdle, void)
101 {
102     SfxObjectShellRef xRef( aHint.GetObjShell() );
103     pAsyncIdle->Stop();
104     SAL_INFO_IF(!xRef.is(), "sfx.appl", "SfxEvent: " << aHint.GetEventName());
105     SfxGetpApp()->Broadcast( aHint );
106     if ( xRef.is() )
107         xRef->Broadcast( aHint );
108     delete this;
109 }
110 
111 
GetOptions(SfxItemSet & rSet)112 void SfxApplication::GetOptions( SfxItemSet& rSet )
113 {
114     bool bRet = false;
115     SfxItemPool &rPool = GetPool();
116 
117     const sal_uInt16 *pRanges = rSet.GetRanges();
118     SvtSaveOptions aSaveOptions;
119     SvtHelpOptions aHelpOptions;
120     SvtSecurityOptions  aSecurityOptions;
121     SvtMiscOptions aMiscOptions;
122 
123     while ( *pRanges )
124     {
125         for(sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich)
126         {
127             switch(nWhich)
128             {
129                 case SID_ATTR_BUTTON_BIGSIZE :
130                 {
131                     if( rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_BUTTON_BIGSIZE ), aMiscOptions.AreCurrentSymbolsLarge() ) ) )
132                         bRet = true;
133                     break;
134                 }
135                 case SID_ATTR_BACKUP :
136                     {
137                         bRet = true;
138                         if (!aSaveOptions.IsReadOnly(SvtSaveOptions::EOption::Backup))
139                             if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_BACKUP ),aSaveOptions.IsBackup())))
140                                 bRet = false;
141                     }
142                     break;
143                 case SID_ATTR_PRETTYPRINTING:
144                     {
145                         bRet = true;
146                         if (!aSaveOptions.IsReadOnly(SvtSaveOptions::EOption::DoPrettyPrinting))
147                             if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_PRETTYPRINTING ), aSaveOptions.IsPrettyPrinting())))
148                                 bRet = false;
149                     }
150                     break;
151                 case SID_ATTR_WARNALIENFORMAT:
152                     {
153                         bRet = true;
154                         if (!aSaveOptions.IsReadOnly(SvtSaveOptions::EOption::WarnAlienFormat))
155                             if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_WARNALIENFORMAT ), aSaveOptions.IsWarnAlienFormat())))
156                                 bRet = false;
157                     }
158                     break;
159                 case SID_ATTR_AUTOSAVE :
160                     {
161                         bRet = true;
162                         if (!aSaveOptions.IsReadOnly(SvtSaveOptions::EOption::AutoSave))
163                             if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_AUTOSAVE ), aSaveOptions.IsAutoSave())))
164                                 bRet = false;
165                     }
166                     break;
167                 case SID_ATTR_AUTOSAVEPROMPT :
168                     {
169                         bRet = true;
170                         if (!aSaveOptions.IsReadOnly(SvtSaveOptions::EOption::AutoSavePrompt))
171                             if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_AUTOSAVEPROMPT ), aSaveOptions.IsAutoSavePrompt())))
172                                 bRet = false;
173                     }
174                     break;
175                 case SID_ATTR_AUTOSAVEMINUTE :
176                     {
177                         bRet = true;
178                         if (!aSaveOptions.IsReadOnly(SvtSaveOptions::EOption::AutoSaveTime))
179                             if (!rSet.Put( SfxUInt16Item( rPool.GetWhich( SID_ATTR_AUTOSAVEMINUTE ), static_cast<sal_uInt16>(aSaveOptions.GetAutoSaveTime()))))
180                                 bRet = false;
181                     }
182                     break;
183                 case SID_ATTR_USERAUTOSAVE :
184                     {
185                         bRet = true;
186                         if (!aSaveOptions.IsReadOnly(SvtSaveOptions::EOption::UserAutoSave))
187                             if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_USERAUTOSAVE ), aSaveOptions.IsUserAutoSave())))
188                                 bRet = false;
189                     }
190                     break;
191                 case SID_ATTR_DOCINFO :
192                     {
193                         bRet = true;
194                         if (!aSaveOptions.IsReadOnly(SvtSaveOptions::EOption::DocInfSave))
195                             if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_DOCINFO ), aSaveOptions.IsDocInfoSave())))
196                                 bRet = false;
197                     }
198                     break;
199                 case SID_ATTR_WORKINGSET :
200                     {
201                         bRet = true;
202                         if (!aSaveOptions.IsReadOnly(SvtSaveOptions::EOption::SaveWorkingSet))
203                             if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_WORKINGSET ), aSaveOptions.IsSaveWorkingSet())))
204                                 bRet = false;
205                     }
206                     break;
207                 case SID_ATTR_SAVEDOCVIEW :
208                     {
209                         bRet = true;
210                         if (!aSaveOptions.IsReadOnly(SvtSaveOptions::EOption::SaveDocView))
211                             if (!rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_SAVEDOCVIEW ), aSaveOptions.IsSaveDocView())))
212                                 bRet = false;
213                     }
214                     break;
215                 case SID_ATTR_METRIC :
216                     break;
217                 case SID_HELPBALLOONS :
218                     if(rSet.Put( SfxBoolItem ( rPool.GetWhich( SID_HELPBALLOONS ),
219                                aHelpOptions.IsExtendedHelp() ) ) )
220                         bRet = true;
221                     break;
222                 case SID_HELPTIPS :
223                     if(rSet.Put( SfxBoolItem ( rPool.GetWhich( SID_HELPTIPS ),
224                                aHelpOptions.IsHelpTips() ) ) )
225                         bRet = true;
226                     break;
227                 case SID_HELP_STYLESHEET :
228                     if(rSet.Put( SfxStringItem ( rPool.GetWhich( SID_HELP_STYLESHEET ),
229                                aHelpOptions.GetHelpStyleSheet() ) ) )
230                         bRet = true;
231                 break;
232                 case SID_ATTR_UNDO_COUNT :
233                     if (rSet.Put(
234                             SfxUInt16Item (
235                                 rPool.GetWhich(SID_ATTR_UNDO_COUNT),
236                                 officecfg::Office::Common::Undo::Steps::get())))
237                     {
238                         bRet = true;
239                     }
240                     break;
241                 case SID_ATTR_QUICKLAUNCHER :
242                 {
243                     if ( ShutdownIcon::IsQuickstarterInstalled() )
244                     {
245                         if ( rSet.Put( SfxBoolItem( rPool.GetWhich( SID_ATTR_QUICKLAUNCHER ),
246                                                     ShutdownIcon::GetAutostart() ) ) )
247                             bRet = true;
248                     }
249                     else
250                     {
251                         rSet.DisableItem( rPool.GetWhich( SID_ATTR_QUICKLAUNCHER ) );
252                         bRet = true;
253                     }
254                     break;
255                 }
256                 case SID_SAVEREL_INET :
257                     {
258                         bRet = true;
259                         if (!aSaveOptions.IsReadOnly(SvtSaveOptions::EOption::SaveRelInet))
260                             if (!rSet.Put( SfxBoolItem ( rPool.GetWhich( SID_SAVEREL_INET ), aSaveOptions.IsSaveRelINet() )))
261                                 bRet = false;
262                     }
263                     break;
264                 case SID_SAVEREL_FSYS :
265                     {
266                         bRet = true;
267                         if (!aSaveOptions.IsReadOnly(SvtSaveOptions::EOption::SaveRelFsys))
268                             if (!rSet.Put( SfxBoolItem ( rPool.GetWhich( SID_SAVEREL_FSYS ), aSaveOptions.IsSaveRelFSys() )))
269                                 bRet = false;
270                     }
271                     break;
272                 case SID_SECURE_URL :
273                     {
274                         bRet = true;
275                         if (!aSecurityOptions.IsReadOnly(SvtSecurityOptions::EOption::SecureUrls))
276                         {
277                             css::uno::Sequence< OUString > seqURLs = aSecurityOptions.GetSecureURLs();
278                             auto aList = comphelper::sequenceToContainer<std::vector<OUString>>(seqURLs);
279 
280                             if( !rSet.Put( SfxStringListItem( rPool.GetWhich(SID_SECURE_URL), &aList ) ) )
281                                 bRet = false;
282                         }
283                     }
284                     break;
285                 case SID_INET_PROXY_TYPE :
286                     if (rSet.Put(
287                             SfxUInt16Item(
288                                 rPool.GetWhich(SID_INET_PROXY_TYPE),
289                                 (officecfg::Inet::Settings::ooInetProxyType::
290                                  get().value_or(0)))))
291                     {
292                         bRet = true;
293                     }
294                     break;
295                 case SID_INET_HTTP_PROXY_NAME :
296                     if (rSet.Put(
297                             SfxStringItem(
298                                 rPool.GetWhich(SID_INET_HTTP_PROXY_NAME),
299                                 officecfg::Inet::Settings::ooInetHTTPProxyName::
300                                 get())))
301                     {
302                         bRet = true;
303                     }
304                     break;
305                 case SID_INET_HTTP_PROXY_PORT :
306                     if (rSet.Put(
307                             SfxInt32Item(
308                                 rPool.GetWhich(SID_INET_HTTP_PROXY_PORT),
309                                 (officecfg::Inet::Settings::
310                                  ooInetHTTPProxyPort::get().value_or(0)))))
311                     {
312                         bRet = true;
313                     }
314                     break;
315                 case SID_INET_FTP_PROXY_NAME :
316                     if (rSet.Put(
317                             SfxStringItem(
318                                 rPool.GetWhich(SID_INET_FTP_PROXY_NAME),
319                                 officecfg::Inet::Settings::ooInetFTPProxyName::
320                                 get())))
321                     {
322                         bRet = true;
323                     }
324                     break;
325                 case SID_INET_FTP_PROXY_PORT :
326                     if (rSet.Put(
327                             SfxInt32Item(
328                                 rPool.GetWhich(SID_INET_FTP_PROXY_PORT),
329                                 (officecfg::Inet::Settings::ooInetFTPProxyPort::
330                                  get().value_or(0)))))
331                     {
332                         bRet = true;
333                     }
334                     break;
335                 case SID_INET_NOPROXY :
336                     if (rSet.Put(
337                             SfxStringItem(
338                                 rPool.GetWhich( SID_INET_NOPROXY),
339                                 (officecfg::Inet::Settings::ooInetNoProxy::
340                                  get()))))
341                     {
342                         bRet = true;
343                     }
344                     break;
345                 case SID_ATTR_PATHNAME :
346                 {
347                     SfxAllEnumItem aValues(rPool.GetWhich(SID_ATTR_PATHNAME));
348                     SvtPathOptions aPathCfg;
349                     for ( sal_uInt16 nProp = static_cast<sal_uInt16>(SvtPathOptions::Paths::AddIn);
350                           nProp <= static_cast<sal_uInt16>(SvtPathOptions::Paths::Work); nProp++ )
351                     {
352                         OUString aValue;
353                         switch ( static_cast<SvtPathOptions::Paths>(nProp) )
354                         {
355                             case SvtPathOptions::Paths::AddIn:        osl::FileBase::getFileURLFromSystemPath( aPathCfg.GetAddinPath(), aValue ); break;
356                             case SvtPathOptions::Paths::AutoCorrect:  aValue = aPathCfg.GetAutoCorrectPath(); break;
357                             case SvtPathOptions::Paths::AutoText:     aValue = aPathCfg.GetAutoTextPath(); break;
358                             case SvtPathOptions::Paths::Backup:       aValue = aPathCfg.GetBackupPath(); break;
359                             case SvtPathOptions::Paths::Basic:        aValue = aPathCfg.GetBasicPath(); break;
360                             case SvtPathOptions::Paths::Bitmap:       aValue = aPathCfg.GetBitmapPath(); break;
361                             case SvtPathOptions::Paths::Config:       aValue = aPathCfg.GetConfigPath(); break;
362                             case SvtPathOptions::Paths::Dictionary:   aValue = aPathCfg.GetDictionaryPath(); break;
363                             case SvtPathOptions::Paths::Favorites:    aValue = aPathCfg.GetFavoritesPath(); break;
364                             case SvtPathOptions::Paths::Filter:       osl::FileBase::getFileURLFromSystemPath( aPathCfg.GetFilterPath(), aValue ); break;
365                             case SvtPathOptions::Paths::Gallery:      aValue = aPathCfg.GetGalleryPath(); break;
366                             case SvtPathOptions::Paths::Graphic:      aValue = aPathCfg.GetGraphicPath(); break;
367                             case SvtPathOptions::Paths::Help:         osl::FileBase::getFileURLFromSystemPath( aPathCfg.GetHelpPath(), aValue ); break;
368                             case SvtPathOptions::Paths::Linguistic:   aValue = aPathCfg.GetLinguisticPath(); break;
369                             case SvtPathOptions::Paths::Module:       osl::FileBase::getFileURLFromSystemPath( aPathCfg.GetModulePath(), aValue ); break;
370                             case SvtPathOptions::Paths::Palette:      aValue = aPathCfg.GetPalettePath(); break;
371                             case SvtPathOptions::Paths::Plugin:       osl::FileBase::getFileURLFromSystemPath( aPathCfg.GetPluginPath(), aValue ); break;
372                             case SvtPathOptions::Paths::Storage:      osl::FileBase::getFileURLFromSystemPath( aPathCfg.GetStoragePath(), aValue ); break;
373                             case SvtPathOptions::Paths::Temp:         aValue = aPathCfg.GetTempPath(); break;
374                             case SvtPathOptions::Paths::Template:     aValue = aPathCfg.GetTemplatePath(); break;
375                             case SvtPathOptions::Paths::UserConfig:   aValue = aPathCfg.GetUserConfigPath(); break;
376                             case SvtPathOptions::Paths::Work:         aValue = aPathCfg.GetWorkPath(); break;
377                             default: break;
378                         }
379                         aValues.SetTextByPos( nProp, aValue );
380                     }
381 
382                     if (rSet.Put(aValues))
383                         bRet = true;
384                 }
385                 break;
386 
387                 default:
388                     SAL_INFO( "sfx.appl", "W1:Wrong ID while getting Options!" );
389                     break;
390             }
391             SAL_WARN_IF(!bRet, "sfx.appl", "Putting options failed!");
392         }
393         pRanges++;
394     }
395 }
396 
397 // TODO/CLEANUP: Why two SetOptions Methods?
SetOptions_Impl(const SfxItemSet & rSet)398 void SfxApplication::SetOptions_Impl( const SfxItemSet& rSet )
399 {
400     const SfxPoolItem *pItem = nullptr;
401     SfxItemPool &rPool = GetPool();
402 
403     SvtSaveOptions aSaveOptions;
404     SvtHelpOptions aHelpOptions;
405     SvtSecurityOptions aSecurityOptions;
406     SvtMiscOptions aMiscOptions;
407     std::shared_ptr< comphelper::ConfigurationChanges > batch(
408         comphelper::ConfigurationChanges::create());
409 
410     if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_BUTTON_BIGSIZE), true, &pItem) )
411     {
412         DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) !=  nullptr, "BoolItem expected");
413         bool bBigSize = static_cast<const SfxBoolItem*>(pItem)->GetValue();
414         aMiscOptions.SetSymbolsSize(
415             sal::static_int_cast< sal_Int16 >(
416                 bBigSize ? SFX_SYMBOLS_SIZE_LARGE : SFX_SYMBOLS_SIZE_SMALL ) );
417         SfxViewFrame* pCurrViewFrame = SfxViewFrame::GetFirst();
418         while ( pCurrViewFrame )
419         {
420             // update all "final" dispatchers
421             pCurrViewFrame->GetDispatcher()->Update_Impl(true);
422             pCurrViewFrame = SfxViewFrame::GetNext(*pCurrViewFrame);
423         }
424     }
425 
426     // Backup
427     if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_BACKUP), true, &pItem) )
428     {
429         DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) !=  nullptr, "BoolItem expected");
430         aSaveOptions.SetBackup( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
431     }
432 
433     // PrettyPrinting
434     if ( SfxItemState::SET == rSet.GetItemState( rPool.GetWhich( SID_ATTR_PRETTYPRINTING ), true, &pItem ) )
435     {
436         DBG_ASSERT( dynamic_cast< const SfxBoolItem *>( pItem ) !=  nullptr, "BoolItem expected" );
437         aSaveOptions.SetPrettyPrinting( static_cast< const SfxBoolItem*> ( pItem )->GetValue() );
438     }
439 
440     // WarnAlienFormat
441     if ( SfxItemState::SET == rSet.GetItemState( rPool.GetWhich( SID_ATTR_WARNALIENFORMAT ), true, &pItem ) )
442     {
443         DBG_ASSERT( dynamic_cast< const SfxBoolItem *>( pItem ) !=  nullptr, "BoolItem expected" );
444         aSaveOptions.SetWarnAlienFormat( static_cast< const SfxBoolItem*> ( pItem )->GetValue() );
445     }
446 
447     // AutoSave
448     if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_AUTOSAVE), true, &pItem))
449     {
450         DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) !=  nullptr, "BoolItem expected");
451         aSaveOptions.SetAutoSave( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
452     }
453 
454     // AutoSave-Prompt
455     if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_AUTOSAVEPROMPT), true, &pItem))
456     {
457         DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) !=  nullptr, "BoolItem expected");
458         aSaveOptions.SetAutoSavePrompt(static_cast<const SfxBoolItem *>(pItem)->GetValue());
459     }
460 
461     // AutoSave-Time
462     if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_AUTOSAVEMINUTE), true, &pItem))
463     {
464         DBG_ASSERT(dynamic_cast< const SfxUInt16Item *>( pItem ) !=  nullptr, "UInt16Item expected");
465         aSaveOptions.SetAutoSaveTime(static_cast<const SfxUInt16Item *>(pItem)->GetValue());
466     }
467 
468     // UserAutoSave
469     if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_USERAUTOSAVE), true, &pItem))
470     {
471         DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) !=  nullptr, "BoolItem expected");
472         aSaveOptions.SetUserAutoSave( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
473     }
474 
475     // DocInfo
476     if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_DOCINFO), true, &pItem))
477     {
478         DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) !=  nullptr, "BoolItem expected");
479         aSaveOptions.SetDocInfoSave(static_cast<const SfxBoolItem *>(pItem)->GetValue());
480     }
481 
482     // Mark open Documents
483     if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_WORKINGSET), true, &pItem))
484     {
485         DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) !=  nullptr, "BoolItem expected");
486         aSaveOptions.SetSaveWorkingSet(static_cast<const SfxBoolItem *>(pItem)->GetValue());
487     }
488 
489     // Save window settings
490     if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_SAVEDOCVIEW), true, &pItem))
491     {
492         DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) !=  nullptr, "BoolItem expected");
493         aSaveOptions.SetSaveDocView(static_cast<const SfxBoolItem *>(pItem)->GetValue());
494     }
495 
496     // Metric
497     if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_METRIC), true, &pItem))
498     {
499         DBG_ASSERT(dynamic_cast< const SfxUInt16Item *>( pItem ) !=  nullptr, "UInt16Item expected");
500     }
501 
502     // HelpBalloons
503     if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_HELPBALLOONS), true, &pItem))
504     {
505         DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) !=  nullptr, "BoolItem expected");
506         aHelpOptions.SetExtendedHelp(static_cast<const SfxBoolItem *>(pItem)->GetValue());
507     }
508 
509     // HelpTips
510     if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_HELPTIPS), true, &pItem))
511     {
512         DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) !=  nullptr, "BoolItem expected");
513         aHelpOptions.SetHelpTips( static_cast<const SfxBoolItem *>(pItem)->GetValue());
514     }
515 
516     if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_HELP_STYLESHEET ), true, &pItem))
517     {
518         DBG_ASSERT(dynamic_cast< const SfxStringItem *>( pItem ) !=  nullptr, "StringItem expected");
519         aHelpOptions.SetHelpStyleSheet( static_cast<const SfxStringItem *>(pItem)->GetValue() );
520     }
521 
522     // SaveRelINet
523     if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_SAVEREL_INET), true, &pItem))
524     {
525         DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) !=  nullptr, "BoolItem expected");
526         aSaveOptions.SetSaveRelINet(static_cast<const SfxBoolItem *>(pItem)->GetValue());
527     }
528 
529     // SaveRelFSys
530     if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_SAVEREL_FSYS), true, &pItem))
531     {
532         DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) !=  nullptr, "BoolItem expected");
533         aSaveOptions.SetSaveRelFSys(static_cast<const SfxBoolItem *>(pItem)->GetValue());
534     }
535 
536     // Undo-Count
537     if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_UNDO_COUNT), true, &pItem))
538     {
539         DBG_ASSERT(dynamic_cast< const SfxUInt16Item *>( pItem ) !=  nullptr, "UInt16Item expected");
540         sal_uInt16 nUndoCount = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
541         officecfg::Office::Common::Undo::Steps::set(nUndoCount, batch);
542 
543         // To catch all Undo-Managers: Iterate over all Frames
544         for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst();
545               pFrame;
546               pFrame = SfxViewFrame::GetNext(*pFrame) )
547         {
548             // Get the Dispatcher of the Frames
549             SfxDispatcher *pDispat = pFrame->GetDispatcher();
550             pDispat->Flush();
551 
552             // Iterate over all SfxShells on the Dispatchers Stack
553             sal_uInt16 nIdx = 0;
554             for ( SfxShell *pSh = pDispat->GetShell(nIdx);
555                   pSh;
556                   ++nIdx, pSh = pDispat->GetShell(nIdx) )
557             {
558                 SfxUndoManager *pShUndoMgr = pSh->GetUndoManager();
559                 if ( pShUndoMgr )
560                     pShUndoMgr->SetMaxUndoActionCount( nUndoCount );
561             }
562         }
563     }
564 
565     // Office autostart
566     if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_QUICKLAUNCHER), true, &pItem))
567     {
568         DBG_ASSERT(dynamic_cast< const SfxBoolItem *>( pItem ) !=  nullptr, "BoolItem expected");
569         ShutdownIcon::SetAutostart( static_cast<const SfxBoolItem*>( pItem )->GetValue() );
570     }
571 
572     if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_INET_PROXY_TYPE), true, &pItem))
573     {
574         DBG_ASSERT( dynamic_cast< const SfxUInt16Item *>( pItem ) !=  nullptr, "UInt16Item expected" );
575         officecfg::Inet::Settings::ooInetProxyType::set(
576             static_cast< SfxUInt16Item const * >(pItem)->GetValue(), batch);
577     }
578 
579     if ( SfxItemState::SET == rSet.GetItemState( rPool.GetWhich( SID_INET_HTTP_PROXY_NAME ), true, &pItem ) )
580     {
581         DBG_ASSERT( dynamic_cast< const SfxStringItem *>( pItem ) !=  nullptr, "StringItem expected" );
582         officecfg::Inet::Settings::ooInetHTTPProxyName::set(
583             static_cast< SfxStringItem const * >(pItem)->GetValue(), batch);
584     }
585     if ( SfxItemState::SET == rSet.GetItemState( rPool.GetWhich( SID_INET_HTTP_PROXY_PORT ), true, &pItem ) )
586     {
587         DBG_ASSERT( dynamic_cast< const SfxInt32Item *>( pItem ) !=  nullptr, "Int32Item expected" );
588         officecfg::Inet::Settings::ooInetHTTPProxyPort::set(
589             static_cast< SfxInt32Item const * >(pItem)->GetValue(), batch);
590     }
591     if ( SfxItemState::SET == rSet.GetItemState( rPool.GetWhich( SID_INET_FTP_PROXY_NAME ), true, &pItem ) )
592     {
593         DBG_ASSERT( dynamic_cast< const SfxStringItem *>( pItem ) !=  nullptr, "StringItem expected" );
594         officecfg::Inet::Settings::ooInetFTPProxyName::set(
595             static_cast< SfxStringItem const * >(pItem)->GetValue(), batch);
596     }
597     if ( SfxItemState::SET == rSet.GetItemState( rPool.GetWhich( SID_INET_FTP_PROXY_PORT ), true, &pItem ) )
598     {
599         DBG_ASSERT( dynamic_cast< const SfxInt32Item *>( pItem ) !=  nullptr, "Int32Item expected" );
600         officecfg::Inet::Settings::ooInetFTPProxyPort::set(
601             static_cast< SfxInt32Item const * >(pItem)->GetValue(), batch);
602     }
603     if ( SfxItemState::SET == rSet.GetItemState(SID_INET_NOPROXY, true, &pItem))
604     {
605         DBG_ASSERT(dynamic_cast< const SfxStringItem *>( pItem ) !=  nullptr, "StringItem expected");
606         officecfg::Inet::Settings::ooInetNoProxy::set(
607             static_cast< SfxStringItem const * >(pItem)->GetValue(), batch);
608     }
609 
610     // Secure-Referrer
611     if ( SfxItemState::SET == rSet.GetItemState(SID_SECURE_URL, true, &pItem))
612     {
613         DBG_ASSERT(dynamic_cast< const SfxStringListItem *>( pItem ) !=  nullptr, "StringListItem expected");
614         css::uno::Sequence< OUString > seqURLs;
615         static_cast<const SfxStringListItem*>(pItem)->GetStringList(seqURLs);
616         aSecurityOptions.SetSecureURLs( seqURLs );
617     }
618 
619     // Store changed data
620     batch->commit();
621 }
622 
623 
SetOptions(const SfxItemSet & rSet)624 void SfxApplication::SetOptions(const SfxItemSet &rSet)
625 {
626     SvtPathOptions aPathOptions;
627 
628     // Data is saved in DocInfo and IniManager
629     const SfxPoolItem *pItem = nullptr;
630     SfxItemPool &rPool = GetPool();
631 
632     SfxAllItemSet aSendSet( rSet );
633 
634     // PathName
635     if ( SfxItemState::SET == rSet.GetItemState(rPool.GetWhich(SID_ATTR_PATHNAME), true, &pItem))
636     {
637         DBG_ASSERT(dynamic_cast< const SfxAllEnumItem *>( pItem ) !=  nullptr, "AllEnumItem expected");
638         const SfxAllEnumItem* pEnumItem = static_cast<const SfxAllEnumItem *>(pItem);
639         sal_uInt32 nCount = pEnumItem->GetTextCount();
640         OUString aNoChangeStr( ' ' );
641         for( sal_uInt32 nPath=0; nPath<nCount; ++nPath )
642         {
643             const OUString& sValue = pEnumItem->GetTextByPos(static_cast<sal_uInt16>(nPath));
644             if ( sValue != aNoChangeStr )
645             {
646                 switch( static_cast<SvtPathOptions::Paths>(nPath) )
647                 {
648                     case SvtPathOptions::Paths::AddIn:
649                     {
650                         OUString aTmp;
651                         if( osl::FileBase::getSystemPathFromFileURL( sValue, aTmp ) == osl::FileBase::E_None )
652                             aPathOptions.SetAddinPath( aTmp );
653                         break;
654                     }
655 
656                     case SvtPathOptions::Paths::AutoCorrect:  aPathOptions.SetAutoCorrectPath( sValue );break;
657                     case SvtPathOptions::Paths::AutoText:     aPathOptions.SetAutoTextPath( sValue );break;
658                     case SvtPathOptions::Paths::Backup:       aPathOptions.SetBackupPath( sValue );break;
659                     case SvtPathOptions::Paths::Basic:        aPathOptions.SetBasicPath( sValue );break;
660                     case SvtPathOptions::Paths::Bitmap:       aPathOptions.SetBitmapPath( sValue );break;
661                     case SvtPathOptions::Paths::Config:       aPathOptions.SetConfigPath( sValue );break;
662                     case SvtPathOptions::Paths::Dictionary:   aPathOptions.SetDictionaryPath( sValue );break;
663                     case SvtPathOptions::Paths::Favorites:    aPathOptions.SetFavoritesPath( sValue );break;
664                     case SvtPathOptions::Paths::Filter:
665                     {
666                         OUString aTmp;
667                         if( osl::FileBase::getSystemPathFromFileURL( sValue, aTmp ) == osl::FileBase::E_None )
668                             aPathOptions.SetFilterPath( aTmp );
669                         break;
670                     }
671                     case SvtPathOptions::Paths::Gallery:      aPathOptions.SetGalleryPath( sValue );break;
672                     case SvtPathOptions::Paths::Graphic:      aPathOptions.SetGraphicPath( sValue );break;
673                     case SvtPathOptions::Paths::Help:
674                     {
675                         OUString aTmp;
676                         if( osl::FileBase::getSystemPathFromFileURL( sValue, aTmp ) == osl::FileBase::E_None )
677                             aPathOptions.SetHelpPath( aTmp );
678                         break;
679                     }
680 
681                     case SvtPathOptions::Paths::Linguistic:   aPathOptions.SetLinguisticPath( sValue );break;
682                     case SvtPathOptions::Paths::Module:
683                     {
684                         OUString aTmp;
685                         if( osl::FileBase::getSystemPathFromFileURL( sValue, aTmp ) == osl::FileBase::E_None )
686                             aPathOptions.SetModulePath( aTmp );
687                         break;
688                     }
689 
690                     case SvtPathOptions::Paths::Palette:      aPathOptions.SetPalettePath( sValue );break;
691                     case SvtPathOptions::Paths::Plugin:
692                     {
693                         OUString aTmp;
694                         if( osl::FileBase::getSystemPathFromFileURL( sValue, aTmp ) == osl::FileBase::E_None )
695                             aPathOptions.SetPluginPath( aTmp );
696                         break;
697                     }
698 
699                     case SvtPathOptions::Paths::Storage:
700                     {
701                         OUString aTmp;
702                         if( osl::FileBase::getSystemPathFromFileURL( sValue, aTmp ) == osl::FileBase::E_None )
703                             aPathOptions.SetStoragePath( aTmp );
704                         break;
705                     }
706 
707                     case SvtPathOptions::Paths::Temp:         aPathOptions.SetTempPath( sValue );break;
708                     case SvtPathOptions::Paths::Template:     aPathOptions.SetTemplatePath( sValue );break;
709                     case SvtPathOptions::Paths::UserConfig:   aPathOptions.SetUserConfigPath( sValue );break;
710                     case SvtPathOptions::Paths::Work:         aPathOptions.SetWorkPath( sValue );break;
711                     default: SAL_WARN( "sfx.appl", "SfxApplication::SetOptions_Impl() Invalid path number found for set directories!" );
712                 }
713             }
714         }
715 
716         aSendSet.ClearItem( rPool.GetWhich( SID_ATTR_PATHNAME ) );
717     }
718 
719     SetOptions_Impl( rSet );
720 
721     // Undo-Count
722     Broadcast( SfxItemSetHint( rSet ) );
723 }
724 
725 
NotifyEvent(const SfxEventHint & rEventHint,bool bSynchron)726 void SfxApplication::NotifyEvent( const SfxEventHint& rEventHint, bool bSynchron )
727 {
728     SfxObjectShell *pDoc = rEventHint.GetObjShell();
729     if ( pDoc && ( pDoc->IsPreview() || !pDoc->Get_Impl()->bInitialized ) )
730         return;
731 
732     if ( bSynchron )
733     {
734         SAL_INFO_IF(!pDoc, "sfx.appl", "SfxEvent: " << rEventHint.GetEventName());
735         Broadcast(rEventHint);
736         if ( pDoc )
737             pDoc->Broadcast( rEventHint );
738     }
739     else
740         new SfxEventAsyncer_Impl( rEventHint );
741 }
742 
743 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
744