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 #ifndef _FILTASK_HXX_ 28 #define _FILTASK_HXX_ 29 #endif 30 31 #include <hash_map> 32 #include <rtl/ustring.hxx> 33 34 #include "osl/mutex.hxx" 35 #include <com/sun/star/ucb/DuplicateCommandIdentifierException.hpp> 36 #include <com/sun/star/ucb/XCommandEnvironment.hpp> 37 #include <com/sun/star/ucb/XProgressHandler.hpp> 38 #include <com/sun/star/task/XInteractionHandler.hpp> 39 #include <com/sun/star/task/XInteractionRequest.hpp> 40 #include "filerror.hxx" 41 42 43 namespace fileaccess 44 { 45 class BaseContent; 46 47 /* 48 * This implementation is inherited by class fileaccess::shell. 49 * The relevant methods in this class all have as first argument the CommandId, 50 * so if necessary, every method has access to its relevant XInteractionHandler and 51 * XProgressHandler. 52 */ 53 54 55 class TaskManager 56 { 57 protected: 58 59 class TaskHandling 60 { 61 private: 62 63 bool m_bAbort,m_bHandled; 64 sal_Int32 m_nErrorCode,m_nMinorCode; 65 com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > m_xInteractionHandler; 66 com::sun::star::uno::Reference< com::sun::star::ucb::XProgressHandler > m_xProgressHandler; 67 com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment > m_xCommandEnvironment; 68 69 70 public: 71 72 TaskHandling( 73 const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >& xCommandEnv 74 = com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >( 0 ) ) 75 : m_bAbort( false ), 76 m_bHandled( false ), 77 m_nErrorCode( TASKHANDLER_NO_ERROR ), 78 m_nMinorCode( TASKHANDLER_NO_ERROR ), 79 m_xInteractionHandler( 0 ), 80 m_xProgressHandler( 0 ), 81 m_xCommandEnvironment( xCommandEnv ) 82 { 83 } 84 85 void SAL_CALL abort() 86 { 87 m_bAbort = true; 88 } 89 90 void setHandled() 91 { 92 m_bHandled = true; 93 } 94 95 bool isHandled() 96 { 97 return true; 98 } 99 100 void clearError() 101 { 102 m_nErrorCode = TASKHANDLER_NO_ERROR; 103 m_nMinorCode = TASKHANDLER_NO_ERROR; 104 } 105 106 void SAL_CALL installError( sal_Int32 nErrorCode, 107 sal_Int32 nMinorCode = TASKHANDLER_NO_ERROR ) 108 { 109 m_nErrorCode = nErrorCode; 110 m_nMinorCode = nMinorCode; 111 } 112 113 sal_Int32 SAL_CALL getInstalledError() 114 { 115 return m_nErrorCode; 116 } 117 118 sal_Int32 SAL_CALL getMinorErrorCode() 119 { 120 return m_nMinorCode; 121 } 122 123 com::sun::star::uno::Reference< com::sun::star::ucb::XProgressHandler > SAL_CALL 124 getProgressHandler() 125 { 126 if( ! m_xProgressHandler.is() && m_xCommandEnvironment.is() ) 127 m_xProgressHandler = m_xCommandEnvironment->getProgressHandler(); 128 129 return m_xProgressHandler; 130 } 131 132 com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > SAL_CALL 133 getInteractionHandler() 134 { 135 if( ! m_xInteractionHandler.is() && m_xCommandEnvironment.is() ) 136 m_xInteractionHandler = m_xCommandEnvironment->getInteractionHandler(); 137 138 return m_xInteractionHandler; 139 } 140 141 com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment > SAL_CALL 142 getCommandEnvironment() 143 { 144 return m_xCommandEnvironment; 145 } 146 147 }; // end class TaskHandling 148 149 150 typedef std::hash_map< sal_Int32,TaskHandling,std::hash< sal_Int32 > > TaskMap; 151 152 153 private: 154 155 osl::Mutex m_aMutex; 156 sal_Int32 m_nCommandId; 157 TaskMap m_aTaskMap; 158 159 160 public: 161 162 TaskManager(); 163 virtual ~TaskManager(); 164 165 void SAL_CALL startTask( 166 sal_Int32 CommandId, 167 const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >& xCommandEnv ) 168 throw( com::sun::star::ucb::DuplicateCommandIdentifierException ); 169 170 sal_Int32 SAL_CALL getCommandId( void ); 171 void SAL_CALL abort( sal_Int32 CommandId ); 172 173 174 /** 175 * The error code may be one of the error codes defined in 176 * filerror.hxx. 177 * The minor code refines the information given in ErrorCode. 178 */ 179 180 void SAL_CALL clearError(); 181 182 void SAL_CALL installError( sal_Int32 CommandId, 183 sal_Int32 ErrorCode, 184 sal_Int32 minorCode = TASKHANDLER_NO_ERROR ); 185 186 187 // void SAL_CALL installError( sal_Int32 CommandId, 188 // sal_Int32 ErrorCode, 189 // rtl::OUString message ); 190 191 // void SAL_CALL installError( sal_Int32 CommandId, 192 // sal_Int32 ErrorCode, 193 // rtl::OUString message ); 194 195 void SAL_CALL retrieveError( sal_Int32 CommandId, 196 sal_Int32 &ErrorCode, 197 sal_Int32 &minorCode); 198 199 /** 200 * Deinstalls the task and evaluates a possibly set error code. 201 * "endTask" throws in case an error code is set the corresponding exception. 202 */ 203 204 void SAL_CALL endTask( sal_Int32 CommandId, 205 // the physical URL of the object 206 const rtl::OUString& aUnqPath, 207 BaseContent* pContent); 208 209 210 /** 211 * Handles an interactionrequest 212 */ 213 214 void SAL_CALL handleTask( sal_Int32 CommandId, 215 const com::sun::star::uno::Reference< com::sun::star::task::XInteractionRequest >& request ); 216 217 /** 218 * Clears any error which are set on the commandid 219 */ 220 221 void SAL_CALL clearError( sal_Int32 ); 222 223 }; 224 225 } // end namespace TaskHandling 226