[Xfce4-commits] <midori:master> Replace illegal characters in filenames

Christian Dywan noreply at xfce.org
Tue Apr 10 21:32:01 CEST 2012


Updating branch refs/heads/master
         to e0c021de3d93d016dc1e55475f0ff889b8aba732 (commit)
       from 3d00303230851e5f6c3aa3006780c993ecebbabb (commit)

commit e0c021de3d93d016dc1e55475f0ff889b8aba732
Author: Martin Natano <natano at natano.net>
Date:   Tue Apr 10 20:54:03 2012 +0200

    Replace illegal characters in filenames
    
    Fixes: https://bugs.launchpad.net/midori/+bug/972931

 midori/midori-browser.c       |   11 +++++++----
 midori/midori-view.c          |    6 ++++--
 midori/sokoke.c               |   15 +++++++++++++++
 midori/sokoke.h               |    3 +++
 panels/midori-transfers.c     |    6 ++++--
 toolbars/midori-transferbar.c |    7 +++++--
 6 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index ae3fae0..e5450f7 100644
--- a/midori/midori-browser.c
+++ b/midori/midori-browser.c
@@ -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
diff --git a/midori/midori-view.c b/midori/midori-view.c
index 65d53f2..14b583f 100644
--- a/midori/midori-view.c
+++ b/midori/midori-view.c
@@ -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 */
diff --git a/midori/sokoke.c b/midori/sokoke.c
index fa8f9df..e4a0a44 100644
--- a/midori/sokoke.c
+++ b/midori/sokoke.c
@@ -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;
+}
+
diff --git a/midori/sokoke.h b/midori/sokoke.h
index a92c6a7..a714cd9 100644
--- a/midori/sokoke.h
+++ b/midori/sokoke.h
@@ -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
 {
diff --git a/panels/midori-transfers.c b/panels/midori-transfers.c
index d24577e..1c8ca47 100644
--- a/panels/midori-transfers.c
+++ b/panels/midori-transfers.c
@@ -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)
diff --git a/toolbars/midori-transferbar.c b/toolbars/midori-transferbar.c
index c86e532..de2b96e 100644
--- a/toolbars/midori-transferbar.c
+++ b/toolbars/midori-transferbar.c
@@ -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 */


More information about the Xfce4-commits mailing list