Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include "interaction/quietinteraction.hxx"
21 : :
22 : : #include <threadhelp/readguard.hxx>
23 : : #include <threadhelp/writeguard.hxx>
24 : : #include <macros/generic.hxx>
25 : : #include <macros/debug.hxx>
26 : :
27 : : #include <com/sun/star/task/XInteractionAbort.hpp>
28 : : #include <com/sun/star/task/XInteractionApprove.hpp>
29 : : #include <com/sun/star/document/XInteractionFilterSelect.hpp>
30 : : #include <com/sun/star/document/XInteractionFilterOptions.hpp>
31 : : #include <com/sun/star/document/AmbigousFilterRequest.hpp>
32 : : #include <com/sun/star/document/FilterOptionsRequest.hpp>
33 : : #include <com/sun/star/task/ErrorCodeRequest.hpp>
34 : :
35 : : #include <com/sun/star/document/LockedDocumentRequest.hpp>
36 : :
37 : : #include <vcl/svapp.hxx>
38 : :
39 : : #ifndef __RSC
40 : : #include <tools/errinf.hxx>
41 : : #endif
42 : :
43 : : namespace framework{
44 : :
45 [ + + ][ + - ]: 229137 : DEFINE_XINTERFACE_2( QuietInteraction ,
46 : : OWeakObject ,
47 : : DIRECT_INTERFACE(css::lang::XTypeProvider ) ,
48 : : DIRECT_INTERFACE(css::task::XInteractionHandler) )
49 : :
50 [ # # ][ # # ]: 0 : DEFINE_XTYPEPROVIDER_2( QuietInteraction ,
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
51 : : css::lang::XTypeProvider ,
52 : : css::task::XInteractionHandler )
53 : :
54 : : //_________________________________________________________________________________________________________________
55 : :
56 : 1761 : QuietInteraction::QuietInteraction()
57 [ + - ]: 1761 : : ThreadHelpBase ( &Application::GetSolarMutex() )
58 : : , ::cppu::OWeakObject( )
59 [ + - ]: 3522 : , m_aRequest ( )
60 : : {
61 : 1761 : }
62 : :
63 : : //_________________________________________________________________________________________________________________
64 : :
65 : 33 : void SAL_CALL QuietInteraction::handle( const css::uno::Reference< css::task::XInteractionRequest >& xRequest ) throw( css::uno::RuntimeException )
66 : : {
67 : : // safe the request for outside analyzing everytime!
68 [ + - ][ + - ]: 33 : css::uno::Any aRequest = xRequest->getRequest();
69 : : /* SAFE { */
70 [ + - ]: 33 : WriteGuard aWriteLock(m_aLock);
71 : 33 : m_aRequest = aRequest;
72 [ + - ]: 33 : aWriteLock.unlock();
73 : : /* } SAFE */
74 : :
75 : : // analyze the request
76 : : // We need XAbort as possible continuation as minimum!
77 : : // An optional filter selection we can handle too.
78 [ + - ][ + - ]: 33 : css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > lContinuations = xRequest->getContinuations();
79 : 33 : css::uno::Reference< css::task::XInteractionAbort > xAbort ;
80 : 33 : css::uno::Reference< css::task::XInteractionApprove > xApprove ;
81 : 33 : css::uno::Reference< css::document::XInteractionFilterSelect > xFilter ;
82 : 33 : css::uno::Reference< css::document::XInteractionFilterOptions > xFOptions ;
83 : :
84 : 33 : sal_Int32 nCount=lContinuations.getLength();
85 [ + + ]: 99 : for (sal_Int32 i=0; i<nCount; ++i)
86 : : {
87 [ + + ]: 66 : if ( ! xAbort.is() )
88 [ + - ][ + - ]: 33 : xAbort = css::uno::Reference< css::task::XInteractionAbort >( lContinuations[i], css::uno::UNO_QUERY );
[ + - ]
89 : :
90 [ + - ]: 66 : if( ! xApprove.is() )
91 [ + - ][ + - ]: 66 : xApprove = css::uno::Reference< css::task::XInteractionApprove >( lContinuations[i], css::uno::UNO_QUERY );
[ + - ]
92 : :
93 [ + - ]: 66 : if ( ! xFilter.is() )
94 [ + - ][ + - ]: 66 : xFilter = css::uno::Reference< css::document::XInteractionFilterSelect >( lContinuations[i], css::uno::UNO_QUERY );
[ + - ]
95 : :
96 [ + - ]: 66 : if ( ! xFOptions.is() )
97 [ + - ][ + - ]: 66 : xFOptions = css::uno::Reference< css::document::XInteractionFilterOptions >( lContinuations[i], css::uno::UNO_QUERY );
[ + - ]
98 : : }
99 : :
100 : : // differ between abortable interactions (error, unknown filter ...)
101 : : // and other ones (ambigous but not unknown filter ...)
102 [ + - ]: 33 : css::task::ErrorCodeRequest aErrorCodeRequest ;
103 [ + - ]: 33 : css::document::AmbigousFilterRequest aAmbigousFilterRequest;
104 [ + - ]: 33 : css::document::LockedDocumentRequest aLockedDocumentRequest;
105 [ + - ]: 33 : css::document::FilterOptionsRequest aFilterOptionsRequest;
106 : :
107 [ + - ][ - + ]: 33 : if (aRequest>>=aAmbigousFilterRequest)
108 : : {
109 [ # # ]: 0 : if (xFilter.is())
110 : : {
111 : : // user selected filter wins everytime!
112 [ # # ][ # # ]: 0 : xFilter->setFilter( aAmbigousFilterRequest.SelectedFilter );
113 [ # # ][ # # ]: 0 : xFilter->select();
114 : : }
115 : : }
116 : : else
117 [ + - ][ + - ]: 33 : if( aRequest >>= aErrorCodeRequest )
118 : : {
119 : : // warnings can be ignored => approve
120 : : // errors must break loading => abort
121 : 33 : sal_Bool bWarning = (aErrorCodeRequest.ErrCode & ERRCODE_WARNING_MASK) == ERRCODE_WARNING_MASK;
122 [ + - ][ + - ]: 33 : if (xApprove.is() && bWarning)
[ + - ]
123 [ + - ][ + - ]: 33 : xApprove->select();
124 : : else
125 [ # # ]: 0 : if (xAbort.is())
126 [ # # ][ # # ]: 0 : xAbort->select();
127 : : }
128 : : else
129 [ # # ][ # # ]: 0 : if( aRequest >>= aLockedDocumentRequest )
130 : : {
131 : : // the locked document should be opened readonly by default
132 [ # # ]: 0 : if (xApprove.is())
133 [ # # ][ # # ]: 0 : xApprove->select();
134 : : else
135 [ # # ]: 0 : if (xAbort.is())
136 [ # # ][ # # ]: 0 : xAbort->select();
137 : : }
138 : : else
139 [ # # ][ # # ]: 0 : if (aRequest>>=aFilterOptionsRequest)
140 : : {
141 [ # # ]: 0 : if (xFOptions.is())
142 : : {
143 : : // let the default filter options be used
144 [ # # ][ # # ]: 0 : xFOptions->select();
145 : : }
146 : : }
147 : : else
148 [ # # ]: 0 : if (xAbort.is())
149 [ # # ][ # # ]: 33 : xAbort->select();
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
150 : 33 : }
151 : :
152 : : //_________________________________________________________________________________________________________________
153 : :
154 : 0 : css::uno::Any QuietInteraction::getRequest() const
155 : : {
156 : : /* SAFE { */
157 [ # # ]: 0 : ReadGuard aReadLock(m_aLock);
158 [ # # ]: 0 : return m_aRequest;
159 : : /* } SAFE */
160 : : }
161 : :
162 : : //_________________________________________________________________________________________________________________
163 : :
164 : 0 : sal_Bool QuietInteraction::wasUsed() const
165 : : {
166 : : /* SAFE { */
167 [ # # ]: 0 : ReadGuard aReadLock(m_aLock);
168 [ # # ]: 0 : return m_aRequest.hasValue();
169 : : /* } SAFE */
170 : : }
171 : :
172 : : } // namespace framework
173 : :
174 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|