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
29using namespace fileaccess;
30using namespace com::sun::star;
31using namespace com::sun::star::ucb;
32
33
34ContentEventNotifier::ContentEventNotifier( TaskManager* pMyShell,
35 const uno::Reference< XContent >& xCreatorContent,
36 const uno::Reference< XContentIdentifier >& xCreatorId,
37 std::vector< uno::Reference< ucb::XContentEventListener > >&& sListeners )
38 : m_pMyShell( pMyShell ),
39 m_xCreatorContent( xCreatorContent ),
40 m_xCreatorId( xCreatorId ),
41 m_sListeners( std::move(sListeners) )
42{
43}
44
45
46ContentEventNotifier::ContentEventNotifier( TaskManager* pMyShell,
47 const uno::Reference< XContent >& xCreatorContent,
48 const uno::Reference< XContentIdentifier >& xCreatorId,
49 const uno::Reference< XContentIdentifier >& xOldId,
50 std::vector< uno::Reference< ucb::XContentEventListener > >&& sListeners )
51 : m_pMyShell( pMyShell ),
52 m_xCreatorContent( xCreatorContent ),
53 m_xCreatorId( xCreatorId ),
54 m_xOldId( xOldId ),
55 m_sListeners( std::move(sListeners) )
56{
57}
58
59
60void ContentEventNotifier::notifyChildInserted( const OUString& aChildName ) const
61{
63
64 uno::Reference< XContent > xChildContent = m_pMyShell->m_pProvider->queryContent( xChildId );
65
66 ContentEvent aEvt( m_xCreatorContent,
67 ContentAction::INSERTED,
68 xChildContent,
70
71 for( const auto& ref : m_sListeners )
72 ref->contentEvent( aEvt );
73}
74
76{
77 ContentEvent aEvt( m_xCreatorContent,
78 ContentAction::DELETED,
81
82
83 for( const auto& ref : m_sListeners )
84 ref->contentEvent( aEvt );
85}
86
87
88void ContentEventNotifier::notifyRemoved( const OUString& aChildName ) const
89{
91
92 rtl::Reference<BaseContent> pp = new BaseContent( m_pMyShell,xChildId,aChildName );
93 {
94 std::unique_lock aGuard( pp->m_aMutex );
95 pp->m_nState |= BaseContent::Deleted;
96 }
97
98 ContentEvent aEvt( m_xCreatorContent,
99 ContentAction::REMOVED,
100 pp,
101 m_xCreatorId );
102
103 for( const auto& ref : m_sListeners )
104 ref->contentEvent( aEvt );
105}
106
108{
109 ContentEvent aEvt( m_xCreatorContent,
110 ContentAction::EXCHANGED,
112 m_xOldId );
113
114 for( const auto& ref : m_sListeners )
115 ref->contentEvent( aEvt );
116}
117
118/*********************************************************************************/
119/* */
120/* PropertySetInfoChangeNotifier */
121/* */
122/*********************************************************************************/
123
124
126 const uno::Reference< XContent >& xCreatorContent,
127 std::vector< uno::Reference< beans::XPropertySetInfoChangeListener > >&& sListeners )
128 : m_xCreatorContent( xCreatorContent ),
129 m_sListeners( std::move(sListeners) )
130{
131
132}
133
134
135void
136PropertySetInfoChangeNotifier::notifyPropertyAdded( const OUString & aPropertyName ) const
137{
138 beans::PropertySetInfoChangeEvent aEvt( m_xCreatorContent,
139 aPropertyName,
140 -1,
141 beans::PropertySetInfoChange::PROPERTY_INSERTED );
142
143 for( const auto& ref : m_sListeners )
144 ref->propertySetInfoChange( aEvt );
145}
146
147
148void
149PropertySetInfoChangeNotifier::notifyPropertyRemoved( const OUString & aPropertyName ) const
150{
151 beans::PropertySetInfoChangeEvent aEvt( m_xCreatorContent,
152 aPropertyName,
153 -1,
154 beans::PropertySetInfoChange::PROPERTY_REMOVED );
155
156 for( const auto& ref : m_sListeners )
157 ref->propertySetInfoChange( aEvt );
158}
159
160
161/*********************************************************************************/
162/* */
163/* PropertySetInfoChangeNotifier */
164/* */
165/*********************************************************************************/
166
167
169 const css::uno::Reference< XContent >& xCreatorContent,
170 ListenerMap&& pListeners )
171 : m_xCreatorContent( xCreatorContent ),
172 m_aListeners( std::move(pListeners) )
173{
174}
175
176
178 const uno::Sequence< beans::PropertyChangeEvent >& seqChanged ) const
179{
180 uno::Sequence< beans::PropertyChangeEvent > Changes = seqChanged;
181
182 for( auto& rChange : asNonConstRange(Changes) )
183 rChange.Source = m_xCreatorContent;
184
185 // notify listeners for all Events
186
187 auto it = m_aListeners.find( OUString() );
188 if (it != m_aListeners.end())
189 {
190 const std::vector< uno::Reference< beans::XPropertiesChangeListener > >& seqList = it->second;
191 for( const auto& rListener : seqList )
192 rListener->propertiesChange( Changes );
193 }
194
195 for( const auto& rChange : std::as_const(Changes) )
196 {
197 uno::Sequence< beans::PropertyChangeEvent > seq{ rChange };
198 it = m_aListeners.find( rChange.PropertyName );
199 if (it != m_aListeners.end())
200 {
201 const std::vector< uno::Reference< beans::XPropertiesChangeListener > >& seqList = it->second;
202 for( const auto& rListener : seqList )
203 rListener->propertiesChange( seq );
204 }
205 }
206}
207
208/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::ucb::XContentIdentifier > m_xCreatorId
Definition: filnot.hxx:40
void notifyRemoved(const OUString &aChildName) const
Definition: filnot.cxx:88
std::vector< css::uno::Reference< css::ucb::XContentEventListener > > m_sListeners
Definition: filnot.hxx:42
css::uno::Reference< css::ucb::XContent > m_xCreatorContent
Definition: filnot.hxx:39
css::uno::Reference< css::ucb::XContentIdentifier > m_xOldId
Definition: filnot.hxx:41
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent(const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier) override
Definition: prov.cxx:112
css::uno::Reference< css::ucb::XContent > m_xCreatorContent
Definition: filnot.hxx:86
void notifyPropertyChanged(const css::uno::Sequence< css::beans::PropertyChangeEvent > &seqChanged) const
Definition: filnot.cxx:177
PropertyChangeNotifier(const css::uno::Reference< css::ucb::XContent > &xCreatorContent, ListenerMap &&pListeners)
std::vector< css::uno::Reference< css::beans::XPropertySetInfoChangeListener > > m_sListeners
Definition: filnot.hxx:69
PropertySetInfoChangeNotifier(const css::uno::Reference< css::ucb::XContent > &xCreatorContent, std::vector< css::uno::Reference< css::beans::XPropertySetInfoChangeListener > > &&sListeners)
Definition: filnot.cxx:125
void notifyPropertyAdded(const OUString &aPropertyName) const
Definition: filnot.cxx:136
css::uno::Reference< css::ucb::XContent > m_xCreatorContent
Definition: filnot.hxx:68
void notifyPropertyRemoved(const OUString &aPropertyName) const
Definition: filnot.cxx:149
FileProvider * m_pProvider
Definition: filtask.hxx:476
std::vector< Reference< css::datatransfer::clipboard::XClipboardListener > > m_aListeners
std::unordered_map< OUString, std::vector< css::uno::Reference< css::beans::XPropertiesChangeListener > > > ListenerMap
Definition: filnot.hxx:81