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 //_________________________________________________________________________________________________________________
35 //_________________________________________________________________________________________________________________
36 #include <threadhelp/readguard.hxx>
37 #include <threadhelp/writeguard.hxx>
38 #include <macros/generic.hxx>
39 #include <macros/debug.hxx>
41 //_________________________________________________________________________________________________________________
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>
56 //_________________________________________________________________________________________________________________
58 //_________________________________________________________________________________________________________________
59 #include <vcl/svapp.hxx>
62 #include <tools/errinf.hxx>
65 //_________________________________________________________________________________________________________________
67 //_________________________________________________________________________________________________________________
71 //_________________________________________________________________________________________________________________
73 //_________________________________________________________________________________________________________________
75 //_________________________________________________________________________________________________________________
76 // exported definitions
77 //_________________________________________________________________________________________________________________
79 DEFINE_XINTERFACE_2( QuietInteraction
,
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( )
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();
104 WriteGuard
aWriteLock(m_aLock
);
105 m_aRequest
= aRequest
;
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
)
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
)
145 // user selected filter wins everytime!
146 xFilter
->setFilter( aAmbigousFilterRequest
.SelectedFilter
);
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
)
163 if( aRequest
>>= aLockedDocumentRequest
)
165 // the locked document should be opened readonly by default
173 if (aRequest
>>=aFilterOptionsRequest
)
177 // let the default filter options be used
186 //_________________________________________________________________________________________________________________
188 css::uno::Any
QuietInteraction::getRequest() const
191 ReadGuard
aReadLock(m_aLock
);
196 //_________________________________________________________________________________________________________________
198 sal_Bool
QuietInteraction::wasUsed() const
201 ReadGuard
aReadLock(m_aLock
);
202 return m_aRequest
.hasValue();
206 } // namespace framework