[simple-scan] Move the scanner selection combo from preferences to the home page.
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [simple-scan] Move the scanner selection combo from preferences to the home page.
- Date: Tue, 3 Dec 2019 22:21:34 +0000 (UTC)
commit 64231a3b3a2a7c6890bbba9930c108630cdde730
Author: Robert Ancell <robert ancell canonical com>
Date: Tue Jul 23 10:40:44 2019 +1200
Move the scanner selection combo from preferences to the home page.
This is a more obvious place to select the scanner to use for the next scan.
Fixes #93
src/app-window.ui | 15 ++++
src/app-window.vala | 180 +++++++++++++++++++++++++++++++++++++++++---
src/preferences-dialog.ui | 45 +----------
src/preferences-dialog.vala | 164 +---------------------------------------
src/simple-scan.vala | 2 +-
5 files changed, 190 insertions(+), 216 deletions(-)
---
diff --git a/src/app-window.ui b/src/app-window.ui
index a41216b..b1a1cad 100644
--- a/src/app-window.ui
+++ b/src/app-window.ui
@@ -197,6 +197,14 @@
</object>
</child>
</object>
+ <object class="GtkListStore" id="device_model">
+ <columns>
+ <!-- column-name device_name -->
+ <column type="gchararray"/>
+ <!-- column-name label -->
+ <column type="gchararray"/>
+ </columns>
+ </object>
<object class="GtkPopover" id="scan_options_popover">
<property name="can_focus">False</property>
<child>
@@ -780,6 +788,13 @@
<property name="position">2</property>
</packing>
</child>
+ <child>
+ <object class="GtkComboBox" id="device_combo">
+ <property name="visible">False</property>
+ <property name="model">device_model</property>
+ <signal name="changed" handler="device_combo_changed_cb" swapped="no"/>
+ </object>
+ </child>
</object>
</child>
</object>
diff --git a/src/app-window.vala b/src/app-window.vala
index a22a3b0..aaa663c 100644
--- a/src/app-window.vala
+++ b/src/app-window.vala
@@ -38,6 +38,9 @@ public class AppWindow : Gtk.ApplicationWindow
private PreferencesDialog preferences_dialog;
+ private bool setting_devices;
+ private bool user_selected_device;
+
[GtkChild]
private Gtk.HeaderBar header_bar;
[GtkChild]
@@ -47,6 +50,10 @@ public class AppWindow : Gtk.ApplicationWindow
[GtkChild]
private Gtk.Label status_primary_label;
[GtkChild]
+ private Gtk.ListStore device_model;
+ [GtkChild]
+ private Gtk.ComboBox device_combo;
+ [GtkChild]
private Gtk.Label status_secondary_label;
[GtkChild]
private Gtk.Box main_vbox;
@@ -173,12 +180,6 @@ public class AppWindow : Gtk.ApplicationWindow
set { preferences_dialog.set_page_delay (value); }
}
- public string? selected_device
- {
- owned get { return preferences_dialog.get_selected_device (); }
- set { preferences_dialog.set_selected_device (value); }
- }
-
public signal void start_scan (string? device, ScanOptions options);
public signal void stop_scan ();
@@ -186,6 +187,11 @@ public class AppWindow : Gtk.ApplicationWindow
{
settings = new Settings ("org.gnome.SimpleScan");
+ var renderer = new Gtk.CellRendererText ();
+ renderer.set_property ("xalign", 0.5);
+ device_combo.pack_start (renderer, true);
+ device_combo.add_attribute (renderer, "text", 1);
+
book = new Book ();
book.page_added.connect (page_added_cb);
book.reordered.connect (reordered_cb);
@@ -238,13 +244,15 @@ public class AppWindow : Gtk.ApplicationWindow
status_primary_label.set_text (/* Label shown when searching for scanners */
_("Searching for Scanners…"));
status_secondary_label.visible = false;
+ device_combo.visible = false;
}
- else if (selected_device != null)
+ else if (get_selected_device () != null)
{
status_primary_label.set_text (/* Label shown when detected a scanner */
_("Ready to Scan"));
- status_secondary_label.set_text (preferences_dialog.get_selected_device_label ());
- status_secondary_label.visible = true;
+ status_secondary_label.set_text (get_selected_device_label ());
+ status_secondary_label.visible = false;
+ device_combo.visible = true;
}
else if (this.missing_driver != null)
{
@@ -253,6 +261,7 @@ public class AppWindow : Gtk.ApplicationWindow
/* Instructions to install driver software */
status_secondary_label.set_markup (_("You need to <a href=\"install-firmware\">install driver
software</a> for your scanner."));
status_secondary_label.visible = true;
+ device_combo.visible = false;
}
else
{
@@ -261,6 +270,7 @@ public class AppWindow : Gtk.ApplicationWindow
/* Hint to user on why there are no scanners detected */
status_secondary_label.set_text (_("Please check your scanner is connected and powered on"));
status_secondary_label.visible = true;
+ device_combo.visible = false;
}
}
@@ -268,7 +278,88 @@ public class AppWindow : Gtk.ApplicationWindow
{
have_devices = true;
this.missing_driver = missing_driver;
- preferences_dialog.set_scan_devices (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;
+
update_scan_status ();
}
@@ -286,6 +377,63 @@ public class AppWindow : Gtk.ApplicationWindow
return response == Gtk.ResponseType.YES;
}
+ private 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;
+ }
+
+ private 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 string? choose_file_location ()
{
/* Get directory to save to */
@@ -621,7 +769,7 @@ public class AppWindow : Gtk.ApplicationWindow
{
status_primary_label.set_text (/* Label shown when scan started */
_("Contacting scanner…"));
- start_scan (selected_device, options);
+ start_scan (get_selected_device (), options);
}
private void scan_single_cb ()
@@ -755,6 +903,16 @@ public class AppWindow : Gtk.ApplicationWindow
return options;
}
+ [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 ());
+ }
+
[GtkCallback]
private void scan_button_clicked_cb (Gtk.Widget widget)
{
diff --git a/src/preferences-dialog.ui b/src/preferences-dialog.ui
index 75d8a4c..de791cb 100644
--- a/src/preferences-dialog.ui
+++ b/src/preferences-dialog.ui
@@ -14,14 +14,6 @@
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
- <object class="GtkListStore" id="device_model">
- <columns>
- <!-- column-name device_name -->
- <column type="gchararray"/>
- <!-- column-name label -->
- <column type="gchararray"/>
- </columns>
- </object>
<object class="GtkListStore" id="paper_size_model">
<columns>
<!-- column-name width -->
@@ -74,34 +66,6 @@
<property name="visible">True</property>
<property name="row_spacing">15</property>
<property name="column_spacing">10</property>
- <child>
- <object class="GtkLabel" id="source_label">
- <property name="visible">True</property>
- <property name="label" translatable="yes" comments="Label beside scan source combo
box">_Scanner</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">device_combo</property>
- <property name="xalign">1</property>
- <style>
- <class name="dim-label"/>
- </style>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkComboBox" id="device_combo">
- <property name="visible">True</property>
- <property name="hexpand">True</property>
- <property name="model">device_model</property>
- <signal name="changed" handler="device_combo_changed_cb" swapped="no"/>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">0</property>
- </packing>
- </child>
<child>
<object class="GtkLabel" id="page_side_label">
<property name="visible">True</property>
@@ -115,7 +79,7 @@
</object>
<packing>
<property name="left_attach">0</property>
- <property name="top_attach">1</property>
+ <property name="top_attach">0</property>
</packing>
</child>
<child>
@@ -130,7 +94,7 @@
</object>
<packing>
<property name="left_attach">0</property>
- <property name="top_attach">2</property>
+ <property name="top_attach">1</property>
</packing>
</child>
<child>
@@ -141,7 +105,7 @@
</object>
<packing>
<property name="left_attach">1</property>
- <property name="top_attach">2</property>
+ <property name="top_attach">1</property>
</packing>
</child>
<child>
@@ -184,7 +148,7 @@
</object>
<packing>
<property name="left_attach">1</property>
- <property name="top_attach">1</property>
+ <property name="top_attach">0</property>
</packing>
</child>
</object>
@@ -471,7 +435,6 @@
</template>
<object class="GtkSizeGroup" id="label_size_group">
<widgets>
- <widget name="source_label"/>
<widget name="page_side_label"/>
<widget name="paper_size_label"/>
<widget name="page_delay_label"/>
diff --git a/src/preferences-dialog.vala b/src/preferences-dialog.vala
index 1533541..8ea9693 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,16 +301,6 @@ 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
diff --git a/src/simple-scan.vala b/src/simple-scan.vala
index 6e5e318..f41ba93 100644
--- a/src/simple-scan.vala
+++ b/src/simple-scan.vala
@@ -83,7 +83,7 @@ public class SimpleScan : Gtk.Application
device_list.append (default_device);
app.set_scan_devices (device_list);
- app.selected_device = default_device.name;
+ app.set_selected_device (default_device.name);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]