[simple-scan] Allow scan double side of single page if Flatbed is not found
- From: Bartosz <bkosiorek src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [simple-scan] Allow scan double side of single page if Flatbed is not found
- Date: Fri, 23 Apr 2021 18:04:56 +0000 (UTC)
commit 8b14b368415ce36cb3ed25bc31571349211785e9
Author: Bartosz Kosiorek <gang65 poczta onet pl>
Date: Tue Mar 30 15:56:17 2021 +0200
Allow scan double side of single page if Flatbed is not found
With previous implementation the Scan Single Page
was working only in case the Flatbed is detected.
It seems that for ADF only scanners, scanning Single Page
could be also useful. Unfortunately simple-scan is scanning
only front page. With this commit it is possible to scan
Single Page with both sides on ADF only scanner.
Fixes #188
src/app-window.vala | 10 +--
src/preferences-dialog.vala | 24 +++---
src/scanner.vala | 182 +++++++++++++++++++++++++++-----------------
3 files changed, 130 insertions(+), 86 deletions(-)
---
diff --git a/src/app-window.vala b/src/app-window.vala
index c4d0cb87..c1d4ea31 100644
--- a/src/app-window.vala
+++ b/src/app-window.vala
@@ -849,8 +849,7 @@ public class AppWindow : Hdy.ApplicationWindow
private void scan_adf_cb ()
{
var options = make_scan_options ();
- options.type = ScanType.ADF_BOTH;
- options.type = preferences_dialog.get_page_side ();
+ options.type = ScanType.ADF;
scan (options);
}
@@ -906,7 +905,7 @@ public class AppWindow : Hdy.ApplicationWindow
scan_single_radio.active = true;
scan_options_image.icon_name = "scanner-symbolic";
break;
- case ScanType.ADF_BOTH:
+ case ScanType.ADF:
scan_adf_radio.active = true;
scan_options_image.icon_name = "scan-type-adf-symbolic";
break;
@@ -928,7 +927,7 @@ public class AppWindow : Hdy.ApplicationWindow
private void scan_adf_radio_toggled_cb (Gtk.ToggleButton button)
{
if (button.active)
- set_scan_type (ScanType.ADF_BOTH);
+ set_scan_type (ScanType.ADF);
}
[GtkCallback]
@@ -996,6 +995,7 @@ public class AppWindow : Hdy.ApplicationWindow
options.brightness = brightness;
options.contrast = contrast;
options.page_delay = page_delay;
+ options.side = preferences_dialog.get_page_side ();
return options;
}
@@ -1017,8 +1017,6 @@ public class AppWindow : Hdy.ApplicationWindow
stop_button.visible = true;
var options = make_scan_options ();
options.type = scan_type;
- if (options.type == ScanType.ADF_BOTH)
- options.type = preferences_dialog.get_page_side ();
scan (options);
}
diff --git a/src/preferences-dialog.vala b/src/preferences-dialog.vala
index e10e1534..8d992abb 100644
--- a/src/preferences-dialog.vala
+++ b/src/preferences-dialog.vala
@@ -87,10 +87,10 @@ private class PreferencesDialog : Hdy.PreferencesWindow
set_dpi_combo (photo_dpi_combo, DEFAULT_PHOTO_DPI, dpi);
photo_dpi_combo.changed.connect (() => { settings.set_int ("photo-dpi", get_photo_dpi ()); });
- set_page_side ((ScanType) settings.get_enum ("page-side"));
- front_side_button.toggled.connect ((button) => { if (button.active) settings.set_enum ("page-side",
ScanType.ADF_FRONT); });
- 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); });
+ set_page_side ((ScanSide) settings.get_enum ("page-side"));
+ front_side_button.toggled.connect ((button) => { if (button.active) settings.set_enum ("page-side",
ScanSide.FRONT); });
+ back_side_button.toggled.connect ((button) => { if (button.active) settings.set_enum ("page-side",
ScanSide.BACK); });
+ both_side_button.toggled.connect ((button) => { if (button.active) settings.set_enum ("page-side",
ScanSide.BOTH); });
var renderer = new Gtk.CellRendererText ();
paper_size_combo.pack_start (renderer, true);
@@ -135,31 +135,31 @@ private class PreferencesDialog : Hdy.PreferencesWindow
page_delay_15s_button.toggled.connect ((button) => { if (button.active) settings.set_int
("page-delay", 15000); });
}
- private void set_page_side (ScanType page_side)
+ private void set_page_side (ScanSide page_side)
{
switch (page_side)
{
- case ScanType.ADF_FRONT:
+ case ScanSide.FRONT:
front_side_button.active = true;
break;
- case ScanType.ADF_BACK:
+ case ScanSide.BACK:
back_side_button.active = true;
break;
default:
- case ScanType.ADF_BOTH:
+ case ScanSide.BOTH:
both_side_button.active = true;
break;
}
}
- public ScanType get_page_side ()
+ public ScanSide get_page_side ()
{
if (front_side_button.active)
- return ScanType.ADF_FRONT;
+ return ScanSide.FRONT;
else if (back_side_button.active)
- return ScanType.ADF_BACK;
+ return ScanSide.BACK;
else
- return ScanType.ADF_BOTH;
+ return ScanSide.BOTH;
}
public void set_paper_size (int width, int height)
diff --git a/src/scanner.vala b/src/scanner.vala
index 6e165bad..71fe4c97 100644
--- a/src/scanner.vala
+++ b/src/scanner.vala
@@ -67,18 +67,24 @@ public enum ScanMode
public enum ScanType
{
SINGLE,
- ADF_FRONT,
- ADF_BACK,
- ADF_BOTH,
+ ADF,
BATCH
}
+public enum ScanSide
+{
+ FRONT,
+ BACK,
+ BOTH
+}
+
public class ScanOptions : Object
{
public int dpi;
public ScanMode scan_mode;
public int depth;
public ScanType type;
+ public ScanSide side;
public int paper_width;
public int paper_height;
public int brightness;
@@ -94,6 +100,7 @@ private class ScanJob : Object
public ScanMode scan_mode;
public int depth;
public ScanType type;
+ public ScanSide side;
public int page_width;
public int page_height;
public int brightness;
@@ -911,6 +918,62 @@ public class Scanner : Object
state = ScanState.GET_OPTION;
}
+ private void set_adf (ScanJob job, Sane.OptionDescriptor option, Sane.Int index)
+ {
+ string[] adf_sources =
+ {
+ "Automatic Document Feeder",
+ Sane.I18N ("Automatic Document Feeder"),
+ "ADF",
+ "Automatic Document Feeder(left aligned)", /* Seen in the proprietary brother3 driver */
+ "Automatic Document Feeder(centrally aligned)", /* Seen in the proprietary brother3 driver */
+ "ADF Simplex" /* Samsung unified driver. LP: # 892915 */
+ };
+
+ string[] adf_front_sources =
+ {
+ "ADF Front",
+ Sane.I18N ("ADF Front")
+ };
+
+ string[] adf_back_sources =
+ {
+ "ADF Back",
+ Sane.I18N ("ADF Back")
+ };
+
+ string[] adf_duplex_sources =
+ {
+ "ADF Duplex",
+ "Duplex ADF", /* Brother DS-720, #157 */
+ Sane.I18N ("ADF Duplex"),
+ "ADF Duplex - Long-Edge Binding", /* Samsung unified driver. LP: # 892915 */
+ "ADF Duplex - Short-Edge Binding",
+ "Duplex", /* HP duplex scan support. LP: #1353599 */
+ "Automatic Document Feeder(centrally aligned,Duplex)", /* Brother duplex scan support. LP:
#1343773 */
+ "Automatic Document Feeder(left aligned,Duplex)"
+ };
+
+ if (job.side == ScanSide.FRONT)
+ {
+ if (!set_constrained_string_option (handle, option, index, adf_front_sources, null))
+ if (!set_constrained_string_option (handle, option, index, adf_sources, null))
+ warning ("Unable to set front ADF source, please file a bug");
+ }
+ else if (job.side == ScanSide.BACK)
+ {
+ if (!set_constrained_string_option (handle, option, index, adf_back_sources, null))
+ if (!set_constrained_string_option (handle, option, index, adf_sources, null))
+ warning ("Unable to set back ADF source, please file a bug");
+ }
+ else if (job.side == ScanSide.BOTH)
+ {
+ if (!set_constrained_string_option (handle, option, index, adf_duplex_sources, null))
+ if (!set_constrained_string_option (handle, option, index, adf_sources, null))
+ warning ("Unable to set duplex ADF source, please file a bug");
+ }
+ }
+
private void do_get_option ()
{
var job = (ScanJob) job_queue.data;
@@ -943,62 +1006,20 @@ public class Scanner : Object
"Document Table" /* Epson scanners, eg. ET-3760 */
};
- string[] adf_sources =
- {
- "Automatic Document Feeder",
- Sane.I18N ("Automatic Document Feeder"),
- "ADF",
- "Automatic Document Feeder(left aligned)", /* Seen in the proprietary brother3 driver */
- "Automatic Document Feeder(centrally aligned)", /* Seen in the proprietary brother3
driver */
- "ADF Simplex" /* Samsung unified driver. LP: # 892915 */
- };
-
- string[] adf_front_sources =
- {
- "ADF Front",
- Sane.I18N ("ADF Front")
- };
-
- string[] adf_back_sources =
- {
- "ADF Back",
- Sane.I18N ("ADF Back")
- };
-
- string[] adf_duplex_sources =
- {
- "ADF Duplex",
- "Duplex ADF", /* Brother DS-720, #157 */
- Sane.I18N ("ADF Duplex"),
- "ADF Duplex - Long-Edge Binding", /* Samsung unified driver. LP: # 892915 */
- "ADF Duplex - Short-Edge Binding",
- "Duplex", /* HP duplex scan support. LP: #1353599 */
- "Automatic Document Feeder(centrally aligned,Duplex)", /* Brother duplex scan support.
LP: #1343773 */
- "Automatic Document Feeder(left aligned,Duplex)"
- };
-
switch (job.type)
{
case ScanType.SINGLE:
case ScanType.BATCH:
if (!set_default_option (handle, option, index))
if (!set_constrained_string_option (handle, option, index, flatbed_sources, null))
- warning ("Unable to set single page source, please file a bug");
- break;
- case ScanType.ADF_FRONT:
- if (!set_constrained_string_option (handle, option, index, adf_front_sources, null))
- if (!set_constrained_string_option (handle, option, index, adf_sources, null))
- warning ("Unable to set front ADF source, please file a bug");
+ {
+ warning ("Unable to set single page source, trying to set ADF instead");
+ warning ("If Flatbed is existing and it is not set, please file a bug");
+ set_adf (job, option, index);
+ }
break;
- case ScanType.ADF_BACK:
- if (!set_constrained_string_option (handle, option, index, adf_back_sources, null))
- if (!set_constrained_string_option (handle, option, index, adf_sources, null))
- warning ("Unable to set back ADF source, please file a bug");
- break;
- case ScanType.ADF_BOTH:
- if (!set_constrained_string_option (handle, option, index, adf_duplex_sources, null))
- if (!set_constrained_string_option (handle, option, index, adf_sources, null))
- warning ("Unable to set duplex ADF source, please file a bug");
+ case ScanType.ADF:
+ set_adf (job, option, index);
break;
}
}
@@ -1076,7 +1097,7 @@ public class Scanner : Object
if (option != null)
{
if (option.type == Sane.ValueType.BOOL)
- set_bool_option (handle, option, index, job.type == ScanType.ADF_BOTH, null);
+ set_bool_option (handle, option, index, job.side == ScanSide.BOTH, null);
}
/* Non-standard Epson GT-S50 ADF options */
@@ -1091,7 +1112,7 @@ public class Scanner : Object
{
"Duplex"
};
- if (job.type == ScanType.ADF_BOTH)
+ if (job.side == ScanSide.BOTH)
set_constrained_string_option (handle, option, index, adf_duplex_modes, null);
else
set_constrained_string_option (handle, option, index, adf_simplex_modes, null);
@@ -1668,12 +1689,8 @@ public class Scanner : Object
return "single";
case ScanType.BATCH:
return "batch";
- case ScanType.ADF_FRONT:
- return "adf-front";
- case ScanType.ADF_BACK:
- return "adf-back";
- case ScanType.ADF_BOTH:
- return "adf-both";
+ case ScanType.ADF:
+ return "adf";
default:
return "%d".printf (type);
}
@@ -1687,23 +1704,51 @@ public class Scanner : Object
return ScanType.SINGLE;
case "batch":
return ScanType.BATCH;
- case "adf-front":
- return ScanType.ADF_FRONT;
- case "adf-back":
- return ScanType.ADF_BACK;
- case "adf-both":
- return ScanType.ADF_BOTH;
+ case "adf":
+ return ScanType.ADF;
default:
warning ("Unknown ScanType: %s. Please report this error.", type);
return ScanType.SINGLE;
}
}
+ public static string side_to_string (ScanSide side)
+ {
+ switch (side)
+ {
+ case ScanSide.FRONT:
+ return "front";
+ case ScanSide.BACK:
+ return "back";
+ case ScanSide.BOTH:
+ return "both";
+ default:
+ return "%d".printf (side);
+ }
+ }
+
+ public static ScanSide side_from_string (string side)
+ {
+ switch (side)
+ {
+ case "front":
+ return ScanSide.FRONT;
+ case "back":
+ return ScanSide.BACK;
+ case "both":
+ return ScanSide.BOTH;
+ default:
+ warning ("Unknown ScanSide: %s. Please report this error.", side);
+ return ScanSide.FRONT;
+ }
+ }
+
public void scan (string? device, ScanOptions options)
{
- debug ("Scanner.scan (\"%s\", dpi=%d, scan_mode=%s, depth=%d, type=%s, paper_width=%d,
paper_height=%d, brightness=%d, contrast=%d, delay=%dms)",
+ debug ("Scanner.scan (\"%s\", dpi=%d, scan_mode=%s, depth=%d, type=%s, side=%s, paper_width=%d,
paper_height=%d, brightness=%d, contrast=%d, delay=%dms)",
device != null ? device : "(null)", options.dpi, get_scan_mode_string (options.scan_mode),
options.depth,
- type_to_string (options.type), options.paper_width, options.paper_height,
+ type_to_string (options.type), side_to_string (options.side),
+ options.paper_width, options.paper_height,
options.brightness, options.contrast, options.page_delay);
var request = new RequestStartScan ();
request.job = new ScanJob ();
@@ -1713,6 +1758,7 @@ public class Scanner : Object
request.job.scan_mode = options.scan_mode;
request.job.depth = options.depth;
request.job.type = options.type;
+ request.job.side = options.side;
request.job.page_width = options.paper_width;
request.job.page_height = options.paper_height;
request.job.brightness = options.brightness;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]