summaryrefslogtreecommitdiff
path: root/src/ui.vala
diff options
context:
space:
mode:
authorAlessio Treglia <alessio@debian.org>2013-10-05 15:28:26 +0100
committerAlessio Treglia <alessio@debian.org>2013-10-05 15:28:26 +0100
commit2d71d20a62ca8f6989d86db58ce64c7a862675dd (patch)
tree534c40e7c4b35662d60e261898b6b1ebd5724bed /src/ui.vala
parent695f537db79b0921621b54998ae46f331fff9105 (diff)
Imported Upstream version 3.10.0upstream/3.10.0
Diffstat (limited to 'src/ui.vala')
-rw-r--r--src/ui.vala153
1 files changed, 131 insertions, 22 deletions
diff --git a/src/ui.vala b/src/ui.vala
index 5b192d9..075c97d 100644
--- a/src/ui.vala
+++ b/src/ui.vala
@@ -31,6 +31,7 @@ public class UserInterface
private Gtk.MenuItem crop_rotate_menuitem;
private Gtk.MenuItem save_menuitem;
private Gtk.MenuItem save_as_menuitem;
+ private Gtk.MenuItem copy_to_clipboard_menuitem;
private Gtk.ToolButton save_toolbutton;
private Gtk.MenuItem stop_menuitem;
private Gtk.ToolButton stop_toolbutton;
@@ -51,11 +52,17 @@ public class UserInterface
private Gtk.ComboBox photo_dpi_combo;
private Gtk.ComboBox page_side_combo;
private Gtk.ComboBox paper_size_combo;
+ private Gtk.Scale brightness_scale;
+ private Gtk.Scale contrast_scale;
+ private Gtk.Scale quality_scale;
private Gtk.ListStore device_model;
private Gtk.ListStore text_dpi_model;
private Gtk.ListStore photo_dpi_model;
private Gtk.ListStore page_side_model;
private Gtk.ListStore paper_size_model;
+ private Gtk.Adjustment brightness_adjustment;
+ private Gtk.Adjustment contrast_adjustment;
+ private Gtk.Adjustment quality_adjustment;
private bool setting_devices;
private bool user_selected_device;
@@ -70,6 +77,8 @@ public class UserInterface
private Book book;
private string? book_uri = null;
+ private AutosaveManager? autosave_manager;
+
private BookView book_view;
private bool updating_page_menu;
private int default_page_width;
@@ -88,17 +97,19 @@ public class UserInterface
public signal void start_scan (string? device, ScanOptions options);
public signal void stop_scan ();
- public signal void email (string profile);
+ public signal void email (string profile, int quality);
public UserInterface ()
{
+ settings = new Settings ("org.gnome.SimpleScan");
+
book = new Book ();
book.page_removed.connect (page_removed_cb);
book.page_added.connect (page_added_cb);
- settings = new Settings ("org.gnome.SimpleScan");
-
load ();
+
+ autosave_manager = AutosaveManager.create (ref book);
}
~UserInterface ()
@@ -316,13 +327,7 @@ public class UserInterface
private void on_file_type_changed (Gtk.TreeSelection selection)
{
- Gtk.TreeModel model;
- Gtk.TreeIter iter;
- if (!selection.get_selected (out model, out iter))
- return;
-
- string extension;
- model.get (iter, 1, out extension, -1);
+ var extension = get_selected_extension (selection);
var path = save_dialog.get_filename ();
var filename = Path.get_basename (path);
@@ -334,6 +339,17 @@ public class UserInterface
save_dialog.set_current_name (filename);
}
+ private string get_selected_extension (Gtk.TreeSelection selection)
+ {
+ Gtk.TreeModel model;
+ Gtk.TreeIter iter;
+ string extension = "";
+
+ if (selection.get_selected (out model, out iter))
+ model.get (iter, 1, out extension, -1);
+ return extension;
+ }
+
private string choose_file_location ()
{
/* Get directory to save to */
@@ -373,10 +389,10 @@ public class UserInterface
expander.set_spacing (5);
save_dialog.set_extra_widget (expander);
- string extension = "";
+ string default_extension = "";
var index = default_file_name.last_index_of_char ('.');
if (index >= 0)
- extension = default_file_name.slice (0, index);
+ default_extension = default_file_name.substring (index);
var file_type_store = new Gtk.ListStore (2, typeof (string), typeof (string));
Gtk.TreeIter iter;
@@ -414,7 +430,7 @@ public class UserInterface
{
string e;
file_type_store.get (iter, 1, out e, -1);
- if (extension == e)
+ if (default_extension == e)
file_type_view.get_selection ().select_iter (iter);
} while (file_type_store.iter_next (ref iter));
}
@@ -426,7 +442,19 @@ public class UserInterface
string? uri = null;
if (response == Gtk.ResponseType.ACCEPT)
- uri = save_dialog.get_uri ();
+ {
+ var selection = file_type_view.get_selection ();
+ var extension = get_selected_extension (selection);
+
+ var path = save_dialog.get_filename ();
+ var filename = Path.get_basename (path);
+
+ var extension_index = filename.last_index_of_char ('.');
+ if (extension_index < 0)
+ path += extension;
+
+ uri = File.new_for_path (path).get_uri ();
+ }
settings.set_string ("save-directory", save_dialog.get_current_folder ());
@@ -465,7 +493,7 @@ public class UserInterface
show_progress_dialog ();
try
{
- book.save (format, file);
+ book.save (format, get_quality (), file);
}
catch (Error e)
{
@@ -525,6 +553,7 @@ public class UserInterface
book_uri = null;
book.set_needs_saving (false);
save_as_menuitem.set_sensitive (false);
+ copy_to_clipboard_menuitem.set_sensitive (false);
}
[CCode (cname = "G_MODULE_EXPORT new_button_clicked_cb", instance_pos = -1)]
@@ -610,6 +639,21 @@ public class UserInterface
if (have_iter)
paper_size_combo.set_active_iter (iter);
}
+
+ private void set_brightness (int brightness)
+ {
+ brightness_adjustment.set_value (brightness);
+ }
+
+ private void set_contrast (int contrast)
+ {
+ contrast_adjustment.set_value (contrast);
+ }
+
+ private void set_quality (int quality)
+ {
+ quality_adjustment.set_value (quality);
+ }
private int get_text_dpi ()
{
@@ -658,6 +702,21 @@ public class UserInterface
return false;
}
+ private int get_brightness ()
+ {
+ return (int) brightness_adjustment.get_value ();
+ }
+
+ private int get_contrast ()
+ {
+ return (int) contrast_adjustment.get_value ();
+ }
+
+ private int get_quality ()
+ {
+ return (int) quality_adjustment.get_value ();
+ }
+
private ScanOptions get_scan_options ()
{
var options = new ScanOptions ();
@@ -674,6 +733,8 @@ public class UserInterface
options.depth = 8;
}
get_paper_size (out options.paper_width, out options.paper_height);
+ options.brightness = get_brightness ();
+ options.contrast = get_contrast ();
return options;
}
@@ -791,7 +852,7 @@ public class UserInterface
try
{
- page.save ("tiff", file);
+ page.save ("tiff", get_quality (), file);
}
catch (Error e)
{
@@ -981,6 +1042,14 @@ public class UserInterface
save_document (false);
}
+ [CCode (cname = "G_MODULE_EXPORT copy_to_clipboard_button_clicked_cb", instance_pos = -1)]
+ public void copy_to_clipboard_button_clicked_cb (Gtk.Widget widget)
+ {
+ var page = book_view.get_selected ();
+ if (page != null)
+ page.copy_to_clipboard (window);
+ }
+
[CCode (cname = "G_MODULE_EXPORT save_as_file_button_clicked_cb", instance_pos = -1)]
public void save_as_file_button_clicked_cb (Gtk.Widget widget)
{
@@ -1015,7 +1084,7 @@ public class UserInterface
[CCode (cname = "G_MODULE_EXPORT email_button_clicked_cb", instance_pos = -1)]
public void email_button_clicked_cb (Gtk.Widget widget)
{
- email (document_hint);
+ email (document_hint, get_quality ());
}
[CCode (cname = "G_MODULE_EXPORT print_button_clicked_cb", instance_pos = -1)]
@@ -1069,7 +1138,7 @@ public class UserInterface
Gtk.show_about_dialog (window,
"title", title,
"program-name", "Simple Scan",
- "version", Config.VERSION,
+ "version", VERSION,
"comments", description,
"logo-icon-name", "scanner",
"authors", authors,
@@ -1101,6 +1170,9 @@ public class UserInterface
settings.set_enum ("page-side", get_page_side ());
settings.set_int ("paper-width", paper_width);
settings.set_int ("paper-height", paper_height);
+ settings.set_int ("brightness", get_brightness ());
+ settings.set_int ("contrast", get_contrast ());
+ settings.set_int ("jpeg-quality", get_quality ());
settings.set_int ("window-width", window_width);
settings.set_int ("window-height", window_height);
settings.set_boolean ("window-is-maximized", window_is_maximized);
@@ -1111,6 +1183,9 @@ public class UserInterface
window.destroy ();
+ if (autosave_manager != null)
+ autosave_manager.cleanup ();
+
return true;
}
@@ -1237,23 +1312,23 @@ public class UserInterface
save_toolbutton.set_sensitive (book.get_needs_saving ());
if (book.get_needs_saving ())
save_as_menuitem.set_sensitive (true);
+ copy_to_clipboard_menuitem.set_sensitive (true);
}
private void load ()
{
- Gtk.IconTheme.get_default ().append_search_path (Config.ICON_DIR);
+ Gtk.IconTheme.get_default ().append_search_path (ICON_DIR);
Gtk.Window.set_default_icon_name ("scanner");
builder = new Gtk.Builder ();
- var filename = Path.build_filename (Config.UI_DIR, "simple-scan.ui", null);
try
{
- builder.add_from_file (filename);
+ builder.add_from_resource ("/org/gnome/SimpleScan/simple-scan.ui");
}
catch (Error e)
{
- critical ("Unable to load UI %s: %s\n", filename, e.message);
+ critical ("Unable to load UI: %s\n", e.message);
show_error_dialog (/* Title of dialog when cannot load required files */
_("Files missing"),
/* Description in dialog when cannot load required files */
@@ -1272,6 +1347,7 @@ public class UserInterface
crop_rotate_menuitem = (Gtk.MenuItem) builder.get_object ("crop_rotate_menuitem");
save_menuitem = (Gtk.MenuItem) builder.get_object ("save_menuitem");
save_as_menuitem = (Gtk.MenuItem) builder.get_object ("save_as_menuitem");
+ copy_to_clipboard_menuitem = (Gtk.MenuItem) builder.get_object ("copy_to_clipboard_menuitem");
save_toolbutton = (Gtk.ToolButton) builder.get_object ("save_toolbutton");
stop_menuitem = (Gtk.MenuItem) builder.get_object ("stop_scan_menuitem");
stop_toolbutton = (Gtk.ToolButton) builder.get_object ("stop_toolbutton");
@@ -1297,6 +1373,12 @@ public class UserInterface
page_side_model = (Gtk.ListStore) page_side_combo.get_model ();
paper_size_combo = (Gtk.ComboBox) builder.get_object ("paper_size_combo");
paper_size_model = (Gtk.ListStore) paper_size_combo.get_model ();
+ brightness_scale = (Gtk.Scale) builder.get_object ("brightness_scale");
+ brightness_adjustment = (Gtk.Adjustment) brightness_scale.get_adjustment ();
+ contrast_scale = (Gtk.Scale) builder.get_object ("contrast_scale");
+ contrast_adjustment = (Gtk.Adjustment) contrast_scale.get_adjustment ();
+ quality_scale = (Gtk.Scale) builder.get_object ("quality_scale");
+ quality_adjustment = (Gtk.Adjustment) quality_scale.get_adjustment ();
/* Add InfoBar (not supported in Glade) */
info_bar = new Gtk.InfoBar ();
@@ -1363,6 +1445,33 @@ public class UserInterface
var paper_height = settings.get_int ("paper-height");
set_paper_size (paper_width, paper_height);
+ var lower = brightness_adjustment.get_lower ();
+ var darker_label = "<small>%s</small>".printf (_("Darker"));
+ var upper = brightness_adjustment.get_upper ();
+ var lighter_label = "<small>%s</small>".printf (_("Lighter"));
+ brightness_scale.add_mark (lower, Gtk.PositionType.BOTTOM, darker_label);
+ brightness_scale.add_mark (0, Gtk.PositionType.BOTTOM, null);
+ brightness_scale.add_mark (upper, Gtk.PositionType.BOTTOM, lighter_label);
+ set_brightness (settings.get_int ("brightness"));
+
+ lower = contrast_adjustment.get_lower ();
+ var less_label = "<small>%s</small>".printf (_("Less"));
+ upper = contrast_adjustment.get_upper ();
+ var more_label = "<small>%s</small>".printf (_("More"));
+ contrast_scale.add_mark (lower, Gtk.PositionType.BOTTOM, less_label);
+ contrast_scale.add_mark (0, Gtk.PositionType.BOTTOM, null);
+ contrast_scale.add_mark (upper, Gtk.PositionType.BOTTOM, more_label);
+ set_contrast (settings.get_int ("contrast"));
+
+ lower = quality_adjustment.get_lower ();
+ var minimum_label = "<small>%s</small>".printf (_("Minimum"));
+ upper = quality_adjustment.get_upper ();
+ var maximum_label = "<small>%s</small>".printf (_("Maximum"));
+ quality_scale.add_mark (lower, Gtk.PositionType.BOTTOM, minimum_label);
+ quality_scale.add_mark (75, Gtk.PositionType.BOTTOM, null);
+ quality_scale.add_mark (upper, Gtk.PositionType.BOTTOM, maximum_label);
+ set_quality (settings.get_int ("jpeg-quality"));
+
var device = settings.get_string ("selected-device");
if (device != null)
{