LibreOffice Module sfx2 (master) 1
appcfg.cxx
Go to the documentation of this file.
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 <osl/file.hxx>
22
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>
32
33#include <sfx2/sfxsids.hrc>
34
35#include <officecfg/Inet.hxx>
36#include <officecfg/Office/Common.hxx>
37#include <officecfg/Office/Recovery.hxx>
40#include <svtools/miscopt.hxx>
41#include <svtools/imgdef.hxx>
42#include <sal/log.hxx>
43#include <vcl/idle.hxx>
44
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"
53
54using namespace ::com::sun::star::uno;
55using namespace ::com::sun::star::util;
56using namespace ::com::sun::star::beans;
57
58namespace {
59
60class SfxEventAsyncer_Impl : public SfxListener
61{
62 SfxEventHint aHint;
63 std::unique_ptr<Idle> pIdle;
64
65public:
66
67 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
68 explicit SfxEventAsyncer_Impl(const SfxEventHint& rHint);
69 DECL_LINK( IdleHdl, Timer*, void );
70};
71
72}
73
74void SfxEventAsyncer_Impl::Notify( SfxBroadcaster&, const SfxHint& rHint )
75{
76 if( rHint.GetId() == SfxHintId::Dying && pIdle->IsActive() )
77 {
78 pIdle->Stop();
79 delete this;
80 }
81}
82
83
84SfxEventAsyncer_Impl::SfxEventAsyncer_Impl( const SfxEventHint& rHint )
85 : aHint( rHint )
86{
87 if( rHint.GetObjShell() )
88 StartListening( *rHint.GetObjShell() );
89 pIdle.reset( new Idle("sfx::SfxEventAsyncer_Impl pIdle") );
90 pIdle->SetInvokeHandler( LINK(this, SfxEventAsyncer_Impl, IdleHdl) );
91 pIdle->SetPriority( TaskPriority::HIGH_IDLE );
92 pIdle->Start();
93}
94
95
96IMPL_LINK(SfxEventAsyncer_Impl, IdleHdl, Timer*, pAsyncIdle, void)
97{
98 SfxObjectShellRef xRef( aHint.GetObjShell() );
99 pAsyncIdle->Stop();
100 SAL_INFO_IF(!xRef.is(), "sfx.appl", "SfxEvent: " << aHint.GetEventName());
101 SfxGetpApp()->Broadcast( aHint );
102 if ( xRef.is() )
103 xRef->Broadcast( aHint );
104 delete this;
105}
106
107namespace
108{
109template <class Cfg, class Item> bool toSet(SfxItemSet& rSet, TypedWhichId<Item> wid)
110{
111 return rSet.Put(Item(wid, Cfg::get()));
112}
113template <class Cfg, class Item, class Val>
114bool toSet_withDefault(SfxItemSet& rSet, TypedWhichId<Item> wid, Val&& defVal)
115{
116 return rSet.Put(Item(wid, Cfg::get().value_or(std::move(defVal))));
117}
118template <class Cfg, class Item> bool toSet_ifRW(SfxItemSet& rSet, TypedWhichId<Item> wid)
119{
120 return Cfg::isReadOnly() || toSet<Cfg>(rSet, wid);
121}
122
123template <class Cfg, class Item>
124void toCfg_ifSet(const SfxItemSet& rSet, TypedWhichId<Item> wid,
125 std::shared_ptr<comphelper::ConfigurationChanges> const& batch)
126{
127 if (const auto* pItem = rSet.GetItemIfSet(wid))
128 Cfg::set(pItem->GetValue(), batch);
129}
130}
131
133{
134 SfxWhichIter iter(rSet);
135 for (auto nWhich = iter.FirstWhich(); nWhich; nWhich = iter.NextWhich())
136 {
137 bool bRet = false;
138 switch(nWhich)
139 {
140 case SID_ATTR_BACKUP:
141 bRet = true;
142 if (!officecfg::Office::Common::Save::Document::CreateBackup::isReadOnly())
143 if (!rSet.Put( SfxBoolItem( SID_ATTR_BACKUP,
144 (officecfg::Office::Common::Save::Document::CreateBackup::get() && !comphelper::LibreOfficeKit::isActive()) )))
145 bRet = false;
146 break;
147 case SID_ATTR_BACKUP_BESIDE_ORIGINAL:
148 bRet = toSet_ifRW<officecfg::Office::Common::Save::Document::BackupIntoDocumentFolder>(
149 rSet, SID_ATTR_BACKUP_BESIDE_ORIGINAL);
150 break;
151 case SID_ATTR_PRETTYPRINTING:
152 bRet = toSet_ifRW<officecfg::Office::Common::Save::Document::PrettyPrinting>(
153 rSet, SID_ATTR_PRETTYPRINTING);
154 break;
155 case SID_ATTR_WARNALIENFORMAT:
156 bRet = toSet_ifRW<officecfg::Office::Common::Save::Document::WarnAlienFormat>(
157 rSet, SID_ATTR_WARNALIENFORMAT);
158 break;
159 case SID_ATTR_AUTOSAVE:
160 bRet = toSet_ifRW<officecfg::Office::Recovery::AutoSave::Enabled>(
161 rSet, SID_ATTR_AUTOSAVE);
162 break;
163 case SID_ATTR_AUTOSAVEMINUTE:
164 bRet = toSet_ifRW<officecfg::Office::Recovery::AutoSave::TimeIntervall>(
165 rSet, SID_ATTR_AUTOSAVEMINUTE);
166 break;
167 case SID_ATTR_USERAUTOSAVE:
168 bRet = toSet_ifRW<officecfg::Office::Recovery::AutoSave::UserAutoSaveEnabled>(
169 rSet, SID_ATTR_USERAUTOSAVE);
170 break;
171 case SID_ATTR_DOCINFO:
172 bRet = toSet_ifRW<officecfg::Office::Common::Save::Document::EditProperty>(
173 rSet, SID_ATTR_DOCINFO);
174 break;
175 case SID_ATTR_QUICKLAUNCHER:
177 {
178 if ( rSet.Put( SfxBoolItem( SID_ATTR_QUICKLAUNCHER,
180 bRet = true;
181 }
182 else
183 {
184 rSet.DisableItem( SID_ATTR_QUICKLAUNCHER );
185 bRet = true;
186 }
187 break;
188 case SID_SAVEREL_INET:
189 bRet = toSet_ifRW<officecfg::Office::Common::Save::URL::Internet>(
190 rSet, SID_SAVEREL_INET);
191 break;
192 case SID_SAVEREL_FSYS:
193 bRet = toSet_ifRW<officecfg::Office::Common::Save::URL::FileSystem>(
194 rSet, SID_SAVEREL_FSYS);
195 break;
196 case SID_SECURE_URL:
197 bRet = true;
199 {
200 std::vector< OUString > seqURLs = SvtSecurityOptions::GetSecureURLs();
201
202 if( !rSet.Put( SfxStringListItem( SID_SECURE_URL, &seqURLs ) ) )
203 bRet = false;
204 }
205 break;
206 case SID_INET_HTTP_PROXY_NAME:
207 bRet = toSet<officecfg::Inet::Settings::ooInetHTTPProxyName>(
208 rSet, SID_INET_HTTP_PROXY_NAME);
209 break;
210 case SID_INET_HTTP_PROXY_PORT:
211 bRet = toSet_withDefault<officecfg::Inet::Settings::ooInetHTTPProxyPort>(
212 rSet, SID_INET_HTTP_PROXY_PORT, 0);
213 break;
214 case SID_INET_FTP_PROXY_NAME:
215 bRet = toSet<officecfg::Inet::Settings::ooInetFTPProxyName>(
216 rSet, SID_INET_FTP_PROXY_NAME);
217 break;
218 case SID_INET_FTP_PROXY_PORT:
219 bRet = toSet_withDefault<officecfg::Inet::Settings::ooInetFTPProxyPort>(
220 rSet, SID_INET_FTP_PROXY_PORT, 0);
221 break;
222 case SID_INET_NOPROXY:
223 bRet = toSet<officecfg::Inet::Settings::ooInetNoProxy>(rSet, SID_INET_NOPROXY);
224 break;
225
226 default:
227 SAL_INFO( "sfx.appl", "W1:Wrong ID while getting Options!" );
228 break;
229 }
230 SAL_WARN_IF(!bRet, "sfx.appl", "Putting options failed!");
231 }
232}
233
235{
236 std::shared_ptr< comphelper::ConfigurationChanges > batch(
238
239 // Backup
240 toCfg_ifSet<officecfg::Office::Common::Save::Document::CreateBackup>(
241 rSet, SID_ATTR_BACKUP, batch);
242
243 toCfg_ifSet<officecfg::Office::Common::Save::Document::BackupIntoDocumentFolder>(
244 rSet, SID_ATTR_BACKUP_BESIDE_ORIGINAL, batch);
245
246 // PrettyPrinting
247 toCfg_ifSet<officecfg::Office::Common::Save::Document::PrettyPrinting>(
248 rSet, SID_ATTR_PRETTYPRINTING, batch);
249
250 // WarnAlienFormat
251 toCfg_ifSet<officecfg::Office::Common::Save::Document::WarnAlienFormat>(
252 rSet, SID_ATTR_WARNALIENFORMAT, batch);
253
254 // AutoSave
255 toCfg_ifSet<officecfg::Office::Recovery::AutoSave::Enabled>(rSet, SID_ATTR_AUTOSAVE, batch);
256
257 // AutoSave-Time
258 toCfg_ifSet<officecfg::Office::Recovery::AutoSave::TimeIntervall>(
259 rSet, SID_ATTR_AUTOSAVEMINUTE, batch);
260
261 // UserAutoSave
262 toCfg_ifSet<officecfg::Office::Recovery::AutoSave::UserAutoSaveEnabled>(
263 rSet, SID_ATTR_USERAUTOSAVE, batch);
264
265 // DocInfo
266 toCfg_ifSet<officecfg::Office::Common::Save::Document::EditProperty>(
267 rSet, SID_ATTR_DOCINFO, batch);
268
269 // HelpBalloons
270 toCfg_ifSet<officecfg::Office::Common::Help::ExtendedTip>(rSet, SID_HELPBALLOONS, batch);
271
272 // HelpTips
273 toCfg_ifSet<officecfg::Office::Common::Help::Tip>(rSet, SID_HELPTIPS, batch);
274
275 // SaveRelINet
276 toCfg_ifSet<officecfg::Office::Common::Save::URL::Internet>(rSet, SID_SAVEREL_INET, batch);
277
278 // SaveRelFSys
279 toCfg_ifSet<officecfg::Office::Common::Save::URL::FileSystem>(rSet, SID_SAVEREL_FSYS, batch);
280
281 // Undo-Count
282 if ( const SfxUInt16Item *pItem = rSet.GetItemIfSet(SID_ATTR_UNDO_COUNT))
283 {
284 sal_uInt16 nUndoCount = pItem->GetValue();
285 officecfg::Office::Common::Undo::Steps::set(nUndoCount, batch);
286
287 // To catch all Undo-Managers: Iterate over all Frames
288 for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst();
289 pFrame;
290 pFrame = SfxViewFrame::GetNext(*pFrame) )
291 {
292 // Get the Dispatcher of the Frames
293 SfxDispatcher *pDispat = pFrame->GetDispatcher();
294 pDispat->Flush();
295
296 // Iterate over all SfxShells on the Dispatchers Stack
297 sal_uInt16 nIdx = 0;
298 for ( SfxShell *pSh = pDispat->GetShell(nIdx);
299 pSh;
300 ++nIdx, pSh = pDispat->GetShell(nIdx) )
301 {
302 SfxUndoManager *pShUndoMgr = pSh->GetUndoManager();
303 if ( pShUndoMgr )
304 pShUndoMgr->SetMaxUndoActionCount( nUndoCount );
305 }
306 }
307 }
308
309 // Office autostart
310 if ( const SfxBoolItem *pItem = rSet.GetItemIfSet(SID_ATTR_QUICKLAUNCHER))
311 {
312 ShutdownIcon::SetAutostart( pItem->GetValue() );
313 }
314
315 toCfg_ifSet<officecfg::Inet::Settings::ooInetProxyType>(rSet, SID_INET_PROXY_TYPE, batch);
316
317 toCfg_ifSet<officecfg::Inet::Settings::ooInetHTTPProxyName>(
318 rSet, SID_INET_HTTP_PROXY_NAME, batch);
319 toCfg_ifSet<officecfg::Inet::Settings::ooInetHTTPProxyPort>(
320 rSet, SID_INET_HTTP_PROXY_PORT, batch);
321 toCfg_ifSet<officecfg::Inet::Settings::ooInetFTPProxyName>(
322 rSet, SID_INET_FTP_PROXY_NAME, batch);
323 toCfg_ifSet<officecfg::Inet::Settings::ooInetFTPProxyPort>(
324 rSet, SID_INET_FTP_PROXY_PORT, batch);
325 toCfg_ifSet<officecfg::Inet::Settings::ooInetNoProxy>(rSet, SID_INET_NOPROXY, batch);
326
327 // Secure-Referrer
328 if ( const SfxStringListItem *pListItem = rSet.GetItemIfSet(SID_SECURE_URL))
329 {
330 SvtSecurityOptions::SetSecureURLs( std::vector(pListItem->GetList()) );
331 }
332
333 // Store changed data
334 batch->commit();
335}
336
337
338void SfxApplication::NotifyEvent( const SfxEventHint& rEventHint, bool bSynchron )
339{
340 SfxObjectShell *pDoc = rEventHint.GetObjShell();
341 if ( pDoc && ( pDoc->IsPreview() || !pDoc->Get_Impl()->bInitialized ) )
342 return;
343
344 if ( bSynchron )
345 {
346 SAL_INFO_IF(!pDoc, "sfx.appl", "SfxEvent: " << rEventHint.GetEventName());
347 Broadcast(rEventHint);
348 if ( pDoc )
349 pDoc->Broadcast( rEventHint );
350 }
351 else
352 new SfxEventAsyncer_Impl( rEventHint );
353}
354
355/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxApplication * SfxGetpApp()
Definition: app.hxx:231
IMPL_LINK(SfxEventAsyncer_Impl, IdleHdl, Timer *, pAsyncIdle, void)
Definition: appcfg.cxx:96
static void GetOptions(SfxItemSet &)
Definition: appcfg.cxx:132
void NotifyEvent(const SfxEventHint &rEvent, bool bSynchron=true)
Definition: appcfg.cxx:338
static void SetOptions(const SfxItemSet &)
Definition: appcfg.cxx:234
void Broadcast(const SfxHint &rHint)
SfxShell * GetShell(sal_uInt16 nIdx) const
Returns a pointer to the <SfxShell> which is at the position nIdx (from the top, last pushed is 0) on...
Definition: dispatch.cxx:529
void Flush()
This method performs outstanding push- and pop- commands.
Definition: dispatch.cxx:155
const OUString & GetEventName() const
Definition: event.hxx:208
SfxObjectShell * GetObjShell() const
Definition: event.hxx:211
SfxHintId GetId() const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void DisableItem(sal_uInt16 nWhich)
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint)
SAL_DLLPRIVATE SfxObjectShell_Impl * Get_Impl()
Definition: objsh.hxx:718
bool IsPreview() const
Definition: objmisc.cxx:1552
The class SfxShell is the base class for all classes, which provide the functionality of the form <Sl...
Definition: shell.hxx:128
void SetMaxUndoActionCount(size_t nMaxUndoActionCount)
static SAL_WARN_UNUSED_RESULT SfxViewFrame * GetNext(const SfxViewFrame &rPrev, const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
Definition: viewfrm.cxx:2006
static SAL_WARN_UNUSED_RESULT SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
Definition: viewfrm.cxx:1983
sal_uInt16 FirstWhich()
sal_uInt16 NextWhich()
static bool IsQuickstarterInstalled()
static bool GetAutostart()
static void SetAutostart(bool bActivate)
static std::shared_ptr< ConfigurationChanges > create()
bool is() const
DECL_LINK(CheckNameHdl, SvxNameDialog &, bool)
#define SAL_INFO_IF(condition, area, stream)
#define SAL_WARN_IF(condition, area, stream)
#define SAL_INFO(area, stream)
bool IsReadOnly(EOption eOption)
void SetSecureURLs(std::vector< OUString > &&urlList)
std::vector< OUString > GetSecureURLs()
static SfxItemSet & rSet
Definition: shell.cxx:534