1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: QuietInteraction.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 #include "interaction/quietinteraction.hxx"
36 //_________________________________________________________________________________________________________________
38 //_________________________________________________________________________________________________________________
39 #include <threadhelp/readguard.hxx>
40 #include <threadhelp/writeguard.hxx>
41 #include <macros/generic.hxx>
42 #include <macros/debug.hxx>
44 //_________________________________________________________________________________________________________________
46 //_________________________________________________________________________________________________________________
47 #include <com/sun/star/task/XInteractionAbort.hpp>
48 #include <com/sun/star/task/XInteractionApprove.hpp>
49 #include <com/sun/star/document/XInteractionFilterSelect.hpp>
50 #include <com/sun/star/document/AmbigousFilterRequest.hpp>
51 #include <com/sun/star/task/ErrorCodeRequest.hpp>
53 #ifndef _COM_SUN_STAR_DOCUMENT_LOCKEDDOCUMENTREQUEST_HPP_
54 #include <com/sun/star/document/LockedDocumentRequest.hpp>
57 //_________________________________________________________________________________________________________________
59 //_________________________________________________________________________________________________________________
60 #include <vcl/svapp.hxx>
63 #include <tools/errinf.hxx>
66 //_________________________________________________________________________________________________________________
68 //_________________________________________________________________________________________________________________
72 //_________________________________________________________________________________________________________________
74 //_________________________________________________________________________________________________________________
76 //_________________________________________________________________________________________________________________
77 // exported definitions
78 //_________________________________________________________________________________________________________________
80 DEFINE_XINTERFACE_2( QuietInteraction
,
82 DIRECT_INTERFACE(css::lang::XTypeProvider
) ,
83 DIRECT_INTERFACE(css::task::XInteractionHandler
) )
85 DEFINE_XTYPEPROVIDER_2( QuietInteraction
,
86 css::lang::XTypeProvider
,
87 css::task::XInteractionHandler
)
89 //_________________________________________________________________________________________________________________
91 QuietInteraction::QuietInteraction()
92 : ThreadHelpBase ( &Application::GetSolarMutex() )
93 , ::cppu::OWeakObject( )
98 //_________________________________________________________________________________________________________________
100 void SAL_CALL
QuietInteraction::handle( const css::uno::Reference
< css::task::XInteractionRequest
>& xRequest
) throw( css::uno::RuntimeException
)
102 // safe the request for outside analyzing everytime!
103 css::uno::Any aRequest
= xRequest
->getRequest();
105 WriteGuard
aWriteLock(m_aLock
);
106 m_aRequest
= aRequest
;
110 // analyze the request
111 // We need XAbort as possible continuation as minimum!
112 // An optional filter selection we can handle too.
113 css::uno::Sequence
< css::uno::Reference
< css::task::XInteractionContinuation
> > lContinuations
= xRequest
->getContinuations();
114 css::uno::Reference
< css::task::XInteractionAbort
> xAbort
;
115 css::uno::Reference
< css::task::XInteractionApprove
> xApprove
;
116 css::uno::Reference
< css::document::XInteractionFilterSelect
> xFilter
;
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
);
131 // differ between abortable interactions (error, unknown filter ...)
132 // and other ones (ambigous but not unknown filter ...)
133 css::task::ErrorCodeRequest aErrorCodeRequest
;
134 css::document::AmbigousFilterRequest aAmbigousFilterRequest
;
135 css::document::LockedDocumentRequest aLockedDocumentRequest
;
137 if (aRequest
>>=aAmbigousFilterRequest
)
141 // user selected filter wins everytime!
142 xFilter
->setFilter( aAmbigousFilterRequest
.SelectedFilter
);
147 if( aRequest
>>= aErrorCodeRequest
)
149 // warnings can be ignored => approve
150 // errors must break loading => abort
151 sal_Bool bWarning
= (aErrorCodeRequest
.ErrCode
& ERRCODE_WARNING_MASK
) == ERRCODE_WARNING_MASK
;
152 if (xApprove
.is() && bWarning
)
159 if( aRequest
>>= aLockedDocumentRequest
)
161 // the locked document should be opened readonly by default
173 //_________________________________________________________________________________________________________________
175 css::uno::Any
QuietInteraction::getRequest() const
178 ReadGuard
aReadLock(m_aLock
);
183 //_________________________________________________________________________________________________________________
185 sal_Bool
QuietInteraction::wasUsed() const
188 ReadGuard
aReadLock(m_aLock
);
189 return m_aRequest
.hasValue();
193 } // namespace framework