LibreOffice Module unotools (master) 1
progresshandlerwrap.cxx
Go to the documentation of this file.
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
21#include <com/sun/star/task/XStatusIndicator.hpp>
22#include <utility>
23
24namespace utl
25{
26
27using namespace ::com::sun::star::uno;
28using namespace ::com::sun::star::task;
29using namespace ::com::sun::star::ucb;
30
31ProgressHandlerWrap::ProgressHandlerWrap( css::uno::Reference< css::task::XStatusIndicator > xSI )
32: m_xStatusIndicator(std::move( xSI ))
33{
34}
35
36static bool getStatusFromAny_Impl( const Any& aAny, OUString& aText, sal_Int32& nNum )
37{
38 bool bNumIsSet = false;
39
40 Sequence< Any > aSetList;
41 if( aAny >>= aSetList )
42 for( const auto& rSet : std::as_const(aSetList) )
43 {
44 if( !bNumIsSet && ( rSet >>= nNum ) )
45 bNumIsSet = true;
46 else
47 aText.isEmpty() && ( rSet >>= aText );
48 }
49
50 return bNumIsSet;
51}
52
53void SAL_CALL ProgressHandlerWrap::push( const Any& Status )
54{
55 if( !m_xStatusIndicator.is() )
56 return;
57
58 OUString aText;
59 sal_Int32 nRange;
60
61 if( getStatusFromAny_Impl( Status, aText, nRange ) )
62 m_xStatusIndicator->start( aText, nRange );
63}
64
65void SAL_CALL ProgressHandlerWrap::update( const Any& Status )
66{
67 if( !m_xStatusIndicator.is() )
68 return;
69
70 OUString aText;
71 sal_Int32 nValue;
72
73 if( getStatusFromAny_Impl( Status, aText, nValue ) )
74 {
75 if( !aText.isEmpty() ) m_xStatusIndicator->setText( aText );
76 m_xStatusIndicator->setValue( nValue );
77 }
78}
79
80void SAL_CALL ProgressHandlerWrap::pop()
81{
82 if( m_xStatusIndicator.is() )
83 m_xStatusIndicator->end();
84}
85
86} // namespace utl
87
88/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int16 nValue
Status
static bool getStatusFromAny_Impl(const Any &aAny, OUString &aText, sal_Int32 &nNum)
static SfxItemSet & rSet