diff options
author | Henry Castro <hcastro@collabora.com> | 2023-09-06 10:30:27 -0400 |
---|---|---|
committer | Henry Castro <hcastro@collabora.com> | 2023-09-15 16:07:07 +0200 |
commit | 61458a1b2221efc217778dcf3fb5764ed75f1474 (patch) | |
tree | df3e29b39f6e3a6cabb46a7c6f25aa2bdafad202 | |
parent | 7cbe8dda1c45ed770194e820c542b237c5b8aae0 (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>
-rw-r--r-- | sfx2/source/doc/objmisc.cxx | 46 |
1 files changed, 46 insertions, 0 deletions
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; } |