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
ProgressHandlerWrap(::com::sun::star::uno::Reference<::com::sun::star::task::XStatusIndicator> xSI)35 ProgressHandlerWrap::ProgressHandlerWrap( ::com::sun::star::uno::Reference< ::com::sun::star::task::XStatusIndicator > xSI )
36 : m_xStatusIndicator( xSI )
37 {
38 }
39
getStatusFromAny_Impl(const Any & aAny,::rtl::OUString & aText,sal_Int32 & nNum)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
push(const Any & Status)57 void SAL_CALL ProgressHandlerWrap::push( const Any& Status )
58 throw( RuntimeException )
59 {
60 if( !m_xStatusIndicator.is() )
61 return;
62
63 ::rtl::OUString aText;
64 sal_Int32 nRange;
65
66 if( getStatusFromAny_Impl( Status, aText, nRange ) )
67 m_xStatusIndicator->start( aText, nRange );
68 }
69
update(const Any & Status)70 void SAL_CALL ProgressHandlerWrap::update( const Any& Status )
71 throw( RuntimeException )
72 {
73 if( !m_xStatusIndicator.is() )
74 return;
75
76 ::rtl::OUString aText;
77 sal_Int32 nValue;
78
79 if( getStatusFromAny_Impl( Status, aText, nValue ) )
80 {
81 if( aText.getLength() ) m_xStatusIndicator->setText( aText );
82 m_xStatusIndicator->setValue( nValue );
83 }
84 }
85
pop()86 void SAL_CALL ProgressHandlerWrap::pop()
87 throw( RuntimeException )
88 {
89 if( m_xStatusIndicator.is() )
90 m_xStatusIndicator->end();
91 }
92
93 } // namespace utl
94
95