summaryrefslogtreecommitdiff
path: root/desktop/source
diff options
context:
space:
mode:
authorHenry Castro <hcastro@collabora.com>2023-09-08 14:23:33 -0400
committerHenry Castro <hcastro@collabora.com>2023-10-09 21:32:49 +0200
commit4dade552c67a36f83cb419f90369722dc913d9fe (patch)
treefb5d7bc4460e9d2e03d5b3f1252ee76a26072990 /desktop/source
parentc3073c81223e9bf0f499d9fd3cfa8a7e8cb497a5 (diff)
lok: add getter function to read "ReadOnly" flag
Signed-off-by: Henry Castro <hcastro@collabora.com> Change-Id: Id9d2bc638d0f48cb33764b07fb8976b97117a621 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156621 Reviewed-by: Ashod Nakashian <ash@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157733 Tested-by: Jenkins
Diffstat (limited to 'desktop/source')
-rw-r--r--desktop/source/lib/init.cxx44
1 files changed, 43 insertions, 1 deletions
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);
}