1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #if ! defined INCLUDED_DP_INTERACT_H 29 #define INCLUDED_DP_INTERACT_H 30 31 #include "rtl/ref.hxx" 32 #include "cppuhelper/implbase1.hxx" 33 #include "com/sun/star/uno/XComponentContext.hpp" 34 #include "com/sun/star/ucb/XCommandEnvironment.hpp" 35 #include "com/sun/star/task/XAbortChannel.hpp" 36 #include "dp_misc_api.hxx" 37 38 namespace css = ::com::sun::star; 39 40 namespace dp_misc 41 { 42 43 inline void progressUpdate( 44 ::rtl::OUString const & status, 45 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) 46 { 47 if (xCmdEnv.is()) { 48 css::uno::Reference<css::ucb::XProgressHandler> xProgressHandler( 49 xCmdEnv->getProgressHandler() ); 50 if (xProgressHandler.is()) { 51 xProgressHandler->update( css::uno::makeAny(status) ); 52 } 53 } 54 } 55 56 //============================================================================== 57 class ProgressLevel 58 { 59 css::uno::Reference<css::ucb::XProgressHandler> m_xProgressHandler; 60 61 public: 62 inline ~ProgressLevel(); 63 inline ProgressLevel( 64 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv, 65 ::rtl::OUString const & status ); 66 67 inline void update( ::rtl::OUString const & status ) const; 68 inline void update( css::uno::Any const & status ) const; 69 }; 70 71 //______________________________________________________________________________ 72 inline ProgressLevel::ProgressLevel( 73 css::uno::Reference< css::ucb::XCommandEnvironment > const & xCmdEnv, 74 ::rtl::OUString const & status ) 75 { 76 if (xCmdEnv.is()) 77 m_xProgressHandler = xCmdEnv->getProgressHandler(); 78 if (m_xProgressHandler.is()) 79 m_xProgressHandler->push( css::uno::makeAny(status) ); 80 } 81 82 //______________________________________________________________________________ 83 inline ProgressLevel::~ProgressLevel() 84 { 85 if (m_xProgressHandler.is()) 86 m_xProgressHandler->pop(); 87 } 88 89 //______________________________________________________________________________ 90 inline void ProgressLevel::update( ::rtl::OUString const & status ) const 91 { 92 if (m_xProgressHandler.is()) 93 m_xProgressHandler->update( css::uno::makeAny(status) ); 94 } 95 96 //______________________________________________________________________________ 97 inline void ProgressLevel::update( css::uno::Any const & status ) const 98 { 99 if (m_xProgressHandler.is()) 100 m_xProgressHandler->update( status ); 101 } 102 103 //############################################################################## 104 105 /** @return true if ia handler is present and any selection has been chosen 106 */ 107 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool interactContinuation( 108 css::uno::Any const & request, 109 css::uno::Type const & continuation, 110 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv, 111 bool * pcont, bool * pabort ); 112 113 //############################################################################## 114 115 //============================================================================== 116 class DESKTOP_DEPLOYMENTMISC_DLLPUBLIC AbortChannel : 117 public ::cppu::WeakImplHelper1<css::task::XAbortChannel> 118 { 119 bool m_aborted; 120 css::uno::Reference<css::task::XAbortChannel> m_xNext; 121 122 public: 123 inline AbortChannel() : m_aborted( false ) {} 124 inline static AbortChannel * get( 125 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel ) 126 { return static_cast<AbortChannel *>(xAbortChannel.get()); } 127 128 inline bool isAborted() const { return m_aborted; } 129 130 // XAbortChannel 131 virtual void SAL_CALL sendAbort() throw (css::uno::RuntimeException); 132 133 class SAL_DLLPRIVATE Chain 134 { 135 const ::rtl::Reference<AbortChannel> m_abortChannel; 136 public: 137 inline Chain( 138 ::rtl::Reference<AbortChannel> const & abortChannel, 139 css::uno::Reference<css::task::XAbortChannel> const & xNext ) 140 : m_abortChannel( abortChannel ) 141 { if (m_abortChannel.is()) m_abortChannel->m_xNext = xNext; } 142 inline ~Chain() 143 { if (m_abortChannel.is()) m_abortChannel->m_xNext.clear(); } 144 }; 145 friend class Chain; 146 }; 147 148 } 149 150 #endif 151