[bijiben] tracker: some cleanup for async functions
- From: Pierre-Yves Luyten <pyluyten src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben] tracker: some cleanup for async functions
- Date: Fri, 17 May 2013 22:56:40 +0000 (UTC)
commit 23ab61f2bcf5fed69529ffac75423126f72359cb
Author: Pierre-Yves Luyten <py luyten fr>
Date: Sat May 18 00:50:32 2013 +0200
tracker: some cleanup for async functions
libbiji user calls only one async function
libbiji deals with GAsyncResult and
triggers the expected callback.
src/bjb-controller.c | 39 ++----
src/bjb-note-tag-dialog.c | 11 +-
src/libbiji/biji-collection.c | 16 +-
src/libbiji/biji-note-book.c | 7 +-
src/libbiji/biji-note-obj.c | 16 ++-
src/libbiji/biji-tracker.c | 343 ++++++++++++++++++++++++-----------------
src/libbiji/biji-tracker.h | 92 ++++++-----
7 files changed, 299 insertions(+), 225 deletions(-)
---
diff --git a/src/bjb-controller.c b/src/bjb-controller.c
index adaf462..34b9da3 100644
--- a/src/bjb-controller.c
+++ b/src/bjb-controller.c
@@ -396,24 +396,21 @@ sort_and_update (BjbController *self)
g_signal_emit (G_OBJECT (self), bjb_controller_signals[DISPLAY_NOTES_CHANGED],0);
}
+
static void
-update_controller_callback (GObject *source_object,
- GAsyncResult *res,
+update_controller_callback (GList *result,
gpointer user_data)
{
- GList *result;
- BjbController *self = BJB_CONTROLLER (user_data);
+ BjbController *self;
- result = biji_get_notes_with_strings_or_collection_finish (source_object, res, self->priv->book);
+ self = BJB_CONTROLLER (user_data);
self->priv->items_to_show = result;
if (!result)
- {
bjb_window_base_switch_to (self->priv->window, BJB_WINDOW_BASE_NO_RESULT);
- return;
- }
- sort_and_update (self);
+ else
+ sort_and_update (self);
}
void
@@ -444,9 +441,8 @@ bjb_controller_apply_needle (BjbController *self)
return;
}
- /* There is a research, apply lookup
- * TODO : also look for collections */
- biji_get_notes_with_string_or_collection_async (needle, update_controller_callback, self);
+ /* There is a research, apply lookup */
+ biji_get_items_matching_async (self->priv->book, needle, update_controller_callback, self);
}
static void
@@ -726,19 +722,6 @@ bjb_controller_shows_item (BjbController *self)
return FALSE;
}
-static void
-bjb_controller_show_collection (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- GList *result;
- BjbController *self = BJB_CONTROLLER (user_data);
-
- result = biji_get_items_with_collection_finish (source_object, res, self->priv->book);
- self->priv->items_to_show = result;
-
- sort_and_update (self);
-}
BijiCollection *
bjb_controller_get_collection (BjbController *self)
@@ -746,6 +729,7 @@ bjb_controller_get_collection (BjbController *self)
return self->priv->collection;
}
+
void
bjb_controller_set_collection (BjbController *self,
BijiCollection *coll)
@@ -771,7 +755,8 @@ bjb_controller_set_collection (BjbController *self,
self->priv->needle = g_strdup ("");
self->priv->collection = coll;
- biji_get_items_with_collection_async (biji_item_get_title (BIJI_ITEM (coll)),
- bjb_controller_show_collection,
+ biji_get_items_with_collection_async (self->priv->book,
+ biji_item_get_title (BIJI_ITEM (coll)),
+ update_controller_callback,
self);
}
diff --git a/src/bjb-note-tag-dialog.c b/src/bjb-note-tag-dialog.c
index 6d724c0..ebc191a 100644
--- a/src/bjb-note-tag-dialog.c
+++ b/src/bjb-note-tag-dialog.c
@@ -160,9 +160,7 @@ bjb_get_path_for_str (GtkTreeModel *model,
}
static void
-bjb_note_tag_dialog_handle_tags (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
+bjb_note_tag_dialog_handle_tags (GHashTable *result, gpointer user_data)
{
BjbNoteTagDialog *self = BJB_NOTE_TAG_DIALOG (user_data);
BjbNoteTagDialogPrivate *priv = self->priv;
@@ -171,7 +169,7 @@ bjb_note_tag_dialog_handle_tags (GObject *source_object,
if (priv->collections)
g_hash_table_destroy (priv->collections);
- priv->collections = biji_get_all_collections_finish (source_object, res);
+ priv->collections = result;
tracker_info = g_hash_table_get_values (priv->collections);
tracker_info = g_list_sort (tracker_info, bjb_compare_collection);
@@ -197,8 +195,11 @@ bjb_note_tag_dialog_handle_tags (GObject *source_object,
static void
update_collections_model_async (BjbNoteTagDialog *self)
{
+ BijiNoteBook *book;
+
+ book = bjb_window_base_get_book (GTK_WIDGET (self->priv->window));
gtk_list_store_clear (self->priv->store);
- biji_get_all_collections_async (bjb_note_tag_dialog_handle_tags, self);
+ biji_get_all_collections_async (book, bjb_note_tag_dialog_handle_tags, self);
}
/* Libbiji handles tracker & saving */
diff --git a/src/libbiji/biji-collection.c b/src/libbiji/biji-collection.c
index df7f1e2..c06d0a4 100644
--- a/src/libbiji/biji-collection.c
+++ b/src/libbiji/biji-collection.c
@@ -28,7 +28,9 @@
#include "biji-collection.h"
#include "biji-tracker.h"
-static void biji_collection_update_collected (GObject *source_object, GAsyncResult *res, gpointer user_data);
+
+static void biji_collection_update_collected (GList *result, gpointer user_data);
+
struct BijiCollectionPrivate_
{
@@ -363,7 +365,8 @@ on_collected_item_change (BijiCollection *self)
}
/* Then re-process the whole stuff */
- biji_get_items_with_collection_async (self->priv->name,
+ biji_get_items_with_collection_async (self->priv->book,
+ self->priv->name,
biji_collection_update_collected,
self);
}
@@ -371,8 +374,7 @@ on_collected_item_change (BijiCollection *self)
/* For convenience, items are retrieved async.
* Thus use a signal once icon & emblem updated.*/
static void
-biji_collection_update_collected (GObject *source_object,
- GAsyncResult *res,
+biji_collection_update_collected (GList *result,
gpointer user_data)
{
BijiCollection *self = user_data;
@@ -383,8 +385,7 @@ biji_collection_update_collected (GObject *source_object,
g_clear_pointer (&priv->icon, g_object_unref);
g_clear_pointer (&priv->emblem, g_object_unref);
- priv->collected_items =
- biji_get_items_with_collection_finish (source_object, res, priv->book);
+ priv->collected_items = result;
/* Connect */
for (l = priv->collected_items; l!= NULL; l=l->next)
@@ -410,7 +411,8 @@ biji_collection_constructed (GObject *obj)
{
BijiCollection *self = BIJI_COLLECTION (obj);
- biji_get_items_with_collection_async (self->priv->name,
+ biji_get_items_with_collection_async (self->priv->book,
+ self->priv->name,
biji_collection_update_collected,
self);
}
diff --git a/src/libbiji/biji-note-book.c b/src/libbiji/biji-note-book.c
index b6688c7..7d84cbc 100644
--- a/src/libbiji/biji-note-book.c
+++ b/src/libbiji/biji-note-book.c
@@ -268,14 +268,11 @@ create_collection_if_needed (gpointer key,
}
static void
-load_book_finish (GObject *source_object,
- GAsyncResult *res,
+load_book_finish (GHashTable *collections,
gpointer user_data)
{
BijiNoteBook *self = BIJI_NOTE_BOOK (user_data);
- GHashTable *collections;
- collections = biji_get_all_collections_finish (source_object, res);
g_hash_table_foreach (collections, create_collection_if_needed, user_data);
g_hash_table_destroy (collections);
@@ -333,7 +330,7 @@ enumerate_next_files_ready_cb (GObject *source,
/* Now we have all notes,
* load the collections and we're good to notify loading done */
- biji_get_all_collections_async (load_book_finish, self);
+ biji_get_all_collections_async (self, load_book_finish, self);
}
static void
diff --git a/src/libbiji/biji-note-obj.c b/src/libbiji/biji-note-obj.c
index 25684e7..31de332 100644
--- a/src/libbiji/biji-note-obj.c
+++ b/src/libbiji/biji-note-obj.c
@@ -540,6 +540,18 @@ biji_note_obj_has_collection (BijiItem *item, gchar *label)
return FALSE;
}
+
+static void
+_biji_collection_refresh (gboolean query_result,
+ gpointer coll)
+{
+ g_return_if_fail (BIJI_IS_COLLECTION (coll));
+
+ if (query_result)
+ biji_collection_refresh (BIJI_COLLECTION (coll));
+}
+
+
/*static */ gboolean
biji_note_obj_add_collection (BijiItem *item,
BijiItem *collection,
@@ -562,7 +574,7 @@ biji_note_obj_add_collection (BijiItem *item,
if (BIJI_IS_COLLECTION (collection))
{
biji_push_existing_collection_to_note (
- note, label, (BijiFunc) biji_collection_refresh, collection); // Tracker
+ note, label, _biji_collection_refresh, collection); // Tracker
biji_note_id_set_last_metadata_change_date_now (note->priv->id);
biji_note_obj_save_note (note);
}
@@ -582,7 +594,7 @@ biji_note_obj_remove_collection (BijiItem *item, BijiItem *collection)
if (g_hash_table_remove (note->priv->labels, biji_item_get_title (collection)))
{
biji_remove_collection_from_note (
- note, collection, (BijiFunc) biji_collection_refresh, collection); // tracker.
+ note, collection, _biji_collection_refresh, collection); // tracker.
biji_note_id_set_last_metadata_change_date_now (note->priv->id);
biji_note_obj_save_note (note);
return TRUE;
diff --git a/src/libbiji/biji-tracker.c b/src/libbiji/biji-tracker.c
index 77fb080..6361fa4 100644
--- a/src/libbiji/biji-tracker.c
+++ b/src/libbiji/biji-tracker.c
@@ -1,5 +1,5 @@
/* biji-tracker.c
- * Copyright (C) Pierre-Yves LUYTEN 2012 <py luyten fr>
+ * Copyright (C) Pierre-Yves LUYTEN 2012, 2013 <py luyten fr>
*
* bijiben is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@ -18,6 +18,18 @@
#include "biji-item.h"
#include "biji-tracker.h"
+
+
+typedef enum
+{
+ BIJI_URN_COL,
+ BIJI_TITLE_COL,
+ BIJI_MTIME_COL,
+ BIJI_NO_COL
+} BijiTrackerColumns;
+
+
+
/* To perform something after async tracker query
* TODO : implemet this with GObject */
typedef struct {
@@ -25,59 +37,80 @@ typedef struct {
BijiNoteBook *book;
/* usually a query */
+
gchar *str;
- /* after the query */
- BijiFunc func;
- BijiCallback callback;
+ /* after the query, _one of_ the callbacks */
+
+ BijiBoolCallback bool_cb;
+ BijiItemCallback item_cb;
+ BijiItemsListCallback list_cb;
+ BijiInfoSetsHCallback hash_cb;
+
+
gpointer user_data;
} BijiTrackerFinisher;
+
+/* finisher stores _one of the possible callbacks _
+ * we could cast as well */
+
+
static BijiTrackerFinisher *
-biji_tracker_finisher_new (BijiNoteBook *book,
- gchar *str,
- BijiFunc f,
- BijiCallback callback,
- gpointer user_data)
+biji_tracker_finisher_new (BijiNoteBook *book,
+ gchar *str,
+ BijiBoolCallback bool_cb,
+ BijiItemCallback item_cb,
+ BijiItemsListCallback list_cb,
+ BijiInfoSetsHCallback hash_cb,
+ gpointer user_data)
{
- BijiTrackerFinisher *retval = g_new (BijiTrackerFinisher, 1);
+ BijiTrackerFinisher *retval = g_slice_new (BijiTrackerFinisher);
retval->book = book;
retval->str = str;
- retval->func = f;
- retval->callback = callback;
+ retval->bool_cb = bool_cb;
+ retval->item_cb = item_cb;
+ retval->list_cb = list_cb;
+ retval->hash_cb = hash_cb;
retval->user_data = user_data;
return retval;
}
+
+/* Only heap is str */
+
static void
biji_tracker_finisher_free (BijiTrackerFinisher *f)
{
- if (f->str)
- g_free (f->str);
-
- g_free (f);
+ g_clear_pointer (&f->str, g_free);
+ g_slice_free (BijiTrackerFinisher, f);
}
+
static BijiTrackerInfoSet *
biji_tracker_info_set_new ()
{
return g_slice_new (BijiTrackerInfoSet);
}
+
static void
biji_tracker_info_set_free (BijiTrackerInfoSet *set)
{
g_free (set->urn);
g_free (set->title);
+ g_free (set->mtime);
g_slice_free (BijiTrackerInfoSet, (gpointer) set);
}
+
TrackerSparqlConnection *bjb_connection ;
+
static TrackerSparqlConnection *
get_connection_singleton(void)
{
@@ -95,27 +128,23 @@ 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);
-}
+
+/* TODO : populate the boolean */
static void
biji_finish_update (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- TrackerSparqlConnection *self = TRACKER_SPARQL_CONNECTION (source_object);
- GError *error = NULL;
- BijiTrackerFinisher *finisher = user_data;
- gchar *query = finisher->str;
+ TrackerSparqlConnection *self;
+ BijiTrackerFinisher *finisher;
+ GError *error;
+ gchar *query;
+
+ self = TRACKER_SPARQL_CONNECTION (source_object);
+ finisher = user_data;
+ error = NULL;
+ query = finisher->str;
tracker_sparql_connection_update_finish (self, res, &error);
@@ -126,16 +155,19 @@ biji_finish_update (GObject *source_object,
}
/* See if the query has something to perform afterward */
- if (finisher->func)
- finisher->func (finisher->user_data);
+ if (finisher->bool_cb)
+ finisher->bool_cb (TRUE, finisher->user_data);
biji_tracker_finisher_free (finisher);
}
+
static void
-biji_perform_update_async_and_free (gchar *query, BijiFunc f, gpointer user_data)
+biji_perform_update_async_and_free (gchar *query, BijiBoolCallback f, gpointer user_data)
{
- BijiTrackerFinisher *finisher = biji_tracker_finisher_new (NULL, query, f, NULL, user_data);
+ BijiTrackerFinisher *finisher;
+ finisher = biji_tracker_finisher_new
+ (NULL, query, f, NULL, NULL, NULL, user_data);
tracker_sparql_connection_update_async (get_connection_singleton(),
query,
@@ -145,6 +177,7 @@ biji_perform_update_async_and_free (gchar *query, BijiFunc f, gpointer user_data
finisher);
}
+
/* Don't worry too much. We just want plain text here */
static gchar *
tracker_str (const gchar * string )
@@ -152,6 +185,7 @@ tracker_str (const gchar * string )
return biji_str_mass_replace (string, "\n", " ", "'", " ", NULL);
}
+
static gchar *
to_8601_date( gchar * dot_iso_8601_date )
{
@@ -160,6 +194,7 @@ to_8601_date( gchar * dot_iso_8601_date )
g_utf8_strncpy (result ,dot_iso_8601_date, 19) );
}
+
static gchar *
get_note_url (BijiNoteObj *note)
{
@@ -167,18 +202,23 @@ get_note_url (BijiNoteObj *note)
}
-/* This func provides Collections, URN, mtime */
-GHashTable *
-biji_get_all_collections_finish (GObject *source_object,
- GAsyncResult *res)
+
+static void
+biji_query_info_hash_finish (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
{
- TrackerSparqlConnection *self = TRACKER_SPARQL_CONNECTION (source_object);
+ TrackerSparqlConnection *self;
TrackerSparqlCursor *cursor;
- GError *error = NULL;
- GHashTable *result = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- NULL,
- (GDestroyNotify) biji_tracker_info_set_free);
+ GError *error;
+ GHashTable *result;
+ BijiTrackerFinisher *finisher;
+
+ self = TRACKER_SPARQL_CONNECTION (source_object);
+ finisher = (BijiTrackerFinisher*) user_data;
+ error = NULL;
+ result = g_hash_table_new_full (
+ g_str_hash, g_str_equal, NULL, (GDestroyNotify) biji_tracker_info_set_free);
cursor = tracker_sparql_connection_query_finish (self,
res,
@@ -207,33 +247,30 @@ biji_get_all_collections_finish (GObject *source_object,
g_object_unref (cursor);
}
- return result;
+ finisher->hash_cb (result, finisher->user_data);
+ biji_tracker_finisher_free (finisher);
+ return;
}
-
-void
-biji_get_all_collections_async (GAsyncReadyCallback f,
- gpointer user_data)
-{
- gchar *query = g_strconcat (
- "SELECT ?c ?title ?mtime ",
- "WHERE { ?c a nfo:DataContainer ;",
- "nie:title ?title ; ",
- "nie:contentLastModified ?mtime ;"
- "nie:generator 'Bijiben'}",
- NULL);
- bjb_perform_query_async (query, f, user_data);
-}
-GList *
-biji_get_items_with_collection_finish (GObject *source_object,
- GAsyncResult *res,
- BijiNoteBook *book)
+static void
+biji_query_items_list_finish (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
{
- TrackerSparqlConnection *self = TRACKER_SPARQL_CONNECTION (source_object);
+ TrackerSparqlConnection *self;
TrackerSparqlCursor *cursor;
- GError *error = NULL;
- GList *result = NULL;
+ BijiTrackerFinisher *finisher;
+ GError *error;
+ GList *result;
+
+ self = TRACKER_SPARQL_CONNECTION (source_object);
+ result = NULL;
+ error = NULL;
+ finisher = (BijiTrackerFinisher *) user_data;
+
+ if (finisher->list_cb == NULL)
+ return;
cursor = tracker_sparql_connection_query_finish (self, res, &error);
@@ -256,89 +293,105 @@ biji_get_items_with_collection_finish (GObject *source_object,
if (g_str_has_prefix (full_path, "file://"))
{
GString *string;
+
string = g_string_new (full_path);
g_string_erase (string, 0, 7);
path = g_string_free (string, FALSE);
}
+
else
{
path = g_strdup (full_path);
}
- item = biji_note_book_get_item_at_path (book, path);
+ item = biji_note_book_get_item_at_path (finisher->book, path);
/* Sorting is done in another place */
if (item)
result = g_list_prepend (result, item);
-
- g_free (path);
}
g_object_unref (cursor);
}
- return result;
+ finisher->list_cb (result, finisher->user_data);
+ biji_tracker_finisher_free (finisher);
}
-void
-biji_get_items_with_collection_async (const gchar *collection,
- GAsyncReadyCallback f,
- gpointer user_data)
+
+
+static void
+bjb_query_async (BijiNoteBook *book,
+ gchar *query,
+ BijiInfoSetsHCallback hash_cb,
+ BijiItemsListCallback list_cb,
+ gpointer user_data)
{
- gchar *query;
+ BijiTrackerFinisher *finisher;
+ GAsyncReadyCallback callback = NULL;
- query = g_strdup_printf ("SELECT ?s WHERE {?c nie:isPartOf ?s; nie:title '%s'}",
- collection);
+ finisher = biji_tracker_finisher_new (book, NULL, NULL, NULL, list_cb, hash_cb, user_data);
+
+ if (hash_cb != NULL)
+ callback = biji_query_info_hash_finish;
- bjb_perform_query_async (query, f, user_data);
+ else if (list_cb != NULL)
+ callback = biji_query_items_list_finish;
+
+ if (callback)
+ tracker_sparql_connection_query_async (
+ get_connection_singleton (), query, NULL, callback, finisher);
}
-GList *
-biji_get_notes_with_strings_or_collection_finish (GObject *source_object,
- GAsyncResult *res,
- BijiNoteBook *book)
+
+void
+biji_get_all_collections_async (BijiNoteBook *book,
+ BijiInfoSetsHCallback cb,
+ gpointer user_data)
{
- TrackerSparqlConnection *self = TRACKER_SPARQL_CONNECTION (source_object);
- TrackerSparqlCursor *cursor;
- GError *error = NULL;
- GList *result = NULL;
+ gchar *query = g_strconcat (
+ "SELECT ?c ?title ?mtime ",
+ "WHERE { ?c a nfo:DataContainer ;",
+ "nie:title ?title ; ",
+ "nie:contentLastModified ?mtime ;"
+ "nie:generator 'Bijiben'}",
+ NULL);
- cursor = tracker_sparql_connection_query_finish (self, res, &error);
+ bjb_query_async (book, query, cb, NULL, user_data);
+}
- if (error)
- {
- g_warning ("%s", error->message);
- g_error_free (error);
- }
- if (cursor)
- {
- const gchar *path;
- BijiItem *item = NULL;
- while (tracker_sparql_cursor_next (cursor, NULL, NULL))
- {
- path = tracker_sparql_cursor_get_string (cursor, 0, NULL);
- item = biji_note_book_get_item_at_path (book, path);
- /* Sorting is done in another place */
- if (item)
- result = g_list_prepend (result, item);
- }
+/* FIXME: returns file://$PATH while we want $PATH
+ * workaround in biji_query_items_list_finish */
+void
+biji_get_items_with_collection_async (BijiNoteBook *book,
+ const gchar *collection,
+ BijiItemsListCallback list_cb,
+ gpointer user_data)
+{
+ gchar *query;
- g_object_unref (cursor);
- }
+ query = g_strdup_printf ("SELECT ?s WHERE {?c nie:isPartOf ?s; nie:title '%s'}",
+ collection);
- return result;
+ bjb_query_async (book, query, NULL, list_cb, user_data);
}
+
+
void
-biji_get_notes_with_string_or_collection_async (gchar *needle, GAsyncReadyCallback f, gpointer user_data)
+biji_get_items_matching_async (BijiNoteBook *book,
+ gchar *needle,
+ BijiItemsListCallback list_cb,
+ gpointer user_data)
{
gchar *lower;
gchar *query;
+
lower = g_utf8_strdown (needle, -1);
query = g_strconcat (
"SELECT ?urn WHERE {",
@@ -354,9 +407,10 @@ biji_get_notes_with_string_or_collection_async (gchar *needle, GAsyncReadyCallba
NULL);
g_free (lower);
- bjb_perform_query_async (query, f, user_data);
+ bjb_query_async (book, query, NULL, list_cb, user_data);
}
+
static void
on_new_collection_query_executed (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
@@ -427,22 +481,23 @@ on_new_collection_query_executed (GObject *source_object, GAsyncResult *res, gpo
/* Run the callback from the caller */
out:
- if (finisher->callback != NULL)
- (*finisher->callback) (BIJI_ITEM (collection), finisher->user_data);
+ if (finisher->item_cb != NULL)
+ (*finisher->item_cb) (BIJI_ITEM (collection), finisher->user_data);
g_free (val);
g_free (key);
biji_tracker_finisher_free (finisher);
}
+
/* This func creates the collection,
* gives the urn to the notebook,
* then run the 'afterward' callback */
void
-biji_create_new_collection_async (BijiNoteBook *book,
- const gchar *name,
- BijiCallback afterward,
- gpointer user_data)
+biji_create_new_collection_async (BijiNoteBook *book,
+ const gchar *name,
+ BijiItemCallback item_cb,
+ gpointer user_data)
{
gchar *query;
GTimeVal tv;
@@ -465,7 +520,7 @@ biji_create_new_collection_async (BijiNoteBook *book,
/* The finisher has all the pointers we want.
* And the callback will free it */
- finisher = biji_tracker_finisher_new (book, g_strdup (name), NULL, afterward, user_data);
+ finisher = biji_tracker_finisher_new (book, g_strdup (name), NULL, item_cb, NULL, NULL, user_data);
tracker_sparql_connection_update_blank_async (get_connection_singleton (),
query,
G_PRIORITY_DEFAULT,
@@ -474,48 +529,57 @@ biji_create_new_collection_async (BijiNoteBook *book,
finisher);
}
-/* removes the tag EVEN if files associated.
- * TODO : afterward */
+
+/* removes the tag EVEN if files associated. */
+
void
biji_remove_collection_from_tracker (const gchar *urn)
{
- gchar *query = g_strdup_printf ("DELETE {'%s' a nfo:DataContainer}", urn);
+ gchar *query;
+
+ query = g_strdup_printf ("DELETE {'%s' a nfo:DataContainer}", urn);
biji_perform_update_async_and_free (query, NULL, NULL);
}
+
void
-biji_push_existing_collection_to_note (BijiNoteObj *note,
- gchar *title,
- BijiFunc afterward,
- gpointer user_data)
+biji_push_existing_collection_to_note (BijiNoteObj *note,
+ gchar *title,
+ BijiBoolCallback afterward,
+ gpointer user_data)
{
- gchar *url = get_note_url (note);
- gchar *query = g_strdup_printf ("INSERT {?urn nie:isPartOf '%s'} WHERE {?urn a nfo:DataContainer;
nie:title '%s'; nie:generator 'Bijiben'}",
- url, title);
+ gchar *url, *query;
+
+ url = get_note_url (note);
+ query = g_strdup_printf ("INSERT {?urn nie:isPartOf '%s'} WHERE {?urn a nfo:DataContainer; nie:title '%s';
nie:generator 'Bijiben'}",
+ url, title);
biji_perform_update_async_and_free (query, afterward, user_data);
g_free (url);
}
-/* This one is to be fixed */
+
+
void
-biji_remove_collection_from_note (BijiNoteObj *note,
- BijiItem *coll,
- BijiFunc afterward,
- gpointer user_data)
+biji_remove_collection_from_note (BijiNoteObj *note,
+ BijiItem *coll,
+ BijiBoolCallback afterward,
+ gpointer user_data)
{
- gchar *url = get_note_url (note);
- gchar *query = g_strconcat ("DELETE {'",
- biji_item_get_uuid (coll),
- "' nie:isPartOf '",
- url,
- "'}",
- NULL);
+ gchar *url, *query;
+
+ url = get_note_url (note);
+
+ query = g_strdup_printf (
+ "DELETE {'%s' nie:isPartOf '%s'}",
+ biji_item_get_uuid (coll), url);
+
biji_perform_update_async_and_free (query, afterward, user_data);
g_free (url);
}
+
void
biji_note_delete_from_tracker (BijiNoteObj *note)
{
@@ -527,6 +591,7 @@ biji_note_delete_from_tracker (BijiNoteObj *note)
biji_perform_update_async_and_free (query, NULL, NULL);
}
+
void
bijiben_push_note_to_tracker (BijiNoteObj *note)
{
diff --git a/src/libbiji/biji-tracker.h b/src/libbiji/biji-tracker.h
index a5c7e21..179cefa 100644
--- a/src/libbiji/biji-tracker.h
+++ b/src/libbiji/biji-tracker.h
@@ -1,5 +1,5 @@
/* biji-tracker.h
- * Copyright (C) Pierre-Yves LUYTEN 2012 <py luyten fr>
+ * Copyright (C) Pierre-Yves LUYTEN 2012,2013 <py luyten fr>
*
* bijiben is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@ -24,13 +24,6 @@
#include "libbiji.h"
-typedef enum
-{
- BIJI_URN_COL,
- BIJI_TITLE_COL,
- BIJI_MTIME_COL,
- BIJI_NO_COL
-} BijiTrackerColumns;
typedef struct
@@ -42,56 +35,75 @@ typedef struct
} BijiTrackerInfoSet;
-typedef void (*BijiFunc) (gpointer user_data);
+/* All possible query return
+ * Free the containers for list & hash */
+
+
+typedef void (*BijiBoolCallback) (gboolean result, gpointer user_data);
+
+
+typedef void (*BijiItemCallback) (BijiItem *item, gpointer user_data);
+
+
+typedef void (*BijiItemsListCallback) (GList *items, gpointer user_data);
+
+
+typedef void (*BijiInfoSetsHCallback) (GHashTable *info_sets, gpointer user_data);
+
+
+
+void biji_get_items_with_collection_async (BijiNoteBook *book,
+ const gchar *needle,
+ BijiItemsListCallback cb,
+ gpointer user_data);
+
+
+void biji_get_items_matching_async (BijiNoteBook *book,
+ gchar *needle,
+ BijiItemsListCallback cb,
+ gpointer user_data);
+
+
+
+void biji_get_all_collections_async (BijiNoteBook *book,
+ BijiInfoSetsHCallback cb,
+ gpointer user_data);
+
+
-typedef void (*BijiCallback) (BijiItem *item, gpointer user_data);
+void biji_create_new_collection_async (BijiNoteBook *book,
+ const gchar *tag,
+ BijiItemCallback afterward,
+ gpointer user_data);
+void biji_remove_collection_from_tracker (const gchar *urn);
-GList * biji_get_items_with_collection_finish (GObject *source_object,
- GAsyncResult *res,
- BijiNoteBook *book);
-void biji_get_items_with_collection_async (const gchar *needle,
- GAsyncReadyCallback f,
- gpointer user_data);
-/* All notes matching (either content or collections) */
-GList * biji_get_notes_with_strings_or_collection_finish (GObject *source_object,
- GAsyncResult *res,
- BijiNoteBook *book);
-void biji_get_notes_with_string_or_collection_async (gchar *needle,
- GAsyncReadyCallback f,
- gpointer user_data);
+void biji_push_existing_collection_to_note (BijiNoteObj *note,
+ gchar *title,
+ BijiBoolCallback bool_cb,
+ gpointer user_data);
-/* Collections */
-/* The URN is the... value. Collection _title_ is the key.*/
-GHashTable * biji_get_all_collections_finish (GObject *source_object, GAsyncResult *res);
-void biji_get_all_collections_async (GAsyncReadyCallback f, gpointer user_data);
+void biji_remove_collection_from_note (BijiNoteObj *note,
+ BijiItem *coll,
+ BijiBoolCallback bool_cb,
+ gpointer user_data);
-void biji_create_new_collection_async (BijiNoteBook *book, const gchar *tag, BijiCallback afterward,
gpointer user_data);
-void biji_remove_collection_from_tracker (const gchar *urn);
+ /* Either insert or update */
+void bijiben_push_note_to_tracker (BijiNoteObj *note);
-void biji_push_existing_collection_to_note (BijiNoteObj *note,
- gchar *title,
- BijiFunc callback,
- gpointer user_data);
-void biji_remove_collection_from_note (BijiNoteObj *note,
- BijiItem *coll,
- BijiFunc afterward,
- gpointer user_data);
+void biji_note_delete_from_tracker (BijiNoteObj *note);
-/* Insert or update */
-void bijiben_push_note_to_tracker(BijiNoteObj *note);
-void biji_note_delete_from_tracker(BijiNoteObj *note);
#endif /*_BIJI_TRACKER_H*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]