merged tag ooo/OOO330_m14
[LibreOffice.git] / framework / source / interaction / quietinteraction.cxx
blobd5d11ebc2097d6f208329ab07d516784a0e44eff
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_framework.hxx"
31 #include "interaction/quietinteraction.hxx"
33 //_________________________________________________________________________________________________________________
34 // my own includes
35 //_________________________________________________________________________________________________________________
36 #include <threadhelp/readguard.hxx>
37 #include <threadhelp/writeguard.hxx>
38 #include <macros/generic.hxx>
39 #include <macros/debug.hxx>
41 //_________________________________________________________________________________________________________________
42 // interface includes
43 //_________________________________________________________________________________________________________________
44 #include <com/sun/star/task/XInteractionAbort.hpp>
45 #include <com/sun/star/task/XInteractionApprove.hpp>
46 #include <com/sun/star/document/XInteractionFilterSelect.hpp>
47 #include <com/sun/star/document/XInteractionFilterOptions.hpp>
48 #include <com/sun/star/document/AmbigousFilterRequest.hpp>
49 #include <com/sun/star/document/FilterOptionsRequest.hpp>
50 #include <com/sun/star/task/ErrorCodeRequest.hpp>
52 #ifndef _COM_SUN_STAR_DOCUMENT_LOCKEDDOCUMENTREQUEST_HPP_
53 #include <com/sun/star/document/LockedDocumentRequest.hpp>
54 #endif
56 //_________________________________________________________________________________________________________________
57 // other includes
58 //_________________________________________________________________________________________________________________
59 #include <vcl/svapp.hxx>
61 #ifndef __RSC
62 #include <tools/errinf.hxx>
63 #endif
65 //_________________________________________________________________________________________________________________
66 // namespace
67 //_________________________________________________________________________________________________________________
69 namespace framework{
71 //_________________________________________________________________________________________________________________
72 // exported const
73 //_________________________________________________________________________________________________________________
75 //_________________________________________________________________________________________________________________
76 // exported definitions
77 //_________________________________________________________________________________________________________________
79 DEFINE_XINTERFACE_2( QuietInteraction ,
80 OWeakObject ,
81 DIRECT_INTERFACE(css::lang::XTypeProvider ) ,
82 DIRECT_INTERFACE(css::task::XInteractionHandler) )
84 DEFINE_XTYPEPROVIDER_2( QuietInteraction ,
85 css::lang::XTypeProvider ,
86 css::task::XInteractionHandler )
88 //_________________________________________________________________________________________________________________
90 QuietInteraction::QuietInteraction()
91 : ThreadHelpBase ( &Application::GetSolarMutex() )
92 , ::cppu::OWeakObject( )
93 , m_aRequest ( )
97 //_________________________________________________________________________________________________________________
99 void SAL_CALL QuietInteraction::handle( const css::uno::Reference< css::task::XInteractionRequest >& xRequest ) throw( css::uno::RuntimeException )
101 // safe the request for outside analyzing everytime!
102 css::uno::Any aRequest = xRequest->getRequest();
103 /* SAFE { */
104 WriteGuard aWriteLock(m_aLock);
105 m_aRequest = aRequest;
106 aWriteLock.unlock();
107 /* } SAFE */
109 // analyze the request
110 // We need XAbort as possible continuation as minimum!
111 // An optional filter selection we can handle too.
112 css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > lContinuations = xRequest->getContinuations();
113 css::uno::Reference< css::task::XInteractionAbort > xAbort ;
114 css::uno::Reference< css::task::XInteractionApprove > xApprove ;
115 css::uno::Reference< css::document::XInteractionFilterSelect > xFilter ;
116 css::uno::Reference< css::document::XInteractionFilterOptions > xFOptions ;
118 sal_Int32 nCount=lContinuations.getLength();
119 for (sal_Int32 i=0; i<nCount; ++i)
121 if ( ! xAbort.is() )
122 xAbort = css::uno::Reference< css::task::XInteractionAbort >( lContinuations[i], css::uno::UNO_QUERY );
124 if( ! xApprove.is() )
125 xApprove = css::uno::Reference< css::task::XInteractionApprove >( lContinuations[i], css::uno::UNO_QUERY );
127 if ( ! xFilter.is() )
128 xFilter = css::uno::Reference< css::document::XInteractionFilterSelect >( lContinuations[i], css::uno::UNO_QUERY );
130 if ( ! xFOptions.is() )
131 xFOptions = css::uno::Reference< css::document::XInteractionFilterOptions >( lContinuations[i], css::uno::UNO_QUERY );
134 // differ between abortable interactions (error, unknown filter ...)
135 // and other ones (ambigous but not unknown filter ...)
136 css::task::ErrorCodeRequest aErrorCodeRequest ;
137 css::document::AmbigousFilterRequest aAmbigousFilterRequest;
138 css::document::LockedDocumentRequest aLockedDocumentRequest;
139 css::document::FilterOptionsRequest aFilterOptionsRequest;
141 if (aRequest>>=aAmbigousFilterRequest)
143 if (xFilter.is())
145 // user selected filter wins everytime!
146 xFilter->setFilter( aAmbigousFilterRequest.SelectedFilter );
147 xFilter->select();
150 else
151 if( aRequest >>= aErrorCodeRequest )
153 // warnings can be ignored => approve
154 // errors must break loading => abort
155 sal_Bool bWarning = (aErrorCodeRequest.ErrCode & ERRCODE_WARNING_MASK) == ERRCODE_WARNING_MASK;
156 if (xApprove.is() && bWarning)
157 xApprove->select();
158 else
159 if (xAbort.is())
160 xAbort->select();
162 else
163 if( aRequest >>= aLockedDocumentRequest )
165 // the locked document should be opened readonly by default
166 if (xApprove.is())
167 xApprove->select();
168 else
169 if (xAbort.is())
170 xAbort->select();
172 else
173 if (aRequest>>=aFilterOptionsRequest)
175 if (xFOptions.is())
177 // let the default filter options be used
178 xFOptions->select();
181 else
182 if (xAbort.is())
183 xAbort->select();
186 //_________________________________________________________________________________________________________________
188 css::uno::Any QuietInteraction::getRequest() const
190 /* SAFE { */
191 ReadGuard aReadLock(m_aLock);
192 return m_aRequest;
193 /* } SAFE */
196 //_________________________________________________________________________________________________________________
198 sal_Bool QuietInteraction::wasUsed() const
200 /* SAFE { */
201 ReadGuard aReadLock(m_aLock);
202 return m_aRequest.hasValue();
203 /* } SAFE */
206 } // namespace framework