simple-scan-team team mailing list archive
-
simple-scan-team team
-
Mailing list archive
-
Message #00672
[Merge] lp:~victor-mireyev/simple-scan/simple-scan into lp:simple-scan
Victor Mireyev has proposed merging lp:~victor-mireyev/simple-scan/simple-scan into lp:simple-scan.
Requested reviews:
Robert Ancell (robert-ancell)
Related bugs:
Bug #559540 in Simple Scan: "Show progress when saving files"
https://bugs.launchpad.net/simple-scan/+bug/559540
For more details, see:
https://code.launchpad.net/~victor-mireyev/simple-scan/simple-scan/+merge/105860
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.
--
https://code.launchpad.net/~victor-mireyev/simple-scan/simple-scan/+merge/105860
Your team Simple Scan Development Team is subscribed to branch lp:simple-scan.
=== modified file 'src/book.vala'
--- src/book.vala 2012-04-17 06:20:16 +0000
+++ src/book.vala 2012-05-15 17:37:17 +0000
@@ -20,6 +20,7 @@
public signal void reordered ();
public signal void cleared ();
public signal void needs_saving_changed ();
+ public signal void saving (int i);
public Book ()
{
@@ -103,11 +104,11 @@
private void save_multi_file (string type, File file) throws Error
{
- int i = 0;
- foreach (var page in pages)
+ for (var i = 0; i < get_n_pages (); i++)
{
+ var page = get_page (i);
page.save (type, make_indexed_file (file.get_uri (), i));
- i++;
+ saving (i);
}
}
@@ -126,14 +127,16 @@
var writer = new PsWriter (stream);
var surface = writer.surface;
- foreach (var page in pages)
+ for (var i = 0; i < get_n_pages (); i++)
{
+ var page = get_page (i);
var image = page.get_image (true);
var width = image.get_width () * 72.0 / page.get_dpi ();
var height = image.get_height () * 72.0 / page.get_dpi ();
surface.set_size (width, height);
save_ps_pdf_surface (surface, image, page.get_dpi ());
surface.show_page ();
+ saving (i);
}
}
@@ -457,6 +460,8 @@
writer.write_string ("\n");
writer.write_string ("endstream\n");
writer.write_string ("endobj\n");
+
+ saving (i);
}
/* Info */
@@ -490,16 +495,20 @@
public void save (string type, File file) throws Error
{
- if (strcmp (type, "jpeg") == 0)
- save_multi_file ("jpeg", file);
- else if (strcmp (type, "png") == 0)
- save_multi_file ("png", file);
- else if (strcmp (type, "tiff") == 0)
- save_multi_file ("tiff", file);
- else if (strcmp (type, "ps") == 0)
+ switch (type)
+ {
+ case "jpeg":
+ case "png":
+ case "tiff":
+ save_multi_file (type, file);
+ break;
+ case "ps":
save_ps (file);
- else if (strcmp (type, "pdf") == 0)
+ break;
+ case "pdf":
save_pdf (file);
+ break;
+ }
}
public void set_needs_saving (bool needs_saving)
=== modified file 'src/simple-scan.vala'
--- src/simple-scan.vala 2011-09-01 00:56:55 +0000
+++ src/simple-scan.vala 2012-05-15 17:37:17 +0000
@@ -349,12 +349,14 @@
if (path != null)
{
var file = File.new_for_path (path);
+ ui.show_progress_dialog();
try
{
book.save ("pdf", file);
}
catch (Error e)
{
+ ui.hide_progress_dialog();
warning ("Unable to save email file: %s", e.message);
return;
}
=== modified file 'src/ui.vala'
--- src/ui.vala 2012-05-02 01:41:44 +0000
+++ src/ui.vala 2012-05-15 17:37:17 +0000
@@ -60,6 +60,7 @@
private bool user_selected_device;
private Gtk.FileChooserDialog? save_dialog;
+ private ProgressBarDialog progress_dialog;
private bool have_error;
private string error_title;
@@ -455,12 +456,14 @@
else if (uri_lower.has_suffix (".tif") || uri_lower.has_suffix (".tiff"))
format = "tiff";
+ show_progress_dialog();
try
{
book.save (format, file);
}
catch (Error e)
{
+ hide_progress_dialog();
warning ("Error saving file: %s", e.message);
show_error (/* Title of error dialog when save failed */
_("Failed to save file"),
@@ -1418,6 +1421,39 @@
add_default_page ();
book.set_needs_saving (false);
book.needs_saving_changed.connect (needs_saving_cb);
+
+ progress_dialog = new ProgressBarDialog (window, _("Saving images to files..."));
+ book.saving.connect (book_saving_cb);
+ }
+
+ private void book_saving_cb(int page_number)
+ {
+ // Prevent GUI from freezing
+ while (Gtk.events_pending ())
+ Gtk.main_iteration ();
+
+ var total = (int)book.get_n_pages ();
+ var fraction = (page_number + 1.0)/total;
+ bool complete = fraction == 1.0;
+ if (complete)
+ Timeout.add(500, () => {
+ progress_dialog.hide();
+ return false;
+ });
+ var message = _("Saving page %d out of %d").printf (page_number, total);
+
+ progress_dialog.set_fraction (fraction);
+ progress_dialog.set_message (message);
+ }
+
+ public void show_progress_dialog ()
+ {
+ progress_dialog.show ();
+ }
+
+ public void hide_progress_dialog ()
+ {
+ progress_dialog.hide ();
}
public Book get_book ()
@@ -1457,3 +1493,43 @@
window.show ();
}
}
+
+class ProgressBarDialog : Gtk.Window {
+ Gtk.ProgressBar bar;
+
+ public ProgressBarDialog(Gtk.Window parent, string title)
+ {
+ bar = new Gtk.ProgressBar();
+ var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 5);
+ var vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 5);
+ hbox.set_hexpand(true);
+
+ bar.set_show_text(true);
+ bar.set_size_request(225, 25);
+ set_size_request(250, 50);
+
+ vbox.pack_start(bar, true, false, 0);
+ hbox.pack_start(vbox, true, false, 0);
+ add(hbox);
+ set_title(title);
+
+ set_transient_for(parent);
+ set_position(Gtk.WindowPosition.CENTER_ON_PARENT);
+ set_modal(true);
+ set_resizable(false);
+
+ hbox.show();
+ vbox.show();
+ bar.show();
+ }
+
+ public void set_fraction(double percent)
+ {
+ bar.set_fraction(percent);
+ }
+
+ public void set_message(string message)
+ {
+ bar.set_text(message);
+ }
+}
Follow ups