1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <memory>
#include <osl/file.hxx>
#include <rtl/ustring.hxx>
#include <svl/itempool.hxx>
#include <svl/itemset.hxx>
#include <svl/slstitm.hxx>
#include <svl/stritem.hxx>
#include <svl/intitem.hxx>
#include <svl/eitem.hxx>
#include <svl/undo.hxx>
#include <svl/whiter.hxx>
#include <sfx2/sfxsids.hrc>
#include <officecfg/Inet.hxx>
#include <officecfg/Office/Common.hxx>
#include <officecfg/Office/Recovery.hxx>
#include <unotools/securityoptions.hxx>
#include <unotools/pathoptions.hxx>
#include <svtools/miscopt.hxx>
#include <svtools/imgdef.hxx>
#include <sal/log.hxx>
#include <vcl/idle.hxx>
#include <sfx2/app.hxx>
#include <sfx2/event.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/objsh.hxx>
#include <comphelper/lok.hxx>
#include <objshimp.hxx>
#include "shutdownicon.hxx"
using namespace ::com::sun::star::uno;
namespace {
class SfxEventAsyncer_Impl : public SfxListener
{
SfxEventHint aHint;
std::unique_ptr<Idle> pIdle;
public:
virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
explicit SfxEventAsyncer_Impl(const SfxEventHint& rHint);
~SfxEventAsyncer_Impl();
DECL_LINK( IdleHdl, Timer*, void );
};
}
void SfxEventAsyncer_Impl::Notify( SfxBroadcaster&, const SfxHint& rHint )
{
if( rHint.GetId() == SfxHintId::Dying && pIdle->IsActive() )
{
pIdle->Stop();
delete this;
}
}
SfxEventAsyncer_Impl::SfxEventAsyncer_Impl( const SfxEventHint& rHint )
: aHint( rHint )
{
if( rHint.GetObjShell() )
StartListening( *rHint.GetObjShell() );
pIdle.reset( new Idle("sfx::SfxEventAsyncer_Impl pIdle") );
pIdle->SetInvokeHandler( LINK(this, SfxEventAsyncer_Impl, IdleHdl) );
pIdle->SetPriority( TaskPriority::HIGH_IDLE );
pIdle->Start();
}
SfxEventAsyncer_Impl::~SfxEventAsyncer_Impl()
{
if (aHint.GetObjShell())
EndListening(*aHint.GetObjShell());
}
IMPL_LINK(SfxEventAsyncer_Impl, IdleHdl, Timer*, pAsyncIdle, void)
{
SfxObjectShellRef xRef( aHint.GetObjShell() );
pAsyncIdle->Stop();
SAL_INFO_IF(!xRef.is(), "sfx.appl", "SfxEvent: " << aHint.GetEventName());
SfxGetpApp()->Broadcast( aHint );
if ( xRef.is() )
xRef->Broadcast( aHint );
delete this;
}
namespace
{
template <class Cfg, class Item> bool toSet(SfxItemSet& rSet, TypedWhichId<Item> wid)
{
return rSet.Put(Item(wid, Cfg::get()));
}
template <class Cfg, class Item, class Val>
bool toSet_withDefault(SfxItemSet& rSet, TypedWhichId<Item> wid, Val&& defVal)
{
return rSet.Put(Item(wid, Cfg::get().value_or(std::move(defVal))));
}
template <class Cfg, class Item> bool toSet_ifRW(SfxItemSet& rSet, TypedWhichId<Item> wid)
{
return Cfg::isReadOnly() || toSet<Cfg>(rSet, wid);
}
template <class Cfg, class Item>
void toCfg_ifSet(const SfxItemSet& rSet, TypedWhichId<Item> wid,
std::shared_ptr<comphelper::ConfigurationChanges> const& batch)
{
if (const auto* pItem = rSet.GetItemIfSet(wid))
Cfg::set(pItem->GetValue(), batch);
}
}
void SfxApplication::GetOptions( SfxItemSet& rSet )
{
SfxWhichIter iter(rSet);
for (auto nWhich = iter.FirstWhich(); nWhich; nWhich = iter.NextWhich())
{
bool bRet = false;
switch(nWhich)
{
case SID_ATTR_BACKUP:
bRet = true;
if (!officecfg::Office::Common::Save::Document::CreateBackup::isReadOnly())
if (!rSet.Put( SfxBoolItem( SID_ATTR_BACKUP,
(officecfg::Office::Common::Save::Document::CreateBackup::get() && !comphelper::LibreOfficeKit::isActive()) )))
bRet = false;
break;
case SID_ATTR_BACKUP_BESIDE_ORIGINAL:
bRet = toSet_ifRW<officecfg::Office::Common::Save::Document::BackupIntoDocumentFolder>(
rSet, SID_ATTR_BACKUP_BESIDE_ORIGINAL);
break;
case SID_ATTR_PRETTYPRINTING:
bRet = toSet_ifRW<officecfg::Office::Common::Save::Document::PrettyPrinting>(
rSet, SID_ATTR_PRETTYPRINTING);
break;
case SID_ATTR_WARNALIENFORMAT:
bRet = toSet_ifRW<officecfg::Office::Common::Save::Document::WarnAlienFormat>(
rSet, SID_ATTR_WARNALIENFORMAT);
break;
case SID_ATTR_AUTOSAVE:
bRet = toSet_ifRW<officecfg::Office::Recovery::AutoSave::Enabled>(
rSet, SID_ATTR_AUTOSAVE);
break;
case SID_ATTR_AUTOSAVEMINUTE:
bRet = toSet_ifRW<officecfg::Office::Recovery::AutoSave::TimeIntervall>(
rSet, SID_ATTR_AUTOSAVEMINUTE);
break;
case SID_ATTR_USERAUTOSAVE:
bRet = toSet_ifRW<officecfg::Office::Recovery::AutoSave::UserAutoSaveEnabled>(
rSet, SID_ATTR_USERAUTOSAVE);
break;
case SID_ATTR_DOCINFO:
bRet = toSet_ifRW<officecfg::Office::Common::Save::Document::EditProperty>(
rSet, SID_ATTR_DOCINFO);
break;
case SID_ATTR_QUICKLAUNCHER:
if ( ShutdownIcon::IsQuickstarterInstalled() )
{
if ( rSet.Put( SfxBoolItem( SID_ATTR_QUICKLAUNCHER,
ShutdownIcon::GetAutostart() ) ) )
bRet = true;
}
else
{
rSet.DisableItem( SID_ATTR_QUICKLAUNCHER );
bRet = true;
}
break;
case SID_SAVEREL_INET:
bRet = toSet_ifRW<officecfg::Office::Common::Save::URL::Internet>(
rSet, SID_SAVEREL_INET);
break;
case SID_SAVEREL_FSYS:
bRet = toSet_ifRW<officecfg::Office::Common::Save::URL::FileSystem>(
rSet, SID_SAVEREL_FSYS);
break;
case SID_SECURE_URL:
bRet = true;
if (!SvtSecurityOptions::IsReadOnly(SvtSecurityOptions::EOption::SecureUrls))
{
std::vector< OUString > seqURLs = SvtSecurityOptions::GetSecureURLs();
if( !rSet.Put( SfxStringListItem( SID_SECURE_URL, &seqURLs ) ) )
bRet = false;
}
break;
case SID_INET_HTTP_PROXY_NAME:
bRet = toSet<officecfg::Inet::Settings::ooInetHTTPProxyName>(
rSet, SID_INET_HTTP_PROXY_NAME);
break;
case SID_INET_HTTP_PROXY_PORT:
bRet = toSet_withDefault<officecfg::Inet::Settings::ooInetHTTPProxyPort>(
rSet, SID_INET_HTTP_PROXY_PORT, 0);
break;
case SID_INET_NOPROXY:
bRet = toSet<officecfg::Inet::Settings::ooInetNoProxy>(rSet, SID_INET_NOPROXY);
break;
default:
SAL_INFO( "sfx.appl", "W1:Wrong ID while getting Options!" );
break;
}
SAL_WARN_IF(!bRet, "sfx.appl", "Putting options failed!");
}
}
void SfxApplication::SetOptions(const SfxItemSet &rSet)
{
std::shared_ptr< comphelper::ConfigurationChanges > batch(
comphelper::ConfigurationChanges::create());
// Backup
toCfg_ifSet<officecfg::Office::Common::Save::Document::CreateBackup>(
rSet, SID_ATTR_BACKUP, batch);
toCfg_ifSet<officecfg::Office::Common::Save::Document::BackupIntoDocumentFolder>(
rSet, SID_ATTR_BACKUP_BESIDE_ORIGINAL, batch);
// PrettyPrinting
toCfg_ifSet<officecfg::Office::Common::Save::Document::PrettyPrinting>(
rSet, SID_ATTR_PRETTYPRINTING, batch);
// WarnAlienFormat
toCfg_ifSet<officecfg::Office::Common::Save::Document::WarnAlienFormat>(
rSet, SID_ATTR_WARNALIENFORMAT, batch);
// AutoSave
toCfg_ifSet<officecfg::Office::Recovery::AutoSave::Enabled>(rSet, SID_ATTR_AUTOSAVE, batch);
// AutoSave-Time
toCfg_ifSet<officecfg::Office::Recovery::AutoSave::TimeIntervall>(
rSet, SID_ATTR_AUTOSAVEMINUTE, batch);
// UserAutoSave
toCfg_ifSet<officecfg::Office::Recovery::AutoSave::UserAutoSaveEnabled>(
rSet, SID_ATTR_USERAUTOSAVE, batch);
// DocInfo
toCfg_ifSet<officecfg::Office::Common::Save::Document::EditProperty>(
rSet, SID_ATTR_DOCINFO, batch);
// HelpBalloons
toCfg_ifSet<officecfg::Office::Common::Help::ExtendedTip>(rSet, SID_HELPBALLOONS, batch);
// HelpTips
toCfg_ifSet<officecfg::Office::Common::Help::Tip>(rSet, SID_HELPTIPS, batch);
// SaveRelINet
toCfg_ifSet<officecfg::Office::Common::Save::URL::Internet>(rSet, SID_SAVEREL_INET, batch);
// SaveRelFSys
toCfg_ifSet<officecfg::Office::Common::Save::URL::FileSystem>(rSet, SID_SAVEREL_FSYS, batch);
// Undo-Count
if ( const SfxUInt16Item *pItem = rSet.GetItemIfSet(SID_ATTR_UNDO_COUNT))
{
sal_uInt16 nUndoCount = pItem->GetValue();
officecfg::Office::Common::Undo::Steps::set(nUndoCount, batch);
// To catch all Undo-Managers: Iterate over all Frames
for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst();
pFrame;
pFrame = SfxViewFrame::GetNext(*pFrame) )
{
// Get the Dispatcher of the Frames
SfxDispatcher *pDispat = pFrame->GetDispatcher();
pDispat->Flush();
// Iterate over all SfxShells on the Dispatchers Stack
sal_uInt16 nIdx = 0;
for ( SfxShell *pSh = pDispat->GetShell(nIdx);
pSh;
++nIdx, pSh = pDispat->GetShell(nIdx) )
{
SfxUndoManager *pShUndoMgr = pSh->GetUndoManager();
if ( pShUndoMgr )
pShUndoMgr->SetMaxUndoActionCount( nUndoCount );
}
}
}
// Office autostart
if ( const SfxBoolItem *pItem = rSet.GetItemIfSet(SID_ATTR_QUICKLAUNCHER))
{
ShutdownIcon::SetAutostart( pItem->GetValue() );
}
toCfg_ifSet<officecfg::Inet::Settings::ooInetProxyType>(rSet, SID_INET_PROXY_TYPE, batch);
toCfg_ifSet<officecfg::Inet::Settings::ooInetHTTPProxyName>(
rSet, SID_INET_HTTP_PROXY_NAME, batch);
toCfg_ifSet<officecfg::Inet::Settings::ooInetHTTPProxyPort>(
rSet, SID_INET_HTTP_PROXY_PORT, batch);
toCfg_ifSet<officecfg::Inet::Settings::ooInetNoProxy>(rSet, SID_INET_NOPROXY, batch);
// Secure-Referrer
if ( const SfxStringListItem *pListItem = rSet.GetItemIfSet(SID_SECURE_URL))
{
SvtSecurityOptions::SetSecureURLs( std::vector(pListItem->GetList()) );
}
// Store changed data
batch->commit();
}
void SfxApplication::NotifyEvent( const SfxEventHint& rEventHint, bool bSynchron )
{
rtl::Reference<SfxObjectShell> pDoc = rEventHint.GetObjShell();
if ( pDoc && ( pDoc->IsPreview() || !pDoc->Get_Impl()->bInitialized ) )
return;
if ( bSynchron )
{
SAL_INFO_IF(!pDoc, "sfx.appl", "SfxEvent: " << rEventHint.GetEventName());
Broadcast(rEventHint);
if ( pDoc )
pDoc->Broadcast( rEventHint );
}
else
new SfxEventAsyncer_Impl( rEventHint );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|