[simple-scan] Remember last Scan type between runs.
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [simple-scan] Remember last Scan type between runs.
- Date: Tue, 10 Dec 2019 03:45:51 +0000 (UTC)
commit e135ee8d4f12073e454bdebc637eb19c11889fc1
Author: Bartosz Kosiorek <gang65 poczta onet pl>
Date: Sat Nov 30 19:28:22 2019 +0100
Remember last Scan type between runs.
Fixes: #45
Fixes: #77
src/app-window.vala | 15 +++++++++++++++
src/scanner.vala | 36 ++++++++++++++++++++++++++++--------
2 files changed, 43 insertions(+), 8 deletions(-)
---
diff --git a/src/app-window.vala b/src/app-window.vala
index 18d6b2d..c82090a 100644
--- a/src/app-window.vala
+++ b/src/app-window.vala
@@ -1882,6 +1882,20 @@ public class AppWindow : Gtk.ApplicationWindow
window_height = 400;
window_is_maximized = state_get_boolean (f, "window", "is-maximized");
window_is_fullscreen = state_get_boolean (f, "window", "is-fullscreen");
+ scan_type = Scanner.type_from_string(state_get_string (f, "scanner", "scan-type", "single"));
+ set_scan_type (scan_type);
+ }
+
+ private string state_get_string (KeyFile f, string group_name, string key, string default)
+ {
+ try
+ {
+ return f.get_string (group_name, key);
+ }
+ catch
+ {
+ return default;
+ }
}
private int state_get_integer (KeyFile f, string group_name, string key, int default = 0)
@@ -1930,6 +1944,7 @@ public class AppWindow : Gtk.ApplicationWindow
f.set_integer ("window", "height", window_height);
f.set_boolean ("window", "is-maximized", window_is_maximized);
f.set_boolean ("window", "is-fullscreen", window_is_fullscreen);
+ f.set_string ("scanner", "scan-type", Scanner.type_to_string(scan_type));
try
{
FileUtils.set_contents (state_filename, f.to_data ());
diff --git a/src/scanner.vala b/src/scanner.vala
index cebc85e..66a20c0 100644
--- a/src/scanner.vala
+++ b/src/scanner.vala
@@ -1587,30 +1587,50 @@ public class Scanner : Object
}
}
- private string get_scan_type_string (ScanType type)
+ public static string type_to_string (ScanType type)
{
switch (type)
{
case ScanType.SINGLE:
- return "ScanType.SINGLE";
+ return "single";
+ case ScanType.BATCH:
+ return "batch";
case ScanType.ADF_FRONT:
- return "ScanType.ADF_FRONT";
+ return "adf-front";
case ScanType.ADF_BACK:
- return "ScanType.ADF_BACK";
+ return "adf-back";
case ScanType.ADF_BOTH:
- return "ScanType.ADF_BOTH";
- case ScanType.BATCH:
- return "ScanType.BATCH";
+ return "adf-both";
default:
return "%d".printf (type);
}
}
+ public static ScanType type_from_string (string type)
+ {
+ switch (type)
+ {
+ case "single":
+ 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;
+ default:
+ warning ("Unknown ScanType: %s. Please report this error.", type);
+ return ScanType.SINGLE;
+ }
+ }
+
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)",
device != null ? device : "(null)", options.dpi, get_scan_mode_string (options.scan_mode),
options.depth,
- get_scan_type_string (options.type), options.paper_width, options.paper_height,
+ type_to_string (options.type), options.paper_width, options.paper_height,
options.brightness, options.contrast, options.page_delay);
var request = new RequestStartScan ();
request.job = new ScanJob ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]