From 5e8887a6997ec1b5648109e3145ee41c0b986a5e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Enrico=20Tr=C3=B6ger?= Date: Fri, 24 Oct 2008 01:15:43 +0200 Subject: [PATCH] Preserve extensions for viewing source files --- midori/midori-browser.c | 45 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/midori/midori-browser.c b/midori/midori-browser.c index f89b78fb..91210f2e 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -1648,11 +1648,51 @@ _action_zoom_normal_activate (GtkAction* action, midori_view_set_zoom_level (MIDORI_VIEW (view), 1.0f); } +static gchar* +midori_browser_get_uri_extension (const gchar* uri) +{ + gchar* extension; + gchar* slash; + gchar* period; + gchar* ext_end; + gchar* tmp = g_strdup (uri); + + /* Find the last slash in the URI and search for the last period + *after* the last slash. This is not completely accurate + but should cover most (simple) URIs */ + slash = strrchr (tmp, '/'); + /* Huh, URI without slashes? */ + if (!slash) + return g_strdup (""); + + ext_end = period = strrchr (slash, '.'); + if (!period) + return g_strdup (""); + + /* Skip the period */ + ext_end++; + /* If *ext_end is 0 here, the URI ended with a period, so skip */ + if (!*ext_end) + return g_strdup (""); + + /* Find the end of the extension */ + while (*ext_end && g_ascii_isalnum (*ext_end)) + ext_end++; + + *ext_end = 0; + extension = g_strdup (period); + + g_free (tmp); + + return extension; +} + static void midori_browser_transfer_cb (KatzeNetRequest* request, MidoriBrowser* browser) { gchar* filename; + gchar* extension; gchar* unique_filename; gchar* text_editor; gint fd; @@ -1660,7 +1700,10 @@ midori_browser_transfer_cb (KatzeNetRequest* request, if (request->data) { - filename = g_strdup_printf ("%uXXXXXX", g_str_hash (request->uri)); + extension = midori_browser_get_uri_extension (request->uri); + filename = g_strdup_printf ("%uXXXXXX%s", + g_str_hash (request->uri), extension); + g_free (extension); if (((fd = g_file_open_tmp (filename, &unique_filename, NULL)) != -1)) { if ((fp = fdopen (fd, "w"))) -- 2.39.5