[bijiben] collections: also refresh icons when notes are removed



commit 43219f59bb0d42a45a7f76c85e590e326101db64
Author: Pierre-Yves Luyten <py luyten fr>
Date:   Mon May 13 03:06:58 2013 +0200

    collections: also refresh icons when notes are removed
    
    Use the same principle as for adding items to collections

 src/bjb-note-tag-dialog.c     |   14 ++++----------
 src/libbiji/biji-collection.c |    2 +-
 src/libbiji/biji-item.c       |    4 ++--
 src/libbiji/biji-item.h       |    4 ++--
 src/libbiji/biji-note-obj.c   |   10 +++++++---
 src/libbiji/biji-tracker.c    |   14 +++++++++++---
 src/libbiji/biji-tracker.h    |    9 ++++++---
 7 files changed, 33 insertions(+), 24 deletions(-)
---
diff --git a/src/bjb-note-tag-dialog.c b/src/bjb-note-tag-dialog.c
index bf19c9d..6d724c0 100644
--- a/src/bjb-note-tag-dialog.c
+++ b/src/bjb-note-tag-dialog.c
@@ -211,16 +211,10 @@ note_dialog_add_collection (gpointer iter, gpointer user_data)
 
 
 static void
-note_dialog_remove_tag (gpointer iter, gpointer user_data)
+note_dialog_remove_collection (gpointer iter, gpointer user_data)
 {
-  BjbNoteTagDialog *self;
-  BijiTrackerInfoSet *set;
-
-  self = user_data;
-  set = g_hash_table_lookup (self->priv->collections,
-                             self->priv->toggled_collection);
-
-  biji_item_remove_collection (BIJI_ITEM (iter), set->title, set->urn);
+  g_return_if_fail (BIJI_IS_COLLECTION (user_data));
+  biji_item_remove_collection (iter, user_data);
 }
 
 static void
@@ -258,7 +252,7 @@ on_tag_toggled (GtkCellRendererToggle *cell,
 
     else
     {
-      g_list_foreach (priv->items, note_dialog_remove_tag, self);
+      g_list_foreach (priv->items, note_dialog_remove_collection, collection);
       toggle_item = SELECTION_FALSE;
     }
   }
diff --git a/src/libbiji/biji-collection.c b/src/libbiji/biji-collection.c
index 804cdb3..df7f1e2 100644
--- a/src/libbiji/biji-collection.c
+++ b/src/libbiji/biji-collection.c
@@ -284,7 +284,7 @@ biji_collection_add_collection (BijiItem *item, BijiItem *coll, gchar *title)
 
 
 static gboolean
-biji_collection_remove_collection (BijiItem *item, gchar *collection, gchar *urn)
+biji_collection_remove_collection (BijiItem *item, BijiItem *collection)
 {
   g_warning ("biji collection remove collection is not implemented.");
   return FALSE;
diff --git a/src/libbiji/biji-item.c b/src/libbiji/biji-item.c
index 607c9c3..e1bac66 100644
--- a/src/libbiji/biji-item.c
+++ b/src/libbiji/biji-item.c
@@ -112,7 +112,7 @@ gboolean         biji_item_add_collection      (BijiItem *item, BijiItem *coll,
   return BIJI_ITEM_GET_CLASS (item)->add_collection (item, coll, title);
 }
 
-gboolean         biji_item_remove_collection   (BijiItem *item, gchar *coll, gchar *urn)
+gboolean         biji_item_remove_collection   (BijiItem *item, BijiItem *collection)
 {
-  return BIJI_ITEM_GET_CLASS (item)->remove_collection (item, coll, urn);
+  return BIJI_ITEM_GET_CLASS (item)->remove_collection (item, collection);
 }
diff --git a/src/libbiji/biji-item.h b/src/libbiji/biji-item.h
index 75f634d..29d7820 100644
--- a/src/libbiji/biji-item.h
+++ b/src/libbiji/biji-item.h
@@ -66,7 +66,7 @@ struct BijiItemClass_
   gboolean      (*trash)                (BijiItem *item);
   gboolean      (*has_collection)       (BijiItem *item, gchar *coll);
   gboolean      (*add_collection)       (BijiItem *item, BijiItem *coll, gchar *title);
-  gboolean      (*remove_collection)    (BijiItem *item, gchar *coll, gchar *urn);
+  gboolean      (*remove_collection)    (BijiItem *item, BijiItem *coll);
 };
 
 /* Do not create a generic items, it's rather an iface
@@ -114,7 +114,7 @@ gboolean         biji_item_add_collection  (BijiItem *item, BijiItem *collection
 /* Remove Collection:
  * always on user action. */
 
-gboolean         biji_item_remove_collection   (BijiItem *item, gchar *coll, gchar *urn);
+gboolean         biji_item_remove_collection   (BijiItem *item, BijiItem *collection);
 
 G_END_DECLS
 
diff --git a/src/libbiji/biji-note-obj.c b/src/libbiji/biji-note-obj.c
index 0ea690e..25684e7 100644
--- a/src/libbiji/biji-note-obj.c
+++ b/src/libbiji/biji-note-obj.c
@@ -570,15 +570,19 @@ biji_note_obj_add_collection (BijiItem *item,
   return TRUE;
 }
 
+
 gboolean
-biji_note_obj_remove_collection (BijiItem *item, gchar *label, gchar *urn)
+biji_note_obj_remove_collection (BijiItem *item, BijiItem *collection)
 {
   g_return_val_if_fail (BIJI_IS_NOTE_OBJ (item), FALSE);
+  g_return_val_if_fail (BIJI_IS_COLLECTION (collection), FALSE);
+
   BijiNoteObj *note = BIJI_NOTE_OBJ (item);
 
-  if (g_hash_table_remove (note->priv->labels, label))
+  if (g_hash_table_remove (note->priv->labels, biji_item_get_title (collection)))
   {
-    biji_remove_collection_from_note (note, urn); // tracker.
+    biji_remove_collection_from_note (
+      note, collection, (BijiFunc) 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 5c518a7..77fb080 100644
--- a/src/libbiji/biji-tracker.c
+++ b/src/libbiji/biji-tracker.c
@@ -499,12 +499,20 @@ biji_push_existing_collection_to_note (BijiNoteObj *note,
 
 /* This one is to be fixed */
 void
-biji_remove_collection_from_note (BijiNoteObj *note, gchar *urn)
+biji_remove_collection_from_note (BijiNoteObj    *note,
+                                  BijiItem       *coll,
+                                  BijiFunc        afterward,
+                                  gpointer        user_data)
 {
   gchar *url = get_note_url (note);
-  gchar *query = g_strdup_printf ("DELETE {'%s' nie:isPartOf '%s'}", urn, url);
+  gchar *query = g_strconcat ("DELETE {'",
+                              biji_item_get_uuid (coll),
+                              "' nie:isPartOf '",
+                              url,
+                              "'}",
+                              NULL);
 
-  biji_perform_update_async_and_free (query, NULL, NULL);
+  biji_perform_update_async_and_free (query, afterward, user_data);
   g_free (url);
 }
 
diff --git a/src/libbiji/biji-tracker.h b/src/libbiji/biji-tracker.h
index 3fa6ce6..a5c7e21 100644
--- a/src/libbiji/biji-tracker.h
+++ b/src/libbiji/biji-tracker.h
@@ -77,14 +77,17 @@ void biji_create_new_collection_async (BijiNoteBook *book, const gchar *tag, Bij
 
 void biji_remove_collection_from_tracker (const gchar *urn);
 
-// when adding an existing collection, use the collection title
+
 void biji_push_existing_collection_to_note (BijiNoteObj *note,
                                             gchar       *title,
                                             BijiFunc     callback,
                                             gpointer     user_data);
 
-// when removing, use the urn
-void biji_remove_collection_from_note (BijiNoteObj *note, gchar *urn);
+
+void biji_remove_collection_from_note      (BijiNoteObj    *note,
+                                            BijiItem       *coll,
+                                            BijiFunc        afterward,
+                                            gpointer        user_data);
 
 /* Insert or update */
 void bijiben_push_note_to_tracker(BijiNoteObj *note);


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