Merge lp:~davidmhewitt/pantheon-photos/fix-1658467 into lp:~pantheon-photos/pantheon-photos/trunk

Proposed by David Hewitt
Status: Merged
Approved by: Corentin Noël
Approved revision: 3126
Merged at revision: 3140
Proposed branch: lp:~davidmhewitt/pantheon-photos/fix-1658467
Merge into: lp:~pantheon-photos/pantheon-photos/trunk
Diff against target: 119 lines (+29/-8)
2 files modified
src/Photo.vala (+13/-0)
src/direct/DirectPhotoPage.vala (+16/-8)
To merge this branch: bzr merge lp:~davidmhewitt/pantheon-photos/fix-1658467
Reviewer Review Type Date Requested Status
Corentin Noël Approve
Review via email: mp+315314@code.launchpad.net

Commit message

see if a file is writeable when closing and offer save as if the file is read only

Description of the change

Now tests to see if a file is writeable when closing the application and offers the save as option instead if the file is read only.

Also changed the behaviour slightly so that the application doesn't still close if there was a different error while saving.

To post a comment you must log in.
Revision history for this message
Corentin Noël (tintou) wrote :

There is a coding-style issue, you have to add a space before each parenthesis

review: Needs Fixing
3125. By David Hewitt

Fixed code style issues

Revision history for this message
David Hewitt (davidmhewitt) wrote :

> There is a coding-style issue, you have to add a space before each parenthesis

Resolved

Revision history for this message
Corentin Noël (tintou) wrote :

Just two tiny things that I haven't see at first and we are good

3126. By David Hewitt

Fixed hardcoded strings and ints and corrected whitespace

Revision history for this message
David Hewitt (davidmhewitt) wrote :

> Just two tiny things that I haven't see at first and we are good

Thanks Corentin, all good feedback. I've resolved the issues in the above commit.

Revision history for this message
Corentin Noël (tintou) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Photo.vala'
2--- src/Photo.vala 2017-01-12 18:13:48 +0000
3+++ src/Photo.vala 2017-01-27 18:01:19 +0000
4@@ -1640,6 +1640,19 @@
5 ? true : is_extension_found (file.get_basename (), IMAGE_EXTENSIONS);
6 }
7
8+ public bool can_write_file () {
9+ var file = File.new_for_path (row.master.filepath);
10+ FileInfo file_info;
11+ try {
12+ file_info = file.query_info (GLib.FileAttribute.ACCESS_CAN_WRITE, FileQueryInfoFlags.NONE);
13+ } catch (Error e) {
14+ warning ("Error while testing if file is writeable: %s\n", e.message);
15+ return false;
16+ }
17+
18+ return file_info.get_attribute_boolean (GLib.FileAttribute.ACCESS_CAN_WRITE);
19+ }
20+
21 private static bool is_extension_found (string basename, string[] extensions) {
22 string name, ext;
23 disassemble_filename (basename, out name, out ext);
24
25=== modified file 'src/direct/DirectPhotoPage.vala'
26--- src/direct/DirectPhotoPage.vala 2017-01-26 15:35:50 +0000
27+++ src/direct/DirectPhotoPage.vala 2017-01-27 18:01:19 +0000
28@@ -373,7 +373,7 @@
29 return true;
30 }
31
32- bool is_writeable = get_photo ().get_file_format ().can_write ();
33+ bool is_writeable = get_photo ().can_write_file () && get_photo ().get_file_format ().can_write ();
34 string save_option = is_writeable ? _ ("_Save") : _ ("_Save a Copy");
35
36 Gtk.ResponseType response = AppWindow.affirm_cancel_negate_question (
37@@ -385,10 +385,10 @@
38 photo.remove_all_transformations ();
39 else if (response == Gtk.ResponseType.NO) {
40 if (is_writeable)
41- save (photo.get_file (), 0, ScaleConstraint.ORIGINAL, Jpeg.Quality.HIGH,
42+ return save (photo.get_file (), 0, ScaleConstraint.ORIGINAL, Jpeg.Quality.HIGH,
43 get_photo ().get_file_format ());
44 else
45- on_save_as ();
46+ return do_save_as ();
47 } else if ((response == Gtk.ResponseType.CANCEL) || (response == Gtk.ResponseType.DELETE_EVENT) ||
48 (response == Gtk.ResponseType.CLOSE)) {
49 return false;
50@@ -405,7 +405,7 @@
51 return (old_photo != null) ? check_ok_to_close_photo (old_photo) : true;
52 }
53
54- private void save (File dest, int scale, ScaleConstraint constraint, Jpeg.Quality quality,
55+ private bool save (File dest, int scale, ScaleConstraint constraint, Jpeg.Quality quality,
56 PhotoFileFormat format, bool copy_unmodified = false, bool save_metadata = true) {
57 Scaling scaling = Scaling.for_constraint (constraint, scale, false);
58
59@@ -415,7 +415,7 @@
60 AppWindow.error_message (_ ("Error while saving to %s: %s").printf (dest.get_path (),
61 err.message));
62
63- return;
64+ return false;
65 }
66
67 // Fetch the DirectPhoto and reimport.
68@@ -427,6 +427,8 @@
69
70 DirectPhoto.global.reimport_photo (photo);
71 display_mirror_of (view_controller, photo);
72+
73+ return true;
74 }
75
76 private void on_save () {
77@@ -439,14 +441,14 @@
78 get_photo ().get_file_format ());
79 }
80
81- private void on_save_as () {
82+ private bool do_save_as () {
83 ExportDialog export_dialog = new ExportDialog (_ ("Save As"));
84
85 int scale;
86 ScaleConstraint constraint;
87 ExportFormatParameters export_params = ExportFormatParameters.last ();
88 if (!export_dialog.execute (out scale, out constraint, ref export_params))
89- return;
90+ return false;
91
92 string filename = get_photo ().get_export_basename_for_parameters (export_params);
93 PhotoFileFormat effective_export_format =
94@@ -472,11 +474,12 @@
95 save_as_dialog.set_local_only (false);
96
97 int response = save_as_dialog.run ();
98+ bool save_successful = false;
99 if (response == Gtk.ResponseType.OK) {
100 // flag to prevent asking user about losing changes to the old file (since they'll be
101 // loaded right into the new one)
102 drop_if_dirty = true;
103- save (File.new_for_uri (save_as_dialog.get_uri ()), scale, constraint, export_params.quality,
104+ save_successful = save (File.new_for_uri (save_as_dialog.get_uri ()), scale, constraint, export_params.quality,
105 effective_export_format, export_params.mode == ExportFormatMode.UNMODIFIED,
106 export_params.export_metadata);
107 drop_if_dirty = false;
108@@ -485,6 +488,11 @@
109 }
110
111 save_as_dialog.destroy ();
112+ return save_successful;
113+ }
114+
115+ private void on_save_as () {
116+ do_save_as ();
117 }
118
119 /** Returns true if the code parameter matches the keycode of the keyval parameter for

Subscribers

People subscribed via source and target branches

to all changes: