diff options
author | Marco Pesenti Gritti <marco@it.gnome.org> | 2003-07-10 21:33:49 +0800 |
---|---|---|
committer | Marco Pesenti Gritti <mpeseng@src.gnome.org> | 2003-07-10 21:33:49 +0800 |
commit | d446a326bb0243e014e3d4e8e6152b6a6f9b7e28 (patch) | |
tree | fccfd27fab44f27b2d8f24c53bac8ddcefcde398 /src/bookmarks/ephy-bookmarks-import.c | |
parent | 268d6be0929222404146c78a5656ee0739af262a (diff) | |
download | gsoc2013-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).
Diffstat (limited to 'src/bookmarks/ephy-bookmarks-import.c')
-rw-r--r-- | src/bookmarks/ephy-bookmarks-import.c | 147 |
1 files changed, 145 insertions, 2 deletions
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; +} |