tracker-search-engine: Fixed 0.7/0.8 issues and add 0.9 cases

This commit is contained in:
Martyn Russell 2010-04-09 14:21:45 +01:00
parent af0a7aea5f
commit f6c1d54b3f

View File

@ -30,13 +30,15 @@ typedef struct _TrackerClient TrackerClient;
typedef enum typedef enum
{ {
TRACKER_UNAVAILABLE = 0,
TRACKER_0_6 = 1 << 0, TRACKER_0_6 = 1 << 0,
TRACKER_0_7 = 1 << 1, TRACKER_0_7 = 1 << 1,
TRACKER_0_8 = 1 << 2 TRACKER_0_8 = 1 << 2,
TRACKER_0_9 = 1 << 3
} TrackerVersion; } TrackerVersion;
/* tracker 0.6 API */ /* Tracker 0.6 API */
typedef void (*TrackerArrayReply) (char **result, GError *error, gpointer user_data); typedef void (*TrackerArrayReply) (char **result, GError *error, gpointer user_data);
static TrackerClient * (*tracker_connect) (gboolean enable_warnings, gint timeout) = NULL; static TrackerClient * (*tracker_connect) (gboolean enable_warnings, gint timeout) = NULL;
@ -53,7 +55,7 @@ static void (*tracker_search_metadata_by_text_and_location_async) (TrackerClient
const char *location, const char *location,
TrackerArrayReply callback, TrackerArrayReply callback,
gpointer user_data) = NULL; gpointer user_data) = NULL;
/* tracker 0.8 API */ /* Tracker 0.7->0.9 API */
typedef enum { typedef enum {
TRACKER_CLIENT_ENABLE_WARNINGS = 1 << 0 TRACKER_CLIENT_ENABLE_WARNINGS = 1 << 0
} TrackerClientFlags; } TrackerClientFlags;
@ -82,12 +84,12 @@ static struct TrackerDlMapping
MAP (tracker_connect, TRACKER_0_6 | TRACKER_0_7), MAP (tracker_connect, TRACKER_0_6 | TRACKER_0_7),
MAP (tracker_disconnect, TRACKER_0_6 | TRACKER_0_7), MAP (tracker_disconnect, TRACKER_0_6 | TRACKER_0_7),
MAP (tracker_get_version, TRACKER_0_6), MAP (tracker_get_version, TRACKER_0_6),
MAP (tracker_cancel_last_call, TRACKER_0_6 | TRACKER_0_7 | TRACKER_0_8), MAP (tracker_cancel_last_call, TRACKER_0_6 | TRACKER_0_7 | TRACKER_0_8 | TRACKER_0_9),
MAP (tracker_search_metadata_by_text_async, TRACKER_0_6 | TRACKER_0_7), MAP (tracker_search_metadata_by_text_async, TRACKER_0_6 | TRACKER_0_7),
MAP (tracker_search_metadata_by_text_and_location_async, TRACKER_0_6 | TRACKER_0_7), MAP (tracker_search_metadata_by_text_and_location_async, TRACKER_0_6 | TRACKER_0_7),
MAP (tracker_client_new, TRACKER_0_8), MAP (tracker_client_new, TRACKER_0_8 | TRACKER_0_9),
MAP (tracker_sparql_escape, TRACKER_0_8), MAP (tracker_sparql_escape, TRACKER_0_8 | TRACKER_0_9),
MAP (tracker_resources_sparql_query_async, TRACKER_0_8) MAP (tracker_resources_sparql_query_async, TRACKER_0_8 | TRACKER_0_9)
#undef MAP #undef MAP
}; };
@ -95,52 +97,46 @@ static TrackerVersion
open_libtracker (void) open_libtracker (void)
{ {
static gboolean done = FALSE; static gboolean done = FALSE;
static TrackerVersion version = 0; static TrackerVersion version = TRACKER_UNAVAILABLE;
gpointer x; gpointer x;
if (!done) if (!done)
{ {
int i; gint i;
GModule *tracker; GModule *tracker;
GModuleFlags flags; GModuleFlags flags;
done = TRUE; done = TRUE;
flags = G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL; flags = G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL;
tracker = g_module_open ("libtracker-client-0.8.so.0", flags); /* So this is the order:
version = TRACKER_0_8; *
* - 0.9 (latest unstable)
* - 0.8 (stable)
* - 0.7 (unstable, 0.6 sucks so badly)
* - 0.6 (stable)
*/
if ((tracker = g_module_open ("libtracker-client-0.9.so.0", flags)) != NULL)
version = TRACKER_0_9;
else if ((tracker = g_module_open ("libtracker-client-0.8.so.0", flags)) != NULL)
version = TRACKER_0_8;
else if ((tracker = g_module_open ("libtracker-client-0.7.so.0", flags)) != NULL)
version = TRACKER_0_7;
else if ((tracker = g_module_open ("libtrackerclient.so.0", flags)) != NULL)
version = TRACKER_0_6;
else
{
g_debug ("No tracker backend available");
return TRACKER_UNAVAILABLE;
}
if (!tracker)
{
tracker = g_module_open ("libtracker-client-0.7.so.0", flags);
if (tracker && !g_module_symbol (tracker, "tracker_resources_sparql_query_async", &x))
{
version = TRACKER_0_7;
}
}
if (!tracker)
{
tracker = g_module_open ("libtrackerclient.so.0", flags);
version = TRACKER_0_6;
}
if (!tracker)
{
tracker = g_module_open ("libtracker.so.0", flags);
version = TRACKER_0_6;
}
if (!tracker)
return 0;
for (i = 0; i < G_N_ELEMENTS (tracker_dl_mapping); i++) for (i = 0; i < G_N_ELEMENTS (tracker_dl_mapping); i++)
{ {
if ((tracker_dl_mapping[i].versions & version) == 0) if ((tracker_dl_mapping[i].versions & version) == 0)
continue; continue;
if (!g_module_symbol (tracker, tracker_dl_mapping[i].fn_name, if (!g_module_symbol (tracker,
tracker_dl_mapping[i].fn_name,
tracker_dl_mapping[i].fn_ptr_ref)) tracker_dl_mapping[i].fn_ptr_ref))
{ {
g_warning ("Missing symbol '%s' in libtracker\n", g_warning ("Missing symbol '%s' in libtracker\n",
@ -150,7 +146,7 @@ open_libtracker (void)
for (i = 0; i < G_N_ELEMENTS (tracker_dl_mapping); i++) for (i = 0; i < G_N_ELEMENTS (tracker_dl_mapping); i++)
tracker_dl_mapping[i].fn_ptr_ref = NULL; tracker_dl_mapping[i].fn_ptr_ref = NULL;
return 0; return TRACKER_UNAVAILABLE;
} }
} }
} }
@ -182,7 +178,8 @@ finalize (GObject *object)
tracker->priv->query = NULL; tracker->priv->query = NULL;
} }
if (tracker->priv->version == TRACKER_0_8) if (tracker->priv->version == TRACKER_0_8 ||
tracker->priv->version == TRACKER_0_9)
g_object_unref (tracker->priv->client); g_object_unref (tracker->priv->client);
else else
tracker_disconnect (tracker->priv->client); tracker_disconnect (tracker->priv->client);
@ -235,7 +232,8 @@ search_callback (gpointer results,
if (!results) if (!results)
return; return;
if (tracker->priv->version == TRACKER_0_8) if (tracker->priv->version == TRACKER_0_8 ||
tracker->priv->version == TRACKER_0_9)
{ {
OUT_result = (GPtrArray*) results; OUT_result = (GPtrArray*) results;
@ -302,7 +300,8 @@ gtk_search_engine_tracker_start (GtkSearchEngine *engine)
location = location_uri; location = location_uri;
} }
if (tracker->priv->version == TRACKER_0_8) if (tracker->priv->version == TRACKER_0_8 ||
tracker->priv->version == TRACKER_0_9)
{ {
sparql = g_string_new ("SELECT ?url WHERE { ?file a nfo:FileDataObject; nie:url ?url; fts:match "); sparql = g_string_new ("SELECT ?url WHERE { ?file a nfo:FileDataObject; nie:url ?url; fts:match ");
sparql_append_string_literal (sparql, search_text); sparql_append_string_literal (sparql, search_text);
@ -416,7 +415,8 @@ _gtk_search_engine_tracker_new (void)
version = open_libtracker (); version = open_libtracker ();
if (version == TRACKER_0_8) if (version == TRACKER_0_8 ||
version == TRACKER_0_9)
{ {
tracker_client = tracker_client_new (TRACKER_CLIENT_ENABLE_WARNINGS, G_MAXINT); tracker_client = tracker_client_new (TRACKER_CLIENT_ENABLE_WARNINGS, G_MAXINT);
} }