Merge lp:~djaler1/screenshot-tool/non-interactive-mode into lp:~elementary-apps/screenshot-tool/trunk

Proposed by Kirill Romanov
Status: Merged
Approved by: Fabio Zaramella
Approved revision: 303
Merged at revision: 307
Proposed branch: lp:~djaler1/screenshot-tool/non-interactive-mode
Merge into: lp:~elementary-apps/screenshot-tool/trunk
Diff against target: 254 lines (+95/-57)
2 files modified
src/Screenshot.vala (+4/-2)
src/ScreenshotWindow.vala (+91/-55)
To merge this branch: bzr merge lp:~djaler1/screenshot-tool/non-interactive-mode
Reviewer Review Type Date Requested Status
Fabio Zaramella (community) Approve
Review via email: mp+317674@code.launchpad.net

Commit message

Implement non-interactive mode (fix bug 1665708)

Description of the change

Implement non-interactive mode (fix bug 1665708)

To post a comment you must log in.
Revision history for this message
Fabio Zaramella (fabiozaramella) wrote :

I'm experiencing two problems:
First, sometimes screenshots are saved, sometimes not, but i can't tell when file is correctly saved.
Second, ok it doesn't build up the gui but... app icon still popup in plank and then immediately close, this is really annoying in my opinion and with the problem above you still can't understand when screenshot is correctly saved.

review: Needs Fixing
Revision history for this message
Fabio Zaramella (fabiozaramella) wrote :

Furthermore, when they are saved is in the home folder not in Pictures even though this is the selected folder.

Revision history for this message
Fabio Zaramella (fabiozaramella) wrote :

Oh, and choosing "current window" option sometimes results in icon being kept in plank until i click on it and then close the main program.

Apart from the fact that i can't tell whether they are saved or not and the problem with the folder, when it works, it works good.

Revision history for this message
Kirill Romanov (djaler1) wrote :

@fabiozaramella I made some changes, can you test again?

Revision history for this message
Fabio Zaramella (fabiozaramella) wrote :

@djaler1 I tested it again and i can confirm that icon doesn't blink anymore, but it persists in plank (and i didn't choose to keep it in the dock). Mh, i think icon shouldn't be displayed at all, you can see how gnome-screenshot works for example.
Furthermore, screenshots aren't saved in the correct folder.

Revision history for this message
Kirill Romanov (djaler1) wrote :

It's strange, cause I didn't see icon in plank now.
And about folder - it save into folder that set in net.launchpad.screenshot.folder-dir. You can change it by gsettings, or, for example, by manual save screenshot to correct folder from GUI version of screenshot-tool

Revision history for this message
Fabio Zaramella (fabiozaramella) wrote :

@djaler1 What i mean is that icon persist, for a while, and then disappears. As if main process is not terminated. Can you reproduce it? If not maybe is better to ask someone else to test it.

About folder, you're right, i looked at the string with dconf-editor and it's empty. That's the reason why they are saved in Pictures from the gui version and in the home folder otherwise.
For some reason the gui version doesn't save the string to the schema (i also tried with trunk) so this is a separate problem, maybe it also need to be set to Picture by default, but again this is a separate bug.

Revision history for this message
Kirill Romanov (djaler1) wrote :

https://youtu.be/31muJSAlxqY there are screencast. I doesn't see icon in plank

Revision history for this message
Fabio Zaramella (fabiozaramella) wrote :

Ok, i figured it out:
When screenshots are taken from terminal, as in you screencast, icon doesn't show but screenshot arent' save (not even in the home folder).
When taken from context menu in slingshot the icon pops up and persists for a while and screenshots are saved in the home folder.

Revision history for this message
Kirill Romanov (djaler1) wrote :

I think this is Slingshot or Plank problem. They waiting for application window opening, but it doesn't show.

Revision history for this message
Kirill Romanov (djaler1) wrote :

And there no differnce in taken from context menu or from terminal to saving file. Context menu just execute command.

Revision history for this message
Fabio Zaramella (fabiozaramella) wrote :

Yes, maybe is plank fault, I just thought it would be nice to avoid this, just like gnome does. :) It wasn't a problem before since save dialog was shown.
And, yes i know slingshot just execute the command, that's the reason why it's strange. If i actually tipe the command in terminal the result is that of your screencast, but launching it from slingshot produces a different result.

Revision history for this message
Kirill Romanov (djaler1) wrote :

I think it impossible with currect codebase. May be it's something in Granite.Application. I tried, but even if I don't create ScreenshotWindow icon pops up.

Revision history for this message
Kirill Romanov (djaler1) wrote :

Just for note - with old version of Slingshot (like from September) icon doesn't pops up.

Revision history for this message
Kirill Romanov (djaler1) wrote :

@fabiozaramella so what?

Revision history for this message
Fabio Zaramella (fabiozaramella) wrote :

Ok after some tests i found out that this is a problem in slingshot. Icon doesn't pop up when the program is launched from terminal and the same happens when writing the command in slingshot's search field, it only occurs when choosing the option from context menu.

Sorry for the late reply, approved. :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Screenshot.vala' (properties changed: -x to +x)
2--- src/Screenshot.vala 2017-02-16 22:02:14 +0000
3+++ src/Screenshot.vala 2017-02-18 22:07:43 +0000
4@@ -32,17 +32,19 @@
5 private bool win = false;
6 private bool area = false;
7 private bool redact = false;
8+ private bool clipboard = false;
9
10 construct {
11 flags |= ApplicationFlags.HANDLES_COMMAND_LINE;
12
13- options = new OptionEntry[6];
14+ options = new OptionEntry[7];
15 options[0] = { "window", 'w', 0, OptionArg.NONE, ref win, _("Capture active window"), null };
16 options[1] = { "area", 'r', 0, OptionArg.NONE, ref area, _("Capture area"), null };
17 options[2] = { "screen", 's', 0, OptionArg.NONE, ref screen, _("Capture the whole screen"), null };
18 options[3] = { "delay", 'd', 0, OptionArg.INT, ref delay, _("Take screenshot after specified delay"), _("Seconds")};
19 options[4] = { "grab-pointer", 'p', 0, OptionArg.NONE, ref grab_pointer, _("Include the pointer with the screenshot"), null };
20 options[5] = { "redact", 'e', 0, OptionArg.NONE, ref redact, _("Redact system text"), null };
21+ options[6] = { "clipboard", 'c', 0, OptionArg.NONE, ref clipboard, _("Save screenshot to clipboard"), null };
22
23 add_main_option_entries (options);
24
25@@ -151,7 +153,7 @@
26 if (action == 0) {
27 normal_startup ();
28 } else {
29- window = new ScreenshotWindow.from_cmd (action, delay, grab_pointer, redact);
30+ window = new ScreenshotWindow.from_cmd (action, delay, grab_pointer, redact, clipboard);
31 window.set_application (this);
32 window.take_clicked ();
33 }
34
35=== modified file 'src/ScreenshotWindow.vala' (properties changed: -x to +x)
36--- src/ScreenshotWindow.vala 2017-02-17 19:10:33 +0000
37+++ src/ScreenshotWindow.vala 2017-02-18 22:07:43 +0000
38@@ -39,6 +39,7 @@
39 private bool close_on_save;
40 private bool redact;
41 private int delay;
42+ private bool to_clipboard;
43
44 public ScreenshotWindow () {
45 Object (border_width: 6,
46@@ -50,9 +51,14 @@
47 close_on_save = settings.get_boolean ("close-on-save");
48 redact = settings.get_boolean ("redact");
49 delay = settings.get_int ("delay");
50+ to_clipboard = false;
51 }
52
53 construct {
54+ if (from_command) {
55+ return;
56+ }
57+
58 set_keep_above (true);
59 stick ();
60
61@@ -164,7 +170,7 @@
62 cancel_btn.clicked.connect (cancel_clicked);
63 }
64
65- public ScreenshotWindow.from_cmd (int? action, int? delay, bool? grab_pointer, bool? redact) {
66+ public ScreenshotWindow.from_cmd (int? action, int? delay, bool? grab_pointer, bool? redact, bool? clipboard) {
67 if (delay != null) {
68 this.delay = delay;
69 }
70@@ -191,6 +197,10 @@
71 }
72 }
73
74+ if (clipboard != null) {
75+ to_clipboard = clipboard;
76+ }
77+
78 close_on_save = true;
79 from_command = true;
80
81@@ -297,60 +307,75 @@
82
83 play_shutter_sound ("screen-capture", _("Screenshot taken"));
84
85- var save_dialog = new Screenshot.Widgets.SaveDialog (screenshot, settings, this);
86- save_dialog.save_response.connect ((response, folder_dir, output_name, format) => {
87- save_dialog.destroy ();
88-
89- if (response) {
90- string[] formats = {".png", ".jpg", ".jpeg",".bmp", ".tiff"};
91- string output = output_name;
92-
93- foreach (string type in formats) {
94- output = output.replace (type, "");
95- }
96-
97- string file_name = "";
98- int attempt = 0;
99-
100- // Check if file exists
101- do {
102- if (attempt == 0) {
103- file_name = Path.build_filename (folder_dir, "%s.%s".printf (output, format));
104- } else {
105- file_name = Path.build_filename (folder_dir, "%s (%d).%s".printf (output, attempt, format));
106- }
107-
108- attempt++;
109- } while (File.new_for_path (file_name).query_exists ());
110-
111- try {
112- screenshot.save (file_name, format);
113-
114- if (close_on_save) {
115- this.destroy ();
116- }
117- } catch (GLib.Error e) {
118- show_error_dialog ();
119- debug (e.message);
120- }
121- }
122-
123- if (from_command && close_on_save) {
124- this.destroy ();
125- }
126- });
127-
128- save_dialog.close.connect (() => {
129- if (close_on_save) {
130- this.destroy ();
131- }
132- });
133-
134- save_dialog.show_all ();
135+ if (from_command == false) {
136+ var save_dialog = new Screenshot.Widgets.SaveDialog (screenshot, settings, this);
137+ save_dialog.save_response.connect ((response, folder_dir, output_name, format) => {
138+ save_dialog.destroy ();
139+
140+ if (response) {
141+ string[] formats = {".png", ".jpg", ".jpeg",".bmp", ".tiff"};
142+ string output = output_name;
143+
144+ foreach (string type in formats) {
145+ output = output.replace (type, "");
146+ }
147+
148+ try {
149+ save_file (output, format, folder_dir, screenshot);
150+
151+ if (close_on_save) {
152+ this.destroy ();
153+ }
154+ } catch (GLib.Error e) {
155+ show_error_dialog ();
156+ debug (e.message);
157+ }
158+ }
159+ });
160+
161+ save_dialog.close.connect (() => {
162+ if (close_on_save) {
163+ this.destroy ();
164+ }
165+ });
166+
167+ save_dialog.show_all ();
168+ } else {
169+ if (to_clipboard) {
170+ Gtk.Clipboard.get_default (this.get_display ()).set_image (screenshot);
171+ } else {
172+ var date_time = new GLib.DateTime.now_local ().format ("%Y-%m-%d %H.%M.%S");
173+
174+ /// TRANSLATORS: %s represents a timestamp here
175+ string file_name = _("Screenshot from %s").printf (date_time);
176+ string folder_dir = settings.get_string ("folder-dir");
177+ string format = settings.get_string ("format");
178+
179+ save_file (file_name, format, folder_dir, screenshot);
180+ }
181+ this.destroy ();
182+ }
183
184 return false;
185 }
186
187+ private void save_file (string file_name, string format, string folder_dir, Gdk.Pixbuf screenshot) {
188+ string full_file_name = "";
189+ int attempt = 0;
190+
191+ do {
192+ if (attempt == 0) {
193+ full_file_name = Path.build_filename (folder_dir, "%s.%s".printf (file_name, format));
194+ } else {
195+ full_file_name = Path.build_filename (folder_dir, "%s (%d).%s".printf (file_name, attempt, format));
196+ }
197+
198+ attempt++;
199+ } while (File.new_for_path (full_file_name).query_exists ());
200+
201+ screenshot.save (full_file_name, format);
202+ }
203+
204 public void take_clicked () {
205 this.set_opacity (0);
206
207@@ -371,7 +396,9 @@
208 this.hide ();
209
210 Timeout.add_seconds (delay - (redact ? 1 : 0), () => {
211- this.present ();
212+ if (from_command == false) {
213+ this.present ();
214+ }
215 return grab_save (null, redact);
216 });
217 }
218@@ -395,7 +422,9 @@
219 item.set_events (item.get_events () | Gdk.EventMask.STRUCTURE_MASK);
220 }
221
222- this.present ();
223+ if (from_command == false) {
224+ this.present ();
225+ }
226
227 if (win != null) {
228 grab_save (win, redact);
229@@ -428,16 +457,23 @@
230 if (close_on_save) {
231 this.destroy ();
232 } else {
233- this.present ();
234+ if (from_command == false) {
235+ this.present ();
236+ }
237 }
238 });
239
240 var win = selection_area.get_window ();
241
242 selection_area.captured.connect (() => {
243+ if (delay == 0) {
244+ selection_area.set_opacity (0);
245+ }
246 selection_area.close ();
247 Timeout.add_seconds (delay - (redact ? 1 : 0), () => {
248- this.present ();
249+ if (from_command == false) {
250+ this.present ();
251+ }
252 return grab_save (win, redact);
253 });
254 });

Subscribers

People subscribed via source and target branches