[bijiben] Tracker : get_all_tags => async version
- From: Pierre-Yves Luyten <pyluyten src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben] Tracker : get_all_tags => async version
- Date: Sat, 17 Nov 2012 23:09:25 +0000 (UTC)
commit 340904e0edd08f722415d1be0ff6f813a812d181
Author: Pierre-Yves Luyten <py luyten fr>
Date: Sat Nov 17 23:56:30 2012 +0100
Tracker : get_all_tags => async version
src/bjb-note-tag-dialog.c | 24 ++++++++++++-----
src/libbiji/biji-tracker.c | 60 ++++++++++++++++++++++++++++++++++++++++++++
src/libbiji/biji-tracker.h | 8 ++++-
3 files changed, 83 insertions(+), 9 deletions(-)
---
diff --git a/src/bjb-note-tag-dialog.c b/src/bjb-note-tag-dialog.c
index abfa94b..1ed6d9b 100644
--- a/src/bjb-note-tag-dialog.c
+++ b/src/bjb-note-tag-dialog.c
@@ -91,15 +91,26 @@ append_tag (gchar *tag, BjbNoteTagDialog *self)
/* Current tags selection & sorting might be improved */
static void
-update_tags_model (BjbNoteTagDialog *self)
+bjb_note_tag_dialog_handle_tags (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
{
- GList *all_tags = NULL;
+ BjbNoteTagDialog *self = BJB_NOTE_TAG_DIALOG (user_data);
+
+ GList *tags;
- all_tags = g_list_copy (bjb_window_base_get_tags (GTK_WIDGET(self->priv->window)));
- all_tags = g_list_sort (all_tags, (GCompareFunc) g_strcmp0);
- g_list_foreach (all_tags, (GFunc) append_tag, self);
+ tags = biji_get_all_tags_finish (source_object, res);
+ tags = g_list_sort (tags, (GCompareFunc) g_strcmp0);
- g_list_free (all_tags);
+ g_list_foreach (tags, (GFunc) append_tag, self);
+ g_list_free_full (tags, g_free);
+}
+
+static void
+update_tags_model (BjbNoteTagDialog *self)
+{
+ gtk_list_store_clear (self->priv->store);
+ biji_get_all_tracker_tags_async (bjb_note_tag_dialog_handle_tags, self);
}
/* TODO This two func should rather be direct call to libbiji
@@ -173,7 +184,6 @@ add_new_tag (BjbNoteTagDialog *self)
bjb_window_base_set_tags (GTK_WIDGET (self->priv->window), get_all_tracker_tags());
/* Update the view */
- gtk_list_store_clear (self->priv->store);
update_tags_model (self);
}
diff --git a/src/libbiji/biji-tracker.c b/src/libbiji/biji-tracker.c
index 044c790..49551a7 100644
--- a/src/libbiji/biji-tracker.c
+++ b/src/libbiji/biji-tracker.c
@@ -36,6 +36,18 @@ get_connection_singleton(void)
return bjb_connection ;
}
+static void
+bjb_perform_query_async (gchar *query,
+ GAsyncReadyCallback f,
+ gpointer user_data)
+{
+ tracker_sparql_connection_query_async (get_connection_singleton (),
+ query,
+ NULL,
+ f,
+ user_data);
+}
+
static TrackerSparqlCursor *
bjb_perform_query ( gchar * query )
{
@@ -151,6 +163,54 @@ tracker_tag_get_number_of_files(gchar *tag)
return result ;
}
+/* This func only provides tags.
+ * TODO : include number of notes / files */
+GList *
+biji_get_all_tags_finish (GObject *source_object,
+ GAsyncResult *res)
+{
+ TrackerSparqlConnection *self = TRACKER_SPARQL_CONNECTION (source_object);
+ TrackerSparqlCursor *cursor;
+ GError *error = NULL;
+ GList *result = NULL;
+
+ cursor = tracker_sparql_connection_query_finish (self,
+ res,
+ &error);
+
+ if (error)
+ {
+ g_warning (error->message);
+ g_error_free (error);
+ }
+
+ if (cursor)
+ {
+ gchar* tag;
+
+ while (tracker_sparql_cursor_next (cursor, NULL, NULL))
+ {
+ tag = g_strdup (tracker_sparql_cursor_get_string (cursor, 0, NULL));
+ result = g_list_prepend (result, (gpointer) tag);
+ }
+
+ g_object_unref (cursor);
+ }
+
+ return result;
+}
+
+void
+biji_get_all_tracker_tags_async (GAsyncReadyCallback f,
+ gpointer user_data)
+{
+ gchar *query = "SELECT DISTINCT ?labels WHERE \
+ { ?tags a nao:Tag ; nao:prefLabel ?labels. }";
+
+ bjb_perform_query_async (query, f, user_data);
+}
+
+/* TODO : delete this one */
GList *
get_all_tracker_tags()
{
diff --git a/src/libbiji/biji-tracker.h b/src/libbiji/biji-tracker.h
index 8737cc1..c20b3b3 100644
--- a/src/libbiji/biji-tracker.h
+++ b/src/libbiji/biji-tracker.h
@@ -29,8 +29,12 @@ GList * tracker_tag_get_files(gchar *tag);
gint tracker_tag_get_number_of_files(gchar *tag);
-/* Free the result */
-GList *get_all_tracker_tags();
+/* Get tags */
+GList * biji_get_all_tags_finish (GObject *source_object, GAsyncResult *res);
+void biji_get_all_tracker_tags_async (GAsyncReadyCallback f, gpointer user_data);
+
+/* don't use this , might block */
+GList *get_all_tracker_tags (void);
void push_tag_to_tracker(gchar *tag);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]