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