Merge lp:~victor-mireyev/simple-scan/simple-scan into lp:~simple-scan-team/simple-scan/trunk

Proposed by Victor Mireyev
Status: Merged
Merge reported by: Robert Ancell
Merged at revision: not available
Proposed branch: lp:~victor-mireyev/simple-scan/simple-scan
Merge into: lp:~simple-scan-team/simple-scan/trunk
Diff against target: 212 lines (+99/-12)
3 files modified
src/book.vala (+21/-12)
src/simple-scan.vala (+2/-0)
src/ui.vala (+76/-0)
To merge this branch: bzr merge lp:~victor-mireyev/simple-scan/simple-scan
Reviewer Review Type Date Requested Status
Robert Ancell Approve
Review via email: mp+105860@code.launchpad.net

Commit message

FIX LP#559540. Show progress when saving files

Description of the change

FIX LP#559540. Show modal dialog (ProgressBarDialog) in the center of the screen with progress bar when saving file directly or sending an email with attached files. For each page saved, the `saving` signal is emitted. The corresponding handler prevent GUI from freezing and updates fraction of the progress bar.

To post a comment you must log in.
Revision history for this message
Robert Ancell (robert-ancell) wrote :

Merged with the following changes:
- Fix whitespace style to match existing code
- Fix off by one error ("Saving page 0 of 5")
- Clear label on progress dialog so doesn't show "0%"
- Change "Saving images to files..." to "Saving document..."

Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/book.vala'
2--- src/book.vala 2012-04-17 06:20:16 +0000
3+++ src/book.vala 2012-05-15 17:37:17 +0000
4@@ -20,6 +20,7 @@
5 public signal void reordered ();
6 public signal void cleared ();
7 public signal void needs_saving_changed ();
8+ public signal void saving (int i);
9
10 public Book ()
11 {
12@@ -103,11 +104,11 @@
13
14 private void save_multi_file (string type, File file) throws Error
15 {
16- int i = 0;
17- foreach (var page in pages)
18+ for (var i = 0; i < get_n_pages (); i++)
19 {
20+ var page = get_page (i);
21 page.save (type, make_indexed_file (file.get_uri (), i));
22- i++;
23+ saving (i);
24 }
25 }
26
27@@ -126,14 +127,16 @@
28 var writer = new PsWriter (stream);
29 var surface = writer.surface;
30
31- foreach (var page in pages)
32+ for (var i = 0; i < get_n_pages (); i++)
33 {
34+ var page = get_page (i);
35 var image = page.get_image (true);
36 var width = image.get_width () * 72.0 / page.get_dpi ();
37 var height = image.get_height () * 72.0 / page.get_dpi ();
38 surface.set_size (width, height);
39 save_ps_pdf_surface (surface, image, page.get_dpi ());
40 surface.show_page ();
41+ saving (i);
42 }
43 }
44
45@@ -457,6 +460,8 @@
46 writer.write_string ("\n");
47 writer.write_string ("endstream\n");
48 writer.write_string ("endobj\n");
49+
50+ saving (i);
51 }
52
53 /* Info */
54@@ -490,16 +495,20 @@
55
56 public void save (string type, File file) throws Error
57 {
58- if (strcmp (type, "jpeg") == 0)
59- save_multi_file ("jpeg", file);
60- else if (strcmp (type, "png") == 0)
61- save_multi_file ("png", file);
62- else if (strcmp (type, "tiff") == 0)
63- save_multi_file ("tiff", file);
64- else if (strcmp (type, "ps") == 0)
65+ switch (type)
66+ {
67+ case "jpeg":
68+ case "png":
69+ case "tiff":
70+ save_multi_file (type, file);
71+ break;
72+ case "ps":
73 save_ps (file);
74- else if (strcmp (type, "pdf") == 0)
75+ break;
76+ case "pdf":
77 save_pdf (file);
78+ break;
79+ }
80 }
81
82 public void set_needs_saving (bool needs_saving)
83
84=== modified file 'src/simple-scan.vala'
85--- src/simple-scan.vala 2011-09-01 00:56:55 +0000
86+++ src/simple-scan.vala 2012-05-15 17:37:17 +0000
87@@ -349,12 +349,14 @@
88 if (path != null)
89 {
90 var file = File.new_for_path (path);
91+ ui.show_progress_dialog();
92 try
93 {
94 book.save ("pdf", file);
95 }
96 catch (Error e)
97 {
98+ ui.hide_progress_dialog();
99 warning ("Unable to save email file: %s", e.message);
100 return;
101 }
102
103=== modified file 'src/ui.vala'
104--- src/ui.vala 2012-05-02 01:41:44 +0000
105+++ src/ui.vala 2012-05-15 17:37:17 +0000
106@@ -60,6 +60,7 @@
107 private bool user_selected_device;
108
109 private Gtk.FileChooserDialog? save_dialog;
110+ private ProgressBarDialog progress_dialog;
111
112 private bool have_error;
113 private string error_title;
114@@ -455,12 +456,14 @@
115 else if (uri_lower.has_suffix (".tif") || uri_lower.has_suffix (".tiff"))
116 format = "tiff";
117
118+ show_progress_dialog();
119 try
120 {
121 book.save (format, file);
122 }
123 catch (Error e)
124 {
125+ hide_progress_dialog();
126 warning ("Error saving file: %s", e.message);
127 show_error (/* Title of error dialog when save failed */
128 _("Failed to save file"),
129@@ -1418,6 +1421,39 @@
130 add_default_page ();
131 book.set_needs_saving (false);
132 book.needs_saving_changed.connect (needs_saving_cb);
133+
134+ progress_dialog = new ProgressBarDialog (window, _("Saving images to files..."));
135+ book.saving.connect (book_saving_cb);
136+ }
137+
138+ private void book_saving_cb(int page_number)
139+ {
140+ // Prevent GUI from freezing
141+ while (Gtk.events_pending ())
142+ Gtk.main_iteration ();
143+
144+ var total = (int)book.get_n_pages ();
145+ var fraction = (page_number + 1.0)/total;
146+ bool complete = fraction == 1.0;
147+ if (complete)
148+ Timeout.add(500, () => {
149+ progress_dialog.hide();
150+ return false;
151+ });
152+ var message = _("Saving page %d out of %d").printf (page_number, total);
153+
154+ progress_dialog.set_fraction (fraction);
155+ progress_dialog.set_message (message);
156+ }
157+
158+ public void show_progress_dialog ()
159+ {
160+ progress_dialog.show ();
161+ }
162+
163+ public void hide_progress_dialog ()
164+ {
165+ progress_dialog.hide ();
166 }
167
168 public Book get_book ()
169@@ -1457,3 +1493,43 @@
170 window.show ();
171 }
172 }
173+
174+class ProgressBarDialog : Gtk.Window {
175+ Gtk.ProgressBar bar;
176+
177+ public ProgressBarDialog(Gtk.Window parent, string title)
178+ {
179+ bar = new Gtk.ProgressBar();
180+ var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 5);
181+ var vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 5);
182+ hbox.set_hexpand(true);
183+
184+ bar.set_show_text(true);
185+ bar.set_size_request(225, 25);
186+ set_size_request(250, 50);
187+
188+ vbox.pack_start(bar, true, false, 0);
189+ hbox.pack_start(vbox, true, false, 0);
190+ add(hbox);
191+ set_title(title);
192+
193+ set_transient_for(parent);
194+ set_position(Gtk.WindowPosition.CENTER_ON_PARENT);
195+ set_modal(true);
196+ set_resizable(false);
197+
198+ hbox.show();
199+ vbox.show();
200+ bar.show();
201+ }
202+
203+ public void set_fraction(double percent)
204+ {
205+ bar.set_fraction(percent);
206+ }
207+
208+ public void set_message(string message)
209+ {
210+ bar.set_text(message);
211+ }
212+}

Subscribers

People subscribed via source and target branches