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 <rtl/ref.hxx>
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 {
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 {
100 
101  rtl::Reference<BaseContent> pp = new BaseContent( m_pMyShell,xChildId,aChildName );
102  {
103  osl::MutexGuard aGuard( pp->m_aMutex );
104  pp->m_nState |= BaseContent::Deleted;
105  }
106 
107  ContentEvent aEvt( m_xCreatorContent,
108  ContentAction::REMOVED,
109  pp,
110  m_xCreatorId );
111 
112  for( const auto& r : m_sListeners )
113  {
114  uno::Reference< XContentEventListener > ref( r, uno::UNO_QUERY );
115  if( ref.is() )
116  ref->contentEvent( aEvt );
117  }
118 }
119 
121 {
122  ContentEvent aEvt( m_xCreatorContent,
123  ContentAction::EXCHANGED,
125  m_xOldId );
126 
127  for( const auto& r : m_sListeners )
128  {
129  uno::Reference< XContentEventListener > ref( r, uno::UNO_QUERY );
130  if( ref.is() )
131  ref->contentEvent( aEvt );
132  }
133 }
134 
135 /*********************************************************************************/
136 /* */
137 /* PropertySetInfoChangeNotifier */
138 /* */
139 /*********************************************************************************/
140 
141 
143  const uno::Reference< XContent >& xCreatorContent,
144  const std::vector< uno::Reference< uno::XInterface > >& sListeners )
145  : m_xCreatorContent( xCreatorContent ),
146  m_sListeners( sListeners )
147 {
148 
149 }
150 
151 
152 void
153 PropertySetInfoChangeNotifier::notifyPropertyAdded( const OUString & aPropertyName )
154 {
155  beans::PropertySetInfoChangeEvent aEvt( m_xCreatorContent,
156  aPropertyName,
157  -1,
158  beans::PropertySetInfoChange::PROPERTY_INSERTED );
159 
160  for( const auto& r : m_sListeners )
161  {
162  uno::Reference< beans::XPropertySetInfoChangeListener > ref( r, uno::UNO_QUERY );
163  if( ref.is() )
164  ref->propertySetInfoChange( aEvt );
165  }
166 }
167 
168 
169 void
171 {
172  beans::PropertySetInfoChangeEvent aEvt( m_xCreatorContent,
173  aPropertyName,
174  -1,
175  beans::PropertySetInfoChange::PROPERTY_REMOVED );
176 
177  for( const auto& r : m_sListeners )
178  {
179  uno::Reference< beans::XPropertySetInfoChangeListener > ref( r, uno::UNO_QUERY );
180  if( ref.is() )
181  ref->propertySetInfoChange( aEvt );
182  }
183 }
184 
185 
186 /*********************************************************************************/
187 /* */
188 /* PropertySetInfoChangeNotifier */
189 /* */
190 /*********************************************************************************/
191 
192 
194  const css::uno::Reference< XContent >& xCreatorContent,
195  std::unique_ptr<ListenerMap> pListeners )
196  : m_xCreatorContent( xCreatorContent ),
197  m_pListeners( std::move(pListeners) )
198 {
199 }
200 
201 
203 {
204 }
205 
206 
208  const uno::Sequence< beans::PropertyChangeEvent >& seqChanged )
209 {
210  uno::Sequence< beans::PropertyChangeEvent > Changes = seqChanged;
211 
212  for( auto& rChange : Changes )
213  rChange.Source = m_xCreatorContent;
214 
215  // notify listeners for all Events
216 
217  uno::Sequence< uno::Reference< uno::XInterface > > seqList = (*m_pListeners)[ OUString() ];
218  for( const auto& rListener : std::as_const(seqList) )
219  {
220  uno::Reference< beans::XPropertiesChangeListener > aListener( rListener,uno::UNO_QUERY );
221  if( aListener.is() )
222  {
223  aListener->propertiesChange( Changes );
224  }
225  }
226 
227  uno::Sequence< beans::PropertyChangeEvent > seq(1);
228  for( const auto& rChange : std::as_const(Changes) )
229  {
230  seq[0] = rChange;
231  seqList = (*m_pListeners)[ rChange.PropertyName ];
232 
233  for( const auto& rListener : std::as_const(seqList) )
234  {
235  uno::Reference< beans::XPropertiesChangeListener > aListener( rListener,uno::UNO_QUERY );
236  if( aListener.is() )
237  {
238  aListener->propertiesChange( seq );
239  }
240  }
241  }
242 }
243 
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void notifyPropertyChanged(const css::uno::Sequence< css::beans::PropertyChangeEvent > &seqChanged)
Definition: filnot.cxx:207
void notifyPropertyRemoved(const OUString &aPropertyName)
Definition: filnot.cxx:170
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:153
PropertyChangeNotifier(const css::uno::Reference< css::ucb::XContent > &xCreatorContent, std::unique_ptr< ListenerMap > pListeners)
FileProvider * m_pProvider
Definition: filtask.hxx:483
css::uno::Reference< css::ucb::XContent > m_xCreatorContent
Definition: filnot.hxx:85
css::uno::Reference< css::ucb::XContentIdentifier > m_xCreatorId
Definition: filnot.hxx:39
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent(const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier) override
Definition: prov.cxx:113
css::uno::Reference< css::ucb::XContentIdentifier > m_xOldId
Definition: filnot.hxx:40
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:142
css::uno::Reference< css::ucb::XContent > m_xCreatorContent
Definition: filnot.hxx:67
std::vector< css::uno::Reference< css::uno::XInterface > > m_sListeners
Definition: filnot.hxx:41
std::vector< css::uno::Reference< css::uno::XInterface > > m_sListeners
Definition: filnot.hxx:68
void notifyRemoved(const OUString &aChildName)
Definition: filnot.cxx:97
css::uno::Reference< css::ucb::XContent > m_xCreatorContent
Definition: filnot.hxx:38