1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/ucb/ContentAction.hpp>
21 #include <com/sun/star/beans/PropertySetInfoChange.hpp>
22 #include <rtl/ref.hxx>
29 using namespace fileaccess
;
30 using namespace com::sun::star
;
31 using namespace com::sun::star::ucb
;
34 ContentEventNotifier::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
) )
46 ContentEventNotifier::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
),
55 m_sListeners( std::move(sListeners
) )
60 void ContentEventNotifier::notifyChildInserted( const OUString
& aChildName
) const
62 rtl::Reference
<FileContentIdentifier
> xChildId
= new FileContentIdentifier( aChildName
);
64 uno::Reference
< XContent
> xChildContent
= m_pMyShell
->m_pProvider
->queryContent( xChildId
);
66 ContentEvent
aEvt( m_xCreatorContent
,
67 ContentAction::INSERTED
,
71 for( const auto& ref
: m_sListeners
)
72 ref
->contentEvent( aEvt
);
75 void ContentEventNotifier::notifyDeleted() const
77 ContentEvent
aEvt( m_xCreatorContent
,
78 ContentAction::DELETED
,
83 for( const auto& ref
: m_sListeners
)
84 ref
->contentEvent( aEvt
);
88 void ContentEventNotifier::notifyRemoved( const OUString
& aChildName
) const
90 rtl::Reference
<FileContentIdentifier
> xChildId
= new FileContentIdentifier( aChildName
);
92 rtl::Reference
<BaseContent
> pp
= new BaseContent( m_pMyShell
,xChildId
,aChildName
);
94 std::unique_lock
aGuard( pp
->m_aMutex
);
95 pp
->m_nState
|= BaseContent::Deleted
;
98 ContentEvent
aEvt( m_xCreatorContent
,
99 ContentAction::REMOVED
,
103 for( const auto& ref
: m_sListeners
)
104 ref
->contentEvent( aEvt
);
107 void ContentEventNotifier::notifyExchanged() const
109 ContentEvent
aEvt( m_xCreatorContent
,
110 ContentAction::EXCHANGED
,
114 for( const auto& ref
: m_sListeners
)
115 ref
->contentEvent( aEvt
);
118 /*********************************************************************************/
120 /* PropertySetInfoChangeNotifier */
122 /*********************************************************************************/
125 PropertySetInfoChangeNotifier::PropertySetInfoChangeNotifier(
126 const uno::Reference
< XContent
>& xCreatorContent
,
127 std::vector
< uno::Reference
< beans::XPropertySetInfoChangeListener
> >&& sListeners
)
128 : m_xCreatorContent( xCreatorContent
),
129 m_sListeners( std::move(sListeners
) )
136 PropertySetInfoChangeNotifier::notifyPropertyAdded( const OUString
& aPropertyName
) const
138 beans::PropertySetInfoChangeEvent
aEvt( m_xCreatorContent
,
141 beans::PropertySetInfoChange::PROPERTY_INSERTED
);
143 for( const auto& ref
: m_sListeners
)
144 ref
->propertySetInfoChange( aEvt
);
149 PropertySetInfoChangeNotifier::notifyPropertyRemoved( const OUString
& aPropertyName
) const
151 beans::PropertySetInfoChangeEvent
aEvt( m_xCreatorContent
,
154 beans::PropertySetInfoChange::PROPERTY_REMOVED
);
156 for( const auto& ref
: m_sListeners
)
157 ref
->propertySetInfoChange( aEvt
);
161 /*********************************************************************************/
163 /* PropertySetInfoChangeNotifier */
165 /*********************************************************************************/
168 PropertyChangeNotifier::PropertyChangeNotifier(
169 const css::uno::Reference
< XContent
>& xCreatorContent
,
170 ListenerMap
&& pListeners
)
171 : m_xCreatorContent( xCreatorContent
),
172 m_aListeners( std::move(pListeners
) )
177 void PropertyChangeNotifier::notifyPropertyChanged(
178 const uno::Sequence
< beans::PropertyChangeEvent
>& seqChanged
) const
180 uno::Sequence
< beans::PropertyChangeEvent
> Changes
= seqChanged
;
182 for( auto& rChange
: asNonConstRange(Changes
) )
183 rChange
.Source
= m_xCreatorContent
;
185 // notify listeners for all Events
187 auto it
= m_aListeners
.find( OUString() );
188 if (it
!= m_aListeners
.end())
190 const std::vector
< uno::Reference
< beans::XPropertiesChangeListener
> >& seqList
= it
->second
;
191 for( const auto& rListener
: seqList
)
192 rListener
->propertiesChange( Changes
);
195 for( const auto& rChange
: std::as_const(Changes
) )
197 uno::Sequence
< beans::PropertyChangeEvent
> seq
{ rChange
};
198 it
= m_aListeners
.find( rChange
.PropertyName
);
199 if (it
!= m_aListeners
.end())
201 const std::vector
< uno::Reference
< beans::XPropertiesChangeListener
> >& seqList
= it
->second
;
202 for( const auto& rListener
: seqList
)
203 rListener
->propertiesChange( seq
);
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */