Update ooo320-m1
[ooovba.git] / ucb / source / ucp / file / filnot.cxx
blob4039e442b754d9582ec7121cbef61c37c470600a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filnot.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucb.hxx"
33 #include <com/sun/star/ucb/XContent.hpp>
34 #include <com/sun/star/ucb/ContentAction.hpp>
35 #include <com/sun/star/beans/PropertySetInfoChange.hpp>
36 #include "filnot.hxx"
37 #include "filid.hxx"
38 #include "bc.hxx"
39 #include "prov.hxx"
43 using namespace fileaccess;
44 using namespace com::sun::star;
45 using namespace com::sun::star::ucb;
48 ContentEventNotifier::ContentEventNotifier( shell* pMyShell,
49 const uno::Reference< XContent >& xCreatorContent,
50 const uno::Reference< XContentIdentifier >& xCreatorId,
51 const uno::Sequence< uno::Reference< uno::XInterface > >& sListeners )
52 : m_pMyShell( pMyShell ),
53 m_xCreatorContent( xCreatorContent ),
54 m_xCreatorId( xCreatorId ),
55 m_sListeners( sListeners )
60 ContentEventNotifier::ContentEventNotifier( shell* pMyShell,
61 const uno::Reference< XContent >& xCreatorContent,
62 const uno::Reference< XContentIdentifier >& xCreatorId,
63 const uno::Reference< XContentIdentifier >& xOldId,
64 const uno::Sequence< uno::Reference< uno::XInterface > >& sListeners )
65 : m_pMyShell( pMyShell ),
66 m_xCreatorContent( xCreatorContent ),
67 m_xCreatorId( xCreatorId ),
68 m_xOldId( xOldId ),
69 m_sListeners( sListeners )
75 void ContentEventNotifier::notifyChildInserted( const rtl::OUString& aChildName )
77 FileContentIdentifier* p = new FileContentIdentifier( m_pMyShell,aChildName );
78 uno::Reference< XContentIdentifier > xChildId( p );
80 uno::Reference< XContent > xChildContent = m_pMyShell->m_pProvider->queryContent( xChildId );
82 ContentEvent aEvt( m_xCreatorContent,
83 ContentAction::INSERTED,
84 xChildContent,
85 m_xCreatorId );
87 for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i )
89 uno::Reference< XContentEventListener > ref( m_sListeners[i],uno::UNO_QUERY );
90 if( ref.is() )
91 ref->contentEvent( aEvt );
95 void ContentEventNotifier::notifyDeleted( void )
98 ContentEvent aEvt( m_xCreatorContent,
99 ContentAction::DELETED,
100 m_xCreatorContent,
101 m_xCreatorId );
104 for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i )
106 uno::Reference< XContentEventListener > ref( m_sListeners[i],uno::UNO_QUERY );
107 if( ref.is() )
108 ref->contentEvent( aEvt );
114 void ContentEventNotifier::notifyRemoved( const rtl::OUString& aChildName )
116 FileContentIdentifier* p = new FileContentIdentifier( m_pMyShell,aChildName );
117 uno::Reference< XContentIdentifier > xChildId( p );
119 BaseContent* pp = new BaseContent( m_pMyShell,xChildId,aChildName );
121 osl::MutexGuard aGuard( pp->m_aMutex );
122 pp->m_nState |= BaseContent::Deleted;
125 uno::Reference< XContent > xDeletedContent( pp );
128 ContentEvent aEvt( m_xCreatorContent,
129 ContentAction::REMOVED,
130 xDeletedContent,
131 m_xCreatorId );
133 for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i )
135 uno::Reference< XContentEventListener > ref( m_sListeners[i],uno::UNO_QUERY );
136 if( ref.is() )
137 ref->contentEvent( aEvt );
141 void ContentEventNotifier::notifyExchanged()
143 ContentEvent aEvt( m_xCreatorContent,
144 ContentAction::EXCHANGED,
145 m_xCreatorContent,
146 m_xOldId );
148 for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i )
150 uno::Reference< XContentEventListener > ref( m_sListeners[i],uno::UNO_QUERY );
151 if( ref.is() )
152 ref->contentEvent( aEvt );
156 /*********************************************************************************/
157 /* */
158 /* PropertySetInfoChangeNotifier */
159 /* */
160 /*********************************************************************************/
163 PropertySetInfoChangeNotifier::PropertySetInfoChangeNotifier(
164 shell* pMyShell,
165 const uno::Reference< XContent >& xCreatorContent,
166 const uno::Reference< XContentIdentifier >& xCreatorId,
167 const uno::Sequence< uno::Reference< uno::XInterface > >& sListeners )
168 : m_pMyShell( pMyShell ),
169 m_xCreatorContent( xCreatorContent ),
170 m_xCreatorId( xCreatorId ),
171 m_sListeners( sListeners )
177 void SAL_CALL
178 PropertySetInfoChangeNotifier::notifyPropertyAdded( const rtl::OUString & aPropertyName )
180 beans::PropertySetInfoChangeEvent aEvt( m_xCreatorContent,
181 aPropertyName,
183 beans::PropertySetInfoChange::PROPERTY_INSERTED );
185 for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i )
187 uno::Reference< beans::XPropertySetInfoChangeListener > ref( m_sListeners[i],uno::UNO_QUERY );
188 if( ref.is() )
189 ref->propertySetInfoChange( aEvt );
194 void SAL_CALL
195 PropertySetInfoChangeNotifier::notifyPropertyRemoved( const rtl::OUString & aPropertyName )
197 beans::PropertySetInfoChangeEvent aEvt( m_xCreatorContent,
198 aPropertyName,
200 beans::PropertySetInfoChange::PROPERTY_REMOVED );
202 for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i )
204 uno::Reference< beans::XPropertySetInfoChangeListener > ref( m_sListeners[i],uno::UNO_QUERY );
205 if( ref.is() )
206 ref->propertySetInfoChange( aEvt );
211 /*********************************************************************************/
212 /* */
213 /* PropertySetInfoChangeNotifier */
214 /* */
215 /*********************************************************************************/
218 PropertyChangeNotifier::PropertyChangeNotifier(
219 shell* pMyShell,
220 const com::sun::star::uno::Reference< XContent >& xCreatorContent,
221 const com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier >& xCreatorId,
222 ListenerMap* pListeners )
223 : m_pMyShell( pMyShell ),
224 m_xCreatorContent( xCreatorContent ),
225 m_xCreatorId( xCreatorId ),
226 m_pListeners( pListeners )
231 PropertyChangeNotifier::~PropertyChangeNotifier()
233 delete m_pListeners;
237 void PropertyChangeNotifier::notifyPropertyChanged(
238 uno::Sequence< beans::PropertyChangeEvent > Changes )
240 sal_Int32 j;
242 for( j = 0; j < Changes.getLength(); ++j )
243 Changes[j].Source = m_xCreatorContent;
245 // notify listeners for all Events
247 uno::Sequence< uno::Reference< uno::XInterface > > seqList = (*m_pListeners)[ rtl::OUString() ];
248 for( j = 0; j < seqList.getLength(); ++j )
250 uno::Reference< beans::XPropertiesChangeListener > aListener( seqList[j],uno::UNO_QUERY );
251 if( aListener.is() )
253 aListener->propertiesChange( Changes );
257 uno::Sequence< beans::PropertyChangeEvent > seq(1);
258 for( j = 0; j < Changes.getLength(); ++j )
260 seq[0] = Changes[j];
261 seqList = (*m_pListeners)[ seq[0].PropertyName ];
263 for( sal_Int32 i = 0; i < seqList.getLength(); ++i )
265 uno::Reference< beans::XPropertiesChangeListener > aListener( seqList[j],uno::UNO_QUERY );
266 if( aListener.is() )
268 aListener->propertiesChange( seq );