Replace illegal characters in filenames

Fixes: https://bugs.launchpad.net/midori/+bug/972931
This commit is contained in:
Martin Natano 2012-04-10 20:54:03 +02:00 committed by Christian Dywan
parent 3d00303230
commit e0c021de3d
6 changed files with 38 additions and 10 deletions

View file

@ -1417,7 +1417,7 @@ static gchar*
midori_browser_download_prepare_destination_uri (WebKitDownload* download, midori_browser_download_prepare_destination_uri (WebKitDownload* download,
const gchar* folder) const gchar* folder)
{ {
const gchar* suggested_filename; gchar* suggested_filename;
GFile* file_source; GFile* file_source;
gchar* file_basename; gchar* file_basename;
gchar* download_dir = NULL; gchar* download_dir = NULL;
@ -1425,8 +1425,9 @@ midori_browser_download_prepare_destination_uri (WebKitDownload* download,
gchar* destination_filename; gchar* destination_filename;
gchar* midori_tmp_dir; 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); file_source = g_file_new_for_uri (suggested_filename);
g_free (suggested_filename);
file_basename = g_file_get_basename (file_source); file_basename = g_file_get_basename (file_source);
if (folder == NULL) 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")) if (g_object_get_data (G_OBJECT (download), "save-as-download"))
{ {
static GtkWidget* dialog = NULL; static GtkWidget* dialog = NULL;
gchar* filename;
if (!dialog) if (!dialog)
{ {
@ -1490,8 +1492,9 @@ midori_view_download_requested_cb (GtkWidget* view,
G_CALLBACK (midori_view_download_save_as_response_cb), browser); G_CALLBACK (midori_view_download_save_as_response_cb), browser);
} }
g_object_set_data (G_OBJECT (dialog), "download", download); g_object_set_data (G_OBJECT (dialog), "download", download);
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename = sokoke_get_download_filename (download);
webkit_download_get_suggested_filename (download)); gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
g_free (filename);
gtk_widget_show (dialog); gtk_widget_show (dialog);
} }
else else

View file

@ -2845,6 +2845,7 @@ webkit_web_view_mime_type_decision_cb (GtkWidget* web_view,
gchar* content_type; gchar* content_type;
gchar* description; gchar* description;
gchar* file_type; gchar* file_type;
gchar* name;
gchar* file_name; gchar* file_name;
WebKitDownload *download; WebKitDownload *download;
WebKitWebDataSource* datasource; WebKitWebDataSource* datasource;
@ -2908,8 +2909,9 @@ webkit_web_view_mime_type_decision_cb (GtkWidget* web_view,
g_free (description); g_free (description);
download = webkit_download_new (request); download = webkit_download_new (request);
file_name = g_strdup_printf (_("File Name: %s"), name = sokoke_get_download_filename (download);
webkit_download_get_suggested_filename (download)); file_name = g_strdup_printf (_("File Name: %s"), name);
g_free (name);
g_object_unref (download); g_object_unref (download);
/* Link Fingerprint */ /* Link Fingerprint */

View file

@ -31,6 +31,7 @@
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <glib/gprintf.h> #include <glib/gprintf.h>
#include <glib/gstdio.h> #include <glib/gstdio.h>
#include <webkit/webkit.h>
#ifdef HAVE_HILDON_FM #ifdef HAVE_HILDON_FM
#include <hildon/hildon-file-chooser-dialog.h> #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;
}

View file

@ -14,6 +14,7 @@
#define __SOKOKE_H__ 1 #define __SOKOKE_H__ 1
#include <JavaScriptCore/JavaScript.h> #include <JavaScriptCore/JavaScript.h>
#include <webkit/webkit.h>
#include <midori/midori-websettings.h> #include <midori/midori-websettings.h>
#include <katze/gtk3-compat.h> #include <katze/gtk3-compat.h>
@ -175,6 +176,8 @@ sokoke_accept_languages (const gchar* const * lang_names);
gboolean gboolean
sokoke_recursive_fork_protection (const gchar* uri, sokoke_recursive_fork_protection (const gchar* uri,
gboolean set_uri); gboolean set_uri);
gchar*
sokoke_get_download_filename (WebKitDownload* download);
typedef struct typedef struct
{ {

View file

@ -257,6 +257,7 @@ midori_transfers_treeview_render_text_cb (GtkTreeViewColumn* column,
gchar* total; gchar* total;
gchar* size_text; gchar* size_text;
gchar* text; gchar* text;
gchar* filename;
gdouble progress; gdouble progress;
gtk_tree_model_get (model, iter, 1, &download, -1); 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); size_text = g_strdup_printf (_("%s of %s"), current, total);
g_free (current); g_free (current);
g_free (total); g_free (total);
text = g_strdup_printf ("%s\n%s", filename = sokoke_get_download_filename (download);
webkit_download_get_suggested_filename (download), size_text); text = g_strdup_printf ("%s\n%s", filename, size_text);
g_free (filename);
g_free (size_text); g_free (size_text);
/* Avoid a bug in WebKit */ /* Avoid a bug in WebKit */
if (webkit_download_get_status (download) != WEBKIT_DOWNLOAD_STATUS_CREATED) if (webkit_download_get_status (download) != WEBKIT_DOWNLOAD_STATUS_CREATED)

View file

@ -262,8 +262,11 @@ midori_transferbar_add_download_item (MidoriTransferbar* transferbar,
g_free (path); g_free (path);
} }
else 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); sokoke_widget_get_text_size (progress, "M", &width, NULL);
gtk_widget_set_size_request (progress, width * 10, 1); gtk_widget_set_size_request (progress, width * 10, 1);
/* Avoid a bug in WebKit */ /* Avoid a bug in WebKit */