summaryrefslogtreecommitdiff
path: root/src/ui.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui.vala')
-rw-r--r--src/ui.vala202
1 files changed, 129 insertions, 73 deletions
diff --git a/src/ui.vala b/src/ui.vala
index 5e375c4..554b161 100644
--- a/src/ui.vala
+++ b/src/ui.vala
@@ -21,7 +21,6 @@ public class UserInterface : Gtk.ApplicationWindow
{ "new_document", new_document_activate_cb },
{ "reorder", reorder_document_activate_cb },
{ "save", save_document_activate_cb },
- { "save_as", save_as_document_activate_cb },
{ "email", email_document_activate_cb },
{ "print", print_document_activate_cb },
{ "preferences", preferences_activate_cb },
@@ -73,7 +72,9 @@ public class UserInterface : Gtk.ApplicationWindow
[GtkChild]
private Gtk.MenuItem save_menuitem;
[GtkChild]
- private Gtk.MenuItem save_as_menuitem;
+ private Gtk.MenuItem email_menuitem;
+ [GtkChild]
+ private Gtk.MenuItem print_menuitem;
[GtkChild]
private Gtk.MenuItem copy_to_clipboard_menuitem;
[GtkChild]
@@ -134,6 +135,8 @@ public class UserInterface : Gtk.ApplicationWindow
[GtkChild]
private Gtk.Scale quality_scale;
[GtkChild]
+ private Gtk.Scale page_delay_scale;
+ [GtkChild]
private Gtk.ListStore device_model;
[GtkChild]
private Gtk.ListStore text_dpi_model;
@@ -149,6 +152,8 @@ public class UserInterface : Gtk.ApplicationWindow
private Gtk.Adjustment contrast_adjustment;
[GtkChild]
private Gtk.Adjustment quality_adjustment;
+ [GtkChild]
+ private Gtk.Adjustment page_delay_adjustment;
private bool setting_devices;
private string? missing_driver = null;
private bool user_selected_device;
@@ -162,6 +167,7 @@ public class UserInterface : Gtk.ApplicationWindow
private bool error_change_scanner_hint;
public Book book { get; private set; }
+ private bool book_needs_saving;
private string? book_uri = null;
public Page selected_page
@@ -227,6 +233,12 @@ public class UserInterface : Gtk.ApplicationWindow
set { quality_adjustment.value = value; }
}
+ public int page_delay
+ {
+ get { return (int) page_delay_adjustment.value; }
+ set { page_delay_adjustment.value = value; }
+ }
+
public string? selected_device
{
owned get
@@ -266,21 +278,23 @@ public class UserInterface : Gtk.ApplicationWindow
book.page_added.connect (page_added_cb);
book.reordered.connect (reordered_cb);
book.page_removed.connect (page_removed_cb);
- book.needs_saving_changed.connect (needs_saving_cb);
+ book.changed.connect (book_changed_cb);
load ();
+ clear_document ();
autosave_manager = new AutosaveManager ();
autosave_manager.book = book;
autosave_manager.load ();
if (book.n_pages == 0)
- {
- add_default_page ();
- book.needs_saving = false;
- }
+ book_needs_saving = false;
else
+ {
book_view.selected_page = book.get_page (0);
+ book_needs_saving = true;
+ book_changed_cb (book);
+ }
}
~UserInterface ()
@@ -483,16 +497,6 @@ public class UserInterface : Gtk.ApplicationWindow
update_info_bar ();
}
- private void add_default_page ()
- {
- var page = new Page (default_page_width,
- default_page_height,
- default_page_dpi,
- default_page_scan_direction);
- book.append_page (page);
- book_view.selected_page = page;
- }
-
private string choose_file_location ()
{
/* Get directory to save to */
@@ -508,12 +512,15 @@ public class UserInterface : Gtk.ApplicationWindow
Gtk.FileChooserAction.SAVE,
_("_Cancel"), Gtk.ResponseType.CANCEL,
_("_Save"), Gtk.ResponseType.ACCEPT,
- null);
- save_dialog.do_overwrite_confirmation = true;
+ null);
save_dialog.local_only = false;
- save_dialog.set_current_folder (directory);
- /* Default filename to use when saving document */
- save_dialog.set_current_name (_("Scanned Document.pdf"));
+ if (book_uri != null)
+ save_dialog.set_uri (book_uri);
+ else {
+ save_dialog.set_current_folder (directory);
+ /* Default filename to use when saving document */
+ save_dialog.set_current_name (_("Scanned Document.pdf"));
+ }
/* Filter to only show images by default */
var filter = new Gtk.FileFilter ();
@@ -584,11 +591,13 @@ public class UserInterface : Gtk.ApplicationWindow
});
box.pack_start (file_type_combo, false, false, 0);
- var response = save_dialog.run ();
-
string? uri = null;
- if (response == Gtk.ResponseType.ACCEPT)
+ while (true)
{
+ var response = save_dialog.run ();
+ if (response != Gtk.ResponseType.ACCEPT)
+ break;
+
var extension = "";
Gtk.TreeIter i;
if (file_type_combo.get_active_iter (out i))
@@ -602,6 +611,20 @@ public class UserInterface : Gtk.ApplicationWindow
path += extension;
uri = File.new_for_path (path).get_uri ();
+
+ /* Check the file(s) don't already exist */
+ var files = new List<File> ();
+ var format = uri_to_format (uri);
+ if (format == "jpeg" || format == "png")
+ {
+ for (var j = 0; j < book.n_pages; j++)
+ files.append (book.make_indexed_file (uri, j));
+ }
+ else
+ files.append (File.new_for_uri (uri));
+
+ if (check_overwrite (save_dialog, files))
+ break;
}
settings.set_string ("save-directory", save_dialog.get_current_folder ());
@@ -612,13 +635,43 @@ public class UserInterface : Gtk.ApplicationWindow
return uri;
}
- private bool save_document (bool force_choose_location)
+ private bool check_overwrite (Gtk.Window parent, List<File> files)
+ {
+ foreach (var file in files)
+ {
+ if (!file.query_exists ())
+ continue;
+
+ var dialog = new Gtk.MessageDialog (parent, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.QUESTION, Gtk.ButtonsType.NONE,
+ /* Contents of dialog that shows if saving would overwrite and existing file. %s is replaced with the name of the file. */
+ _("A file named ā€œ%sā€ already exists. Do you want to replace it?"), file.get_basename ());
+ dialog.add_button (_("_Cancel"), Gtk.ResponseType.CANCEL);
+ dialog.add_button (/* Button in dialog that shows if saving would overwrite and existing file. Clicking the button allows simple-scan to overwrite the file. */
+ _("_Replace"), Gtk.ResponseType.ACCEPT);
+ var response = dialog.run ();
+ dialog.destroy ();
+
+ if (response != Gtk.ResponseType.ACCEPT)
+ return false;
+ }
+
+ return true;
+ }
+
+ private string uri_to_format (string uri)
{
- string? uri;
- if (book_uri != null && !force_choose_location)
- uri = book_uri;
+ var uri_lower = uri.down ();
+ if (uri_lower.has_suffix (".pdf"))
+ return "pdf";
+ else if (uri_lower.has_suffix (".png"))
+ return "png";
else
- uri = choose_file_location ();
+ return "jpeg";
+ }
+
+ private bool save_document ()
+ {
+ var uri = choose_file_location ();
if (uri == null)
return false;
@@ -626,16 +679,7 @@ public class UserInterface : Gtk.ApplicationWindow
debug ("Saving to '%s'", uri);
- var uri_lower = uri.down ();
- string format = "jpeg";
- if (uri_lower.has_suffix (".pdf"))
- format = "pdf";
- else if (uri_lower.has_suffix (".ps"))
- format = "ps";
- else if (uri_lower.has_suffix (".png"))
- format = "png";
- else if (uri_lower.has_suffix (".tif") || uri_lower.has_suffix (".tiff"))
- format = "tiff";
+ var format = uri_to_format (uri);
show_progress_dialog ();
try
@@ -653,14 +697,14 @@ public class UserInterface : Gtk.ApplicationWindow
return false;
}
+ book_needs_saving = false;
book_uri = uri;
- book.needs_saving = false;
return true;
}
private bool prompt_to_save (string title, string discard_label)
{
- if (!book.needs_saving)
+ if (!book_needs_saving)
return true;
var dialog = new Gtk.MessageDialog (this,
@@ -681,7 +725,7 @@ public class UserInterface : Gtk.ApplicationWindow
switch (response)
{
case Gtk.ResponseType.YES:
- if (save_document (false))
+ if (save_document ())
return true;
else
return false;
@@ -694,11 +738,18 @@ public class UserInterface : Gtk.ApplicationWindow
private void clear_document ()
{
+ book_view.default_page = new Page (default_page_width,
+ default_page_height,
+ default_page_dpi,
+ default_page_scan_direction);
book.clear ();
- add_default_page ();
+ book_needs_saving = false;
book_uri = null;
- book.needs_saving = false;
- save_as_menuitem.sensitive = false;
+ save_menuitem.sensitive = false;
+ email_menuitem.sensitive = false;
+ print_menuitem.sensitive = false;
+ save_button.sensitive = false;
+ save_toolbutton.sensitive = false;
copy_to_clipboard_menuitem.sensitive = false;
}
@@ -866,6 +917,7 @@ public class UserInterface : Gtk.ApplicationWindow
get_paper_size (out options.paper_width, out options.paper_height);
options.brightness = brightness;
options.contrast = contrast;
+ options.page_delay = page_delay;
return options;
}
@@ -898,6 +950,14 @@ public class UserInterface : Gtk.ApplicationWindow
}
[GtkCallback]
+ private void batch_button_clicked_cb (Gtk.Widget widget)
+ {
+ var options = make_scan_options ();
+ options.type = ScanType.BATCH;
+ start_scan (selected_device, options);
+ }
+
+ [GtkCallback]
private void preferences_button_clicked_cb (Gtk.Widget widget)
{
preferences_dialog.present ();
@@ -977,14 +1037,14 @@ public class UserInterface : Gtk.ApplicationWindow
private void show_page_cb (BookView view, Page page)
{
- var path = get_temporary_filename ("scanned-page", "tiff");
+ var path = get_temporary_filename ("scanned-page", "png");
if (path == null)
return;
var file = File.new_for_path (path);
try
{
- page.save ("tiff", quality, file);
+ page.save ("png", quality, file);
}
catch (Error e)
{
@@ -1347,12 +1407,12 @@ public class UserInterface : Gtk.ApplicationWindow
[GtkCallback]
private void save_file_button_clicked_cb (Gtk.Widget widget)
{
- save_document (false);
+ save_document ();
}
public void save_document_activate_cb ()
{
- save_document (false);
+ save_document ();
}
[GtkCallback]
@@ -1363,17 +1423,6 @@ public class UserInterface : Gtk.ApplicationWindow
page.copy_to_clipboard (this);
}
- [GtkCallback]
- private void save_as_file_button_clicked_cb (Gtk.Widget widget)
- {
- save_document (true);
- }
-
- public void save_as_document_activate_cb ()
- {
- save_document (true);
- }
-
private void draw_page (Gtk.PrintOperation operation,
Gtk.PrintContext print_context,
int page_number)
@@ -1761,10 +1810,6 @@ public class UserInterface : Gtk.ApplicationWindow
page.size_changed.disconnect (page_size_changed_cb);
page.scan_direction_changed.disconnect (page_scan_direction_changed_cb);
- /* If this is the last page add a new blank one */
- if (book.n_pages == 0)
- add_default_page ();
-
update_page_menu ();
}
@@ -1801,13 +1846,14 @@ public class UserInterface : Gtk.ApplicationWindow
}
}
- private void needs_saving_cb (Book book)
+ private void book_changed_cb (Book book)
{
- save_menuitem.sensitive = book.needs_saving;
- save_button.sensitive = book.needs_saving;
- save_toolbutton.sensitive = book.needs_saving;
- if (book.needs_saving)
- save_as_menuitem.sensitive = true;
+ save_menuitem.sensitive = true;
+ email_menuitem.sensitive = true;
+ print_menuitem.sensitive = true;
+ save_button.sensitive = true;
+ save_toolbutton.sensitive = true;
+ book_needs_saving = true;
copy_to_clipboard_menuitem.sensitive = true;
}
@@ -1840,7 +1886,6 @@ public class UserInterface : Gtk.ApplicationWindow
section.append_submenu (_("Document"), menu);
menu.append (_("Reorder Pages"), "app.reorder");
menu.append (_("Save"), "app.save");
- menu.append (_("Save As..."), "app.save_as");
menu.append (_("Email..."), "app.email");
menu.append (_("Print..."), "app.print");
@@ -1858,7 +1903,6 @@ public class UserInterface : Gtk.ApplicationWindow
app.add_accelerator ("<Ctrl>N", "app.new_document", null);
app.add_accelerator ("<Ctrl>S", "app.save", null);
- app.add_accelerator ("<Shift><Ctrl>S", "app.save_as", null);
app.add_accelerator ("<Ctrl>E", "app.email", null);
app.add_accelerator ("<Ctrl>P", "app.print", null);
app.add_accelerator ("F1", "app.help", null);
@@ -1973,6 +2017,18 @@ public class UserInterface : Gtk.ApplicationWindow
quality = settings.get_int ("jpeg-quality");
quality_adjustment.value_changed.connect (() => { settings.set_int ("jpeg-quality", quality); });
+ page_delay_scale.add_mark (0, Gtk.PositionType.BOTTOM, null);
+ page_delay_scale.add_mark (500, Gtk.PositionType.BOTTOM, null);
+ page_delay_scale.add_mark (1000, Gtk.PositionType.BOTTOM, null);
+ page_delay_scale.add_mark (2000, Gtk.PositionType.BOTTOM, null);
+ page_delay_scale.add_mark (4000, Gtk.PositionType.BOTTOM, null);
+ page_delay_scale.add_mark (6000, Gtk.PositionType.BOTTOM, null);
+ page_delay_scale.add_mark (8000, Gtk.PositionType.BOTTOM, null);
+ page_delay_scale.add_mark (10000, Gtk.PositionType.BOTTOM, null);
+ page_delay = settings.get_int ("page-delay");
+ page_delay_scale.format_value.connect ((value) => { return "%.1fs".printf (value / 1000.0); });
+ page_delay_adjustment.value_changed.connect (() => { settings.set_int ("page-delay", page_delay); });
+
var document_type = settings.get_string ("document-type");
if (document_type != null)
set_document_hint (document_type);