[bijiben: 7/11] bijiItem: handle more collection stuff at item level



commit f4dd06a6338da0337b5951fc3b6835f143616708
Author: Pierre-Yves Luyten <py luyten fr>
Date:   Sun Apr 28 20:59:41 2013 +0200

    bijiItem: handle more collection stuff at item level
    
    Notes and Collections should share some accessors.
    This partly fixes the note/tag dialog and prepare for next.

 src/bjb-note-tag-dialog.c                         |   17 ++++++++---------
 src/libbiji/biji-collection.c                     |   16 ++++++++++++++++
 src/libbiji/biji-item.c                           |   10 ++++++++++
 src/libbiji/biji-item.h                           |   20 ++++++++++++++++++++
 src/libbiji/biji-note-obj.c                       |   16 +++++++++++-----
 src/libbiji/biji-note-obj.h                       |    4 ----
 src/libbiji/deserializer/biji-lazy-deserializer.c |    2 +-
 7 files changed, 66 insertions(+), 19 deletions(-)
---
diff --git a/src/bjb-note-tag-dialog.c b/src/bjb-note-tag-dialog.c
index 9590f60..76a93ec 100644
--- a/src/bjb-note-tag-dialog.c
+++ b/src/bjb-note-tag-dialog.c
@@ -199,21 +199,20 @@ update_collections_model_async (BjbNoteTagDialog *self)
 static void
 note_dialog_add_tag (gpointer iter, gpointer collection)
 {
-  BijiNoteObj *note = BIJI_NOTE_OBJ (iter);
-  gchar *title = (gchar*) collection;
-
-  biji_note_obj_add_collection (note, title, TRUE);
+  biji_item_add_collection (BIJI_ITEM (iter), (gchar*) collection, TRUE);
 }
 
 static void
 note_dialog_remove_tag (gpointer iter, gpointer user_data)
 {
-  BijiNoteObj *note = BIJI_NOTE_OBJ (iter);
-  BjbNoteTagDialog *self = user_data;
-  gchar *urn = g_hash_table_lookup (self->priv->collections,
-                                    self->priv->toggled_collection);
+  BjbNoteTagDialog *self;
+  gchar *urn;
+
+  self = user_data;
+  urn = g_hash_table_lookup (self->priv->collections,
+                             self->priv->toggled_collection);
 
-  biji_note_obj_remove_collection (note, self->priv->toggled_collection, urn);
+  biji_item_remove_collection (BIJI_ITEM (iter), self->priv->toggled_collection, urn);
 }
 
 static void
diff --git a/src/libbiji/biji-collection.c b/src/libbiji/biji-collection.c
index 3361bf8..22223f7 100644
--- a/src/libbiji/biji-collection.c
+++ b/src/libbiji/biji-collection.c
@@ -206,6 +206,20 @@ biji_collection_has_collection (BijiItem *item, gchar *collection)
   return FALSE;
 }
 
+static gboolean
+biji_collection_add_collection (BijiItem *item, gchar *collection, gboolean notify)
+{
+  g_warning ("biji collection add collection is not implemented.");
+  return FALSE;
+}
+
+static gboolean
+biji_collection_remove_collection (BijiItem *item, gchar *collection, gchar *urn)
+{
+  g_warning ("biji collection remove collection is not implemented.");
+  return FALSE;
+}
+
 static void
 biji_collection_set_property (GObject      *object,
                               guint         property_id,
@@ -277,6 +291,8 @@ biji_collection_class_init (BijiCollectionClass *klass)
   item_class->get_change_sec = biji_collection_get_changed_sec;
   item_class->trash = biji_collection_trash;
   item_class->has_collection = biji_collection_has_collection;
+  item_class->add_collection = biji_collection_add_collection;
+  item_class->remove_collection = biji_collection_remove_collection;
 }
 
 
diff --git a/src/libbiji/biji-item.c b/src/libbiji/biji-item.c
index b6d88a0..b494d05 100644
--- a/src/libbiji/biji-item.c
+++ b/src/libbiji/biji-item.c
@@ -98,3 +98,13 @@ biji_item_has_collection      (BijiItem *item, gchar *coll)
 {
   return BIJI_ITEM_GET_CLASS (item)->has_collection (item, coll);
 }
+
+gboolean         biji_item_add_collection      (BijiItem *item, gchar *coll, gboolean on_user_action)
+{
+  return BIJI_ITEM_GET_CLASS (item)->add_collection (item, coll, on_user_action);
+}
+
+gboolean         biji_item_remove_collection   (BijiItem *item, gchar *coll, gchar *urn)
+{
+  return BIJI_ITEM_GET_CLASS (item)->remove_collection (item, coll, urn);
+}
diff --git a/src/libbiji/biji-item.h b/src/libbiji/biji-item.h
index 893b07a..311e21d 100644
--- a/src/libbiji/biji-item.h
+++ b/src/libbiji/biji-item.h
@@ -64,29 +64,49 @@ struct BijiItemClass_
   glong         (*get_change_sec)       (BijiItem *item);
   gboolean      (*trash)                (BijiItem *item);
   gboolean      (*has_collection)       (BijiItem *item, gchar *coll);
+  gboolean      (*add_collection)       (BijiItem *item, gchar *coll, gboolean on_user_action);
+  gboolean      (*remove_collection)    (BijiItem *item, gchar *coll, gchar *urn);
 };
 
 /* Do not create a generic items.
  * It's rather an iface */
+
 GType biji_item_get_type (void);
 
+
 /* Do not free title */
+
 gchar *          biji_item_get_title           (BijiItem *item);
 
+
 /* Always g_free uuid
  * NoteObj uuid is a location           */
+
 gchar *          biji_item_get_uuid            (BijiItem *item);
 
+
 GdkPixbuf *      biji_item_get_icon            (BijiItem *item);
 
+
 GdkPixbuf *      biji_item_get_emblem          (BijiItem *item);
 
+
 glong            biji_item_get_last_change     (BijiItem *item);
 
+
 gboolean         biji_item_trash               (BijiItem *item);
 
+
 gboolean         biji_item_has_collection      (BijiItem *item, gchar *collection);
 
+
+/* add_collection / on_user_action : thus biji_item does notify */
+
+gboolean         biji_item_add_collection      (BijiItem *item, gchar *coll, gboolean on_user_action);
+
+
+gboolean         biji_item_remove_collection   (BijiItem *item, gchar *coll, gchar *urn);
+
 G_END_DECLS
 
 #endif /* BIJI_ITEM_H_ */
diff --git a/src/libbiji/biji-note-obj.c b/src/libbiji/biji-note-obj.c
index 64d5329..d9fb807 100644
--- a/src/libbiji/biji-note-obj.c
+++ b/src/libbiji/biji-note-obj.c
@@ -85,6 +85,8 @@ static GdkPixbuf * biji_note_obj_get_emblem               (BijiItem *note);
 static gboolean    biji_note_obj_trash                    (BijiItem *note);
 static glong       biji_note_obj_get_last_change_date_sec (BijiItem *note);
 static gboolean    biji_note_obj_has_collection           (BijiItem *note, gchar *label);
+static gboolean    biji_note_obj_add_collection           (BijiItem *note, gchar *label, gboolean 
on_user_action);
+static gboolean    biji_note_obj_remove_collection        (BijiItem *note, gchar *label, gchar *urn);
 
 static void
 on_save_timeout (BijiNoteObj *self)
@@ -297,6 +299,8 @@ biji_note_obj_class_init (BijiNoteObjClass *klass)
   item_class->get_change_sec = biji_note_obj_get_last_change_date_sec;
   item_class->trash = biji_note_obj_trash;
   item_class->has_collection = biji_note_obj_has_collection;
+  item_class->add_collection = biji_note_obj_add_collection;
+  item_class->remove_collection = biji_note_obj_remove_collection;
 }
 
 BijiNoteObj *
@@ -623,12 +627,13 @@ biji_note_obj_has_collection (BijiItem *item, gchar *label)
 }
 
 gboolean
-biji_note_obj_add_collection (BijiNoteObj *note, gchar *label, gboolean on_user_action_cb)
+biji_note_obj_add_collection (BijiItem *item, gchar *label, gboolean on_user_action_cb)
 {
-  g_return_val_if_fail (BIJI_IS_NOTE_OBJ (note), FALSE);
+  g_return_val_if_fail (BIJI_IS_NOTE_OBJ (item), FALSE);
   g_return_val_if_fail (label != NULL, FALSE);
-  g_return_val_if_fail (!biji_note_obj_has_collection (BIJI_ITEM (note), label), FALSE);
+  g_return_val_if_fail (!biji_note_obj_has_collection (item, label), FALSE);
 
+  BijiNoteObj *note = BIJI_NOTE_OBJ (item);
   gchar *tag = g_strdup (label);
 
   g_hash_table_add (note->priv->labels, tag);
@@ -644,9 +649,10 @@ biji_note_obj_add_collection (BijiNoteObj *note, gchar *label, gboolean on_user_
 }
 
 gboolean
-biji_note_obj_remove_collection (BijiNoteObj *note, gchar *label, gchar *urn)
+biji_note_obj_remove_collection (BijiItem *item, gchar *label, gchar *urn)
 {
-  g_return_val_if_fail (BIJI_IS_NOTE_OBJ (note), FALSE);
+  g_return_val_if_fail (BIJI_IS_NOTE_OBJ (item), FALSE);
+  BijiNoteObj *note = BIJI_NOTE_OBJ (item);
 
   if (g_hash_table_remove (note->priv->labels, label))
   {
diff --git a/src/libbiji/biji-note-obj.h b/src/libbiji/biji-note-obj.h
index 31a1f94..577794a 100644
--- a/src/libbiji/biji-note-obj.h
+++ b/src/libbiji/biji-note-obj.h
@@ -110,10 +110,6 @@ void biji_note_obj_set_rgba(BijiNoteObj *n, GdkRGBA *rgba) ;
 
 GList * biji_note_obj_get_collections (BijiNoteObj *n);
 
-gboolean biji_note_obj_add_collection (BijiNoteObj *note, gchar *label, gboolean on_user_action_cb);
-
-gboolean biji_note_obj_remove_collection (BijiNoteObj *note, gchar *label, gchar *urn);
-
 gboolean note_obj_is_template(BijiNoteObj *n) ;
 
 void note_obj_set_is_template(BijiNoteObj *n,gboolean is_template);
diff --git a/src/libbiji/deserializer/biji-lazy-deserializer.c 
b/src/libbiji/deserializer/biji-lazy-deserializer.c
index 7985ac2..a543504 100644
--- a/src/libbiji/deserializer/biji-lazy-deserializer.c
+++ b/src/libbiji/deserializer/biji-lazy-deserializer.c
@@ -492,7 +492,7 @@ processNode (BijiLazyDeserializer *self)
     {
       norm = g_string_new (tag);
       g_string_erase (norm,0,16);
-      biji_note_obj_add_collection (n, norm->str, FALSE);
+      biji_item_add_collection (BIJI_ITEM (n), norm->str, FALSE);
       g_string_free (norm, TRUE);
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]