diff options
author | gue5t <gue5t@midori.launchpad> | 2014-01-06 15:51:09 -0600 |
---|---|---|
committer | gue5t <gue5t@midori.launchpad> | 2014-01-06 15:51:09 -0600 |
commit | 4781b675321fd9fa0455d3c360d8fef4c61b2a14 (patch) | |
tree | 60cf7cf5cefb9807bc8e6f85d5952220fd351f60 | |
parent | 0a9bab4b0447dee17456a5825583d7d78167d438 (diff) | |
download | midori-4781b675321fd9fa0455d3c360d8fef4c61b2a14.tar.gz |
move Midori.URI.get_basename_for_display to Midori.Download namespace
-rw-r--r-- | extensions/transfers.vala | 4 | ||||
-rw-r--r-- | katze/midori-uri.vala | 19 | ||||
-rw-r--r-- | midori/midori-download.vala | 33 |
3 files changed, 30 insertions, 26 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 08f3889c..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), @@ -301,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); @@ -320,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 { @@ -341,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)); } |