LibreOffice Module framework (master) 1
quietinteraction.cxx
Go to the documentation of this file.
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
21
22#include <com/sun/star/task/XInteractionAbort.hpp>
23#include <com/sun/star/task/XInteractionApprove.hpp>
24#include <com/sun/star/document/XInteractionFilterSelect.hpp>
25#include <com/sun/star/document/XInteractionFilterOptions.hpp>
26#include <com/sun/star/document/FilterOptionsRequest.hpp>
27#include <com/sun/star/task/ErrorCodeRequest.hpp>
28
29#include <com/sun/star/document/LockedDocumentRequest.hpp>
30
32#include <vcl/svapp.hxx>
33
34namespace framework{
35
37{
38}
39
40void SAL_CALL QuietInteraction::handle( const css::uno::Reference< css::task::XInteractionRequest >& xRequest )
41{
42 // safe the request for outside analyzing every time!
43 css::uno::Any aRequest = xRequest->getRequest();
44 {
46 m_aRequest = aRequest;
47 }
48
49 // analyze the request
50 // We need XAbort as possible continuation as minimum!
51 // An optional filter selection we can handle too.
52 css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > lContinuations = xRequest->getContinuations();
53 css::uno::Reference< css::task::XInteractionAbort > xAbort;
54 css::uno::Reference< css::task::XInteractionApprove > xApprove;
55 css::uno::Reference< css::document::XInteractionFilterSelect > xFilter;
56 css::uno::Reference< css::document::XInteractionFilterOptions > xFOptions;
57
58 sal_Int32 nCount=lContinuations.getLength();
59 for (sal_Int32 i=0; i<nCount; ++i)
60 {
61 if ( ! xAbort.is() )
62 xAbort.set( lContinuations[i], css::uno::UNO_QUERY );
63
64 if( ! xApprove.is() )
65 xApprove.set( lContinuations[i], css::uno::UNO_QUERY );
66
67 if ( ! xFilter.is() )
68 xFilter.set( lContinuations[i], css::uno::UNO_QUERY );
69
70 if ( ! xFOptions.is() )
71 xFOptions.set( lContinuations[i], css::uno::UNO_QUERY );
72 }
73
74 // differ between abortable interactions (error, unknown filter...)
75 // and other ones (ambiguous but not unknown filter...)
76 css::task::ErrorCodeRequest aErrorCodeRequest;
77 css::document::LockedDocumentRequest aLockedDocumentRequest;
78 css::document::FilterOptionsRequest aFilterOptionsRequest;
79
80 if( aRequest >>= aErrorCodeRequest )
81 {
82 // warnings can be ignored => approve
83 // errors must break loading => abort
84 bool bWarning = ErrCode(aErrorCodeRequest.ErrCode).IsWarning();
85 if (xApprove.is() && bWarning)
86 xApprove->select();
87 else
88 if (xAbort.is())
89 xAbort->select();
90 }
91 else
92 if( aRequest >>= aLockedDocumentRequest )
93 {
94 // the locked document should be opened readonly by default
95 if (xApprove.is())
96 xApprove->select();
97 else
98 if (xAbort.is())
99 xAbort->select();
100 }
101 else
102 if (aRequest>>=aFilterOptionsRequest)
103 {
104 if (xFOptions.is())
105 {
106 // let the default filter options be used
107 xFOptions->select();
108 }
109 }
110 else
111 if (xAbort.is())
112 xAbort->select();
113}
114
115css::uno::Any QuietInteraction::getRequest() const
116{
118 return m_aRequest;
119}
120
122{
124 return m_aRequest.hasValue();
125}
126
127} // namespace framework
128
129/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsWarning() const
css::uno::Any m_aRequest
in case an unknown interaction was aborted - we save it for our external user!
QuietInteraction()
ctor to guarantee right initialized instances of this class @threadsafe not necessary
virtual void SAL_CALL handle(const css::uno::Reference< css::task::XInteractionRequest > &xRequest) override
bool wasUsed() const
returns information if interaction was used @descr It can be useful to know the reason for a failed o...
css::uno::Any getRequest() const
return the handled interaction request @descr We saved any obtained interaction request internally.
int nCount
int i