From 34d7a8033bf718a815130e8a7e682cdeae1485e2 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Sat, 31 Jul 2010 01:42:14 +0200 Subject: [PATCH] Use KatzeArray* to signal new items to MidoriHistory --- midori/midori-browser.c | 4 ++++ panels/midori-history.c | 51 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 91b6d9e1..f3d1d71a 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -5389,6 +5389,10 @@ midori_browser_new_history_item (MidoriBrowser* browser, sqlite3_errmsg (db)); sqlite3_reset (stmt); sqlite3_clear_bindings (stmt); + + /* FIXME: Workaround for the lack of a database interface */ + katze_array_add_item (browser->history, item); + katze_array_remove_item (browser->history, item); } static void diff --git a/panels/midori-history.c b/panels/midori-history.c index d8aed73f..f681ddc3 100644 --- a/panels/midori-history.c +++ b/panels/midori-history.c @@ -408,6 +408,51 @@ midori_history_viewable_iface_init (MidoriViewableIface* iface) iface->get_toolbar = midori_history_get_toolbar; } +static void +midori_history_add_item_cb (KatzeArray* array, + KatzeItem* item, + MidoriHistory* history) +{ + GtkTreeView* treeview = GTK_TREE_VIEW (history->treeview); + GtkTreeModel* model = gtk_tree_view_get_model (treeview); + GtkTreeIter iter; + KatzeItem* today; + time_t current_time; + + current_time = time (NULL); + if (gtk_tree_model_iter_children (model, &iter, NULL)) + { + gint64 day; + gboolean has_today; + + gtk_tree_model_get (model, &iter, 0, &today, -1); + + day = katze_item_get_added (today); + has_today = sokoke_days_between ((time_t*)&day, ¤t_time) == 0; + g_object_unref (today); + if (has_today) + { + gchar* tooltip = g_markup_escape_text (katze_item_get_uri (item), -1); + KatzeItem* copy = katze_item_copy (item); + gtk_tree_store_insert_with_values (GTK_TREE_STORE (model), NULL, &iter, + 0, 0, copy, 1, tooltip, -1); + g_object_unref (copy); + g_free (tooltip); + return; + } + } + + today = (KatzeItem*)katze_array_new (KATZE_TYPE_ITEM); + katze_item_set_added (today, current_time); + katze_item_set_meta_integer (today, "day", + sokoke_time_t_to_julian (¤t_time)); + gtk_tree_store_insert_with_values (GTK_TREE_STORE (model), &iter, NULL, + 0, 0, today, -1); + /* That's an invisible dummy, so we always have an expander */ + gtk_tree_store_insert_with_values (GTK_TREE_STORE (model), NULL, &iter, + 0, 0, NULL, -1); +} + static void midori_history_set_app (MidoriHistory* history, MidoriApp* app) @@ -416,7 +461,9 @@ midori_history_set_app (MidoriHistory* history, if (history->array) { - g_object_unref (history->array); + g_signal_handlers_disconnect_by_func (history->array, + midori_history_add_item_cb, history); + katze_object_assign (history->array, NULL); model = gtk_tree_view_get_model (GTK_TREE_VIEW (history->treeview)); gtk_tree_store_clear (GTK_TREE_STORE (model)); } @@ -427,6 +474,8 @@ midori_history_set_app (MidoriHistory* history, g_object_ref (app); history->array = katze_object_get_object (app, "history"); + g_signal_connect (history->array, "add-item", + G_CALLBACK (midori_history_add_item_cb), history); model = gtk_tree_view_get_model (GTK_TREE_VIEW (history->treeview)); if (history->array) midori_history_read_from_db_to_model (history, GTK_TREE_STORE (model), NULL, 0, NULL);