Show expected download size in dialog if available

Switch to using a GString to add lines as needed.
This commit is contained in:
Christian Dywan 2012-05-20 18:15:39 +02:00
parent 9fe40ad850
commit fe72235e83

View file

@ -2920,17 +2920,14 @@ webkit_web_view_download_requested_cb (GtkWidget* web_view,
GtkWidget* dialog; GtkWidget* dialog;
gchar* content_type; gchar* content_type;
gchar* description; gchar* description;
gchar* file_type;
gchar* name; gchar* name;
gchar* file_name;
WebKitWebFrame* web_frame; WebKitWebFrame* web_frame;
const gchar* mime_type; const gchar* mime_type;
WebKitWebDataSource* datasource; WebKitWebDataSource* datasource;
WebKitNetworkRequest* request; WebKitNetworkRequest* request;
WebKitNetworkRequest* original_request; WebKitNetworkRequest* original_request;
const gchar* original_uri; const gchar* original_uri;
gchar* fingerprint; GString* details;
gchar* fplabel;
#if GTK_CHECK_VERSION (2, 14, 0) #if GTK_CHECK_VERSION (2, 14, 0)
GIcon* icon; GIcon* icon;
GtkWidget* image; GtkWidget* image;
@ -2961,36 +2958,53 @@ webkit_web_view_download_requested_cb (GtkWidget* web_view,
gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image); gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
#endif #endif
g_free (content_type); g_free (content_type);
if (g_strrstr (description, mime_type))
file_type = g_strdup_printf (_("File Type: '%s'"), mime_type);
else
file_type = g_strdup_printf (_("File Type: %s ('%s')"), description, mime_type);
g_free (description);
details = g_string_sized_new (20 * 4);
name = sokoke_get_download_filename (download); name = sokoke_get_download_filename (download);
file_name = g_strdup_printf (_("File Name: %s"), name); g_string_append_printf (details, _("File Name: %s"), name);
g_string_append_c (details, '\n');
g_free (name); g_free (name);
if (g_strrstr (description, mime_type))
g_string_append_printf (details, _("File Type: '%s'"), mime_type);
else
g_string_append_printf (details, _("File Type: %s ('%s')"), description, mime_type);
g_string_append_c (details, '\n');
g_free (description);
/* Link Fingerprint */ /* Link Fingerprint */
/* We look at the original URI because redirection would lose the fragment */ /* We look at the original URI because redirection would lose the fragment */
web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view)); web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view));
datasource = webkit_web_frame_get_provisional_data_source (web_frame); datasource = webkit_web_frame_get_provisional_data_source (web_frame);
if (datasource) if (datasource)
{ {
gchar* fingerprint;
gchar* fplabel;
original_request = webkit_web_data_source_get_initial_request (datasource); original_request = webkit_web_data_source_get_initial_request (datasource);
original_uri = webkit_network_request_get_uri (original_request); original_uri = webkit_network_request_get_uri (original_request);
midori_uri_get_fingerprint (original_uri, &fingerprint, &fplabel); midori_uri_get_fingerprint (original_uri, &fingerprint, &fplabel);
if (fplabel && fingerprint)
{
g_string_append (details, fplabel);
g_string_append_c (details, ' ');
g_string_append (details, fingerprint);
g_string_append_c (details, '\n');
}
g_free (fplabel);
g_free (fingerprint);
} }
else
if (webkit_download_get_total_size (download) > webkit_download_get_current_size (download))
{ {
fingerprint = fplabel = NULL; gchar* total = g_format_size (webkit_download_get_total_size (download));
g_string_append_printf (details, _("Size: %s"), total);
g_string_append_c (details, '\n');
g_free (total);
} }
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
"%s\n%s\n%s %s", file_name, file_type, fplabel ? fplabel : "", fingerprint ? fingerprint : ""); "%s", details->str);
g_free (fingerprint); g_string_free (details, TRUE);
g_free (fplabel);
g_free (file_name);
g_free (file_type);
gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE); gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE);
/* i18n: A file open dialog title, ie. "Open http://fila.com/manual.tgz" */ /* i18n: A file open dialog title, ie. "Open http://fila.com/manual.tgz" */