Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / ucb / source / ucp / file / filnot.cxx
blobd384dc0ea717f57ba3fc150a3897519b78b91ec9
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 <com/sun/star/ucb/ContentAction.hpp>
21 #include <com/sun/star/beans/PropertySetInfoChange.hpp>
22 #include <rtl/ref.hxx>
23 #include "filnot.hxx"
24 #include "filid.hxx"
25 #include "bc.hxx"
26 #include "prov.hxx"
29 using namespace fileaccess;
30 using namespace com::sun::star;
31 using namespace com::sun::star::ucb;
34 ContentEventNotifier::ContentEventNotifier( TaskManager* pMyShell,
35 const uno::Reference< XContent >& xCreatorContent,
36 const uno::Reference< XContentIdentifier >& xCreatorId,
37 std::vector< uno::Reference< ucb::XContentEventListener > >&& sListeners )
38 : m_pMyShell( pMyShell ),
39 m_xCreatorContent( xCreatorContent ),
40 m_xCreatorId( xCreatorId ),
41 m_sListeners( std::move(sListeners) )
46 ContentEventNotifier::ContentEventNotifier( TaskManager* pMyShell,
47 const uno::Reference< XContent >& xCreatorContent,
48 const uno::Reference< XContentIdentifier >& xCreatorId,
49 const uno::Reference< XContentIdentifier >& xOldId,
50 std::vector< uno::Reference< ucb::XContentEventListener > >&& sListeners )
51 : m_pMyShell( pMyShell ),
52 m_xCreatorContent( xCreatorContent ),
53 m_xCreatorId( xCreatorId ),
54 m_xOldId( xOldId ),
55 m_sListeners( std::move(sListeners) )
60 void ContentEventNotifier::notifyChildInserted( const OUString& aChildName ) const
62 rtl::Reference<FileContentIdentifier> xChildId = new FileContentIdentifier( aChildName );
64 uno::Reference< XContent > xChildContent = m_pMyShell->m_pProvider->queryContent( xChildId );
66 ContentEvent aEvt( m_xCreatorContent,
67 ContentAction::INSERTED,
68 xChildContent,
69 m_xCreatorId );
71 for( const auto& ref : m_sListeners )
72 ref->contentEvent( aEvt );
75 void ContentEventNotifier::notifyDeleted() const
77 ContentEvent aEvt( m_xCreatorContent,
78 ContentAction::DELETED,
79 m_xCreatorContent,
80 m_xCreatorId );
83 for( const auto& ref : m_sListeners )
84 ref->contentEvent( aEvt );
88 void ContentEventNotifier::notifyRemoved( const OUString& aChildName ) const
90 rtl::Reference<FileContentIdentifier> xChildId = new FileContentIdentifier( aChildName );
92 rtl::Reference<BaseContent> pp = new BaseContent( m_pMyShell,xChildId,aChildName );
94 std::unique_lock aGuard( pp->m_aMutex );
95 pp->m_nState |= BaseContent::Deleted;
98 ContentEvent aEvt( m_xCreatorContent,
99 ContentAction::REMOVED,
101 m_xCreatorId );
103 for( const auto& ref : m_sListeners )
104 ref->contentEvent( aEvt );
107 void ContentEventNotifier::notifyExchanged() const
109 ContentEvent aEvt( m_xCreatorContent,
110 ContentAction::EXCHANGED,
111 m_xCreatorContent,
112 m_xOldId );
114 for( const auto& ref : m_sListeners )
115 ref->contentEvent( aEvt );
118 /*********************************************************************************/
119 /* */
120 /* PropertySetInfoChangeNotifier */
121 /* */
122 /*********************************************************************************/
125 PropertySetInfoChangeNotifier::PropertySetInfoChangeNotifier(
126 const uno::Reference< XContent >& xCreatorContent,
127 std::vector< uno::Reference< beans::XPropertySetInfoChangeListener > >&& sListeners )
128 : m_xCreatorContent( xCreatorContent ),
129 m_sListeners( std::move(sListeners) )
135 void
136 PropertySetInfoChangeNotifier::notifyPropertyAdded( const OUString & aPropertyName ) const
138 beans::PropertySetInfoChangeEvent aEvt( m_xCreatorContent,
139 aPropertyName,
141 beans::PropertySetInfoChange::PROPERTY_INSERTED );
143 for( const auto& ref : m_sListeners )
144 ref->propertySetInfoChange( aEvt );
148 void
149 PropertySetInfoChangeNotifier::notifyPropertyRemoved( const OUString & aPropertyName ) const
151 beans::PropertySetInfoChangeEvent aEvt( m_xCreatorContent,
152 aPropertyName,
154 beans::PropertySetInfoChange::PROPERTY_REMOVED );
156 for( const auto& ref : m_sListeners )
157 ref->propertySetInfoChange( aEvt );
161 /*********************************************************************************/
162 /* */
163 /* PropertySetInfoChangeNotifier */
164 /* */
165 /*********************************************************************************/
168 PropertyChangeNotifier::PropertyChangeNotifier(
169 const css::uno::Reference< XContent >& xCreatorContent,
170 ListenerMap&& pListeners )
171 : m_xCreatorContent( xCreatorContent ),
172 m_aListeners( std::move(pListeners) )
177 void PropertyChangeNotifier::notifyPropertyChanged(
178 const uno::Sequence< beans::PropertyChangeEvent >& seqChanged ) const
180 uno::Sequence< beans::PropertyChangeEvent > Changes = seqChanged;
182 for( auto& rChange : asNonConstRange(Changes) )
183 rChange.Source = m_xCreatorContent;
185 // notify listeners for all Events
187 auto it = m_aListeners.find( OUString() );
188 if (it != m_aListeners.end())
190 const std::vector< uno::Reference< beans::XPropertiesChangeListener > >& seqList = it->second;
191 for( const auto& rListener : seqList )
192 rListener->propertiesChange( Changes );
195 for( const auto& rChange : std::as_const(Changes) )
197 uno::Sequence< beans::PropertyChangeEvent > seq{ rChange };
198 it = m_aListeners.find( rChange.PropertyName );
199 if (it != m_aListeners.end())
201 const std::vector< uno::Reference< beans::XPropertiesChangeListener > >& seqList = it->second;
202 for( const auto& rListener : seqList )
203 rListener->propertiesChange( seq );
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */