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