gnome-scan r738 - in trunk: . modules/gsane



Author: bersace
Date: Tue Dec 23 21:53:30 2008
New Revision: 738
URL: http://svn.gnome.org/viewvc/gnome-scan?rev=738&view=rev

Log:
Added GSaneOptionSource enabling mass acquisition.

Added:
   trunk/modules/gsane/gsane-option-source.c
   trunk/modules/gsane/gsane-option-source.h
Modified:
   trunk/ChangeLog
   trunk/modules/gsane/Makefile.am
   trunk/modules/gsane/gsane-module.c

Modified: trunk/modules/gsane/Makefile.am
==============================================================================
--- trunk/modules/gsane/Makefile.am	(original)
+++ trunk/modules/gsane/Makefile.am	Tue Dec 23 21:53:30 2008
@@ -18,6 +18,8 @@
 	gsane-option-handler.c		\
 	gsane-option-handler-generic.h	\
 	gsane-option-handler-generic.c	\
+	gsane-option-source.h		\
+	gsane-option-source.c		\
 	gsane-option-manager.h		\
 	gsane-option-manager.c		\
 	gsane-processor.h		\

Modified: trunk/modules/gsane/gsane-module.c
==============================================================================
--- trunk/modules/gsane/gsane-module.c	(original)
+++ trunk/modules/gsane/gsane-module.c	Tue Dec 23 21:53:30 2008
@@ -30,6 +30,7 @@
 #include "gsane-common.h"
 #include "gsane-option-manager.h"
 #include "gsane-option-handler-generic.h"
+#include "gsane-option-source.h"
 #include "gsane-backend.h"
 #include "gsane-scanner.h"
 
@@ -64,6 +65,7 @@
 	gsane_option_manager_add_rule_by_type(gsane_option_manager, SANE_TYPE_INT, GSANE_TYPE_OPTION_HANDLER_GENERIC);
 	gsane_option_manager_add_rule_by_type(gsane_option_manager, SANE_TYPE_FIXED, GSANE_TYPE_OPTION_HANDLER_GENERIC);
 	gsane_option_manager_add_rule_by_type(gsane_option_manager, SANE_TYPE_STRING, GSANE_TYPE_OPTION_HANDLER_GENERIC);
+	gsane_option_manager_add_rules_by_name(gsane_option_manager, GSANE_TYPE_OPTION_SOURCE, "source", "doc-source", NULL);
 }
 
 G_MODULE_EXPORT void

Added: trunk/modules/gsane/gsane-option-source.c
==============================================================================
--- (empty file)
+++ trunk/modules/gsane/gsane-option-source.c	Tue Dec 23 21:53:30 2008
@@ -0,0 +1,180 @@
+/* GSane - SANE GNOME Scan backend 
+ * Copyright  2007-2008  Ãtienne Bersac <bersace gnome org>
+ *
+ * GSane is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ * 
+ * GSane is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GSane.  If not, write to:
+ *
+ *	the Free Software Foundation, Inc.
+ *	51 Franklin Street, Fifth Floor
+ *	Boston, MA 02110-1301, USA
+ */
+
+#include <config.h>
+#include <glib/gi18n-lib.h>
+#include "gsane-scanner.h"
+#include "gsane-option-source.h"
+#include "gsane-common.h"
+
+#define GSANE_OPTION_SOURCE_GET_PRIVATE(o)	(G_TYPE_INSTANCE_GET_PRIVATE((o), GSANE_TYPE_OPTION_SOURCE, GSaneOptionSourcePrivate))
+
+struct _GSaneOptionSourcePrivate {
+	GSANE_OPTION_HANDLER_DEFINE_OPTION(source);
+};
+
+G_DEFINE_TYPE(GSaneOptionSource, gsane_option_source, GSANE_TYPE_OPTION_HANDLER);
+
+/*
+ * GSaneOptionSource has many jobs to fill.
+ *
+ * - It expose source option as a primary option, making some changes
+ *   to void backend inconsistency.
+ *
+ * - It knows whether the ADF has been selected in order to enable
+ *   mass acquisition.
+ *
+ * TODO:
+ *
+ * - Support ADF boolean option.
+ *
+ * - Support duplex scan (boolean and special source).
+ */
+
+/* some unlisted sources :
+ *
+ * - Slide(s)
+ * - TMA Slides
+ * - ADF Back
+ * - ADF Duplex (should be mapped to duplex boolean)
+ */
+
+/* List of known source used for flatbed  */
+#define	GSANE_SOURCE_FLATBED	_("Flatbed")
+static const gchar* flatbed_src[] = {
+	"FB",
+	"Normal",
+	"Manual Feed Tray",
+	"Opaque/Normal",
+	NULL
+};
+
+/* List of known source used for Automatic Document Feeder */
+#define	GSANE_SOURCE_ADF	_("Automatic Document Feeder")
+static const gchar* adf_src[] = {
+	"ADF",
+	"ADF Front",
+	"Automatic Slide Feeder",
+	"Document Feeder",
+	"AutoFeeder",
+	NULL
+};
+
+/* List of known source used for Transparency Adapter */
+#define	GSANE_SOURCE_TMA	_("Transparency Adapter")
+static const gchar* tma_src[] = {
+	"Transparency",
+	"Transparency Adapter",
+	"Transparency Unit",
+	"TMA",			/* Transparent Media Adapter */
+	NULL
+};
+
+/* List of known source used for Negative Adapter */
+#define GSANE_SOURCE_NEGATIVE	_("Negative Adapter")
+static const gchar* negative_src[] = {
+	"Negative",
+	"Negative Unit",
+	"TMA Negative",
+	"Filmstrip",
+	"Film",
+	NULL
+};
+
+static gboolean
+gsane_string_in_array(const gchar* str, const gchar** array)
+{
+	for(; *array; array++)
+		if (g_str_equal(str, *array))
+			return TRUE;
+	return FALSE;
+}
+
+static void
+gsane_option_source_option_changed(GSaneOptionSource* self, GObject* option)
+{
+	GnomeScanEnumValue *evalue = NULL;
+	gnome_scan_option_enum_get_value(GNOME_SCAN_OPTION_ENUM(option), &evalue);
+	gsane_scanner_set_mass_acquisition(GSANE_SCANNER(GSANE_OPTION_HANDLER(self)->scanner),
+					   g_str_equal(evalue->label, GSANE_SOURCE_ADF));
+	gsane_option_handler_set_enum(GSANE_OPTION_HANDLER(self), self->priv->source_desc, self->priv->source_index, evalue, NULL);
+}
+
+static void
+gsane_option_handler_handle_source(GSaneOptionHandler* handler, const SANE_Option_Descriptor* desc, SANE_Int n, const gchar*group)
+{
+	GSaneOptionSource* self = GSANE_OPTION_SOURCE(handler);
+	GSList *iter, *values = gsane_option_handler_enum_list_string_values(handler, desc, n);
+	GnomeScanEnumValue *value, *default_value;
+	const gchar* src;
+
+	/* override label to make source consistent accross backends,
+	   this also allow to know whether ADF is selected. */
+	for(iter = values; iter; iter = iter->next) {
+		value = iter->data;
+		src = g_value_get_string(&value->value);
+		if (gsane_string_in_array(src, flatbed_src))
+			value->label = GSANE_SOURCE_FLATBED;
+		else if (gsane_string_in_array(src, adf_src))
+			value->label = GSANE_SOURCE_ADF;
+		else if (gsane_string_in_array(src, tma_src))
+			value->label = GSANE_SOURCE_TMA;
+		else if (gsane_string_in_array(src, negative_src))
+			value->label = GSANE_SOURCE_NEGATIVE;
+	}
+
+	default_value = gsane_option_handler_get_enum(handler, desc, n, values, NULL);
+	self->priv->source_option = GNOME_SCAN_OPTION(gnome_scan_option_enum_new(desc->name, S_(desc->title), S_(desc->desc), GNOME_SCAN_OPTION_GROUP_SCANNER, SANE_GETTEXT_PACKAGE,
+										 default_value, values, GNOME_SCAN_OPTION_HINT_PRIMARY));
+	g_signal_connect_swapped(self->priv->source_option, "changed", G_CALLBACK(gsane_option_source_option_changed), self);
+	gnome_scan_node_install_option(GNOME_SCAN_NODE(handler->scanner), self->priv->source_option);
+}
+
+void
+gsane_option_source_handle_option(GSaneOptionHandler *handler, const SANE_Option_Descriptor* desc, SANE_Int n, const gchar*group)
+{
+	GSaneOptionSource *self = GSANE_OPTION_SOURCE(handler);
+	GSaneOptionSourceClass *klass = GSANE_OPTION_SOURCE_GET_CLASS(self);
+
+ 	GSANE_OPTION_HANDLER_MATCH_OPTION(self, klass, source, desc, n, group);
+}
+
+void
+gsane_option_source_class_init(GSaneOptionSourceClass *klass)
+{
+	GSaneOptionHandlerClass *oh_class = GSANE_OPTION_HANDLER_CLASS(klass);
+
+	g_type_class_add_private(klass, sizeof(GSaneOptionSourcePrivate));
+
+	oh_class->handle_option = gsane_option_source_handle_option;
+	GSANE_OPTION_HANDLER_CLASS_INSTALL_OPTION(klass, source);
+}
+
+void
+gsane_option_source_class_finalize(GSaneOptionSourceClass *klass)
+{
+}
+
+void
+gsane_option_source_init(GSaneOptionSource *self)
+{
+	self->priv = GSANE_OPTION_SOURCE_GET_PRIVATE(self);
+}

Added: trunk/modules/gsane/gsane-option-source.h
==============================================================================
--- (empty file)
+++ trunk/modules/gsane/gsane-option-source.h	Tue Dec 23 21:53:30 2008
@@ -0,0 +1,51 @@
+/* GSane - SANE GNOME Scan backend 
+ * Copyright  2007-2008  Ãtienne Bersac <bersace gnome org>
+ *
+ * GSane is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ * 
+ * GSane is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GSane.  If not, write to:
+ *
+ *	the Free Software Foundation, Inc.
+ *	51 Franklin Street, Fifth Floor
+ *	Boston, MA 02110-1301, USA
+ */
+
+#ifndef _GSANE_OPTION_SOURCE_H_
+#define _GSANE_OPTION_SOURCE_H_
+
+#include "gsane-option-handler.h"
+
+G_BEGIN_DECLS
+
+#define	GSANE_TYPE_OPTION_SOURCE	(gsane_option_source_get_type())
+#define	GSANE_OPTION_SOURCE(o)		(G_TYPE_CHECK_INSTANCE_CAST((o), GSANE_TYPE_OPTION_SOURCE, GSaneOptionSource))
+#define	GSANE_OPTION_SOURCE_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS((o), GSANE_TYPE_OPTION_SOURCE, GSaneOptionSourceClass))
+
+typedef struct _GSaneOptionSourceClass GSaneOptionSourceClass;
+typedef struct _GSaneOptionSource GSaneOptionSource;
+typedef struct _GSaneOptionSourcePrivate GSaneOptionSourcePrivate;
+
+struct _GSaneOptionSourceClass {
+	GSaneOptionHandlerClass	parent_class;
+	GSANE_OPTION_HANDLER_CLASS_DEFINE_HANDLER(source);
+};
+
+struct _GSaneOptionSource {
+	GSaneOptionHandler parent_instance;
+	GSaneOptionSourcePrivate *priv;
+};
+
+GType gsane_option_source_get_type(void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]