[Libreoffice-commits] core.git: desktop/source include/LibreOfficeKit

Tor Lillqvist tml at collabora.com
Wed Apr 8 13:27:42 PDT 2015


 desktop/source/lib/init.cxx                 |   21 +++++++++++++---
 include/LibreOfficeKit/LibreOfficeKitInit.h |   36 ++++++++++++++++++++++------
 2 files changed, 46 insertions(+), 11 deletions(-)

New commits:
commit 5cc0da153e8516a11bbd3e5809e8dcaf0b0dc7d9
Author: Tor Lillqvist <tml at collabora.com>
Date:   Wed Apr 8 22:44:29 2015 +0300

    Add lok_init_2() that takes also the path to a user profile to use
    
    In some LibreOfficeKit use cases it will be useful to use a separate
    (initially empty) user profile each time, instead of whatever the default
    might turn out to be. (When using the "instdir" of a LibreOffice build tree,
    the user profile is the "instdir/user" directory.)
    
    Also add a corresponding new function to be looked up, libreofficekit_hook_2.
    
    I did not bother with any more descriptive name. After all, "lok_init" already
    is quite terse, so calling the new function "lok_init_with_user_profile" or
    something similarly verbose would in my humble opinion have been
    inconsistent. (And if/when we need to extend the LibreOfficeKit initialisation
    function with even more parameters, the name would become really long.) But
    feel free to change this if you feel like it...
    
    Make sure to stay backward-compatible with source code calling lok_init() and
    with binaries looking for only the libreofficekit_hook entry point.
    
    Change-Id: Ifa9ce8f72c2f60554fb3431d522e5784afa8d8d3

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 94c95ed..186f60b 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -268,7 +268,7 @@ static void doc_destroy(LibreOfficeKitDocument *pThis)
 }
 
 static void                    lo_destroy       (LibreOfficeKit* pThis);
-static int                     lo_initialize    (LibreOfficeKit* pThis, const char* pInstallPath);
+static int                     lo_initialize    (LibreOfficeKit* pThis, const char* pInstallPath, const char* pUserProfilePath);
 static LibreOfficeKitDocument* lo_documentLoad  (LibreOfficeKit* pThis, const char* pURL);
 static char *                  lo_getError      (LibreOfficeKit* pThis);
 static LibreOfficeKitDocument* lo_documentLoadWithOptions  (LibreOfficeKit* pThis,
@@ -839,7 +839,7 @@ static void lo_startmain(void*)
 
 static bool bInitialized = false;
 
-static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath)
+static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char* pUserProfilePath)
 {
     LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
 
@@ -848,6 +848,9 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath)
 
     comphelper::LibreOfficeKit::setActive();
 
+    if (pUserProfilePath)
+        rtl::Bootstrap::set(OUString("UserInstallation"), OUString(pUserProfilePath, strlen(pUserProfilePath), RTL_TEXTENCODING_UTF8));
+
     OUString aAppPath;
     if (pAppPath)
     {
@@ -947,14 +950,14 @@ __attribute__ ((visibility("default")))
 #else
 SAL_DLLPUBLIC_EXPORT
 #endif
-LibreOfficeKit *libreofficekit_hook(const char* install_path)
+LibreOfficeKit *libreofficekit_hook_2(const char* install_path, const char* user_profile_path)
 {
     if (!gImpl)
     {
         SAL_INFO("lok", "Create libreoffice object");
 
         gImpl = new LibLibreOffice_Impl();
-        if (!lo_initialize(gImpl, install_path))
+        if (!lo_initialize(gImpl, install_path, user_profile_path))
         {
             lo_destroy(gImpl);
         }
@@ -962,6 +965,16 @@ LibreOfficeKit *libreofficekit_hook(const char* install_path)
     return static_cast<LibreOfficeKit*>(gImpl);
 }
 
+#if defined(__GNUC__) && defined(HAVE_GCC_VISIBILITY_FEATURE) && defined(DISABLE_DYNLOADING)
+__attribute__ ((visibility("default")))
+#else
+SAL_DLLPUBLIC_EXPORT
+#endif
+LibreOfficeKit *libreofficekit_hook(const char* install_path)
+{
+    return libreofficekit_hook_2(install_path, NULL);
+}
+
 static void lo_destroy(LibreOfficeKit* pThis)
 {
     LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
diff --git a/include/LibreOfficeKit/LibreOfficeKitInit.h b/include/LibreOfficeKit/LibreOfficeKitInit.h
index fe10cd9..c0d3d5d 100644
--- a/include/LibreOfficeKit/LibreOfficeKitInit.h
+++ b/include/LibreOfficeKit/LibreOfficeKitInit.h
@@ -126,11 +126,14 @@ extern "C"
 
 typedef LibreOfficeKit *(HookFunction)( const char *install_path);
 
-static LibreOfficeKit *lok_init( const char *install_path )
+typedef LibreOfficeKit *(HookFunction2)( const char *install_path, const char *user_profile_path );
+
+static LibreOfficeKit *lok_init_2( const char *install_path,  const char *user_profile_path )
 {
     char *imp_lib;
     void *dlhandle;
     HookFunction *pSym;
+    HookFunction2 *pSym2;
 
 #if !(defined(__APPLE__) && defined(__arm__))
     size_t partial_length;
@@ -173,17 +176,36 @@ static LibreOfficeKit *lok_init( const char *install_path )
     dlhandle = RTLD_MAIN_ONLY;
 #endif
 
-    pSym = (HookFunction *) _dlsym( dlhandle, "libreofficekit_hook" );
-    if (!pSym)
+    pSym2 = (HookFunction2 *) _dlsym( dlhandle, "libreofficekit_hook_2" );
+    if (!pSym2)
     {
-        fprintf( stderr, "failed to find hook in library '%s'\n", imp_lib );
-        _dlclose( dlhandle );
+        if (user_profile_path != NULL)
+        {
+            fprintf( stderr, "the LibreOffice version in '%s' does not support passing a user profile to the hook function\n",
+                     imp_lib );
+            _dlclose( dlhandle );
+            free( imp_lib );
+            return NULL;
+        }
+        pSym = (HookFunction *) _dlsym( dlhandle, "libreofficekit_hook" );
+        if (!pSym)
+        {
+            fprintf( stderr, "failed to find hook in library '%s'\n", imp_lib );
+            _dlclose( dlhandle );
+            free( imp_lib );
+            return NULL;
+        }
         free( imp_lib );
-        return NULL;
+        return pSym( install_path );
     }
 
     free( imp_lib );
-    return pSym( install_path );
+    return pSym2( install_path, user_profile_path );
+}
+
+static LibreOfficeKit *lok_init( const char *install_path )
+{
+    return lok_init_2( install_path, NULL );
 }
 
 #undef SEPARATOR // It is used at least in enum class MenuItemType


More information about the Libreoffice-commits mailing list