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_fpicker.hxx" 26 #include "fpinteraction.hxx" 27 #include <tools/debug.hxx> 28 #include <com/sun/star/ucb/InteractiveIOException.hpp> 29 #include <com/sun/star/task/XInteractionAbort.hpp> 30 #include <com/sun/star/task/XInteractionApprove.hpp> 31 #include <com/sun/star/task/XInteractionDisapprove.hpp> 32 #include <com/sun/star/task/XInteractionRetry.hpp> 33 34 //........................................................................ 35 namespace svt 36 { 37 //........................................................................ 38 using namespace ::com::sun::star::uno; 39 using namespace ::com::sun::star::task; 40 using namespace ::com::sun::star::ucb; 41 42 //==================================================================== 43 //= OFilePickerInteractionHandler 44 //==================================================================== DBG_NAME(OFilePickerInteractionHandler)45 DBG_NAME( OFilePickerInteractionHandler ) 46 //-------------------------------------------------------------------- 47 OFilePickerInteractionHandler::OFilePickerInteractionHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& _rxMaster ) 48 :m_xMaster( _rxMaster ) 49 ,m_bUsed( sal_False ) 50 ,m_eInterceptions( OFilePickerInteractionHandler::E_NOINTERCEPTION ) 51 { 52 DBG_CTOR( OFilePickerInteractionHandler, NULL ); 53 DBG_ASSERT( m_xMaster.is(), "OFilePickerInteractionHandler::OFilePickerInteractionHandler: invalid master handler!" ); 54 } 55 56 //-------------------------------------------------------------------- ~OFilePickerInteractionHandler()57 OFilePickerInteractionHandler::~OFilePickerInteractionHandler( ) 58 { 59 DBG_DTOR( OFilePickerInteractionHandler, NULL ); 60 } 61 62 //-------------------------------------------------------------------- handle(const Reference<XInteractionRequest> & _rxRequest)63 void SAL_CALL OFilePickerInteractionHandler::handle( const Reference< XInteractionRequest >& _rxRequest ) throw (RuntimeException) 64 { 65 if (!_rxRequest.is()) 66 return; 67 68 m_bUsed = sal_True; 69 70 // extract some generic continuations ... might we need it later 71 // if something goes wrong. 72 Reference< XInteractionAbort > xAbort; 73 Reference< XInteractionApprove > xApprove; 74 Reference< XInteractionDisapprove > xDisapprove; 75 Reference< XInteractionRetry > xRetry; 76 77 const Sequence< Reference< XInteractionContinuation > > lConts = _rxRequest->getContinuations(); 78 const Reference< XInteractionContinuation >* pConts = lConts.getConstArray(); 79 for (sal_Int32 i=0; i<lConts.getLength(); ++i) 80 { 81 if (!xAbort.is()) 82 xAbort = Reference< XInteractionAbort >(pConts[i], UNO_QUERY); 83 if (!xApprove.is()) 84 xApprove = Reference< XInteractionApprove >(pConts[i], UNO_QUERY); 85 if (!xDisapprove.is()) 86 xDisapprove = Reference< XInteractionDisapprove >(pConts[i], UNO_QUERY); 87 if (!xRetry.is()) 88 xRetry = Reference< XInteractionRetry >(pConts[i], UNO_QUERY); 89 } 90 91 // safe the original request for later analyzing! 92 m_aException = _rxRequest->getRequest(); 93 94 // intercept some interesting interactions 95 96 // The "does not exist" interaction will be supressed here completly. 97 if (m_eInterceptions & OFilePickerInteractionHandler::E_DOESNOTEXIST) 98 { 99 InteractiveIOException aIoException; 100 if ( 101 (m_aException >>= aIoException ) && 102 (IOErrorCode_NOT_EXISTING == aIoException.Code) 103 ) 104 { 105 if (xAbort.is()) 106 xAbort->select(); 107 return; 108 } 109 } 110 111 // no master => abort this operation ... 112 if (!m_xMaster.is()) 113 { 114 if (xAbort.is()) 115 xAbort->select(); 116 return; 117 } 118 119 // forward it to our master - so he can handle all 120 // not interesting interactions :-) 121 m_xMaster->handle(_rxRequest); 122 } 123 124 //-------------------------------------------------------------------- enableInterceptions(EInterceptedInteractions eInterceptions)125 void OFilePickerInteractionHandler::enableInterceptions( EInterceptedInteractions eInterceptions ) 126 { 127 m_eInterceptions = eInterceptions; 128 } 129 130 //-------------------------------------------------------------------- wasUsed() const131 sal_Bool OFilePickerInteractionHandler::wasUsed() const 132 { 133 return m_bUsed; 134 } 135 136 //-------------------------------------------------------------------- resetUseState()137 void OFilePickerInteractionHandler::resetUseState() 138 { 139 m_bUsed = sal_False; 140 } 141 142 //-------------------------------------------------------------------- forgetRequest()143 void OFilePickerInteractionHandler::forgetRequest() 144 { 145 m_aException = Any(); 146 } 147 148 //-------------------------------------------------------------------- wasAccessDenied() const149 sal_Bool OFilePickerInteractionHandler::wasAccessDenied() const 150 { 151 InteractiveIOException aIoException; 152 if ( 153 (m_aException >>= aIoException ) && 154 (IOErrorCode_ACCESS_DENIED == aIoException.Code) 155 ) 156 { 157 return sal_True; 158 } 159 return sal_False; 160 } 161 162 //........................................................................ 163 } // namespace svt 164 //........................................................................ 165 166