[bijiben] Remove tag booklets. Rely on tracker for notes search.
- From: Pierre-Yves Luyten <pyluyten src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben] Remove tag booklets. Rely on tracker for notes search.
- Date: Sat, 8 Dec 2012 18:22:25 +0000 (UTC)
commit 6ef69c7d68f0bc891a1b19881e179081f011104a
Author: Pierre-Yves Luyten <py luyten fr>
Date: Sat Dec 8 19:20:56 2012 +0100
Remove tag booklets. Rely on tracker for notes search.
Tracker is now properly handled by libiji for Main View
src/bjb-controller.c | 55 +++++----------
src/bjb-note-tag-dialog.c | 22 +-----
src/libbiji/biji-note-book.c | 156 ------------------------------------------
src/libbiji/biji-note-book.h | 8 +--
src/libbiji/biji-note-obj.c | 40 +++++------
src/libbiji/biji-tracker.c | 54 +++++++++++++++
src/libbiji/biji-tracker.h | 4 +
7 files changed, 98 insertions(+), 241 deletions(-)
---
diff --git a/src/bjb-controller.c b/src/bjb-controller.c
index 9d07bcf..a4d7daf 100644
--- a/src/bjb-controller.c
+++ b/src/bjb-controller.c
@@ -250,30 +250,23 @@ sort_notes( BjbController *self)
}
static void
-add_note_if_searched ( BijiNoteObj *obj , BjbController *self )
+sort_and_update (BjbController *self)
{
- gboolean add_note ;
-
- BjbControllerPrivate *priv = self->priv ;
- add_note = FALSE ;
-
- /* Title match ? */
- if (g_strrstr(g_utf8_casefold(biji_note_obj_get_title(obj),-1),
- g_utf8_casefold(priv->needle,-1)))
- add_note = TRUE ;
-
- /* Tag match ? */
- if ( _biji_note_obj_has_tag_prefix(obj,priv->needle))
- add_note = TRUE ;
-
- /* Content match? */
- if (g_strrstr(g_utf8_casefold(biji_note_get_raw_text(obj),-1),
- g_utf8_casefold(priv->needle,-1)))
- add_note = TRUE ;
+ sort_notes (self) ;
+ update_view(self);
+}
+static void
+update_controller_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GList *result;
+ BjbController *self = BJB_CONTROLLER (user_data);
- if ( add_note )
- priv->notes_to_show = g_list_append ( priv->notes_to_show, obj ) ;
+ result = biji_get_notes_with_strings_or_tag_finish (source_object, res, self->priv->book);
+ self->priv->notes_to_show = result;
+ sort_and_update (self);
}
static void
@@ -290,25 +283,11 @@ bjb_controller_apply_needle ( BjbController *self )
if ( needle == NULL || g_strcmp0 (needle,"") == 0)
{
self->priv->notes_to_show = biji_note_book_get_notes(self->priv->book);
- }
-
- /* Test which note to show */
- else
- {
- GList *all_notes ;
-
- all_notes = biji_note_book_get_notes(self->priv->book) ;
-
- g_list_foreach (all_notes,
- (GFunc) add_note_if_searched,
- self) ;
-
- g_list_free(all_notes);
-
+ sort_and_update (self);
+ return;
}
- sort_notes (self) ;
- update_view(self);
+ biji_get_notes_with_string_or_tag_async (needle, update_controller_callback, self);
}
static void
diff --git a/src/bjb-note-tag-dialog.c b/src/bjb-note-tag-dialog.c
index 38e55b5..73b1bb5 100644
--- a/src/bjb-note-tag-dialog.c
+++ b/src/bjb-note-tag-dialog.c
@@ -113,33 +113,17 @@ update_tags_model (BjbNoteTagDialog *self)
biji_get_all_tracker_tags_async (bjb_note_tag_dialog_handle_tags, self);
}
-/* TODO This two func should rather be direct call to libbiji
- * (simply biji_note_obj_*_tag)
- * It's up to libbiji to handle tracker & save */
+/* Libbiji handles tracker & saving */
static void
note_dialog_add_tag (BijiNoteObj *note, gchar *tag)
{
- g_warning ("note %s:", biji_note_obj_get_title (note));
- g_warning ("adding tag %s:", tag);
-
- if (biji_note_obj_add_tag (note, tag))
- {
- biji_note_obj_save_note (note);
- push_existing_or_new_tag_to_note (tag, note);
- }
+ biji_note_obj_add_tag (note, tag);
}
static void
note_dialog_remove_tag (BijiNoteObj *note, gchar *tag)
{
- g_warning ("note %s:", biji_note_obj_get_title (note));
- g_warning ("removing tag %s:", tag);
-
- if (biji_note_obj_remove_tag (note, tag))
- {
- biji_note_obj_save_note (note);
- remove_tag_from_note (tag, note);
- }
+ biji_note_obj_remove_tag (note, tag);
}
static void
diff --git a/src/libbiji/biji-note-book.c b/src/libbiji/biji-note-book.c
index 8357b7b..a3ce17d 100644
--- a/src/libbiji/biji-note-book.c
+++ b/src/libbiji/biji-note-book.c
@@ -25,9 +25,7 @@
struct _BijiNoteBookPrivate
{
- /* Notes & TagBooks */
GHashTable *notes;
- GList *tags;
/* Signals */
gulong note_renamed ;
@@ -67,7 +65,6 @@ biji_note_book_init (BijiNoteBook *self)
g_str_equal,
NULL,
g_object_unref);
- self->priv->tags = NULL;
}
static void
@@ -80,8 +77,6 @@ biji_note_book_finalize (GObject *object)
g_clear_object (&book->priv->load_cancellable);
g_clear_object (&book->priv->location);
-
- g_list_free (book->priv->tags); // g_list_free_full ?
g_hash_table_destroy (book->priv->notes);
G_OBJECT_CLASS (biji_note_book_parent_class)->finalize (object);
@@ -126,56 +121,6 @@ biji_note_book_get_property (GObject *object,
}
}
-/* tag books are a trial. not really necessary, but make life easier*/
-
-static void
-biji_note_book_add_tag_book(BijiNoteBook *book, TagBook *tag)
-{
- book->priv->tags = g_list_append(book->priv->tags,tag);
-}
-
-static TagBook *
-biji_tag_book_new(gchar *name)
-{
- TagBook *result = (TagBook*) g_malloc0 ( sizeof(TagBook) ) ;
-
- result->name = name ;
- result->notes = NULL ;
- result->length = 0 ;
-
- return result ;
-}
-
-static TagBook *
-biji_note_book_get_tag_book(BijiNoteBook *book, gchar *tag)
-{
- gint i;
- for (i=0 ; i < g_list_length(book->priv->tags) ; i++ )
- {
- TagBook *iter = g_list_nth_data (book->priv->tags,i) ;
-
- if ( g_strcmp0 (iter->name , tag) == 0 )
- return iter ;
- }
-
- return NULL ;
-}
-
-// Return the book or create and return a brand new book
-static TagBook *
-biji_book_get_or_create_tag_book(BijiNoteBook *book, gchar *tag)
-{
- TagBook *result = biji_note_book_get_tag_book(book,tag);
-
- if ( result == NULL )
- {
- result = biji_tag_book_new(tag);
- biji_note_book_add_tag_book(book,result);
- }
-
- return result ;
-}
-
static gboolean
title_is_unique (BijiNoteBook *book,gchar *title)
{
@@ -236,32 +181,9 @@ static void
_biji_note_book_add_one_note(BijiNoteBook *book,BijiNoteObj *note)
{
g_return_if_fail(BIJI_IS_NOTE_OBJ(note));
- gint i;
- /* Welcome to the book ! */
_biji_note_obj_set_book(note,(gpointer)book);
- // Handle tags
- GList *note_tags = _biji_note_obj_get_tags(note) ;
- for ( i=0 ; i<g_list_length (note_tags) ; i++ )
- {
- TagBook *tag_book;
- tag_book = biji_book_get_or_create_tag_book(book,
- g_list_nth_data (note_tags,i));
-
- // Handle template
- if ( note_obj_is_template(note) )
- {
- tag_book->template_note = note ;
- }
-
- else
- {
- tag_book->notes = g_list_append(tag_book->notes,note) ;
- tag_book->length ++ ;
- }
- }
-
// Add it to the list and emit signal
g_hash_table_insert (book->priv->notes,
biji_note_obj_get_path (note), note);
@@ -424,16 +346,6 @@ biji_note_book_class_init (BijiNoteBookClass *klass)
g_type_class_add_private (klass, sizeof (BijiNoteBookPrivate));
}
-void
-_biji_note_book_add_note_to_tag_book(BijiNoteBook *book,
- BijiNoteObj *note,
- gchar *tag)
-{
- TagBook *tag_book;
- tag_book = biji_book_get_or_create_tag_book(book,tag);
- tag_book->notes = g_list_append(tag_book->notes,note);
-}
-
gboolean
_note_book_remove_one_note(BijiNoteBook *book,BijiNoteObj *note)
{
@@ -455,35 +367,6 @@ _note_book_remove_one_note(BijiNoteBook *book,BijiNoteObj *note)
return FALSE;
}
-static void
-add_note_to_list_if_tag_prefix(BijiNoteObj *note,TagBook *booklet)
-{
- if ( _biji_note_obj_has_tag_prefix(note,booklet->name) )
- {
- booklet->notes = g_list_append(booklet->notes,note);
- }
-}
-
-static void
-add_note_to_list_if_no_tag (BijiNoteObj *note, GList **notes)
-{
- if ( _biji_note_obj_get_tags(note) == NULL )
- {
- *(notes) = g_list_append(*(notes),note);
- }
-}
-
-GList *
-_biji_note_book_get_no_tag_notes(BijiNoteBook *book)
-{
- GList *result = NULL ;
- GList *notes = g_hash_table_get_values (book->priv->notes);
-
- g_list_foreach (notes, (GFunc) add_note_to_list_if_no_tag, &result);
- g_list_free (notes);
- return result;
-}
-
/* Notes collection */
void note_book_append_new_note(BijiNoteBook *book,BijiNoteObj *note)
{
@@ -512,45 +395,6 @@ note_book_get_note_at_path (BijiNoteBook *book, gchar *path)
return g_hash_table_lookup (book->priv->notes, path);
}
-GList *
-biji_note_book_get_notes_with_tag (BijiNoteBook *book,gchar* tag)
-{
- g_return_val_if_fail(BIJI_IS_NOTE_BOOK(book),NULL);
-
- TagBook *tag_book = biji_book_get_or_create_tag_book(book,tag);
- return tag_book->notes ;
-}
-
-GList *
-biji_note_book_get_notes_with_tag_prefix (BijiNoteBook *book,gchar* tag)
-{
- g_return_val_if_fail(BIJI_IS_NOTE_BOOK(book),NULL);
-
- // we do create a pseudo tag book for convenience...
- TagBook booklet ;
- booklet.name = tag ;
- booklet.notes = NULL ;
-
- GList *notes;
- notes = g_hash_table_get_values (book->priv->notes);
-
- g_list_foreach (notes,(GFunc)add_note_to_list_if_tag_prefix,&booklet);
- g_list_free (notes);
- return booklet.notes ;
-}
-
-void
-biji_note_book_remove_tag(BijiNoteBook *book,gchar *tag)
-{
- GList *notes = biji_note_book_get_notes_with_tag (book,tag) ;
-
- // Remove the tag then save the note.
- g_list_foreach(notes,(GFunc) biji_note_obj_remove_tag,tag);
- g_list_foreach(notes,(GFunc) biji_note_obj_save_note,NULL);
-
- g_list_free (notes);
-}
-
BijiNoteBook *
biji_note_book_new (GFile *location)
{
diff --git a/src/libbiji/biji-note-book.h b/src/libbiji/biji-note-book.h
index 736c0d2..4ce104a 100644
--- a/src/libbiji/biji-note-book.h
+++ b/src/libbiji/biji-note-book.h
@@ -48,16 +48,10 @@ gboolean biji_note_book_remove_note(BijiNoteBook *book,BijiNoteObj *note);
BijiNoteObj * note_book_get_note_at_path(BijiNoteBook *book,gchar *path);
-void biji_note_book_remove_tag(BijiNoteBook *book,gchar *tag);
-
-/* All GLIST return values should be freed, and never the content */
+/* GList return values should be freed, and never the content */
GList * biji_note_book_get_notes (BijiNoteBook *book);
-GList * biji_note_book_get_notes_with_tag (BijiNoteBook *book,gchar* tag);
-
-GList * biji_note_book_get_notes_with_tag_prefix (BijiNoteBook *book,gchar* tag);
-
/* New Notes */
BijiNoteObj* biji_note_get_new_from_file (const gchar* tomboy_format_note_path);
diff --git a/src/libbiji/biji-note-obj.c b/src/libbiji/biji-note-obj.c
index 564eaaf..8b5c0ab 100644
--- a/src/libbiji/biji-note-obj.c
+++ b/src/libbiji/biji-note-obj.c
@@ -604,11 +604,10 @@ biji_note_obj_add_tag (BijiNoteObj *note, gchar *tag)
g_return_val_if_fail (! _biji_note_obj_has_tag (note, tag), FALSE);
note->priv->tags = g_list_prepend (note->priv->tags, g_strdup (tag));
-
- if (BIJI_IS_NOTE_BOOK (note->priv->book))
- _biji_note_book_add_note_to_tag_book (note->priv->book, note, tag);
-
+ push_existing_or_new_tag_to_note (tag, note);
biji_note_id_set_last_metadata_change_date_now (note->priv->id);
+ biji_note_obj_save_note (note);
+
return TRUE;
}
@@ -810,29 +809,28 @@ GList *biji_note_obj_get_tags(BijiNoteObj *note)
}
gboolean
-biji_note_obj_remove_tag(BijiNoteObj *note,gchar *tag)
+biji_note_obj_remove_tag (BijiNoteObj *note,gchar *tag)
{
- // If the note has tag, remove it.
- if ( _biji_note_obj_has_tag(note,tag) )
+ g_return_val_if_fail (BIJI_IS_NOTE_OBJ (note), FALSE);
+ g_return_val_if_fail (_biji_note_obj_has_tag (note, tag), FALSE);
+
+ remove_tag_from_note (tag, note); // tracker.
+
+ GList *current = biji_note_obj_get_tags (note);
+ GList *l;
+
+ for (l=current; l != NULL; l=l->next)
{
- GList *current = _biji_note_obj_get_tags(note);
- gint i ;
- gchar *to_remove = NULL ;
-
- for ( i = 0 ; i < g_list_length(current) ; i++ )
+ if (g_strcmp0 (l->data,tag) == 0)
{
- if ( g_strcmp0 (g_list_nth_data(current,i),tag) == 0 )
- {
- to_remove = g_list_nth_data(current,i);
- }
+ _biji_note_obj_set_tags (note, g_list_remove (current, l->data));
+ biji_note_id_set_last_metadata_change_date_now (note->priv->id);
+ biji_note_obj_save_note (note);
+ return TRUE;
}
-
- _biji_note_obj_set_tags(note,g_list_remove(current,to_remove));
- return TRUE ;
}
- // Else return false
- return FALSE ;
+ return FALSE;
}
gchar *
diff --git a/src/libbiji/biji-tracker.c b/src/libbiji/biji-tracker.c
index 2ec5969..fe3d93b 100644
--- a/src/libbiji/biji-tracker.c
+++ b/src/libbiji/biji-tracker.c
@@ -149,6 +149,60 @@ biji_get_all_tracker_tags_async (GAsyncReadyCallback f,
bjb_perform_query_async (query, f, user_data);
}
+GList *
+biji_get_notes_with_strings_or_tag_finish (GObject *source_object,
+ GAsyncResult *res,
+ BijiNoteBook *book)
+{
+ 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 ("%s", error->message);
+ g_error_free (error);
+ }
+
+ if (cursor)
+ {
+ gchar * uri;
+ BijiNoteObj *note = NULL;
+
+ while (tracker_sparql_cursor_next (cursor, NULL, NULL))
+ {
+ uri = g_strdup (tracker_sparql_cursor_get_string (cursor, 0, NULL));
+ note = note_book_get_note_at_path (book, uri);
+
+ /* Sorting is done in another place */
+ if (note)
+ result = g_list_prepend (result, note);
+ }
+
+ g_object_unref (cursor);
+ }
+
+ return result;
+}
+
+/* TODO : not case sensitive */
+void
+biji_get_notes_with_string_or_tag_async (gchar *needle, GAsyncReadyCallback f, gpointer user_data)
+{
+ gchar *query;
+
+ query = g_strdup_printf ("SELECT ?s WHERE {{ ?s nie:generator 'Bijiben'. \
+ ?s a nfo:Note ;nao:hasTag [nao:prefLabel'%s'] } \
+ UNION { ?s fts:match '%s'. ?s nie:generator 'Bijiben'}}",
+ needle, needle);
+
+ bjb_perform_query_async (query, f, user_data);
+ g_free (query);
+}
+
void
push_tag_to_tracker(gchar *tag)
{
diff --git a/src/libbiji/biji-tracker.h b/src/libbiji/biji-tracker.h
index 1e2dd87..66a8ce3 100644
--- a/src/libbiji/biji-tracker.h
+++ b/src/libbiji/biji-tracker.h
@@ -24,6 +24,10 @@
#include <libbiji/libbiji.h>
+/* All notes matching (either content or tag) */
+GList * biji_get_notes_with_strings_or_tag_finish (GObject *source_object, GAsyncResult *res, BijiNoteBook *book);
+void biji_get_notes_with_string_or_tag_async (gchar *needle, GAsyncReadyCallback f, gpointer user_data);
+
/* 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]