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