diff options
author | Henry Castro <hcastro@collabora.com> | 2023-09-06 10:30:27 -0400 |
---|---|---|
committer | Henry Castro <hcastro@collabora.com> | 2023-10-09 19:52:30 +0200 |
commit | 0855520cced8662ba0a8cfdaccbe55a812b13c60 (patch) | |
tree | 6fc84f5e0f225a03cfae0125bbf6e72cde19d8e2 | |
parent | cf17d5384cc8e254684bc1423176ad8562d49bee (diff) |
sfx2: invoke handler "LoadReadOnlyRequest"
It will ask the user if open the Excel documents "read only"
Signed-off-by: Henry Castro <hcastro@collabora.com>
Change-Id: I909fb39709198e02496f8c522f477c077fb875e5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156624
Reviewed-by: Ashod Nakashian <ash@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157730
Tested-by: Jenkins
-rw-r--r-- | sfx2/source/doc/objmisc.cxx | 49 |
1 files changed, 49 insertions, 0 deletions
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; } |