1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir #ifndef _FILTASK_HXX_ 28*cdf0e10cSrcweir #define _FILTASK_HXX_ 29*cdf0e10cSrcweir #endif 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <hash_map> 32*cdf0e10cSrcweir #include <rtl/ustring.hxx> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #include "osl/mutex.hxx" 35*cdf0e10cSrcweir #include <com/sun/star/ucb/DuplicateCommandIdentifierException.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandEnvironment.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/ucb/XProgressHandler.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/task/XInteractionRequest.hpp> 40*cdf0e10cSrcweir #include "filerror.hxx" 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir namespace fileaccess 44*cdf0e10cSrcweir { 45*cdf0e10cSrcweir class BaseContent; 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir /* 48*cdf0e10cSrcweir * This implementation is inherited by class fileaccess::shell. 49*cdf0e10cSrcweir * The relevant methods in this class all have as first argument the CommandId, 50*cdf0e10cSrcweir * so if necessary, every method has access to its relevant XInteractionHandler and 51*cdf0e10cSrcweir * XProgressHandler. 52*cdf0e10cSrcweir */ 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir class TaskManager 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir protected: 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir class TaskHandling 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir private: 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir bool m_bAbort,m_bHandled; 64*cdf0e10cSrcweir sal_Int32 m_nErrorCode,m_nMinorCode; 65*cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > m_xInteractionHandler; 66*cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::ucb::XProgressHandler > m_xProgressHandler; 67*cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment > m_xCommandEnvironment; 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir public: 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir TaskHandling( 73*cdf0e10cSrcweir const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >& xCommandEnv 74*cdf0e10cSrcweir = com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >( 0 ) ) 75*cdf0e10cSrcweir : m_bAbort( false ), 76*cdf0e10cSrcweir m_bHandled( false ), 77*cdf0e10cSrcweir m_nErrorCode( TASKHANDLER_NO_ERROR ), 78*cdf0e10cSrcweir m_nMinorCode( TASKHANDLER_NO_ERROR ), 79*cdf0e10cSrcweir m_xInteractionHandler( 0 ), 80*cdf0e10cSrcweir m_xProgressHandler( 0 ), 81*cdf0e10cSrcweir m_xCommandEnvironment( xCommandEnv ) 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir void SAL_CALL abort() 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir m_bAbort = true; 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir void setHandled() 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir m_bHandled = true; 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir bool isHandled() 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir return true; 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir void clearError() 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir m_nErrorCode = TASKHANDLER_NO_ERROR; 103*cdf0e10cSrcweir m_nMinorCode = TASKHANDLER_NO_ERROR; 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir void SAL_CALL installError( sal_Int32 nErrorCode, 107*cdf0e10cSrcweir sal_Int32 nMinorCode = TASKHANDLER_NO_ERROR ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir m_nErrorCode = nErrorCode; 110*cdf0e10cSrcweir m_nMinorCode = nMinorCode; 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir sal_Int32 SAL_CALL getInstalledError() 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir return m_nErrorCode; 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir sal_Int32 SAL_CALL getMinorErrorCode() 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir return m_nMinorCode; 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::ucb::XProgressHandler > SAL_CALL 124*cdf0e10cSrcweir getProgressHandler() 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir if( ! m_xProgressHandler.is() && m_xCommandEnvironment.is() ) 127*cdf0e10cSrcweir m_xProgressHandler = m_xCommandEnvironment->getProgressHandler(); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir return m_xProgressHandler; 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > SAL_CALL 133*cdf0e10cSrcweir getInteractionHandler() 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir if( ! m_xInteractionHandler.is() && m_xCommandEnvironment.is() ) 136*cdf0e10cSrcweir m_xInteractionHandler = m_xCommandEnvironment->getInteractionHandler(); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir return m_xInteractionHandler; 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment > SAL_CALL 142*cdf0e10cSrcweir getCommandEnvironment() 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir return m_xCommandEnvironment; 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir }; // end class TaskHandling 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir typedef std::hash_map< sal_Int32,TaskHandling,std::hash< sal_Int32 > > TaskMap; 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir private: 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir osl::Mutex m_aMutex; 156*cdf0e10cSrcweir sal_Int32 m_nCommandId; 157*cdf0e10cSrcweir TaskMap m_aTaskMap; 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir public: 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir TaskManager(); 163*cdf0e10cSrcweir virtual ~TaskManager(); 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir void SAL_CALL startTask( 166*cdf0e10cSrcweir sal_Int32 CommandId, 167*cdf0e10cSrcweir const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >& xCommandEnv ) 168*cdf0e10cSrcweir throw( com::sun::star::ucb::DuplicateCommandIdentifierException ); 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir sal_Int32 SAL_CALL getCommandId( void ); 171*cdf0e10cSrcweir void SAL_CALL abort( sal_Int32 CommandId ); 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir /** 175*cdf0e10cSrcweir * The error code may be one of the error codes defined in 176*cdf0e10cSrcweir * filerror.hxx. 177*cdf0e10cSrcweir * The minor code refines the information given in ErrorCode. 178*cdf0e10cSrcweir */ 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir void SAL_CALL clearError(); 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir void SAL_CALL installError( sal_Int32 CommandId, 183*cdf0e10cSrcweir sal_Int32 ErrorCode, 184*cdf0e10cSrcweir sal_Int32 minorCode = TASKHANDLER_NO_ERROR ); 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir // void SAL_CALL installError( sal_Int32 CommandId, 188*cdf0e10cSrcweir // sal_Int32 ErrorCode, 189*cdf0e10cSrcweir // rtl::OUString message ); 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir // void SAL_CALL installError( sal_Int32 CommandId, 192*cdf0e10cSrcweir // sal_Int32 ErrorCode, 193*cdf0e10cSrcweir // rtl::OUString message ); 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir void SAL_CALL retrieveError( sal_Int32 CommandId, 196*cdf0e10cSrcweir sal_Int32 &ErrorCode, 197*cdf0e10cSrcweir sal_Int32 &minorCode); 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir /** 200*cdf0e10cSrcweir * Deinstalls the task and evaluates a possibly set error code. 201*cdf0e10cSrcweir * "endTask" throws in case an error code is set the corresponding exception. 202*cdf0e10cSrcweir */ 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir void SAL_CALL endTask( sal_Int32 CommandId, 205*cdf0e10cSrcweir // the physical URL of the object 206*cdf0e10cSrcweir const rtl::OUString& aUnqPath, 207*cdf0e10cSrcweir BaseContent* pContent); 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir /** 211*cdf0e10cSrcweir * Handles an interactionrequest 212*cdf0e10cSrcweir */ 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir void SAL_CALL handleTask( sal_Int32 CommandId, 215*cdf0e10cSrcweir const com::sun::star::uno::Reference< com::sun::star::task::XInteractionRequest >& request ); 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir /** 218*cdf0e10cSrcweir * Clears any error which are set on the commandid 219*cdf0e10cSrcweir */ 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir void SAL_CALL clearError( sal_Int32 ); 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir }; 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir } // end namespace TaskHandling 226