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



Author: bersace
Date: Fri Dec 12 20:48:03 2008
New Revision: 670
URL: http://svn.gnome.org/viewvc/gnome-scan?rev=670&view=rev

Log:
Added generic option handlerin GSane.

Added:
   trunk/modules/gsane/gsane-option-handler-generic.c
   trunk/modules/gsane/gsane-option-handler-generic.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	Fri Dec 12 20:48:03 2008
@@ -12,17 +12,19 @@
 
 
 libgsane_la_SOURCES = \
-	gsane-common.h     	\
-	gsane-common.c		\
-	gsane-option-handler.h	\
-	gsane-option-handler.c	\
-	gsane-option-manager.h	\
-	gsane-option-manager.c	\
-	gsane-scanner.h     	\
-	gsane-scanner.c     	\
-	gsane-backend.h     	\
-	gsane-backend.c     	\
-	gsane-module.c     	\
+	gsane-common.h     		\
+	gsane-common.c			\
+	gsane-option-handler.h		\
+	gsane-option-handler.c		\
+	gsane-option-handler-generic.h	\
+	gsane-option-handler-generic.c	\
+	gsane-option-manager.h		\
+	gsane-option-manager.c		\
+	gsane-scanner.h     		\
+	gsane-scanner.c     		\
+	gsane-backend.h     		\
+	gsane-backend.c     		\
+	gsane-module.c     		\
 	$(NULL)
 
 libgsane_la_LDFLAGS = -avoid-version -module

Modified: trunk/modules/gsane/gsane-module.c
==============================================================================
--- trunk/modules/gsane/gsane-module.c	(original)
+++ trunk/modules/gsane/gsane-module.c	Fri Dec 12 20:48:03 2008
@@ -19,11 +19,17 @@
  *	Boston, MA 02110-1301, USA
  */
 
+#if	HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib/gi18n-lib.h>
 #include <gmodule.h>
 #include <sane/sane.h>
 #include <gnome-scan-module.h>
 #include "gsane-common.h"
 #include "gsane-option-manager.h"
+#include "gsane-option-handler-generic.h"
 #include "gsane-backend.h"
 #include "gsane-scanner.h"
 
@@ -54,6 +60,10 @@
 
 	/* GSane option handling */
 	gsane_option_manager = gsane_option_manager_new();
+	gsane_option_manager_add_rule_by_type(gsane_option_manager, SANE_TYPE_BOOL, GSANE_TYPE_OPTION_HANDLER_GENERIC);
+	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);
 }
 
 G_MODULE_EXPORT void

Added: trunk/modules/gsane/gsane-option-handler-generic.c
==============================================================================
--- (empty file)
+++ trunk/modules/gsane/gsane-option-handler-generic.c	Fri Dec 12 20:48:03 2008
@@ -0,0 +1,107 @@
+/* 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 <gnome-scan-option.h>
+#include "gsane-common.h"
+#include "gsane-option-handler-generic.h"
+
+#define	GSANE_OPTION_HANDLER_GENERIC_GET_PRIVATE(o)	(G_TYPE_INSTANCE_GET_PRIVATE((o), GSANE_TYPE_OPTION_HANDLER_GENERIC, GSaneOptionHandlerGenericPrivate))
+
+struct _GSaneOptionHandlerGenericPrivate
+{
+	SANE_Int n;
+	const SANE_Option_Descriptor* desc;
+	const gchar*		group;
+	GnomeScanOption*	option;
+};
+
+static GSaneOptionHandlerClass*gsane_option_handler_generic_parent_class = NULL;
+
+static void
+gsane_option_handler_generic_handle_option(GSaneOptionHandler *handler, SANE_Int n, const SANE_Option_Descriptor*desc, const gchar* group)
+{
+	GSaneOptionHandlerGeneric* self = GSANE_OPTION_HANDLER_GENERIC(handler);
+	self->priv->n = n;
+	self->priv->desc = desc;
+	self->priv->group = group;
+	static gboolean monitor = FALSE;
+
+	/* don't trust SANE test backend */
+	GnomeScanOptionHint hint = GNOME_SCAN_OPTION_HINT_SECONDARY;
+
+	switch(desc->type) {
+	case SANE_TYPE_BOOL:
+		self->priv->option = GNOME_SCAN_OPTION(gnome_scan_option_bool_new(desc->name, desc->title, desc->desc, group, SANE_GETTEXT_PACKAGE, FALSE, hint));
+		break;
+	default:
+		break;
+	}
+
+	if (!self->priv->option)
+		return;
+
+	/* register callbacks */
+
+	/* install option */
+	gnome_scan_node_install_option(GNOME_SCAN_NODE(handler->scanner), self->priv->option);
+}
+
+void
+gsane_option_handler_generic_class_init(gpointer g_class, gpointer class_data)
+{
+	gsane_option_handler_generic_parent_class = g_type_class_peek_parent(g_class);
+	g_type_class_add_private(g_class, sizeof(GSaneOptionHandlerGenericPrivate));
+	GSaneOptionHandlerClass* oh_class = GSANE_OPTION_HANDLER_CLASS(g_class);
+	oh_class->handle_option = gsane_option_handler_generic_handle_option;
+}
+
+void
+gsane_option_handler_generic_instance_init(GTypeInstance* instance, gpointer g_class)
+{
+	GSaneOptionHandlerGeneric *self = GSANE_OPTION_HANDLER_GENERIC(instance);
+	self->priv = GSANE_OPTION_HANDLER_GENERIC_GET_PRIVATE(self);
+}
+
+GType
+gsane_option_handler_generic_get_type(void)
+{
+	static GType type = 0;
+	static const GTypeInfo info = {
+		.class_size	= sizeof(GSaneOptionHandlerGenericClass),
+		.base_init	= NULL,
+		.base_finalize	= NULL,
+		.class_init	= gsane_option_handler_generic_class_init,
+		.class_finalize	= NULL,
+		.class_data	= NULL,
+		.instance_size	= sizeof(GSaneOptionHandlerGeneric),
+		.n_preallocs	= 0,
+		.instance_init	= gsane_option_handler_generic_instance_init,
+		.value_table	= NULL,
+	};
+
+	if (G_UNLIKELY(type == 0)) {
+		type = g_type_register_static(GSANE_TYPE_OPTION_HANDLER,
+					      "GSaneOptionHandlerGeneric",
+					      &info, 0);
+	}
+
+	return type;
+}

Added: trunk/modules/gsane/gsane-option-handler-generic.h
==============================================================================
--- (empty file)
+++ trunk/modules/gsane/gsane-option-handler-generic.h	Fri Dec 12 20:48:03 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_HANDLER_GENERIC_H_
+#define _GSANE_OPTION_HANDLER_GENERIC_H_
+
+#include "gsane-option-handler.h"
+
+G_BEGIN_DECLS
+
+#define	GSANE_TYPE_OPTION_HANDLER_GENERIC	(gsane_option_handler_generic_get_type())
+#define	GSANE_OPTION_HANDLER_GENERIC(o)		(G_TYPE_CHECK_INSTANCE_CAST((o), GSANE_TYPE_OPTION_HANDLER_GENERIC, GSaneOptionHandlerGeneric))
+
+typedef struct _GSaneOptionHandlerGenericClass GSaneOptionHandlerGenericClass;
+typedef struct _GSaneOptionHandlerGeneric GSaneOptionHandlerGeneric;
+typedef struct _GSaneOptionHandlerGenericPrivate GSaneOptionHandlerGenericPrivate;
+
+struct _GSaneOptionHandlerGeneric
+{
+	GSaneOptionHandler parent_instance;
+	GSaneOptionHandlerGenericPrivate* priv;
+};
+
+struct _GSaneOptionHandlerGenericClass
+{
+	GSaneOptionHandlerClass parent_class;
+};
+
+GType gsane_option_handler_generic_get_type(void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif



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