summaryrefslogtreecommitdiff
path: root/desktop/source/lib/lokinteractionhandler.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'desktop/source/lib/lokinteractionhandler.cxx')
-rw-r--r--desktop/source/lib/lokinteractionhandler.cxx107
1 files changed, 102 insertions, 5 deletions
diff --git a/desktop/source/lib/lokinteractionhandler.cxx b/desktop/source/lib/lokinteractionhandler.cxx
index 1d20b0219e28..50a79721ff69 100644
--- a/desktop/source/lib/lokinteractionhandler.cxx
+++ b/desktop/source/lib/lokinteractionhandler.cxx
@@ -19,14 +19,28 @@
#include "lokinteractionhandler.hxx"
+#include <rtl/ref.hxx>
#include <cppuhelper/supportsservice.hxx>
+#include <com/sun/star/task/XInteractionAbort.hpp>
#include <com/sun/star/task/XInteractionApprove.hpp>
+#include <com/sun/star/task/XInteractionPassword2.hpp>
+#include <com/sun/star/task/DocumentPasswordRequest2.hpp>
+
+#define LOK_USE_UNSTABLE_API
+#include <../../inc/lib/init.hxx>
+
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
using namespace com::sun::star;
-LOKInteractionHandler::LOKInteractionHandler(uno::Reference<uno::XComponentContext> const & /*rxContext*/)
+LOKInteractionHandler::LOKInteractionHandler(
+ uno::Reference<uno::XComponentContext> const & /*rxContext*/,
+ desktop::LibLibreOffice_Impl *const pLOKit)
+ : m_pLOKit(pLOKit)
+ , m_usePassword(false)
{
+ assert(m_pLOKit);
}
LOKInteractionHandler::~LOKInteractionHandler()
@@ -58,15 +72,84 @@ void SAL_CALL LOKInteractionHandler::initialize(uno::Sequence<uno::Any> const &
{
}
-void SAL_CALL LOKInteractionHandler::handle(uno::Reference<task::XInteractionRequest> const & rRequest) throw (uno::RuntimeException, std::exception)
+void SAL_CALL LOKInteractionHandler::handle(
+ uno::Reference<task::XInteractionRequest> const & xRequest)
+throw (uno::RuntimeException, std::exception)
{
// just do the same thing in both cases
- handleInteractionRequest(rRequest);
+ handleInteractionRequest(xRequest);
}
-sal_Bool SAL_CALL LOKInteractionHandler::handleInteractionRequest(const uno::Reference<task::XInteractionRequest >& rRequest) throw ( uno::RuntimeException, std::exception )
+sal_Bool SAL_CALL LOKInteractionHandler::handleInteractionRequest(
+ const uno::Reference<task::XInteractionRequest>& xRequest)
+throw (uno::RuntimeException, std::exception)
{
- uno::Sequence<uno::Reference<task::XInteractionContinuation>> const &rContinuations = rRequest->getContinuations();
+ uno::Sequence<uno::Reference<task::XInteractionContinuation>> const &rContinuations = xRequest->getContinuations();
+
+ uno::Any const request(xRequest->getRequest());
+ task::DocumentPasswordRequest2 passwordRequest;
+ if (request >>= passwordRequest)
+ {
+ if (m_pLOKit->hasOptionalFeature((passwordRequest.IsRequestPasswordToModify)
+ ? LOK_FEATURE_DOCUMENT_PASSWORD_TO_MODIFY
+ : LOK_FEATURE_DOCUMENT_PASSWORD))
+ {
+ OString const url(passwordRequest.Name.toUtf8());
+ m_pLOKit->mpCallback(passwordRequest.IsRequestPasswordToModify
+ ? LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY
+ : LOK_CALLBACK_DOCUMENT_PASSWORD,
+ url.getStr(),
+ m_pLOKit->mpCallbackData);
+
+ // block until SetPassword is called
+ m_havePassword.wait();
+ m_havePassword.reset();
+ }
+
+ for (sal_Int32 i = 0; i < rContinuations.getLength(); ++i)
+ {
+ if (m_usePassword)
+ {
+ if (passwordRequest.IsRequestPasswordToModify)
+ {
+ uno::Reference<task::XInteractionPassword2> const xIPW2(
+ rContinuations[i], uno::UNO_QUERY);
+ xIPW2->setPasswordToModify(m_Password);
+ xIPW2->select();
+ }
+ else
+ {
+ uno::Reference<task::XInteractionPassword> const xIPW(
+ rContinuations[i], uno::UNO_QUERY);
+ if (xIPW.is())
+ {
+ xIPW->setPassword(m_Password);
+ xIPW->select();
+ }
+ }
+ }
+ else
+ {
+ if (passwordRequest.IsRequestPasswordToModify)
+ {
+ uno::Reference<task::XInteractionPassword2> const xIPW2(
+ rContinuations[i], uno::UNO_QUERY);
+ xIPW2->setRecommendReadOnly(true);
+ xIPW2->select();
+ }
+ else
+ {
+ uno::Reference<task::XInteractionAbort> const xAbort(
+ rContinuations[i], uno::UNO_QUERY);
+ if (xAbort.is())
+ {
+ xAbort->select();
+ }
+ }
+ }
+ }
+ return sal_True;
+ }
// TODO: add LOK api that allows handling this for real, for the moment we
// just set the interaction as 'Approved'
@@ -80,4 +163,18 @@ sal_Bool SAL_CALL LOKInteractionHandler::handleInteractionRequest(const uno::Ref
return sal_True;
}
+void LOKInteractionHandler::SetPassword(char const*const pPassword)
+{
+ if (pPassword)
+ {
+ m_Password = OUString(pPassword, strlen(pPassword), RTL_TEXTENCODING_UTF8);
+ m_usePassword = true;
+ }
+ else
+ {
+ m_usePassword = false;
+ }
+ m_havePassword.set();
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */