diff options
author | gue5t <gue5t@midori.launchpad> | 2014-01-10 02:20:35 -0500 |
---|---|---|
committer | RabbitBot <> | 2014-01-10 02:20:35 -0500 |
commit | 4c29589cf99e6c0fbe45fbc54255882fda219653 (patch) | |
tree | c71a4d8aebc88afc4d5b42c3f08581801b91e865 | |
parent | 9355e05bf95c0cd87e350496b8be867afe5713da (diff) | |
parent | 4781b675321fd9fa0455d3c360d8fef4c61b2a14 (diff) | |
download | midori-4c29589cf99e6c0fbe45fbc54255882fda219653.tar.gz |
Fix Midori.Download.get_filename_suggestion_for_uri regression since r6498
-rw-r--r-- | extensions/transfers.vala | 4 | ||||
-rw-r--r-- | katze/midori-uri.vala | 19 | ||||
-rw-r--r-- | midori/midori-download.vala | 39 |
3 files changed, 35 insertions, 27 deletions
diff --git a/extensions/transfers.vala b/extensions/transfers.vala index 87a3a282..5b6ad425 100644 --- a/extensions/transfers.vala +++ b/extensions/transfers.vala @@ -325,7 +325,7 @@ namespace Transfers { progress.show_text = true; #endif progress.ellipsize = Pango.EllipsizeMode.MIDDLE; - string filename = Midori.URI.get_basename_for_display (transfer.destination); + string filename = Midori.Download.get_basename_for_display (transfer.destination); progress.text = filename; int width; Sokoke.widget_get_text_size (progress, "M", out width, null); @@ -469,7 +469,7 @@ namespace Transfers { } string uri = transfer.destination; - string filename = Midori.URI.get_basename_for_display (uri); + string filename = Midori.Download.get_basename_for_display (uri); var item = new Katze.Item (); item.uri = uri; item.name = filename; diff --git a/katze/midori-uri.vala b/katze/midori-uri.vala index 972e0f0c..4eda36d6 100644 --- a/katze/midori-uri.vala +++ b/katze/midori-uri.vala @@ -178,25 +178,6 @@ namespace Midori { return null; } - /** - * Returns a string showing a file:// URI's intended filename on - * disk, suited for displaying to a user. - * - * The string returned is the basename (final path segment) of the - * filename of the uri. If the uri is invalid, not file://, or has no - * basename, the uri itself is returned. - * - * Since: 0.5.7 - **/ - public static string get_basename_for_display (string uri) { - try { - string filename = Filename.from_uri (uri); - if(filename != null && filename != "") - return Path.get_basename (filename); - } catch (Error error) { } - return uri; - } - public static GLib.ChecksumType get_fingerprint (string uri, out string checksum, out string label) { diff --git a/midori/midori-download.vala b/midori/midori-download.vala index fadb9dee..e2923abb 100644 --- a/midori/midori-download.vala +++ b/midori/midori-download.vala @@ -54,7 +54,7 @@ namespace Midori { public static string get_tooltip (WebKit.Download download) { #if !HAVE_WEBKIT2 - string filename = Midori.URI.get_basename_for_display (download.destination_uri); + string filename = Midori.Download.get_basename_for_display (download.destination_uri); /* i18n: Download tooltip (size): 4KB of 43MB */ string size = _("%s of %s").printf ( format_size (download.current_size), @@ -256,9 +256,13 @@ namespace Midori { #endif } + /** + * Returns a filename of the form "name.ext" to use as a suggested name for + * a download of the given uri + */ public string get_filename_suggestion_for_uri (string mime_type, string uri) { return_val_if_fail (Midori.URI.is_location (uri), uri); - string filename = Midori.URI.get_basename_for_display (uri); + string filename = File.new_for_uri (uri).get_basename (); if (uri.index_of_char ('.') == -1) return Path.build_filename (filename, fallback_extension (null, mime_type)); return filename; @@ -297,6 +301,25 @@ namespace Midori { return filename; } + /** + * Returns a string showing a file:// URI's intended filename on + * disk, suited for displaying to a user. + * + * The string returned is the basename (final path segment) of the + * filename of the uri. If the uri is invalid, not file://, or has no + * basename, the uri itself is returned. + * + * Since: 0.5.7 + **/ + public static string get_basename_for_display (string uri) { + try { + string filename = Filename.from_uri (uri); + if(filename != null && filename != "") + return Path.get_basename (filename); + } catch (Error error) { } + return uri; + } + public string prepare_destination_uri (WebKit.Download download, string? folder) { string suggested_filename = get_suggested_filename (download); string basename = Path.get_basename (suggested_filename); @@ -316,9 +339,13 @@ namespace Midori { } } - public static bool has_enough_space (WebKit.Download download, string uri) { + /** + * Returns whether it seems possible to save @download to the path specified by + * @destination_uri, considering space on disk and permissions + */ + public static bool has_enough_space (WebKit.Download download, string destination_uri) { #if !HAVE_WEBKIT2 - var folder = File.new_for_uri (uri).get_parent (); + var folder = File.new_for_uri (destination_uri).get_parent (); bool can_write; uint64 free_space; try { @@ -337,12 +364,12 @@ namespace Midori { string detailed_message; if (!can_write) { message = _("The file \"%s\" can't be saved in this folder.").printf ( - Midori.URI.get_basename_for_display (uri)); + Midori.Download.get_basename_for_display (destination_uri)); detailed_message = _("You don't have permission to write in this location."); } else if (free_space < download.total_size) { message = _("There is not enough free space to download \"%s\".").printf ( - Midori.URI.get_basename_for_display (uri)); + Midori.Download.get_basename_for_display (destination_uri)); detailed_message = _("The file needs %s but only %s are left.").printf ( format_size (download.total_size), format_size (free_space)); } |