1*6d739b60SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*6d739b60SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*6d739b60SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*6d739b60SAndrew Rist * distributed with this work for additional information 6*6d739b60SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*6d739b60SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*6d739b60SAndrew Rist * "License"); you may not use this file except in compliance 9*6d739b60SAndrew Rist * with the License. You may obtain a copy of the License at 10*6d739b60SAndrew Rist * 11*6d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*6d739b60SAndrew Rist * 13*6d739b60SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*6d739b60SAndrew Rist * software distributed under the License is distributed on an 15*6d739b60SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*6d739b60SAndrew Rist * KIND, either express or implied. See the License for the 17*6d739b60SAndrew Rist * specific language governing permissions and limitations 18*6d739b60SAndrew Rist * under the License. 19*6d739b60SAndrew Rist * 20*6d739b60SAndrew Rist *************************************************************/ 21*6d739b60SAndrew Rist 22*6d739b60SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_framework.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "interaction/quietinteraction.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 30cdf0e10cSrcweir // my own includes 31cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 32cdf0e10cSrcweir #include <threadhelp/readguard.hxx> 33cdf0e10cSrcweir #include <threadhelp/writeguard.hxx> 34cdf0e10cSrcweir #include <macros/generic.hxx> 35cdf0e10cSrcweir #include <macros/debug.hxx> 36cdf0e10cSrcweir 37cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 38cdf0e10cSrcweir // interface includes 39cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 40cdf0e10cSrcweir #include <com/sun/star/task/XInteractionAbort.hpp> 41cdf0e10cSrcweir #include <com/sun/star/task/XInteractionApprove.hpp> 42cdf0e10cSrcweir #include <com/sun/star/document/XInteractionFilterSelect.hpp> 43cdf0e10cSrcweir #include <com/sun/star/document/XInteractionFilterOptions.hpp> 44cdf0e10cSrcweir #include <com/sun/star/document/AmbigousFilterRequest.hpp> 45cdf0e10cSrcweir #include <com/sun/star/document/FilterOptionsRequest.hpp> 46cdf0e10cSrcweir #include <com/sun/star/task/ErrorCodeRequest.hpp> 47cdf0e10cSrcweir 48cdf0e10cSrcweir #ifndef _COM_SUN_STAR_DOCUMENT_LOCKEDDOCUMENTREQUEST_HPP_ 49cdf0e10cSrcweir #include <com/sun/star/document/LockedDocumentRequest.hpp> 50cdf0e10cSrcweir #endif 51cdf0e10cSrcweir 52cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 53cdf0e10cSrcweir // other includes 54cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 55cdf0e10cSrcweir #include <vcl/svapp.hxx> 56cdf0e10cSrcweir 57cdf0e10cSrcweir #ifndef __RSC 58cdf0e10cSrcweir #include <tools/errinf.hxx> 59cdf0e10cSrcweir #endif 60cdf0e10cSrcweir 61cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 62cdf0e10cSrcweir // namespace 63cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 64cdf0e10cSrcweir 65cdf0e10cSrcweir namespace framework{ 66cdf0e10cSrcweir 67cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 68cdf0e10cSrcweir // exported const 69cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 70cdf0e10cSrcweir 71cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 72cdf0e10cSrcweir // exported definitions 73cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 74cdf0e10cSrcweir 75cdf0e10cSrcweir DEFINE_XINTERFACE_2( QuietInteraction , 76cdf0e10cSrcweir OWeakObject , 77cdf0e10cSrcweir DIRECT_INTERFACE(css::lang::XTypeProvider ) , 78cdf0e10cSrcweir DIRECT_INTERFACE(css::task::XInteractionHandler) ) 79cdf0e10cSrcweir 80cdf0e10cSrcweir DEFINE_XTYPEPROVIDER_2( QuietInteraction , 81cdf0e10cSrcweir css::lang::XTypeProvider , 82cdf0e10cSrcweir css::task::XInteractionHandler ) 83cdf0e10cSrcweir 84cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 85cdf0e10cSrcweir 86cdf0e10cSrcweir QuietInteraction::QuietInteraction() 87cdf0e10cSrcweir : ThreadHelpBase ( &Application::GetSolarMutex() ) 88cdf0e10cSrcweir , ::cppu::OWeakObject( ) 89cdf0e10cSrcweir , m_aRequest ( ) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir } 92cdf0e10cSrcweir 93cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 94cdf0e10cSrcweir 95cdf0e10cSrcweir void SAL_CALL QuietInteraction::handle( const css::uno::Reference< css::task::XInteractionRequest >& xRequest ) throw( css::uno::RuntimeException ) 96cdf0e10cSrcweir { 97cdf0e10cSrcweir // safe the request for outside analyzing everytime! 98cdf0e10cSrcweir css::uno::Any aRequest = xRequest->getRequest(); 99cdf0e10cSrcweir /* SAFE { */ 100cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 101cdf0e10cSrcweir m_aRequest = aRequest; 102cdf0e10cSrcweir aWriteLock.unlock(); 103cdf0e10cSrcweir /* } SAFE */ 104cdf0e10cSrcweir 105cdf0e10cSrcweir // analyze the request 106cdf0e10cSrcweir // We need XAbort as possible continuation as minimum! 107cdf0e10cSrcweir // An optional filter selection we can handle too. 108cdf0e10cSrcweir css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > lContinuations = xRequest->getContinuations(); 109cdf0e10cSrcweir css::uno::Reference< css::task::XInteractionAbort > xAbort ; 110cdf0e10cSrcweir css::uno::Reference< css::task::XInteractionApprove > xApprove ; 111cdf0e10cSrcweir css::uno::Reference< css::document::XInteractionFilterSelect > xFilter ; 112cdf0e10cSrcweir css::uno::Reference< css::document::XInteractionFilterOptions > xFOptions ; 113cdf0e10cSrcweir 114cdf0e10cSrcweir sal_Int32 nCount=lContinuations.getLength(); 115cdf0e10cSrcweir for (sal_Int32 i=0; i<nCount; ++i) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir if ( ! xAbort.is() ) 118cdf0e10cSrcweir xAbort = css::uno::Reference< css::task::XInteractionAbort >( lContinuations[i], css::uno::UNO_QUERY ); 119cdf0e10cSrcweir 120cdf0e10cSrcweir if( ! xApprove.is() ) 121cdf0e10cSrcweir xApprove = css::uno::Reference< css::task::XInteractionApprove >( lContinuations[i], css::uno::UNO_QUERY ); 122cdf0e10cSrcweir 123cdf0e10cSrcweir if ( ! xFilter.is() ) 124cdf0e10cSrcweir xFilter = css::uno::Reference< css::document::XInteractionFilterSelect >( lContinuations[i], css::uno::UNO_QUERY ); 125cdf0e10cSrcweir 126cdf0e10cSrcweir if ( ! xFOptions.is() ) 127cdf0e10cSrcweir xFOptions = css::uno::Reference< css::document::XInteractionFilterOptions >( lContinuations[i], css::uno::UNO_QUERY ); 128cdf0e10cSrcweir } 129cdf0e10cSrcweir 130cdf0e10cSrcweir // differ between abortable interactions (error, unknown filter ...) 131cdf0e10cSrcweir // and other ones (ambigous but not unknown filter ...) 132cdf0e10cSrcweir css::task::ErrorCodeRequest aErrorCodeRequest ; 133cdf0e10cSrcweir css::document::AmbigousFilterRequest aAmbigousFilterRequest; 134cdf0e10cSrcweir css::document::LockedDocumentRequest aLockedDocumentRequest; 135cdf0e10cSrcweir css::document::FilterOptionsRequest aFilterOptionsRequest; 136cdf0e10cSrcweir 137cdf0e10cSrcweir if (aRequest>>=aAmbigousFilterRequest) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir if (xFilter.is()) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir // user selected filter wins everytime! 142cdf0e10cSrcweir xFilter->setFilter( aAmbigousFilterRequest.SelectedFilter ); 143cdf0e10cSrcweir xFilter->select(); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir } 146cdf0e10cSrcweir else 147cdf0e10cSrcweir if( aRequest >>= aErrorCodeRequest ) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir // warnings can be ignored => approve 150cdf0e10cSrcweir // errors must break loading => abort 151cdf0e10cSrcweir sal_Bool bWarning = (aErrorCodeRequest.ErrCode & ERRCODE_WARNING_MASK) == ERRCODE_WARNING_MASK; 152cdf0e10cSrcweir if (xApprove.is() && bWarning) 153cdf0e10cSrcweir xApprove->select(); 154cdf0e10cSrcweir else 155cdf0e10cSrcweir if (xAbort.is()) 156cdf0e10cSrcweir xAbort->select(); 157cdf0e10cSrcweir } 158cdf0e10cSrcweir else 159cdf0e10cSrcweir if( aRequest >>= aLockedDocumentRequest ) 160cdf0e10cSrcweir { 161cdf0e10cSrcweir // the locked document should be opened readonly by default 162cdf0e10cSrcweir if (xApprove.is()) 163cdf0e10cSrcweir xApprove->select(); 164cdf0e10cSrcweir else 165cdf0e10cSrcweir if (xAbort.is()) 166cdf0e10cSrcweir xAbort->select(); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir else 169cdf0e10cSrcweir if (aRequest>>=aFilterOptionsRequest) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir if (xFOptions.is()) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir // let the default filter options be used 174cdf0e10cSrcweir xFOptions->select(); 175cdf0e10cSrcweir } 176cdf0e10cSrcweir } 177cdf0e10cSrcweir else 178cdf0e10cSrcweir if (xAbort.is()) 179cdf0e10cSrcweir xAbort->select(); 180cdf0e10cSrcweir } 181cdf0e10cSrcweir 182cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 183cdf0e10cSrcweir 184cdf0e10cSrcweir css::uno::Any QuietInteraction::getRequest() const 185cdf0e10cSrcweir { 186cdf0e10cSrcweir /* SAFE { */ 187cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 188cdf0e10cSrcweir return m_aRequest; 189cdf0e10cSrcweir /* } SAFE */ 190cdf0e10cSrcweir } 191cdf0e10cSrcweir 192cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 193cdf0e10cSrcweir 194cdf0e10cSrcweir sal_Bool QuietInteraction::wasUsed() const 195cdf0e10cSrcweir { 196cdf0e10cSrcweir /* SAFE { */ 197cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 198cdf0e10cSrcweir return m_aRequest.hasValue(); 199cdf0e10cSrcweir /* } SAFE */ 200cdf0e10cSrcweir } 201cdf0e10cSrcweir 202cdf0e10cSrcweir } // namespace framework 203