summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorPranam Lashkari <lpranam@collabora.com>2021-09-15 23:39:32 +0530
committerMiklos Vajna <vmiklos@collabora.com>2021-10-22 16:54:20 +0200
commitd05c69a892535b910943fe98fbce42f5cc860aa4 (patch)
tree10dfcfc58a5456627821d3903f7c013a8f585e6c /sfx2
parent6c9909dee4b06948ca6932397caa338d77ec7290 (diff)
LOK: unify freemium APIs and uno command restriction APIs
Conflicts: include/LibreOfficeKit/LibreOfficeKit.hxx sfx2/source/control/unoctitm.cxx Change-Id: I3badb038822331ab5cb30df6a66ce9a0640cf340 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124047 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/control/unoctitm.cxx40
-rw-r--r--sfx2/source/view/lokhelper.cxx17
2 files changed, 26 insertions, 31 deletions
diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx
index 5b55a4d75b75..eecf6fabead3 100644
--- a/sfx2/source/control/unoctitm.cxx
+++ b/sfx2/source/control/unoctitm.cxx
@@ -49,6 +49,7 @@
#include <vcl/svapp.hxx>
#include <vcl/uitest/logger.hxx>
#include <boost/property_tree/json_parser.hpp>
+#include <tools/json_writer.hxx>
#include <sfx2/app.hxx>
#include <unoctitm.hxx>
@@ -515,6 +516,17 @@ void collectUIInformation(const util::URL& rURL, const css::uno::Sequence< css::
}
}
+static void lcl_BlockCommand(const rtl::OUString& command, const rtl::OUString& kind)
+{
+ tools::JsonWriter aTree;
+ aTree.put("code", "");
+ aTree.put("kind", kind);
+ aTree.put("cmd", command);
+ aTree.put("message", "Blocked feature");
+ aTree.put("viewID", SfxViewShell::Current()->GetViewShellId().get());
+
+ SfxViewShell::Current()->libreOfficeKitViewCallback(LOK_CALLBACK_ERROR, aTree.extractData());
+}
void SfxDispatchController_Impl::dispatch( const css::util::URL& aURL,
const css::uno::Sequence< css::beans::PropertyValue >& aArgs,
@@ -529,34 +541,18 @@ void SfxDispatchController_Impl::dispatch( const css::util::URL& aURL,
SolarMutexGuard aGuard;
if (comphelper::LibreOfficeKit::isActive() &&
- SfxViewShell::Current()->isFreemiumView() &&
- comphelper::LibreOfficeKit::isCommandFreemiumDenied(aURL.Complete))
+ SfxViewShell::Current()->isRestrictedView() &&
+ comphelper::LibreOfficeKit::isRestrictedCommand(aURL.Complete))
{
- tools::JsonWriter aJson;
- aJson.put("code", "");
- aJson.put("kind", "freemiumdeny");
- aJson.put("cmd", aURL.Complete);
- aJson.put("message", "Blocked Freemium feature");
- aJson.put("viewID", SfxViewShell::Current()->GetViewShellId().get());
-
- SfxViewShell::Current()->libreOfficeKitViewCallback(LOK_CALLBACK_ERROR, aJson.extractAsOString().getStr());
+ lcl_BlockCommand(aURL.Complete, "restricted");
return;
}
if (comphelper::LibreOfficeKit::isActive() &&
- SfxViewShell::Current()->isRestrictedView() &&
- comphelper::LibreOfficeKit::isRestrictedCommand(aURL.Complete))
+ SfxViewShell::Current()->isFreemiumView() &&
+ comphelper::LibreOfficeKit::isCommandFreemiumDenied(aURL.Complete))
{
- boost::property_tree::ptree aTree;
- aTree.put("code", "");
- aTree.put("kind", "restricted");
- aTree.put("cmd", aURL.Complete);
- aTree.put("message", "Blocked restricted feature");
- aTree.put("viewID", SfxViewShell::Current()->GetViewShellId().get());
-
- std::stringstream aStream;
- boost::property_tree::write_json(aStream, aTree);
- SfxViewShell::Current()->libreOfficeKitViewCallback(LOK_CALLBACK_ERROR, aStream.str().c_str());
+ lcl_BlockCommand(aURL.Complete, "freemiumdeny");
return;
}
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index beafa3fa437c..80fd65e45f7f 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -739,21 +739,20 @@ void SfxLokHelper::postKeyEventAsync(const VclPtr<vcl::Window> &xWindow,
postEventAsync(pLOKEv);
}
-void SfxLokHelper::setFreemiumView(int nViewId, bool isFreemium)
+void SfxLokHelper::setBlockedCommandView(int nViewId, const OUString& type, bool isBlocked)
{
+ OUString aType = type;
SfxViewShell* pViewShell = SfxLokHelper::getViewOfId(nViewId);
if(pViewShell)
- pViewShell->setFreemiumView(isFreemium);
+ {
+ if(aType == "freemium")
+ pViewShell->setFreemiumView(isBlocked);
+ else
+ pViewShell->setRestrictedView(isBlocked);
+ }
}
-void SfxLokHelper::setRestrictedView(int nViewId, bool isRestricted)
-{
- SfxViewShell* pViewShell = SfxLokHelper::getViewOfId(nViewId);
-
- if(pViewShell)
- pViewShell->setRestrictedView(isRestricted);
-}
void SfxLokHelper::postExtTextEventAsync(const VclPtr<vcl::Window> &xWindow,
int nType, const OUString &rText)
{