diff options
author | Tor Lillqvist <tml@collabora.com> | 2015-05-06 16:43:33 +0300 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2015-05-06 17:55:59 +0300 |
commit | e449308e5d1c2de7e405115a737c0094fa9c5485 (patch) | |
tree | 7de800b99583a10797fb8e5f9578baf63a13c83b | |
parent | cec72eff99d1d683f2236c8a86a2814b34ad861e (diff) |
Add support for progress bar callbacks to LibreOfficeKit
The libsofficeapp and LibreOfficeKit API bits.
Change-Id: I4efe9880dfa4e0387f05b50e64b5eaee448e0925
-rw-r--r-- | desktop/source/lib/init.cxx | 45 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.h | 5 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKitEnums.h | 31 |
3 files changed, 78 insertions, 3 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 44cf2b0a9b5e..99dfbcb70262 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 e576e0a91089..7eb42e898b87 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 d4d1b4c4fc3b..aaf99be60535 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; |