1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <osl/file.hxx>
23 #include <rtl/ustring.hxx>
24 #include <svl/itempool.hxx>
25 #include <svl/itemset.hxx>
26 #include <svl/slstitm.hxx>
27 #include <svl/stritem.hxx>
28 #include <svl/intitem.hxx>
29 #include <svl/eitem.hxx>
30 #include <svl/undo.hxx>
31 #include <svl/whiter.hxx>
33 #include <sfx2/sfxsids.hrc>
35 #include <officecfg/Inet.hxx>
36 #include <officecfg/Office/Common.hxx>
37 #include <officecfg/Office/Recovery.hxx>
38 #include <unotools/securityoptions.hxx>
39 #include <unotools/pathoptions.hxx>
40 #include <svtools/miscopt.hxx>
41 #include <svtools/imgdef.hxx>
42 #include <sal/log.hxx>
43 #include <vcl/idle.hxx>
45 #include <sfx2/app.hxx>
46 #include <sfx2/event.hxx>
47 #include <sfx2/viewfrm.hxx>
48 #include <sfx2/dispatch.hxx>
49 #include <sfx2/objsh.hxx>
50 #include <comphelper/lok.hxx>
51 #include <objshimp.hxx>
52 #include "shutdownicon.hxx"
54 using namespace ::com::sun::star::uno
;
58 class SfxEventAsyncer_Impl
: public SfxListener
61 std::unique_ptr
<Idle
> pIdle
;
65 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
66 explicit SfxEventAsyncer_Impl(const SfxEventHint
& rHint
);
67 ~SfxEventAsyncer_Impl();
68 DECL_LINK( IdleHdl
, Timer
*, void );
73 void SfxEventAsyncer_Impl::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
75 if( rHint
.GetId() == SfxHintId::Dying
&& pIdle
->IsActive() )
83 SfxEventAsyncer_Impl::SfxEventAsyncer_Impl( const SfxEventHint
& rHint
)
86 if( rHint
.GetObjShell() )
87 StartListening( *rHint
.GetObjShell() );
88 pIdle
.reset( new Idle("sfx::SfxEventAsyncer_Impl pIdle") );
89 pIdle
->SetInvokeHandler( LINK(this, SfxEventAsyncer_Impl
, IdleHdl
) );
90 pIdle
->SetPriority( TaskPriority::HIGH_IDLE
);
95 SfxEventAsyncer_Impl::~SfxEventAsyncer_Impl()
97 if (aHint
.GetObjShell())
98 EndListening(*aHint
.GetObjShell());
102 IMPL_LINK(SfxEventAsyncer_Impl
, IdleHdl
, Timer
*, pAsyncIdle
, void)
104 SfxObjectShellRef
xRef( aHint
.GetObjShell() );
106 SAL_INFO_IF(!xRef
.is(), "sfx.appl", "SfxEvent: " << aHint
.GetEventName());
107 SfxGetpApp()->Broadcast( aHint
);
109 xRef
->Broadcast( aHint
);
115 template <class Cfg
, class Item
> bool toSet(SfxItemSet
& rSet
, TypedWhichId
<Item
> wid
)
117 return rSet
.Put(Item(wid
, Cfg::get()));
119 template <class Cfg
, class Item
, class Val
>
120 bool toSet_withDefault(SfxItemSet
& rSet
, TypedWhichId
<Item
> wid
, Val
&& defVal
)
122 return rSet
.Put(Item(wid
, Cfg::get().value_or(std::move(defVal
))));
124 template <class Cfg
, class Item
> bool toSet_ifRW(SfxItemSet
& rSet
, TypedWhichId
<Item
> wid
)
126 return Cfg::isReadOnly() || toSet
<Cfg
>(rSet
, wid
);
129 template <class Cfg
, class Item
>
130 void toCfg_ifSet(const SfxItemSet
& rSet
, TypedWhichId
<Item
> wid
,
131 std::shared_ptr
<comphelper::ConfigurationChanges
> const& batch
)
133 if (const auto* pItem
= rSet
.GetItemIfSet(wid
))
134 Cfg::set(pItem
->GetValue(), batch
);
138 void SfxApplication::GetOptions( SfxItemSet
& rSet
)
140 SfxWhichIter
iter(rSet
);
141 for (auto nWhich
= iter
.FirstWhich(); nWhich
; nWhich
= iter
.NextWhich())
146 case SID_ATTR_BACKUP
:
148 if (!officecfg::Office::Common::Save::Document::CreateBackup::isReadOnly())
149 if (!rSet
.Put( SfxBoolItem( SID_ATTR_BACKUP
,
150 (officecfg::Office::Common::Save::Document::CreateBackup::get() && !comphelper::LibreOfficeKit::isActive()) )))
153 case SID_ATTR_BACKUP_BESIDE_ORIGINAL
:
154 bRet
= toSet_ifRW
<officecfg::Office::Common::Save::Document::BackupIntoDocumentFolder
>(
155 rSet
, SID_ATTR_BACKUP_BESIDE_ORIGINAL
);
157 case SID_ATTR_PRETTYPRINTING
:
158 bRet
= toSet_ifRW
<officecfg::Office::Common::Save::Document::PrettyPrinting
>(
159 rSet
, SID_ATTR_PRETTYPRINTING
);
161 case SID_ATTR_WARNALIENFORMAT
:
162 bRet
= toSet_ifRW
<officecfg::Office::Common::Save::Document::WarnAlienFormat
>(
163 rSet
, SID_ATTR_WARNALIENFORMAT
);
165 case SID_ATTR_AUTOSAVE
:
166 bRet
= toSet_ifRW
<officecfg::Office::Recovery::AutoSave::Enabled
>(
167 rSet
, SID_ATTR_AUTOSAVE
);
169 case SID_ATTR_AUTOSAVEMINUTE
:
170 bRet
= toSet_ifRW
<officecfg::Office::Recovery::AutoSave::TimeIntervall
>(
171 rSet
, SID_ATTR_AUTOSAVEMINUTE
);
173 case SID_ATTR_USERAUTOSAVE
:
174 bRet
= toSet_ifRW
<officecfg::Office::Recovery::AutoSave::UserAutoSaveEnabled
>(
175 rSet
, SID_ATTR_USERAUTOSAVE
);
177 case SID_ATTR_DOCINFO
:
178 bRet
= toSet_ifRW
<officecfg::Office::Common::Save::Document::EditProperty
>(
179 rSet
, SID_ATTR_DOCINFO
);
181 case SID_ATTR_QUICKLAUNCHER
:
182 if ( ShutdownIcon::IsQuickstarterInstalled() )
184 if ( rSet
.Put( SfxBoolItem( SID_ATTR_QUICKLAUNCHER
,
185 ShutdownIcon::GetAutostart() ) ) )
190 rSet
.DisableItem( SID_ATTR_QUICKLAUNCHER
);
194 case SID_SAVEREL_INET
:
195 bRet
= toSet_ifRW
<officecfg::Office::Common::Save::URL::Internet
>(
196 rSet
, SID_SAVEREL_INET
);
198 case SID_SAVEREL_FSYS
:
199 bRet
= toSet_ifRW
<officecfg::Office::Common::Save::URL::FileSystem
>(
200 rSet
, SID_SAVEREL_FSYS
);
204 if (!SvtSecurityOptions::IsReadOnly(SvtSecurityOptions::EOption::SecureUrls
))
206 std::vector
< OUString
> seqURLs
= SvtSecurityOptions::GetSecureURLs();
208 if( !rSet
.Put( SfxStringListItem( SID_SECURE_URL
, &seqURLs
) ) )
212 case SID_INET_HTTP_PROXY_NAME
:
213 bRet
= toSet
<officecfg::Inet::Settings::ooInetHTTPProxyName
>(
214 rSet
, SID_INET_HTTP_PROXY_NAME
);
216 case SID_INET_HTTP_PROXY_PORT
:
217 bRet
= toSet_withDefault
<officecfg::Inet::Settings::ooInetHTTPProxyPort
>(
218 rSet
, SID_INET_HTTP_PROXY_PORT
, 0);
220 case SID_INET_NOPROXY
:
221 bRet
= toSet
<officecfg::Inet::Settings::ooInetNoProxy
>(rSet
, SID_INET_NOPROXY
);
225 SAL_INFO( "sfx.appl", "W1:Wrong ID while getting Options!" );
228 SAL_WARN_IF(!bRet
, "sfx.appl", "Putting options failed!");
232 void SfxApplication::SetOptions(const SfxItemSet
&rSet
)
234 std::shared_ptr
< comphelper::ConfigurationChanges
> batch(
235 comphelper::ConfigurationChanges::create());
238 toCfg_ifSet
<officecfg::Office::Common::Save::Document::CreateBackup
>(
239 rSet
, SID_ATTR_BACKUP
, batch
);
241 toCfg_ifSet
<officecfg::Office::Common::Save::Document::BackupIntoDocumentFolder
>(
242 rSet
, SID_ATTR_BACKUP_BESIDE_ORIGINAL
, batch
);
245 toCfg_ifSet
<officecfg::Office::Common::Save::Document::PrettyPrinting
>(
246 rSet
, SID_ATTR_PRETTYPRINTING
, batch
);
249 toCfg_ifSet
<officecfg::Office::Common::Save::Document::WarnAlienFormat
>(
250 rSet
, SID_ATTR_WARNALIENFORMAT
, batch
);
253 toCfg_ifSet
<officecfg::Office::Recovery::AutoSave::Enabled
>(rSet
, SID_ATTR_AUTOSAVE
, batch
);
256 toCfg_ifSet
<officecfg::Office::Recovery::AutoSave::TimeIntervall
>(
257 rSet
, SID_ATTR_AUTOSAVEMINUTE
, batch
);
260 toCfg_ifSet
<officecfg::Office::Recovery::AutoSave::UserAutoSaveEnabled
>(
261 rSet
, SID_ATTR_USERAUTOSAVE
, batch
);
264 toCfg_ifSet
<officecfg::Office::Common::Save::Document::EditProperty
>(
265 rSet
, SID_ATTR_DOCINFO
, batch
);
268 toCfg_ifSet
<officecfg::Office::Common::Help::ExtendedTip
>(rSet
, SID_HELPBALLOONS
, batch
);
271 toCfg_ifSet
<officecfg::Office::Common::Help::Tip
>(rSet
, SID_HELPTIPS
, batch
);
274 toCfg_ifSet
<officecfg::Office::Common::Save::URL::Internet
>(rSet
, SID_SAVEREL_INET
, batch
);
277 toCfg_ifSet
<officecfg::Office::Common::Save::URL::FileSystem
>(rSet
, SID_SAVEREL_FSYS
, batch
);
280 if ( const SfxUInt16Item
*pItem
= rSet
.GetItemIfSet(SID_ATTR_UNDO_COUNT
))
282 sal_uInt16 nUndoCount
= pItem
->GetValue();
283 officecfg::Office::Common::Undo::Steps::set(nUndoCount
, batch
);
285 // To catch all Undo-Managers: Iterate over all Frames
286 for ( SfxViewFrame
*pFrame
= SfxViewFrame::GetFirst();
288 pFrame
= SfxViewFrame::GetNext(*pFrame
) )
290 // Get the Dispatcher of the Frames
291 SfxDispatcher
*pDispat
= pFrame
->GetDispatcher();
294 // Iterate over all SfxShells on the Dispatchers Stack
296 for ( SfxShell
*pSh
= pDispat
->GetShell(nIdx
);
298 ++nIdx
, pSh
= pDispat
->GetShell(nIdx
) )
300 SfxUndoManager
*pShUndoMgr
= pSh
->GetUndoManager();
302 pShUndoMgr
->SetMaxUndoActionCount( nUndoCount
);
308 if ( const SfxBoolItem
*pItem
= rSet
.GetItemIfSet(SID_ATTR_QUICKLAUNCHER
))
310 ShutdownIcon::SetAutostart( pItem
->GetValue() );
313 toCfg_ifSet
<officecfg::Inet::Settings::ooInetProxyType
>(rSet
, SID_INET_PROXY_TYPE
, batch
);
315 toCfg_ifSet
<officecfg::Inet::Settings::ooInetHTTPProxyName
>(
316 rSet
, SID_INET_HTTP_PROXY_NAME
, batch
);
317 toCfg_ifSet
<officecfg::Inet::Settings::ooInetHTTPProxyPort
>(
318 rSet
, SID_INET_HTTP_PROXY_PORT
, batch
);
319 toCfg_ifSet
<officecfg::Inet::Settings::ooInetNoProxy
>(rSet
, SID_INET_NOPROXY
, batch
);
322 if ( const SfxStringListItem
*pListItem
= rSet
.GetItemIfSet(SID_SECURE_URL
))
324 SvtSecurityOptions::SetSecureURLs( std::vector(pListItem
->GetList()) );
327 // Store changed data
332 void SfxApplication::NotifyEvent( const SfxEventHint
& rEventHint
, bool bSynchron
)
334 rtl::Reference
<SfxObjectShell
> pDoc
= rEventHint
.GetObjShell();
335 if ( pDoc
&& ( pDoc
->IsPreview() || !pDoc
->Get_Impl()->bInitialized
) )
340 SAL_INFO_IF(!pDoc
, "sfx.appl", "SfxEvent: " << rEventHint
.GetEventName());
341 Broadcast(rEventHint
);
343 pDoc
->Broadcast( rEventHint
);
346 new SfxEventAsyncer_Impl( rEventHint
);
349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */