aboutsummaryrefslogtreecommitdiffstats
path: root/embed
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@it.gnome.org>2003-05-24 05:06:13 +0800
committerMarco Pesenti Gritti <mpeseng@src.gnome.org>2003-05-24 05:06:13 +0800
commita98d9364cb5395aca5adc9fa4db219df7545ab98 (patch)
tree59c8fce41d8d0e2e720f433eca186ec4a307ac37 /embed
parentbf20b4938c2e01f15d72dc2962c12400bb15d4d4 (diff)
downloadgsoc2013-epiphany-a98d9364cb5395aca5adc9fa4db219df7545ab98.tar
gsoc2013-epiphany-a98d9364cb5395aca5adc9fa4db219df7545ab98.tar.gz
gsoc2013-epiphany-a98d9364cb5395aca5adc9fa4db219df7545ab98.tar.bz2
gsoc2013-epiphany-a98d9364cb5395aca5adc9fa4db219df7545ab98.tar.lz
gsoc2013-epiphany-a98d9364cb5395aca5adc9fa4db219df7545ab98.tar.xz
gsoc2013-epiphany-a98d9364cb5395aca5adc9fa4db219df7545ab98.tar.zst
gsoc2013-epiphany-a98d9364cb5395aca5adc9fa4db219df7545ab98.zip
Implement generic way to save/load db and make it low disk safe.
2003-05-23 Marco Pesenti Gritti <marco@it.gnome.org> * embed/ephy-favicon-cache.c: (ephy_favicon_cache_load), (ephy_favicon_cache_save), (ephy_favicon_cache_init), (ephy_favicon_cache_finalize): * embed/ephy-history.c: (ephy_history_load), (ephy_history_save), (ephy_history_init): * lib/ephy-node-db.c: (ephy_node_db_set_version), (ephy_node_db_get_property), (ephy_node_db_set_property), (ephy_node_db_class_init), (ephy_node_db_init), (ephy_node_db_finalize), (ephy_node_db_new), (_ephy_node_db_remove_id), (ephy_node_db_load_from_xml), (ephy_node_db_save_to_xml): * lib/ephy-node-db.h: * lib/ephy-node.c: (ephy_node_to_xml): * lib/ephy-node.h: * lib/ephy-state.c: (ephy_states_load), (ephy_states_save), (ensure_states): * src/bookmarks/ephy-bookmarks.c: (ephy_bookmarks_load), (ephy_bookmarks_save), (ephy_bookmarks_init), (ephy_bookmarks_finalize): Implement generic way to save/load db and make it low disk safe.
Diffstat (limited to 'embed')
-rw-r--r--embed/ephy-favicon-cache.c60
-rw-r--r--embed/ephy-history.c68
2 files changed, 8 insertions, 120 deletions
diff --git a/embed/ephy-favicon-cache.c b/embed/ephy-favicon-cache.c
index 1391c5f5c..e73a03340 100644
--- a/embed/ephy-favicon-cache.c
+++ b/embed/ephy-favicon-cache.c
@@ -122,30 +122,7 @@ ephy_favicon_cache_new (void)
static void
ephy_favicon_cache_load (EphyFaviconCache *eb)
{
- xmlDocPtr doc;
- xmlNodePtr root, child;
- char *tmp;
-
- if (g_file_test (eb->priv->xml_file, G_FILE_TEST_EXISTS) == FALSE)
- return;
-
- doc = xmlParseFile (eb->priv->xml_file);
- g_assert (doc != NULL);
-
- root = xmlDocGetRootElement (doc);
-
- tmp = xmlGetProp (root, "version");
- g_assert (tmp != NULL && strcmp (tmp, EPHY_FAVICON_CACHE_XML_VERSION) == 0);
- g_free (tmp);
-
- for (child = root->children; child != NULL; child = child->next)
- {
- EphyNode *node;
-
- node = ephy_node_new_from_xml (eb->priv->db, child);
- }
-
- xmlFreeDoc (doc);
+ ephy_node_db_load_from_xml (eb->priv->db, eb->priv->xml_file);
}
static gboolean
@@ -229,33 +206,7 @@ remove_obsolete_icons (EphyFaviconCache *eb)
static void
ephy_favicon_cache_save (EphyFaviconCache *eb)
{
- xmlDocPtr doc;
- xmlNodePtr root;
- GPtrArray *children;
- int i;
-
- /* save nodes to xml */
- xmlIndentTreeOutput = TRUE;
- doc = xmlNewDoc ("1.0");
-
- root = xmlNewDocNode (doc, NULL, "ephy_favicons_cache", NULL);
- xmlSetProp (root, "version", EPHY_FAVICON_CACHE_XML_VERSION);
- xmlDocSetRootElement (doc, root);
-
- children = ephy_node_get_children (eb->priv->icons);
- for (i = 0; i < children->len; i++)
- {
- EphyNode *kid;
-
- kid = g_ptr_array_index (children, i);
-
- ephy_node_save_to_xml (kid, root);
- }
- ephy_node_thaw (eb->priv->icons);
-
- xmlSaveFormatFile (eb->priv->xml_file, doc, 1);
-
- xmlFreeDoc (doc);
+ ephy_node_db_save_to_xml (eb->priv->db, eb->priv->xml_file);
}
static void
@@ -265,7 +216,7 @@ ephy_favicon_cache_init (EphyFaviconCache *cache)
cache->priv = g_new0 (EphyFaviconCachePrivate, 1);
- db = ephy_node_db_new ("EphyFaviconCache");
+ db = ephy_node_db_new ("EphyFaviconCache", EPHY_FAVICON_CACHE_XML_VERSION);
cache->priv->db = db;
cache->priv->xml_file = g_build_filename (ephy_dot_dir (),
@@ -351,17 +302,16 @@ ephy_favicon_cache_finalize (GObject *object)
g_return_if_fail (cache->priv != NULL);
- g_object_unref (cache->priv->db);
-
+ ephy_favicon_cache_save (cache);
cleanup_downloads_hash (cache);
remove_obsolete_icons (cache);
- ephy_favicon_cache_save (cache);
g_free (cache->priv->xml_file);
g_free (cache->priv->directory);
g_hash_table_destroy (cache->priv->icons_hash);
g_static_rw_lock_free (cache->priv->icons_hash_lock);
g_hash_table_destroy (cache->priv->downloads_hash);
+ g_object_unref (cache->priv->db);
g_free (cache->priv);
diff --git a/embed/ephy-history.c b/embed/ephy-history.c
index c9541c618..0806ee2f3 100644
--- a/embed/ephy-history.c
+++ b/embed/ephy-history.c
@@ -199,30 +199,7 @@ ephy_history_class_init (EphyHistoryClass *klass)
static void
ephy_history_load (EphyHistory *eb)
{
- xmlDocPtr doc;
- xmlNodePtr root, child;
- char *tmp;
-
- if (g_file_test (eb->priv->xml_file, G_FILE_TEST_EXISTS) == FALSE)
- return;
-
- doc = xmlParseFile (eb->priv->xml_file);
- g_return_if_fail (doc != NULL);
-
- root = xmlDocGetRootElement (doc);
-
- tmp = xmlGetProp (root, "version");
- g_assert (tmp != NULL && strcmp (tmp, EPHY_HISTORY_XML_VERSION) == 0);
- g_free (tmp);
-
- for (child = root->children; child != NULL; child = child->next)
- {
- EphyNode *node;
-
- node = ephy_node_new_from_xml (eb->priv->db, child);
- }
-
- xmlFreeDoc (doc);
+ ephy_node_db_load_from_xml (eb->priv->db, eb->priv->xml_file);
}
static gboolean
@@ -271,46 +248,7 @@ remove_obsolete_pages (EphyHistory *eb)
static void
ephy_history_save (EphyHistory *eb)
{
- xmlDocPtr doc;
- xmlNodePtr root;
- GPtrArray *children;
- int i;
-
- LOG ("Saving history")
-
- /* save nodes to xml */
- xmlIndentTreeOutput = TRUE;
- doc = xmlNewDoc ("1.0");
-
- root = xmlNewDocNode (doc, NULL, "ephy_history", NULL);
- xmlSetProp (root, "version", EPHY_HISTORY_XML_VERSION);
- xmlDocSetRootElement (doc, root);
-
- children = ephy_node_get_children (eb->priv->hosts);
- for (i = 0; i < children->len; i++)
- {
- EphyNode *kid;
-
- kid = g_ptr_array_index (children, i);
- if (kid == eb->priv->pages) continue;
-
- ephy_node_save_to_xml (kid, root);
- }
- ephy_node_thaw (eb->priv->hosts);
-
- children = ephy_node_get_children (eb->priv->pages);
- for (i = 0; i < children->len; i++)
- {
- EphyNode *kid;
-
- kid = g_ptr_array_index (children, i);
-
- ephy_node_save_to_xml (kid, root);
- }
- ephy_node_thaw (eb->priv->pages);
-
- xmlSaveFormatFile (eb->priv->xml_file, doc, 1);
- xmlFreeDoc(doc);
+ ephy_node_db_save_to_xml (eb->priv->db, eb->priv->xml_file);
}
static void
@@ -399,7 +337,7 @@ ephy_history_init (EphyHistory *eb)
eb->priv = g_new0 (EphyHistoryPrivate, 1);
- db = ephy_node_db_new ("EphyHistory");
+ db = ephy_node_db_new ("EphyHistory", EPHY_HISTORY_XML_VERSION);
eb->priv->db = db;
eb->priv->xml_file = g_build_filename (ephy_dot_dir (),