aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@it.gnome.org>2003-07-10 21:33:49 +0800
committerMarco Pesenti Gritti <mpeseng@src.gnome.org>2003-07-10 21:33:49 +0800
commitd446a326bb0243e014e3d4e8e6152b6a6f9b7e28 (patch)
treefccfd27fab44f27b2d8f24c53bac8ddcefcde398
parent268d6be0929222404146c78a5656ee0739af262a (diff)
downloadgsoc2013-epiphany-d446a326bb0243e014e3d4e8e6152b6a6f9b7e28.tar
gsoc2013-epiphany-d446a326bb0243e014e3d4e8e6152b6a6f9b7e28.tar.gz
gsoc2013-epiphany-d446a326bb0243e014e3d4e8e6152b6a6f9b7e28.tar.bz2
gsoc2013-epiphany-d446a326bb0243e014e3d4e8e6152b6a6f9b7e28.tar.lz
gsoc2013-epiphany-d446a326bb0243e014e3d4e8e6152b6a6f9b7e28.tar.xz
gsoc2013-epiphany-d446a326bb0243e014e3d4e8e6152b6a6f9b7e28.tar.zst
gsoc2013-epiphany-d446a326bb0243e014e3d4e8e6152b6a6f9b7e28.zip
Some minor changes in rdf format (thanks to Edd Dumbill), and use
2003-07-10 Marco Pesenti Gritti <marco@it.gnome.org> * src/bookmarks/ephy-bookmarks-export.c: (add_topics_list), (ephy_bookmarks_export_rdf): Some minor changes in rdf format (thanks to Edd Dumbill), and use namespaces in the code. * src/bookmarks/ephy-bookmarks-import.c: (bookmark_add), (ephy_bookmarks_import_xbel), (parse_rdf_subjects), (parse_rdf_item), (ephy_bookmarks_import_rdf): * src/bookmarks/ephy-bookmarks-import.h: Add an rdf importer. * src/bookmarks/ephy-bookmarks.c: (ephy_bookmarks_load), (ephy_bookmarks_save), (ephy_bookmarks_init), (ephy_bookmarks_finalize): Update db to 1.0, import bookmarks from the rdf first time. WARNING Backup your bookmarks.rdf file before using this and let me know if you get any problems. (esp if you had a < 0.7.3 epiphany version).
-rw-r--r--ChangeLog25
-rw-r--r--src/bookmarks/ephy-bookmarks-export.c81
-rw-r--r--src/bookmarks/ephy-bookmarks-import.c147
-rw-r--r--src/bookmarks/ephy-bookmarks-import.h3
-rw-r--r--src/bookmarks/ephy-bookmarks.c41
5 files changed, 262 insertions, 35 deletions
diff --git a/ChangeLog b/ChangeLog
index 51fe451b6..5528d1998 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,30 @@
2003-07-10 Marco Pesenti Gritti <marco@it.gnome.org>
+ * src/bookmarks/ephy-bookmarks-export.c: (add_topics_list),
+ (ephy_bookmarks_export_rdf):
+
+ Some minor changes in rdf format (thanks to Edd Dumbill),
+ and use namespaces in the code.
+
+ * src/bookmarks/ephy-bookmarks-import.c: (bookmark_add),
+ (ephy_bookmarks_import_xbel), (parse_rdf_subjects),
+ (parse_rdf_item), (ephy_bookmarks_import_rdf):
+ * src/bookmarks/ephy-bookmarks-import.h:
+
+ Add an rdf importer.
+
+ * src/bookmarks/ephy-bookmarks.c: (ephy_bookmarks_load),
+ (ephy_bookmarks_save), (ephy_bookmarks_init),
+ (ephy_bookmarks_finalize):
+
+ Update db to 1.0, import bookmarks from the rdf first time.
+
+ WARNING Backup your bookmarks.rdf file before using this
+ and let me know if you get any problems. (esp if you had a
+ < 0.7.3 epiphany version).
+
+2003-07-10 Marco Pesenti Gritti <marco@it.gnome.org>
+
* data/ui/epiphany-toolbar.xml.in:
* embed/ephy-favicon-cache.c: (ephy_favicon_cache_load),
(ephy_favicon_cache_init):
diff --git a/src/bookmarks/ephy-bookmarks-export.c b/src/bookmarks/ephy-bookmarks-export.c
index 7ca93811e..7f026f3a1 100644
--- a/src/bookmarks/ephy-bookmarks-export.c
+++ b/src/bookmarks/ephy-bookmarks-export.c
@@ -17,6 +17,7 @@
*/
#include <libxml/tree.h>
+#include <libgnomevfs/gnome-vfs-uri.h>
#include <libgnomevfs/gnome-vfs-utils.h>
#include "ephy-bookmarks-export.h"
@@ -25,12 +26,12 @@
#include "ephy-debug.h"
static void
-add_topics_list (EphyNode *topics, EphyNode *bmk, xmlNodePtr parent)
+add_topics_list (EphyNode *topics, EphyNode *bmk,
+ xmlNodePtr parent, xmlNsPtr dc_ns)
{
GPtrArray *children;
int i;
GList *bmks = NULL, *l;
- xmlNodePtr xml_node;
children = ephy_node_get_children (topics);
for (i = 0; i < children->len; i++)
@@ -57,11 +58,12 @@ add_topics_list (EphyNode *topics, EphyNode *bmk, xmlNodePtr parent)
{
const char *name;
EphyNode *node = l->data;
+ xmlNodePtr item_node;
- xml_node = xmlNewChild (parent, NULL, "dc:subject", NULL);
name = ephy_node_get_property_string
(node, EPHY_NODE_KEYWORD_PROP_NAME);
- xmlNodeSetContent (xml_node, name);
+ item_node = xmlNewChild (parent, dc_ns, "subject", NULL);
+ xmlNodeSetContent (item_node, name);
}
g_list_free (bmks);
@@ -75,8 +77,9 @@ ephy_bookmarks_export_rdf (EphyBookmarks *bookmarks,
EphyNode *topics;
xmlDocPtr doc;
xmlNodePtr root, xml_node, channel_node, channel_seq_node;
- char *uri;
+ xmlNsPtr ephy_ns, rdf_ns, dc_ns;
GPtrArray *children;
+ char *file_uri;
int i;
LOG ("Exporting to rdf")
@@ -86,14 +89,14 @@ ephy_bookmarks_export_rdf (EphyBookmarks *bookmarks,
root = xmlNewDocNode (doc, NULL, "rdf:RDF", NULL);
xmlDocSetRootElement (doc, root);
- xmlSetProp (root, "xmlns:rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
- xmlSetProp (root, "xmlns", "http://purl.org/rss/1.0/");
- xmlSetProp (root, "xmlns:dc", "http://purl.org/dc/elements/1.1/");
-
+ rdf_ns = xmlNewNs (root, "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf");
+ xmlNewNs (root, "http://purl.org/rss/1.0/", NULL);
+ dc_ns = xmlNewNs (root, "http://purl.org/dc/elements/1.1/", "dc");
+ ephy_ns = xmlNewNs (root, "http://gnome.org/ns/epiphany#", "ephy");
channel_node = xmlNewChild (root, NULL, "channel", NULL);
- uri = gnome_vfs_get_uri_from_local_path (filename);
- xmlSetProp (channel_node, "rdf:about", uri);
- g_free (uri);
+ file_uri = gnome_vfs_get_uri_from_local_path (filename);
+ xmlSetProp (channel_node, "rdf:about", file_uri);
+ g_free (file_uri);
xml_node = xmlNewChild (channel_node, NULL, "title", NULL);
xmlNodeSetContent (xml_node, "Epiphany bookmarks");
@@ -103,7 +106,7 @@ ephy_bookmarks_export_rdf (EphyBookmarks *bookmarks,
xml_node = xmlNewChild (channel_node, NULL, "items", NULL);
- channel_seq_node = xmlNewChild (xml_node, NULL, "rdf:Seq", NULL);
+ channel_seq_node = xmlNewChild (xml_node, rdf_ns, "Seq", NULL);
bmks = ephy_bookmarks_get_bookmarks (bookmarks);
topics = ephy_bookmarks_get_keywords (bookmarks);
@@ -114,28 +117,62 @@ ephy_bookmarks_export_rdf (EphyBookmarks *bookmarks,
EphyNode *kid;
const char *url, *title;
xmlNodePtr item_node;
+ xmlChar *encoded_link;
+ char *link = NULL;
+ gboolean smart_url;
kid = g_ptr_array_index (children, i);
-
+ smart_url = ephy_node_get_property_boolean
+ (kid, EPHY_NODE_BMK_PROP_HAS_SMART_ADDRESS);
url = ephy_node_get_property_string
(kid, EPHY_NODE_BMK_PROP_LOCATION);
title = ephy_node_get_property_string
(kid, EPHY_NODE_BMK_PROP_TITLE);
- item_node = xmlNewChild (channel_seq_node, NULL, "rdf:li", NULL);
- xmlSetProp (item_node, "rdf:about", url);
+ if (smart_url)
+ {
+ GnomeVFSURI *uri;
+
+ uri = gnome_vfs_uri_new (url);
+
+ if (uri)
+ {
+ link = g_strconcat (gnome_vfs_uri_get_scheme (uri),
+ "://",
+ gnome_vfs_uri_get_host_name (uri),
+ NULL);
+
+ gnome_vfs_uri_unref (uri);
+ }
+ }
+
+ if (link == NULL)
+ {
+ link = g_strdup (url);
+ }
+
+ encoded_link = xmlEncodeEntitiesReentrant (doc, link);
+
+ item_node = xmlNewChild (channel_seq_node, rdf_ns, "li", NULL);
+ xmlSetNsProp (item_node, rdf_ns, "about", link);
item_node = xmlNewChild (root, NULL, "item", NULL);
- xmlSetProp (item_node, "rdf:about", url);
+ xmlSetNsProp (item_node, rdf_ns, "about", link);
- xml_node = xmlNewChild (item_node, NULL, "title", NULL);
- xmlNodeSetContent (xml_node, title);
+ xml_node = xmlNewChild (item_node, NULL, "title", title);
+
+ xml_node = xmlNewChild (item_node, NULL, "link", encoded_link);
+
+ if (smart_url)
+ {
+ xml_node = xmlNewChild (item_node, ephy_ns, "smartlink", url);
+ }
- xml_node = xmlNewChild (item_node, NULL, "link", NULL);
- xmlNodeSetContent (xml_node, url);
+ add_topics_list (topics, kid, item_node, dc_ns);
- add_topics_list (topics, kid, item_node);
+ xmlFree (encoded_link);
+ g_free (link);
}
ephy_node_thaw (bmks);
diff --git a/src/bookmarks/ephy-bookmarks-import.c b/src/bookmarks/ephy-bookmarks-import.c
index 55deca320..31791fd81 100644
--- a/src/bookmarks/ephy-bookmarks-import.c
+++ b/src/bookmarks/ephy-bookmarks-import.c
@@ -43,7 +43,7 @@ typedef struct _XbelInfo
char *smarturl;
} XbelInfo;
-static void
+static EphyNode *
bookmark_add (EphyBookmarks *bookmarks,
const char *title,
const char *address,
@@ -52,7 +52,7 @@ bookmark_add (EphyBookmarks *bookmarks,
EphyNode *topic;
EphyNode *bmk;
- if (ephy_bookmarks_find_bookmark (bookmarks, address)) return;
+ if (ephy_bookmarks_find_bookmark (bookmarks, address)) return NULL;
bmk = ephy_bookmarks_add (bookmarks, title, address);
@@ -66,6 +66,8 @@ bookmark_add (EphyBookmarks *bookmarks,
ephy_bookmarks_set_keyword (bookmarks, topic, bmk);
}
+
+ return bmk;
}
gboolean
@@ -444,3 +446,144 @@ ephy_bookmarks_import_xbel (EphyBookmarks *bookmarks,
return TRUE;
}
+
+#define OLD_RDF_TEMPORARY_HACK
+
+static void
+parse_rdf_subjects (xmlNodePtr node,
+ GList **subjects)
+{
+ xmlChar *subject;
+
+#ifdef OLD_RDF_TEMPORARY_HACK
+ xmlNode *child;
+
+ child = node->children;
+
+ while (child != NULL)
+ {
+ if (xmlStrEqual (child->name, "Bag"))
+ {
+ child = child->children;
+
+ while (child != NULL)
+ {
+ if (xmlStrEqual (child->name, "li"))
+ {
+ subject = xmlNodeGetContent (child);
+ *subjects = g_list_append (*subjects, subject);
+ }
+
+ child = child->next;
+ }
+
+ return;
+ }
+
+ child = child->next;
+ }
+#endif
+
+ subject = xmlNodeGetContent (node);
+
+ if (subject)
+ {
+ *subjects = g_list_append (*subjects, subject);
+ }
+}
+
+static void
+parse_rdf_item (EphyBookmarks *bookmarks,
+ xmlNodePtr node)
+{
+ xmlChar *title = NULL;
+ xmlChar *link = NULL;
+ GList *subjects = NULL, *l = NULL;
+ xmlNode *child;
+ EphyNode *bmk;
+
+ child = node->children;
+
+#ifdef OLD_RDF_TEMPORARY_HACK
+ link = xmlGetProp (node, "about");
+#endif
+
+ while (child != NULL)
+ {
+ if (xmlStrEqual (child->name, "title"))
+ {
+ title = xmlNodeGetContent (child);
+ }
+#ifndef OLD_RDF_TEMPORARY_HACK
+ else if (xmlStrEqual (child->name, "link"))
+ {
+ link = xmlNodeGetContent (child);
+ }
+#endif
+ else if (xmlStrEqual (child->name, "subject"))
+ {
+ parse_rdf_subjects (child, &subjects);
+ }
+
+ child = child->next;
+ }
+
+ bmk = bookmark_add (bookmarks, title, link, NULL);
+ if (bmk)
+ {
+ l = subjects;
+ }
+
+ for (; l != NULL; l = l->next)
+ {
+ char *topic_name = l->data;
+ EphyNode *topic;
+
+ topic = ephy_bookmarks_find_keyword (bookmarks, topic_name, FALSE);
+
+ if (topic == NULL)
+ {
+ topic = ephy_bookmarks_add_keyword (bookmarks, topic_name);
+ }
+
+ ephy_bookmarks_set_keyword (bookmarks, topic, bmk);
+ }
+
+ xmlFree (title);
+ xmlFree (link);
+
+ g_list_foreach (subjects, (GFunc)xmlFree, NULL);
+ g_list_free (subjects);
+}
+
+gboolean
+ephy_bookmarks_import_rdf (EphyBookmarks *bookmarks,
+ const char *filename)
+{
+ xmlDocPtr doc;
+ xmlNodePtr child;
+ xmlNodePtr root;
+
+ if (g_file_test (filename, G_FILE_TEST_EXISTS) == FALSE)
+ return FALSE;
+
+ doc = xmlParseFile (filename);
+ g_assert (doc != NULL);
+ root = xmlDocGetRootElement (doc);
+
+ child = root->children;
+
+ while (child != NULL)
+ {
+ if (xmlStrEqual (child->name, "item"))
+ {
+ parse_rdf_item (bookmarks, child);
+ }
+
+ child = child->next;
+ }
+
+ xmlFreeDoc (doc);
+
+ return TRUE;
+}
diff --git a/src/bookmarks/ephy-bookmarks-import.h b/src/bookmarks/ephy-bookmarks-import.h
index 1aec1fa53..d4b75ccc9 100644
--- a/src/bookmarks/ephy-bookmarks-import.h
+++ b/src/bookmarks/ephy-bookmarks-import.h
@@ -36,6 +36,9 @@ gboolean ephy_bookmarks_import_mozilla (EphyBookmarks *bookmarks,
gboolean ephy_bookmarks_import_xbel (EphyBookmarks *bookmarks,
const char *filename);
+gboolean ephy_bookmarks_import_rdf (EphyBookmarks *bookmarks,
+ const char *filename);
+
G_END_DECLS
#endif
diff --git a/src/bookmarks/ephy-bookmarks.c b/src/bookmarks/ephy-bookmarks.c
index bb6db5bd7..757b2f3b3 100644
--- a/src/bookmarks/ephy-bookmarks.c
+++ b/src/bookmarks/ephy-bookmarks.c
@@ -31,12 +31,13 @@
#include "ephy-node-common.h"
#include "ephy-toolbars-model.h"
#include "ephy-bookmarks-export.h"
+#include "ephy-bookmarks-import.h"
#include <string.h>
#include <bonobo/bonobo-i18n.h>
#include <libgnomevfs/gnome-vfs-utils.h>
-#define EPHY_BOOKMARKS_XML_VERSION "0.1"
+#define EPHY_BOOKMARKS_XML_VERSION "1.0"
#define BOOKMARKS_SAVE_DELAY (3 * 1000)
#define MAX_FAVORITES_NUM 10
@@ -47,6 +48,7 @@ struct EphyBookmarksPrivate
gboolean dirty;
guint save_timeout_id;
char *xml_file;
+ char *rdf_file;
EphyNodeDb *db;
EphyNode *bookmarks;
EphyNode *keywords;
@@ -313,6 +315,7 @@ ephy_bookmarks_load (EphyBookmarks *eb)
xmlDocPtr doc;
xmlNodePtr root, child;
char *tmp;
+ gboolean result = TRUE;
if (g_file_test (eb->priv->xml_file, G_FILE_TEST_EXISTS) == FALSE)
return FALSE;
@@ -323,7 +326,12 @@ ephy_bookmarks_load (EphyBookmarks *eb)
root = xmlDocGetRootElement (doc);
tmp = xmlGetProp (root, "version");
- g_assert (tmp != NULL && strcmp (tmp, EPHY_BOOKMARKS_XML_VERSION) == 0);
+ if (tmp != NULL && strcmp (tmp, EPHY_BOOKMARKS_XML_VERSION) != 0)
+ {
+ g_warning ("Old bookmarks database format detected");
+ child = NULL;
+ result = FALSE;
+ }
g_free (tmp);
for (child = root->children; child != NULL; child = child->next)
@@ -335,7 +343,7 @@ ephy_bookmarks_load (EphyBookmarks *eb)
xmlFreeDoc (doc);
- return TRUE;
+ return result;
}
static void
@@ -343,9 +351,9 @@ ephy_bookmarks_save (EphyBookmarks *eb)
{
xmlDocPtr doc;
xmlNodePtr root;
+ xmlNodePtr comment;
GPtrArray *children;
int i;
- char *rdf_file;
LOG ("Saving bookmarks")
@@ -357,6 +365,9 @@ ephy_bookmarks_save (EphyBookmarks *eb)
xmlSetProp (root, "version", EPHY_BOOKMARKS_XML_VERSION);
xmlDocSetRootElement (doc, root);
+ comment = xmlNewDocComment (doc, "Do not rely on this file, it's only for internal use. Use bookmarks.rdf instead.");
+ xmlAddChild (root, comment);
+
children = ephy_node_get_children (eb->priv->keywords);
for (i = 0; i < children->len; i++)
{
@@ -388,11 +399,7 @@ ephy_bookmarks_save (EphyBookmarks *eb)
xmlFreeDoc(doc);
/* Export bookmarks in rdf */
- rdf_file = g_build_filename (ephy_dot_dir (),
- "bookmarks.rdf",
- NULL);
- ephy_bookmarks_export_rdf (eb, rdf_file);
- g_free (rdf_file);
+ ephy_bookmarks_export_rdf (eb, eb->priv->rdf_file);
}
static gboolean
@@ -667,7 +674,10 @@ ephy_bookmarks_init (EphyBookmarks *eb)
eb->priv->dirty = FALSE;
eb->priv->save_timeout_id = 0;
eb->priv->xml_file = g_build_filename (ephy_dot_dir (),
- "bookmarks.xml",
+ "ephy-bookmarks.xml",
+ NULL);
+ eb->priv->rdf_file = g_build_filename (ephy_dot_dir (),
+ "bookmarks.rdf",
NULL);
/* Bookmarks */
@@ -739,7 +749,13 @@ ephy_bookmarks_init (EphyBookmarks *eb)
g_value_unset (&value);
ephy_node_add_child (eb->priv->keywords, eb->priv->notcategorized);
- eb->priv->init_defaults = !ephy_bookmarks_load (eb);
+ if (!ephy_bookmarks_load (eb))
+ {
+ if (!ephy_bookmarks_import_rdf (eb, eb->priv->rdf_file))
+ {
+ eb->priv->init_defaults = !ephy_bookmarks_load (eb);
+ }
+ }
ephy_bookmarks_emit_data_changed (eb);
@@ -778,6 +794,9 @@ ephy_bookmarks_finalize (GObject *object)
(gpointer *)&eb->priv->toolbars_model);
}
+ g_free (eb->priv->xml_file);
+ g_free (eb->priv->rdf_file);
+
g_free (eb->priv);
LOG ("Bookmarks finalized")