summaryrefslogtreecommitdiff
path: root/src/preferences-dialog.vala
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2020-03-22 17:06:19 +0100
committerJörg Frings-Fürst <debian@jff.email>2020-03-22 17:06:19 +0100
commit36ea9e0aa630a76096d25fedbf6abf5c0463cfda (patch)
treeeaaa24afe631aaee5c974eae548f6a0d52ad9677 /src/preferences-dialog.vala
parent269974bfb404016bd592358df7b43f8ece82ddc9 (diff)
parent7ac7082eb0fa3735eb23acf72dbe607217a358c2 (diff)
Merge branch 'feature/upstrem' into develop
Diffstat (limited to 'src/preferences-dialog.vala')
-rw-r--r--src/preferences-dialog.vala229
1 files changed, 1 insertions, 228 deletions
diff --git a/src/preferences-dialog.vala b/src/preferences-dialog.vala
index 1533541..06dca75 100644
--- a/src/preferences-dialog.vala
+++ b/src/preferences-dialog.vala
@@ -15,11 +15,6 @@ private class PreferencesDialog : Gtk.Dialog
{
private Settings settings;
- private bool setting_devices;
- private bool user_selected_device;
-
- [GtkChild]
- private Gtk.ComboBox device_combo;
[GtkChild]
private Gtk.ComboBox text_dpi_combo;
[GtkChild]
@@ -31,8 +26,6 @@ private class PreferencesDialog : Gtk.Dialog
[GtkChild]
private Gtk.Scale contrast_scale;
[GtkChild]
- private Gtk.ListStore device_model;
- [GtkChild]
private Gtk.RadioButton page_delay_3s_button;
[GtkChild]
private Gtk.RadioButton page_delay_5s_button;
@@ -85,10 +78,6 @@ private class PreferencesDialog : Gtk.Dialog
paper_size_model.append (out iter);
paper_size_model.set (iter, 0, 1016, 1, 1524, 2, "4×6", -1);
- var renderer = new Gtk.CellRendererText ();
- device_combo.pack_start (renderer, true);
- device_combo.add_attribute (renderer, "text", 1);
-
var dpi = settings.get_int ("text-dpi");
if (dpi <= 0)
dpi = DEFAULT_TEXT_DPI;
@@ -105,7 +94,7 @@ private class PreferencesDialog : Gtk.Dialog
back_side_button.toggled.connect ((button) => { if (button.active) settings.set_enum ("page-side", ScanType.ADF_BACK); });
both_side_button.toggled.connect ((button) => { if (button.active) settings.set_enum ("page-side", ScanType.ADF_BOTH); });
- renderer = new Gtk.CellRendererText ();
+ var renderer = new Gtk.CellRendererText ();
paper_size_combo.pack_start (renderer, true);
paper_size_combo.add_attribute (renderer, "text", 2);
@@ -148,147 +137,6 @@ private class PreferencesDialog : Gtk.Dialog
page_delay_15s_button.toggled.connect ((button) => { if (button.active) settings.set_int ("page-delay", 15000); });
}
- public void set_scan_devices (List<ScanDevice> devices)
- {
- setting_devices = true;
-
- /* If the user hasn't chosen a scanner choose the best available one */
- var have_selection = false;
- if (user_selected_device)
- have_selection = device_combo.active >= 0;
-
- /* Add new devices */
- int index = 0;
- Gtk.TreeIter iter;
- foreach (var device in devices)
- {
- int n_delete = -1;
-
- /* Find if already exists */
- if (device_model.iter_nth_child (out iter, null, index))
- {
- int i = 0;
- do
- {
- string name;
- bool matched;
-
- device_model.get (iter, 0, out name, -1);
- matched = name == device.name;
-
- if (matched)
- {
- n_delete = i;
- break;
- }
- i++;
- } while (device_model.iter_next (ref iter));
- }
-
- /* If exists, remove elements up to this one */
- if (n_delete >= 0)
- {
- int i;
-
- /* Update label */
- device_model.set (iter, 1, device.label, -1);
-
- for (i = 0; i < n_delete; i++)
- {
- device_model.iter_nth_child (out iter, null, index);
-#if VALA_0_36
- device_model.remove (ref iter);
-#else
- device_model.remove (iter);
-#endif
- }
- }
- else
- {
- device_model.insert (out iter, index);
- device_model.set (iter, 0, device.name, 1, device.label, -1);
- }
- index++;
- }
-
- /* Remove any remaining devices */
- while (device_model.iter_nth_child (out iter, null, index))
-#if VALA_0_36
- device_model.remove (ref iter);
-#else
- device_model.remove (iter);
-#endif
-
- /* Select the previously selected device or the first available device */
- if (!have_selection)
- {
- var device = settings.get_string ("selected-device");
- if (device != null && find_scan_device (device, out iter))
- device_combo.set_active_iter (iter);
- else
- device_combo.set_active (0);
- }
-
- setting_devices = false;
- }
-
- public string? get_selected_device ()
- {
- Gtk.TreeIter iter;
-
- if (device_combo.get_active_iter (out iter))
- {
- string device;
- device_model.get (iter, 0, out device, -1);
- return device;
- }
-
- return null;
- }
-
- public string? get_selected_device_label ()
- {
- Gtk.TreeIter iter;
-
- if (device_combo.get_active_iter (out iter))
- {
- string label;
- device_model.get (iter, 1, out label, -1);
- return label;
- }
-
- return null;
- }
-
- public void set_selected_device (string device)
- {
- user_selected_device = true;
-
- Gtk.TreeIter iter;
- if (!find_scan_device (device, out iter))
- return;
-
- device_combo.set_active_iter (iter);
- }
-
- private bool find_scan_device (string device, out Gtk.TreeIter iter)
- {
- bool have_iter = false;
-
- if (device_model.get_iter_first (out iter))
- {
- do
- {
- string d;
- device_model.get (iter, 0, out d, -1);
- if (d == device)
- have_iter = true;
- } while (!have_iter && device_model.iter_next (ref iter));
- }
-
- return have_iter;
- }
-
private void set_page_side (ScanType page_side)
{
switch (page_side)
@@ -453,79 +301,4 @@ private class PreferencesDialog : Gtk.Dialog
combo.set_active_iter (iter);
}
}
-
- [GtkCallback]
- private void device_combo_changed_cb (Gtk.Widget widget)
- {
- if (setting_devices)
- return;
- user_selected_device = true;
- if (get_selected_device () != null)
- settings.set_string ("selected-device", get_selected_device ());
- }
-}
-
-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;
- }
}