aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVincent Untz <vuntz@src.gnome.org>2009-03-03 21:07:11 +0800
committerVincent Untz <vuntz@src.gnome.org>2009-03-03 21:07:11 +0800
commitbf4027081dd79cb6593aa9f0ef465f0be234888e (patch)
treecae901afa57cb5002f6995c30a47ecf5bde4f4e7 /src
parent44a02e8cebe8bee54730e7954684b415ee797f08 (diff)
downloadgsoc2013-epiphany-bf4027081dd79cb6593aa9f0ef465f0be234888e.tar
gsoc2013-epiphany-bf4027081dd79cb6593aa9f0ef465f0be234888e.tar.gz
gsoc2013-epiphany-bf4027081dd79cb6593aa9f0ef465f0be234888e.tar.bz2
gsoc2013-epiphany-bf4027081dd79cb6593aa9f0ef465f0be234888e.tar.lz
gsoc2013-epiphany-bf4027081dd79cb6593aa9f0ef465f0be234888e.tar.xz
gsoc2013-epiphany-bf4027081dd79cb6593aa9f0ef465f0be234888e.tar.zst
gsoc2013-epiphany-bf4027081dd79cb6593aa9f0ef465f0be234888e.zip
Fix the RDF bookmark importer (bug #129852).
Correctly handle translations (for title, but also for localized URL). Correctly handle bookmark topics. svn path=/trunk/; revision=8840
Diffstat (limited to 'src')
-rw-r--r--src/bookmarks/ephy-bookmarks-import.c122
1 files changed, 77 insertions, 45 deletions
diff --git a/src/bookmarks/ephy-bookmarks-import.c b/src/bookmarks/ephy-bookmarks-import.c
index 7d5a4918e..c50027e7c 100644
--- a/src/bookmarks/ephy-bookmarks-import.c
+++ b/src/bookmarks/ephy-bookmarks-import.c
@@ -812,49 +812,65 @@ ephy_bookmarks_import_xbel (EphyBookmarks *bookmarks,
return ret >= 0 ? TRUE : FALSE;
}
-#define OLD_RDF_TEMPORARY_HACK
-
static void
-parse_rdf_subjects (xmlNodePtr node,
- GList **subjects)
+parse_rdf_lang_tag (xmlNode *child,
+ xmlChar **value,
+ int *best_match)
{
- xmlChar *subject;
-
-#ifdef OLD_RDF_TEMPORARY_HACK
- xmlNode *child;
-
- child = node->children;
-
- while (child != NULL)
+ const char * const *locales;
+ char *this_language;
+ xmlChar *lang;
+ xmlChar *content;
+ int i;
+
+ if (*best_match == 0)
+ /* there's no way we can do better */
+ return;
+
+ content = xmlNodeGetContent (child);
+ if (!content)
+ return;
+
+ lang = xmlNodeGetLang (child);
+ if (lang == NULL)
{
- if (xmlStrEqual (child->name, (xmlChar *) "Bag"))
- {
- child = child->children;
-
- while (child != NULL)
- {
- if (xmlStrEqual (child->name, (xmlChar *) "li"))
- {
- subject = xmlNodeGetContent (child);
- *subjects = g_list_append (*subjects, subject);
- }
+ const char *translated;
- child = child->next;
- }
+ translated = _((char *) content);
+ if ((char *) content != translated)
+ {
+ /* if we have a translation for the content of the
+ * node, then we just use this */
+ if (*value) xmlFree (*value);
+ *value = (xmlChar *) g_strdup (translated);
+ *best_match = 0;
+ xmlFree (content);
return;
}
- child = child->next;
+ this_language = "C";
}
-#endif
+ else
+ this_language = (char *) lang;
- subject = xmlNodeGetContent (node);
+ locales = g_get_language_names ();
- if (subject)
- {
- *subjects = g_list_append (*subjects, subject);
+ for (i = 0; locales[i] && i < *best_match; i++) {
+ if (!strcmp (locales[i], this_language)) {
+ /* if we've already encountered a less accurate
+ * translation, then free it */
+ if (*value) xmlFree (*value);
+
+ *value = content;
+ *best_match = i;
+
+ break;
+ }
}
+
+ if (lang) xmlFree (lang);
+ if (*value != content) xmlFree (content);
}
static void
@@ -862,43 +878,59 @@ parse_rdf_item (EphyBookmarks *bookmarks,
xmlNodePtr node)
{
xmlChar *title = NULL;
+ int best_match_title = INT_MAX;
xmlChar *link = NULL;
+ int best_match_link = INT_MAX;
+ /* we consider that it's better to use a non-localized smart link than
+ * a localized link */
+ gboolean use_smartlink = FALSE;
+ xmlChar *subject = NULL;
GList *subjects = NULL, *l = NULL;
xmlNode *child;
- EphyNode *bmk;
+ EphyNode *bmk = NULL;
child = node->children;
-#ifdef OLD_RDF_TEMPORARY_HACK
link = xmlGetProp (node, (xmlChar *) "about");
-#endif
while (child != NULL)
{
if (xmlStrEqual (child->name, (xmlChar *) "title"))
{
- title = xmlNodeGetContent (child);
+ parse_rdf_lang_tag (child, &title, &best_match_title);
}
-#ifndef OLD_RDF_TEMPORARY_HACK
- else if (xmlStrEqual (child->name, (xmlChar *) "link"))
+ else if (xmlStrEqual (child->name, (xmlChar *) "link") &&
+ !use_smartlink)
{
- link = xmlNodeGetContent (child);
+ parse_rdf_lang_tag (child, &link, &best_match_link);
}
-#endif
- else if (xmlStrEqual (child->name, (xmlChar *) "subject"))
+ else if (child->ns &&
+ xmlStrEqual (child->ns->prefix, (xmlChar *) "ephy") &&
+ xmlStrEqual (child->name, (xmlChar *) "smartlink"))
{
- parse_rdf_subjects (child, &subjects);
+ if (!use_smartlink)
+ {
+ use_smartlink = TRUE;
+ best_match_link = INT_MAX;
+ }
+
+ parse_rdf_lang_tag (child, &link, &best_match_link);
}
- else if (xmlStrEqual (child->name, (xmlChar *) "smartlink"))
+ else if (child->ns &&
+ xmlStrEqual (child->ns->prefix, (xmlChar *) "dc") &&
+ xmlStrEqual (child->name, (xmlChar *) "subject"))
{
- if (link) xmlFree (link);
- link = xmlNodeGetContent (child);
+ subject = xmlNodeGetContent (child);
+ if (subject)
+ subjects = g_list_prepend (subjects, subject);
}
child = child->next;
}
- bmk = bookmark_add (bookmarks, (char *) title, (char *) link);
+ if (link)
+ bmk = bookmark_add (bookmarks, (char *) title, (char *) link);
+
if (bmk)
{
l = subjects;