xref: /aoo42x/main/ucb/source/ucp/file/filnot.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_ucb.hxx"
30*cdf0e10cSrcweir #include <com/sun/star/ucb/XContent.hpp>
31*cdf0e10cSrcweir #include <com/sun/star/ucb/ContentAction.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/beans/PropertySetInfoChange.hpp>
33*cdf0e10cSrcweir #include "filnot.hxx"
34*cdf0e10cSrcweir #include "filid.hxx"
35*cdf0e10cSrcweir #include "bc.hxx"
36*cdf0e10cSrcweir #include "prov.hxx"
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir using namespace fileaccess;
41*cdf0e10cSrcweir using namespace com::sun::star;
42*cdf0e10cSrcweir using namespace com::sun::star::ucb;
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir ContentEventNotifier::ContentEventNotifier( shell* pMyShell,
46*cdf0e10cSrcweir 											const uno::Reference< XContent >& xCreatorContent,
47*cdf0e10cSrcweir 											const uno::Reference< XContentIdentifier >& xCreatorId,
48*cdf0e10cSrcweir 											const uno::Sequence< uno::Reference< uno::XInterface > >& sListeners )
49*cdf0e10cSrcweir 	: m_pMyShell( pMyShell ),
50*cdf0e10cSrcweir 	  m_xCreatorContent( xCreatorContent ),
51*cdf0e10cSrcweir 	  m_xCreatorId( xCreatorId ),
52*cdf0e10cSrcweir 	  m_sListeners( sListeners )
53*cdf0e10cSrcweir {
54*cdf0e10cSrcweir }
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir ContentEventNotifier::ContentEventNotifier( shell* pMyShell,
58*cdf0e10cSrcweir 											const uno::Reference< XContent >& xCreatorContent,
59*cdf0e10cSrcweir 											const uno::Reference< XContentIdentifier >& xCreatorId,
60*cdf0e10cSrcweir 											const uno::Reference< XContentIdentifier >& xOldId,
61*cdf0e10cSrcweir 											const uno::Sequence< uno::Reference< uno::XInterface > >& sListeners )
62*cdf0e10cSrcweir 	: m_pMyShell( pMyShell ),
63*cdf0e10cSrcweir 	  m_xCreatorContent( xCreatorContent ),
64*cdf0e10cSrcweir 	  m_xCreatorId( xCreatorId ),
65*cdf0e10cSrcweir 	  m_xOldId( xOldId ),
66*cdf0e10cSrcweir 	  m_sListeners( sListeners )
67*cdf0e10cSrcweir {
68*cdf0e10cSrcweir }
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir void ContentEventNotifier::notifyChildInserted( const rtl::OUString& aChildName )
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir 	FileContentIdentifier* p = new FileContentIdentifier( m_pMyShell,aChildName );
75*cdf0e10cSrcweir 	uno::Reference< XContentIdentifier > xChildId( p );
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir 	uno::Reference< XContent > xChildContent = m_pMyShell->m_pProvider->queryContent( xChildId );
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 	ContentEvent aEvt( m_xCreatorContent,
80*cdf0e10cSrcweir 					   ContentAction::INSERTED,
81*cdf0e10cSrcweir 					   xChildContent,
82*cdf0e10cSrcweir 					   m_xCreatorId );
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir 	for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i )
85*cdf0e10cSrcweir 	{
86*cdf0e10cSrcweir 		uno::Reference< XContentEventListener > ref( m_sListeners[i],uno::UNO_QUERY );
87*cdf0e10cSrcweir 		if( ref.is() )
88*cdf0e10cSrcweir 			ref->contentEvent( aEvt );
89*cdf0e10cSrcweir 	}
90*cdf0e10cSrcweir }
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir void ContentEventNotifier::notifyDeleted( void )
93*cdf0e10cSrcweir {
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 	ContentEvent aEvt( m_xCreatorContent,
96*cdf0e10cSrcweir 					   ContentAction::DELETED,
97*cdf0e10cSrcweir 					   m_xCreatorContent,
98*cdf0e10cSrcweir 					   m_xCreatorId );
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir 	for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i )
102*cdf0e10cSrcweir 	{
103*cdf0e10cSrcweir 		uno::Reference< XContentEventListener > ref( m_sListeners[i],uno::UNO_QUERY );
104*cdf0e10cSrcweir 		if( ref.is() )
105*cdf0e10cSrcweir 			ref->contentEvent( aEvt );
106*cdf0e10cSrcweir 	}
107*cdf0e10cSrcweir }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir void ContentEventNotifier::notifyRemoved( const rtl::OUString& aChildName )
112*cdf0e10cSrcweir {
113*cdf0e10cSrcweir 	FileContentIdentifier* p = new FileContentIdentifier( m_pMyShell,aChildName );
114*cdf0e10cSrcweir 	uno::Reference< XContentIdentifier > xChildId( p );
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir 	BaseContent* pp = new BaseContent( m_pMyShell,xChildId,aChildName );
117*cdf0e10cSrcweir 	{
118*cdf0e10cSrcweir 		osl::MutexGuard aGuard( pp->m_aMutex );
119*cdf0e10cSrcweir 		pp->m_nState |= BaseContent::Deleted;
120*cdf0e10cSrcweir 	}
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 	uno::Reference< XContent > xDeletedContent( pp );
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir 	ContentEvent aEvt( m_xCreatorContent,
126*cdf0e10cSrcweir 					   ContentAction::REMOVED,
127*cdf0e10cSrcweir 					   xDeletedContent,
128*cdf0e10cSrcweir 					   m_xCreatorId );
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 	for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i )
131*cdf0e10cSrcweir 	{
132*cdf0e10cSrcweir 		uno::Reference< XContentEventListener > ref( m_sListeners[i],uno::UNO_QUERY );
133*cdf0e10cSrcweir 		if( ref.is() )
134*cdf0e10cSrcweir 			ref->contentEvent( aEvt );
135*cdf0e10cSrcweir 	}
136*cdf0e10cSrcweir }
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir void ContentEventNotifier::notifyExchanged()
139*cdf0e10cSrcweir {
140*cdf0e10cSrcweir 	ContentEvent aEvt( m_xCreatorContent,
141*cdf0e10cSrcweir 					   ContentAction::EXCHANGED,
142*cdf0e10cSrcweir 					   m_xCreatorContent,
143*cdf0e10cSrcweir 					   m_xOldId );
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 	for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i )
146*cdf0e10cSrcweir 	{
147*cdf0e10cSrcweir 		uno::Reference< XContentEventListener > ref( m_sListeners[i],uno::UNO_QUERY );
148*cdf0e10cSrcweir 		if( ref.is() )
149*cdf0e10cSrcweir 			ref->contentEvent( aEvt );
150*cdf0e10cSrcweir 	}
151*cdf0e10cSrcweir }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir /*********************************************************************************/
154*cdf0e10cSrcweir /*                                                                               */
155*cdf0e10cSrcweir /*                      PropertySetInfoChangeNotifier                            */
156*cdf0e10cSrcweir /*                                                                               */
157*cdf0e10cSrcweir /*********************************************************************************/
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir PropertySetInfoChangeNotifier::PropertySetInfoChangeNotifier(
161*cdf0e10cSrcweir 	shell* pMyShell,
162*cdf0e10cSrcweir 	const uno::Reference< XContent >& xCreatorContent,
163*cdf0e10cSrcweir 	const uno::Reference< XContentIdentifier >& xCreatorId,
164*cdf0e10cSrcweir 	const uno::Sequence< uno::Reference< uno::XInterface > >& sListeners )
165*cdf0e10cSrcweir 	: m_pMyShell( pMyShell ),
166*cdf0e10cSrcweir 	  m_xCreatorContent( xCreatorContent ),
167*cdf0e10cSrcweir 	  m_xCreatorId( xCreatorId ),
168*cdf0e10cSrcweir 	  m_sListeners( sListeners )
169*cdf0e10cSrcweir {
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir }
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir void SAL_CALL
175*cdf0e10cSrcweir PropertySetInfoChangeNotifier::notifyPropertyAdded( const rtl::OUString & aPropertyName )
176*cdf0e10cSrcweir {
177*cdf0e10cSrcweir 	beans::PropertySetInfoChangeEvent aEvt( m_xCreatorContent,
178*cdf0e10cSrcweir 											aPropertyName,
179*cdf0e10cSrcweir 											-1,
180*cdf0e10cSrcweir 											beans::PropertySetInfoChange::PROPERTY_INSERTED );
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 	for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i )
183*cdf0e10cSrcweir 	{
184*cdf0e10cSrcweir 		uno::Reference< beans::XPropertySetInfoChangeListener > ref( m_sListeners[i],uno::UNO_QUERY );
185*cdf0e10cSrcweir 		if( ref.is() )
186*cdf0e10cSrcweir 			ref->propertySetInfoChange( aEvt );
187*cdf0e10cSrcweir 	}
188*cdf0e10cSrcweir }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir void SAL_CALL
192*cdf0e10cSrcweir PropertySetInfoChangeNotifier::notifyPropertyRemoved( const rtl::OUString & aPropertyName )
193*cdf0e10cSrcweir {
194*cdf0e10cSrcweir 	beans::PropertySetInfoChangeEvent aEvt( m_xCreatorContent,
195*cdf0e10cSrcweir 											aPropertyName,
196*cdf0e10cSrcweir 											-1,
197*cdf0e10cSrcweir 											beans::PropertySetInfoChange::PROPERTY_REMOVED );
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir 	for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i )
200*cdf0e10cSrcweir 	{
201*cdf0e10cSrcweir 		uno::Reference< beans::XPropertySetInfoChangeListener > ref( m_sListeners[i],uno::UNO_QUERY );
202*cdf0e10cSrcweir 		if( ref.is() )
203*cdf0e10cSrcweir 			ref->propertySetInfoChange( aEvt );
204*cdf0e10cSrcweir 	}
205*cdf0e10cSrcweir }
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir /*********************************************************************************/
209*cdf0e10cSrcweir /*                                                                               */
210*cdf0e10cSrcweir /*                      PropertySetInfoChangeNotifier                            */
211*cdf0e10cSrcweir /*                                                                               */
212*cdf0e10cSrcweir /*********************************************************************************/
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir PropertyChangeNotifier::PropertyChangeNotifier(
216*cdf0e10cSrcweir 	shell* pMyShell,
217*cdf0e10cSrcweir 	const com::sun::star::uno::Reference< XContent >& xCreatorContent,
218*cdf0e10cSrcweir 	const com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier >& xCreatorId,
219*cdf0e10cSrcweir 	ListenerMap* pListeners )
220*cdf0e10cSrcweir 	: m_pMyShell( pMyShell ),
221*cdf0e10cSrcweir 	  m_xCreatorContent( xCreatorContent ),
222*cdf0e10cSrcweir 	  m_xCreatorId( xCreatorId ),
223*cdf0e10cSrcweir 	  m_pListeners( pListeners )
224*cdf0e10cSrcweir {
225*cdf0e10cSrcweir }
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir PropertyChangeNotifier::~PropertyChangeNotifier()
229*cdf0e10cSrcweir {
230*cdf0e10cSrcweir 	delete m_pListeners;
231*cdf0e10cSrcweir }
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir void PropertyChangeNotifier::notifyPropertyChanged(
235*cdf0e10cSrcweir 	uno::Sequence< beans::PropertyChangeEvent > Changes )
236*cdf0e10cSrcweir {
237*cdf0e10cSrcweir 	sal_Int32 j;
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir 	for( j = 0; j < Changes.getLength(); ++j )
240*cdf0e10cSrcweir 		Changes[j].Source = m_xCreatorContent;
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir 	// notify listeners for all Events
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir 	uno::Sequence< uno::Reference< uno::XInterface > > seqList = (*m_pListeners)[ rtl::OUString() ];
245*cdf0e10cSrcweir 	for( j = 0; j < seqList.getLength(); ++j )
246*cdf0e10cSrcweir 	{
247*cdf0e10cSrcweir 		uno::Reference< beans::XPropertiesChangeListener > aListener( seqList[j],uno::UNO_QUERY );
248*cdf0e10cSrcweir 		if( aListener.is() )
249*cdf0e10cSrcweir 		{
250*cdf0e10cSrcweir 			aListener->propertiesChange( Changes );
251*cdf0e10cSrcweir 		}
252*cdf0e10cSrcweir 	}
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir 	uno::Sequence< beans::PropertyChangeEvent > seq(1);
255*cdf0e10cSrcweir 	for( j = 0; j < Changes.getLength(); ++j )
256*cdf0e10cSrcweir 	{
257*cdf0e10cSrcweir 		seq[0] = Changes[j];
258*cdf0e10cSrcweir 		seqList = (*m_pListeners)[ seq[0].PropertyName ];
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir 		for( sal_Int32 i = 0; i < seqList.getLength(); ++i )
261*cdf0e10cSrcweir 		{
262*cdf0e10cSrcweir 			uno::Reference< beans::XPropertiesChangeListener > aListener( seqList[j],uno::UNO_QUERY );
263*cdf0e10cSrcweir 			if( aListener.is() )
264*cdf0e10cSrcweir 			{
265*cdf0e10cSrcweir 				aListener->propertiesChange( seq );
266*cdf0e10cSrcweir 			}
267*cdf0e10cSrcweir 		}
268*cdf0e10cSrcweir 	}
269*cdf0e10cSrcweir }
270