Pick fallback extension based on MIME type

This commit is contained in:
Christian Dywan 2012-02-19 22:57:45 +01:00
parent f549824b66
commit b20a1e7efd

View file

@ -5008,6 +5008,23 @@ midori_view_get_uri_extension (const gchar* uri)
return g_strdup (period); return g_strdup (period);
} }
static const gchar*
midori_view_fallback_extension (MidoriView* view,
const gchar* extension)
{
if (!view->mime_type)
extension = "";
if (extension && *extension)
return extension;
if (strstr (view->mime_type, "css"))
return ".css";
if (strstr (view->mime_type, "javascript"))
return ".js";
if (strstr (view->mime_type, "html"))
return ".htm";
return "";
}
/** /**
* midori_view_save_source: * midori_view_save_source:
* @view: a #MidoriView * @view: a #MidoriView
@ -5044,7 +5061,7 @@ midori_view_save_source (MidoriView* view,
{ {
gchar* extension = midori_view_get_uri_extension (uri); gchar* extension = midori_view_get_uri_extension (uri);
gchar* filename = g_strdup_printf ("%uXXXXXX%s", gchar* filename = g_strdup_printf ("%uXXXXXX%s",
g_str_hash (uri), extension && *extension ? extension : ".htm"); g_str_hash (uri), midori_view_fallback_extension (view, extension));
g_free (extension); g_free (extension);
fd = g_file_open_tmp (filename, &unique_filename, NULL); fd = g_file_open_tmp (filename, &unique_filename, NULL);
g_free (filename); g_free (filename);