Merge lp:~gue5t/midori/suggestion-regression into lp:midori

Proposed by gue5t gue5t
Status: Merged
Approved by: Cris Dywan
Approved revision: 6500
Merged at revision: 6530
Proposed branch: lp:~gue5t/midori/suggestion-regression
Merge into: lp:midori
Diff against target: 136 lines (+35/-27)
3 files modified
extensions/transfers.vala (+2/-2)
katze/midori-uri.vala (+0/-19)
midori/midori-download.vala (+33/-6)
To merge this branch: bzr merge lp:~gue5t/midori/suggestion-regression
Reviewer Review Type Date Requested Status
Cris Dywan Approve
Review via email: mp+200599@code.launchpad.net

This proposal supersedes a proposal from 2013-11-25.

Commit message

Fix Midori.Download.get_filename_suggestion_for_uri regression since r6498

Description of the change

Midori.Download.get_filename_suggestion_for_uri accepts arbitrary web URIs, not WebKitDownload-style file:// "destination" URIs (which is what Midori.URI.get_basename_for_display accepts). This was confused in r6498. Fix the confusion and move Midori.URI.get_basename_for_display to Midori.Download.get_basename_for_display to make it clearer that it only works on file:// URIs.

To post a comment you must log in.
Revision history for this message
Cris Dywan (kalikiana) wrote : Posted in a previous version of this proposal

What "arbitrary web URI" does get_basename_for_display not support that get_filename_suggestion_for_uri does handle? I don't see an obvious reason why get_basename_for_display would not take all URLs - originally it even was proposed to be implemented exactly as done here.

review: Needs Information
Revision history for this message
gue5t gue5t (gue5t) wrote : Posted in a previous version of this proposal

Midori.URI.get_basename_for_display was introduced to be used with the file:// URIs that the WebKitDownload API uses for its "destinations". It uses "Filename.from_uri", which fails on non-"file://" URIs: g_filename_from_uri("http://google.com/foo/bar/baz.txt", NULL , NULL) == NULL. Hence, it was only intended to be used with these WebKitDownload-provided uris and it was a mistake to have used it to implement get_filename_suggestion_for_uri which takes an arbitrary web (http/https) URI and returns a filesystem path. This restriction on the argument to Midori.URI.get_basename_for_display is documented, but we could also change its name to clarify so this kind of bug doesn't recur.

Revision history for this message
Cris Dywan (kalikiana) wrote : Posted in a previous version of this proposal

Nice! Totally like your docs tweaks also!

review: Approve
Revision history for this message
Cris Dywan (kalikiana) wrote :

Nice! Totally like your docs tweaks also!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'extensions/transfers.vala'
2--- extensions/transfers.vala 2013-11-22 19:54:24 +0000
3+++ extensions/transfers.vala 2014-01-06 21:54:39 +0000
4@@ -325,7 +325,7 @@
5 progress.show_text = true;
6 #endif
7 progress.ellipsize = Pango.EllipsizeMode.MIDDLE;
8- string filename = Midori.URI.get_basename_for_display (transfer.destination);
9+ string filename = Midori.Download.get_basename_for_display (transfer.destination);
10 progress.text = filename;
11 int width;
12 Sokoke.widget_get_text_size (progress, "M", out width, null);
13@@ -469,7 +469,7 @@
14 }
15
16 string uri = transfer.destination;
17- string filename = Midori.URI.get_basename_for_display (uri);
18+ string filename = Midori.Download.get_basename_for_display (uri);
19 var item = new Katze.Item ();
20 item.uri = uri;
21 item.name = filename;
22
23=== modified file 'katze/midori-uri.vala'
24--- katze/midori-uri.vala 2013-11-22 19:54:24 +0000
25+++ katze/midori-uri.vala 2014-01-06 21:54:39 +0000
26@@ -178,25 +178,6 @@
27 return null;
28 }
29
30- /**
31- * Returns a string showing a file:// URI's intended filename on
32- * disk, suited for displaying to a user.
33- *
34- * The string returned is the basename (final path segment) of the
35- * filename of the uri. If the uri is invalid, not file://, or has no
36- * basename, the uri itself is returned.
37- *
38- * Since: 0.5.7
39- **/
40- public static string get_basename_for_display (string uri) {
41- try {
42- string filename = Filename.from_uri (uri);
43- if(filename != null && filename != "")
44- return Path.get_basename (filename);
45- } catch (Error error) { }
46- return uri;
47- }
48-
49 public static GLib.ChecksumType get_fingerprint (string uri,
50 out string checksum, out string label) {
51
52
53=== modified file 'midori/midori-download.vala'
54--- midori/midori-download.vala 2013-11-22 19:54:24 +0000
55+++ midori/midori-download.vala 2014-01-06 21:54:39 +0000
56@@ -54,7 +54,7 @@
57
58 public static string get_tooltip (WebKit.Download download) {
59 #if !HAVE_WEBKIT2
60- string filename = Midori.URI.get_basename_for_display (download.destination_uri);
61+ string filename = Midori.Download.get_basename_for_display (download.destination_uri);
62 /* i18n: Download tooltip (size): 4KB of 43MB */
63 string size = _("%s of %s").printf (
64 format_size (download.current_size),
65@@ -256,9 +256,13 @@
66 #endif
67 }
68
69+ /**
70+ * Returns a filename of the form "name.ext" to use as a suggested name for
71+ * a download of the given uri
72+ */
73 public string get_filename_suggestion_for_uri (string mime_type, string uri) {
74 return_val_if_fail (Midori.URI.is_location (uri), uri);
75- string filename = Midori.URI.get_basename_for_display (uri);
76+ string filename = File.new_for_uri (uri).get_basename ();
77 if (uri.index_of_char ('.') == -1)
78 return Path.build_filename (filename, fallback_extension (null, mime_type));
79 return filename;
80@@ -297,6 +301,25 @@
81 return filename;
82 }
83
84+ /**
85+ * Returns a string showing a file:// URI's intended filename on
86+ * disk, suited for displaying to a user.
87+ *
88+ * The string returned is the basename (final path segment) of the
89+ * filename of the uri. If the uri is invalid, not file://, or has no
90+ * basename, the uri itself is returned.
91+ *
92+ * Since: 0.5.7
93+ **/
94+ public static string get_basename_for_display (string uri) {
95+ try {
96+ string filename = Filename.from_uri (uri);
97+ if(filename != null && filename != "")
98+ return Path.get_basename (filename);
99+ } catch (Error error) { }
100+ return uri;
101+ }
102+
103 public string prepare_destination_uri (WebKit.Download download, string? folder) {
104 string suggested_filename = get_suggested_filename (download);
105 string basename = Path.get_basename (suggested_filename);
106@@ -316,9 +339,13 @@
107 }
108 }
109
110- public static bool has_enough_space (WebKit.Download download, string uri) {
111+ /**
112+ * Returns whether it seems possible to save @download to the path specified by
113+ * @destination_uri, considering space on disk and permissions
114+ */
115+ public static bool has_enough_space (WebKit.Download download, string destination_uri) {
116 #if !HAVE_WEBKIT2
117- var folder = File.new_for_uri (uri).get_parent ();
118+ var folder = File.new_for_uri (destination_uri).get_parent ();
119 bool can_write;
120 uint64 free_space;
121 try {
122@@ -337,12 +364,12 @@
123 string detailed_message;
124 if (!can_write) {
125 message = _("The file \"%s\" can't be saved in this folder.").printf (
126- Midori.URI.get_basename_for_display (uri));
127+ Midori.Download.get_basename_for_display (destination_uri));
128 detailed_message = _("You don't have permission to write in this location.");
129 }
130 else if (free_space < download.total_size) {
131 message = _("There is not enough free space to download \"%s\".").printf (
132- Midori.URI.get_basename_for_display (uri));
133+ Midori.Download.get_basename_for_display (destination_uri));
134 detailed_message = _("The file needs %s but only %s are left.").printf (
135 format_size (download.total_size), format_size (free_space));
136 }

Subscribers

People subscribed via source and target branches

to all changes: