]> spindle.queued.net Git - midori/commitdiff
Replace illegal characters in filenames
authorMartin Natano <natano@natano.net>
Tue, 10 Apr 2012 18:54:03 +0000 (20:54 +0200)
committerChristian Dywan <christian@twotoasts.de>
Tue, 10 Apr 2012 19:29:56 +0000 (21:29 +0200)
Fixes: https://bugs.launchpad.net/midori/+bug/972931
midori/midori-browser.c
midori/midori-view.c
midori/sokoke.c
midori/sokoke.h
panels/midori-transfers.c
toolbars/midori-transferbar.c

index ae3fae0d439ee7b5b0f7c3b91ec28f543da98eed..e5450f7d29ba28e157c288d2a7efe1d945c07a99 100644 (file)
@@ -1417,7 +1417,7 @@ static gchar*
 midori_browser_download_prepare_destination_uri (WebKitDownload* download,
                                                  const gchar*    folder)
 {
-    const gchar* suggested_filename;
+    gchar* suggested_filename;
     GFile* file_source;
     gchar* file_basename;
     gchar* download_dir = NULL;
@@ -1425,8 +1425,9 @@ midori_browser_download_prepare_destination_uri (WebKitDownload* download,
     gchar* destination_filename;
     gchar* midori_tmp_dir;
 
-    suggested_filename = webkit_download_get_suggested_filename (download);
+    suggested_filename = sokoke_get_download_filename (download);
     file_source = g_file_new_for_uri (suggested_filename);
+    g_free (suggested_filename);
     file_basename = g_file_get_basename (file_source);
     if (folder == NULL)
     {
@@ -1472,6 +1473,7 @@ midori_view_download_requested_cb (GtkWidget*      view,
         if (g_object_get_data (G_OBJECT (download), "save-as-download"))
         {
             static GtkWidget* dialog = NULL;
+            gchar* filename;
 
             if (!dialog)
             {
@@ -1490,8 +1492,9 @@ midori_view_download_requested_cb (GtkWidget*      view,
                     G_CALLBACK (midori_view_download_save_as_response_cb), browser);
             }
             g_object_set_data (G_OBJECT (dialog), "download", download);
-            gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog),
-                webkit_download_get_suggested_filename (download));
+            filename = sokoke_get_download_filename (download);
+            gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
+            g_free (filename);
             gtk_widget_show (dialog);
         }
         else
index 65d53f25cc3d488b9d83613ba04a3e13ddffda06..14b583fa61ae704aa83f57b28f1f510d6b77c239 100644 (file)
@@ -2845,6 +2845,7 @@ webkit_web_view_mime_type_decision_cb (GtkWidget*               web_view,
     gchar* content_type;
     gchar* description;
     gchar* file_type;
+    gchar* name;
     gchar* file_name;
     WebKitDownload *download;
     WebKitWebDataSource* datasource;
@@ -2908,8 +2909,9 @@ webkit_web_view_mime_type_decision_cb (GtkWidget*               web_view,
     g_free (description);
 
     download = webkit_download_new (request);
-    file_name = g_strdup_printf (_("File Name: %s"),
-            webkit_download_get_suggested_filename (download));
+    name = sokoke_get_download_filename (download);
+    file_name = g_strdup_printf (_("File Name: %s"), name);
+    g_free (name);
     g_object_unref (download);
 
     /* Link Fingerprint */
index fa8f9dfd9c23f466fb5c2d9c261063d7fe1f1304..e4a0a444fb143221f41e9bde26ae52aafc1ae757 100644 (file)
@@ -31,6 +31,7 @@
 #include <glib/gi18n.h>
 #include <glib/gprintf.h>
 #include <glib/gstdio.h>
+#include <webkit/webkit.h>
 
 #ifdef HAVE_HILDON_FM
     #include <hildon/hildon-file-chooser-dialog.h>
@@ -1732,3 +1733,17 @@ sokoke_entry_set_clear_button_visible (GtkEntry* entry,
     }
 }
 
+gchar*
+sokoke_get_download_filename (WebKitDownload* download)
+{
+    /* https://bugs.webkit.org/show_bug.cgi?id=83161 */
+    /* https://d19vezwu8eufl6.cloudfront.net/nlp/slides%2F03-01-FormalizingNB.pdf */
+    gchar* filename = g_strdup (webkit_download_get_suggested_filename (download));
+    #ifdef G_OS_WIN32
+    g_strdelimit (filename, "/\\<>:\"|?*", '_');
+    #else
+    g_strdelimit (filename, "/", '_');
+    #endif
+    return filename;
+}
+
index a92c6a775c83ec561fe9c929cb9fa38f77e11d0e..a714cd98ad06b109ed0de40c07d10344d6abc6c1 100644 (file)
@@ -14,6 +14,7 @@
 #define __SOKOKE_H__ 1
 
 #include <JavaScriptCore/JavaScript.h>
+#include <webkit/webkit.h>
 #include <midori/midori-websettings.h>
 #include <katze/gtk3-compat.h>
 
@@ -175,6 +176,8 @@ sokoke_accept_languages                 (const gchar* const * lang_names);
 gboolean
 sokoke_recursive_fork_protection        (const gchar*         uri,
                                          gboolean             set_uri);
+gchar*
+sokoke_get_download_filename            (WebKitDownload*      download);
 
 typedef struct
 {
index d24577e0b44cec348b70dfefcb5c783707225e29..1c8ca47077f68ee7e5cafbf78b8a316216081821 100644 (file)
@@ -257,6 +257,7 @@ midori_transfers_treeview_render_text_cb (GtkTreeViewColumn* column,
     gchar* total;
     gchar* size_text;
     gchar* text;
+    gchar* filename;
     gdouble progress;
 
     gtk_tree_model_get (model, iter, 1, &download, -1);
@@ -267,8 +268,9 @@ midori_transfers_treeview_render_text_cb (GtkTreeViewColumn* column,
     size_text = g_strdup_printf (_("%s of %s"), current, total);
     g_free (current);
     g_free (total);
-    text = g_strdup_printf ("%s\n%s",
-        webkit_download_get_suggested_filename (download), size_text);
+    filename = sokoke_get_download_filename (download);
+    text = g_strdup_printf ("%s\n%s", filename, size_text);
+    g_free (filename);
     g_free (size_text);
     /* Avoid a bug in WebKit */
     if (webkit_download_get_status (download) != WEBKIT_DOWNLOAD_STATUS_CREATED)
index c86e5323359b4007516a955672c626be5846fa7f..de2b96e9d7e9b986de8ff5d6ebed9095e3134511 100644 (file)
@@ -262,8 +262,11 @@ midori_transferbar_add_download_item (MidoriTransferbar* transferbar,
         g_free (path);
     }
     else
-        gtk_progress_bar_set_text (GTK_PROGRESS_BAR (progress),
-            webkit_download_get_suggested_filename (download));
+    {
+        gchar* filename = sokoke_get_download_filename (download);
+        gtk_progress_bar_set_text (GTK_PROGRESS_BAR (progress), filename);
+        g_free (filename);
+    }
     sokoke_widget_get_text_size (progress, "M", &width, NULL);
     gtk_widget_set_size_request (progress, width * 10, 1);
     /* Avoid a bug in WebKit */