bump product version to 5.0.4.1
[LibreOffice.git] / comphelper / source / misc / stillreadwriteinteraction.cxx
blob1ad24fa2fed2dde9522b561b26816a734ea97440
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 <comphelper/stillreadwriteinteraction.hxx>
22 #include <com/sun/star/ucb/InteractiveIOException.hpp>
24 #include <com/sun/star/task/XInteractionAbort.hpp>
26 #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
28 namespace comphelper{
30 StillReadWriteInteraction::StillReadWriteInteraction(const css::uno::Reference< css::task::XInteractionHandler >& xHandler)
31 : m_bUsed (false)
32 , m_bHandledByMySelf (false)
33 , m_bHandledByInternalHandler(false)
35 ::std::vector< ::ucbhelper::InterceptedInteraction::InterceptedRequest > lInterceptions;
36 ::ucbhelper::InterceptedInteraction::InterceptedRequest aInterceptedRequest;
38 aInterceptedRequest.Handle = HANDLE_INTERACTIVEIOEXCEPTION;
39 aInterceptedRequest.Request <<= css::ucb::InteractiveIOException();
40 aInterceptedRequest.Continuation = cppu::UnoType<css::task::XInteractionAbort>::get();
41 aInterceptedRequest.MatchExact = false;
42 lInterceptions.push_back(aInterceptedRequest);
44 aInterceptedRequest.Handle = HANDLE_UNSUPPORTEDDATASINKEXCEPTION;
45 aInterceptedRequest.Request <<= css::ucb::UnsupportedDataSinkException();
46 aInterceptedRequest.Continuation = cppu::UnoType<css::task::XInteractionAbort>::get();
47 aInterceptedRequest.MatchExact = false;
48 lInterceptions.push_back(aInterceptedRequest);
50 setInterceptedHandler(xHandler);
51 setInterceptions(lInterceptions);
54 void StillReadWriteInteraction::resetInterceptions()
56 setInterceptions(::std::vector< ::ucbhelper::InterceptedInteraction::InterceptedRequest >());
59 void StillReadWriteInteraction::resetErrorStates()
61 m_bUsed = false;
62 m_bHandledByMySelf = false;
63 m_bHandledByInternalHandler = false;
67 ucbhelper::InterceptedInteraction::EInterceptionState StillReadWriteInteraction::intercepted(const ::ucbhelper::InterceptedInteraction::InterceptedRequest& aRequest,
68 const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& xRequest)
70 // we are used!
71 m_bUsed = true;
73 // check if it's a real interception - might some parameters are not the right ones ...
74 bool bAbort = false;
75 switch(aRequest.Handle)
77 case HANDLE_INTERACTIVEIOEXCEPTION:
79 css::ucb::InteractiveIOException exIO;
80 xRequest->getRequest() >>= exIO;
81 bAbort = (
82 (exIO.Code == css::ucb::IOErrorCode_ACCESS_DENIED )
83 || (exIO.Code == css::ucb::IOErrorCode_LOCKING_VIOLATION )
84 || (exIO.Code == css::ucb::IOErrorCode_NOT_EXISTING )
85 #ifdef MACOSX
86 // this is a workaround for MAC, on this platform if the file is locked
87 // the returned error code looks to be wrong
88 || (exIO.Code == css::ucb::IOErrorCode_GENERAL )
89 #endif
92 break;
94 case HANDLE_UNSUPPORTEDDATASINKEXCEPTION:
96 bAbort = true;
98 break;
101 // handle interaction by ourself
102 if (bAbort)
104 m_bHandledByMySelf = true;
105 css::uno::Reference< css::task::XInteractionContinuation > xAbort = ::ucbhelper::InterceptedInteraction::extractContinuation(
106 xRequest->getContinuations(),
107 cppu::UnoType<css::task::XInteractionAbort>::get() );
108 if (!xAbort.is())
109 return ::ucbhelper::InterceptedInteraction::E_NO_CONTINUATION_FOUND;
110 xAbort->select();
111 return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
114 // Otherwhise use internal handler.
115 if (m_xInterceptedHandler.is())
117 m_bHandledByInternalHandler = true;
118 m_xInterceptedHandler->handle(xRequest);
120 return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */