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