Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / ucb / source / ucp / file / filnot.cxx
blobc5d25b38d058eb6919e9d43514062721325c7d7c
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 "filnot.hxx"
23 #include "filid.hxx"
24 #include "bc.hxx"
25 #include "prov.hxx"
28 using namespace fileaccess;
29 using namespace com::sun::star;
30 using namespace com::sun::star::ucb;
33 ContentEventNotifier::ContentEventNotifier( TaskManager* pMyShell,
34 const uno::Reference< XContent >& xCreatorContent,
35 const uno::Reference< XContentIdentifier >& xCreatorId,
36 const std::vector< uno::Reference< uno::XInterface > >& sListeners )
37 : m_pMyShell( pMyShell ),
38 m_xCreatorContent( xCreatorContent ),
39 m_xCreatorId( xCreatorId ),
40 m_sListeners( sListeners )
45 ContentEventNotifier::ContentEventNotifier( TaskManager* pMyShell,
46 const uno::Reference< XContent >& xCreatorContent,
47 const uno::Reference< XContentIdentifier >& xCreatorId,
48 const uno::Reference< XContentIdentifier >& xOldId,
49 const std::vector< uno::Reference< uno::XInterface > >& sListeners )
50 : m_pMyShell( pMyShell ),
51 m_xCreatorContent( xCreatorContent ),
52 m_xCreatorId( xCreatorId ),
53 m_xOldId( xOldId ),
54 m_sListeners( sListeners )
59 void ContentEventNotifier::notifyChildInserted( const OUString& aChildName )
61 FileContentIdentifier* p = new FileContentIdentifier( aChildName );
62 uno::Reference< XContentIdentifier > xChildId( p );
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& r : m_sListeners )
73 uno::Reference< XContentEventListener > ref( r, uno::UNO_QUERY );
74 if( ref.is() )
75 ref->contentEvent( aEvt );
79 void ContentEventNotifier::notifyDeleted()
82 ContentEvent aEvt( m_xCreatorContent,
83 ContentAction::DELETED,
84 m_xCreatorContent,
85 m_xCreatorId );
88 for( const auto& r : m_sListeners )
90 uno::Reference< XContentEventListener > ref( r, uno::UNO_QUERY );
91 if( ref.is() )
92 ref->contentEvent( aEvt );
97 void ContentEventNotifier::notifyRemoved( const OUString& aChildName )
99 FileContentIdentifier* p = new FileContentIdentifier( aChildName );
100 uno::Reference< XContentIdentifier > xChildId( p );
102 BaseContent* pp = new BaseContent( m_pMyShell,xChildId,aChildName );
104 osl::MutexGuard aGuard( pp->m_aMutex );
105 pp->m_nState |= BaseContent::Deleted;
108 uno::Reference< XContent > xDeletedContent( pp );
111 ContentEvent aEvt( m_xCreatorContent,
112 ContentAction::REMOVED,
113 xDeletedContent,
114 m_xCreatorId );
116 for( const auto& r : m_sListeners )
118 uno::Reference< XContentEventListener > ref( r, uno::UNO_QUERY );
119 if( ref.is() )
120 ref->contentEvent( aEvt );
124 void ContentEventNotifier::notifyExchanged()
126 ContentEvent aEvt( m_xCreatorContent,
127 ContentAction::EXCHANGED,
128 m_xCreatorContent,
129 m_xOldId );
131 for( const auto& r : m_sListeners )
133 uno::Reference< XContentEventListener > ref( r, uno::UNO_QUERY );
134 if( ref.is() )
135 ref->contentEvent( aEvt );
139 /*********************************************************************************/
140 /* */
141 /* PropertySetInfoChangeNotifier */
142 /* */
143 /*********************************************************************************/
146 PropertySetInfoChangeNotifier::PropertySetInfoChangeNotifier(
147 const uno::Reference< XContent >& xCreatorContent,
148 const std::vector< uno::Reference< uno::XInterface > >& sListeners )
149 : m_xCreatorContent( xCreatorContent ),
150 m_sListeners( sListeners )
156 void
157 PropertySetInfoChangeNotifier::notifyPropertyAdded( const OUString & aPropertyName )
159 beans::PropertySetInfoChangeEvent aEvt( m_xCreatorContent,
160 aPropertyName,
162 beans::PropertySetInfoChange::PROPERTY_INSERTED );
164 for( const auto& r : m_sListeners )
166 uno::Reference< beans::XPropertySetInfoChangeListener > ref( r, uno::UNO_QUERY );
167 if( ref.is() )
168 ref->propertySetInfoChange( aEvt );
173 void
174 PropertySetInfoChangeNotifier::notifyPropertyRemoved( const OUString & aPropertyName )
176 beans::PropertySetInfoChangeEvent aEvt( m_xCreatorContent,
177 aPropertyName,
179 beans::PropertySetInfoChange::PROPERTY_REMOVED );
181 for( const auto& r : m_sListeners )
183 uno::Reference< beans::XPropertySetInfoChangeListener > ref( r, uno::UNO_QUERY );
184 if( ref.is() )
185 ref->propertySetInfoChange( aEvt );
190 /*********************************************************************************/
191 /* */
192 /* PropertySetInfoChangeNotifier */
193 /* */
194 /*********************************************************************************/
197 PropertyChangeNotifier::PropertyChangeNotifier(
198 const css::uno::Reference< XContent >& xCreatorContent,
199 std::unique_ptr<ListenerMap> pListeners )
200 : m_xCreatorContent( xCreatorContent ),
201 m_pListeners( std::move(pListeners) )
206 PropertyChangeNotifier::~PropertyChangeNotifier()
211 void PropertyChangeNotifier::notifyPropertyChanged(
212 const uno::Sequence< beans::PropertyChangeEvent >& seqChanged )
214 uno::Sequence< beans::PropertyChangeEvent > Changes = seqChanged;
216 for( auto& rChange : Changes )
217 rChange.Source = m_xCreatorContent;
219 // notify listeners for all Events
221 uno::Sequence< uno::Reference< uno::XInterface > > seqList = (*m_pListeners)[ OUString() ];
222 for( const auto& rListener : std::as_const(seqList) )
224 uno::Reference< beans::XPropertiesChangeListener > aListener( rListener,uno::UNO_QUERY );
225 if( aListener.is() )
227 aListener->propertiesChange( Changes );
231 uno::Sequence< beans::PropertyChangeEvent > seq(1);
232 for( const auto& rChange : std::as_const(Changes) )
234 seq[0] = rChange;
235 seqList = (*m_pListeners)[ rChange.PropertyName ];
237 for( const auto& rListener : std::as_const(seqList) )
239 uno::Reference< beans::XPropertiesChangeListener > aListener( rListener,uno::UNO_QUERY );
240 if( aListener.is() )
242 aListener->propertiesChange( seq );
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */