[epiphany] Compile template pages as GResources
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] Compile template pages as GResources
- Date: Fri, 5 Apr 2013 13:47:48 +0000 (UTC)
commit a2181b928e5a0f6d27487859fe86a276c1eed25c
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Thu Mar 28 17:06:47 2013 +0100
Compile template pages as GResources
So that they are loaded from memory instead of disk every time they are
needed.
We also get rid of ephy_file searching for the files in the file system.
https://bugzilla.gnome.org/show_bug.cgi?id=696792
data/pages/Makefile.am | 8 +-----
embed/ephy-web-view.c | 24 +++++++++----------
src/Makefile.am | 11 +++++---
src/epiphany.gresource.xml | 3 ++
{data/pages => src/resources}/error.html | 0
.../resources/process-crash.html | 0
{data/pages => src/resources}/recovery.html | 0
tests/Makefile.am | 1 +
8 files changed, 23 insertions(+), 24 deletions(-)
---
diff --git a/data/pages/Makefile.am b/data/pages/Makefile.am
index 4b00a41..0ff1540 100644
--- a/data/pages/Makefile.am
+++ b/data/pages/Makefile.am
@@ -1,11 +1,5 @@
-errorpagesdir = $(pkgdatadir)/pages
-errorpages_DATA = \
- recovery.html \
- process_crash.html \
- error.html
-
stylepagesdir = $(pkgdatadir)/pages
stylepages_DATA = \
about.css
-EXTRA_DIST = $(errorpages_DATA) $(stylepages_DATA)
+EXTRA_DIST = $(stylepages_DATA)
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index ce0312a..92cdb38 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -63,6 +63,10 @@
#define MAX_TITLE_LENGTH 512 /* characters */
#define EMPTY_PAGE _("Blank page") /* Title for the empty page */
+#define EPHY_PAGE_TEMPLATE_ERROR "/org/gnome/epiphany/page-templates/error.html"
+#define EPHY_PAGE_TEMPLATE_RECOVERY "/org/gnome/epiphany/page-templates/recovery.html"
+#define EPHY_PAGE_TEMPLATE_PROCESS_CRASH "/org/gnome/epiphany/page-templates/process-crash.html"
+
struct _EphyWebViewPrivate {
EphyWebViewSecurityLevel security_level;
EphyWebViewDocumentType document_type;
@@ -1699,22 +1703,17 @@ ephy_web_view_load_error_page (EphyWebView *view,
{
GString *html = g_string_new ("");
const char *reason;
-
char *hostname;
char *lang;
-
char *page_title;
char *msg_title;
char *msg;
char *button_label;
- const char *html_file;
+ GBytes *html_file;
const char *stock_icon;
-
GtkIconInfo *icon_info;
char *image_data;
- char *template;
-
if (error)
reason = error->message;
else
@@ -1741,7 +1740,7 @@ ephy_web_view_load_error_page (EphyWebView *view,
button_label = g_strdup (_("Try again"));
- html_file = ephy_file ("error.html");
+ html_file = g_resources_lookup_data (EPHY_PAGE_TEMPLATE_ERROR, 0, NULL);
stock_icon = "dialog-error";
break;
case EPHY_WEB_VIEW_ERROR_PAGE_CRASH:
@@ -1759,7 +1758,7 @@ ephy_web_view_load_error_page (EphyWebView *view,
button_label = g_strdup (_("Load again anyway"));
- html_file = ephy_file ("recovery.html");
+ html_file = g_resources_lookup_data (EPHY_PAGE_TEMPLATE_RECOVERY, 0, NULL);
stock_icon = "dialog-information";
break;
case EPHY_WEB_VIEW_ERROR_PROCESS_CRASH:
@@ -1768,7 +1767,7 @@ ephy_web_view_load_error_page (EphyWebView *view,
msg = g_strdup (_("Something went wrong while displaying this page. Please reload or visit a different
page to continue."));
button_label = NULL;
- html_file = ephy_file ("process_crash.html");
+ html_file = g_resources_lookup_data (EPHY_PAGE_TEMPLATE_PROCESS_CRASH, 0, NULL);
stock_icon = "computer-fail-symbolic";
break;
@@ -1785,13 +1784,12 @@ ephy_web_view_load_error_page (EphyWebView *view,
image_data = icon_info ? ephy_file_create_data_uri_for_filename (gtk_icon_info_get_filename (icon_info),
NULL) : NULL;
- g_file_get_contents (html_file, &template, NULL, NULL);
-
ephy_web_view_set_title (view, page_title);
_ephy_web_view_update_icon (view);
- g_string_printf (html, template,
+ g_string_printf (html,
+ g_bytes_get_data (html_file, NULL),
lang, lang,
((gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL) ? "rtl" : "ltr"),
page_title,
@@ -1799,7 +1797,7 @@ ephy_web_view_load_error_page (EphyWebView *view,
image_data ? image_data : "",
msg_title, msg, button_label);
- g_free (template);
+ g_bytes_unref (html_file);
g_free (lang);
g_free (page_title);
g_free (msg_title);
diff --git a/src/Makefile.am b/src/Makefile.am
index 290ca0f..b7e6448 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,7 +8,7 @@ bin_PROGRAMS = epiphany
EXTRA_DIST = \
epiphany.gresource.xml \
- $(UI_FILES) \
+ $(RESOURCE_FILES) \
$(NULL)
NOINST_H_FILES = \
@@ -98,7 +98,7 @@ libephymain_la_CFLAGS = \
$(CODE_COVERAGE_CFLAGS) \
$(AM_CFLAGS)
-UI_FILES = \
+RESOURCE_FILES = \
resources/epiphany-bookmark-editor-ui.xml \
resources/epiphany-history-window-ui.xml \
resources/epiphany-ui.xml \
@@ -106,12 +106,15 @@ UI_FILES = \
resources/epiphany-application-menu.ui \
resources/prefs-dialog.ui \
resources/epiphany.css \
+ resources/error.html \
+ resources/process-crash.html \
+ resources/recovery.html \
$(NULL)
-epiphany-resources.c: epiphany.gresource.xml $(UI_FILES)
+epiphany-resources.c: epiphany.gresource.xml $(RESOURCE_FILES)
$(AM_V_GEN)glib-compile-resources --target=$@ --sourcedir=$(srcdir)/resources --generate-source
--c-name epiphany $(srcdir)/epiphany.gresource.xml
-epiphany-resources.h: epiphany.gresource.xml $(UI_FILES)
+epiphany-resources.h: epiphany.gresource.xml $(RESOURCE_FILES)
$(AM_V_GEN)glib-compile-resources --target=$@ --sourcedir=$(srcdir)/resources --generate-header
--c-name epiphany $(srcdir)/epiphany.gresource.xml
EPIPHANY_RESOURCES = \
diff --git a/src/epiphany.gresource.xml b/src/epiphany.gresource.xml
index b756466..8e4d719 100644
--- a/src/epiphany.gresource.xml
+++ b/src/epiphany.gresource.xml
@@ -8,5 +8,8 @@
<file preprocess="xml-stripblanks">epiphany-bookmark-editor-ui.xml</file>
<file preprocess="xml-stripblanks">epiphany-history-window-ui.xml</file>
<file>epiphany.css</file>
+ <file alias="page-templates/error.html" compressed="true">error.html</file>
+ <file alias="page-templates/process-crash.html" compressed="true">process-crash.html</file>
+ <file alias="page-templates/recovery.html" compressed="true">recovery.html</file>
</gresource>
</gresources>
diff --git a/data/pages/error.html b/src/resources/error.html
similarity index 100%
rename from data/pages/error.html
rename to src/resources/error.html
diff --git a/data/pages/process_crash.html b/src/resources/process-crash.html
similarity index 100%
rename from data/pages/process_crash.html
rename to src/resources/process-crash.html
diff --git a/data/pages/recovery.html b/src/resources/recovery.html
similarity index 100%
rename from data/pages/recovery.html
rename to src/resources/recovery.html
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b69d602..1db8a32 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -177,6 +177,7 @@ test_ephy_web_app_utils_SOURCES = \
ephy-web-app-utils-test.c
test_ephy_web_view_SOURCES = \
+ $(top_builddir)/src/epiphany-resources.c \
ephy-web-view-test.c
EXTRA_DIST = \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]