connectivity/source/drivers/evoab2/EApi.cxx              |   57 +++++++++++----
 connectivity/source/drivers/evoab2/EApi.h                |    1 
 connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx |    8 --
 connectivity/source/drivers/evoab2/NResultSet.cxx        |   21 +++++
 4 files changed, 64 insertions(+), 23 deletions(-)

New commits:
commit b2983b4653339d83d3e98df4d44608f031dabe9f
Author: Mathias Hasselmann <math...@openismus.com>
Date:   Fri Mar 8 11:47:10 2013 +0100

    evoab2: Follow API changes in EDS 3.8
    
    EDS 3.8 deprecates e_book_client_new() and replaces it with various
    e_book_client_connect() functions. This patch follows the change
    and enables direct read access for the addressbook. That means
    instead of receiving contacts via the D-Bus session bus, the
    connectivity driver now directly accesses the underlaying SQLite
    data base (for reading).
    
    This patch also shuffles code in EApiInit() slightly to avoid
    excessive if/else nesting.
    
    Change-Id: If41fb92eed2ea26bbf2d3125a9ba2250f142c5a2

diff --git a/connectivity/source/drivers/evoab2/EApi.cxx 
b/connectivity/source/drivers/evoab2/EApi.cxx
index 987510c..8b7b5cd 100644
--- a/connectivity/source/drivers/evoab2/EApi.cxx
+++ b/connectivity/source/drivers/evoab2/EApi.cxx
@@ -63,7 +63,7 @@ static ApiMap aCommonApiMap[] =
     SYM_MAP( e_book_query_field_exists )
 };
 
-//< 3-6 api
+//< 3.6 api
 static ApiMap aOldApiMap[] =
 {
     SYM_MAP( e_book_get_addressbooks ),
@@ -76,7 +76,7 @@ static ApiMap aOldApiMap[] =
     SYM_MAP( e_source_group_peek_sources )
 };
 
-//>= 3-6 api
+//>= 3.6 api
 static ApiMap aNewApiMap[] =
 {
     SYM_MAP( e_source_registry_list_sources ),
@@ -87,12 +87,24 @@ static ApiMap aNewApiMap[] =
     SYM_MAP( e_source_get_display_name ),
     SYM_MAP( e_source_get_uid ),
     SYM_MAP( e_source_registry_ref_source),
-    SYM_MAP( e_book_client_new ),
     SYM_MAP( e_client_open_sync ),
     SYM_MAP( e_client_get_source ),
     SYM_MAP( e_book_client_get_contacts_sync ),
     SYM_MAP( e_client_util_free_object_slist )
 };
+
+//== indirect read access (3.6 only)
+static ApiMap aClientApiMap36[] =
+{
+    SYM_MAP( e_book_client_new )
+};
+
+//>= direct read access API (>= 3.8)
+static ApiMap aClientApiMap38[] =
+{
+    SYM_MAP( e_book_client_connect_direct_sync )
+};
+
 #undef SYM_MAP
 
 template<size_t N> static bool
@@ -122,22 +134,33 @@ bool EApiInit()
         aModule = osl_loadModule( rtl::OUString::createFromAscii
                                   ( eBookLibNames[ j ] ).pData,
                                   SAL_LOADMODULE_DEFAULT );
-        if( aModule)
+
+        if( aModule == NULL)
+            continue;
+
+        if (tryLink( aModule, eBookLibNames[ j ], aCommonApiMap))
         {
-            if (tryLink( aModule, eBookLibNames[ j ], aCommonApiMap))
+            if (eds_check_version( 3, 6, 0 ) != NULL)
+            {
+                if (tryLink( aModule, eBookLibNames[ j ], aOldApiMap))
+                    return true;
+            }
+            else if (tryLink( aModule, eBookLibNames[ j ], aNewApiMap))
             {
-                if (eds_check_version(3, 6, 0) == NULL)
+                if (eds_check_version( 3, 7, 6 ) != NULL)
                 {
-                    if (tryLink( aModule, eBookLibNames[ j ], aNewApiMap))
+                    if (tryLink( aModule, eBookLibNames[ j ], aClientApiMap36))
                         return true;
                 }
-                else if (tryLink( aModule, eBookLibNames[ j ], aOldApiMap))
+                else
                 {
-                    return true;
+                    if (tryLink( aModule, eBookLibNames[ j ], aClientApiMap38))
+                        return true;
                 }
             }
-            osl_unloadModule( aModule );
         }
+
+        osl_unloadModule( aModule );
     }
     fprintf( stderr, "Can find no compliant libebook client libraries\n" );
     return false;
diff --git a/connectivity/source/drivers/evoab2/EApi.h 
b/connectivity/source/drivers/evoab2/EApi.h
index 8d188a9..59e2c3a 100644
--- a/connectivity/source/drivers/evoab2/EApi.h
+++ b/connectivity/source/drivers/evoab2/EApi.h
@@ -147,6 +147,7 @@ EAPI_EXTERN const gchar* (*eds_check_version) (guint 
required_major, guint requi
 EAPI_EXTERN const gchar* (*e_source_get_uid) (ESource *source);
 EAPI_EXTERN ESource* (*e_source_registry_ref_source) (ESourceRegistry 
*registry, const gchar *uid);
 EAPI_EXTERN EBookClient* (*e_book_client_new) (ESource *source, GError 
**error);
+EAPI_EXTERN EBookClient* (*e_book_client_connect_direct_sync) (ESourceRegistry 
*registry, ESource *source, GCancellable *cancellable, GError **error);
 EAPI_EXTERN gboolean (*e_client_open_sync) (EClient *client, gboolean 
only_if_exists, GCancellable *cancellable, GError **error);
 EAPI_EXTERN ESource* (*e_client_get_source) (EClient *client);
 EAPI_EXTERN gboolean (*e_book_client_get_contacts_sync) (EBookClient *client, 
const gchar *sexp, GSList **contacts, GCancellable *cancellable, GError 
**error);
diff --git a/connectivity/source/drivers/evoab2/NResultSet.cxx 
b/connectivity/source/drivers/evoab2/NResultSet.cxx
index 154db40..f3a5ca3 100644
--- a/connectivity/source/drivers/evoab2/NResultSet.cxx
+++ b/connectivity/source/drivers/evoab2/NResultSet.cxx
@@ -411,7 +411,7 @@ public:
             return NULL;
 
         ESource *pSource = 
e_source_registry_ref_source(get_e_source_registry(), id);
-        EBookClient *pBook = pSource ? e_book_client_new (pSource, NULL) : 
NULL;
+        EBookClient *pBook = pSource ? createClient (pSource) : NULL;
         if (pBook && !e_client_open_sync (pBook, TRUE, NULL, NULL))
         {
             g_object_unref (G_OBJECT (pBook));
@@ -479,6 +479,21 @@ public:
         m_pContacts = g_slist_sort_with_data( m_pContacts, &CompareContacts,
             const_cast< gpointer >( static_cast< gconstpointer >( &_rCompData 
) ) );
     }
+
+protected:
+    virtual EBookClient * createClient( ESource *pSource )
+    {
+        return e_book_client_new (pSource, NULL);
+    }
+};
+
+class OEvoabVersion38Helper : public OEvoabVersion36Helper
+{
+protected:
+    virtual EBookClient * createClient( ESource *pSource )
+    {
+        return e_book_client_connect_direct_sync (get_e_source_registry (), 
pSource, NULL, NULL);
+    }
 };
 
 class OEvoabVersion35Helper : public OEvoabVersionHelper
@@ -614,7 +629,9 @@ OEvoabResultSet::OEvoabResultSet( OCommonStatement* pStmt, 
OEvoabConnection *pCo
     ,m_nIndex(-1)
     ,m_nLength(0)
 {
-    if (eds_check_version(3, 6, 0) == NULL)
+    if (eds_check_version( 3, 7, 6 ) == NULL)
+        m_pVersionHelper  = new OEvoabVersion38Helper;
+    else if (eds_check_version( 3, 6, 0 ) == NULL)
         m_pVersionHelper  = new OEvoabVersion36Helper;
     else
         m_pVersionHelper  = new OEvoabVersion35Helper;
commit c20518286c5599a3a649f06450838490382f93fc
Author: Mathias Hasselmann <math...@openismus.com>
Date:   Fri Mar 8 13:03:12 2013 +0100

    evoab2: Move get_e_source_registry() to EApi.cxx
    
    get_e_source_registry() was declared in EApi.hxx, but defined in
    NDatabaseMetaData.cxx. This doesn't seem right, the header file
    and the purpose of the function indicate that it belongs into
    EApi.cxx.
    
    Change-Id: Iea3f11a901398aa3f467b96fbe8778c403887bcb

diff --git a/connectivity/source/drivers/evoab2/EApi.cxx 
b/connectivity/source/drivers/evoab2/EApi.cxx
index 8e0d0db..987510c 100644
--- a/connectivity/source/drivers/evoab2/EApi.cxx
+++ b/connectivity/source/drivers/evoab2/EApi.cxx
@@ -143,4 +143,12 @@ bool EApiInit()
     return false;
 }
 
+ESourceRegistry *get_e_source_registry()
+{
+    static ESourceRegistry *theInstance;
+    if (!theInstance)
+        theInstance = e_source_registry_new_sync(NULL, NULL);
+    return theInstance;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx 
b/connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx
index bfe9f01..a214bd1 100644
--- a/connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx
+++ b/connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx
@@ -1086,14 +1086,6 @@ Reference< XResultSet > SAL_CALL 
OEvoabDatabaseMetaData::getColumns(
     return xResultSet;
 }
 
-ESourceRegistry *get_e_source_registry()
-{
-    static ESourceRegistry *theInstance;
-    if (!theInstance)
-        theInstance = e_source_registry_new_sync(NULL, NULL);
-    return theInstance;
-}
-
 // -------------------------------------------------------------------------
 bool isSourceBackend(ESource *pSource, const char *backendname)
 {
commit e3645fad6b2ea48851bcf6fdfb895ced74a6d8cb
Author: Mathias Hasselmann <math...@openismus.com>
Date:   Fri Mar 8 11:14:09 2013 +0100

    evoab2: Avoid G_N_ELEMENTS when loading symbols
    
    With G_N_ELEMENTS() the array name has to be twice, which can cause
    hard to spot typos in code derived from copy-and-paste, as we have
    here in the module loader. C++ can avoid the duplication by using
    the proper templates.
    
    Change-Id: I485e28a92e74b7e24f4a59cced6e5635f3a53a38

diff --git a/connectivity/source/drivers/evoab2/EApi.cxx 
b/connectivity/source/drivers/evoab2/EApi.cxx
index 608b1f9..8e0d0db 100644
--- a/connectivity/source/drivers/evoab2/EApi.cxx
+++ b/connectivity/source/drivers/evoab2/EApi.cxx
@@ -95,10 +95,10 @@ static ApiMap aNewApiMap[] =
 };
 #undef SYM_MAP
 
-static bool
-tryLink( oslModule &aModule, const char *pName, ApiMap *pMap, guint nEntries )
+template<size_t N> static bool
+tryLink( oslModule &aModule, const char *pName, const ApiMap (&pMap)[N])
 {
-    for (guint i = 0; i < nEntries; ++i)
+    for (guint i = 0; i < N; ++i)
     {
         SymbolFunc aMethod = (SymbolFunc)osl_getFunctionSymbol
             (aModule, OUString::createFromAscii ( pMap[ i ].sym_name ).pData);
@@ -124,14 +124,14 @@ bool EApiInit()
                                   SAL_LOADMODULE_DEFAULT );
         if( aModule)
         {
-            if (tryLink( aModule, eBookLibNames[ j ], aCommonApiMap, 
G_N_ELEMENTS(aCommonApiMap)))
+            if (tryLink( aModule, eBookLibNames[ j ], aCommonApiMap))
             {
                 if (eds_check_version(3, 6, 0) == NULL)
                 {
-                    if (tryLink( aModule, eBookLibNames[ j ], aNewApiMap, 
G_N_ELEMENTS(aNewApiMap)))
+                    if (tryLink( aModule, eBookLibNames[ j ], aNewApiMap))
                         return true;
                 }
-                else if (tryLink( aModule, eBookLibNames[ j ], aOldApiMap, 
G_N_ELEMENTS(aOldApiMap)))
+                else if (tryLink( aModule, eBookLibNames[ j ], aOldApiMap))
                 {
                     return true;
                 }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to