1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_ucb.hxx"
26 #include <com/sun/star/ucb/XContent.hpp>
27 #include <com/sun/star/ucb/ContentAction.hpp>
28 #include <com/sun/star/beans/PropertySetInfoChange.hpp>
29 #include "filnot.hxx"
30 #include "filid.hxx"
31 #include "bc.hxx"
32 #include "prov.hxx"
33
34
35
36 using namespace fileaccess;
37 using namespace com::sun::star;
38 using namespace com::sun::star::ucb;
39
40
ContentEventNotifier(shell * pMyShell,const uno::Reference<XContent> & xCreatorContent,const uno::Reference<XContentIdentifier> & xCreatorId,const uno::Sequence<uno::Reference<uno::XInterface>> & sListeners)41 ContentEventNotifier::ContentEventNotifier( shell* pMyShell,
42 const uno::Reference< XContent >& xCreatorContent,
43 const uno::Reference< XContentIdentifier >& xCreatorId,
44 const uno::Sequence< uno::Reference< uno::XInterface > >& sListeners )
45 : m_pMyShell( pMyShell ),
46 m_xCreatorContent( xCreatorContent ),
47 m_xCreatorId( xCreatorId ),
48 m_sListeners( sListeners )
49 {
50 }
51
52
ContentEventNotifier(shell * pMyShell,const uno::Reference<XContent> & xCreatorContent,const uno::Reference<XContentIdentifier> & xCreatorId,const uno::Reference<XContentIdentifier> & xOldId,const uno::Sequence<uno::Reference<uno::XInterface>> & sListeners)53 ContentEventNotifier::ContentEventNotifier( shell* pMyShell,
54 const uno::Reference< XContent >& xCreatorContent,
55 const uno::Reference< XContentIdentifier >& xCreatorId,
56 const uno::Reference< XContentIdentifier >& xOldId,
57 const uno::Sequence< uno::Reference< uno::XInterface > >& sListeners )
58 : m_pMyShell( pMyShell ),
59 m_xCreatorContent( xCreatorContent ),
60 m_xCreatorId( xCreatorId ),
61 m_xOldId( xOldId ),
62 m_sListeners( sListeners )
63 {
64 }
65
66
67
notifyChildInserted(const rtl::OUString & aChildName)68 void ContentEventNotifier::notifyChildInserted( const rtl::OUString& aChildName )
69 {
70 FileContentIdentifier* p = new FileContentIdentifier( m_pMyShell,aChildName );
71 uno::Reference< XContentIdentifier > xChildId( p );
72
73 uno::Reference< XContent > xChildContent = m_pMyShell->m_pProvider->queryContent( xChildId );
74
75 ContentEvent aEvt( m_xCreatorContent,
76 ContentAction::INSERTED,
77 xChildContent,
78 m_xCreatorId );
79
80 for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i )
81 {
82 uno::Reference< XContentEventListener > ref( m_sListeners[i],uno::UNO_QUERY );
83 if( ref.is() )
84 ref->contentEvent( aEvt );
85 }
86 }
87
notifyDeleted(void)88 void ContentEventNotifier::notifyDeleted( void )
89 {
90
91 ContentEvent aEvt( m_xCreatorContent,
92 ContentAction::DELETED,
93 m_xCreatorContent,
94 m_xCreatorId );
95
96
97 for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i )
98 {
99 uno::Reference< XContentEventListener > ref( m_sListeners[i],uno::UNO_QUERY );
100 if( ref.is() )
101 ref->contentEvent( aEvt );
102 }
103 }
104
105
106
notifyRemoved(const rtl::OUString & aChildName)107 void ContentEventNotifier::notifyRemoved( const rtl::OUString& aChildName )
108 {
109 FileContentIdentifier* p = new FileContentIdentifier( m_pMyShell,aChildName );
110 uno::Reference< XContentIdentifier > xChildId( p );
111
112 BaseContent* pp = new BaseContent( m_pMyShell,xChildId,aChildName );
113 {
114 osl::MutexGuard aGuard( pp->m_aMutex );
115 pp->m_nState |= BaseContent::Deleted;
116 }
117
118 uno::Reference< XContent > xDeletedContent( pp );
119
120
121 ContentEvent aEvt( m_xCreatorContent,
122 ContentAction::REMOVED,
123 xDeletedContent,
124 m_xCreatorId );
125
126 for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i )
127 {
128 uno::Reference< XContentEventListener > ref( m_sListeners[i],uno::UNO_QUERY );
129 if( ref.is() )
130 ref->contentEvent( aEvt );
131 }
132 }
133
notifyExchanged()134 void ContentEventNotifier::notifyExchanged()
135 {
136 ContentEvent aEvt( m_xCreatorContent,
137 ContentAction::EXCHANGED,
138 m_xCreatorContent,
139 m_xOldId );
140
141 for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i )
142 {
143 uno::Reference< XContentEventListener > ref( m_sListeners[i],uno::UNO_QUERY );
144 if( ref.is() )
145 ref->contentEvent( aEvt );
146 }
147 }
148
149 /*********************************************************************************/
150 /* */
151 /* PropertySetInfoChangeNotifier */
152 /* */
153 /*********************************************************************************/
154
155
PropertySetInfoChangeNotifier(shell * pMyShell,const uno::Reference<XContent> & xCreatorContent,const uno::Reference<XContentIdentifier> & xCreatorId,const uno::Sequence<uno::Reference<uno::XInterface>> & sListeners)156 PropertySetInfoChangeNotifier::PropertySetInfoChangeNotifier(
157 shell* pMyShell,
158 const uno::Reference< XContent >& xCreatorContent,
159 const uno::Reference< XContentIdentifier >& xCreatorId,
160 const uno::Sequence< uno::Reference< uno::XInterface > >& sListeners )
161 : m_pMyShell( pMyShell ),
162 m_xCreatorContent( xCreatorContent ),
163 m_xCreatorId( xCreatorId ),
164 m_sListeners( sListeners )
165 {
166
167 }
168
169
170 void SAL_CALL
notifyPropertyAdded(const rtl::OUString & aPropertyName)171 PropertySetInfoChangeNotifier::notifyPropertyAdded( const rtl::OUString & aPropertyName )
172 {
173 beans::PropertySetInfoChangeEvent aEvt( m_xCreatorContent,
174 aPropertyName,
175 -1,
176 beans::PropertySetInfoChange::PROPERTY_INSERTED );
177
178 for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i )
179 {
180 uno::Reference< beans::XPropertySetInfoChangeListener > ref( m_sListeners[i],uno::UNO_QUERY );
181 if( ref.is() )
182 ref->propertySetInfoChange( aEvt );
183 }
184 }
185
186
187 void SAL_CALL
notifyPropertyRemoved(const rtl::OUString & aPropertyName)188 PropertySetInfoChangeNotifier::notifyPropertyRemoved( const rtl::OUString & aPropertyName )
189 {
190 beans::PropertySetInfoChangeEvent aEvt( m_xCreatorContent,
191 aPropertyName,
192 -1,
193 beans::PropertySetInfoChange::PROPERTY_REMOVED );
194
195 for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i )
196 {
197 uno::Reference< beans::XPropertySetInfoChangeListener > ref( m_sListeners[i],uno::UNO_QUERY );
198 if( ref.is() )
199 ref->propertySetInfoChange( aEvt );
200 }
201 }
202
203
204 /*********************************************************************************/
205 /* */
206 /* PropertySetInfoChangeNotifier */
207 /* */
208 /*********************************************************************************/
209
210
PropertyChangeNotifier(shell * pMyShell,const com::sun::star::uno::Reference<XContent> & xCreatorContent,const com::sun::star::uno::Reference<com::sun::star::ucb::XContentIdentifier> & xCreatorId,ListenerMap * pListeners)211 PropertyChangeNotifier::PropertyChangeNotifier(
212 shell* pMyShell,
213 const com::sun::star::uno::Reference< XContent >& xCreatorContent,
214 const com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier >& xCreatorId,
215 ListenerMap* pListeners )
216 : m_pMyShell( pMyShell ),
217 m_xCreatorContent( xCreatorContent ),
218 m_xCreatorId( xCreatorId ),
219 m_pListeners( pListeners )
220 {
221 }
222
223
~PropertyChangeNotifier()224 PropertyChangeNotifier::~PropertyChangeNotifier()
225 {
226 delete m_pListeners;
227 }
228
229
notifyPropertyChanged(uno::Sequence<beans::PropertyChangeEvent> Changes)230 void PropertyChangeNotifier::notifyPropertyChanged(
231 uno::Sequence< beans::PropertyChangeEvent > Changes )
232 {
233 sal_Int32 j;
234
235 for( j = 0; j < Changes.getLength(); ++j )
236 Changes[j].Source = m_xCreatorContent;
237
238 // notify listeners for all Events
239
240 uno::Sequence< uno::Reference< uno::XInterface > > seqList = (*m_pListeners)[ rtl::OUString() ];
241 for( j = 0; j < seqList.getLength(); ++j )
242 {
243 uno::Reference< beans::XPropertiesChangeListener > aListener( seqList[j],uno::UNO_QUERY );
244 if( aListener.is() )
245 {
246 aListener->propertiesChange( Changes );
247 }
248 }
249
250 uno::Sequence< beans::PropertyChangeEvent > seq(1);
251 for( j = 0; j < Changes.getLength(); ++j )
252 {
253 seq[0] = Changes[j];
254 seqList = (*m_pListeners)[ seq[0].PropertyName ];
255
256 for( sal_Int32 i = 0; i < seqList.getLength(); ++i )
257 {
258 uno::Reference< beans::XPropertiesChangeListener > aListener( seqList[j],uno::UNO_QUERY );
259 if( aListener.is() )
260 {
261 aListener->propertiesChange( seq );
262 }
263 }
264 }
265 }
266