desktop/source/lib/init.cxx | 45 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-)
New commits: commit 34a952418da0411f24d98dd5f422dc58d602bd7e Author: Henry Castro <[email protected]> AuthorDate: Fri Sep 8 14:23:33 2023 -0400 Commit: Henry Castro <[email protected]> CommitDate: Fri Sep 15 16:12:11 2023 +0200 lok: add getter function to read "ReadOnly" flag Signed-off-by: Henry Castro <[email protected]> Change-Id: Id9d2bc638d0f48cb33764b07fb8976b97117a621 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156621 Reviewed-by: Ashod Nakashian <[email protected]> diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index e4d212b067b1..817062ad55fa 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -5940,6 +5940,45 @@ static void addLocale(boost::property_tree::ptree& rValues, css::lang::Locale co rValues.push_back(std::make_pair("", aChild)); } +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 = + SfxItemSet::GetItem<SfxBoolItem>(pMedium->GetItemSet(), + 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(const char* pCommand) { css::uno::Sequence< css::lang::Locale > aLocales; @@ -6311,7 +6350,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(pCommand); }
