summaryrefslogtreecommitdiff
path: root/src/ui.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui.vala')
-rw-r--r--src/ui.vala903
1 files changed, 600 insertions, 303 deletions
diff --git a/src/ui.vala b/src/ui.vala
index 31ec151..2117a9a 100644
--- a/src/ui.vala
+++ b/src/ui.vala
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2009-2011 Canonical Ltd.
- * Author: Robert Ancell <robert.ancell@canonical.com>
+ * Author: Robert Ancell <robert.ancell@canonical.com>,
+ * Eduard Gotwig <g@ox.io>
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
@@ -9,7 +10,8 @@
* license.
*/
-public class UserInterface
+[GtkTemplate (ui = "/org/gnome/SimpleScan/simple-scan.ui")]
+public class UserInterface : Gtk.ApplicationWindow
{
private const int DEFAULT_TEXT_DPI = 150;
private const int DEFAULT_PHOTO_DPI = 300;
@@ -17,6 +19,7 @@ public class UserInterface
private const GLib.ActionEntry[] action_entries =
{
{ "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 },
@@ -29,54 +32,121 @@ public class UserInterface
private Settings settings;
- private Gtk.Builder builder;
-
- private Gtk.ApplicationWindow window;
- private GLib.MenuModel app_menu;
+ [GtkChild]
private Gtk.MenuBar menubar;
+ [GtkChild]
+ private Gtk.Toolbar toolbar;
+ [GtkChild]
+ private Gtk.Menu page_menu;
+ [GtkChild]
private Gtk.Box main_vbox;
private Gtk.InfoBar info_bar;
private Gtk.Image info_bar_image;
private Gtk.Label info_bar_label;
private Gtk.Button info_bar_close_button;
private Gtk.Button info_bar_change_scanner_button;
+ [GtkChild]
+ private Gtk.RadioMenuItem custom_crop_menuitem;
+ [GtkChild]
+ private Gtk.RadioMenuItem a4_menuitem;
+ [GtkChild]
+ private Gtk.RadioMenuItem a5_menuitem;
+ [GtkChild]
+ private Gtk.RadioMenuItem a6_menuitem;
+ [GtkChild]
+ private Gtk.RadioMenuItem letter_menuitem;
+ [GtkChild]
+ private Gtk.RadioMenuItem legal_menuitem;
+ [GtkChild]
+ private Gtk.RadioMenuItem four_by_six_menuitem;
+ [GtkChild]
+ private Gtk.RadioMenuItem no_crop_menuitem;
+ [GtkChild]
private Gtk.MenuItem page_move_left_menuitem;
+ [GtkChild]
private Gtk.MenuItem page_move_right_menuitem;
+ [GtkChild]
private Gtk.MenuItem page_delete_menuitem;
+ [GtkChild]
private Gtk.MenuItem crop_rotate_menuitem;
+ [GtkChild]
private Gtk.MenuItem save_menuitem;
+ [GtkChild]
private Gtk.MenuItem save_as_menuitem;
+ [GtkChild]
private Gtk.MenuItem copy_to_clipboard_menuitem;
+ [GtkChild]
+ private Gtk.Button save_button;
+ [GtkChild]
private Gtk.ToolButton save_toolbutton;
- private Gtk.MenuItem stop_menuitem;
+ [GtkChild]
+ private Gtk.MenuItem stop_scan_menuitem;
+ [GtkChild]
private Gtk.ToolButton stop_toolbutton;
-
- private Gtk.RadioMenuItem text_toolbar_menuitem;
- private Gtk.RadioMenuItem text_menu_menuitem;
- private Gtk.RadioMenuItem photo_toolbar_menuitem;
- private Gtk.RadioMenuItem photo_menu_menuitem;
-
+ [GtkChild]
+ private Gtk.ToggleButton crop_button;
+ [GtkChild]
+ private Gtk.ToggleToolButton crop_toolbutton;
+ [GtkChild]
+ private Gtk.Button stop_button;
+ [GtkChild]
+ private Gtk.Button scan_button;
+
+ [GtkChild]
+ private Gtk.RadioMenuItem text_button_menuitem;
+ [GtkChild]
+ private Gtk.RadioMenuItem text_button_hb_menuitem;
+ [GtkChild]
+ private Gtk.RadioMenuItem text_menuitem;
+ [GtkChild]
+ private Gtk.RadioMenuItem photo_button_menuitem;
+ [GtkChild]
+ private Gtk.RadioMenuItem photo_button_hb_menuitem;
+ [GtkChild]
+ private Gtk.RadioMenuItem photo_menuitem;
+
+ [GtkChild]
private Gtk.Dialog authorize_dialog;
+ [GtkChild]
private Gtk.Label authorize_label;
+ [GtkChild]
private Gtk.Entry username_entry;
+ [GtkChild]
private Gtk.Entry password_entry;
+ [GtkChild]
private Gtk.Dialog preferences_dialog;
+ [GtkChild]
private Gtk.ComboBox device_combo;
+ [GtkChild]
private Gtk.ComboBox text_dpi_combo;
+ [GtkChild]
private Gtk.ComboBox photo_dpi_combo;
+ [GtkChild]
private Gtk.ComboBox page_side_combo;
+ [GtkChild]
private Gtk.ComboBox paper_size_combo;
+ [GtkChild]
private Gtk.Scale brightness_scale;
+ [GtkChild]
private Gtk.Scale contrast_scale;
+ [GtkChild]
private Gtk.Scale quality_scale;
+ [GtkChild]
private Gtk.ListStore device_model;
+ [GtkChild]
private Gtk.ListStore text_dpi_model;
+ [GtkChild]
private Gtk.ListStore photo_dpi_model;
+ [GtkChild]
private Gtk.ListStore page_side_model;
+ [GtkChild]
private Gtk.ListStore paper_size_model;
+ [GtkChild]
private Gtk.Adjustment brightness_adjustment;
+ [GtkChild]
private Gtk.Adjustment contrast_adjustment;
+ [GtkChild]
private Gtk.Adjustment quality_adjustment;
private bool setting_devices;
private bool user_selected_device;
@@ -123,9 +193,11 @@ public class UserInterface
set
{
scanning_ = value;
- page_delete_menuitem.set_sensitive (!value);
- stop_menuitem.set_sensitive (value);
- stop_toolbutton.set_sensitive (value);
+ page_delete_menuitem.sensitive = !value;
+ stop_scan_menuitem.sensitive = value;
+ stop_toolbutton.sensitive = value;
+ scan_button.visible = !value;
+ stop_button.visible = value;
}
}
@@ -137,20 +209,20 @@ public class UserInterface
public int brightness
{
- get { return (int) brightness_adjustment.get_value (); }
- set { brightness_adjustment.set_value (value); }
+ get { return (int) brightness_adjustment.value; }
+ set { brightness_adjustment.value = value; }
}
public int contrast
{
- get { return (int) contrast_adjustment.get_value (); }
- set { contrast_adjustment.set_value (value); }
+ get { return (int) contrast_adjustment.value; }
+ set { contrast_adjustment.value = value; }
}
public int quality
{
- get { return (int) quality_adjustment.get_value (); }
- set { quality_adjustment.set_value (value); }
+ get { return (int) quality_adjustment.value; }
+ set { quality_adjustment.value = value; }
}
public string? selected_device
@@ -189,8 +261,9 @@ public class UserInterface
settings = new Settings ("org.gnome.SimpleScan");
book = new Book ();
- book.page_removed.connect (page_removed_cb);
book.page_added.connect (page_added_cb);
+ book.reordered.connect (reordered_cb);
+ book.page_removed.connect (page_removed_cb);
load ();
@@ -210,8 +283,9 @@ public class UserInterface
~UserInterface ()
{
- book.page_removed.disconnect (page_removed_cb);
book.page_added.disconnect (page_added_cb);
+ book.reordered.disconnect (reordered_cb);
+ book.page_removed.disconnect (page_removed_cb);
}
private bool find_scan_device (string device, out Gtk.TreeIter iter)
@@ -234,7 +308,7 @@ public class UserInterface
private void show_error_dialog (string error_title, string error_text)
{
- var dialog = new Gtk.MessageDialog (window,
+ var dialog = new Gtk.MessageDialog (this,
Gtk.DialogFlags.MODAL,
Gtk.MessageType.WARNING,
Gtk.ButtonsType.NONE,
@@ -249,20 +323,20 @@ public class UserInterface
/* Label in authorization dialog. '%s' is replaced with the name of the resource requesting authorization */
var description = _("Username and password required to access '%s'").printf (resource);
- username_entry.set_text ("");
- password_entry.set_text ("");
+ username_entry.text = "";
+ password_entry.text = "";
authorize_label.set_text (description);
- authorize_dialog.show ();
+ authorize_dialog.visible = true;
authorize_dialog.run ();
- authorize_dialog.hide ();
+ authorize_dialog.visible = false;
- username = username_entry.get_text ();
- password = password_entry.get_text ();
+ username = username_entry.text;
+ password = password_entry.text;
}
- [CCode (cname = "G_MODULE_EXPORT device_combo_changed_cb", instance_pos = -1)]
- public void device_combo_changed_cb (Gtk.Widget widget)
+ [GtkCallback]
+ private void device_combo_changed_cb (Gtk.Widget widget)
{
if (setting_devices)
return;
@@ -298,17 +372,17 @@ public class UserInterface
}
else
{
- info_bar.hide ();
+ info_bar.visible = false;
return;
}
- info_bar.set_message_type (type);
+ info_bar.message_type = type;
info_bar_image.set_from_icon_name (image_id, Gtk.IconSize.DIALOG);
var message = "<big><b>%s</b></big>\n\n%s".printf (title, text);
info_bar_label.set_markup (message);
- info_bar_close_button.set_visible (show_close_button);
- info_bar_change_scanner_button.set_visible (show_change_scanner_button);
- info_bar.show ();
+ info_bar_close_button.visible = show_close_button;
+ info_bar_change_scanner_button.visible = show_change_scanner_button;
+ info_bar.visible = true;
}
public void set_scan_devices (List<ScanDevice> devices)
@@ -321,7 +395,7 @@ public class UserInterface
/* If the user hasn't chosen a scanner choose the best available one */
if (user_selected_device)
- have_selection = device_combo.get_active () >= 0;
+ have_selection = device_combo.active >= 0;
/* Add new devices */
index = 0;
@@ -431,13 +505,13 @@ public class UserInterface
save_dialog = new Gtk.FileChooserDialog (/* Save dialog: Dialog title */
_("Save As..."),
- window,
+ this,
Gtk.FileChooserAction.SAVE,
_("_Cancel"), Gtk.ResponseType.CANCEL,
_("_Save"), Gtk.ResponseType.ACCEPT,
null);
- save_dialog.set_do_overwrite_confirmation (true);
- save_dialog.set_local_only (false);
+ save_dialog.do_overwrite_confirmation = true;
+ save_dialog.local_only = false;
save_dialog.set_current_folder (directory);
save_dialog.set_current_name (default_file_name);
@@ -456,7 +530,7 @@ public class UserInterface
var expander = new Gtk.Expander.with_mnemonic (/* */
_("Select File _Type"));
- expander.set_spacing (5);
+ expander.spacing = 5;
save_dialog.set_extra_widget (expander);
string default_extension = "";
@@ -486,8 +560,8 @@ public class UserInterface
-1);
var file_type_view = new Gtk.TreeView.with_model (file_type_store);
- file_type_view.set_headers_visible (false);
- file_type_view.set_rules_hint (true);
+ file_type_view.headers_visible = false;
+ file_type_view.rules_hint = true;
var column = new Gtk.TreeViewColumn.with_attributes ("",
new Gtk.CellRendererText (),
"text", 0, null);
@@ -586,7 +660,7 @@ public class UserInterface
if (!book.needs_saving)
return true;
- var dialog = new Gtk.MessageDialog (window,
+ var dialog = new Gtk.MessageDialog (this,
Gtk.DialogFlags.MODAL,
Gtk.MessageType.WARNING,
Gtk.ButtonsType.NONE,
@@ -622,8 +696,8 @@ public class UserInterface
add_default_page ();
book_uri = null;
book.needs_saving = false;
- save_as_menuitem.set_sensitive (false);
- copy_to_clipboard_menuitem.set_sensitive (false);
+ save_as_menuitem.sensitive = false;
+ copy_to_clipboard_menuitem.sensitive = false;
}
private void new_document ()
@@ -639,8 +713,8 @@ public class UserInterface
clear_document ();
}
- [CCode (cname = "G_MODULE_EXPORT new_button_clicked_cb", instance_pos = -1)]
- public void new_button_clicked_cb (Gtk.Widget widget)
+ [GtkCallback]
+ private void new_button_clicked_cb (Gtk.Widget widget)
{
new_document();
}
@@ -656,33 +730,33 @@ public class UserInterface
if (document_hint == "text")
{
- text_toolbar_menuitem.set_active (true);
- text_menu_menuitem.set_active (true);
+ text_button_menuitem.active = true;
+ text_button_hb_menuitem.active = true;
+ text_menuitem.active = true;
}
else if (document_hint == "photo")
{
- photo_toolbar_menuitem.set_active (true);
- photo_menu_menuitem.set_active (true);
+ photo_button_menuitem.active = true;
+ photo_button_hb_menuitem.active = true;
+ photo_menuitem.active = true;
}
if (save)
settings.set_string ("document-type", document_hint);
}
- [CCode (cname = "G_MODULE_EXPORT text_menuitem_toggled_cb", instance_pos = -1)]
- public void text_menuitem_toggled_cb (Gtk.CheckMenuItem widget)
+ [GtkCallback]
+ private void text_menuitem_toggled_cb (Gtk.CheckMenuItem widget)
{
- if (widget.get_active ())
+ if (widget.active)
set_document_hint ("text", true);
}
- [CCode (cname = "G_MODULE_EXPORT photo_menuitem_toggled_cb", instance_pos = -1)]
- public void photo_menuitem_toggled_cb (Gtk.CheckMenuItem widget)
+ [GtkCallback]
+ private void photo_menuitem_toggled_cb (Gtk.CheckMenuItem widget)
{
- if (widget.get_active ())
- {
+ if (widget.active)
set_document_hint ("photo", true);
- }
}
private void set_page_side (ScanType page_side)
@@ -794,22 +868,22 @@ public class UserInterface
return options;
}
- [CCode (cname = "G_MODULE_EXPORT scan_button_clicked_cb", instance_pos = -1)]
- public void scan_button_clicked_cb (Gtk.Widget widget)
+ [GtkCallback]
+ private void scan_button_clicked_cb (Gtk.Widget widget)
{
var options = make_scan_options ();
options.type = ScanType.SINGLE;
start_scan (selected_device, options);
}
- [CCode (cname = "G_MODULE_EXPORT stop_scan_button_clicked_cb", instance_pos = -1)]
- public void stop_scan_button_clicked_cb (Gtk.Widget widget)
+ [GtkCallback]
+ private void stop_scan_button_clicked_cb (Gtk.Widget widget)
{
stop_scan ();
}
- [CCode (cname = "G_MODULE_EXPORT continuous_scan_button_clicked_cb", instance_pos = -1)]
- public void continuous_scan_button_clicked_cb (Gtk.Widget widget)
+ [GtkCallback]
+ private void continuous_scan_button_clicked_cb (Gtk.Widget widget)
{
if (scanning)
stop_scan ();
@@ -821,8 +895,8 @@ public class UserInterface
}
}
- [CCode (cname = "G_MODULE_EXPORT preferences_button_clicked_cb", instance_pos = -1)]
- public void preferences_button_clicked_cb (Gtk.Widget widget)
+ [GtkCallback]
+ private void preferences_button_clicked_cb (Gtk.Widget widget)
{
preferences_dialog.present ();
}
@@ -832,16 +906,16 @@ public class UserInterface
preferences_dialog.present ();
}
- [CCode (cname = "G_MODULE_EXPORT preferences_dialog_delete_event_cb", instance_pos = -1)]
- public bool preferences_dialog_delete_event_cb (Gtk.Widget widget)
+ [GtkCallback]
+ private bool preferences_dialog_delete_event_cb (Gtk.Widget widget, Gdk.EventAny event)
{
return true;
}
- [CCode (cname = "G_MODULE_EXPORT preferences_dialog_response_cb", instance_pos = -1)]
- public void preferences_dialog_response_cb (Gtk.Widget widget, int response_id)
+ [GtkCallback]
+ private void preferences_dialog_response_cb (Gtk.Widget widget, int response_id)
{
- preferences_dialog.hide ();
+ preferences_dialog.visible = false;
}
private void update_page_menu ()
@@ -849,14 +923,14 @@ public class UserInterface
var page = book_view.selected_page;
if (page == null)
{
- page_move_left_menuitem.set_sensitive (false);
- page_move_right_menuitem.set_sensitive (false);
+ page_move_left_menuitem.sensitive = false;
+ page_move_right_menuitem.sensitive = false;
}
else
{
var index = book.get_page_index (page);
- page_move_left_menuitem.set_sensitive (index > 0);
- page_move_right_menuitem.set_sensitive (index < book.n_pages - 1);
+ page_move_left_menuitem.sensitive = index > 0;
+ page_move_right_menuitem.sensitive = index < book.n_pages - 1;
}
}
@@ -869,35 +943,33 @@ public class UserInterface
update_page_menu ();
- var name = "no_crop_menuitem";
+ var menuitem = no_crop_menuitem;
if (page.has_crop)
{
- // FIXME: Make more generic, move into page-size.c and reuse
var crop_name = page.crop_name;
if (crop_name != null)
{
if (crop_name == "A4")
- name = "a4_menuitem";
+ menuitem = a4_menuitem;
else if (crop_name == "A5")
- name = "a5_menuitem";
+ menuitem = a5_menuitem;
else if (crop_name == "A6")
- name = "a6_menuitem";
+ menuitem = a6_menuitem;
else if (crop_name == "letter")
- name = "letter_menuitem";
+ menuitem = letter_menuitem;
else if (crop_name == "legal")
- name = "legal_menuitem";
+ menuitem = legal_menuitem;
else if (crop_name == "4x6")
- name = "4x6_menuitem";
+ menuitem = four_by_six_menuitem;
}
else
- name = "custom_crop_menuitem";
+ menuitem = custom_crop_menuitem;
}
- var menuitem = (Gtk.RadioMenuItem) builder.get_object (name);
- menuitem.set_active (true);
- var toolbutton = (Gtk.ToggleToolButton) builder.get_object ("crop_toolbutton");
- toolbutton.set_active (page.has_crop);
-
+ menuitem.active = true;
+ crop_button.active = page.has_crop;
+ crop_toolbutton.active = page.has_crop;
+
updating_page_menu = false;
}
@@ -922,7 +994,7 @@ public class UserInterface
try
{
- Gtk.show_uri (window.get_screen (), file.get_uri (), Gtk.get_current_event_time ());
+ Gtk.show_uri (screen, file.get_uri (), Gtk.get_current_event_time ());
}
catch (Error e)
{
@@ -934,12 +1006,11 @@ public class UserInterface
private void show_page_menu_cb (BookView view)
{
- var menu = (Gtk.Menu) builder.get_object ("page_menu");
- menu.popup (null, null, null, 3, Gtk.get_current_event_time());
+ page_menu.popup (null, null, null, 3, Gtk.get_current_event_time ());
}
- [CCode (cname = "G_MODULE_EXPORT rotate_left_button_clicked_cb", instance_pos = -1)]
- public void rotate_left_button_clicked_cb (Gtk.Widget widget)
+ [GtkCallback]
+ private void rotate_left_button_clicked_cb (Gtk.Widget widget)
{
if (updating_page_menu)
return;
@@ -948,8 +1019,8 @@ public class UserInterface
page.rotate_left ();
}
- [CCode (cname = "G_MODULE_EXPORT rotate_right_button_clicked_cb", instance_pos = -1)]
- public void rotate_right_button_clicked_cb (Gtk.Widget widget)
+ [GtkCallback]
+ private void rotate_right_button_clicked_cb (Gtk.Widget widget)
{
if (updating_page_menu)
return;
@@ -960,7 +1031,7 @@ public class UserInterface
private void set_crop (string? crop_name)
{
- crop_rotate_menuitem.set_sensitive (crop_name != null);
+ crop_rotate_menuitem.sensitive = crop_name != null;
if (updating_page_menu)
return;
@@ -987,78 +1058,88 @@ public class UserInterface
page.set_named_crop (crop_name);
}
- [CCode (cname = "G_MODULE_EXPORT no_crop_menuitem_toggled_cb", instance_pos = -1)]
- public void no_crop_menuitem_toggled_cb (Gtk.CheckMenuItem widget)
+ [GtkCallback]
+ private void no_crop_menuitem_toggled_cb (Gtk.CheckMenuItem widget)
{
- if (widget.get_active ())
+ if (widget.active)
set_crop (null);
}
- [CCode (cname = "G_MODULE_EXPORT custom_crop_menuitem_toggled_cb", instance_pos = -1)]
- public void custom_crop_menuitem_toggled_cb (Gtk.CheckMenuItem widget)
+ [GtkCallback]
+ private void custom_crop_menuitem_toggled_cb (Gtk.CheckMenuItem widget)
{
- if (widget.get_active ())
+ if (widget.active)
set_crop ("custom");
}
- [CCode (cname = "G_MODULE_EXPORT crop_toolbutton_toggled_cb", instance_pos = -1)]
- public void crop_toolbutton_toggled_cb (Gtk.ToggleToolButton widget)
+ [GtkCallback]
+ private void crop_button_toggled_cb (Gtk.ToggleButton widget)
+ {
+ if (updating_page_menu)
+ return;
+
+ if (widget.active)
+ custom_crop_menuitem.active = true;
+ else
+ no_crop_menuitem.active = true;
+ }
+
+ [GtkCallback]
+ private void crop_toolbutton_toggled_cb (Gtk.ToggleToolButton widget)
{
if (updating_page_menu)
return;
- Gtk.RadioMenuItem menuitem;
- if (widget.get_active ())
- menuitem = (Gtk.RadioMenuItem) builder.get_object ("custom_crop_menuitem");
+ if (widget.active)
+ custom_crop_menuitem.active = true;
else
- menuitem = (Gtk.RadioMenuItem) builder.get_object ("no_crop_menuitem");
- menuitem.set_active (true);
+ no_crop_menuitem.active = true;
}
- [CCode (cname = "G_MODULE_EXPORT four_by_six_menuitem_toggled_cb", instance_pos = -1)]
- public void four_by_six_menuitem_toggled_cb (Gtk.CheckMenuItem widget)
+ [GtkCallback]
+ private void four_by_six_menuitem_toggled_cb (Gtk.CheckMenuItem widget)
{
- if (widget.get_active ())
+ if (widget.active)
set_crop ("4x6");
}
- [CCode (cname = "G_MODULE_EXPORT legal_menuitem_toggled_cb", instance_pos = -1)]
- public void legal_menuitem_toggled_cb (Gtk.CheckMenuItem widget)
+ [GtkCallback]
+ private void legal_menuitem_toggled_cb (Gtk.CheckMenuItem widget)
{
- if (widget.get_active ())
+ if (widget.active)
set_crop ("legal");
}
- [CCode (cname = "G_MODULE_EXPORT letter_menuitem_toggled_cb", instance_pos = -1)]
- public void letter_menuitem_toggled_cb (Gtk.CheckMenuItem widget)
+ [GtkCallback]
+ private void letter_menuitem_toggled_cb (Gtk.CheckMenuItem widget)
{
- if (widget.get_active ())
+ if (widget.active)
set_crop ("letter");
}
- [CCode (cname = "G_MODULE_EXPORT a6_menuitem_toggled_cb", instance_pos = -1)]
- public void a6_menuitem_toggled_cb (Gtk.CheckMenuItem widget)
+ [GtkCallback]
+ private void a6_menuitem_toggled_cb (Gtk.CheckMenuItem widget)
{
- if (widget.get_active ())
+ if (widget.active)
set_crop ("A6");
}
- [CCode (cname = "G_MODULE_EXPORT a5_menuitem_toggled_cb", instance_pos = -1)]
- public void a5_menuitem_toggled_cb (Gtk.CheckMenuItem widget)
+ [GtkCallback]
+ private void a5_menuitem_toggled_cb (Gtk.CheckMenuItem widget)
{
- if (widget.get_active ())
+ if (widget.active)
set_crop ("A5");
}
- [CCode (cname = "G_MODULE_EXPORT a4_menuitem_toggled_cb", instance_pos = -1)]
- public void a4_menuitem_toggled_cb (Gtk.CheckMenuItem widget)
+ [GtkCallback]
+ private void a4_menuitem_toggled_cb (Gtk.CheckMenuItem widget)
{
- if (widget.get_active ())
+ if (widget.active)
set_crop ("A4");
}
- [CCode (cname = "G_MODULE_EXPORT crop_rotate_menuitem_activate_cb", instance_pos = -1)]
- public void crop_rotate_menuitem_activate_cb (Gtk.Widget widget)
+ [GtkCallback]
+ private void crop_rotate_menuitem_activate_cb (Gtk.Widget widget)
{
var page = book_view.selected_page;
if (page == null)
@@ -1066,36 +1147,203 @@ public class UserInterface
page.rotate_crop ();
}
- [CCode (cname = "G_MODULE_EXPORT page_move_left_menuitem_activate_cb", instance_pos = -1)]
- public void page_move_left_menuitem_activate_cb (Gtk.Widget widget)
+ [GtkCallback]
+ private void page_move_left_menuitem_activate_cb (Gtk.Widget widget)
{
var page = book_view.selected_page;
var index = book.get_page_index (page);
if (index > 0)
book.move_page (page, index - 1);
-
- update_page_menu ();
}
- [CCode (cname = "G_MODULE_EXPORT page_move_right_menuitem_activate_cb", instance_pos = -1)]
- public void page_move_right_menuitem_activate_cb (Gtk.Widget widget)
+ [GtkCallback]
+ private void page_move_right_menuitem_activate_cb (Gtk.Widget widget)
{
var page = book_view.selected_page;
var index = book.get_page_index (page);
if (index < book.n_pages - 1)
book.move_page (page, book.get_page_index (page) + 1);
-
- update_page_menu ();
}
- [CCode (cname = "G_MODULE_EXPORT page_delete_menuitem_activate_cb", instance_pos = -1)]
- public void page_delete_menuitem_activate_cb (Gtk.Widget widget)
+ [GtkCallback]
+ private void page_delete_menuitem_activate_cb (Gtk.Widget widget)
{
book_view.book.delete_page (book_view.selected_page);
}
- [CCode (cname = "G_MODULE_EXPORT save_file_button_clicked_cb", instance_pos = -1)]
- public void save_file_button_clicked_cb (Gtk.Widget widget)
+ private void reorder_document ()
+ {
+ var dialog = new Gtk.Window ();
+ dialog.type_hint = Gdk.WindowTypeHint.DIALOG;
+ dialog.modal = true;
+ dialog.border_width = 12;
+ /* Title of dialog to reorder pages */
+ dialog.title = _("Reorder Pages");
+ dialog.set_transient_for (this);
+ dialog.key_press_event.connect ((e) =>
+ {
+ if (e.state == 0 && e.keyval == Gdk.Key.Escape)
+ {
+ dialog.destroy ();
+ return true;
+ }
+
+ return false;
+ });
+ dialog.visible = true;
+
+ var g = new Gtk.Grid ();
+ g.row_homogeneous = true;
+ g.row_spacing = 6;
+ g.column_homogeneous = true;
+ g.column_spacing = 6;
+ g.visible = true;
+ dialog.add (g);
+
+ /* Label on button for combining sides in reordering dialog */
+ var b = make_reorder_button (_("Combine sides"), "F1F2F3B1B2B3-F1B1F2B2F3B3");
+ b.clicked.connect (() =>
+ {
+ book.combine_sides ();
+ dialog.destroy ();
+ });
+ b.visible = true;
+ g.attach (b, 0, 0, 1, 1);
+
+ /* Label on button for combining sides in reverse order in reordering dialog */
+ b = make_reorder_button (_("Combine sides (reverse)"), "F1F2F3B3B2B1-F1B1F2B2F3B3");
+ b.clicked.connect (() =>
+ {
+ book.combine_sides_reverse ();
+ dialog.destroy ();
+ });
+ b.visible = true;
+ g.attach (b, 1, 0, 1, 1);
+
+ /* Label on button for reversing in reordering dialog */
+ b = make_reorder_button (_("Reverse"), "C1C2C3C4C5C6-C6C5C4C3C2C1");
+ b.clicked.connect (() =>
+ {
+ book.reverse ();
+ dialog.destroy ();
+ });
+ b.visible = true;
+ g.attach (b, 0, 2, 1, 1);
+
+ /* Label on button for cancelling page reordering dialog */
+ b = make_reorder_button (_("Keep unchanged"), "C1C2C3C4C5C6-C1C2C3C4C5C6");
+ b.clicked.connect (() =>
+ {
+ dialog.destroy ();
+ });
+ b.visible = true;
+ g.attach (b, 1, 2, 1, 1);
+
+ dialog.present ();
+ }
+
+ public void reorder_document_activate_cb ()
+ {
+ reorder_document ();
+ }
+
+ [GtkCallback]
+ private void reorder_menuitem_activate_cb (Gtk.Widget widget)
+ {
+ reorder_document ();
+ }
+
+ private Gtk.Button make_reorder_button (string text, string items)
+ {
+ var b = new Gtk.Button ();
+
+ var vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 6);
+ vbox.visible = true;
+ b.add (vbox);
+
+ var label = new Gtk.Label (text);
+ label.visible = true;
+ vbox.pack_start (label, true, true, 0);
+
+ var rb = make_reorder_box (items);
+ rb.visible = true;
+ vbox.pack_start (rb, true, true, 0);
+
+ return b;
+ }
+
+ private Gtk.Box make_reorder_box (string items)
+ {
+ var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
+ box.visible = true;
+
+ Gtk.Box? page_box = null;
+ for (var i = 0; items[i] != '\0'; i++)
+ {
+ if (items[i] == '-')
+ {
+ var a = new Gtk.Arrow (Gtk.ArrowType.RIGHT, Gtk.ShadowType.NONE);
+ a.visible = true;
+ box.pack_start (a, false, false, 0);
+ page_box = null;
+ continue;
+ }
+
+ /* First character describes side */
+ var side = items[i];
+ i++;
+ if (items[i] == '\0')
+ break;
+
+ if (page_box == null)
+ {
+ page_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 3);
+ page_box.visible = true;
+ box.pack_start (page_box, false, false, 0);
+ }
+
+ /* Get colours for each page (from Tango palette) */
+ var r = 1.0;
+ var g = 1.0;
+ var b = 1.0;
+ switch (side)
+ {
+ case 'F':
+ /* Plum */
+ r = 0x75 / 255.0;
+ g = 0x50 / 255.0;
+ b = 0x7B / 255.0;
+ break;
+ case 'B':
+ /* Orange */
+ r = 0xF5 / 255.0;
+ g = 0x79 / 255.0;
+ b = 0.0;
+ break;
+ case 'C':
+ /* Butter to Scarlet Red */
+ var p = (items[i] - '1') / 5.0;
+ r = (0xED / 255.0) * (1 - p) + 0xCC * p;
+ g = (0xD4 / 255.0) * (1 - p);
+ b = 0;
+ break;
+ }
+
+ /* Mix with white to look more paper like */
+ r = r + (1.0 - r) * 0.7;
+ g = g + (1.0 - g) * 0.7;
+ b = b + (1.0 - b) * 0.7;
+
+ var icon = new PageIcon ("%c".printf (items[i]), r, g, b);
+ icon.visible = true;
+ page_box.pack_start (icon, false, false, 0);
+ }
+
+ return box;
+ }
+
+ [GtkCallback]
+ private void save_file_button_clicked_cb (Gtk.Widget widget)
{
save_document (false);
}
@@ -1105,16 +1353,16 @@ 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)
+ [GtkCallback]
+ private void copy_to_clipboard_button_clicked_cb (Gtk.Widget widget)
{
var page = book_view.selected_page;
if (page != null)
- page.copy_to_clipboard (window);
+ page.copy_to_clipboard (this);
}
- [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)
+ [GtkCallback]
+ private void save_as_file_button_clicked_cb (Gtk.Widget widget)
{
save_document (true);
}
@@ -1149,8 +1397,8 @@ public class UserInterface
context.paint ();
}
- [CCode (cname = "G_MODULE_EXPORT email_button_clicked_cb", instance_pos = -1)]
- public void email_button_clicked_cb (Gtk.Widget widget)
+ [GtkCallback]
+ private void email_button_clicked_cb (Gtk.Widget widget)
{
email (document_hint, quality);
}
@@ -1163,12 +1411,12 @@ public class UserInterface
private void print_document ()
{
var print = new Gtk.PrintOperation ();
- print.set_n_pages ((int) book.n_pages);
+ print.n_pages = (int) book.n_pages;
print.draw_page.connect (draw_page);
try
{
- print.run (Gtk.PrintOperationAction.PRINT_DIALOG, window);
+ print.run (Gtk.PrintOperationAction.PRINT_DIALOG, this);
}
catch (Error e)
{
@@ -1178,8 +1426,8 @@ public class UserInterface
print.draw_page.disconnect (draw_page);
}
- [CCode (cname = "G_MODULE_EXPORT print_button_clicked_cb", instance_pos = -1)]
- public void print_button_clicked_cb (Gtk.Widget widget)
+ [GtkCallback]
+ private void print_button_clicked_cb (Gtk.Widget widget)
{
print_document ();
}
@@ -1189,11 +1437,11 @@ public class UserInterface
print_document ();
}
- private void show_help ()
+ private void launch_help ()
{
try
{
- Gtk.show_uri (window.get_screen (), "help:simple-scan", Gtk.get_current_event_time ());
+ Gtk.show_uri (screen, "help:simple-scan", Gtk.get_current_event_time ());
}
catch (Error e)
{
@@ -1203,15 +1451,15 @@ public class UserInterface
}
}
- [CCode (cname = "G_MODULE_EXPORT help_contents_menuitem_activate_cb", instance_pos = -1)]
- public void help_contents_menuitem_activate_cb (Gtk.Widget widget)
+ [GtkCallback]
+ private void help_contents_menuitem_activate_cb (Gtk.Widget widget)
{
- show_help ();
+ launch_help ();
}
public void help_contents_activate_cb ()
{
- show_help ();
+ launch_help ();
}
private void show_about ()
@@ -1227,7 +1475,7 @@ public class UserInterface
/* Description of program */
string description = _("Simple document scanning tool");
- Gtk.show_about_dialog (window,
+ Gtk.show_about_dialog (this,
"title", title,
"program-name", "Simple Scan",
"version", VERSION,
@@ -1242,8 +1490,8 @@ public class UserInterface
null);
}
- [CCode (cname = "G_MODULE_EXPORT about_menuitem_activate_cb", instance_pos = -1)]
- public void about_menuitem_activate_cb (Gtk.Widget widget)
+ [GtkCallback]
+ private void about_menuitem_activate_cb (Gtk.Widget widget)
{
show_about ();
}
@@ -1261,7 +1509,7 @@ public class UserInterface
_("Quit without Saving")))
return false;
- window.destroy ();
+ destroy ();
if (save_state_timeout != 0)
save_state (true);
@@ -1271,8 +1519,8 @@ public class UserInterface
return true;
}
- [CCode (cname = "G_MODULE_EXPORT quit_menuitem_activate_cb", instance_pos = -1)]
- public void quit_menuitem_activate_cb (Gtk.Widget widget)
+ [GtkCallback]
+ private void quit_menuitem_activate_cb (Gtk.Widget widget)
{
on_quit ();
}
@@ -1282,8 +1530,8 @@ public class UserInterface
on_quit ();
}
- [CCode (cname = "G_MODULE_EXPORT simple_scan_window_configure_event_cb", instance_pos = -1)]
- public bool simple_scan_window_configure_event_cb (Gtk.Widget widget, Gdk.EventConfigure event)
+ [GtkCallback]
+ private bool simple_scan_window_configure_event_cb (Gtk.Widget widget, Gdk.EventConfigure event)
{
if (!window_is_maximized)
{
@@ -1311,8 +1559,8 @@ public class UserInterface
}
}
- [CCode (cname = "G_MODULE_EXPORT simple_scan_window_window_state_event_cb", instance_pos = -1)]
- public bool simple_scan_window_window_state_event_cb (Gtk.Widget widget, Gdk.EventWindowState event)
+ [GtkCallback]
+ private bool simple_scan_window_window_state_event_cb (Gtk.Widget widget, Gdk.EventWindowState event)
{
if ((event.changed_mask & Gdk.WindowState.MAXIMIZED) != 0)
{
@@ -1322,8 +1570,8 @@ public class UserInterface
return false;
}
- [CCode (cname = "G_MODULE_EXPORT window_delete_event_cb", instance_pos = -1)]
- public bool window_delete_event_cb (Gtk.Widget widget, Gdk.Event event)
+ [GtkCallback]
+ private bool window_delete_event_cb (Gtk.Widget widget, Gdk.EventAny event)
{
return !on_quit ();
}
@@ -1352,6 +1600,11 @@ public class UserInterface
update_page_menu ();
}
+ private void reordered_cb (Book book)
+ {
+ update_page_menu ();
+ }
+
private void page_removed_cb (Book book, Page page)
{
page.size_changed.disconnect (page_size_changed_cb);
@@ -1370,7 +1623,7 @@ public class UserInterface
combo.pack_start (renderer, true);
combo.add_attribute (renderer, "text", 1);
- var model = (Gtk.ListStore) combo.get_model ();
+ var model = combo.model as Gtk.ListStore;
int[] scan_resolutions = {75, 150, 300, 600, 1200, 2400};
foreach (var dpi in scan_resolutions)
{
@@ -1399,27 +1652,22 @@ public class UserInterface
private void needs_saving_cb (Book book)
{
- save_menuitem.set_sensitive (book.needs_saving);
- save_toolbutton.set_sensitive (book.needs_saving);
+ 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.set_sensitive (true);
- copy_to_clipboard_menuitem.set_sensitive (true);
+ save_as_menuitem.sensitive = true;
+ copy_to_clipboard_menuitem.sensitive = true;
}
- private bool has_app_menu (Gtk.Application app)
+ private bool shell_shows_menubar
{
- /* We have three cases:
- * - GNOME 3: show-app-menu true, show-menubar false -> use the app menu
- * - Unity, OSX: show-app-menu and show-menubar true -> use the normal menu
- * - Other WM, Windows: show-app-menu and show-menubar false -> use the normal menu
- */
- var gtk_settings = Gtk.Settings.get_default ();
-
- bool show_app_menu = false;
- bool show_menubar = true;
- gtk_settings.get ("gtk-shell-shows-app-menu", &show_app_menu, "gtk-shell-shows-menubar", &show_menubar, null);
-
- return show_app_menu && !show_menubar;
+ get
+ {
+ bool shell_shows_menubar;
+ Gtk.Settings.get_default ().get ("gtk-shell-shows-menubar", out shell_shows_menubar);
+ return shell_shows_menubar;
+ }
}
private void load ()
@@ -1430,95 +1678,74 @@ public class UserInterface
var app = Application.get_default () as Gtk.Application;
- builder = new Gtk.Builder ();
- try
+ if (!shell_shows_menubar)
{
- builder.add_from_resource ("/org/gnome/SimpleScan/simple-scan.ui");
- if (has_app_menu (app))
- builder.add_from_resource ("/org/gnome/SimpleScan/simple-scan-menu.ui");
- }
- catch (Error e)
- {
- 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 */
- _("Please check your installation"));
- Posix.exit (Posix.EXIT_FAILURE);
- }
- builder.connect_signals (this);
+ app.add_action_entries (action_entries, this);
- window = (Gtk.ApplicationWindow) builder.get_object ("simple_scan_window");
- app.add_window (window);
- menubar = (Gtk.MenuBar) builder.get_object ("menubar");
- if (has_app_menu (app))
+ var appmenu = new Menu ();
+ var section = new Menu ();
+ appmenu.append_section (null, section);
+ section.append (_("New Document"), "app.new_document");
+
+ section = new Menu ();
+ appmenu.append_section (null, section);
+ var menu = new Menu ();
+ 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");
+
+ section = new Menu ();
+ appmenu.append_section (null, section);
+ section.append (_("Preferences"), "app.preferences");
+
+ section = new Menu ();
+ appmenu.append_section (null, section);
+ section.append (_("Help"), "app.help");
+ section.append (_("About"), "app.about");
+ section.append (_("Quit"), "app.quit");
+
+ app.app_menu = appmenu;
+
+ 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);
+ app.add_accelerator ("<Ctrl>Q", "app.quit", null);
+ }
+ else
{
- app_menu = (GLib.MenuModel) builder.get_object ("appmenu");
- app.add_action_entries (action_entries, this);
- app.set_app_menu (app_menu);
- menubar.set_visible(false);
+ set_titlebar (null);
+ menubar.visible = true;
+ toolbar.visible = true;
}
- main_vbox = (Gtk.Box) builder.get_object ("main_vbox");
- page_move_left_menuitem = (Gtk.MenuItem) builder.get_object ("page_move_left_menuitem");
- page_move_right_menuitem = (Gtk.MenuItem) builder.get_object ("page_move_right_menuitem");
- page_delete_menuitem = (Gtk.MenuItem) builder.get_object ("page_delete_menuitem");
- 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");
-
- text_toolbar_menuitem = (Gtk.RadioMenuItem) builder.get_object ("text_toolbutton_menuitem");
- text_menu_menuitem = (Gtk.RadioMenuItem) builder.get_object ("text_menuitem");
- photo_toolbar_menuitem = (Gtk.RadioMenuItem) builder.get_object ("photo_toolbutton_menuitem");
- photo_menu_menuitem = (Gtk.RadioMenuItem) builder.get_object ("photo_menuitem");
-
- authorize_dialog = (Gtk.Dialog) builder.get_object ("authorize_dialog");
- authorize_label = (Gtk.Label) builder.get_object ("authorize_label");
- username_entry = (Gtk.Entry) builder.get_object ("username_entry");
- password_entry = (Gtk.Entry) builder.get_object ("password_entry");
-
- preferences_dialog = (Gtk.Dialog) builder.get_object ("preferences_dialog");
- device_combo = (Gtk.ComboBox) builder.get_object ("device_combo");
- device_model = (Gtk.ListStore) device_combo.get_model ();
- text_dpi_combo = (Gtk.ComboBox) builder.get_object ("text_dpi_combo");
- text_dpi_model = (Gtk.ListStore) text_dpi_combo.get_model ();
- photo_dpi_combo = (Gtk.ComboBox) builder.get_object ("photo_dpi_combo");
- photo_dpi_model = (Gtk.ListStore) photo_dpi_combo.get_model ();
- page_side_combo = (Gtk.ComboBox) builder.get_object ("page_side_combo");
- 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 ();
+ app.add_window (this);
/* Add InfoBar (not supported in Glade) */
info_bar = new Gtk.InfoBar ();
info_bar.response.connect (info_bar_response_cb);
main_vbox.pack_start (info_bar, false, true, 0);
var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 12);
- var content_area = (Gtk.Container) info_bar.get_content_area ();
+ var content_area = info_bar.get_content_area () as Gtk.Container;
content_area.add (hbox);
- hbox.show ();
+ hbox.visible = true;
info_bar_image = new Gtk.Image.from_icon_name ("dialog-warning", Gtk.IconSize.DIALOG);
hbox.pack_start (info_bar_image, false, true, 0);
- info_bar_image.show ();
+ info_bar_image.visible = true;
info_bar_label = new Gtk.Label (null);
info_bar_label.set_alignment (0.0f, 0.5f);
hbox.pack_start (info_bar_label, true, true, 0);
- info_bar_label.show ();
+ info_bar_label.visible = true;
- info_bar_close_button = (Gtk.Button) info_bar.add_button (_("_Close"), Gtk.ResponseType.CLOSE);
- info_bar_change_scanner_button = (Gtk.Button) info_bar.add_button (/* Button in error infobar to open preferences dialog and change scanner */
- _("Change _Scanner"), 1);
+ info_bar_close_button = info_bar.add_button (_("_Close"), Gtk.ResponseType.CLOSE) as Gtk.Button;
+ info_bar_change_scanner_button = info_bar.add_button (/* Button in error infobar to open preferences dialog and change scanner */
+ _("Change _Scanner"), 1) as Gtk.Button;
Gtk.TreeIter iter;
paper_size_model.append (out iter);
@@ -1573,9 +1800,9 @@ public class UserInterface
settings.set_int ("paper-height", h);
});
- var lower = brightness_adjustment.get_lower ();
+ var lower = brightness_adjustment.lower;
var darker_label = "<small>%s</small>".printf (_("Darker"));
- var upper = brightness_adjustment.get_upper ();
+ var upper = brightness_adjustment.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);
@@ -1583,9 +1810,9 @@ public class UserInterface
brightness = settings.get_int ("brightness");
brightness_adjustment.value_changed.connect (() => { settings.set_int ("brightness", brightness); });
- lower = contrast_adjustment.get_lower ();
+ lower = contrast_adjustment.lower;
var less_label = "<small>%s</small>".printf (_("Less"));
- upper = contrast_adjustment.get_upper ();
+ upper = contrast_adjustment.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);
@@ -1593,9 +1820,9 @@ public class UserInterface
contrast = settings.get_int ("contrast");
contrast_adjustment.value_changed.connect (() => { settings.set_int ("contrast", contrast); });
- lower = quality_adjustment.get_lower ();
+ lower = quality_adjustment.lower;
var minimum_label = "<small>%s</small>".printf (_("Minimum"));
- upper = quality_adjustment.get_upper ();
+ upper = quality_adjustment.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);
@@ -1615,26 +1842,29 @@ public class UserInterface
set_document_hint (document_type);
book_view = new BookView (book);
- book_view.set_border_width (18);
+ book_view.border_width = 18;
main_vbox.pack_end (book_view, true, true, 0);
book_view.page_selected.connect (page_selected_cb);
book_view.show_page.connect (show_page_cb);
book_view.show_menu.connect (show_page_menu_cb);
- book_view.show ();
+ book_view.visible = true;
+
+ authorize_dialog.transient_for = this;
+ preferences_dialog.transient_for = this;
/* Load previous state */
load_state ();
/* Restore window size */
debug ("Restoring window to %dx%d pixels", window_width, window_height);
- window.set_default_size (window_width, window_height);
+ set_default_size (window_width, window_height);
if (window_is_maximized)
{
debug ("Restoring window to maximized");
- window.maximize ();
+ maximize ();
}
- progress_dialog = new ProgressBarDialog (window, _("Saving document..."));
+ progress_dialog = new ProgressBarDialog (this, _("Saving document..."));
book.saving.connect (book_saving_cb);
}
@@ -1780,24 +2010,24 @@ public class UserInterface
var fraction = (page_number + 1.0) / total;
var complete = fraction == 1.0;
if (complete)
- Timeout.add(500, () => {
- progress_dialog.hide();
+ Timeout.add (500, () => {
+ progress_dialog.visible = false;
return false;
});
var message = _("Saving page %d out of %d").printf (page_number + 1, total);
- progress_dialog.set_fraction (fraction);
- progress_dialog.set_message (message);
+ progress_dialog.fraction = fraction;
+ progress_dialog.message = message;
}
public void show_progress_dialog ()
{
- progress_dialog.show ();
+ progress_dialog.visible = true;
}
public void hide_progress_dialog ()
{
- progress_dialog.hide ();
+ progress_dialog.visible = false;
}
public void show_error (string error_title, string error_text, bool change_scanner_hint)
@@ -1811,49 +2041,51 @@ public class UserInterface
public void start ()
{
- window.show ();
+ visible = true;
}
}
-class ProgressBarDialog : Gtk.Window
+private class ProgressBarDialog : Gtk.Window
{
- Gtk.ProgressBar bar;
+ private Gtk.ProgressBar bar;
+
+ public double fraction
+ {
+ get { return bar.fraction; }
+ set { bar.fraction = value; }
+ }
+
+ public string message
+ {
+ get { return bar.text; }
+ set { bar.text = value; }
+ }
public ProgressBarDialog (Gtk.ApplicationWindow 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);
+ hbox.hexpand = true;
- bar.set_text ("");
- bar.set_show_text (true);
+ bar.text = "";
+ bar.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);
+ this.title = title;
- set_transient_for (parent);
+ transient_for = parent;
set_position (Gtk.WindowPosition.CENTER_ON_PARENT);
- set_modal (true);
- set_resizable (false);
-
- hbox.show ();
- vbox.show ();
- bar.show ();
- }
+ modal = true;
+ resizable = false;
- public void set_fraction (double percent)
- {
- bar.set_fraction (percent);
- }
-
- public void set_message (string message)
- {
- bar.set_text (message);
+ hbox.visible = true;
+ vbox.visible = true;
+ bar.visible = true;
}
}
@@ -1878,3 +2110,68 @@ private string? get_temporary_filename (string prefix, string extension)
return path;
}
+
+private class PageIcon : Gtk.DrawingArea
+{
+ private string text;
+ private double r;
+ private double g;
+ private double b;
+ private const int MINIMUM_WIDTH = 20;
+
+ public PageIcon (string text, double r = 1.0, double g = 1.0, double b = 1.0)
+ {
+ this.text = text;
+ this.r = r;
+ this.g = g;
+ this.b = b;
+ }
+
+ public override void get_preferred_width (out int minimum_width, out int natural_width)
+ {
+ minimum_width = natural_width = MINIMUM_WIDTH;
+ }
+
+ public override void get_preferred_height (out int minimum_height, out int natural_height)
+ {
+ minimum_height = natural_height = (int) Math.round (MINIMUM_WIDTH * Math.SQRT2);
+ }
+
+ public override void get_preferred_height_for_width (int width, out int minimum_height, out int natural_height)
+ {
+ minimum_height = natural_height = (int) (width * Math.SQRT2);
+ }
+
+ public override void get_preferred_width_for_height (int height, out int minimum_width, out int natural_width)
+ {
+ minimum_width = natural_width = (int) (height / Math.SQRT2);
+ }
+
+ public override bool draw (Cairo.Context c)
+ {
+ var w = get_allocated_width ();
+ var h = get_allocated_height ();
+ if (w * Math.SQRT2 > h)
+ w = (int) Math.round (h / Math.SQRT2);
+ else
+ h = (int) Math.round (w * Math.SQRT2);
+
+ c.translate ((get_allocated_width () - w) / 2, (get_allocated_height () - h) / 2);
+
+ c.rectangle (0.5, 0.5, w - 1, h - 1);
+
+ c.set_source_rgb (r, g, b);
+ c.fill_preserve ();
+
+ c.set_line_width (1.0);
+ c.set_source_rgb (0.0, 0.0, 0.0);
+ c.stroke ();
+
+ Cairo.TextExtents extents;
+ c.text_extents (text, out extents);
+ c.translate ((w - extents.width) * 0.5 - 0.5, (h + extents.height) * 0.5 - 0.5);
+ c.show_text (text);
+
+ return true;
+ }
+}