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 <macros/generic.hxx>
23 :
24 : #include <com/sun/star/task/XInteractionAbort.hpp>
25 : #include <com/sun/star/task/XInteractionApprove.hpp>
26 : #include <com/sun/star/document/XInteractionFilterSelect.hpp>
27 : #include <com/sun/star/document/XInteractionFilterOptions.hpp>
28 : #include <com/sun/star/document/FilterOptionsRequest.hpp>
29 : #include <com/sun/star/task/ErrorCodeRequest.hpp>
30 :
31 : #include <com/sun/star/document/LockedDocumentRequest.hpp>
32 :
33 : #include <vcl/svapp.hxx>
34 :
35 : #ifndef __RSC
36 : #include <tools/errinf.hxx>
37 : #endif
38 :
39 : namespace framework{
40 :
41 3298 : QuietInteraction::QuietInteraction()
42 3298 : : m_aRequest ( )
43 : {
44 3298 : }
45 :
46 159 : void SAL_CALL QuietInteraction::handle( const css::uno::Reference< css::task::XInteractionRequest >& xRequest ) throw( css::uno::RuntimeException, std::exception )
47 : {
48 : // safe the request for outside analyzing every time!
49 159 : css::uno::Any aRequest = xRequest->getRequest();
50 : {
51 159 : SolarMutexGuard g;
52 159 : m_aRequest = aRequest;
53 : }
54 :
55 : // analyze the request
56 : // We need XAbort as possible continuation as minimum!
57 : // An optional filter selection we can handle too.
58 318 : css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > lContinuations = xRequest->getContinuations();
59 318 : css::uno::Reference< css::task::XInteractionAbort > xAbort;
60 318 : css::uno::Reference< css::task::XInteractionApprove > xApprove;
61 318 : css::uno::Reference< css::document::XInteractionFilterSelect > xFilter;
62 318 : css::uno::Reference< css::document::XInteractionFilterOptions > xFOptions;
63 :
64 159 : sal_Int32 nCount=lContinuations.getLength();
65 476 : for (sal_Int32 i=0; i<nCount; ++i)
66 : {
67 317 : if ( ! xAbort.is() )
68 159 : xAbort = css::uno::Reference< css::task::XInteractionAbort >( lContinuations[i], css::uno::UNO_QUERY );
69 :
70 317 : if( ! xApprove.is() )
71 317 : xApprove = css::uno::Reference< css::task::XInteractionApprove >( lContinuations[i], css::uno::UNO_QUERY );
72 :
73 317 : if ( ! xFilter.is() )
74 317 : xFilter = css::uno::Reference< css::document::XInteractionFilterSelect >( lContinuations[i], css::uno::UNO_QUERY );
75 :
76 317 : if ( ! xFOptions.is() )
77 317 : xFOptions = css::uno::Reference< css::document::XInteractionFilterOptions >( lContinuations[i], css::uno::UNO_QUERY );
78 : }
79 :
80 : // differ between abortable interactions (error, unknown filter ...)
81 : // and other ones (ambigous but not unknown filter ...)
82 318 : css::task::ErrorCodeRequest aErrorCodeRequest;
83 318 : css::document::LockedDocumentRequest aLockedDocumentRequest;
84 318 : css::document::FilterOptionsRequest aFilterOptionsRequest;
85 :
86 159 : if( aRequest >>= aErrorCodeRequest )
87 : {
88 : // warnings can be ignored => approve
89 : // errors must break loading => abort
90 158 : bool bWarning = (aErrorCodeRequest.ErrCode & ERRCODE_WARNING_MASK) == ERRCODE_WARNING_MASK;
91 158 : if (xApprove.is() && bWarning)
92 157 : xApprove->select();
93 : else
94 1 : if (xAbort.is())
95 1 : xAbort->select();
96 : }
97 : else
98 1 : if( aRequest >>= aLockedDocumentRequest )
99 : {
100 : // the locked document should be opened readonly by default
101 0 : if (xApprove.is())
102 0 : xApprove->select();
103 : else
104 0 : if (xAbort.is())
105 0 : xAbort->select();
106 : }
107 : else
108 1 : if (aRequest>>=aFilterOptionsRequest)
109 : {
110 0 : if (xFOptions.is())
111 : {
112 : // let the default filter options be used
113 0 : xFOptions->select();
114 : }
115 : }
116 : else
117 1 : if (xAbort.is())
118 160 : xAbort->select();
119 159 : }
120 :
121 1 : css::uno::Any QuietInteraction::getRequest() const
122 : {
123 1 : SolarMutexGuard g;
124 1 : return m_aRequest;
125 : }
126 :
127 1 : bool QuietInteraction::wasUsed() const
128 : {
129 1 : SolarMutexGuard g;
130 1 : return m_aRequest.hasValue();
131 : }
132 :
133 : } // namespace framework
134 :
135 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|