tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / sfx2 / source / appl / appcfg.cxx
blob074ad93b6f74060288883b8529af2d8cca14944b
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 <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;
56 namespace {
58 class SfxEventAsyncer_Impl : public SfxListener
60 SfxEventHint aHint;
61 std::unique_ptr<Idle> pIdle;
63 public:
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() )
77 pIdle->Stop();
78 delete this;
83 SfxEventAsyncer_Impl::SfxEventAsyncer_Impl( const SfxEventHint& rHint )
84 : aHint( 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 );
91 pIdle->Start();
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() );
105 pAsyncIdle->Stop();
106 SAL_INFO_IF(!xRef.is(), "sfx.appl", "SfxEvent: " << aHint.GetEventName());
107 SfxGetpApp()->Broadcast( aHint );
108 if ( xRef.is() )
109 xRef->Broadcast( aHint );
110 delete this;
113 namespace
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())
143 bool bRet = false;
144 switch(nWhich)
146 case SID_ATTR_BACKUP:
147 bRet = true;
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()) )))
151 bRet = false;
152 break;
153 case SID_ATTR_BACKUP_BESIDE_ORIGINAL:
154 bRet = toSet_ifRW<officecfg::Office::Common::Save::Document::BackupIntoDocumentFolder>(
155 rSet, SID_ATTR_BACKUP_BESIDE_ORIGINAL);
156 break;
157 case SID_ATTR_PRETTYPRINTING:
158 bRet = toSet_ifRW<officecfg::Office::Common::Save::Document::PrettyPrinting>(
159 rSet, SID_ATTR_PRETTYPRINTING);
160 break;
161 case SID_ATTR_WARNALIENFORMAT:
162 bRet = toSet_ifRW<officecfg::Office::Common::Save::Document::WarnAlienFormat>(
163 rSet, SID_ATTR_WARNALIENFORMAT);
164 break;
165 case SID_ATTR_AUTOSAVE:
166 bRet = toSet_ifRW<officecfg::Office::Recovery::AutoSave::Enabled>(
167 rSet, SID_ATTR_AUTOSAVE);
168 break;
169 case SID_ATTR_AUTOSAVEMINUTE:
170 bRet = toSet_ifRW<officecfg::Office::Recovery::AutoSave::TimeIntervall>(
171 rSet, SID_ATTR_AUTOSAVEMINUTE);
172 break;
173 case SID_ATTR_USERAUTOSAVE:
174 bRet = toSet_ifRW<officecfg::Office::Recovery::AutoSave::UserAutoSaveEnabled>(
175 rSet, SID_ATTR_USERAUTOSAVE);
176 break;
177 case SID_ATTR_DOCINFO:
178 bRet = toSet_ifRW<officecfg::Office::Common::Save::Document::EditProperty>(
179 rSet, SID_ATTR_DOCINFO);
180 break;
181 case SID_ATTR_QUICKLAUNCHER:
182 if ( ShutdownIcon::IsQuickstarterInstalled() )
184 if ( rSet.Put( SfxBoolItem( SID_ATTR_QUICKLAUNCHER,
185 ShutdownIcon::GetAutostart() ) ) )
186 bRet = true;
188 else
190 rSet.DisableItem( SID_ATTR_QUICKLAUNCHER );
191 bRet = true;
193 break;
194 case SID_SAVEREL_INET:
195 bRet = toSet_ifRW<officecfg::Office::Common::Save::URL::Internet>(
196 rSet, SID_SAVEREL_INET);
197 break;
198 case SID_SAVEREL_FSYS:
199 bRet = toSet_ifRW<officecfg::Office::Common::Save::URL::FileSystem>(
200 rSet, SID_SAVEREL_FSYS);
201 break;
202 case SID_SECURE_URL:
203 bRet = true;
204 if (!SvtSecurityOptions::IsReadOnly(SvtSecurityOptions::EOption::SecureUrls))
206 std::vector< OUString > seqURLs = SvtSecurityOptions::GetSecureURLs();
208 if( !rSet.Put( SfxStringListItem( SID_SECURE_URL, &seqURLs ) ) )
209 bRet = false;
211 break;
212 case SID_INET_HTTP_PROXY_NAME:
213 bRet = toSet<officecfg::Inet::Settings::ooInetHTTPProxyName>(
214 rSet, SID_INET_HTTP_PROXY_NAME);
215 break;
216 case SID_INET_HTTP_PROXY_PORT:
217 bRet = toSet_withDefault<officecfg::Inet::Settings::ooInetHTTPProxyPort>(
218 rSet, SID_INET_HTTP_PROXY_PORT, 0);
219 break;
220 case SID_INET_NOPROXY:
221 bRet = toSet<officecfg::Inet::Settings::ooInetNoProxy>(rSet, SID_INET_NOPROXY);
222 break;
224 default:
225 SAL_INFO( "sfx.appl", "W1:Wrong ID while getting Options!" );
226 break;
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());
237 // Backup
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);
244 // PrettyPrinting
245 toCfg_ifSet<officecfg::Office::Common::Save::Document::PrettyPrinting>(
246 rSet, SID_ATTR_PRETTYPRINTING, batch);
248 // WarnAlienFormat
249 toCfg_ifSet<officecfg::Office::Common::Save::Document::WarnAlienFormat>(
250 rSet, SID_ATTR_WARNALIENFORMAT, batch);
252 // AutoSave
253 toCfg_ifSet<officecfg::Office::Recovery::AutoSave::Enabled>(rSet, SID_ATTR_AUTOSAVE, batch);
255 // AutoSave-Time
256 toCfg_ifSet<officecfg::Office::Recovery::AutoSave::TimeIntervall>(
257 rSet, SID_ATTR_AUTOSAVEMINUTE, batch);
259 // UserAutoSave
260 toCfg_ifSet<officecfg::Office::Recovery::AutoSave::UserAutoSaveEnabled>(
261 rSet, SID_ATTR_USERAUTOSAVE, batch);
263 // DocInfo
264 toCfg_ifSet<officecfg::Office::Common::Save::Document::EditProperty>(
265 rSet, SID_ATTR_DOCINFO, batch);
267 // HelpBalloons
268 toCfg_ifSet<officecfg::Office::Common::Help::ExtendedTip>(rSet, SID_HELPBALLOONS, batch);
270 // HelpTips
271 toCfg_ifSet<officecfg::Office::Common::Help::Tip>(rSet, SID_HELPTIPS, batch);
273 // SaveRelINet
274 toCfg_ifSet<officecfg::Office::Common::Save::URL::Internet>(rSet, SID_SAVEREL_INET, batch);
276 // SaveRelFSys
277 toCfg_ifSet<officecfg::Office::Common::Save::URL::FileSystem>(rSet, SID_SAVEREL_FSYS, batch);
279 // Undo-Count
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();
287 pFrame;
288 pFrame = SfxViewFrame::GetNext(*pFrame) )
290 // Get the Dispatcher of the Frames
291 SfxDispatcher *pDispat = pFrame->GetDispatcher();
292 pDispat->Flush();
294 // Iterate over all SfxShells on the Dispatchers Stack
295 sal_uInt16 nIdx = 0;
296 for ( SfxShell *pSh = pDispat->GetShell(nIdx);
297 pSh;
298 ++nIdx, pSh = pDispat->GetShell(nIdx) )
300 SfxUndoManager *pShUndoMgr = pSh->GetUndoManager();
301 if ( pShUndoMgr )
302 pShUndoMgr->SetMaxUndoActionCount( nUndoCount );
307 // Office autostart
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);
321 // Secure-Referrer
322 if ( const SfxStringListItem *pListItem = rSet.GetItemIfSet(SID_SECURE_URL))
324 SvtSecurityOptions::SetSecureURLs( std::vector(pListItem->GetList()) );
327 // Store changed data
328 batch->commit();
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 ) )
336 return;
338 if ( bSynchron )
340 SAL_INFO_IF(!pDoc, "sfx.appl", "SfxEvent: " << rEventHint.GetEventName());
341 Broadcast(rEventHint);
342 if ( pDoc )
343 pDoc->Broadcast( rEventHint );
345 else
346 new SfxEventAsyncer_Impl( rEventHint );
349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */