From 84beea9108bd00722202e5bdbb7f663cf35da760 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Wed, 19 Jan 2011 21:58:26 +0100 Subject: [PATCH] Add KatzeArray::update and call it after import This new function and according signal allow one update of the treeview after importing directly into the database. --- katze/katze-array.c | 42 ++++++++++++++++++++++++++++++++++++++- katze/katze-array.h | 3 +++ midori/midori-browser.c | 1 + panels/midori-bookmarks.c | 13 ++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/katze/katze-array.c b/katze/katze-array.c index 35bc5376..76638df0 100644 --- a/katze/katze-array.c +++ b/katze/katze-array.c @@ -1,5 +1,5 @@ /* - Copyright (C) 2008-2010 Christian Dywan + Copyright (C) 2008-2011 Christian Dywan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -50,6 +50,9 @@ struct _KatzeArrayClass gint index); void (*clear) (KatzeArray* array); + + void + (*update) (KatzeArray* array); }; G_DEFINE_TYPE (KatzeArray, katze_array, KATZE_TYPE_ITEM); @@ -59,6 +62,7 @@ enum { REMOVE_ITEM, MOVE_ITEM, CLEAR, + UPDATE, LAST_SIGNAL }; @@ -175,6 +179,25 @@ katze_array_class_init (KatzeArrayClass* class) g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + /** + * KatzeArray::update: + * @array: the object on which the signal is emitted + * + * The array changed and any display widgets should + * be updated. + * + * Since: 0.3.0 + **/ + signals[UPDATE] = g_signal_new ( + "update", + G_TYPE_FROM_CLASS (class), + (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + 0, + 0, + NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + gobject_class = G_OBJECT_CLASS (class); gobject_class->finalize = katze_array_finalize; @@ -485,3 +508,20 @@ katze_array_clear (KatzeArray* array) g_signal_emit (array, signals[CLEAR], 0); } + +/** + * katze_array_update: + * @array: a #KatzeArray + * + * Indicates that the array changed and any display + * widgets should be updated. + * + * Since: 0.3.0 + **/ +void +katze_array_update (KatzeArray* array) +{ + g_return_if_fail (KATZE_IS_ARRAY (array)); + + g_signal_emit (array, signals[UPDATE], 0); +} diff --git a/katze/katze-array.h b/katze/katze-array.h index 0593bec0..a2f601c4 100644 --- a/katze/katze-array.h +++ b/katze/katze-array.h @@ -119,6 +119,9 @@ extern GList* kalistglobal; void katze_array_clear (KatzeArray* array); +void +katze_array_update (KatzeArray* array); + G_END_DECLS #endif /* __KATZE_ARRAY_H__ */ diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 0e78307d..802806a3 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -4118,6 +4118,7 @@ _action_bookmarks_import_activate (GtkAction* action, g_error_free (error); } midori_bookmarks_import_array_db (db, browser->bookmarks, selected); + katze_array_update (browser->bookmarks); g_free (selected); g_free (path); } diff --git a/panels/midori-bookmarks.c b/panels/midori-bookmarks.c index 3e0924f0..d8c70da1 100644 --- a/panels/midori-bookmarks.c +++ b/panels/midori-bookmarks.c @@ -309,6 +309,17 @@ midori_bookmarks_remove_item_cb (KatzeArray* array, GTK_TREE_STORE (model), NULL, NULL, bookmarks->filter); } +static void +midori_bookmarks_update_cb (KatzeArray* array, + MidoriBookmarks* bookmarks) +{ + GtkTreeModel* model = gtk_tree_view_get_model (GTK_TREE_VIEW (bookmarks->treeview)); + gtk_tree_store_clear (GTK_TREE_STORE (model)); + midori_bookmarks_read_from_db_to_model (bookmarks, + GTK_TREE_STORE (model), NULL, NULL, bookmarks->filter); +} + + static void midori_bookmarks_row_changed_cb (GtkTreeModel* model, GtkTreePath* path, @@ -498,6 +509,8 @@ midori_bookmarks_set_app (MidoriBookmarks* bookmarks, G_CALLBACK (midori_bookmarks_add_item_cb), bookmarks); g_signal_connect (bookmarks->array, "remove-item", G_CALLBACK (midori_bookmarks_remove_item_cb), bookmarks); + g_signal_connect (bookmarks->array, "update", + G_CALLBACK (midori_bookmarks_update_cb), bookmarks); g_signal_connect_after (model, "row-changed", G_CALLBACK (midori_bookmarks_row_changed_cb), bookmarks);