summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@it.gnome.org>2003-01-07 20:34:09 +0000
committerMarco Pesenti Gritti <mpeseng@src.gnome.org>2003-01-07 20:34:09 +0000
commit977e13469d48102bc3812140bdf3faf955e9f11a (patch)
tree133d157d8c0399adf9792a32207fcfa41ccbfeab
parentc088c9ab24ffeafeef6b7b092facb6f3f57efc28 (diff)
downloadepiphany-977e13469d48102bc3812140bdf3faf955e9f11a.tar.gz
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.
-rw-r--r--ChangeLog19
-rw-r--r--data/starthere/Makefile.am7
-rw-r--r--data/starthere/index.xml.in19
-rw-r--r--data/starthere/section.css29
-rw-r--r--data/starthere/section.xsl45
-rw-r--r--embed/mozilla/StartHereProtocolHandler.cpp22
-rw-r--r--embed/mozilla/mozilla-embed-shell.cpp35
-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
11 files changed, 290 insertions, 31 deletions
diff --git a/ChangeLog b/ChangeLog
index 567bf2244..c40c11cce 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,24 @@
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.
+
+2003-01-07 Marco Pesenti Gritti <marco@it.gnome.org>
+
* configure.in:
* data/Makefile.am:
* data/start_here.html:
diff --git a/data/starthere/Makefile.am b/data/starthere/Makefile.am
index 411c442cf..77b723f8b 100644
--- a/data/starthere/Makefile.am
+++ b/data/starthere/Makefile.am
@@ -4,9 +4,10 @@ xmldir = $(pkgdatadir)/starthere
xml_in_files = index.xml.in
xml_DATA = $(xml_in_files:.xml.in=.xml)
-xsldir = $(pkgdatadir)/starthere
-xsl_DATA = section.xsl
+pagedir = $(pkgdatadir)/starthere
+page_DATA = section.xsl section.css
EXTRA_DIST = $(xml_DATA) \
- $(xml_in_files)
+ $(xml_in_files) \
+ $(page_DATA)
diff --git a/data/starthere/index.xml.in b/data/starthere/index.xml.in
index b24de14f1..dd8a0f9a8 100644
--- a/data/starthere/index.xml.in
+++ b/data/starthere/index.xml.in
@@ -1,8 +1,23 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="section.xsl"?>
<section>
+<bar>
+<item section="start-here:">Start Here</item>
+<item section="start-here:smartbookmarks">Smart Bookmarks</item>
+</bar>
<_title>The web browser</_title>
-<_paragraph>What you use it for ?</_paragraph>
+<_paragraph>
+You can start browsing web pages either by typing a location (example: www.google.com)
+or a keyword (example: best computer shop) in the toolbar text entry.
+</_paragraph>
<_title>Getting started</_title>
-<_paragraph>How I begin ? Import bookmarks, proxy settings</_paragraph>
+<_paragraph>
+To import bookmarks from another browser installed on your system just
+click on one of the links below:
+<content id="bookmarks-import"/>
+</_paragraph>
+<_paragraph>
+If your internet connection requires it, make sure to setup your proxy in the
+desktop wide <_action>configuration dialog</_action>.
+</_paragraph>
</section>
diff --git a/data/starthere/section.css b/data/starthere/section.css
new file mode 100644
index 000000000..6b0cf8608
--- /dev/null
+++ b/data/starthere/section.css
@@ -0,0 +1,29 @@
+body {
+ margin-left: 150;
+ margin-right: 150;
+ background: #000000;
+ color: #FFFFFF;
+ font-family: Verdana, Helvetica, Arial, sans-serif;
+ font-size: 14px;
+}
+
+div.topbar {
+ height: 25px;
+ padding: 7px;
+ color: #000000;
+ background-color: #e57f20;
+ font-weight: bold;
+ margin-bottom: 50;
+}
+
+div.topbar a {
+ margin-right: 15;
+ font-size: 20px;
+ font-weight: bold;
+ color: #000000;
+}
+
+h2 {
+ color: #e57f20;
+ font-size: 18px;
+}
diff --git a/data/starthere/section.xsl b/data/starthere/section.xsl
index 6b349c626..62bdcf598 100644
--- a/data/starthere/section.xsl
+++ b/data/starthere/section.xsl
@@ -3,15 +3,14 @@
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
-<!-- root rule -->
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
-<!-- main rule for document element -->
<xsl:template match="section">
<html>
<head>
+ <link rel="stylesheet" href="section.css" type="text/css"/>
</head>
<body>
<xsl:apply-templates/>
@@ -19,5 +18,47 @@
</html>
</xsl:template>
+<xsl:template match="content">
+<div class="body">
+ <xsl:apply-templates/>
+</div>
+</xsl:template>
+
+<xsl:template match="bar">
+<div class="topbar">
+ <xsl:apply-templates/>
+</div>
+</xsl:template>
+
+<xsl:template match="item">
+<a href="{@section}">
+ <xsl:apply-templates/>
+</a>
+</xsl:template>
+
+<xsl:template match="title">
+<h2>
+ <xsl:apply-templates/>
+</h2>
+</xsl:template>
+
+<xsl:template match="paragraph">
+<p>
+ <xsl:apply-templates/>
+</p>
+</xsl:template>
+
+<xsl:template match="buildcontent">
+<p>
+ <xsl:apply-templates/>
+</p>
+</xsl:template>
+
+<xsl:template match="action">
+<a href="action:{@id}?{@param}">
+ <xsl:apply-templates/>
+</a>
+</xsl:template>
+
</xsl:stylesheet>
diff --git a/embed/mozilla/StartHereProtocolHandler.cpp b/embed/mozilla/StartHereProtocolHandler.cpp
index 4ea95294c..2d2bb3c35 100644
--- a/embed/mozilla/StartHereProtocolHandler.cpp
+++ b/embed/mozilla/StartHereProtocolHandler.cpp
@@ -41,7 +41,6 @@ class GStartHereProtocolHandler : public nsIProtocolHandler
virtual ~GStartHereProtocolHandler();
nsCOMPtr<nsIChannel> mChannel;
- nsCOMPtr<nsIURI> mURI;
};
/* Implementation file */
@@ -115,10 +114,9 @@ NS_IMETHODIMP GStartHereProtocolHandler::NewChannel(nsIURI *aURI,
nsresult rv;
EphyStartHere *sh;
char *buf;
+ const char *aBaseURI;
PRUint32 bytesWritten;
-
- mURI = aURI;
-
+
nsCAutoString path;
rv = aURI->GetPath(path);
if (NS_FAILED(rv)) return rv;
@@ -134,9 +132,16 @@ NS_IMETHODIMP GStartHereProtocolHandler::NewChannel(nsIURI *aURI,
sh = ephy_start_here_new ();
buf = ephy_start_here_get_page (sh, "index");
- rv = stream->Write (buf, strlen (buf), &bytesWritten);
- g_free (buf);
+ aBaseURI = ephy_start_here_get_base_uri (sh);
+ rv = stream->Write (buf, strlen (buf), &bytesWritten);
+ if (NS_FAILED (rv)) return NS_ERROR_FAILURE;
+
+ nsCOMPtr<nsIURI> uri;
+ nsCAutoString spec(aBaseURI);
+ rv = NS_NewURI(getter_AddRefs(uri), spec.get());
+ if (NS_FAILED (rv)) return NS_ERROR_FAILURE;
+
nsCOMPtr<nsIInputStream> iStream;
PRUint32 size;
@@ -146,10 +151,13 @@ NS_IMETHODIMP GStartHereProtocolHandler::NewChannel(nsIURI *aURI,
rv = sStream->NewInputStream(0, getter_AddRefs(iStream));
if (NS_FAILED(rv)) return rv;
- rv = NS_NewInputStreamChannel(getter_AddRefs(mChannel), mURI,
+ rv = NS_NewInputStreamChannel(getter_AddRefs(mChannel), uri,
iStream, NS_LITERAL_CSTRING("text/xml"),
NS_LITERAL_CSTRING("utf-8"), size);
+ g_free (buf);
+ g_object_unref (sh);
+
NS_IF_ADDREF (*_retval = mChannel);
return rv;
diff --git a/embed/mozilla/mozilla-embed-shell.cpp b/embed/mozilla/mozilla-embed-shell.cpp
index 8a66191b9..6b8c5e8f1 100644
--- a/embed/mozilla/mozilla-embed-shell.cpp
+++ b/embed/mozilla/mozilla-embed-shell.cpp
@@ -184,6 +184,39 @@ mozilla_embed_shell_class_init (MozillaEmbedShellClass *klass)
}
static void
+mozilla_load_language_prefs (MozillaEmbedShell *shell)
+{
+ GString *langs;
+ const GList *l;
+
+ langs = g_string_new (NULL);
+
+ l = gnome_i18n_get_language_list ("LC_MESSAGES");
+ for (; l != NULL; l = l->next)
+ {
+ char *lang = (char *)l->data;
+ int len;
+ char *lg, *enc;
+
+ g_print ("%s\n", lang);
+
+ lg = strchr (lang, '_');
+ enc = strchr (lang, '.');
+
+ len = strlen (lang);
+ if (enc) len = enc - lang;
+ if (lg) len = lg - lang;
+
+ g_string_append (langs, ",");
+ g_string_append_len (langs, lang, len);
+ }
+
+ mozilla_prefs_set_string ("intl.accept_languages", langs->str + 1);
+
+ g_string_free (langs, TRUE);
+}
+
+static void
mozilla_load_proxy_prefs (MozillaEmbedShell *shell)
{
char *tmp;
@@ -424,6 +457,8 @@ mozilla_embed_shell_init (MozillaEmbedShell *mes)
}
mozilla_load_proxy_prefs (mes);
+
+ mozilla_load_language_prefs (mes);
mozilla_init_single (mes);
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