/* -*- 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 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "shutdownicon.hxx" using namespace ::com::sun::star::uno; using namespace ::com::sun::star::util; using namespace ::com::sun::star::beans; namespace { class SfxEventAsyncer_Impl : public SfxListener { SfxEventHint aHint; std::unique_ptr pIdle; public: virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override; explicit SfxEventAsyncer_Impl(const SfxEventHint& rHint); 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(); } 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 bool toSet(SfxItemSet& rSet, TypedWhichId wid) { return rSet.Put(Item(wid, Cfg::get())); } template bool toSet_withDefault(SfxItemSet& rSet, TypedWhichId wid, Val&& defVal) { return rSet.Put(Item(wid, Cfg::get().value_or(std::move(defVal)))); } template bool toSet_ifRW(SfxItemSet& rSet, TypedWhichId wid) { return Cfg::isReadOnly() || toSet(rSet, wid); } template void toCfg_ifSet(const SfxItemSet& rSet, TypedWhichId wid, std::shared_ptr 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( rSet, SID_ATTR_BACKUP_BESIDE_ORIGINAL); break; case SID_ATTR_PRETTYPRINTING: bRet = toSet_ifRW( rSet, SID_ATTR_PRETTYPRINTING); break; case SID_ATTR_WARNALIENFORMAT: bRet = toSet_ifRW( rSet, SID_ATTR_WARNALIENFORMAT); break; case SID_ATTR_AUTOSAVE: bRet = toSet_ifRW( rSet, SID_ATTR_AUTOSAVE); break; case SID_ATTR_AUTOSAVEMINUTE: bRet = toSet_ifRW( rSet, SID_ATTR_AUTOSAVEMINUTE); break; case SID_ATTR_USERAUTOSAVE: bRet = toSet_ifRW( rSet, SID_ATTR_USERAUTOSAVE); break; case SID_ATTR_DOCINFO: bRet = toSet_ifRW( 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( rSet, SID_SAVEREL_INET); break; case SID_SAVEREL_FSYS: bRet = toSet_ifRW( 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( rSet, SID_INET_HTTP_PROXY_NAME); break; case SID_INET_HTTP_PROXY_PORT: bRet = toSet_withDefault( rSet, SID_INET_HTTP_PROXY_PORT, 0); break; case SID_INET_NOPROXY: bRet = toSet(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( rSet, SID_ATTR_BACKUP, batch); toCfg_ifSet( rSet, SID_ATTR_BACKUP_BESIDE_ORIGINAL, batch); // PrettyPrinting toCfg_ifSet( rSet, SID_ATTR_PRETTYPRINTING, batch); // WarnAlienFormat toCfg_ifSet( rSet, SID_ATTR_WARNALIENFORMAT, batch); // AutoSave toCfg_ifSet(rSet, SID_ATTR_AUTOSAVE, batch); // AutoSave-Time toCfg_ifSet( rSet, SID_ATTR_AUTOSAVEMINUTE, batch); // UserAutoSave toCfg_ifSet( rSet, SID_ATTR_USERAUTOSAVE, batch); // DocInfo toCfg_ifSet( rSet, SID_ATTR_DOCINFO, batch); // HelpBalloons toCfg_ifSet(rSet, SID_HELPBALLOONS, batch); // HelpTips toCfg_ifSet(rSet, SID_HELPTIPS, batch); // SaveRelINet toCfg_ifSet(rSet, SID_SAVEREL_INET, batch); // SaveRelFSys toCfg_ifSet(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(rSet, SID_INET_PROXY_TYPE, batch); toCfg_ifSet( rSet, SID_INET_HTTP_PROXY_NAME, batch); toCfg_ifSet( rSet, SID_INET_HTTP_PROXY_PORT, batch); toCfg_ifSet(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 ) { 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: */