[bijiben] trash : plug a deleted signal when an item is definitely deleted



commit 7eda49247e793bd3379e241e996acd6daf7d3aeb
Author: Pierre-Yves Luyten <py luyten fr>
Date:   Mon Dec 9 01:08:49 2013 +0100

    trash : plug a deleted signal when an item is definitely deleted
    
    The view removes the item.

 src/bjb-controller.c       |    3 ++
 src/bjb-trash-bar.c        |   11 ++++--
 src/libbiji/biji-item.c    |   69 ++++++++++++++++++++++++++++++++++++++++++--
 src/libbiji/biji-manager.c |   13 +++++++-
 src/libbiji/biji-manager.h |    1 +
 5 files changed, 89 insertions(+), 8 deletions(-)
---
diff --git a/src/bjb-controller.c b/src/bjb-controller.c
index b60ded5..bad9743 100644
--- a/src/bjb-controller.c
+++ b/src/bjb-controller.c
@@ -616,6 +616,8 @@ on_manager_changed (BijiManager            *manager,
                             GD_MAIN_COLUMN_ICON, biji_item_get_emblem (item), -1);
       break;
 
+    case BIJI_MANAGER_ITEM_DELETED:
+      g_warning ("on item deleted");
     case BIJI_MANAGER_ITEM_TRASHED:
       if (bjb_controller_get_iter (self, item, &p_iter))
         gtk_list_store_remove (GTK_LIST_STORE (priv->model), p_iter);
@@ -624,6 +626,7 @@ on_manager_changed (BijiManager            *manager,
       notify_displayed_items_changed (self);
       break;
 
+
     default:
       bjb_controller_apply_needle (self);
       if (flag == BIJI_MANAGER_MASS_CHANGE)
diff --git a/src/bjb-trash-bar.c b/src/bjb-trash-bar.c
index ba952bf..3b54606 100644
--- a/src/bjb-trash-bar.c
+++ b/src/bjb-trash-bar.c
@@ -67,10 +67,10 @@ G_DEFINE_TYPE (BjbTrashBar, bjb_trash_bar, GTK_TYPE_BOX)
 static void
 on_empty_clicked_callback        (BjbTrashBar *self)
 {
-  GList *selection;
 
-  selection = bjb_main_view_get_selected_items (self->priv->view);
-  g_list_free (selection);
+  biji_manager_empty_bin (
+    bjb_window_base_get_manager (
+      gtk_widget_get_toplevel (GTK_WIDGET (self))));
 }
 
 
@@ -87,9 +87,12 @@ on_restore_clicked_callback      (BjbTrashBar *self)
 static void
 on_delete_clicked_callback        (BjbTrashBar *self)
 {
-  GList *selection;
+  GList *selection, *l;
 
   selection = bjb_main_view_get_selected_items (self->priv->view);
+  for (l=selection; l!=NULL; l=l->next)
+    biji_item_delete (BIJI_ITEM (l->data));
+
   g_list_free (selection);
 }
 
diff --git a/src/libbiji/biji-item.c b/src/libbiji/biji-item.c
index 87a0854..6897e0d 100644
--- a/src/libbiji/biji-item.c
+++ b/src/libbiji/biji-item.c
@@ -31,6 +31,17 @@ enum {
 static GParamSpec *properties[BIJI_ITEM_PROP] = { NULL, };
 
 
+/* Signals */
+enum {
+  ITEM_TRASHED,
+  ITEM_DELETED,
+  ITEM_RESTORED,
+  BIJI_ITEM_SIGNALS
+};
+
+static guint biji_item_signals [BIJI_ITEM_SIGNALS] = { 0 };
+
+
 struct BijiItemPrivate_
 {
   BijiManager *manager;
@@ -101,6 +112,40 @@ biji_item_class_init (BijiItemClass *klass)
 
   g_object_class_install_properties (g_object_class, BIJI_ITEM_PROP, properties);
 
+
+  biji_item_signals[ITEM_DELETED] =
+    g_signal_new ("deleted",
+                  G_OBJECT_CLASS_TYPE (klass),
+                  G_SIGNAL_RUN_LAST,
+                  0,
+                  NULL,
+                  NULL,
+                  g_cclosure_marshal_VOID__VOID,
+                  G_TYPE_NONE,
+                  0);
+
+  biji_item_signals[ITEM_TRASHED] =
+    g_signal_new ("trashed",
+                  G_OBJECT_CLASS_TYPE (klass),
+                  G_SIGNAL_RUN_LAST,
+                  0,
+                  NULL,
+                  NULL,
+                  g_cclosure_marshal_VOID__VOID,
+                  G_TYPE_NONE,
+                  0);
+
+  biji_item_signals[ITEM_RESTORED] =
+    g_signal_new ("restored",
+                  G_OBJECT_CLASS_TYPE (klass),
+                  G_SIGNAL_RUN_LAST,
+                  0,
+                  NULL,
+                  NULL,
+                  g_cclosure_marshal_VOID__VOID,
+                  G_TYPE_NONE,
+                  0);
+
   g_type_class_add_private ((gpointer)klass, sizeof (BijiItemPrivate));
 }
 
@@ -199,18 +244,30 @@ biji_item_has_color           (BijiItem *item)
 gboolean
 biji_item_trash               (BijiItem *item)
 {
+  gboolean retval;
+
+
   g_return_val_if_fail (BIJI_IS_ITEM (item), FALSE);
 
-  return BIJI_ITEM_GET_CLASS (item)->trash (item);
+  retval = BIJI_ITEM_GET_CLASS (item)->trash (item);
+  if (retval == TRUE)
+    g_signal_emit_by_name (item, "trashed", NULL);
+
+  return retval;
 }
 
 
 gboolean
 biji_item_restore             (BijiItem *item)
 {
+  gboolean retval;
   g_return_val_if_fail (BIJI_IS_ITEM (item), FALSE);
 
-  return BIJI_ITEM_GET_CLASS (item)->restore (item);
+  retval = BIJI_ITEM_GET_CLASS (item)->restore (item);
+  if (retval == TRUE)
+    g_signal_emit_by_name (item, "restored", NULL);
+
+  return retval;
 }
 
 
@@ -218,9 +275,15 @@ biji_item_restore             (BijiItem *item)
 gboolean
 biji_item_delete               (BijiItem *item)
 {
+  gboolean retval;
+
   g_return_val_if_fail (BIJI_IS_ITEM (item), FALSE);
 
-  return BIJI_ITEM_GET_CLASS (item)->delete (item);
+  retval = BIJI_ITEM_GET_CLASS (item)->delete (item);
+  if (retval == TRUE)
+    g_signal_emit_by_name (item, "deleted", NULL);
+
+  return retval;
 }
 
 
diff --git a/src/libbiji/biji-manager.c b/src/libbiji/biji-manager.c
index 12d6dd7..fe5436b 100644
--- a/src/libbiji/biji-manager.c
+++ b/src/libbiji/biji-manager.c
@@ -288,6 +288,15 @@ biji_manager_notify_changed (BijiManager            *manager,
 }
 
 
+static void
+on_item_deleted_cb (BijiItem *item, BijiManager *manager)
+{
+  biji_manager_notify_changed (manager,
+                               BIJI_ARCHIVED_ITEMS,
+                               BIJI_MANAGER_ITEM_DELETED,
+                               item);
+}
+
 
 void
 manager_on_note_changed_cb (BijiNoteObj *note, BijiManager *manager)
@@ -351,6 +360,8 @@ biji_manager_add_item (BijiManager *manager,
                            (gpointer) biji_item_get_uuid (item), item);
 
     /* Connect */
+    g_signal_connect (item, "deleted", G_CALLBACK (on_item_deleted_cb), manager);
+
     if (BIJI_IS_NOTE_OBJ (item))
     {
       g_signal_connect (item, "changed", G_CALLBACK (manager_on_note_changed_cb), manager);
@@ -640,7 +651,7 @@ _delete_item (gpointer key,
 }
 
 
-
+void
 biji_manager_empty_bin              (BijiManager        *manager)
 {
   g_hash_table_foreach (manager->priv->archives, _delete_item, NULL);
diff --git a/src/libbiji/biji-manager.h b/src/libbiji/biji-manager.h
index 9524770..5aa73af 100644
--- a/src/libbiji/biji-manager.h
+++ b/src/libbiji/biji-manager.h
@@ -23,6 +23,7 @@ typedef enum
   BIJI_MANAGER_MASS_CHANGE,        // Startup, mass import.. rather rebuild the whole.
   BIJI_MANAGER_ITEM_ADDED,         // Single item added
   BIJI_MANAGER_ITEM_TRASHED,       // Single item trashed
+  BIJI_MANAGER_ITEM_DELETED,       // Single item deleted
   BIJI_MANAGER_ITEM_ICON_CHANGED,  // Single item icon
   BIJI_MANAGER_NOTE_AMENDED,       // Single note amended (title, content)
 } BijiManagerChangeFlag;


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