diff options
Diffstat (limited to 'embed')
-rw-r--r-- | embed/ephy-history.c | 74 |
1 files changed, 70 insertions, 4 deletions
diff --git a/embed/ephy-history.c b/embed/ephy-history.c index 8ba9edbb8..911567dda 100644 --- a/embed/ephy-history.c +++ b/embed/ephy-history.c @@ -57,6 +57,7 @@ struct EphyHistoryPrivate GHashTable *pages_hash; GStaticRWLock *pages_hash_lock; int autosave_timeout; + guint update_hosts_idle; }; enum @@ -357,10 +358,68 @@ periodic_save_cb (EphyHistory *eh) return TRUE; } +static void +update_host_on_child_remove (EphyNode *node) +{ + GPtrArray *children; + int i, host_last_visit, new_host_last_visit = 0; + + if (ephy_node_get_n_children (node) == 0) + { + ephy_node_unref (node); + return; + } + + host_last_visit = ephy_node_get_property_int + (node, EPHY_NODE_PAGE_PROP_LAST_VISIT); + + children = ephy_node_get_children (node); + for (i = 0; i < children->len; i++) + { + EphyNode *kid; + int last_visit; + + kid = g_ptr_array_index (children, i); + + last_visit = ephy_node_get_property_int + (kid, EPHY_NODE_PAGE_PROP_LAST_VISIT); + + if (last_visit > new_host_last_visit) + { + new_host_last_visit = last_visit; + } + } + ephy_node_thaw (node); + + if (host_last_visit != new_host_last_visit) + { + GValue value = { 0, }; + + g_value_init (&value, G_TYPE_INT); + g_value_set_int (&value, new_host_last_visit); + ephy_node_set_property (node, EPHY_NODE_PAGE_PROP_LAST_VISIT, + &value); + g_value_unset (&value); + } +} + static gboolean -unref_empty_host (EphyNode *node) +update_hosts (EphyHistory *eh) { - ephy_node_unref (node); + GPtrArray *children; + int i; + + children = ephy_node_get_children (eh->priv->hosts); + ephy_node_thaw (eh->priv->hosts); + for (i = 0; i < children->len; i++) + { + EphyNode *kid; + + kid = g_ptr_array_index (children, i); + update_host_on_child_remove (kid); + } + + eh->priv->update_hosts_idle = 0; return FALSE; } @@ -371,9 +430,10 @@ page_removed_from_host_cb (EphyNode *node, guint old_index, EphyHistory *eb) { - if (ephy_node_get_n_children (node) == 0) + if (!eb->priv->update_hosts_idle) { - g_idle_add ((GSourceFunc)unref_empty_host, node); + eb->priv->update_hosts_idle = g_idle_add + ((GSourceFunc)update_hosts, eb); } } @@ -397,6 +457,7 @@ ephy_history_init (EphyHistory *eb) EphyNodeDb *db; eb->priv = EPHY_HISTORY_GET_PRIVATE (eb); + eb->priv->update_hosts_idle = 0; db = ephy_node_db_new (EPHY_NODE_DB_HISTORY); eb->priv->db = db; @@ -477,6 +538,11 @@ ephy_history_finalize (GObject *object) { EphyHistory *eb = EPHY_HISTORY (object); + if (eb->priv->update_hosts_idle) + { + g_source_remove (eb->priv->update_hosts_idle); + } + ephy_history_save (eb); ephy_node_unref (eb->priv->pages); |