[Xfce4-commits] <midori:master> Use KatzeArray* to signal new items to MidoriHistory

Christian Dywan noreply at xfce.org
Sun Aug 1 17:14:06 CEST 2010


Updating branch refs/heads/master
         to 34d7a8033bf718a815130e8a7e682cdeae1485e2 (commit)
       from 60eca91b74449e511041432ddfcd0268bab6bc6f (commit)

commit 34d7a8033bf718a815130e8a7e682cdeae1485e2
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sat Jul 31 01:42:14 2010 +0200

    Use KatzeArray* to signal new items to MidoriHistory

 midori/midori-browser.c |    4 +++
 panels/midori-history.c |   51 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 54 insertions(+), 1 deletions(-)

diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index 91b6d9e..f3d1d71 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 d8aed73..f681ddc 100644
--- a/panels/midori-history.c
+++ b/panels/midori-history.c
@@ -409,6 +409,51 @@ midori_history_viewable_iface_init (MidoriViewableIface* iface)
 }
 
 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, &current_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 (&current_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);



More information about the Xfce4-commits mailing list