LibreOffice Module fpicker (master) 1
fpinteraction.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
20#include "fpinteraction.hxx"
21#include <com/sun/star/ucb/InteractiveIOException.hpp>
22#include <com/sun/star/task/XInteractionAbort.hpp>
23#include <com/sun/star/task/XInteractionApprove.hpp>
24#include <com/sun/star/task/XInteractionDisapprove.hpp>
25#include <com/sun/star/task/XInteractionRetry.hpp>
26
27#include <sal/log.hxx>
28#include <utility>
29
30
31namespace svt
32{
33
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::task;
36 using namespace ::com::sun::star::ucb;
37
38 OFilePickerInteractionHandler::OFilePickerInteractionHandler( css::uno::Reference< css::task::XInteractionHandler > _xMaster )
39 :m_xMaster(std::move( _xMaster ))
40 ,m_bUsed( false )
41 ,m_eInterceptions( OFilePickerInteractionHandler::E_NOINTERCEPTION )
42 {
43 SAL_WARN_IF( !m_xMaster.is(), "fpicker.office", "OFilePickerInteractionHandler::OFilePickerInteractionHandler: invalid master handler!" );
44 }
45
46
48 {
49 }
50
51
52 void SAL_CALL OFilePickerInteractionHandler::handle( const Reference< XInteractionRequest >& _rxRequest )
53 {
54 if (!_rxRequest.is())
55 return;
56
57 m_bUsed = true;
58
59 // extract some generic continuations ... might we need it later
60 // if something goes wrong.
61 Reference< XInteractionAbort > xAbort;
62 Reference< XInteractionApprove > xApprove;
63 Reference< XInteractionDisapprove > xDisapprove;
64 Reference< XInteractionRetry > xRetry;
65
66 const Sequence< Reference< XInteractionContinuation > > lConts = _rxRequest->getContinuations();
67 for (const Reference< XInteractionContinuation >& rCont : lConts)
68 {
69 if (!xAbort.is())
70 xAbort.set(rCont, UNO_QUERY);
71 if (!xApprove.is())
72 xApprove.set(rCont, UNO_QUERY);
73 if (!xDisapprove.is())
74 xDisapprove.set(rCont, UNO_QUERY);
75 if (!xRetry.is())
76 xRetry.set(rCont, UNO_QUERY);
77 }
78
79 // safe the original request for later analyzing!
80 m_aException = _rxRequest->getRequest();
81
82 // intercept some interesting interactions
83
84 // The "does not exist" interaction will be suppressed here completely.
86 {
87 InteractiveIOException aIoException;
88 if (
89 (m_aException >>= aIoException ) &&
90 (IOErrorCode_NOT_EXISTING == aIoException.Code)
91 )
92 {
93 if (xAbort.is())
94 xAbort->select();
95 return;
96 }
97 }
98
99 // no master => abort this operation ...
100 if (!m_xMaster.is())
101 {
102 if (xAbort.is())
103 xAbort->select();
104 return;
105 }
106
107 // forward it to our master - so he can handle all
108 // not interesting interactions :-)
109 m_xMaster->handle(_rxRequest);
110 }
111
112
114 {
115 m_eInterceptions = eInterceptions;
116 }
117
118
120 {
121 m_bUsed = false;
122 }
123
124
126 {
127 m_aException = Any();
128 }
129
130
132 {
133 InteractiveIOException aIoException;
134 return (m_aException >>= aIoException ) &&
135 (IOErrorCode_ACCESS_DENIED == aIoException.Code);
136 }
137
138
139} // namespace svt
140
141
142/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
an InteractionHandler implementation which extends another handler with some customizability
OFilePickerInteractionHandler(css::uno::Reference< css::task::XInteractionHandler > _xMaster)
void enableInterceptions(EInterceptedInteractions eInterceptions)
virtual void SAL_CALL handle(const css::uno::Reference< css::task::XInteractionRequest > &_rxRequest) override
css::uno::Reference< css::task::XInteractionHandler > m_xMaster
virtual ~OFilePickerInteractionHandler() override
EInterceptedInteractions m_eInterceptions
EInterceptedInteractions
flags, which indicates special handled interactions These values will be used combined as flags - so ...
#define SAL_WARN_IF(condition, area, stream)