1*2f86921cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2f86921cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2f86921cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2f86921cSAndrew Rist * distributed with this work for additional information 6*2f86921cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2f86921cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2f86921cSAndrew Rist * "License"); you may not use this file except in compliance 9*2f86921cSAndrew Rist * with the License. You may obtain a copy of the License at 10*2f86921cSAndrew Rist * 11*2f86921cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*2f86921cSAndrew Rist * 13*2f86921cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2f86921cSAndrew Rist * software distributed under the License is distributed on an 15*2f86921cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2f86921cSAndrew Rist * KIND, either express or implied. See the License for the 17*2f86921cSAndrew Rist * specific language governing permissions and limitations 18*2f86921cSAndrew Rist * under the License. 19*2f86921cSAndrew Rist * 20*2f86921cSAndrew Rist *************************************************************/ 21*2f86921cSAndrew Rist 22*2f86921cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_ucb.hxx" 26cdf0e10cSrcweir #include <com/sun/star/ucb/XContent.hpp> 27cdf0e10cSrcweir #include <com/sun/star/ucb/ContentAction.hpp> 28cdf0e10cSrcweir #include <com/sun/star/beans/PropertySetInfoChange.hpp> 29cdf0e10cSrcweir #include "filnot.hxx" 30cdf0e10cSrcweir #include "filid.hxx" 31cdf0e10cSrcweir #include "bc.hxx" 32cdf0e10cSrcweir #include "prov.hxx" 33cdf0e10cSrcweir 34cdf0e10cSrcweir 35cdf0e10cSrcweir 36cdf0e10cSrcweir using namespace fileaccess; 37cdf0e10cSrcweir using namespace com::sun::star; 38cdf0e10cSrcweir using namespace com::sun::star::ucb; 39cdf0e10cSrcweir 40cdf0e10cSrcweir 41cdf0e10cSrcweir ContentEventNotifier::ContentEventNotifier( shell* pMyShell, 42cdf0e10cSrcweir const uno::Reference< XContent >& xCreatorContent, 43cdf0e10cSrcweir const uno::Reference< XContentIdentifier >& xCreatorId, 44cdf0e10cSrcweir const uno::Sequence< uno::Reference< uno::XInterface > >& sListeners ) 45cdf0e10cSrcweir : m_pMyShell( pMyShell ), 46cdf0e10cSrcweir m_xCreatorContent( xCreatorContent ), 47cdf0e10cSrcweir m_xCreatorId( xCreatorId ), 48cdf0e10cSrcweir m_sListeners( sListeners ) 49cdf0e10cSrcweir { 50cdf0e10cSrcweir } 51cdf0e10cSrcweir 52cdf0e10cSrcweir 53cdf0e10cSrcweir ContentEventNotifier::ContentEventNotifier( shell* pMyShell, 54cdf0e10cSrcweir const uno::Reference< XContent >& xCreatorContent, 55cdf0e10cSrcweir const uno::Reference< XContentIdentifier >& xCreatorId, 56cdf0e10cSrcweir const uno::Reference< XContentIdentifier >& xOldId, 57cdf0e10cSrcweir const uno::Sequence< uno::Reference< uno::XInterface > >& sListeners ) 58cdf0e10cSrcweir : m_pMyShell( pMyShell ), 59cdf0e10cSrcweir m_xCreatorContent( xCreatorContent ), 60cdf0e10cSrcweir m_xCreatorId( xCreatorId ), 61cdf0e10cSrcweir m_xOldId( xOldId ), 62cdf0e10cSrcweir m_sListeners( sListeners ) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir 67cdf0e10cSrcweir 68cdf0e10cSrcweir void ContentEventNotifier::notifyChildInserted( const rtl::OUString& aChildName ) 69cdf0e10cSrcweir { 70cdf0e10cSrcweir FileContentIdentifier* p = new FileContentIdentifier( m_pMyShell,aChildName ); 71cdf0e10cSrcweir uno::Reference< XContentIdentifier > xChildId( p ); 72cdf0e10cSrcweir 73cdf0e10cSrcweir uno::Reference< XContent > xChildContent = m_pMyShell->m_pProvider->queryContent( xChildId ); 74cdf0e10cSrcweir 75cdf0e10cSrcweir ContentEvent aEvt( m_xCreatorContent, 76cdf0e10cSrcweir ContentAction::INSERTED, 77cdf0e10cSrcweir xChildContent, 78cdf0e10cSrcweir m_xCreatorId ); 79cdf0e10cSrcweir 80cdf0e10cSrcweir for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i ) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir uno::Reference< XContentEventListener > ref( m_sListeners[i],uno::UNO_QUERY ); 83cdf0e10cSrcweir if( ref.is() ) 84cdf0e10cSrcweir ref->contentEvent( aEvt ); 85cdf0e10cSrcweir } 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir void ContentEventNotifier::notifyDeleted( void ) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir 91cdf0e10cSrcweir ContentEvent aEvt( m_xCreatorContent, 92cdf0e10cSrcweir ContentAction::DELETED, 93cdf0e10cSrcweir m_xCreatorContent, 94cdf0e10cSrcweir m_xCreatorId ); 95cdf0e10cSrcweir 96cdf0e10cSrcweir 97cdf0e10cSrcweir for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i ) 98cdf0e10cSrcweir { 99cdf0e10cSrcweir uno::Reference< XContentEventListener > ref( m_sListeners[i],uno::UNO_QUERY ); 100cdf0e10cSrcweir if( ref.is() ) 101cdf0e10cSrcweir ref->contentEvent( aEvt ); 102cdf0e10cSrcweir } 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir 106cdf0e10cSrcweir 107cdf0e10cSrcweir void ContentEventNotifier::notifyRemoved( const rtl::OUString& aChildName ) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir FileContentIdentifier* p = new FileContentIdentifier( m_pMyShell,aChildName ); 110cdf0e10cSrcweir uno::Reference< XContentIdentifier > xChildId( p ); 111cdf0e10cSrcweir 112cdf0e10cSrcweir BaseContent* pp = new BaseContent( m_pMyShell,xChildId,aChildName ); 113cdf0e10cSrcweir { 114cdf0e10cSrcweir osl::MutexGuard aGuard( pp->m_aMutex ); 115cdf0e10cSrcweir pp->m_nState |= BaseContent::Deleted; 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir uno::Reference< XContent > xDeletedContent( pp ); 119cdf0e10cSrcweir 120cdf0e10cSrcweir 121cdf0e10cSrcweir ContentEvent aEvt( m_xCreatorContent, 122cdf0e10cSrcweir ContentAction::REMOVED, 123cdf0e10cSrcweir xDeletedContent, 124cdf0e10cSrcweir m_xCreatorId ); 125cdf0e10cSrcweir 126cdf0e10cSrcweir for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i ) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir uno::Reference< XContentEventListener > ref( m_sListeners[i],uno::UNO_QUERY ); 129cdf0e10cSrcweir if( ref.is() ) 130cdf0e10cSrcweir ref->contentEvent( aEvt ); 131cdf0e10cSrcweir } 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir void ContentEventNotifier::notifyExchanged() 135cdf0e10cSrcweir { 136cdf0e10cSrcweir ContentEvent aEvt( m_xCreatorContent, 137cdf0e10cSrcweir ContentAction::EXCHANGED, 138cdf0e10cSrcweir m_xCreatorContent, 139cdf0e10cSrcweir m_xOldId ); 140cdf0e10cSrcweir 141cdf0e10cSrcweir for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i ) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir uno::Reference< XContentEventListener > ref( m_sListeners[i],uno::UNO_QUERY ); 144cdf0e10cSrcweir if( ref.is() ) 145cdf0e10cSrcweir ref->contentEvent( aEvt ); 146cdf0e10cSrcweir } 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir /*********************************************************************************/ 150cdf0e10cSrcweir /* */ 151cdf0e10cSrcweir /* PropertySetInfoChangeNotifier */ 152cdf0e10cSrcweir /* */ 153cdf0e10cSrcweir /*********************************************************************************/ 154cdf0e10cSrcweir 155cdf0e10cSrcweir 156cdf0e10cSrcweir PropertySetInfoChangeNotifier::PropertySetInfoChangeNotifier( 157cdf0e10cSrcweir shell* pMyShell, 158cdf0e10cSrcweir const uno::Reference< XContent >& xCreatorContent, 159cdf0e10cSrcweir const uno::Reference< XContentIdentifier >& xCreatorId, 160cdf0e10cSrcweir const uno::Sequence< uno::Reference< uno::XInterface > >& sListeners ) 161cdf0e10cSrcweir : m_pMyShell( pMyShell ), 162cdf0e10cSrcweir m_xCreatorContent( xCreatorContent ), 163cdf0e10cSrcweir m_xCreatorId( xCreatorId ), 164cdf0e10cSrcweir m_sListeners( sListeners ) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir 170cdf0e10cSrcweir void SAL_CALL 171cdf0e10cSrcweir PropertySetInfoChangeNotifier::notifyPropertyAdded( const rtl::OUString & aPropertyName ) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir beans::PropertySetInfoChangeEvent aEvt( m_xCreatorContent, 174cdf0e10cSrcweir aPropertyName, 175cdf0e10cSrcweir -1, 176cdf0e10cSrcweir beans::PropertySetInfoChange::PROPERTY_INSERTED ); 177cdf0e10cSrcweir 178cdf0e10cSrcweir for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i ) 179cdf0e10cSrcweir { 180cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfoChangeListener > ref( m_sListeners[i],uno::UNO_QUERY ); 181cdf0e10cSrcweir if( ref.is() ) 182cdf0e10cSrcweir ref->propertySetInfoChange( aEvt ); 183cdf0e10cSrcweir } 184cdf0e10cSrcweir } 185cdf0e10cSrcweir 186cdf0e10cSrcweir 187cdf0e10cSrcweir void SAL_CALL 188cdf0e10cSrcweir PropertySetInfoChangeNotifier::notifyPropertyRemoved( const rtl::OUString & aPropertyName ) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir beans::PropertySetInfoChangeEvent aEvt( m_xCreatorContent, 191cdf0e10cSrcweir aPropertyName, 192cdf0e10cSrcweir -1, 193cdf0e10cSrcweir beans::PropertySetInfoChange::PROPERTY_REMOVED ); 194cdf0e10cSrcweir 195cdf0e10cSrcweir for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i ) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfoChangeListener > ref( m_sListeners[i],uno::UNO_QUERY ); 198cdf0e10cSrcweir if( ref.is() ) 199cdf0e10cSrcweir ref->propertySetInfoChange( aEvt ); 200cdf0e10cSrcweir } 201cdf0e10cSrcweir } 202cdf0e10cSrcweir 203cdf0e10cSrcweir 204cdf0e10cSrcweir /*********************************************************************************/ 205cdf0e10cSrcweir /* */ 206cdf0e10cSrcweir /* PropertySetInfoChangeNotifier */ 207cdf0e10cSrcweir /* */ 208cdf0e10cSrcweir /*********************************************************************************/ 209cdf0e10cSrcweir 210cdf0e10cSrcweir 211cdf0e10cSrcweir PropertyChangeNotifier::PropertyChangeNotifier( 212cdf0e10cSrcweir shell* pMyShell, 213cdf0e10cSrcweir const com::sun::star::uno::Reference< XContent >& xCreatorContent, 214cdf0e10cSrcweir const com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier >& xCreatorId, 215cdf0e10cSrcweir ListenerMap* pListeners ) 216cdf0e10cSrcweir : m_pMyShell( pMyShell ), 217cdf0e10cSrcweir m_xCreatorContent( xCreatorContent ), 218cdf0e10cSrcweir m_xCreatorId( xCreatorId ), 219cdf0e10cSrcweir m_pListeners( pListeners ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir 224cdf0e10cSrcweir PropertyChangeNotifier::~PropertyChangeNotifier() 225cdf0e10cSrcweir { 226cdf0e10cSrcweir delete m_pListeners; 227cdf0e10cSrcweir } 228cdf0e10cSrcweir 229cdf0e10cSrcweir 230cdf0e10cSrcweir void PropertyChangeNotifier::notifyPropertyChanged( 231cdf0e10cSrcweir uno::Sequence< beans::PropertyChangeEvent > Changes ) 232cdf0e10cSrcweir { 233cdf0e10cSrcweir sal_Int32 j; 234cdf0e10cSrcweir 235cdf0e10cSrcweir for( j = 0; j < Changes.getLength(); ++j ) 236cdf0e10cSrcweir Changes[j].Source = m_xCreatorContent; 237cdf0e10cSrcweir 238cdf0e10cSrcweir // notify listeners for all Events 239cdf0e10cSrcweir 240cdf0e10cSrcweir uno::Sequence< uno::Reference< uno::XInterface > > seqList = (*m_pListeners)[ rtl::OUString() ]; 241cdf0e10cSrcweir for( j = 0; j < seqList.getLength(); ++j ) 242cdf0e10cSrcweir { 243cdf0e10cSrcweir uno::Reference< beans::XPropertiesChangeListener > aListener( seqList[j],uno::UNO_QUERY ); 244cdf0e10cSrcweir if( aListener.is() ) 245cdf0e10cSrcweir { 246cdf0e10cSrcweir aListener->propertiesChange( Changes ); 247cdf0e10cSrcweir } 248cdf0e10cSrcweir } 249cdf0e10cSrcweir 250cdf0e10cSrcweir uno::Sequence< beans::PropertyChangeEvent > seq(1); 251cdf0e10cSrcweir for( j = 0; j < Changes.getLength(); ++j ) 252cdf0e10cSrcweir { 253cdf0e10cSrcweir seq[0] = Changes[j]; 254cdf0e10cSrcweir seqList = (*m_pListeners)[ seq[0].PropertyName ]; 255cdf0e10cSrcweir 256cdf0e10cSrcweir for( sal_Int32 i = 0; i < seqList.getLength(); ++i ) 257cdf0e10cSrcweir { 258cdf0e10cSrcweir uno::Reference< beans::XPropertiesChangeListener > aListener( seqList[j],uno::UNO_QUERY ); 259cdf0e10cSrcweir if( aListener.is() ) 260cdf0e10cSrcweir { 261cdf0e10cSrcweir aListener->propertiesChange( seq ); 262cdf0e10cSrcweir } 263cdf0e10cSrcweir } 264cdf0e10cSrcweir } 265cdf0e10cSrcweir } 266