sfx2/source/doc/objmisc.cxx | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
New commits: commit 61458a1b2221efc217778dcf3fb5764ed75f1474 Author: Henry Castro <hcas...@collabora.com> AuthorDate: Wed Sep 6 10:30:27 2023 -0400 Commit: Henry Castro <hcas...@collabora.com> CommitDate: Fri Sep 15 16:07:07 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> diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx index 6b86e2163ccb..57698b41f82e 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> @@ -1093,6 +1094,51 @@ 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 = + SfxItemSet::GetItem<SfxStringItem>(pMedium->GetItemSet(), + SID_FILTER_NAME, false)) + aFilterName = pFilterNameItem->GetValue(); + + OUString aFileName; + if (const SfxStringItem* pFileNameItem = + SfxItemSet::GetItem<SfxStringItem>(pMedium->GetItemSet(), + SID_FILE_NAME, false)) + { + const INetURLObject aURL( pFileNameItem->GetValue() ); + aFileName = aURL.getBase(INetURLObject::LAST_SEGMENT, true, + INetURLObject::DecodeMechanism::WithCharset); + } + + if (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; }