Merge lp:~hyuchia/screenshot-tool/fix-1668074 into lp:~elementary-apps/screenshot-tool/trunk

Proposed by Diego Islas Ocampo
Status: Merged
Approved by: Jeremy Wootten
Approved revision: 315
Merged at revision: 317
Proposed branch: lp:~hyuchia/screenshot-tool/fix-1668074
Merge into: lp:~elementary-apps/screenshot-tool/trunk
Diff against target: 83 lines (+34/-19)
2 files modified
src/ScreenshotWindow.vala (+30/-17)
src/Widgets/SaveDialog.vala (+4/-2)
To merge this branch: bzr merge lp:~hyuchia/screenshot-tool/fix-1668074
Reviewer Review Type Date Requested Status
Jeremy Wootten Approve
Review via email: mp+318721@code.launchpad.net

Commit message

Ensure screenshots are saved to correct directory when launched from Slingshot.

Description of the change

Changed the saving directory to the one available in the settings or the environment's pictures default folder for screenshots taken from the launcher.

To post a comment you must log in.
Revision history for this message
Adam Bieńkowski (donadigo) wrote :

Just left some diff comments.

311. By Diego Islas Ocampo

Remove redundant calls

Revision history for this message
Diego Islas Ocampo (hyuchia) wrote :

You were right, changing it to owned was not necessary, I've also used a variable instead o calling the function twice. Thanks!

Revision history for this message
Jeremy Wootten (jeremywootten) wrote :

I guess it is not strictly needed for this fix, but it would be better to just save the screenshot and deal with any arising GLib.Error (which should be done anyway) - rather than use the rather strange do loop to check for (non)existence.

The branch does work as expected.

312. By Diego Islas Ocampo

Show error dialog when save raises an error

313. By Diego Islas Ocampo

Add check for save directory existance

Revision history for this message
Jeremy Wootten (jeremywootten) wrote :

If save_file gets passed an invalid (non-existent) directory (which could happen when using the Plank context menu method) then the save fails, so it would be best to do an existence check here as well as in the SaveDialog. You can just pass "" as the folder_dir parameter when called with from_command == true, instead of looking up the setting twice.

314. By Diego Islas Ocampo

Remove unnecessary directory specificaction

315. By Diego Islas Ocampo

Add folder existance check

Revision history for this message
Jeremy Wootten (jeremywootten) wrote :

Looks good now :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ScreenshotWindow.vala'
2--- src/ScreenshotWindow.vala 2017-02-18 22:07:14 +0000
3+++ src/ScreenshotWindow.vala 2017-03-21 17:14:34 +0000
4@@ -348,10 +348,13 @@
5
6 /// TRANSLATORS: %s represents a timestamp here
7 string file_name = _("Screenshot from %s").printf (date_time);
8- string folder_dir = settings.get_string ("folder-dir");
9 string format = settings.get_string ("format");
10-
11- save_file (file_name, format, folder_dir, screenshot);
12+ try {
13+ save_file (file_name, format, "", screenshot);
14+ } catch (GLib.Error e) {
15+ show_error_dialog ();
16+ debug (e.message);
17+ }
18 }
19 this.destroy ();
20 }
21@@ -359,21 +362,31 @@
22 return false;
23 }
24
25- private void save_file (string file_name, string format, string folder_dir, Gdk.Pixbuf screenshot) {
26+ private void save_file (string file_name, string format, string folder_dir, Gdk.Pixbuf screenshot) throws GLib.Error {
27 string full_file_name = "";
28- int attempt = 0;
29-
30- do {
31- if (attempt == 0) {
32- full_file_name = Path.build_filename (folder_dir, "%s.%s".printf (file_name, format));
33- } else {
34- full_file_name = Path.build_filename (folder_dir, "%s (%d).%s".printf (file_name, attempt, format));
35- }
36-
37- attempt++;
38- } while (File.new_for_path (full_file_name).query_exists ());
39-
40- screenshot.save (full_file_name, format);
41+
42+ if (folder_dir == "") {
43+ string folder_from_settings = settings.get_string ("folder-dir");
44+ if (folder_from_settings != "" && File.new_for_path (folder_from_settings).query_exists ()) {
45+ folder_dir = folder_from_settings;
46+ } else {
47+ folder_dir = GLib.Environment.get_user_special_dir (GLib.UserDirectory.PICTURES);
48+ }
49+ }
50+
51+ int attempt = 0;
52+
53+ do {
54+ if (attempt == 0) {
55+ full_file_name = Path.build_filename (folder_dir, "%s.%s".printf (file_name, format));
56+ } else {
57+ full_file_name = Path.build_filename (folder_dir, "%s (%d).%s".printf (file_name, attempt, format));
58+ }
59+
60+ attempt++;
61+ } while (File.new_for_path (full_file_name).query_exists ());
62+
63+ screenshot.save (full_file_name, format);
64 }
65
66 public void take_clicked () {
67
68=== modified file 'src/Widgets/SaveDialog.vala'
69--- src/Widgets/SaveDialog.vala 2017-02-15 21:00:15 +0000
70+++ src/Widgets/SaveDialog.vala 2017-03-21 17:14:34 +0000
71@@ -45,8 +45,10 @@
72
73 var folder_dir = Environment.get_user_special_dir (UserDirectory.PICTURES);
74
75- if (settings.get_string ("folder-dir") != folder_dir && settings.get_string ("folder-dir") != "") {
76- folder_dir = settings.get_string ("folder-dir");
77+ var folder_from_settings = settings.get_string ("folder-dir");
78+
79+ if (folder_from_settings != folder_dir && folder_from_settings != "" && File.new_for_path (folder_from_settings).query_exists ()) {
80+ folder_dir = folder_from_settings;
81 }
82
83 int width = pixbuf.get_width () / 4;

Subscribers

People subscribed via source and target branches