From 3dd224ab9286d3099a503d21a0771417372b377e Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Sat, 1 Nov 2003 13:43:47 +0000 Subject: Only save history db if there have been changes. Fixes bug #125973. 2003-11-01 Christian Persch * embed/ephy-history.c: (ephy_history_save), (hosts_added_cb), (hosts_removed_cb), (hosts_changed_cb), (pages_added_cb), (pages_removed_cb), (pages_changed_cb), (ephy_history_init): Only save history db if there have been changes. Fixes bug #125973. --- embed/ephy-history.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'embed/ephy-history.c') diff --git a/embed/ephy-history.c b/embed/ephy-history.c index 1c4cb3b28..1f269af70 100644 --- a/embed/ephy-history.c +++ b/embed/ephy-history.c @@ -57,6 +57,7 @@ struct EphyHistoryPrivate GStaticRWLock *pages_hash_lock; int autosave_timeout; guint update_hosts_idle; + gboolean dirty; }; enum @@ -183,6 +184,12 @@ ephy_history_save (EphyHistory *eb) LOG ("Saving history") + /* only save if there are changes */ + if (eb->priv->dirty == FALSE) + { + return; + } + /* save nodes to xml */ xmlIndentTreeOutput = TRUE; doc = xmlNewDoc ("1.0"); @@ -214,7 +221,12 @@ ephy_history_save (EphyHistory *eb) } ephy_node_thaw (eb->priv->pages); - ephy_file_save_xml (eb->priv->xml_file, doc); + if (ephy_file_save_xml (eb->priv->xml_file, doc)) + { + /* save was successful */ + eb->priv->dirty = FALSE; + } + xmlFreeDoc(doc); } @@ -223,6 +235,8 @@ hosts_added_cb (EphyNode *node, EphyNode *child, EphyHistory *eb) { + eb->priv->dirty = TRUE; + g_static_rw_lock_writer_lock (eb->priv->hosts_hash_lock); g_hash_table_insert (eb->priv->hosts_hash, @@ -238,6 +252,8 @@ hosts_removed_cb (EphyNode *node, guint old_index, EphyHistory *eb) { + eb->priv->dirty = TRUE; + g_static_rw_lock_writer_lock (eb->priv->hosts_hash_lock); g_hash_table_remove (eb->priv->hosts_hash, @@ -246,11 +262,21 @@ hosts_removed_cb (EphyNode *node, g_static_rw_lock_writer_unlock (eb->priv->hosts_hash_lock); } +static void +hosts_changed_cb (EphyNode *node, + EphyNode *child, + EphyHistory *eb) +{ + eb->priv->dirty = TRUE; +} + static void pages_added_cb (EphyNode *node, EphyNode *child, EphyHistory *eb) { + eb->priv->dirty = TRUE; + g_static_rw_lock_writer_lock (eb->priv->pages_hash_lock); g_hash_table_insert (eb->priv->pages_hash, @@ -266,6 +292,8 @@ pages_removed_cb (EphyNode *node, guint old_index, EphyHistory *eb) { + eb->priv->dirty = TRUE; + g_static_rw_lock_writer_lock (eb->priv->pages_hash_lock); g_hash_table_remove (eb->priv->pages_hash, @@ -274,6 +302,14 @@ pages_removed_cb (EphyNode *node, g_static_rw_lock_writer_unlock (eb->priv->pages_hash_lock); } +static void +pages_changed_cb (EphyNode *node, + EphyNode *child, + EphyHistory *eb) +{ + eb->priv->dirty = TRUE; +} + static gboolean periodic_save_cb (EphyHistory *eh) { @@ -436,6 +472,10 @@ ephy_history_init (EphyHistory *eb) EPHY_NODE_CHILD_REMOVED, (EphyNodeCallback) pages_removed_cb, G_OBJECT (eb)); + ephy_node_signal_connect_object (eb->priv->pages, + EPHY_NODE_CHILD_CHANGED, + (EphyNodeCallback) pages_changed_cb, + G_OBJECT (eb)); /* Hosts */ eb->priv->hosts = ephy_node_new_with_id (db, HOSTS_NODE_ID); @@ -448,6 +488,10 @@ ephy_history_init (EphyHistory *eb) EPHY_NODE_CHILD_REMOVED, (EphyNodeCallback) hosts_removed_cb, G_OBJECT (eb)); + ephy_node_signal_connect_object (eb->priv->hosts, + EPHY_NODE_CHILD_CHANGED, + (EphyNodeCallback) hosts_changed_cb, + G_OBJECT (eb)); ephy_node_add_child (eb->priv->hosts, eb->priv->pages); @@ -459,6 +503,9 @@ ephy_history_init (EphyHistory *eb) (GHFunc) connect_page_removed_from_host, eb); + /* mark as clean */ + eb->priv->dirty = FALSE; + /* setup the periodic history saving callback */ eb->priv->autosave_timeout = g_timeout_add (HISTORY_SAVE_INTERVAL, -- cgit v1.2.3