gnome-scan r524 - in trunk: . modules
- From: bersace svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-scan r524 - in trunk: . modules
- Date: Tue, 26 Feb 2008 23:37:44 +0000 (GMT)
Author: bersace
Date: Tue Feb 26 23:37:44 2008
New Revision: 524
URL: http://svn.gnome.org/viewvc/gnome-scan?rev=524&view=rev
Log:
Show ignored scanners. Move webcam code from gsane_scanner_new() to
gsane_scanner_constructor().
Modified:
trunk/ChangeLog
trunk/modules/gsane-backend.c
trunk/modules/gsane-scanner.c
Modified: trunk/modules/gsane-backend.c
==============================================================================
--- trunk/modules/gsane-backend.c (original)
+++ trunk/modules/gsane-backend.c Tue Feb 26 23:37:44 2008
@@ -71,6 +71,10 @@
gnome_scan_backend_add_scanner(backend, scanner);
g_object_unref (scanner);
}
+ else {
+ g_debug("SANE device %s failed or ignored",
+ devices[i].name);
+ }
}
}
Modified: trunk/modules/gsane-scanner.c
==============================================================================
--- trunk/modules/gsane-scanner.c (original)
+++ trunk/modules/gsane-scanner.c Tue Feb 26 23:37:44 2008
@@ -34,21 +34,21 @@
typedef struct _GSaneScannerPrivate GSaneScannerPrivate;
typedef void (* GSSDataFunc) (GSaneScanner *sane,
- GeglRectangle *rect,
- Babl *format,
- guchar *buf,
- gint len);
+ GeglRectangle *rect,
+ Babl *format,
+ guchar *buf,
+ gint len);
struct _GSaneScannerPrivate
{
/* INTERNALS */
- GThread* init_thread;
+ GThread* init_thread;
/* SANE */
- gchar* sane_id;
+ gchar* sane_id;
SANE_Handle handle;
/* Aquisition */
- SANE_Parameters params;
+ SANE_Parameters params;
SANE_Int data_len;
SANE_Int chunk_len;
guint bytes_read;
@@ -59,31 +59,31 @@
guint frame_no;
/* NULL terminated list of MetaParams */
- GHashTable* meta_params;
+ GHashTable* meta_params;
/* temp */
- gboolean reload;
+ gboolean reload;
gboolean changed;
gboolean first;
GnomeScanSettings *settings;
};
enum
-{
- PROP_0,
- PROP_SANE_ID
-};
+ {
+ PROP_0,
+ PROP_SANE_ID
+ };
static GnomeScannerClass* parent_class = NULL;
/* PLUGIN API */
static void gss_configure (GnomeScanPlugin *plugin,
- GnomeScanSettings *settings);
+ GnomeScanSettings *settings);
static GList* gss_get_child_nodes (GnomeScanPlugin *plugin,
- GeglNode *root);
+ GeglNode *root);
static gboolean gss_start_frame (GnomeScanPlugin *plugin);
static gboolean gss_work (GnomeScanPlugin *plugin,
- gdouble *progress);
+ gdouble *progress);
static void gss_end_frame (GnomeScanPlugin *plugin);
/* SCANNER API */
@@ -96,24 +96,24 @@
/* OPTIONS */
static void gss_probe_options (GSaneScanner *sane);
static void gss_mp_foreach_option_matches (const gchar *key,
- MetaParam *mp,
- GPtrArray* arg);
+ MetaParam *mp,
+ GPtrArray* arg);
static void gss_mp_foreach_add_param (const gchar* key,
- MetaParam *mp,
- GSaneScanner *sane);
+ MetaParam *mp,
+ GSaneScanner *sane);
static void gss_params_foreach_set_param (GParamSpec *spec,
- GSaneScanner *gss);
+ GSaneScanner *gss);
static GParamSpec* gss_option_get_param_spec (GSaneScanner *sane,
- SANE_Int n);
+ SANE_Int n);
static void gss_params_foreach_update_param (GParamSpec *pspec,
- GSaneScanner *gss);
+ GSaneScanner *gss);
static void gss_option_set_default_value_by_index (GSaneScanner *gss,
- SANE_Int n,
- GType type);
+ SANE_Int n,
+ GType type);
static GValue* gss_option_get_value_by_index (GSaneScanner *sane,
- SANE_Int n,
- GType type);
+ SANE_Int n,
+ GType type);
/* utils */
#define gss_option_name_matches_array(spec,names) gsane_str_matches_strv(g_param_spec_get_name(spec),names)
@@ -134,21 +134,31 @@
GSaneScannerPrivate *priv = GET_PRIVATE(object);
SANE_Status status;
+ /* v4l set type as "virtual device". Welcome to the bazar of
+ SANE backends :( */
+ if (g_str_equal(device->type, "video camera")
+ || g_str_equal(device->type, "webcam")
+ || g_strstr_len(device->name, 4, "v4l"))
+ return NULL;
+
status = sane_open (priv->sane_id, &(priv->handle));
if (status != SANE_STATUS_GOOD) {
g_warning ("Unable to open device %s (%s) : %s",
- gnome_scan_plugin_get_name (GNOME_SCAN_PLUGIN (object)),
- priv->sane_id, sane_strstatus (status));
+ gnome_scan_plugin_get_name (GNOME_SCAN_PLUGIN (object)),
+ priv->sane_id, sane_strstatus (status));
return NULL;
}
+
+
- /* Since the use needs to select the scanner before showing options, we can
- do the probe in a seperate thread, this will quicken the probe, while the user
- choose the device. */
- priv->init_thread = g_thread_create((GThreadFunc) gss_init,
- GSANE_SCANNER(object),
- TRUE, &error);
+ /* Since the use needs to select the scanner before showing
+ options, we can do the probe in a seperate thread, this
+ will quicken the probe, while the user choose the
+ device. */
+ priv->init_thread = g_thread_create((GThreadFunc) gss_init,
+ GSANE_SCANNER(object),
+ TRUE, &error);
return object;
}
@@ -158,7 +168,7 @@
{
GSaneScannerPrivate *priv = GET_PRIVATE (object);
priv->meta_params = g_hash_table_new (g_str_hash,
- g_str_equal);
+ g_str_equal);
}
static void
@@ -182,14 +192,14 @@
g_return_if_fail (GNOME_IS_SCANNER_SANE (object));
switch (prop_id)
- {
+ {
case PROP_SANE_ID:
GET_PRIVATE (object)->sane_id = g_value_dup_string(value);
- break;
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ break;
+ }
}
#if 0
@@ -199,11 +209,11 @@
g_return_if_fail (GNOME_IS_SCANNER_SANE (object));
switch (prop_id)
- {
+ {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ break;
+ }
}
#endif
@@ -230,35 +240,28 @@
object_class->finalize = gsane_scanner_finalize;
g_object_class_install_property (object_class,
- PROP_SANE_ID,
- g_param_spec_string ("sane-id",
- "SANE id",
- "SANE device identifier",
- "",
- G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+ PROP_SANE_ID,
+ g_param_spec_string ("sane-id",
+ "SANE id",
+ "SANE device identifier",
+ "",
+ G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}
GnomeScanner*
gsane_scanner_new (const SANE_Device *device)
{
- /* v4l set type as "virtual device". Welcome to the bazar of
- SANE backends :( */
- if (g_str_equal(device->type, "video camera")
- || g_str_equal(device->type, "webcam")
- || g_strstr_len(device->name, 4, "v4l"))
- return NULL;
-
GObject *object =
g_object_new (GSANE_TYPE_SCANNER,
- "name", g_strconcat(device->vendor,
- " ",
- device->model,
- NULL),
- "blurb", "",
- "icon-name", "scanner",
- "sane-id", device->name,
- NULL);
+ "name", g_strconcat(device->vendor,
+ " ",
+ device->model,
+ NULL),
+ "blurb", "",
+ "icon-name", "scanner",
+ "sane-id", device->name,
+ NULL);
return GNOME_SCANNER (object);
}
@@ -266,7 +269,7 @@
static void
gss_configure (GnomeScanPlugin *plugin,
- GnomeScanSettings *settings)
+ GnomeScanSettings *settings)
{
GSaneScannerPrivate *priv = GET_PRIVATE (plugin);
@@ -274,13 +277,13 @@
priv->first = TRUE;
gnome_scan_plugin_params_foreach (plugin,
- (GFunc) gss_params_foreach_set_param,
- GSANE_SCANNER (plugin));
+ (GFunc) gss_params_foreach_set_param,
+ GSANE_SCANNER (plugin));
if (priv->reload) {
gnome_scan_plugin_params_foreach (plugin,
- (GFunc) gss_params_foreach_update_param,
- GSANE_SCANNER (plugin));
+ (GFunc) gss_params_foreach_update_param,
+ GSANE_SCANNER (plugin));
priv->reload = FALSE;
}
priv->settings = NULL;
@@ -288,7 +291,7 @@
static GList*
gss_get_child_nodes (GnomeScanPlugin *plugin,
- GeglNode *root)
+ GeglNode *root)
{
GSaneScannerPrivate *priv = GET_PRIVATE (plugin);
GList* list = NULL;
@@ -342,8 +345,8 @@
return FALSE;
priv->format = fmt = g_strdup_printf("%s u%i",
- priv->params.format == SANE_FRAME_GRAY ? "Y" : "RGB",
- MAX(8, priv->params.depth));
+ priv->params.format == SANE_FRAME_GRAY ? "Y" : "RGB",
+ MAX(8, priv->params.depth));
format = babl_format(fmt);
priv->chunk_len = priv->params.bytes_per_line;
@@ -354,7 +357,7 @@
priv->buffer = gegl_buffer_new (&extent, format);
g_debug (G_STRLOC ": buffer is %p in format %s",
- priv->buffer, fmt);
+ priv->buffer, fmt);
gegl_node_set (priv->load,
"buffer", priv->buffer,
@@ -403,18 +406,18 @@
tlen = len * 8;
tbuf = g_new0 (guchar, tlen);
/* we loop each bit */
- for (i = 0; i < tlen; i++) {
- /* get the byte containing the inth bit */
- val = buf[i/8];
- /* first bit is the MSB */
- mask = (0x80 >> (i%8));
- tbuf[i] = (val & mask) ? 0xFF : 0x00;
- }
+ for (i = 0; i < tlen; i++) {
+ /* get the byte containing the inth bit */
+ val = buf[i/8];
+ /* first bit is the MSB */
+ mask = (0x80 >> (i%8));
+ tbuf[i] = (val & mask) ? 0xFF : 0x00;
+ }
gegl_buffer_set (GET_PRIVATE (gss)->buffer,
- rect,
- format,
- tbuf,
- GEGL_AUTO_ROWSTRIDE);
+ rect,
+ format,
+ tbuf,
+ GEGL_AUTO_ROWSTRIDE);
g_free (tbuf);
}
@@ -422,25 +425,25 @@
/* process 8/16 bit RGB in to â 8/16 bit RGB */
static void
gss_data_color (GSaneScanner *gss,
- GeglRectangle *rect,
- Babl* format,
- guchar* buf,
- gint len)
+ GeglRectangle *rect,
+ Babl* format,
+ guchar* buf,
+ gint len)
{
gegl_buffer_set (GET_PRIVATE (gss)->buffer,
- rect,
- format,
- buf,
- GEGL_AUTO_ROWSTRIDE);
+ rect,
+ format,
+ buf,
+ GEGL_AUTO_ROWSTRIDE);
}
/* process 1 bit RGB into RGB 8bit */
static void
gss_data_color1_three_pass (GSaneScanner *gss,
- GeglRectangle *rect,
- Babl* format,
- guchar *buf,
- gint len)
+ GeglRectangle *rect,
+ Babl* format,
+ guchar *buf,
+ gint len)
{
GSaneScannerPrivate *priv = GET_PRIVATE (gss);
guchar *tbuf;
@@ -448,17 +451,17 @@
guchar mask;
switch (priv->params.format) {
- case SANE_FRAME_RED:
- offset = 0;
+ case SANE_FRAME_RED:
+ offset = 0;
break;
- case SANE_FRAME_GREEN:
- offset = 1;;
+ case SANE_FRAME_GREEN:
+ offset = 1;;
break;
- case SANE_FRAME_BLUE:
- offset = 2;;
+ case SANE_FRAME_BLUE:
+ offset = 2;;
+ break;
+ default:
break;
- default:
- break;
}
tbuf = g_new0 (guchar, tlen * 3);
@@ -468,17 +471,17 @@
tbuf[i*3+offset] = (buf[i/8] & mask) ? 0xFF : 0x00;
}
gegl_buffer_set (priv->buffer, rect, format, tbuf,
- GEGL_AUTO_ROWSTRIDE);
+ GEGL_AUTO_ROWSTRIDE);
g_free (tbuf);
}
/* 8/16 bit three pass RGB */
static void
gss_data_color_three_pass (GSaneScanner *gss,
- GeglRectangle *rect,
- Babl* format,
- guchar* buf,
- gint len)
+ GeglRectangle *rect,
+ Babl* format,
+ guchar* buf,
+ gint len)
{
GSaneScannerPrivate *priv = GET_PRIVATE (gss);
guchar *tbuf;
@@ -486,21 +489,21 @@
/* sample stride */
- sp_stride = priv->params.depth/8;
+ sp_stride = priv->params.depth/8;
px_stride = 3 * sp_stride;
switch (priv->params.format) {
- case SANE_FRAME_RED:
- offset = 0;
+ case SANE_FRAME_RED:
+ offset = 0;
break;
- case SANE_FRAME_GREEN:
- offset = 1;
+ case SANE_FRAME_GREEN:
+ offset = 1;
break;
- case SANE_FRAME_BLUE:
- offset = 2;
+ case SANE_FRAME_BLUE:
+ offset = 2;
+ break;
+ default:
break;
- default:
- break;
}
offset*= sp_stride;
@@ -509,11 +512,11 @@
for (i = 0; i < len/sp_stride; i++) {
/* copy 1 or 2 bytes of sample at the right place */
- memcpy(tbuf+i*px_stride+offset, buf+i*sp_stride, sp_stride);
+ memcpy(tbuf+i*px_stride+offset, buf+i*sp_stride, sp_stride);
}
gegl_buffer_set (priv->buffer, rect, NULL, tbuf,
- GEGL_AUTO_ROWSTRIDE);
+ GEGL_AUTO_ROWSTRIDE);
g_free (tbuf);
}
@@ -532,7 +535,7 @@
tbuf[i] = (buf[i/8] & mask) ? 0xFF : 0x00;
}
gegl_buffer_set (GET_PRIVATE (gss)->buffer, rect, format, tbuf,
- GEGL_AUTO_ROWSTRIDE);
+ GEGL_AUTO_ROWSTRIDE);
g_free (tbuf);
}
@@ -541,7 +544,7 @@
gss_data_gray (GSaneScanner *gss, GeglRectangle *rect, Babl* format, guchar* buf, gint len)
{
gegl_buffer_set (GET_PRIVATE (gss)->buffer, rect, format, buf,
- GEGL_AUTO_ROWSTRIDE);
+ GEGL_AUTO_ROWSTRIDE);
}
@@ -561,37 +564,37 @@
status = sane_read (priv->handle, buf, priv->chunk_len, &len);
/* start new frame for three pass acquisition */
- if (status == SANE_STATUS_EOF && !priv->params.last_frame) {
- g_free (buf);
- return gss_sane_start (gss);
- }
+ if (status == SANE_STATUS_EOF && !priv->params.last_frame) {
+ g_free (buf);
+ return gss_sane_start (gss);
+ }
/* EOF, NO_DOCS, errors â */
- if (status != SANE_STATUS_GOOD) {
- gs_debug (G_STRLOC ": %s", sane_strstatus (status));
- g_free (buf);
- return FALSE;
- }
+ if (status != SANE_STATUS_GOOD) {
+ gs_debug (G_STRLOC ": %s", sane_strstatus (status));
+ g_free (buf);
+ return FALSE;
+ }
/* determine which function to call */
- switch (priv->params.format) {
- case SANE_FRAME_RGB:
- processor = priv->params.depth == 1 ? gss_data_color1 : gss_data_color;
- priv->n_frames = 1;
- break;
- case SANE_FRAME_RED:
- case SANE_FRAME_GREEN:
- case SANE_FRAME_BLUE:
- processor = (priv->params.depth == 1) ? gss_data_color1_three_pass : gss_data_color_three_pass;
- break;
- case SANE_FRAME_GRAY:
- processor = (priv->params.depth == 1) ? gss_data_gray1 : gss_data_gray;
- break;
- default:
- g_warning ("Frame format not supported");
- return FALSE;
- break;
- }
+ switch (priv->params.format) {
+ case SANE_FRAME_RGB:
+ processor = priv->params.depth == 1 ? gss_data_color1 : gss_data_color;
+ priv->n_frames = 1;
+ break;
+ case SANE_FRAME_RED:
+ case SANE_FRAME_GREEN:
+ case SANE_FRAME_BLUE:
+ processor = (priv->params.depth == 1) ? gss_data_color1_three_pass : gss_data_color_three_pass;
+ break;
+ case SANE_FRAME_GRAY:
+ processor = (priv->params.depth == 1) ? gss_data_gray1 : gss_data_gray;
+ break;
+ default:
+ g_warning ("Frame format not supported");
+ return FALSE;
+ break;
+ }
rect.x = priv->bytes_read % priv->params.bytes_per_line;
rect.y = priv->bytes_read / priv->params.bytes_per_line;
@@ -607,7 +610,7 @@
priv->bytes_read+= len;
/* This very complex formula compute the right progress over one or three frame */
- *progress = ((gdouble) priv->frame_no-1) * (1./(gdouble) priv->n_frames) + ((gdouble) priv->bytes_read / (gdouble) priv->data_len) / (gdouble) priv->n_frames;
+ *progress = ((gdouble) priv->frame_no-1) * (1./(gdouble) priv->n_frames) + ((gdouble) priv->bytes_read / (gdouble) priv->data_len) / (gdouble) priv->n_frames;
return TRUE;
}
@@ -638,15 +641,15 @@
/* declare MetaParams */
#define gss_mp_new(name, gss) mp = meta_param_##name(gss); \
-g_hash_table_insert (priv->meta_params, meta_param_get_name (mp), mp)
+ g_hash_table_insert (priv->meta_params, meta_param_get_name (mp), mp)
- gss_mp_new(paper_size, gss);
+ gss_mp_new(paper_size, gss);
gss_mp_new(source, gss);
#undef gss_mp_new
/* launch options probe */
- gss_probe_options (gss);
+ gss_probe_options (gss);
}
static void
@@ -670,53 +673,53 @@
};
gnome_scanner_set_status (GNOME_SCANNER (gss),
- GNOME_SCANNER_BUSY);
+ GNOME_SCANNER_BUSY);
spec = gss_option_get_param_spec (gss, 0);
value = gsane_scanner_option_get_value(gss, spec);
n = g_value_get_int (value);
gs_debug(" === Device %s (%d options) ===",
- gnome_scan_plugin_get_name(GNOME_SCAN_PLUGIN(gss)), n);
+ gnome_scan_plugin_get_name(GNOME_SCAN_PLUGIN(gss)), n);
g_ptr_array_add (arg, gss);
g_ptr_array_add (arg, &mp);
/* loop each sane option */
- for (i = 1; i < n; i++) {
- /* get corresponding spec */
- spec = gss_option_get_param_spec(gss, i);
- if (spec) {
- /* override group for front options */
- if (gss_option_name_matches_array (spec, front_option_names)) {
- gs_param_spec_set_group (spec, GS_PARAM_GROUP_SCANNER_FRONT);
- }
+ for (i = 1; i < n; i++) {
+ /* get corresponding spec */
+ spec = gss_option_get_param_spec(gss, i);
+ if (spec) {
+ /* override group for front options */
+ if (gss_option_name_matches_array (spec, front_option_names)) {
+ gs_param_spec_set_group (spec, GS_PARAM_GROUP_SCANNER_FRONT);
+ }
- if (gss_option_name_matches_array (spec, hidden_options)) {
- gs_param_spec_set_group (spec, GS_PARAM_GROUP_HIDDEN);
- }
+ if (gss_option_name_matches_array (spec, hidden_options)) {
+ gs_param_spec_set_group (spec, GS_PARAM_GROUP_HIDDEN);
+ }
- /* search if this option does not belong to a MetaParam */
- mp = NULL;
- g_ptr_array_add (arg, spec);
- g_hash_table_foreach (priv->meta_params,
- (GHFunc) gss_mp_foreach_option_matches,
- arg);
- g_ptr_array_remove (arg, spec);
+ /* search if this option does not belong to a MetaParam */
+ mp = NULL;
+ g_ptr_array_add (arg, spec);
+ g_hash_table_foreach (priv->meta_params,
+ (GHFunc) gss_mp_foreach_option_matches,
+ arg);
+ g_ptr_array_remove (arg, spec);
- if (mp)
- meta_param_add_params (mp, spec);
- /* or add directly to scanner */
- else
- gnome_scan_plugin_params_add (GNOME_SCAN_PLUGIN (gss), spec);
- }
+ if (mp)
+ meta_param_add_params (mp, spec);
+ /* or add directly to scanner */
+ else
+ gnome_scan_plugin_params_add (GNOME_SCAN_PLUGIN (gss), spec);
}
+ }
/* now ask each MetaParam to add its param to the scanner */
- g_hash_table_foreach (priv->meta_params,
- (GHFunc) gss_mp_foreach_add_param,
- gss);
+ g_hash_table_foreach (priv->meta_params,
+ (GHFunc) gss_mp_foreach_add_param,
+ gss);
gs_debug ("\n");
@@ -753,69 +756,69 @@
desc = sane_get_option_descriptor(priv->handle, n);
/* FLAG */
- sflags = "";
+ sflags = "";
if (SANE_OPTION_IS_ACTIVE (desc->cap)) {
flags = flags | G_PARAM_WRITABLE;
sflags = "writable";
}
/* UNIT */
- switch (desc->unit) {
- case SANE_UNIT_PIXEL:
- unit = GS_UNIT_PIXEL;
- break;
- case SANE_UNIT_BIT:
- unit = GS_UNIT_BIT;
- break;
- case SANE_UNIT_MM:
- unit = GS_UNIT_MM;
- break;
- case SANE_UNIT_DPI:
- unit = GS_UNIT_DPI;
- break;
- case SANE_UNIT_PERCENT:
- unit = GS_UNIT_PERCENT;
- break;
- case SANE_UNIT_MICROSECOND:
- unit = GS_UNIT_PERCENT;
- break;
- case SANE_UNIT_NONE:
- default:
- unit = GS_UNIT_NONE;
- break;
- }
+ switch (desc->unit) {
+ case SANE_UNIT_PIXEL:
+ unit = GS_UNIT_PIXEL;
+ break;
+ case SANE_UNIT_BIT:
+ unit = GS_UNIT_BIT;
+ break;
+ case SANE_UNIT_MM:
+ unit = GS_UNIT_MM;
+ break;
+ case SANE_UNIT_DPI:
+ unit = GS_UNIT_DPI;
+ break;
+ case SANE_UNIT_PERCENT:
+ unit = GS_UNIT_PERCENT;
+ break;
+ case SANE_UNIT_MICROSECOND:
+ unit = GS_UNIT_PERCENT;
+ break;
+ case SANE_UNIT_NONE:
+ default:
+ unit = GS_UNIT_NONE;
+ break;
+ }
enumclass = g_type_class_ref (GNOME_TYPE_SCAN_UNIT);
enumvalue = g_enum_get_value (enumclass, unit);
g_type_class_unref (enumclass);
/* VALUE TYPE*/
- switch (desc->type) {
- case SANE_TYPE_BOOL:
- type = G_TYPE_BOOLEAN;
- break;
- case SANE_TYPE_INT:
- type = G_TYPE_INT;
- break;
- case SANE_TYPE_FIXED:
- type = G_TYPE_DOUBLE;
- break;
- case SANE_TYPE_STRING:
- type = G_TYPE_STRING;
- break;
- case SANE_TYPE_GROUP:
- group = g_quark_from_string(desc->title);
- gs_debug ("\n");
- gs_debug (" -- Group ÂÂ%sÂÂ --", desc->title);
- type = G_TYPE_NONE;
- return NULL;
- break;
- case SANE_TYPE_BUTTON:
- gs_debug("// button : %s (%s)", desc->title, desc->desc);
- type = G_TYPE_NONE;
- return NULL;
- break;
- }
+ switch (desc->type) {
+ case SANE_TYPE_BOOL:
+ type = G_TYPE_BOOLEAN;
+ break;
+ case SANE_TYPE_INT:
+ type = G_TYPE_INT;
+ break;
+ case SANE_TYPE_FIXED:
+ type = G_TYPE_DOUBLE;
+ break;
+ case SANE_TYPE_STRING:
+ type = G_TYPE_STRING;
+ break;
+ case SANE_TYPE_GROUP:
+ group = g_quark_from_string(desc->title);
+ gs_debug ("\n");
+ gs_debug (" -- Group ÂÂ%sÂÂ --", desc->title);
+ type = G_TYPE_NONE;
+ return NULL;
+ break;
+ case SANE_TYPE_BUTTON:
+ gs_debug("// button : %s (%s)", desc->title, desc->desc);
+ type = G_TYPE_NONE;
+ return NULL;
+ break;
+ }
name = g_utf8_strlen(desc->name, 32) < 1 ?
g_strdup_printf("option-%i", unnamed++)
@@ -828,38 +831,38 @@
/* SPEC_TYPE */
- switch (desc->constraint_type) {
- /* RANGE */
- case SANE_CONSTRAINT_RANGE:
- spec_type = GS_TYPE_PARAM_RANGE;
- break;
+ switch (desc->constraint_type) {
+ /* RANGE */
+ case SANE_CONSTRAINT_RANGE:
+ spec_type = GS_TYPE_PARAM_RANGE;
+ break;
- /* ENUM */
- case SANE_CONSTRAINT_WORD_LIST:
- case SANE_CONSTRAINT_STRING_LIST:
- spec_type = GS_TYPE_PARAM_ENUM;
+ /* ENUM */
+ case SANE_CONSTRAINT_WORD_LIST:
+ case SANE_CONSTRAINT_STRING_LIST:
+ spec_type = GS_TYPE_PARAM_ENUM;
+ break;
+ case SANE_CONSTRAINT_NONE:
+ constraint = NULL;
+ switch (type) {
+ case G_TYPE_BOOLEAN:
+ spec_type = G_TYPE_PARAM_BOOLEAN;
break;
- case SANE_CONSTRAINT_NONE:
- constraint = NULL;
- switch (type) {
- case G_TYPE_BOOLEAN:
- spec_type = G_TYPE_PARAM_BOOLEAN;
- break;
- case G_TYPE_INT:
- spec_type = G_TYPE_PARAM_INT;
- break;
- case G_TYPE_DOUBLE:
- spec_type = G_TYPE_PARAM_DOUBLE;
- break;
- case G_TYPE_STRING:
- spec_type = G_TYPE_PARAM_STRING;
- break;
- default:
- spec_type = G_TYPE_NONE;
- break;
- }
+ case G_TYPE_INT:
+ spec_type = G_TYPE_PARAM_INT;
+ break;
+ case G_TYPE_DOUBLE:
+ spec_type = G_TYPE_PARAM_DOUBLE;
+ break;
+ case G_TYPE_STRING:
+ spec_type = G_TYPE_PARAM_STRING;
+ break;
+ default:
+ spec_type = G_TYPE_NONE;
break;
}
+ break;
+ }
if (type != G_TYPE_NONE) {
if (desc->cap & SANE_CAP_AUTOMATIC)
@@ -868,30 +871,30 @@
}
/* SPEC */
- if (spec_type == G_TYPE_PARAM_BOOLEAN) {
- spec = gs_param_spec_boolean (name, desc->title, desc->desc, group,
- g_value_get_boolean (default_value), flags);
- }
+ if (spec_type == G_TYPE_PARAM_BOOLEAN) {
+ spec = gs_param_spec_boolean (name, desc->title, desc->desc, group,
+ g_value_get_boolean (default_value), flags);
+ }
else if (spec_type == G_TYPE_PARAM_INT) {
spec = gs_param_spec_int(name, desc->title, desc->desc, group,
- G_MININT, G_MAXINT,
- g_value_get_int (default_value), flags);
+ G_MININT, G_MAXINT,
+ g_value_get_int (default_value), flags);
}
else if (spec_type == G_TYPE_PARAM_DOUBLE) {
spec = gs_param_spec_double (name, desc->title, desc->desc, group,
- G_MINDOUBLE, G_MAXDOUBLE,
- MIN (G_MAXDOUBLE, MAX (G_MINDOUBLE, g_value_get_double (default_value))),
- flags);
+ G_MINDOUBLE, G_MAXDOUBLE,
+ MIN (G_MAXDOUBLE, MAX (G_MINDOUBLE, g_value_get_double (default_value))),
+ flags);
}
else if (spec_type == G_TYPE_PARAM_STRING) {
spec = gs_param_spec_string (name, desc->title, desc->desc, group,
- dgettext ("sane-backends",
- g_value_get_string (default_value)),
- flags);
+ dgettext ("sane-backends",
+ g_value_get_string (default_value)),
+ flags);
}
else if (spec_type == GS_TYPE_PARAM_RANGE) {
/* init values */
- value = g_new0(GValue, 1);
+ value = g_new0(GValue, 1);
g_value_init (value, type);
vmin = g_new0(GValue, 1);
g_value_init (vmin, type);
@@ -901,99 +904,99 @@
g_value_init (vstep, type);
/* set values */
- switch (type) {
- case G_TYPE_INT:
- g_value_set_int (vmin, desc->constraint.range->min);
- g_value_set_int (vmax, desc->constraint.range->max);
- g_value_set_int (vstep, desc->constraint.range->quant);
- break;
- case G_TYPE_DOUBLE:
- g_value_set_double (vmin, SANE_UNFIX (desc->constraint.range->min));
- g_value_set_double (vmax, SANE_UNFIX (desc->constraint.range->max));
- g_value_set_double (vstep, SANE_UNFIX (desc->constraint.range->quant));
- break;
- }
+ switch (type) {
+ case G_TYPE_INT:
+ g_value_set_int (vmin, desc->constraint.range->min);
+ g_value_set_int (vmax, desc->constraint.range->max);
+ g_value_set_int (vstep, desc->constraint.range->quant);
+ break;
+ case G_TYPE_DOUBLE:
+ g_value_set_double (vmin, SANE_UNFIX (desc->constraint.range->min));
+ g_value_set_double (vmax, SANE_UNFIX (desc->constraint.range->max));
+ g_value_set_double (vstep, SANE_UNFIX (desc->constraint.range->quant));
+ break;
+ }
constraint = g_strdup_printf ("[%s;%s;%s]",
- g_strdup_value_contents (vmin),
- g_strdup_value_contents (vstep),
- g_strdup_value_contents (vmax));
+ g_strdup_value_contents (vmin),
+ g_strdup_value_contents (vstep),
+ g_strdup_value_contents (vmax));
/* create spec */
- spec = gs_param_spec_range(name, desc->title, desc->desc, group,
- vmin, vmax, vstep, default_value, flags);
+ spec = gs_param_spec_range(name, desc->title, desc->desc, group,
+ vmin, vmax, vstep, default_value, flags);
g_free (vmin);
g_free (vmax);
g_free (vstep);
}
/* ENUM */
- else if (spec_type == GS_TYPE_PARAM_ENUM) {
- value = g_new0(GValue, 1);
- g_value_init (value, type);
- constraint = "";
+ else if (spec_type == GS_TYPE_PARAM_ENUM) {
+ value = g_new0(GValue, 1);
+ g_value_init (value, type);
+ constraint = "";
- if (type == G_TYPE_STRING) {
- values = g_value_array_new (0);
- for (i = 0; desc->constraint.string_list[i]; i++) {
- g_value_set_static_string (value,
- desc->constraint.string_list[i]);
- g_value_array_append(values, value);
- }
- if (g_value_get_string (default_value) == NULL) {
- g_value_unset (default_value);
- g_free (default_value);
- default_value = values->values;
- }
- constraint = g_strdup_printf ("{\"%s\"}",
- g_strjoinv("\", \"",
- (gchar**) desc->constraint.string_list));
+ if (type == G_TYPE_STRING) {
+ values = g_value_array_new (0);
+ for (i = 0; desc->constraint.string_list[i]; i++) {
+ g_value_set_static_string (value,
+ desc->constraint.string_list[i]);
+ g_value_array_append(values, value);
}
- else {
- m = (gint) desc->constraint.word_list[0];
- values = g_value_array_new (m);
- for (i = 0; i < m; i++) {
- switch (type) {
- case G_TYPE_INT:
- g_value_set_int (value, desc->constraint.word_list[i+1]);
- constraint = g_strdup_printf("%s, %d", constraint,
- g_value_get_int (value));
- break;
- case G_TYPE_DOUBLE:
- g_value_set_double (value, SANE_UNFIX(desc->constraint.word_list[i+1]));
- constraint = g_strdup_printf("%s; %.2f", constraint,
- g_value_get_double (value));
- break;
- }
- g_value_array_append (values, value);
+ if (g_value_get_string (default_value) == NULL) {
+ g_value_unset (default_value);
+ g_free (default_value);
+ default_value = values->values;
+ }
+ constraint = g_strdup_printf ("{\"%s\"}",
+ g_strjoinv("\", \"",
+ (gchar**) desc->constraint.string_list));
+ }
+ else {
+ m = (gint) desc->constraint.word_list[0];
+ values = g_value_array_new (m);
+ for (i = 0; i < m; i++) {
+ switch (type) {
+ case G_TYPE_INT:
+ g_value_set_int (value, desc->constraint.word_list[i+1]);
+ constraint = g_strdup_printf("%s, %d", constraint,
+ g_value_get_int (value));
+ break;
+ case G_TYPE_DOUBLE:
+ g_value_set_double (value, SANE_UNFIX(desc->constraint.word_list[i+1]));
+ constraint = g_strdup_printf("%s; %.2f", constraint,
+ g_value_get_double (value));
+ break;
}
- constraint = g_strdup_printf("{%s}", constraint+2);
+ g_value_array_append (values, value);
}
- g_value_unset (value);
- g_free (value);
-
- spec = gs_param_spec_enum(name, desc->title, desc->desc, group,
- values, default_value, flags);
+ constraint = g_strdup_printf("{%s}", constraint+2);
}
+ g_value_unset (value);
+ g_free (value);
+
+ spec = gs_param_spec_enum(name, desc->title, desc->desc, group,
+ values, default_value, flags);
+ }
else if (spec_type == G_TYPE_NONE) {
return NULL;
}
/* common specs datas */
- if (spec) {
- g_param_spec_set_qdata (spec, GSANE_OPTION_DESC_QUARK, (gpointer) desc);
- gs_param_spec_set_group (spec, group);
- gs_param_spec_set_domain (spec, "sane-backends");
- gs_param_spec_set_unit (spec, unit);
- gs_param_spec_set_index(spec, (guint) n);
- }
+ if (spec) {
+ g_param_spec_set_qdata (spec, GSANE_OPTION_DESC_QUARK, (gpointer) desc);
+ gs_param_spec_set_group (spec, group);
+ gs_param_spec_set_domain (spec, "sane-backends");
+ gs_param_spec_set_unit (spec, unit);
+ gs_param_spec_set_index(spec, (guint) n);
+ }
gs_debug ("%s (%s):", desc->title, desc->name);
gs_debug (" %s %s (%s), %s",
- g_type_name(type), enumvalue->value_nick,
- g_type_name(spec_type), constraint);
+ g_type_name(type), enumvalue->value_nick,
+ g_type_name(spec_type), constraint);
gs_debug (" default = %s ; flags = {%s}",
- g_strdup_value_contents (default_value), sflags);
+ g_strdup_value_contents (default_value), sflags);
gs_debug ("%s", "");
g_free (name);
@@ -1011,14 +1014,14 @@
SANE_Int i;
status = sane_control_option (priv->handle, n, SANE_ACTION_SET_AUTO,
- NULL, &i);
+ NULL, &i);
}
GValue*
gsane_scanner_option_get_value (GSaneScanner *sane, GParamSpec *spec)
{
/* determine true value type using gs_param_value_set_default */
- GValue *default_value = g_new0 (GValue, 1);
+ GValue *default_value = g_new0 (GValue, 1);
GType type;
g_value_init (default_value, G_PARAM_SPEC_VALUE_TYPE (spec));
g_param_value_set_default (spec, default_value);
@@ -1027,8 +1030,8 @@
g_free (default_value);
return gss_option_get_value_by_index (sane,
- (SANE_Int) gs_param_spec_get_index (spec),
- type);
+ (SANE_Int) gs_param_spec_get_index (spec),
+ type);
}
@@ -1049,36 +1052,36 @@
status = sane_control_option(priv->handle, n, SANE_ACTION_GET_VALUE, v, &i);
switch (type) {
- case G_TYPE_BOOLEAN:
- g_value_set_boolean(value, *((gboolean*) v));
+ case G_TYPE_BOOLEAN:
+ g_value_set_boolean(value, *((gboolean*) v));
break;
- case G_TYPE_INT:
- g_value_set_int(value, *((gint*) v));
+ case G_TYPE_INT:
+ g_value_set_int(value, *((gint*) v));
break;
- case G_TYPE_DOUBLE:
- g_value_set_double(value, SANE_UNFIX (*((SANE_Word*) v)));
+ case G_TYPE_DOUBLE:
+ g_value_set_double(value, SANE_UNFIX (*((SANE_Word*) v)));
break;
- case G_TYPE_FLOAT:
- g_value_set_float(value, SANE_UNFIX (*((SANE_Word*) v)));
+ case G_TYPE_FLOAT:
+ g_value_set_float(value, SANE_UNFIX (*((SANE_Word*) v)));
break;
- case G_TYPE_STRING:
- g_value_set_string (value, g_strdup(v));
+ case G_TYPE_STRING:
+ g_value_set_string (value, g_strdup(v));
break;
- default:
- g_warning ("%s: Can't retrieve value of type %s for option %s.",
- G_STRLOC,
- g_type_name(type),
- desc->name);
+ default:
+ g_warning ("%s: Can't retrieve value of type %s for option %s.",
+ G_STRLOC,
+ g_type_name(type),
+ desc->name);
break;
}
/*
- if (i & SANE_INFO_RELOAD_OPTIONS) {
- gs_debug ("Option reload needed for %s !", desc->name);
- }
+ if (i & SANE_INFO_RELOAD_OPTIONS) {
+ gs_debug ("Option reload needed for %s !", desc->name);
+ }
*/
- return value;
+ return value;
}
/* returns TRUE if we need to reload options. */
@@ -1098,33 +1101,33 @@
return 0;
switch (G_VALUE_TYPE (value)) {
- case G_TYPE_BOOLEAN:
- boolean = g_value_get_boolean (value);
+ case G_TYPE_BOOLEAN:
+ boolean = g_value_get_boolean (value);
v = &boolean;
break;
- case G_TYPE_INT:
- word = g_value_get_int (value);
+ case G_TYPE_INT:
+ word = g_value_get_int (value);
v = &word;
break;
- case G_TYPE_DOUBLE:
- word = SANE_FIX (g_value_get_double (value));
+ case G_TYPE_DOUBLE:
+ word = SANE_FIX (g_value_get_double (value));
v = &word;
break;
- case G_TYPE_FLOAT:
- word = SANE_FIX (g_value_get_float (value));
- v = &word;
+ case G_TYPE_FLOAT:
+ word = SANE_FIX (g_value_get_float (value));
+ v = &word;
break;
- case G_TYPE_STRING:
- v = g_value_dup_string (value);
+ case G_TYPE_STRING:
+ v = g_value_dup_string (value);
break;
}
gs_debug ("setting '%s' to %s",
- g_param_spec_get_name (spec),
- g_strdup_value_contents(value));
+ g_param_spec_get_name (spec),
+ g_strdup_value_contents(value));
status = sane_control_option (GET_PRIVATE (gss)->handle, n,
- SANE_ACTION_SET_VALUE, v, &i);
+ SANE_ACTION_SET_VALUE, v, &i);
return i;
}
@@ -1141,7 +1144,7 @@
mp = g_param_spec_get_qdata (spec, GSANE_META_PARAM_QUARK);
value = gnome_scan_settings_get (priv->settings,
- g_param_spec_get_name (spec));
+ g_param_spec_get_name (spec));
i = mp ? meta_param_set_value (mp, spec, priv->settings) : gsane_scanner_option_set_value (gss, spec, value);
@@ -1154,8 +1157,8 @@
if (value0)
g_value_copy (value0, value);
gnome_scan_settings_set (priv->settings,
- g_param_spec_get_name (spec),
- value);
+ g_param_spec_get_name (spec),
+ value);
priv->changed = TRUE;
gs_debug (" exact value = %s", g_strdup_value_contents (value));
}
@@ -1177,7 +1180,7 @@
if (flags != pspec->flags) {
gs_debug (G_STRLOC ": %s %sabled", g_param_spec_get_name (pspec),
- (flags & G_PARAM_WRITABLE ? "en" : "dis"));
+ (flags & G_PARAM_WRITABLE ? "en" : "dis"));
pspec->flags = flags;
gnome_scan_plugin_params_changed (GNOME_SCAN_PLUGIN (gss), pspec);
}
@@ -1189,14 +1192,14 @@
MetaParam **dest = g_ptr_array_index (arg, 1);
GParamSpec *spec = g_ptr_array_index (arg, 2);
if (gss_option_name_matches_array (spec,
- (const gchar**) meta_param_get_options_names (mp))) {
- *dest = mp;
- }
+ (const gchar**) meta_param_get_options_names (mp))) {
+ *dest = mp;
+ }
}
static void
gss_mp_foreach_add_param (const gchar* key, MetaParam *mp, GSaneScanner *gss)
{
/* ask MetaParam to add its sub params to gss */
- meta_param_get_params (mp);
+ meta_param_get_params (mp);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]