/src/libreoffice/ucb/source/ucp/file/filnot.cxx
Line | Count | Source |
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 | | |
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 | 0 | : m_pMyShell( pMyShell ), |
39 | 0 | m_xCreatorContent( xCreatorContent ), |
40 | 0 | m_xCreatorId( xCreatorId ), |
41 | 0 | m_sListeners( std::move(sListeners) ) |
42 | 0 | { |
43 | 0 | } |
44 | | |
45 | | |
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 | 0 | : m_pMyShell( pMyShell ), |
52 | 0 | m_xCreatorContent( xCreatorContent ), |
53 | 0 | m_xCreatorId( xCreatorId ), |
54 | 0 | m_xOldId( xOldId ), |
55 | 0 | m_sListeners( std::move(sListeners) ) |
56 | 0 | { |
57 | 0 | } |
58 | | |
59 | | |
60 | | void ContentEventNotifier::notifyChildInserted( const OUString& aChildName ) const |
61 | 0 | { |
62 | 0 | rtl::Reference<FileContentIdentifier> xChildId = new FileContentIdentifier( aChildName ); |
63 | |
|
64 | 0 | uno::Reference< XContent > xChildContent = m_pMyShell->m_pProvider->queryContent( xChildId ); |
65 | |
|
66 | 0 | ContentEvent aEvt( m_xCreatorContent, |
67 | 0 | ContentAction::INSERTED, |
68 | 0 | xChildContent, |
69 | 0 | m_xCreatorId ); |
70 | |
|
71 | 0 | for( const auto& ref : m_sListeners ) |
72 | 0 | ref->contentEvent( aEvt ); |
73 | 0 | } |
74 | | |
75 | | void ContentEventNotifier::notifyDeleted() const |
76 | 0 | { |
77 | 0 | ContentEvent aEvt( m_xCreatorContent, |
78 | 0 | ContentAction::DELETED, |
79 | 0 | m_xCreatorContent, |
80 | 0 | m_xCreatorId ); |
81 | | |
82 | |
|
83 | 0 | for( const auto& ref : m_sListeners ) |
84 | 0 | ref->contentEvent( aEvt ); |
85 | 0 | } |
86 | | |
87 | | |
88 | | void ContentEventNotifier::notifyRemoved( const OUString& aChildName ) const |
89 | 0 | { |
90 | 0 | rtl::Reference<FileContentIdentifier> xChildId = new FileContentIdentifier( aChildName ); |
91 | |
|
92 | 0 | rtl::Reference<BaseContent> pp = new BaseContent(m_pMyShell, xChildId, aChildName, |
93 | 0 | BaseContent::FullFeatured | BaseContent::Deleted); |
94 | |
|
95 | 0 | ContentEvent aEvt( m_xCreatorContent, |
96 | 0 | ContentAction::REMOVED, |
97 | 0 | pp, |
98 | 0 | m_xCreatorId ); |
99 | |
|
100 | 0 | for( const auto& ref : m_sListeners ) |
101 | 0 | ref->contentEvent( aEvt ); |
102 | 0 | } |
103 | | |
104 | | void ContentEventNotifier::notifyExchanged() const |
105 | 0 | { |
106 | 0 | ContentEvent aEvt( m_xCreatorContent, |
107 | 0 | ContentAction::EXCHANGED, |
108 | 0 | m_xCreatorContent, |
109 | 0 | m_xOldId ); |
110 | |
|
111 | 0 | for( const auto& ref : m_sListeners ) |
112 | 0 | ref->contentEvent( aEvt ); |
113 | 0 | } |
114 | | |
115 | | /*********************************************************************************/ |
116 | | /* */ |
117 | | /* PropertySetInfoChangeNotifier */ |
118 | | /* */ |
119 | | /*********************************************************************************/ |
120 | | |
121 | | |
122 | | PropertySetInfoChangeNotifier::PropertySetInfoChangeNotifier( |
123 | | const uno::Reference< XContent >& xCreatorContent, |
124 | | std::vector< uno::Reference< beans::XPropertySetInfoChangeListener > >&& sListeners ) |
125 | 0 | : m_xCreatorContent( xCreatorContent ), |
126 | 0 | m_sListeners( std::move(sListeners) ) |
127 | 0 | { |
128 | |
|
129 | 0 | } |
130 | | |
131 | | |
132 | | void |
133 | | PropertySetInfoChangeNotifier::notifyPropertyAdded( const OUString & aPropertyName ) const |
134 | 0 | { |
135 | 0 | beans::PropertySetInfoChangeEvent aEvt( m_xCreatorContent, |
136 | 0 | aPropertyName, |
137 | 0 | -1, |
138 | 0 | beans::PropertySetInfoChange::PROPERTY_INSERTED ); |
139 | |
|
140 | 0 | for( const auto& ref : m_sListeners ) |
141 | 0 | ref->propertySetInfoChange( aEvt ); |
142 | 0 | } |
143 | | |
144 | | |
145 | | void |
146 | | PropertySetInfoChangeNotifier::notifyPropertyRemoved( const OUString & aPropertyName ) const |
147 | 0 | { |
148 | 0 | beans::PropertySetInfoChangeEvent aEvt( m_xCreatorContent, |
149 | 0 | aPropertyName, |
150 | 0 | -1, |
151 | 0 | beans::PropertySetInfoChange::PROPERTY_REMOVED ); |
152 | |
|
153 | 0 | for( const auto& ref : m_sListeners ) |
154 | 0 | ref->propertySetInfoChange( aEvt ); |
155 | 0 | } |
156 | | |
157 | | |
158 | | /*********************************************************************************/ |
159 | | /* */ |
160 | | /* PropertySetInfoChangeNotifier */ |
161 | | /* */ |
162 | | /*********************************************************************************/ |
163 | | |
164 | | |
165 | | PropertyChangeNotifier::PropertyChangeNotifier( |
166 | | const css::uno::Reference< XContent >& xCreatorContent, |
167 | | ListenerMap&& pListeners ) |
168 | 0 | : m_xCreatorContent( xCreatorContent ), |
169 | 0 | m_aListeners( std::move(pListeners) ) |
170 | 0 | { |
171 | 0 | } |
172 | | |
173 | | |
174 | | void PropertyChangeNotifier::notifyPropertyChanged( |
175 | | const uno::Sequence< beans::PropertyChangeEvent >& seqChanged ) const |
176 | 0 | { |
177 | 0 | uno::Sequence< beans::PropertyChangeEvent > Changes = seqChanged; |
178 | |
|
179 | 0 | for( auto& rChange : asNonConstRange(Changes) ) |
180 | 0 | rChange.Source = m_xCreatorContent; |
181 | | |
182 | | // notify listeners for all Events |
183 | |
|
184 | 0 | auto it = m_aListeners.find( OUString() ); |
185 | 0 | if (it != m_aListeners.end()) |
186 | 0 | { |
187 | 0 | const std::vector< uno::Reference< beans::XPropertiesChangeListener > >& seqList = it->second; |
188 | 0 | for( const auto& rListener : seqList ) |
189 | 0 | rListener->propertiesChange( Changes ); |
190 | 0 | } |
191 | |
|
192 | 0 | for (const auto& rChange : Changes) |
193 | 0 | { |
194 | 0 | uno::Sequence< beans::PropertyChangeEvent > seq{ rChange }; |
195 | 0 | it = m_aListeners.find( rChange.PropertyName ); |
196 | 0 | if (it != m_aListeners.end()) |
197 | 0 | { |
198 | 0 | const std::vector< uno::Reference< beans::XPropertiesChangeListener > >& seqList = it->second; |
199 | 0 | for( const auto& rListener : seqList ) |
200 | 0 | rListener->propertiesChange( seq ); |
201 | 0 | } |
202 | 0 | } |
203 | 0 | } |
204 | | |
205 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |