1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_unotools.hxx" 26 #include <unotools/progresshandlerwrap.hxx> 27 28 namespace utl 29 { 30 31 using namespace ::com::sun::star::uno; 32 using namespace ::com::sun::star::task; 33 using namespace ::com::sun::star::ucb; 34 35 ProgressHandlerWrap::ProgressHandlerWrap( ::com::sun::star::uno::Reference< ::com::sun::star::task::XStatusIndicator > xSI ) 36 : m_xStatusIndicator( xSI ) 37 { 38 } 39 40 sal_Bool getStatusFromAny_Impl( const Any& aAny, ::rtl::OUString& aText, sal_Int32& nNum ) 41 { 42 sal_Bool bNumIsSet = sal_False; 43 44 Sequence< Any > aSetList; 45 if( ( aAny >>= aSetList ) && aSetList.getLength() ) 46 for( int ind = 0; ind < aSetList.getLength(); ind++ ) 47 { 48 if( !bNumIsSet && ( aSetList[ind] >>= nNum ) ) 49 bNumIsSet = sal_True; 50 else 51 !aText.getLength() && ( aSetList[ind] >>= aText ); 52 } 53 54 return bNumIsSet; 55 } 56 57 void SAL_CALL ProgressHandlerWrap::push( const Any& Status ) 58 { 59 if( !m_xStatusIndicator.is() ) 60 return; 61 62 ::rtl::OUString aText; 63 sal_Int32 nRange; 64 65 if( getStatusFromAny_Impl( Status, aText, nRange ) ) 66 m_xStatusIndicator->start( aText, nRange ); 67 } 68 69 void SAL_CALL ProgressHandlerWrap::update( const Any& Status ) 70 { 71 if( !m_xStatusIndicator.is() ) 72 return; 73 74 ::rtl::OUString aText; 75 sal_Int32 nValue; 76 77 if( getStatusFromAny_Impl( Status, aText, nValue ) ) 78 { 79 if( aText.getLength() ) m_xStatusIndicator->setText( aText ); 80 m_xStatusIndicator->setValue( nValue ); 81 } 82 } 83 84 void SAL_CALL ProgressHandlerWrap::pop() 85 { 86 if( m_xStatusIndicator.is() ) 87 m_xStatusIndicator->end(); 88 } 89 90 } // namespace utl 91