aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@it.gnome.org>2003-01-08 04:34:09 +0800
committerMarco Pesenti Gritti <mpeseng@src.gnome.org>2003-01-08 04:34:09 +0800
commit977e13469d48102bc3812140bdf3faf955e9f11a (patch)
tree133d157d8c0399adf9792a32207fcfa41ccbfeab /lib
parentc088c9ab24ffeafeef6b7b092facb6f3f57efc28 (diff)
downloadgsoc2013-epiphany-977e13469d48102bc3812140bdf3faf955e9f11a.tar
gsoc2013-epiphany-977e13469d48102bc3812140bdf3faf955e9f11a.tar.gz
gsoc2013-epiphany-977e13469d48102bc3812140bdf3faf955e9f11a.tar.bz2
gsoc2013-epiphany-977e13469d48102bc3812140bdf3faf955e9f11a.tar.lz
gsoc2013-epiphany-977e13469d48102bc3812140bdf3faf955e9f11a.tar.xz
gsoc2013-epiphany-977e13469d48102bc3812140bdf3faf955e9f11a.tar.zst
gsoc2013-epiphany-977e13469d48102bc3812140bdf3faf955e9f11a.zip
More work on the start here page.
2003-01-07 Marco Pesenti Gritti <marco@it.gnome.org> * data/starthere/Makefile.am: * data/starthere/index.xml.in: * data/starthere/section.css: * data/starthere/section.xsl: * embed/mozilla/StartHereProtocolHandler.cpp: * embed/mozilla/mozilla-embed-shell.cpp: * lib/ephy-file-helpers.c: (ephy_ensure_dir_exists), (ephy_find_file_recursive), (ephy_file_find): * lib/ephy-file-helpers.h: * lib/ephy-start-here.c: (ephy_start_here_init), (ephy_start_here_finalize), (is_my_lang), (mozilla_bookmarks), (attach_content), (build_content), (ephy_start_here_get_page), (ephy_start_here_get_base_uri): * lib/ephy-start-here.h: More work on the start here page.
Diffstat (limited to 'lib')
-rw-r--r--lib/ephy-file-helpers.c41
-rw-r--r--lib/ephy-file-helpers.h3
-rw-r--r--lib/ephy-start-here.c99
-rw-r--r--lib/ephy-start-here.h2
4 files changed, 128 insertions, 17 deletions
diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c
index 2e867e3f5..1b66004f0 100644
--- a/lib/ephy-file-helpers.c
+++ b/lib/ephy-file-helpers.c
@@ -22,6 +22,7 @@
#include <config.h>
#endif
+#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
@@ -324,3 +325,43 @@ ephy_ensure_dir_exists (const char *dir)
g_error (_("Failed to create directory %s."), dir);
}
}
+
+static void
+ephy_find_file_recursive (const char *path,
+ const char *fname, GSList **l,
+ gint depth, gint maxdepth)
+{
+ GDir *d = g_dir_open (path, 0, NULL);
+ const gchar *f;
+ if (d)
+ {
+ while ((f = g_dir_read_name (d)))
+ {
+ char *new_path = g_build_filename (path, f, NULL);
+ if (depth < maxdepth)
+ {
+ ephy_find_file_recursive (new_path, fname, l,
+ depth + 1, maxdepth);
+ }
+ if (!strcmp (f, fname))
+ {
+ *l = g_slist_prepend (*l, new_path);
+ }
+ else
+ {
+ g_free (new_path);
+ }
+ }
+ g_dir_close (d);
+ }
+}
+
+GSList *
+ephy_file_find (const char *path,
+ const char *fname,
+ gint maxdepth)
+{
+ GSList *ret = NULL;
+ ephy_find_file_recursive (path, fname, &ret, 0, maxdepth);
+ return ret;
+}
diff --git a/lib/ephy-file-helpers.h b/lib/ephy-file-helpers.h
index 75f6a0e9e..0fb24b254 100644
--- a/lib/ephy-file-helpers.h
+++ b/lib/ephy-file-helpers.h
@@ -42,6 +42,9 @@ char *ephy_file_tmp_filename (const char *base,
void ephy_ensure_dir_exists (const char *dir);
+GSList *ephy_file_find (const char *path,
+ const char *fname,
+ gint maxdepth);
G_END_DECLS
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;
+}
diff --git a/lib/ephy-start-here.h b/lib/ephy-start-here.h
index addbe45cf..df2b2ce26 100644
--- a/lib/ephy-start-here.h
+++ b/lib/ephy-start-here.h
@@ -54,6 +54,8 @@ EphyStartHere *ephy_start_here_new (void);
char *ephy_start_here_get_page (EphyStartHere *sh,
const char *id);
+const char *ephy_start_here_get_base_uri (EphyStartHere *sh);
+
G_END_DECLS
#endif