LibreOffice Module ucb (master)  1
filnot.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <com/sun/star/ucb/XContent.hpp>
21 #include <com/sun/star/ucb/ContentAction.hpp>
22 #include <com/sun/star/beans/PropertySetInfoChange.hpp>
23 #include "filnot.hxx"
24 #include "filid.hxx"
25 #include "bc.hxx"
26 #include "prov.hxx"
27 
28 
29 using namespace fileaccess;
30 using namespace com::sun::star;
31 using namespace com::sun::star::ucb;
32 
33 
35  const uno::Reference< XContent >& xCreatorContent,
36  const uno::Reference< XContentIdentifier >& xCreatorId,
37  const std::vector< uno::Reference< uno::XInterface > >& sListeners )
38  : m_pMyShell( pMyShell ),
39  m_xCreatorContent( xCreatorContent ),
40  m_xCreatorId( xCreatorId ),
41  m_sListeners( sListeners )
42 {
43 }
44 
45 
47  const uno::Reference< XContent >& xCreatorContent,
48  const uno::Reference< XContentIdentifier >& xCreatorId,
49  const uno::Reference< XContentIdentifier >& xOldId,
50  const std::vector< uno::Reference< uno::XInterface > >& sListeners )
51  : m_pMyShell( pMyShell ),
52  m_xCreatorContent( xCreatorContent ),
53  m_xCreatorId( xCreatorId ),
54  m_xOldId( xOldId ),
55  m_sListeners( sListeners )
56 {
57 }
58 
59 
60 void ContentEventNotifier::notifyChildInserted( const OUString& aChildName )
61 {
62  FileContentIdentifier* p = new FileContentIdentifier( aChildName );
63  uno::Reference< XContentIdentifier > xChildId( p );
64 
65  uno::Reference< XContent > xChildContent = m_pMyShell->m_pProvider->queryContent( xChildId );
66 
67  ContentEvent aEvt( m_xCreatorContent,
68  ContentAction::INSERTED,
69  xChildContent,
70  m_xCreatorId );
71 
72  for( const auto& r : m_sListeners )
73  {
74  uno::Reference< XContentEventListener > ref( r, uno::UNO_QUERY );
75  if( ref.is() )
76  ref->contentEvent( aEvt );
77  }
78 }
79 
81 {
82 
83  ContentEvent aEvt( m_xCreatorContent,
84  ContentAction::DELETED,
86  m_xCreatorId );
87 
88 
89  for( const auto& r : m_sListeners )
90  {
91  uno::Reference< XContentEventListener > ref( r, uno::UNO_QUERY );
92  if( ref.is() )
93  ref->contentEvent( aEvt );
94  }
95 }
96 
97 
98 void ContentEventNotifier::notifyRemoved( const OUString& aChildName )
99 {
100  FileContentIdentifier* p = new FileContentIdentifier( aChildName );
101  uno::Reference< XContentIdentifier > xChildId( p );
102 
103  BaseContent* pp = new BaseContent( m_pMyShell,xChildId,aChildName );
104  {
105  osl::MutexGuard aGuard( pp->m_aMutex );
107  }
108 
109  uno::Reference< XContent > xDeletedContent( pp );
110 
111 
112  ContentEvent aEvt( m_xCreatorContent,
113  ContentAction::REMOVED,
114  xDeletedContent,
115  m_xCreatorId );
116 
117  for( const auto& r : m_sListeners )
118  {
119  uno::Reference< XContentEventListener > ref( r, uno::UNO_QUERY );
120  if( ref.is() )
121  ref->contentEvent( aEvt );
122  }
123 }
124 
126 {
127  ContentEvent aEvt( m_xCreatorContent,
128  ContentAction::EXCHANGED,
130  m_xOldId );
131 
132  for( const auto& r : m_sListeners )
133  {
134  uno::Reference< XContentEventListener > ref( r, uno::UNO_QUERY );
135  if( ref.is() )
136  ref->contentEvent( aEvt );
137  }
138 }
139 
140 /*********************************************************************************/
141 /* */
142 /* PropertySetInfoChangeNotifier */
143 /* */
144 /*********************************************************************************/
145 
146 
148  const uno::Reference< XContent >& xCreatorContent,
149  const std::vector< uno::Reference< uno::XInterface > >& sListeners )
150  : m_xCreatorContent( xCreatorContent ),
151  m_sListeners( sListeners )
152 {
153 
154 }
155 
156 
157 void
158 PropertySetInfoChangeNotifier::notifyPropertyAdded( const OUString & aPropertyName )
159 {
160  beans::PropertySetInfoChangeEvent aEvt( m_xCreatorContent,
161  aPropertyName,
162  -1,
163  beans::PropertySetInfoChange::PROPERTY_INSERTED );
164 
165  for( const auto& r : m_sListeners )
166  {
167  uno::Reference< beans::XPropertySetInfoChangeListener > ref( r, uno::UNO_QUERY );
168  if( ref.is() )
169  ref->propertySetInfoChange( aEvt );
170  }
171 }
172 
173 
174 void
176 {
177  beans::PropertySetInfoChangeEvent aEvt( m_xCreatorContent,
178  aPropertyName,
179  -1,
180  beans::PropertySetInfoChange::PROPERTY_REMOVED );
181 
182  for( const auto& r : m_sListeners )
183  {
184  uno::Reference< beans::XPropertySetInfoChangeListener > ref( r, uno::UNO_QUERY );
185  if( ref.is() )
186  ref->propertySetInfoChange( aEvt );
187  }
188 }
189 
190 
191 /*********************************************************************************/
192 /* */
193 /* PropertySetInfoChangeNotifier */
194 /* */
195 /*********************************************************************************/
196 
197 
199  const css::uno::Reference< XContent >& xCreatorContent,
200  std::unique_ptr<ListenerMap> pListeners )
201  : m_xCreatorContent( xCreatorContent ),
202  m_pListeners( std::move(pListeners) )
203 {
204 }
205 
206 
208 {
209 }
210 
211 
213  const uno::Sequence< beans::PropertyChangeEvent >& Changes_ )
214 {
215  sal_Int32 j;
216  uno::Sequence< beans::PropertyChangeEvent > Changes = Changes_;
217 
218  for( j = 0; j < Changes.getLength(); ++j )
219  Changes[j].Source = m_xCreatorContent;
220 
221  // notify listeners for all Events
222 
223  uno::Sequence< uno::Reference< uno::XInterface > > seqList = (*m_pListeners)[ OUString() ];
224  for( j = 0; j < seqList.getLength(); ++j )
225  {
226  uno::Reference< beans::XPropertiesChangeListener > aListener( seqList[j],uno::UNO_QUERY );
227  if( aListener.is() )
228  {
229  aListener->propertiesChange( Changes );
230  }
231  }
232 
233  uno::Sequence< beans::PropertyChangeEvent > seq(1);
234  for( j = 0; j < Changes.getLength(); ++j )
235  {
236  seq[0] = Changes[j];
237  seqList = (*m_pListeners)[ seq[0].PropertyName ];
238 
239  for( sal_Int32 i = 0; i < seqList.getLength(); ++i )
240  {
241  uno::Reference< beans::XPropertiesChangeListener > aListener( seqList[j],uno::UNO_QUERY );
242  if( aListener.is() )
243  {
244  aListener->propertiesChange( seq );
245  }
246  }
247  }
248 }
249 
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void notifyPropertyChanged(const css::uno::Sequence< css::beans::PropertyChangeEvent > &seqChanged)
Definition: filnot.cxx:212
void notifyPropertyRemoved(const OUString &aPropertyName)
Definition: filnot.cxx:175
ContentEventNotifier(TaskManager *pMyShell, const css::uno::Reference< css::ucb::XContent > &xCreatorContent, const css::uno::Reference< css::ucb::XContentIdentifier > &xCreatorId, const std::vector< css::uno::Reference< css::uno::XInterface > > &sListeners)
void notifyPropertyAdded(const OUString &aPropertyName)
Definition: filnot.cxx:158
PropertyChangeNotifier(const css::uno::Reference< css::ucb::XContent > &xCreatorContent, std::unique_ptr< ListenerMap > pListeners)
FileProvider * m_pProvider
Definition: filtask.hxx:498
css::uno::Reference< css::ucb::XContent > m_xCreatorContent
Definition: filnot.hxx:86
int i
css::uno::Reference< css::ucb::XContentIdentifier > m_xCreatorId
Definition: filnot.hxx:40
sal_uInt16 m_nState
Definition: bc.hxx:230
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent(const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier) override
Definition: prov.cxx:166
css::uno::Reference< css::ucb::XContentIdentifier > m_xOldId
Definition: filnot.hxx:41
void notifyChildInserted(const OUString &aChildName)
Definition: filnot.cxx:60
PropertySetInfoChangeNotifier(const css::uno::Reference< css::ucb::XContent > &xCreatorContent, const std::vector< css::uno::Reference< css::uno::XInterface > > &sListeners)
Definition: filnot.cxx:147
css::uno::Reference< css::ucb::XContent > m_xCreatorContent
Definition: filnot.hxx:68
osl::Mutex m_aMutex
Definition: bc.hxx:232
std::vector< css::uno::Reference< css::uno::XInterface > > m_sListeners
Definition: filnot.hxx:42
std::vector< css::uno::Reference< css::uno::XInterface > > m_sListeners
Definition: filnot.hxx:69
void notifyRemoved(const OUString &aChildName)
Definition: filnot.cxx:98
css::uno::Reference< css::ucb::XContent > m_xCreatorContent
Definition: filnot.hxx:39