desktop/source/lib/init.cxx | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-)
New commits: commit 4dade552c67a36f83cb419f90369722dc913d9fe Author: Henry Castro <hcas...@collabora.com> AuthorDate: Fri Sep 8 14:23:33 2023 -0400 Commit: Henry Castro <hcas...@collabora.com> CommitDate: Mon Oct 9 21:32:49 2023 +0200 lok: add getter function to read "ReadOnly" flag Signed-off-by: Henry Castro <hcas...@collabora.com> Change-Id: Id9d2bc638d0f48cb33764b07fb8976b97117a621 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156621 Reviewed-by: Ashod Nakashian <a...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157733 Tested-by: Jenkins diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index d0c3e5fe939b..52ca105d09b9 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -5968,6 +5968,44 @@ static void doc_resetSelection(LibreOfficeKitDocument* pThis) pDoc->resetSelection(); } +static char* getDocReadOnly(LibreOfficeKitDocument* pThis) +{ + LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis); + if (!pDocument) + return nullptr; + + SfxBaseModel* pBaseModel = dynamic_cast<SfxBaseModel*>(pDocument->mxComponent.get()); + if (!pBaseModel) + return nullptr; + + SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); + if (!pObjectShell) + return nullptr; + + SfxMedium* pMedium = pObjectShell->GetMedium(); + if (!pMedium) + return nullptr; + + bool bDocReadOnly = false; + if (const SfxBoolItem* pReadOnlyItem = + pMedium->GetItemSet().GetItem(SID_DOC_READONLY, false)) + bDocReadOnly = pReadOnlyItem->GetValue(); + + boost::property_tree::ptree aTree; + aTree.put("commandName", ".uno:ReadOnly"); + aTree.put("success", bDocReadOnly); + + std::stringstream aStream; + boost::property_tree::write_json(aStream, aTree); + char* pJson = static_cast<char*>(malloc(aStream.str().size() + 1)); + if (!pJson) + return nullptr; + + strcpy(pJson, aStream.str().c_str()); + pJson[aStream.str().size()] = '\0'; + return pJson; +} + static char* getLanguages(LibreOfficeKitDocument* pThis, const char* pCommand) { css::uno::Sequence< css::lang::Locale > aLocales; @@ -6345,7 +6383,11 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo return nullptr; } - if (!strcmp(pCommand, ".uno:LanguageStatus")) + if (!strcmp(pCommand, ".uno:ReadOnly")) + { + return getDocReadOnly(pThis); + } + else if (!strcmp(pCommand, ".uno:LanguageStatus")) { return getLanguages(pThis, pCommand); }