[bijiben] bijiNoteBook, controller : model for note trashed and color change



commit ddf48cb0fd04c24bccd44fd0649de3613c17c996
Author: Pierre-Yves Luyten <py luyten fr>
Date:   Fri Feb 15 22:30:35 2013 +0100

    bijiNoteBook, controller : model for note trashed and color change
    
    Book signals now gives a pointer to note
    Don't rebuild model when deletion
    Have a dedicated flag for color changed
    Only rebuild the whole tree if mass change

 .gitignore                       |    2 +
 src/bjb-controller.c             |   46 ++++++++++++++++++++++++--------------
 src/bjb-main-view.c              |    1 -
 src/bjb-window-base.c            |    1 -
 src/libbiji/biji-marshalers.list |    2 +-
 src/libbiji/biji-note-book.c     |   45 ++++++++++++++++++-------------------
 src/libbiji/biji-note-book.h     |    5 ++-
 src/libbiji/biji-note-obj.c      |    2 -
 8 files changed, 57 insertions(+), 47 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index b530082..bfb7385 100644
--- a/.gitignore
+++ b/.gitignore
@@ -46,6 +46,8 @@ src/bijiben
 src/libbiji.a
 src/bjb-resources*
 src/bijiben-shell-search-provider-generated*
+src/libbiji/biji-marshalers.c
+src/libbiji/biji-marshalers.h
 data/org.gnome.Bijiben.SearchProvider.service
 src/bijiben-shell-search-provider
 ChangeLog
diff --git a/src/bjb-controller.c b/src/bjb-controller.c
index 8e852b3..52527b9 100644
--- a/src/bjb-controller.c
+++ b/src/bjb-controller.c
@@ -44,6 +44,7 @@ struct _BjbControllerPrivate
 
   /*  Private  */
   GList         *notes_to_show ;
+  gboolean       connected;
   gulong         book_change;
 };
 
@@ -97,6 +98,7 @@ bjb_controller_init (BjbController *self)
   priv->model = GTK_TREE_MODEL(store) ;
   priv->notes_to_show = NULL;
   priv->needle = NULL;
+  priv->connected = FALSE;
 
   completion  = gtk_list_store_new (1, G_TYPE_STRING);
   priv->completion = GTK_TREE_MODEL (completion);
@@ -185,6 +187,7 @@ bjb_controller_add_note (BjbController *self,
   GdkPixbuf     *pix = NULL;
   gchar         *path;
 
+  g_return_if_fail (BIJI_IS_NOTE_OBJ (note));
   store = GTK_LIST_STORE (self->priv->model);
 
   if (prepend)
@@ -399,9 +402,10 @@ refresh_completion(BjbController *self)
 }
 
 static gboolean
-bjb_controller_get_iter_at_note (BjbController *self, gchar *needle, GtkTreeIter **iter)
+bjb_controller_get_iter_at_note (BjbController *self, BijiNoteObj *note, GtkTreeIter **iter)
 {
   BjbControllerPrivate *priv = self->priv;
+  gchar *needle = biji_note_obj_get_path (note);
   gboolean retval = FALSE;
   gboolean still = gtk_tree_model_get_iter_first (priv->model, *iter);
 
@@ -423,6 +427,7 @@ bjb_controller_get_iter_at_note (BjbController *self, gchar *needle, GtkTreeIter
       still = gtk_tree_model_iter_next (priv->model, *iter);
   }
 
+  g_free (needle);
   return retval;
 }
 
@@ -431,11 +436,11 @@ bjb_controller_get_iter_at_note (BjbController *self, gchar *needle, GtkTreeIter
 static void
 on_book_changed (BijiNoteBook           *book,
                  BijiNoteBookChangeFlag  flag,
-                 gchar                  *note_path,
+                 gpointer               *note_obj,
                  BjbController          *self)
 {
   BjbControllerPrivate *priv = self->priv;
-  BijiNoteObj *note;
+  BijiNoteObj *note = BIJI_NOTE_OBJ (note_obj);
   GtkTreeIter iter;
   GtkTreeIter *p_iter = &iter;
 
@@ -444,33 +449,38 @@ on_book_changed (BijiNoteBook           *book,
     /* If this is a *new* note, per def prepend
      * But do not add a new note to a search window */
     case BIJI_BOOK_NOTE_ADDED:
-      note = note_book_get_note_at_path (book, note_path);
-      if (note)
-      {
         bjb_controller_add_note_if_needed (self, note, TRUE);
         priv->notes_to_show = g_list_prepend (priv->notes_to_show, note);
-      }
       break;
 
     /* If the note is *amended*, then per definition we prepend.
      * but if we add other ordering this does not work */
     case BIJI_BOOK_NOTE_AMENDED:
-      if (bjb_controller_get_iter_at_note (self, note_path, &p_iter))
+      if (bjb_controller_get_iter_at_note (self, note, &p_iter))
       {
         gtk_list_store_remove (GTK_LIST_STORE (priv->model), p_iter);
-        note = note_book_get_note_at_path (book, note_path);
-        if (note)
-          bjb_controller_add_note_if_needed (self, note, TRUE);
+        bjb_controller_add_note_if_needed (self, note, TRUE);
       }
       break;
 
-    /* Trashed? rebuilding the whole model might be more simple */
+    /* If color changed we just amend the icon */
+    case BIJI_BOOK_NOTE_COLORED:
+      if (gd_main_view_get_view_type (priv->cur) == GD_MAIN_VIEW_ICON
+          && bjb_controller_get_iter_at_note (self, note, &p_iter))
+        gtk_list_store_set (GTK_LIST_STORE (priv->model), p_iter,
+                            COL_IMAGE, biji_note_obj_get_icon (note), -1);
+      break;
+
     case BIJI_BOOK_NOTE_TRASHED:
+      if (bjb_controller_get_iter_at_note (self, note, &p_iter))
+        gtk_list_store_remove (GTK_LIST_STORE (priv->model), p_iter);
+      break;
+
     default:
       bjb_controller_apply_needle (self);
   }
 
-  /* we refresh the whole completion model each time */
+  /* FIXME we refresh the whole completion model each time */
   refresh_completion(self);
 }
 
@@ -478,11 +488,13 @@ void
 bjb_controller_connect (BjbController *self)
 {
   BjbControllerPrivate *priv = self->priv;
-
-  /* TODO Should rather connect to notes individually
-   * and only book for new notes */
-  priv->book_change = g_signal_connect (self->priv->book, "changed",
+  
+  if (!priv->connected)
+  {
+    priv->book_change = g_signal_connect (self->priv->book, "changed",
                                      G_CALLBACK(on_book_changed), self);
+    priv->connected = TRUE;
+  }
 }
 
 void
diff --git a/src/bjb-main-view.c b/src/bjb-main-view.c
index 9357a44..89a9b83 100644
--- a/src/bjb-main-view.c
+++ b/src/bjb-main-view.c
@@ -181,7 +181,6 @@ biji_main_view_constructor (GType                  gtype,
 void
 switch_to_note_view (BjbMainView *self, BijiNoteObj *note)
 {
-  bjb_controller_disconnect (self->priv->controller);
   bjb_search_toolbar_disconnect (self->priv->search_bar);
   bjb_main_view_disconnect_handlers (self);
   bjb_note_view_new (self->priv->window, note);
diff --git a/src/bjb-window-base.c b/src/bjb-window-base.c
index 5d20eb3..1c85053 100644
--- a/src/bjb-window-base.c
+++ b/src/bjb-window-base.c
@@ -261,7 +261,6 @@ bjb_window_base_switch_to (BjbWindowBase *bwb, BjbWindowViewType type)
   {
     priv->note = NULL;
     bjb_main_view_connect_signals (priv->view);
-    bjb_controller_update_view (priv->controller);
   }
 
   gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), type);
diff --git a/src/libbiji/biji-marshalers.list b/src/libbiji/biji-marshalers.list
index f8ebf72..8d6795e 100644
--- a/src/libbiji/biji-marshalers.list
+++ b/src/libbiji/biji-marshalers.list
@@ -1 +1 @@
-VOID:ENUM,STRING
+VOID:ENUM,POINTER
diff --git a/src/libbiji/biji-note-book.c b/src/libbiji/biji-note-book.c
index 281e1d0..22a5f73 100644
--- a/src/libbiji/biji-note-book.c
+++ b/src/libbiji/biji-note-book.c
@@ -171,7 +171,7 @@ biji_note_book_get_unique_title (BijiNoteBook *book, gchar *title)
 gboolean
 biji_note_book_notify_changed (BijiNoteBook            *book,
                                BijiNoteBookChangeFlag   flag,
-                               gchar                   *note)
+                               BijiNoteObj              *note)
 {
   g_signal_emit (G_OBJECT (book), biji_book_signals[BOOK_AMENDED], 0, flag, note);
   return FALSE;
@@ -180,9 +180,13 @@ biji_note_book_notify_changed (BijiNoteBook            *book,
 void
 book_on_note_changed_cb (BijiNoteObj *note, BijiNoteBook *book)
 {
-  gchar *path = biji_note_obj_get_path (note);
-  biji_note_book_notify_changed (book, BIJI_BOOK_NOTE_AMENDED, path);
-  g_free (path);
+  biji_note_book_notify_changed (book, BIJI_BOOK_NOTE_AMENDED, note);
+}
+
+static void
+book_on_note_color_changed_cb (BijiNoteObj *note, BijiNoteBook *book)
+{
+  biji_note_book_notify_changed (book, BIJI_BOOK_NOTE_COLORED, note);
 }
 
 static void
@@ -198,6 +202,7 @@ _biji_note_book_add_one_note(BijiNoteBook *book,BijiNoteObj *note)
 
   g_signal_connect (note, "changed", G_CALLBACK (book_on_note_changed_cb), book);
   g_signal_connect (note, "renamed", G_CALLBACK (book_on_note_changed_cb), book);
+  g_signal_connect (note, "color-changed", G_CALLBACK (book_on_note_color_changed_cb), book);
 }
 
 #define ATTRIBUTES_FOR_NOTEBOOK "standard::content-type,standard::name"
@@ -349,8 +354,8 @@ biji_note_book_class_init (BijiNoteBookClass *klass)
   biji_book_signals[BOOK_AMENDED] =
     g_signal_new ("changed", G_OBJECT_CLASS_TYPE (klass), G_SIGNAL_RUN_LAST,
                   0, NULL, NULL,                         /* offset & accumulator */
-                  _biji_marshal_VOID__ENUM_STRING,
-                  G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_STRING);
+                  _biji_marshal_VOID__ENUM_POINTER,
+                  G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_POINTER);
 
   properties[PROP_LOCATION] =
     g_param_spec_object("location",
@@ -363,9 +368,12 @@ biji_note_book_class_init (BijiNoteBookClass *klass)
   g_type_class_add_private (klass, sizeof (BijiNoteBookPrivate));
 }
 
-gboolean
-_note_book_remove_one_note(BijiNoteBook *book,BijiNoteObj *note)
+gboolean 
+biji_note_book_remove_note (BijiNoteBook *book, BijiNoteObj *note)
 {
+  g_return_val_if_fail (BIJI_IS_NOTE_BOOK (book), FALSE);
+  g_return_val_if_fail (BIJI_IS_NOTE_OBJ  (note), FALSE);
+
   BijiNoteObj *to_delete = NULL;
   gchar *path;
   gboolean retval = FALSE;
@@ -375,11 +383,15 @@ _note_book_remove_one_note(BijiNoteBook *book,BijiNoteObj *note)
 
   if (to_delete)
   {
+    /* Signal before doing anything here. So the note is still
+     * fully available for signal receiver. */
+    biji_note_book_notify_changed (book, BIJI_BOOK_NOTE_TRASHED, to_delete);
+
     /* Ref note first, hash_table won't finalize it & we can delete it*/
     g_object_ref (to_delete);
     g_hash_table_remove (book->priv->notes, path);
     biji_note_obj_trash (note);
-    biji_note_book_notify_changed (book, BIJI_BOOK_NOTE_TRASHED, path);
+
     retval = TRUE;
   }
 
@@ -397,20 +409,7 @@ biji_note_book_append_new_note (BijiNoteBook *book, BijiNoteObj *note, gboolean
   _biji_note_book_add_one_note (book,note);
 
   if (notify)
-  {
-    gchar *path = biji_note_obj_get_path (note);
-    biji_note_book_notify_changed (book, BIJI_BOOK_NOTE_ADDED, path);
-    g_free (path);
-  }
-}
-
-gboolean 
-biji_note_book_remove_note(BijiNoteBook *book,BijiNoteObj *note)
-{
-  g_return_val_if_fail(BIJI_IS_NOTE_BOOK(book),FALSE);
-  g_return_val_if_fail(BIJI_IS_NOTE_OBJ(note),FALSE);
-
-  return _note_book_remove_one_note(book,note);
+    biji_note_book_notify_changed (book, BIJI_BOOK_NOTE_ADDED, note);
 }
  
 GList *
diff --git a/src/libbiji/biji-note-book.h b/src/libbiji/biji-note-book.h
index 0dfea72..bd956c6 100644
--- a/src/libbiji/biji-note-book.h
+++ b/src/libbiji/biji-note-book.h
@@ -15,7 +15,8 @@ typedef enum
   BIJI_BOOK_CHANGE_FLAG,
   BIJI_BOOK_MASS_CHANGE,   // Startup, mass import.. rather rebuild the whole.
   BIJI_BOOK_NOTE_ADDED,    // Single note added
-  BIJI_BOOK_NOTE_AMENDED,  // Single note amended (title, color,...)
+  BIJI_BOOK_NOTE_AMENDED,  // Single note amended (title, content)
+  BIJI_BOOK_NOTE_COLORED,  // Single note color
   BIJI_BOOK_NOTE_TRASHED,  // Single note trashed
 } BijiNoteBookChangeFlag;
 
@@ -56,7 +57,7 @@ void biji_note_book_append_new_note (BijiNoteBook *book, BijiNoteObj *note, gboo
 
 gboolean biji_note_book_notify_changed (BijiNoteBook           *book,
                                         BijiNoteBookChangeFlag  flag,
-                                        gchar                  *note);
+                                        BijiNoteObj            *note);
 
 gboolean biji_note_book_remove_note(BijiNoteBook *book,BijiNoteObj *note);
 
diff --git a/src/libbiji/biji-note-obj.c b/src/libbiji/biji-note-obj.c
index ae7fc24..9e5d3ea 100644
--- a/src/libbiji/biji-note-obj.c
+++ b/src/libbiji/biji-note-obj.c
@@ -507,9 +507,7 @@ biji_note_obj_set_rgba_internal (BijiNoteObj *n, GdkRGBA *rgba)
   n->priv->color = gdk_rgba_copy(rgba);
   n->priv->icon_needs_update = TRUE;
 
-  /* Make editor & notebook know about this change */
   g_signal_emit (G_OBJECT (n), biji_obj_signals[NOTE_COLOR_CHANGED],0);
-  g_signal_emit (G_OBJECT (n), biji_obj_signals[NOTE_CHANGED],0);
 }
 
 


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