Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / framework / source / interaction / quietinteraction.cxx
blob490041a258ba04a06a4d16e7c673c3aa74c93eed
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <interaction/quietinteraction.hxx>
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>
29 #include <com/sun/star/document/LockedDocumentRequest.hpp>
31 #include <vcl/svapp.hxx>
33 #include <vcl/errinf.hxx>
35 namespace framework{
37 QuietInteraction::QuietInteraction()
38 : m_aRequest ( )
42 void SAL_CALL QuietInteraction::handle( const css::uno::Reference< css::task::XInteractionRequest >& xRequest )
44 // safe the request for outside analyzing every time!
45 css::uno::Any aRequest = xRequest->getRequest();
47 SolarMutexGuard g;
48 m_aRequest = aRequest;
51 // analyze the request
52 // We need XAbort as possible continuation as minimum!
53 // An optional filter selection we can handle too.
54 css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > lContinuations = xRequest->getContinuations();
55 css::uno::Reference< css::task::XInteractionAbort > xAbort;
56 css::uno::Reference< css::task::XInteractionApprove > xApprove;
57 css::uno::Reference< css::document::XInteractionFilterSelect > xFilter;
58 css::uno::Reference< css::document::XInteractionFilterOptions > xFOptions;
60 sal_Int32 nCount=lContinuations.getLength();
61 for (sal_Int32 i=0; i<nCount; ++i)
63 if ( ! xAbort.is() )
64 xAbort.set( lContinuations[i], css::uno::UNO_QUERY );
66 if( ! xApprove.is() )
67 xApprove.set( lContinuations[i], css::uno::UNO_QUERY );
69 if ( ! xFilter.is() )
70 xFilter.set( lContinuations[i], css::uno::UNO_QUERY );
72 if ( ! xFOptions.is() )
73 xFOptions.set( lContinuations[i], css::uno::UNO_QUERY );
76 // differ between abortable interactions (error, unknown filter...)
77 // and other ones (ambiguous but not unknown filter...)
78 css::task::ErrorCodeRequest aErrorCodeRequest;
79 css::document::LockedDocumentRequest aLockedDocumentRequest;
80 css::document::FilterOptionsRequest aFilterOptionsRequest;
82 if( aRequest >>= aErrorCodeRequest )
84 // warnings can be ignored => approve
85 // errors must break loading => abort
86 bool bWarning = ErrCode(aErrorCodeRequest.ErrCode).IsWarning();
87 if (xApprove.is() && bWarning)
88 xApprove->select();
89 else
90 if (xAbort.is())
91 xAbort->select();
93 else
94 if( aRequest >>= aLockedDocumentRequest )
96 // the locked document should be opened readonly by default
97 if (xApprove.is())
98 xApprove->select();
99 else
100 if (xAbort.is())
101 xAbort->select();
103 else
104 if (aRequest>>=aFilterOptionsRequest)
106 if (xFOptions.is())
108 // let the default filter options be used
109 xFOptions->select();
112 else
113 if (xAbort.is())
114 xAbort->select();
117 css::uno::Any QuietInteraction::getRequest() const
119 SolarMutexGuard g;
120 return m_aRequest;
123 bool QuietInteraction::wasUsed() const
125 SolarMutexGuard g;
126 return m_aRequest.hasValue();
129 } // namespace framework
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */