From 2b5cfe828cef29dd20225540fdd2bf5fcbf6b8fc Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Tue, 29 May 2012 14:30:49 +0200 Subject: e-file-helpers: Add ephy_file_create_data_uri_for_filename() It creates a data URI for the given filename. Use the new function when building error and applications pages. https://bugzilla.gnome.org/show_bug.cgi?id=677025 --- embed/ephy-request-about.c | 16 +++++++--------- embed/ephy-web-view.c | 33 +-------------------------------- 2 files changed, 8 insertions(+), 41 deletions(-) (limited to 'embed') diff --git a/embed/ephy-request-about.c b/embed/ephy-request-about.c index e239c1123..bfff22f95 100644 --- a/embed/ephy-request-about.c +++ b/embed/ephy-request-about.c @@ -182,19 +182,17 @@ ephy_request_about_send (SoupRequest *request, applications = ephy_web_application_get_application_list (); for (p = applications; p; p = p->next) { - char *img_data = NULL, *img_data_base64 = NULL; - gsize data_length; + char *icon_uri; EphyWebApplication *app = (EphyWebApplication*)p->data; - - if (g_file_get_contents (app->icon_url, &img_data, &data_length, NULL)) - img_data_base64 = g_base64_encode ((guchar*)img_data, data_length); - g_string_append_printf (data_str, "" \ + + icon_uri = ephy_file_create_data_uri_for_filename (app->icon_url, "image/png"); + g_string_append_printf (data_str, "" \ "
%s
%s
%s
%s", - img_data_base64, app->name, app->url, app->name, + icon_uri ? icon_uri : "", + app->name, app->url, app->name, /* Note for translators: this refers to the installation date. */ _("Installed on:"), app->install_date); - g_free (img_data_base64); - g_free (img_data); + g_free (icon_uri); } g_string_append (data_str, ""); diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c index f0b3d8f94..e4ae30f09 100644 --- a/embed/ephy-web-view.c +++ b/embed/ephy-web-view.c @@ -2052,37 +2052,6 @@ load_status_cb (WebKitWebView *web_view, g_object_thaw_notify (object); } -static char * -get_file_content_as_base64 (const char *path) -{ - GFile *file; - GFileInfo *file_info; - const char *image_type; - char *image_raw; - gsize len; - char *image_data; - char *image64; - - file = g_file_new_for_path (path); - file_info = g_file_query_info (file, - G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, - G_FILE_QUERY_INFO_NONE, - NULL, NULL); - image_type = g_file_info_get_content_type (file_info); - - g_file_get_contents (path, &image_raw, &len, NULL); - image_data = g_base64_encode ((guchar *) image_raw, len); - image64 = g_strdup_printf ("data:%s;base64,%s", image_type, image_data); - - g_free (image_raw); - g_free (image_data); - - g_object_unref (file); - g_object_unref (file_info); - - return image64; -} - /** * ephy_web_view_load_error_page: * @view: an #EphyWebView @@ -2175,7 +2144,7 @@ ephy_web_view_load_error_page (EphyWebView *view, 48, GTK_ICON_LOOKUP_GENERIC_FALLBACK); - image_data = icon_info ? get_file_content_as_base64 (gtk_icon_info_get_filename (icon_info)) : NULL; + 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); -- cgit v1.2.3