[bijiben] bjbController: do not refresh the model while hidden
- From: Pierre-Yves Luyten <pyluyten src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben] bjbController: do not refresh the model while hidden
- Date: Wed, 13 Feb 2013 23:50:37 +0000 (UTC)
commit 5176619f9868383a8501618d67894e61f7970923
Author: Pierre-Yves Luyten <py luyten fr>
Date: Sun Feb 10 01:12:04 2013 +0100
bjbController: do not refresh the model while hidden
While editing a note, the main view is hidden, thus refreshing the model has no sense. The counterpart is
to refresh the model when switching back to main view.
src/bjb-controller.c | 36 +++++++++++++++++++++++++-----------
src/bjb-controller.h | 6 ++++++
src/bjb-main-view.c | 7 ++++++-
src/bjb-window-base.c | 8 ++++++++
4 files changed, 45 insertions(+), 12 deletions(-)
---
diff --git a/src/bjb-controller.c b/src/bjb-controller.c
index 751fe8a..f004c73 100644
--- a/src/bjb-controller.c
+++ b/src/bjb-controller.c
@@ -44,6 +44,7 @@ struct _BjbControllerPrivate
/* Private */
GList *notes_to_show ;
+ gulong book_change;
};
enum {
@@ -223,8 +224,8 @@ bjb_controller_add_note ( BijiNoteObj *note, BjbController *self )
}
}
-static void
-update_view (BjbController *self)
+void
+bjb_controller_update_view (BjbController *self)
{
GList *notes ;
@@ -259,7 +260,7 @@ static void
sort_and_update (BjbController *self)
{
sort_notes (self) ;
- update_view(self);
+ bjb_controller_update_view (self);
}
static void
@@ -340,17 +341,30 @@ on_book_changed ( BijiNoteBook *book, BjbController *self )
bjb_controller_apply_needle (self);
}
+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",
+ G_CALLBACK(on_book_changed), self);
+}
+
+void
+bjb_controller_disconnect (BjbController *self)
+{
+ BjbControllerPrivate *priv = self->priv;
+
+ g_signal_handler_disconnect (priv->book, priv->book_change);
+ priv->book_change = 0;
+}
+
static void
bjb_controller_constructed (GObject *obj)
{
- BjbController *self = BJB_CONTROLLER (obj);
-
G_OBJECT_CLASS(bjb_controller_parent_class)->constructed(obj);
-
- /* Rather connect to notes individually
- * and only book for new notes */
- g_signal_connect (self->priv->book, "changed",
- G_CALLBACK(on_book_changed), self);
}
static void
@@ -456,7 +470,7 @@ bjb_controller_set_main_view (BjbController *self, GdMainView *current)
{
/* Refresh the model */
self->priv->cur = current;
- update_view(self);
+ bjb_controller_update_view (self);
}
diff --git a/src/bjb-controller.h b/src/bjb-controller.h
index e3050b1..450eeca 100644
--- a/src/bjb-controller.h
+++ b/src/bjb-controller.h
@@ -71,6 +71,8 @@ enum
BjbController * bjb_controller_new ( BijiNoteBook *book, gchar *needle ) ;
+void bjb_controller_update_view (BjbController *self);
+
void bjb_controller_set_book (BjbController * self, BijiNoteBook * book ) ;
void bjb_controller_set_needle (BjbController *self, const gchar *needle ) ;
@@ -81,6 +83,10 @@ GtkTreeModel * bjb_controller_get_model (BjbController *self) ;
GtkTreeModel * bjb_controller_get_completion(BjbController *self);
+void bjb_controller_connect (BjbController *self);
+
+void bjb_controller_disconnect (BjbController *self);
+
void bjb_controller_set_main_view (BjbController *self, GdMainView *current);
G_END_DECLS
diff --git a/src/bjb-main-view.c b/src/bjb-main-view.c
index 7fa9d6e..73a6af9 100644
--- a/src/bjb-main-view.c
+++ b/src/bjb-main-view.c
@@ -184,6 +184,7 @@ 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);
@@ -253,6 +254,7 @@ action_tag_selected_notes (GtkWidget *w, BjbMainView *view)
gchar *url = get_note_url_from_tree_path (l->data, view) ;
notes = g_list_prepend (notes, note_book_get_note_at_path
(bjb_window_base_get_book(view->priv->window),url));
+ g_free (url);
}
g_list_free_full (paths, (GDestroyNotify) gtk_tree_path_free);
@@ -271,6 +273,7 @@ bjb_main_view_get_selected_notes_color (BjbMainView *view, GdkRGBA *color)
paths = get_selected_paths(view);
url = get_note_url_from_tree_path (paths->data, view) ;
note = note_book_get_note_at_path (bjb_window_base_get_book(view->priv->window), url);
+ g_free (url);
g_list_free_full (paths, (GDestroyNotify) gtk_tree_path_free);
return biji_note_obj_get_rgba (note, color);
@@ -293,6 +296,7 @@ action_color_selected_notes (GtkWidget *w, BjbMainView *view)
gchar *url = get_note_url_from_tree_path (l->data, view) ;
notes = g_list_prepend (notes, note_book_get_note_at_path
(bjb_window_base_get_book(view->priv->window),url));
+ g_free (url);
}
g_list_free_full (paths, (GDestroyNotify) gtk_tree_path_free);
@@ -319,7 +323,7 @@ action_delete_selected_notes(GtkWidget *w,BjbMainView *view)
gchar *url = get_note_url_from_tree_path (l->data, view) ;
notes = g_list_prepend (notes, note_book_get_note_at_path
(bjb_window_base_get_book(view->priv->window),url));
-
+ g_free (url);
}
g_list_free_full (paths, (GDestroyNotify) gtk_tree_path_free);
@@ -465,6 +469,7 @@ bjb_main_view_connect_signals (BjbMainView *self)
{
BjbMainViewPriv *priv = self->priv;
+ bjb_controller_connect (priv->controller);
bjb_search_toolbar_connect (priv->search_bar);
priv->key = g_signal_connect (priv->window, "key-press-event",
diff --git a/src/bjb-window-base.c b/src/bjb-window-base.c
index c9a739c..0bb7a16 100644
--- a/src/bjb-window-base.c
+++ b/src/bjb-window-base.c
@@ -63,6 +63,7 @@ bjb_window_base_finalize (GObject *object)
BjbWindowBasePriv *priv = self->priv;
g_clear_object (&priv->controller);
+ g_clear_object (&priv->view);
G_OBJECT_CLASS (bjb_window_base_parent_class)->finalize (object);
}
@@ -77,9 +78,12 @@ bjb_window_base_class_init (BjbWindowBaseClass *klass)
g_type_class_add_private (klass, sizeof (BjbWindowBasePriv));
}
+/* Just disconnect to avoid crash, the finalize does the real
+ * job */
static void
bjb_window_base_destroy (gpointer a, BjbWindowBase * self)
{
+ bjb_controller_disconnect (self->priv->controller);
}
/* Gobj */
@@ -249,10 +253,14 @@ bjb_window_base_switch_to (BjbWindowBase *bwb, BjbWindowViewType type)
{
BjbWindowBasePriv *priv = bwb->priv;
+ /* Precise the window does not display any specific note
+ * Refresh the model
+ * Ensure the main view receives the proper signals */
if (type == MAIN_VIEW)
{
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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]