/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #include "lokinteractionhandler.hxx" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "../../inc/lib/init.hxx" #include #include #include #include #include #include using namespace com::sun::star; LOKInteractionHandler::LOKInteractionHandler( OString command, desktop::LibLibreOffice_Impl *const pLOKit, desktop::LibLODocument_Impl *const pLOKDocument) : m_pLOKit(pLOKit) , m_pLOKDocument(pLOKDocument) , m_command(std::move(command)) , m_usePassword(false) { assert(m_pLOKit); } LOKInteractionHandler::~LOKInteractionHandler() { } OUString SAL_CALL LOKInteractionHandler::getImplementationName() { return "com.sun.star.comp.uui.LOKInteractionHandler"; } sal_Bool SAL_CALL LOKInteractionHandler::supportsService(OUString const & rServiceName) { return cppu::supportsService(this, rServiceName); } uno::Sequence< OUString > SAL_CALL LOKInteractionHandler::getSupportedServiceNames() { return { "com.sun.star.task.InteractionHandler", // added to indicate support for configuration.backend.MergeRecoveryRequest "com.sun.star.configuration.backend.InteractionHandler", // for backwards compatibility "com.sun.star.uui.InteractionHandler" }; } void SAL_CALL LOKInteractionHandler::initialize(uno::Sequence const & /*rArguments*/) { } void SAL_CALL LOKInteractionHandler::handle( uno::Reference const & xRequest) { // just do the same thing in both cases handleInteractionRequest(xRequest); } void LOKInteractionHandler::postError(css::task::InteractionClassification classif, const char* kind, ErrCode code, const OUString &message) { std::string classification = "error"; switch (classif) { case task::InteractionClassification_ERROR: break; case task::InteractionClassification_WARNING: classification = "warning"; break; case task::InteractionClassification_INFO: classification = "info"; break; case task::InteractionClassification_QUERY: classification = "query"; break; default: assert(false); break; } // create the JSON representation tools::JsonWriter aJson; aJson.put("classification", classification); aJson.put("cmd", m_command.getStr()); aJson.put("kind", kind); aJson.put("code", static_cast(code)); aJson.put("message", message.toUtf8()); std::size_t nView = SfxViewShell::Current() ? SfxLokHelper::getView() : 0; if (m_pLOKDocument && m_pLOKDocument->mpCallbackFlushHandlers.count(nView)) m_pLOKDocument->mpCallbackFlushHandlers[nView]->queue(LOK_CALLBACK_ERROR, aJson.finishAndGetAsOString()); else if (m_pLOKit->mpCallback) m_pLOKit->mpCallback(LOK_CALLBACK_ERROR, aJson.finishAndGetAsOString().getStr(), m_pLOKit->mpCallbackData); } namespace { /// Just approve the interaction. void selectApproved(uno::Sequence> const &rContinuations) { for (auto const & c : rContinuations) { uno::Reference xApprove(c, uno::UNO_QUERY); if (xApprove.is()) xApprove->select(); } } } bool LOKInteractionHandler::handleIOException(const css::uno::Sequence> &rContinuations, const css::uno::Any& rRequest) { ucb::InteractiveIOException aIoException; if (!(rRequest >>= aIoException)) return false; static ErrCode const aErrorCode[int(ucb::IOErrorCode_WRONG_VERSION) + 1] = { ERRCODE_IO_ABORT, ERRCODE_IO_ACCESSDENIED, ERRCODE_IO_ALREADYEXISTS, ERRCODE_IO_BADCRC, ERRCODE_IO_CANTCREATE, ERRCODE_IO_CANTREAD, ERRCODE_IO_CANTSEEK, ERRCODE_IO_CANTTELL, ERRCODE_IO_CANTWRITE, ERRCODE_IO_CURRENTDIR, ERRCODE_IO_DEVICENOTREADY, ERRCODE_IO_NOTSAMEDEVICE, ERRCODE_IO_GENERAL, ERRCODE_IO_INVALIDACCESS, ERRCODE_IO_INVALIDCHAR, ERRCODE_IO_INVALIDDEVICE, ERRCODE_IO_INVALIDLENGTH, ERRCODE_IO_INVALIDPARAMETER, ERRCODE_IO_ISWILDCARD, ERRCODE_IO_LOCKVIOLATION, ERRCODE_IO_MISPLACEDCHAR, ERRCODE_IO_NAMETOOLONG, ERRCODE_IO_NOTEXISTS, ERRCODE_IO_NOTEXISTSPATH, ERRCODE_IO_NOTSUPPORTED, ERRCODE_IO_NOTADIRECTORY, ERRCODE_IO_NOTAFILE, ERRCODE_IO_OUTOFSPACE, ERRCODE_IO_TOOMANYOPENFILES, ERRCODE_IO_OUTOFMEMORY, ERRCODE_IO_PENDING, ERRCODE_IO_RECURSIVE, ERRCODE_IO_UNKNOWN, ERRCODE_IO_WRITEPROTECTED, ERRCODE_IO_WRONGFORMAT, ERRCODE_IO_WRONGVERSION, }; postError(aIoException.Classification, "io", aErrorCode[static_cast(aIoException.Code)], ""); selectApproved(rContinuations); return true; } bool LOKInteractionHandler::handleNetworkException(const uno::Sequence> &rContinuations, const uno::Any &rRequest) { ucb::InteractiveNetworkException aNetworkException; if (!(rRequest >>= aNetworkException)) return false; ErrCode nErrorCode; OUString aMessage; ucb::InteractiveNetworkOffLineException aOffLineException; ucb::InteractiveNetworkResolveNameException aResolveNameException; ucb::InteractiveNetworkConnectException aConnectException; ucb::InteractiveNetworkReadException aReadException; ucb::InteractiveNetworkWriteException aWriteException; if (rRequest >>= aOffLineException) { nErrorCode = ERRCODE_INET_OFFLINE; } else if (rRequest >>= aResolveNameException) { nErrorCode = ERRCODE_INET_NAME_RESOLVE; aMessage = aResolveNameException.Server; } else if (rRequest >>= aConnectException) { nErrorCode = ERRCODE_INET_CONNECT; aMessage = aConnectException.Server; } else if (rRequest >>= aReadException) { nErrorCode = ERRCODE_INET_READ; aMessage = aReadException.Diagnostic; } else if (rRequest >>= aWriteException) { nErrorCode = ERRCODE_INET_WRITE; aMessage = aWriteException.Diagnostic; } else { nErrorCode = ERRCODE_INET_GENERAL; } postError(aNetworkException.Classification, "network", nErrorCode, aMessage); selectApproved(rContinuations); return true; } bool LOKInteractionHandler::handlePasswordRequest(const uno::Sequence> &rContinuations, const uno::Any &rRequest) { bool bPasswordRequestFound = false; bool bIsRequestPasswordToModify = false; OString sUrl; task::DocumentPasswordRequest passwordRequest; if (rRequest >>= passwordRequest) { bIsRequestPasswordToModify = false; sUrl = passwordRequest.Name.toUtf8(); bPasswordRequestFound = true; } task::DocumentPasswordRequest2 passwordRequest2; if (rRequest >>= passwordRequest2) { bIsRequestPasswordToModify = passwordRequest2.IsRequestPasswordToModify; sUrl = passwordRequest2.Name.toUtf8(); bPasswordRequestFound = true; } task::DocumentMSPasswordRequest2 passwordMSRequest; if (rRequest >>= passwordMSRequest) { bIsRequestPasswordToModify = passwordMSRequest.IsRequestPasswordToModify; sUrl = passwordMSRequest.Name.toUtf8(); bPasswordRequestFound = true; } if (!bPasswordRequestFound) return false; if (m_pLOKit->mpCallback && m_pLOKit->hasOptionalFeature(bIsRequestPasswordToModify ? LOK_FEATURE_DOCUMENT_PASSWORD_TO_MODIFY : LOK_FEATURE_DOCUMENT_PASSWORD)) { // release SolarMutex, so the callback handler, which may run in another thread, // can acquire it in 'lo_setDocumentPassword' SolarMutexReleaser aReleaser; m_pLOKit->mpCallback(bIsRequestPasswordToModify ? LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY : LOK_CALLBACK_DOCUMENT_PASSWORD, sUrl.getStr(), m_pLOKit->mpCallbackData); // block until SetPassword is called m_havePassword.wait(); m_havePassword.reset(); } for (auto const & cont : rContinuations) { if (m_usePassword) { if (bIsRequestPasswordToModify) { uno::Reference const xIPW2(cont, uno::UNO_QUERY); xIPW2->setPasswordToModify(m_Password); xIPW2->select(); } else { uno::Reference const xIPW(cont, uno::UNO_QUERY); if (xIPW.is()) { xIPW->setPassword(m_Password); xIPW->select(); } } } else { if (bIsRequestPasswordToModify) { uno::Reference const xIPW2(cont, uno::UNO_QUERY); xIPW2->setRecommendReadOnly(true); xIPW2->select(); } else { uno::Reference const xAbort(cont, uno::UNO_QUERY); if (xAbort.is()) { xAbort->select(); } } } } return true; } bool LOKInteractionHandler::handleMacroConfirmationRequest(const uno::Reference& xRequest) { uno::Any const request(xRequest->getRequest()); task::DocumentMacroConfirmationRequest aConfirmRequest; if (request >>= aConfirmRequest) { auto xInteraction(task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(), nullptr)); if (xInteraction.is()) xInteraction->handleInteractionRequest(xRequest); return true; } return false; } bool LOKInteractionHandler::handlePackageReparationRequest(const uno::Reference& xRequest) { uno::Any const request(xRequest->getRequest()); document::BrokenPackageRequest aBrokenPackageRequest; if (request >>= aBrokenPackageRequest) { auto xInteraction(task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(), nullptr)); if (xInteraction.is()) xInteraction->handleInteractionRequest(xRequest); return true; } return false; } bool LOKInteractionHandler::handleLoadReadOnlyRequest(const uno::Reference& xRequest) { uno::Any const request(xRequest->getRequest()); OUString aFileName; beans::NamedValue aLoadReadOnlyRequest; if ((request >>= aLoadReadOnlyRequest) && aLoadReadOnlyRequest.Name == "LoadReadOnlyRequest" && (aLoadReadOnlyRequest.Value >>= aFileName)) { auto xInteraction(task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(), nullptr)); if (xInteraction.is()) xInteraction->handleInteractionRequest(xRequest); return true; } return false; } bool LOKInteractionHandler::handleFilterOptionsRequest(const uno::Reference& xRequest) { document::FilterOptionsRequest aFilterOptionsRequest; uno::Any const request(xRequest->getRequest()); if (request >>= aFilterOptionsRequest) { uno::Reference< task::XInteractionHandler2 > xInteraction( task::InteractionHandler::createWithParent( ::comphelper::getProcessComponentContext(), nullptr)); if (xInteraction.is()) xInteraction->handleInteractionRequest(xRequest); return true; } return false; } sal_Bool SAL_CALL LOKInteractionHandler::handleInteractionRequest( const uno::Reference& xRequest) { uno::Sequence> const &rContinuations = xRequest->getContinuations(); uno::Any const request(xRequest->getRequest()); if (handleIOException(rContinuations, request)) return true; if (handleNetworkException(rContinuations, request)) return true; if (handlePasswordRequest(rContinuations, request)) return true; if (handleFilterOptionsRequest(xRequest)) return true; if (handleMacroConfirmationRequest(xRequest)) return true; if (handlePackageReparationRequest(xRequest)) return true; if (handleLoadReadOnlyRequest(xRequest)) return true; // TODO: perform more interactions 'for real' like the above selectApproved(rContinuations); return true; } void LOKInteractionHandler::SetPassword(char const*const pPassword) { if (pPassword) { m_Password = OUString(pPassword, strlen(pPassword), RTL_TEXTENCODING_UTF8); m_usePassword = true; } else { m_usePassword = false; } m_havePassword.set(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 935b LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
AgeCommit message (Expand)Author
2015-08-11loplugin: defaultparamsNoel Grandin
2015-06-30CreateAccessible just forwards to the parent impl alreadyCaolán McNamara
2015-05-28convert PARENTCLIPMODE constants to scoped enumNoel Grandin
2015-05-25convert SHOW constants to scoped enumNoel Grandin
2015-05-20convert TEXT_DRAW constants to scoped enumNoel Grandin
2015-05-19remove setup of painting for help windows (done in ApplySettings)Tomaž Vajngerl
2015-05-18ApplySettings for dialogTomaž Vajngerl
2015-05-18refactor how font, fg. and bg. are applied in widgets/controlsTomaž Vajngerl
2015-05-14convert QUICKHELP constants to scoped enumNoel Grandin
2015-05-07refactor "HelpTextWindow" - use RenderContextTomaž Vajngerl
2015-05-05Use typed Timer::SetTimeoutHdl LinkStephan Bergmann
2015-04-29mass rewrite Paint(Rect&) to Paint(RenderContext&, Rect&)Tomaž Vajngerl
2015-04-28Merge remote-tracking branch 'origin/feature/vclptr'Michael Meeks
2015-04-20vcl: convert new to ::CreateMichael Meeks
2015-04-10vclwidget: check for calling delete on subclasses of vcl::WindowNoel Grandin
2015-04-10vclwidget: only call dispose() onceNoel Grandin
2015-04-09vcl: window destructors calling disposeNoel Grandin
2015-04-09Change tools::Time::GetSystemTicks to sal_uInt64Stephan Bergmann
2015-01-06fdo#84938: convert CTRL_STATE_ #defines to 'enum class'Noel Grandin
2014-10-01fdo#82577: Handle TimeNoel Grandin
2014-09-29loplugin: cstylecastNoel Grandin
2014-09-23fdo#82577: Handle WindowNoel Grandin
2014-08-20vcl: use enum for complex text layout constantsNoel Grandin
2014-04-02Kill superfluous vertical whitespaceTor Lillqvist
2014-02-27Removed unnecessary comment decorations and wspace from VCL sourcesChris Sherlock
2014-02-26Removed unnecessary comment decorations from VCL sourcesChris Sherlock
2014-02-26Remove visual noise from vclAlexander Wilms
2014-02-23Remove unneccessary commentsAlexander Wilms
2014-02-21vcl: sal_Bool -> boolStephan Bergmann
2014-02-20Remove vcl/settings.hxx from vcl/svapp.hxx and vcl/outdev.hxxTobias Lippert
2014-01-28bool improvementsStephan Bergmann
2013-09-08Related: fdo#38838 drop String::EmptyString now as wellCaolán McNamara