sfx2/source/doc/objmisc.cxx | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
New commits: commit 0855520cced8662ba0a8cfdaccbe55a812b13c60 Author: Henry Castro <hcas...@collabora.com> AuthorDate: Wed Sep 6 10:30:27 2023 -0400 Commit: Henry Castro <hcas...@collabora.com> CommitDate: Mon Oct 9 19:52:30 2023 +0200 sfx2: invoke handler "LoadReadOnlyRequest" It will ask the user if open the Excel documents "read only" Signed-off-by: Henry Castro <hcas...@collabora.com> Change-Id: I909fb39709198e02496f8c522f477c077fb875e5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156624 Reviewed-by: Ashod Nakashian <a...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157730 Tested-by: Jenkins diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx index 69d0ac4b3bea..123d234734f7 100644 --- a/sfx2/source/doc/objmisc.cxx +++ b/sfx2/source/doc/objmisc.cxx @@ -77,6 +77,7 @@ #include <comphelper/storagehelper.hxx> #include <comphelper/documentconstants.hxx> #include <comphelper/namedvaluecollection.hxx> +#include <ucbhelper/simpleinteractionrequest.hxx> #include <officecfg/Office/Common.hxx> #include <sfx2/signaturestate.hxx> @@ -1098,6 +1099,54 @@ void SfxObjectShell::FinishedLoading( SfxLoadedFlags nFlags ) bHasName = true; // the document is loaded, so the name should already available GetTitle( SFX_TITLE_DETECT ); InitOwnModel_Impl(); + + if (IsLoadReadonly()) + { + OUString aFilterName; + if (const SfxStringItem* pFilterNameItem = + pMedium->GetItemSet().GetItem(SID_FILTER_NAME, false)) + aFilterName = pFilterNameItem->GetValue(); + + OUString aFileName; + if (const SfxStringItem* pFileNameItem = + pMedium->GetItemSet().GetItem(SID_FILE_NAME, false)) + { + const INetURLObject aURL(pFileNameItem->GetValue()); + aFileName = aURL.getBase(INetURLObject::LAST_SEGMENT, true, + INetURLObject::DecodeMechanism::WithCharset); + } + + bool bSilent = false; + if (const SfxBoolItem* pSilentNameItem = + pMedium->GetItemSet().GetItem(SID_SILENT, false)) + bSilent = pSilentNameItem->GetValue(); + + if (!bSilent && aFilterName.indexOf("Excel") != -1) + { + Reference<task::XInteractionHandler> xHandler(pMedium->GetInteractionHandler()); + if (xHandler.is()) + { + beans::NamedValue aLoadReadOnlyRequest; + aLoadReadOnlyRequest.Name = "LoadReadOnlyRequest"; + aLoadReadOnlyRequest.Value <<= aFileName; + + Any aRequest(aLoadReadOnlyRequest); + rtl::Reference<ucbhelper::SimpleInteractionRequest> xRequest + = new ucbhelper::SimpleInteractionRequest(aRequest, + ContinuationFlags::Approve | + ContinuationFlags::Disapprove); + + xHandler->handle(xRequest); + + if (xRequest->getResponse() == ContinuationFlags::Disapprove) + { + SetSecurityOptOpenReadOnly(false); + pMedium->GetItemSet().Put(SfxBoolItem(SID_DOC_READONLY, false)); + } + } + } + } + pImpl->nFlagsInProgress &= ~SfxLoadedFlags::MAINDOCUMENT; }