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 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_framework.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "interaction/quietinteraction.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 34*cdf0e10cSrcweir // my own includes 35*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 36*cdf0e10cSrcweir #include <threadhelp/readguard.hxx> 37*cdf0e10cSrcweir #include <threadhelp/writeguard.hxx> 38*cdf0e10cSrcweir #include <macros/generic.hxx> 39*cdf0e10cSrcweir #include <macros/debug.hxx> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 42*cdf0e10cSrcweir // interface includes 43*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 44*cdf0e10cSrcweir #include <com/sun/star/task/XInteractionAbort.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/task/XInteractionApprove.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/document/XInteractionFilterSelect.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/document/XInteractionFilterOptions.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/document/AmbigousFilterRequest.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/document/FilterOptionsRequest.hpp> 50*cdf0e10cSrcweir #include <com/sun/star/task/ErrorCodeRequest.hpp> 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_DOCUMENT_LOCKEDDOCUMENTREQUEST_HPP_ 53*cdf0e10cSrcweir #include <com/sun/star/document/LockedDocumentRequest.hpp> 54*cdf0e10cSrcweir #endif 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 57*cdf0e10cSrcweir // other includes 58*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 59*cdf0e10cSrcweir #include <vcl/svapp.hxx> 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir #ifndef __RSC 62*cdf0e10cSrcweir #include <tools/errinf.hxx> 63*cdf0e10cSrcweir #endif 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 66*cdf0e10cSrcweir // namespace 67*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir namespace framework{ 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 72*cdf0e10cSrcweir // exported const 73*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 76*cdf0e10cSrcweir // exported definitions 77*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir DEFINE_XINTERFACE_2( QuietInteraction , 80*cdf0e10cSrcweir OWeakObject , 81*cdf0e10cSrcweir DIRECT_INTERFACE(css::lang::XTypeProvider ) , 82*cdf0e10cSrcweir DIRECT_INTERFACE(css::task::XInteractionHandler) ) 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir DEFINE_XTYPEPROVIDER_2( QuietInteraction , 85*cdf0e10cSrcweir css::lang::XTypeProvider , 86*cdf0e10cSrcweir css::task::XInteractionHandler ) 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir QuietInteraction::QuietInteraction() 91*cdf0e10cSrcweir : ThreadHelpBase ( &Application::GetSolarMutex() ) 92*cdf0e10cSrcweir , ::cppu::OWeakObject( ) 93*cdf0e10cSrcweir , m_aRequest ( ) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir void SAL_CALL QuietInteraction::handle( const css::uno::Reference< css::task::XInteractionRequest >& xRequest ) throw( css::uno::RuntimeException ) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir // safe the request for outside analyzing everytime! 102*cdf0e10cSrcweir css::uno::Any aRequest = xRequest->getRequest(); 103*cdf0e10cSrcweir /* SAFE { */ 104*cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 105*cdf0e10cSrcweir m_aRequest = aRequest; 106*cdf0e10cSrcweir aWriteLock.unlock(); 107*cdf0e10cSrcweir /* } SAFE */ 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir // analyze the request 110*cdf0e10cSrcweir // We need XAbort as possible continuation as minimum! 111*cdf0e10cSrcweir // An optional filter selection we can handle too. 112*cdf0e10cSrcweir css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > lContinuations = xRequest->getContinuations(); 113*cdf0e10cSrcweir css::uno::Reference< css::task::XInteractionAbort > xAbort ; 114*cdf0e10cSrcweir css::uno::Reference< css::task::XInteractionApprove > xApprove ; 115*cdf0e10cSrcweir css::uno::Reference< css::document::XInteractionFilterSelect > xFilter ; 116*cdf0e10cSrcweir css::uno::Reference< css::document::XInteractionFilterOptions > xFOptions ; 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir sal_Int32 nCount=lContinuations.getLength(); 119*cdf0e10cSrcweir for (sal_Int32 i=0; i<nCount; ++i) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir if ( ! xAbort.is() ) 122*cdf0e10cSrcweir xAbort = css::uno::Reference< css::task::XInteractionAbort >( lContinuations[i], css::uno::UNO_QUERY ); 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir if( ! xApprove.is() ) 125*cdf0e10cSrcweir xApprove = css::uno::Reference< css::task::XInteractionApprove >( lContinuations[i], css::uno::UNO_QUERY ); 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir if ( ! xFilter.is() ) 128*cdf0e10cSrcweir xFilter = css::uno::Reference< css::document::XInteractionFilterSelect >( lContinuations[i], css::uno::UNO_QUERY ); 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir if ( ! xFOptions.is() ) 131*cdf0e10cSrcweir xFOptions = css::uno::Reference< css::document::XInteractionFilterOptions >( lContinuations[i], css::uno::UNO_QUERY ); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir // differ between abortable interactions (error, unknown filter ...) 135*cdf0e10cSrcweir // and other ones (ambigous but not unknown filter ...) 136*cdf0e10cSrcweir css::task::ErrorCodeRequest aErrorCodeRequest ; 137*cdf0e10cSrcweir css::document::AmbigousFilterRequest aAmbigousFilterRequest; 138*cdf0e10cSrcweir css::document::LockedDocumentRequest aLockedDocumentRequest; 139*cdf0e10cSrcweir css::document::FilterOptionsRequest aFilterOptionsRequest; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir if (aRequest>>=aAmbigousFilterRequest) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir if (xFilter.is()) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir // user selected filter wins everytime! 146*cdf0e10cSrcweir xFilter->setFilter( aAmbigousFilterRequest.SelectedFilter ); 147*cdf0e10cSrcweir xFilter->select(); 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir else 151*cdf0e10cSrcweir if( aRequest >>= aErrorCodeRequest ) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir // warnings can be ignored => approve 154*cdf0e10cSrcweir // errors must break loading => abort 155*cdf0e10cSrcweir sal_Bool bWarning = (aErrorCodeRequest.ErrCode & ERRCODE_WARNING_MASK) == ERRCODE_WARNING_MASK; 156*cdf0e10cSrcweir if (xApprove.is() && bWarning) 157*cdf0e10cSrcweir xApprove->select(); 158*cdf0e10cSrcweir else 159*cdf0e10cSrcweir if (xAbort.is()) 160*cdf0e10cSrcweir xAbort->select(); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir else 163*cdf0e10cSrcweir if( aRequest >>= aLockedDocumentRequest ) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir // the locked document should be opened readonly by default 166*cdf0e10cSrcweir if (xApprove.is()) 167*cdf0e10cSrcweir xApprove->select(); 168*cdf0e10cSrcweir else 169*cdf0e10cSrcweir if (xAbort.is()) 170*cdf0e10cSrcweir xAbort->select(); 171*cdf0e10cSrcweir } 172*cdf0e10cSrcweir else 173*cdf0e10cSrcweir if (aRequest>>=aFilterOptionsRequest) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir if (xFOptions.is()) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir // let the default filter options be used 178*cdf0e10cSrcweir xFOptions->select(); 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir else 182*cdf0e10cSrcweir if (xAbort.is()) 183*cdf0e10cSrcweir xAbort->select(); 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir css::uno::Any QuietInteraction::getRequest() const 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir /* SAFE { */ 191*cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 192*cdf0e10cSrcweir return m_aRequest; 193*cdf0e10cSrcweir /* } SAFE */ 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir sal_Bool QuietInteraction::wasUsed() const 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir /* SAFE { */ 201*cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 202*cdf0e10cSrcweir return m_aRequest.hasValue(); 203*cdf0e10cSrcweir /* } SAFE */ 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir } // namespace framework 207