mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-27 14:10:30 +00:00
tracker-search-engine: Fixed 0.7/0.8 issues and add 0.9 cases
This commit is contained in:
parent
af0a7aea5f
commit
f6c1d54b3f
@ -30,13 +30,15 @@ typedef struct _TrackerClient TrackerClient;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TRACKER_UNAVAILABLE = 0,
|
||||
TRACKER_0_6 = 1 << 0,
|
||||
TRACKER_0_7 = 1 << 1,
|
||||
TRACKER_0_8 = 1 << 2
|
||||
TRACKER_0_8 = 1 << 2,
|
||||
TRACKER_0_9 = 1 << 3
|
||||
} TrackerVersion;
|
||||
|
||||
|
||||
/* tracker 0.6 API */
|
||||
/* Tracker 0.6 API */
|
||||
typedef void (*TrackerArrayReply) (char **result, GError *error, gpointer user_data);
|
||||
|
||||
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,
|
||||
TrackerArrayReply callback,
|
||||
gpointer user_data) = NULL;
|
||||
/* tracker 0.8 API */
|
||||
/* Tracker 0.7->0.9 API */
|
||||
typedef enum {
|
||||
TRACKER_CLIENT_ENABLE_WARNINGS = 1 << 0
|
||||
} TrackerClientFlags;
|
||||
@ -82,12 +84,12 @@ static struct TrackerDlMapping
|
||||
MAP (tracker_connect, TRACKER_0_6 | TRACKER_0_7),
|
||||
MAP (tracker_disconnect, TRACKER_0_6 | TRACKER_0_7),
|
||||
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_and_location_async, TRACKER_0_6 | TRACKER_0_7),
|
||||
MAP (tracker_client_new, TRACKER_0_8),
|
||||
MAP (tracker_sparql_escape, TRACKER_0_8),
|
||||
MAP (tracker_resources_sparql_query_async, TRACKER_0_8)
|
||||
MAP (tracker_client_new, TRACKER_0_8 | TRACKER_0_9),
|
||||
MAP (tracker_sparql_escape, TRACKER_0_8 | TRACKER_0_9),
|
||||
MAP (tracker_resources_sparql_query_async, TRACKER_0_8 | TRACKER_0_9)
|
||||
#undef MAP
|
||||
};
|
||||
|
||||
@ -95,52 +97,46 @@ static TrackerVersion
|
||||
open_libtracker (void)
|
||||
{
|
||||
static gboolean done = FALSE;
|
||||
static TrackerVersion version = 0;
|
||||
static TrackerVersion version = TRACKER_UNAVAILABLE;
|
||||
gpointer x;
|
||||
|
||||
if (!done)
|
||||
{
|
||||
int i;
|
||||
gint i;
|
||||
GModule *tracker;
|
||||
GModuleFlags flags;
|
||||
|
||||
done = TRUE;
|
||||
flags = G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL;
|
||||
|
||||
tracker = g_module_open ("libtracker-client-0.8.so.0", flags);
|
||||
version = TRACKER_0_8;
|
||||
/* So this is the order:
|
||||
*
|
||||
* - 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++)
|
||||
{
|
||||
if ((tracker_dl_mapping[i].versions & version) == 0)
|
||||
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))
|
||||
{
|
||||
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++)
|
||||
tracker_dl_mapping[i].fn_ptr_ref = NULL;
|
||||
|
||||
return 0;
|
||||
return TRACKER_UNAVAILABLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -182,7 +178,8 @@ finalize (GObject *object)
|
||||
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);
|
||||
else
|
||||
tracker_disconnect (tracker->priv->client);
|
||||
@ -235,7 +232,8 @@ search_callback (gpointer results,
|
||||
if (!results)
|
||||
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;
|
||||
|
||||
@ -302,7 +300,8 @@ gtk_search_engine_tracker_start (GtkSearchEngine *engine)
|
||||
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_append_string_literal (sparql, search_text);
|
||||
@ -416,7 +415,8 @@ _gtk_search_engine_tracker_new (void)
|
||||
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user