Kaydet (Commit) e449308e authored tarafından Tor Lillqvist's avatar Tor Lillqvist

Add support for progress bar callbacks to LibreOfficeKit

The libsofficeapp and LibreOfficeKit API bits.

Change-Id: I4efe9880dfa4e0387f05b50e64b5eaee448e0925
üst cec72eff
......@@ -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);
......
......@@ -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)
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment