aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ephy-start-here.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ephy-start-here.c')
-rw-r--r--lib/ephy-start-here.c99
1 files changed, 82 insertions, 17 deletions
diff --git a/lib/ephy-start-here.c b/lib/ephy-start-here.c
index 8906155b9..7363baeb2 100644
--- a/lib/ephy-start-here.c
+++ b/lib/ephy-start-here.c
@@ -29,6 +29,8 @@
struct EphyStartHerePrivate
{
const GList *langs;
+ char *base_uri;
+ xmlDocPtr doc;
};
static void
@@ -84,6 +86,9 @@ ephy_start_here_init (EphyStartHere *eb)
eb->priv = g_new0 (EphyStartHerePrivate, 1);
eb->priv->langs = gnome_i18n_get_language_list ("LC_MESSAGES");
+ eb->priv->base_uri = g_strconcat ("file://",
+ ephy_file ("starthere/"),
+ NULL);
}
static void
@@ -97,6 +102,8 @@ ephy_start_here_finalize (GObject *object)
g_return_if_fail (eb->priv != NULL);
+ g_free (eb->priv->base_uri);
+
g_free (eb->priv);
G_OBJECT_CLASS (parent_class)->finalize (object);
@@ -119,18 +126,9 @@ is_my_lang (EphyStartHere *sh, char *my_lang)
for (l = sh->priv->langs; l != NULL; l = l->next)
{
- char *lang = l->data;
- int len;
- char *lg, *enc;
-
- lg = strchr (my_lang, '_');
- enc = strchr (my_lang, '.');
+ char *lang = (char *)l->data;
- len = strlen (my_lang);
- if (enc) len = enc - my_lang;
- if (lg) len = lg - my_lang;
-
- if (strncmp (lang, my_lang, len) == 0)
+ if (strcmp (lang, my_lang) == 0)
return TRUE;
}
@@ -206,10 +204,70 @@ select_language (EphyStartHere *sh, xmlNodePtr node)
}
}
+static char *
+mozilla_bookmarks (void)
+{
+ GSList *l;
+ char *dir;
+ char *result;
+
+ dir = g_build_filename (g_get_home_dir (), ".mozilla", NULL);
+ l = ephy_file_find (dir, "bookmarks.html", 4);
+ g_free (dir);
+
+ result = l ? g_strdup (l->data) : NULL;
+
+ g_slist_foreach (l, (GFunc) g_free, NULL);
+ g_slist_free (l);
+
+ return result;
+}
+
+static void
+attach_content (EphyStartHere *sh, xmlNodePtr node, xmlChar *id)
+{
+ if (xmlStrEqual (id, "bookmarks-import"))
+ {
+ xmlNodePtr child;
+ char *bmk_file;
+
+ bmk_file = mozilla_bookmarks ();
+ if (bmk_file)
+ {
+ child = xmlNewDocNode (sh->priv->doc, NULL, "action",
+ _("Import mozilla bookmarks"));
+ xmlSetProp (child, "id", "import-bookmarks");
+ xmlSetProp (child, "param", bmk_file);
+ xmlAddChild (node, child);
+ }
+ g_free (bmk_file);
+ }
+}
+
+static void
+build_content (EphyStartHere *sh, xmlNodePtr node)
+{
+ while (node)
+ {
+ xmlChar *id;
+ xmlNodePtr next;
+
+ next = node->next;
+
+ id = xmlGetProp (node, "id");
+ if (id)
+ {
+ attach_content (sh, node, id);
+ xmlFree (id);
+ }
+
+ build_content (sh, node->children);
+ node = node->next;
+ }
+}
char *
ephy_start_here_get_page (EphyStartHere *sh, const char *id)
{
- xmlDocPtr doc;
xmlNodePtr child;
xmlNodePtr root;
xmlBufferPtr buf;
@@ -221,22 +279,29 @@ ephy_start_here_get_page (EphyStartHere *sh, const char *id)
xml_filepath = ephy_file (xml_filename);
g_free (xml_filename);
- doc = xmlParseFile (xml_filepath);
- root = xmlDocGetRootElement (doc);
+ sh->priv->doc = xmlParseFile (xml_filepath);
+ root = xmlDocGetRootElement (sh->priv->doc);
buf = xmlBufferCreate ();
select_language (sh, root);
+ build_content (sh, root);
- child = doc->children;
+ child = sh->priv->doc->children;
while (child)
{
- xmlNodeDump (buf, doc, child, 1, 1);
+ xmlNodeDump (buf, sh->priv->doc, child, 1, 1);
child = child->next;
}
content = g_strdup (xmlBufferContent (buf));
xmlBufferFree (buf);
- xmlFreeDoc (doc);
+ xmlFreeDoc (sh->priv->doc);
return content;
}
+
+const char *
+ephy_start_here_get_base_uri (EphyStartHere *sh)
+{
+ return sh->priv->base_uri;
+}