[Libreoffice-commits] core.git: 6 commits - comphelper/source desktop/source framework/inc framework/source include/comphelper include/LibreOfficeKit

Tor Lillqvist tml at collabora.com
Wed May 6 07:58:03 PDT 2015


 comphelper/source/misc/lok.cxx               |   27 ++++++++++++++
 desktop/source/lib/init.cxx                  |   45 +++++++++++++++++++++++-
 framework/inc/helper/statusindicator.hxx     |    2 +
 framework/source/helper/statusindicator.cxx  |   49 +++++++++++++++------------
 include/LibreOfficeKit/LibreOfficeKit.h      |    5 ++
 include/LibreOfficeKit/LibreOfficeKitEnums.h |   31 ++++++++++++++++-
 include/comphelper/lok.hxx                   |   23 ++++++++++++
 7 files changed, 158 insertions(+), 24 deletions(-)

New commits:
commit e449308e5d1c2de7e405115a737c0094fa9c5485
Author: Tor Lillqvist <tml at collabora.com>
Date:   Wed May 6 16:43:33 2015 +0300

    Add support for progress bar callbacks to LibreOfficeKit
    
    The libsofficeapp and LibreOfficeKit API bits.
    
    Change-Id: I4efe9880dfa4e0387f05b50e64b5eaee448e0925

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 44cf2b0..99dfbcb 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -278,16 +278,21 @@ static char *                  lo_getError      (LibreOfficeKit* pThis);
 static LibreOfficeKitDocument* lo_documentLoadWithOptions  (LibreOfficeKit* pThis,
                                                            const char* pURL,
                                                            const char* pOptions);
-
+static void                    lo_registerCallback (LibreOfficeKit* pThis,
+                                                    LibreOfficeKitCallback pCallback,
+                                                    void* pData);
 
 struct LibLibreOffice_Impl : public _LibreOfficeKit
 {
     OUString maLastExceptionMsg;
     shared_ptr< LibreOfficeKitClass > m_pOfficeClass;
     oslThread maThread;
+    LibreOfficeKitCallback mpCallback;
+    void *mpCallbackData;
 
     LibLibreOffice_Impl()
-        : maThread(0)
+        : maThread(0),
+          mpCallback(nullptr)
     {
         if(!(m_pOfficeClass = gOfficeClass.lock())) {
             m_pOfficeClass.reset(new LibreOfficeKitClass);
@@ -297,6 +302,7 @@ struct LibLibreOffice_Impl : public _LibreOfficeKit
             m_pOfficeClass->documentLoad = lo_documentLoad;
             m_pOfficeClass->getError = lo_getError;
             m_pOfficeClass->documentLoadWithOptions = lo_documentLoadWithOptions;
+            m_pOfficeClass->registerCallback = lo_registerCallback;
 
             gOfficeClass = m_pOfficeClass;
         }
@@ -382,6 +388,17 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis,
 
     return NULL;
 }
+
+static void lo_registerCallback (LibreOfficeKit* pThis,
+                                 LibreOfficeKitCallback pCallback,
+                                 void* pData)
+{
+    LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
+
+    pLib->mpCallback = pCallback;
+    pLib->mpCallbackData = pData;
+}
+
 static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const char* pFormat, const char* pFilterOptions)
 {
     LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
@@ -873,6 +890,27 @@ static void lo_startmain(void*)
 
 static bool bInitialized = false;
 
+static void lo_status_indicator_callback(void *data, comphelper::LibreOfficeKit::statusIndicatorCallbackType type, int percent)
+{
+    LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(data);
+
+    if (!pLib->mpCallback)
+        return;
+
+    switch (type)
+    {
+    case comphelper::LibreOfficeKit::statusIndicatorCallbackType::Start:
+        pLib->mpCallback(LOK_CALLBACK_STATUS_INDICATOR_START, 0, pLib->mpCallbackData);
+        break;
+    case comphelper::LibreOfficeKit::statusIndicatorCallbackType::SetValue:
+        pLib->mpCallback(LOK_CALLBACK_STATUS_INDICATOR_SET_VALUE, std::to_string(percent).c_str(), pLib->mpCallbackData);
+        break;
+    case comphelper::LibreOfficeKit::statusIndicatorCallbackType::Finish:
+        pLib->mpCallback(LOK_CALLBACK_STATUS_INDICATOR_FINISH, 0, pLib->mpCallbackData);
+        break;
+    }
+}
+
 static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char* pUserProfilePath)
 {
     LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
@@ -881,6 +919,7 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
         return 1;
 
     comphelper::LibreOfficeKit::setActive();
+    comphelper::LibreOfficeKit::setStatusIndicatorCallback(lo_status_indicator_callback, pLib);
 
     if (pUserProfilePath)
         rtl::Bootstrap::set(OUString("UserInstallation"), OUString(pUserProfilePath, strlen(pUserProfilePath), RTL_TEXTENCODING_UTF8));
@@ -1016,6 +1055,8 @@ static void lo_destroy(LibreOfficeKit* pThis)
 
     SAL_INFO("lok", "LO Destroy");
 
+    comphelper::LibreOfficeKit::setStatusIndicatorCallback(0, 0);
+
     Application::Quit();
     osl_joinWithThread(pLib->maThread);
     osl_destroyThread(pLib->maThread);
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index e576e0a..7eb42e8 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -50,6 +50,11 @@ struct _LibreOfficeKitClass
     LibreOfficeKitDocument* (*documentLoadWithOptions) (LibreOfficeKit* pThis,
                                                         const char* pURL,
                                                         const char* pOptions);
+#ifdef LOK_USE_UNSTABLE_API
+    void (*registerCallback) (LibreOfficeKit* pThis,
+                              LibreOfficeKitCallback pCallback,
+                              void* pData);
+#endif
 };
 
 #define LIBREOFFICEKIT_DOCUMENT_HAS(pDoc,member) LIBREOFFICEKIT_HAS_MEMBER(LibreOfficeKitDocumentClass,member,(pDoc)->pClass->nSize)
diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h
index d4d1b4c..aaf99be 100644
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
@@ -109,7 +109,36 @@ typedef enum
      * For example, when cursor is on bold text, this callback is triggered
      * with payload: ".uno:Bold=true"
      */
-    LOK_CALLBACK_STATE_CHANGED
+    LOK_CALLBACK_STATE_CHANGED,
+
+    /**
+     * Start a "status indicator" (here restricted to a progress bar type
+     * indicator). The payload is the descriptive text (or empty). Even if
+     * there is no documentation that would promise so, we assume that de facto
+     * for a document being viewed or edited, there will be at most one status
+     * indicator, and its descriptive text will not change.
+     *
+     * Note that for the case of the progress indication during loading of a
+     * document, the status indicator callbacks will arrive to the callback
+     * registered for the LibreOfficeKit (singleton) object, not a
+     * LibreOfficeKitDocument one, because we are in the very progress of
+     * loading a docuemnt and then constructing a LibreOfficeKitDocument
+     * object.
+     */
+    LOK_CALLBACK_STATUS_INDICATOR_START,
+
+    /**
+     * Sets the numeric value of the status indicator.
+     * The payload should be a percentage, an integer between 0 and 100.
+     */
+    LOK_CALLBACK_STATUS_INDICATOR_SET_VALUE,
+
+    /**
+     * Ends the status indicator.
+     *
+     * Not necessarily ever emitted.
+     */
+    LOK_CALLBACK_STATUS_INDICATOR_FINISH
 }
 LibreOfficeKitCallbackType;
 
commit cec72eff99d1d683f2236c8a86a2814b34ad861e
Author: Tor Lillqvist <tml at collabora.com>
Date:   Wed May 6 16:32:58 2015 +0300

    Don't bother ensuring progress bar LibreOfficeKit callbacks are monotonical
    
    It can well be that the StatusIndicator code is called for multiple
    independent sections while loading some document format, and that the first
    progress is not the one that actually takes much time at all, so following
    just the progress of that would be misleading, the progress would be "stuck"
    at the highest value set by the first progress (forever, if it has gone up to
    100%).
    
    For example, when loading the odk/examples/java/DocumentHandling/
    test/test1.odt sample document, the code first calls the StatusIndicator while
    parsing the styles.xml, going from 0% to 100%. But the styles.xml is typically
    rather small. Then the code calls the StatusIndicator *again* while parsing
    the much more relevant concent.xml. For that particular document, this time
    the progress goes from 0% to 27% only, for some reason. Oh well, GIGO.
    
    Change-Id: I87bfc586a53efcbeb94924f21dd365ca63da88d7

diff --git a/framework/inc/helper/statusindicator.hxx b/framework/inc/helper/statusindicator.hxx
index 6043cf2..d52216e 100644
--- a/framework/inc/helper/statusindicator.hxx
+++ b/framework/inc/helper/statusindicator.hxx
@@ -69,8 +69,6 @@ class StatusIndicator : public  ::cppu::WeakImplHelper1< css::task::XStatusIndic
         css::uno::WeakReference< css::task::XStatusIndicatorFactory > m_xFactory;
 
         sal_Int32 m_nRange;
-        // We want the callback percentages to increase monotonically
-        int m_nLastCallbackPercent;
 
     // c++ interface
     public:
diff --git a/framework/source/helper/statusindicator.cxx b/framework/source/helper/statusindicator.cxx
index 1b76a1e..88c247e 100644
--- a/framework/source/helper/statusindicator.cxx
+++ b/framework/source/helper/statusindicator.cxx
@@ -38,7 +38,6 @@ void SAL_CALL StatusIndicator::start(const OUString& sText ,
     if (comphelper::LibreOfficeKit::isActive())
     {
         m_nRange = nRange;
-        m_nLastCallbackPercent = -1;
 
         comphelper::LibreOfficeKit::statusIndicatorStart();
         return;
@@ -103,11 +102,7 @@ void SAL_CALL StatusIndicator::setValue(sal_Int32 nValue)
     if (comphelper::LibreOfficeKit::isActive())
     {
         int nPercent = (100*nValue)/m_nRange;
-        if (nPercent > m_nLastCallbackPercent)
-        {
-            comphelper::LibreOfficeKit::statusIndicatorSetValue(nPercent);
-            m_nLastCallbackPercent = nPercent;
-        }
+        comphelper::LibreOfficeKit::statusIndicatorSetValue(nPercent);
         return;
     }
 
commit 951c986d79c4674bcd9e63e81d9dded7d2c1a2fa
Author: Tor Lillqvist <tml at collabora.com>
Date:   Wed May 6 16:31:39 2015 +0300

    Add a bit of documentation
    
    Change-Id: Ie202c072ab10783c4030af280023795e498d2523

diff --git a/include/comphelper/lok.hxx b/include/comphelper/lok.hxx
index ba4745c..704fb1f 100644
--- a/include/comphelper/lok.hxx
+++ b/include/comphelper/lok.hxx
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
 /*
  * This file is part of the LibreOffice project.
  *
@@ -12,24 +12,35 @@
 
 #include <comphelper/comphelperdllapi.h>
 
+// Interface between the LibreOfficeKit implementation called by LibreOfficeKit clients and other
+// LibreOffice code.
+
 namespace comphelper
 {
 
 namespace LibreOfficeKit
 {
 
-COMPHELPER_DLLPUBLIC void setActive();
+// Functions to be called only from the LibreOfficeKit implementation in desktop, not from other
+// places in LibreOffice code.
 
-COMPHELPER_DLLPUBLIC bool isActive();
+COMPHELPER_DLLPUBLIC void setActive();
 
 enum class statusIndicatorCallbackType { Start, SetValue, Finish };
 
 COMPHELPER_DLLPUBLIC void setStatusIndicatorCallback(void (*callback)(void *data, statusIndicatorCallbackType type, int percent), void *data);
 
-COMPHELPER_DLLPUBLIC void statusIndicatorStart();
 
-COMPHELPER_DLLPUBLIC void statusIndicatorSetValue(int percent);
+// Functions that can be called from arbitrary places in LibreOffice.
+
+// Check whether the code is running as invoked through LibreOfficeKit.
+COMPHELPER_DLLPUBLIC bool isActive();
 
+// Status indicator handling. Even if in theory there could be several status indicators active at
+// the same time, in practice there is only one at a time, so we don't handle any identification of
+// status indicator in this API.
+COMPHELPER_DLLPUBLIC void statusIndicatorStart();
+COMPHELPER_DLLPUBLIC void statusIndicatorSetValue(int percent);
 COMPHELPER_DLLPUBLIC void statusIndicatorFinish();
 
 }
commit 0145fa21f5e1825516fc0b386e820e0b1104462f
Author: Tor Lillqvist <tml at collabora.com>
Date:   Wed May 6 16:22:04 2015 +0300

    We don't use <config_features.h> any more here
    
    Change-Id: I06a382917717906a0e5fdee57e296bab407c5348

diff --git a/framework/source/helper/statusindicator.cxx b/framework/source/helper/statusindicator.cxx
index fc5ae8b..1b76a1e 100644
--- a/framework/source/helper/statusindicator.cxx
+++ b/framework/source/helper/statusindicator.cxx
@@ -17,8 +17,6 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
-#include <config_features.h>
-
 #include <comphelper/lok.hxx>
 #include <helper/statusindicator.hxx>
 
commit a00cd9025b017c86431db17ca7076f7434462fd7
Author: Tor Lillqvist <tml at collabora.com>
Date:   Wed May 6 16:18:42 2015 +0300

    Add support for progress bar callbacks to LibreOfficeKit clients
    
    The framework bits.
    
    Change-Id: I9cbd649c7766284bfcf8846d2b5e129dd2731ee8

diff --git a/framework/inc/helper/statusindicator.hxx b/framework/inc/helper/statusindicator.hxx
index e8928e2..6043cf2 100644
--- a/framework/inc/helper/statusindicator.hxx
+++ b/framework/inc/helper/statusindicator.hxx
@@ -68,6 +68,10 @@ class StatusIndicator : public  ::cppu::WeakImplHelper1< css::task::XStatusIndic
          */
         css::uno::WeakReference< css::task::XStatusIndicatorFactory > m_xFactory;
 
+        sal_Int32 m_nRange;
+        // We want the callback percentages to increase monotonically
+        int m_nLastCallbackPercent;
+
     // c++ interface
     public:
 
diff --git a/framework/source/helper/statusindicator.cxx b/framework/source/helper/statusindicator.cxx
index 307adcf..fc5ae8b 100644
--- a/framework/source/helper/statusindicator.cxx
+++ b/framework/source/helper/statusindicator.cxx
@@ -19,6 +19,7 @@
 
 #include <config_features.h>
 
+#include <comphelper/lok.hxx>
 #include <helper/statusindicator.hxx>
 
 namespace framework{
@@ -33,76 +34,91 @@ StatusIndicator::~StatusIndicator()
 }
 
 void SAL_CALL StatusIndicator::start(const OUString& sText ,
-                                           sal_Int32        nRange)
+                                     sal_Int32       nRange)
     throw(css::uno::RuntimeException, std::exception)
 {
-#if !HAVE_FEATURE_DESKTOP
-    (void) sText;
-    (void) nRange;
-#else
+    if (comphelper::LibreOfficeKit::isActive())
+    {
+        m_nRange = nRange;
+        m_nLastCallbackPercent = -1;
+
+        comphelper::LibreOfficeKit::statusIndicatorStart();
+        return;
+    }
+
     css::uno::Reference< css::task::XStatusIndicatorFactory > xFactory(m_xFactory);
     if (xFactory.is())
     {
         StatusIndicatorFactory* pFactory = static_cast<StatusIndicatorFactory*>(xFactory.get());
         pFactory->start(this, sText, nRange);
     }
-#endif
 }
 
 void SAL_CALL StatusIndicator::end()
     throw(css::uno::RuntimeException, std::exception)
 {
-#if HAVE_FEATURE_DESKTOP
+    if (comphelper::LibreOfficeKit::isActive())
+    {
+        comphelper::LibreOfficeKit::statusIndicatorFinish();
+        return;
+    }
+
     css::uno::Reference< css::task::XStatusIndicatorFactory > xFactory(m_xFactory);
     if (xFactory.is())
     {
         StatusIndicatorFactory* pFactory = static_cast<StatusIndicatorFactory*>(xFactory.get());
         pFactory->end(this);
     }
-#endif
 }
 
 void SAL_CALL StatusIndicator::reset()
     throw(css::uno::RuntimeException, std::exception)
 {
-#if HAVE_FEATURE_DESKTOP
+    if (comphelper::LibreOfficeKit::isActive())
+        return;
+
     css::uno::Reference< css::task::XStatusIndicatorFactory > xFactory(m_xFactory);
     if (xFactory.is())
     {
         StatusIndicatorFactory* pFactory = static_cast<StatusIndicatorFactory*>(xFactory.get());
         pFactory->reset(this);
     }
-#endif
 }
 
 void SAL_CALL StatusIndicator::setText(const OUString& sText)
     throw(css::uno::RuntimeException, std::exception)
 {
-#if !HAVE_FEATURE_DESKTOP
-    (void) sText;
-#else
+    if (comphelper::LibreOfficeKit::isActive())
+        return;
+
     css::uno::Reference< css::task::XStatusIndicatorFactory > xFactory(m_xFactory);
     if (xFactory.is())
     {
         StatusIndicatorFactory* pFactory = static_cast<StatusIndicatorFactory*>(xFactory.get());
         pFactory->setText(this, sText);
     }
-#endif
 }
 
 void SAL_CALL StatusIndicator::setValue(sal_Int32 nValue)
     throw(css::uno::RuntimeException, std::exception)
 {
-#if !HAVE_FEATURE_DESKTOP
-    (void) nValue;
-#else
+    if (comphelper::LibreOfficeKit::isActive())
+    {
+        int nPercent = (100*nValue)/m_nRange;
+        if (nPercent > m_nLastCallbackPercent)
+        {
+            comphelper::LibreOfficeKit::statusIndicatorSetValue(nPercent);
+            m_nLastCallbackPercent = nPercent;
+        }
+        return;
+    }
+
     css::uno::Reference< css::task::XStatusIndicatorFactory > xFactory(m_xFactory);
     if (xFactory.is())
     {
         StatusIndicatorFactory* pFactory = static_cast<StatusIndicatorFactory*>(xFactory.get());
         pFactory->setValue(this, nValue);
     }
-#endif
 }
 
 } // namespace framework
commit 44724236a014072a5a5012a9e77fb9d2a903fe1d
Author: Tor Lillqvist <tml at collabora.com>
Date:   Wed May 6 16:00:35 2015 +0300

    Add support for progress bar callbacks to LibreOfficeKit clients
    
    The comphelper::LibreOfficeKit bits. Also will need additions to the
    libsofficeapp bits in desktop and then to the StatusIndicator implementation
    in framework.
    
    Change-Id: I15c2505bbf6439c07d1956685d0a6d2a22aefc58

diff --git a/comphelper/source/misc/lok.cxx b/comphelper/source/misc/lok.cxx
index 71bc922..fc8a09d 100644
--- a/comphelper/source/misc/lok.cxx
+++ b/comphelper/source/misc/lok.cxx
@@ -27,6 +27,33 @@ bool isActive()
     return bActive;
 }
 
+static void (*pStatusIndicatorCallback)(void *data, statusIndicatorCallbackType type, int percent)(nullptr);
+static void *pStatusIndicatorCallbackData(nullptr);
+
+void setStatusIndicatorCallback(void (*callback)(void *data, statusIndicatorCallbackType type, int percent), void *data)
+{
+    pStatusIndicatorCallback = callback;
+    pStatusIndicatorCallbackData = data;
+}
+
+void statusIndicatorStart()
+{
+    if (pStatusIndicatorCallback)
+        pStatusIndicatorCallback(pStatusIndicatorCallbackData, statusIndicatorCallbackType::Start, 0);
+}
+
+void statusIndicatorSetValue(int percent)
+{
+    if (pStatusIndicatorCallback)
+        pStatusIndicatorCallback(pStatusIndicatorCallbackData, statusIndicatorCallbackType::SetValue, percent);
+}
+
+void statusIndicatorFinish()
+{
+    if (pStatusIndicatorCallback)
+        pStatusIndicatorCallback(pStatusIndicatorCallbackData, statusIndicatorCallbackType::Finish, 0);
+}
+
 } // namespace LibreOfficeKit
 
 } // namespace comphelper
diff --git a/include/comphelper/lok.hxx b/include/comphelper/lok.hxx
index 8ddfb5a..ba4745c 100644
--- a/include/comphelper/lok.hxx
+++ b/include/comphelper/lok.hxx
@@ -22,6 +22,16 @@ COMPHELPER_DLLPUBLIC void setActive();
 
 COMPHELPER_DLLPUBLIC bool isActive();
 
+enum class statusIndicatorCallbackType { Start, SetValue, Finish };
+
+COMPHELPER_DLLPUBLIC void setStatusIndicatorCallback(void (*callback)(void *data, statusIndicatorCallbackType type, int percent), void *data);
+
+COMPHELPER_DLLPUBLIC void statusIndicatorStart();
+
+COMPHELPER_DLLPUBLIC void statusIndicatorSetValue(int percent);
+
+COMPHELPER_DLLPUBLIC void statusIndicatorFinish();
+
 }
 }
 


More information about the Libreoffice-commits mailing list