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/XContent.hpp>
21 #include <com/sun/star/ucb/ContentAction.hpp>
22 #include <com/sun/star/beans/PropertySetInfoChange.hpp>
30 using namespace fileaccess
;
31 using namespace com::sun::star
;
32 using namespace com::sun::star::ucb
;
35 ContentEventNotifier::ContentEventNotifier( shell
* pMyShell
,
36 const uno::Reference
< XContent
>& xCreatorContent
,
37 const uno::Reference
< XContentIdentifier
>& xCreatorId
,
38 const uno::Sequence
< uno::Reference
< uno::XInterface
> >& sListeners
)
39 : m_pMyShell( pMyShell
),
40 m_xCreatorContent( xCreatorContent
),
41 m_xCreatorId( xCreatorId
),
42 m_sListeners( sListeners
)
47 ContentEventNotifier::ContentEventNotifier( shell
* pMyShell
,
48 const uno::Reference
< XContent
>& xCreatorContent
,
49 const uno::Reference
< XContentIdentifier
>& xCreatorId
,
50 const uno::Reference
< XContentIdentifier
>& xOldId
,
51 const uno::Sequence
< uno::Reference
< uno::XInterface
> >& sListeners
)
52 : m_pMyShell( pMyShell
),
53 m_xCreatorContent( xCreatorContent
),
54 m_xCreatorId( xCreatorId
),
56 m_sListeners( sListeners
)
62 void ContentEventNotifier::notifyChildInserted( const rtl::OUString
& aChildName
)
64 FileContentIdentifier
* p
= new FileContentIdentifier( m_pMyShell
,aChildName
);
65 uno::Reference
< XContentIdentifier
> xChildId( p
);
67 uno::Reference
< XContent
> xChildContent
= m_pMyShell
->m_pProvider
->queryContent( xChildId
);
69 ContentEvent
aEvt( m_xCreatorContent
,
70 ContentAction::INSERTED
,
74 for( sal_Int32 i
= 0; i
< m_sListeners
.getLength(); ++i
)
76 uno::Reference
< XContentEventListener
> ref( m_sListeners
[i
],uno::UNO_QUERY
);
78 ref
->contentEvent( aEvt
);
82 void ContentEventNotifier::notifyDeleted( void )
85 ContentEvent
aEvt( m_xCreatorContent
,
86 ContentAction::DELETED
,
91 for( sal_Int32 i
= 0; i
< m_sListeners
.getLength(); ++i
)
93 uno::Reference
< XContentEventListener
> ref( m_sListeners
[i
],uno::UNO_QUERY
);
95 ref
->contentEvent( aEvt
);
101 void ContentEventNotifier::notifyRemoved( const rtl::OUString
& aChildName
)
103 FileContentIdentifier
* p
= new FileContentIdentifier( m_pMyShell
,aChildName
);
104 uno::Reference
< XContentIdentifier
> xChildId( p
);
106 BaseContent
* pp
= new BaseContent( m_pMyShell
,xChildId
,aChildName
);
108 osl::MutexGuard
aGuard( pp
->m_aMutex
);
109 pp
->m_nState
|= BaseContent::Deleted
;
112 uno::Reference
< XContent
> xDeletedContent( pp
);
115 ContentEvent
aEvt( m_xCreatorContent
,
116 ContentAction::REMOVED
,
120 for( sal_Int32 i
= 0; i
< m_sListeners
.getLength(); ++i
)
122 uno::Reference
< XContentEventListener
> ref( m_sListeners
[i
],uno::UNO_QUERY
);
124 ref
->contentEvent( aEvt
);
128 void ContentEventNotifier::notifyExchanged()
130 ContentEvent
aEvt( m_xCreatorContent
,
131 ContentAction::EXCHANGED
,
135 for( sal_Int32 i
= 0; i
< m_sListeners
.getLength(); ++i
)
137 uno::Reference
< XContentEventListener
> ref( m_sListeners
[i
],uno::UNO_QUERY
);
139 ref
->contentEvent( aEvt
);
143 /*********************************************************************************/
145 /* PropertySetInfoChangeNotifier */
147 /*********************************************************************************/
150 PropertySetInfoChangeNotifier::PropertySetInfoChangeNotifier(
151 const uno::Reference
< XContent
>& xCreatorContent
,
152 const uno::Reference
< XContentIdentifier
>& xCreatorId
,
153 const uno::Sequence
< uno::Reference
< uno::XInterface
> >& sListeners
)
154 : m_xCreatorContent( xCreatorContent
),
155 m_xCreatorId( xCreatorId
),
156 m_sListeners( sListeners
)
163 PropertySetInfoChangeNotifier::notifyPropertyAdded( const rtl::OUString
& aPropertyName
)
165 beans::PropertySetInfoChangeEvent
aEvt( m_xCreatorContent
,
168 beans::PropertySetInfoChange::PROPERTY_INSERTED
);
170 for( sal_Int32 i
= 0; i
< m_sListeners
.getLength(); ++i
)
172 uno::Reference
< beans::XPropertySetInfoChangeListener
> ref( m_sListeners
[i
],uno::UNO_QUERY
);
174 ref
->propertySetInfoChange( aEvt
);
180 PropertySetInfoChangeNotifier::notifyPropertyRemoved( const rtl::OUString
& aPropertyName
)
182 beans::PropertySetInfoChangeEvent
aEvt( m_xCreatorContent
,
185 beans::PropertySetInfoChange::PROPERTY_REMOVED
);
187 for( sal_Int32 i
= 0; i
< m_sListeners
.getLength(); ++i
)
189 uno::Reference
< beans::XPropertySetInfoChangeListener
> ref( m_sListeners
[i
],uno::UNO_QUERY
);
191 ref
->propertySetInfoChange( aEvt
);
196 /*********************************************************************************/
198 /* PropertySetInfoChangeNotifier */
200 /*********************************************************************************/
203 PropertyChangeNotifier::PropertyChangeNotifier(
204 const com::sun::star::uno::Reference
< XContent
>& xCreatorContent
,
205 const com::sun::star::uno::Reference
< com::sun::star::ucb::XContentIdentifier
>& xCreatorId
,
206 ListenerMap
* pListeners
)
207 : m_xCreatorContent( xCreatorContent
),
208 m_xCreatorId( xCreatorId
),
209 m_pListeners( pListeners
)
214 PropertyChangeNotifier::~PropertyChangeNotifier()
220 void PropertyChangeNotifier::notifyPropertyChanged(
221 uno::Sequence
< beans::PropertyChangeEvent
> Changes
)
225 for( j
= 0; j
< Changes
.getLength(); ++j
)
226 Changes
[j
].Source
= m_xCreatorContent
;
228 // notify listeners for all Events
230 uno::Sequence
< uno::Reference
< uno::XInterface
> > seqList
= (*m_pListeners
)[ rtl::OUString() ];
231 for( j
= 0; j
< seqList
.getLength(); ++j
)
233 uno::Reference
< beans::XPropertiesChangeListener
> aListener( seqList
[j
],uno::UNO_QUERY
);
236 aListener
->propertiesChange( Changes
);
240 uno::Sequence
< beans::PropertyChangeEvent
> seq(1);
241 for( j
= 0; j
< Changes
.getLength(); ++j
)
244 seqList
= (*m_pListeners
)[ seq
[0].PropertyName
];
246 for( sal_Int32 i
= 0; i
< seqList
.getLength(); ++i
)
248 uno::Reference
< beans::XPropertiesChangeListener
> aListener( seqList
[j
],uno::UNO_QUERY
);
251 aListener
->propertiesChange( seq
);
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */