summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/book.c1
-rw-r--r--src/scanner.c48
-rw-r--r--src/simple-scan.c45
-rw-r--r--src/ui.c15
4 files changed, 78 insertions, 31 deletions
diff --git a/src/book.c b/src/book.c
index 6bf4d0a..036d133 100644
--- a/src/book.c
+++ b/src/book.c
@@ -321,6 +321,7 @@ book_save_pdf_with_imagemagick (Book *book, GFile *file, GError **error)
g_warning ("stdout: %s", stdout_text);
g_warning ("stderr: %s", stderr_text);
result = FALSE;
+ g_set_error (error, BOOK_TYPE, 0, "ImageMagick returned error code %d, command line was: %s", exit_status, command_line->str);
}
g_free (stdout_text);
g_free (stderr_text);
diff --git a/src/scanner.c b/src/scanner.c
index daf1b15..9181868 100644
--- a/src/scanner.c
+++ b/src/scanner.c
@@ -99,6 +99,9 @@ struct ScannerPrivate
/* Last option read */
SANE_Int option_index;
+
+ /* Option index for scan area */
+ SANE_Int br_x_option_index, br_y_option_index;
/* Buffer for received line */
SANE_Byte *buffer;
@@ -869,6 +872,8 @@ do_open (Scanner *scanner)
scanner->priv->page_number = 0;
scanner->priv->notified_page = -1;
scanner->priv->option_index = 0;
+ scanner->priv->br_x_option_index = 0;
+ scanner->priv->br_y_option_index = 0;
if (!job->device && scanner->priv->default_device)
job->device = g_strdup (scanner->priv->default_device);
@@ -919,7 +924,7 @@ do_get_option (Scanner *scanner)
const SANE_Option_Descriptor *option;
SANE_Int option_index;
ScanJob *job;
-
+
job = (ScanJob *) scanner->priv->job_queue->data;
option = sane_get_option_descriptor (scanner->priv->handle, scanner->priv->option_index);
@@ -928,6 +933,28 @@ do_get_option (Scanner *scanner)
scanner->priv->option_index++;
if (!option) {
+ /* Always use maximum scan area - some scanners default to using partial areas. This should be patched in sane-backends */
+ if (scanner->priv->br_x_option_index) {
+ option = sane_get_option_descriptor (scanner->priv->handle, scanner->priv->br_x_option_index);
+ g_debug ("sane_get_option_descriptor (%d)", scanner->priv->br_x_option_index);
+ if (option->constraint_type == SANE_CONSTRAINT_RANGE) {
+ if (option->type == SANE_TYPE_FIXED)
+ set_fixed_option (scanner->priv->handle, option, scanner->priv->br_x_option_index, SANE_UNFIX (option->constraint.range->max), NULL);
+ else
+ set_int_option (scanner->priv->handle, option, scanner->priv->br_x_option_index, option->constraint.range->max, NULL);
+ }
+ }
+ if (scanner->priv->br_y_option_index) {
+ option = sane_get_option_descriptor (scanner->priv->handle, scanner->priv->br_y_option_index);
+ g_debug ("sane_get_option_descriptor (%d)", scanner->priv->br_y_option_index);
+ if (option->constraint_type == SANE_CONSTRAINT_RANGE) {
+ if (option->type == SANE_TYPE_FIXED)
+ set_fixed_option (scanner->priv->handle, option, scanner->priv->br_y_option_index, SANE_UNFIX (option->constraint.range->max), NULL);
+ else
+ set_int_option (scanner->priv->handle, option, scanner->priv->br_y_option_index, option->constraint.range->max, NULL);
+ }
+ }
+
scanner->priv->state = STATE_START;
return;
}
@@ -1091,21 +1118,10 @@ do_get_option (Scanner *scanner)
if (!set_constrained_string_option (scanner->priv->handle, option, option_index, disable_compression_names, NULL))
g_warning ("Unable to disable compression, please file a bug");
}
- /* Always use maximum scan area - some scanners default to using partial areas. This should be patched in sane-backends */
- else if (strcmp (option->name, SANE_NAME_SCAN_BR_X) == 0 ||
- strcmp (option->name, SANE_NAME_SCAN_BR_Y) == 0) {
- switch (option->constraint_type)
- {
- case SANE_CONSTRAINT_RANGE:
- if (option->type == SANE_TYPE_FIXED)
- set_fixed_option (scanner->priv->handle, option, option_index, SANE_UNFIX (option->constraint.range->max), NULL);
- else
- set_int_option (scanner->priv->handle, option, option_index, option->constraint.range->max, NULL);
- break;
- default:
- break;
- }
- }
+ else if (strcmp (option->name, SANE_NAME_SCAN_BR_X) == 0)
+ scanner->priv->br_x_option_index = option_index;
+ else if (strcmp (option->name, SANE_NAME_SCAN_BR_Y) == 0)
+ scanner->priv->br_y_option_index = option_index;
else if (strcmp (option->name, SANE_NAME_PAGE_WIDTH) == 0) {
if (job->page_width > 0.0) {
if (option->type == SANE_TYPE_FIXED)
diff --git a/src/simple-scan.c b/src/simple-scan.c
index ab59299..b8c3962 100644
--- a/src/simple-scan.c
+++ b/src/simple-scan.c
@@ -24,7 +24,7 @@
#include "book.h"
-static const char *default_device = NULL;
+static ScanDevice *default_device = NULL;
static GUdevClient *udev_client;
@@ -44,7 +44,27 @@ static gboolean debug = FALSE;
static void
update_scan_devices_cb (Scanner *scanner, GList *devices)
{
- ui_set_scan_devices (ui, devices);
+ GList *devices_copy;
+
+ devices_copy = g_list_copy (devices);
+
+ /* If the default device is not detected add it to the list */
+ if (default_device) {
+ GList *i;
+
+ for (i = devices_copy; i; i = i->next) {
+ ScanDevice *device = i->data;
+ if (strcmp (device->name, default_device->name) == 0)
+ break;
+ }
+
+ if (!i)
+ devices_copy = g_list_prepend (devices_copy, default_device);
+ }
+
+ ui_set_scan_devices (ui, devices_copy);
+
+ g_list_free (devices_copy);
}
@@ -343,7 +363,7 @@ get_temporary_filename (const gchar *prefix, const gchar *extension)
/* NOTE: I'm not sure if this is a 100% safe strategy to use g_file_open_tmp(), close and
* use the filename but it appears to work in practise */
- filename = g_strdup_printf ("%s-XXXXXX.%s", prefix, extension);
+ filename = g_strdup_printf ("%sXXXXXX.%s", prefix, extension);
fd = g_file_open_tmp (filename, &path, &error);
g_free (filename);
if (fd < 0) {
@@ -371,7 +391,7 @@ email_cb (SimpleScan *ui, const gchar *profile)
gchar *path;
/* Open a temporary file */
- path = get_temporary_filename ("scanned-document", "pdf");
+ path = get_temporary_filename ("scan", "pdf");
if (path) {
GFile *file;
@@ -389,7 +409,7 @@ email_cb (SimpleScan *ui, const gchar *profile)
gchar *path;
GFile *file;
- path = get_temporary_filename ("scanned-document", "jpg");
+ path = get_temporary_filename ("scan", "jpg");
if (!path) {
saved = FALSE;
break;
@@ -558,7 +578,9 @@ get_options (int argc, char **argv)
fprintf (stderr, "Unknown argument: '%s'\n", arg);
exit (1);
}
- default_device = arg;
+ default_device = g_malloc0 (sizeof (ScanDevice));
+ default_device->name = g_strdup (arg);
+ default_device->label = g_strdup (arg);
}
}
}
@@ -621,8 +643,15 @@ main (int argc, char **argv)
udev_client = g_udev_client_new (udev_subsystems);
g_signal_connect (udev_client, "uevent", G_CALLBACK (on_uevent), NULL);
- if (default_device)
- ui_set_selected_device (ui, default_device);
+ if (default_device) {
+ GList device_list;
+
+ device_list.data = default_device;
+ device_list.next = NULL;
+ device_list.prev = NULL;
+ ui_set_scan_devices (ui, &device_list);
+ ui_set_selected_device (ui, default_device->name);
+ }
ui_start (ui);
scanner_start (scanner);
diff --git a/src/ui.c b/src/ui.c
index 92e83c7..6fdd2e4 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -198,6 +198,9 @@ ui_set_scan_devices (SimpleScan *ui, GList *devices)
if (n_delete >= 0) {
gint i;
+ /* Update label */
+ gtk_list_store_set (GTK_LIST_STORE (ui->priv->device_model), &iter, 1, device->label, -1);
+
for (i = 0; i < n_delete; i++) {
gtk_tree_model_iter_nth_child (ui->priv->device_model, &iter, NULL, index);
gtk_list_store_remove (GTK_LIST_STORE (ui->priv->device_model), &iter);
@@ -255,13 +258,11 @@ ui_set_selected_device (SimpleScan *ui, const gchar *device)
{
GtkTreeIter iter;
- /* If doesn't exist add with label set to device name */
- if (!find_scan_device (ui, device, &iter)) {
- gtk_list_store_append (GTK_LIST_STORE (ui->priv->device_model), &iter);
- gtk_list_store_set (GTK_LIST_STORE (ui->priv->device_model), &iter, 0, device, 1, device, -1);
- }
+ if (!find_scan_device (ui, device, &iter))
+ return;
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (ui->priv->device_combo), &iter);
+ ui->priv->user_selected_device = TRUE;
}
@@ -1343,11 +1344,11 @@ ui_load (SimpleScan *ui)
gtk_list_store_append (GTK_LIST_STORE (ui->priv->paper_size_model), &iter);
gtk_list_store_set (GTK_LIST_STORE (ui->priv->paper_size_model), &iter, 0, 0, 1, 0, 2, "Automatic", -1);
gtk_list_store_append (GTK_LIST_STORE (ui->priv->paper_size_model), &iter);
- gtk_list_store_set (GTK_LIST_STORE (ui->priv->paper_size_model), &iter, 0, 2050, 1, 1480, 2, "A6", -1);
+ gtk_list_store_set (GTK_LIST_STORE (ui->priv->paper_size_model), &iter, 0, 1050, 1, 1480, 2, "A6", -1);
gtk_list_store_append (GTK_LIST_STORE (ui->priv->paper_size_model), &iter);
gtk_list_store_set (GTK_LIST_STORE (ui->priv->paper_size_model), &iter, 0, 1480, 1, 2100, 2, "A5", -1);
gtk_list_store_append (GTK_LIST_STORE (ui->priv->paper_size_model), &iter);
- gtk_list_store_set (GTK_LIST_STORE (ui->priv->paper_size_model), &iter, 0, 2100, 1, 1970, 2, "A4", -1);
+ gtk_list_store_set (GTK_LIST_STORE (ui->priv->paper_size_model), &iter, 0, 2100, 1, 2970, 2, "A4", -1);
gtk_list_store_append (GTK_LIST_STORE (ui->priv->paper_size_model), &iter);
gtk_list_store_set (GTK_LIST_STORE (ui->priv->paper_size_model), &iter, 0, 2159, 1, 2794, 2, "Letter", -1);
gtk_list_store_append (GTK_LIST_STORE (ui->priv->paper_size_model), &iter);