gnome-scan r531 - in trunk: . lib modules
- From: bersace svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-scan r531 - in trunk: . lib modules
- Date: Wed, 27 Feb 2008 19:14:35 +0000 (GMT)
Author: bersace
Date: Wed Feb 27 19:14:34 2008
New Revision: 531
URL: http://svn.gnome.org/viewvc/gnome-scan?rev=531&view=rev
Log:
Added MetaParamPreview.
Modified:
trunk/ChangeLog
trunk/lib/gnome-scan-dialog.c
trunk/modules/gsane-meta-param.c
trunk/modules/gsane-meta-param.h
trunk/modules/gsane-scanner.c
trunk/modules/gsane-scanner.h
Modified: trunk/lib/gnome-scan-dialog.c
==============================================================================
--- trunk/lib/gnome-scan-dialog.c (original)
+++ trunk/lib/gnome-scan-dialog.c Wed Feb 27 19:14:34 2008
@@ -1276,9 +1276,8 @@
GnomeScanSettings *settings = gnome_scan_job_get_settings (priv->preview_job);
/* first, restore settings */
+ gnome_scan_settings_set_boolean (settings, "preview", FALSE);
gnome_scan_settings_set (settings, "resolution", priv->saved_res);
- gnome_scan_settings_set (settings, "origin", priv->saved_origin);
- gnome_scan_settings_set (settings, "paper-size", priv->saved_paper_size);
/* restore UI */
GTK_WIDGET_SET_VISIBLE (priv->preview_acquisition_box, FALSE);
@@ -1327,8 +1326,8 @@
GTK_WIDGET_SET_VISIBLE(priv->preview_box, FALSE);
/* CONFIGURE */
-
- /* USE 50dpi RESOLUTION */
+
+ /* USE hard coded RESOLUTION */
priv->saved_res = gnome_scan_settings_get (settings, "resolution");
/* transform to int or double */
pspec = gnome_scan_plugin_params_lookup (GNOME_SCAN_PLUGIN (scanner), "resolution");
@@ -1337,31 +1336,14 @@
g_param_value_set_default (pspec, value);
g_value_transform (priv->preview_res, value);
gnome_scan_settings_set (settings, "resolution", value);
- gnome_scan_plugin_configure (GNOME_SCAN_PLUGIN (scanner), settings);
- g_value_unset (value);
-
- /* USE manual max PAPER SIZE */
- priv->saved_paper_size = gnome_scan_settings_get (settings, "paper-size");
- g_value_init (value, G_VALUE_TYPE (priv->saved_paper_size));
- g_value_copy (priv->saved_paper_size, value);
- pspec = gnome_scan_plugin_params_lookup (GNOME_SCAN_PLUGIN (scanner), "paper-size");
- /* ugly, should rely on papername "maximal" */
- g_value_set_boxed (value,
- GS_PARAM_SPEC_PAPER_SIZE (pspec)->enumeration->next->data);
- gnome_scan_settings_set (settings, "paper-size", value);
g_value_unset (value);
-
- priv->saved_origin = gnome_scan_settings_get (settings, "origin");
- g_value_init (value, G_VALUE_TYPE (priv->saved_origin));
- g_value_copy (priv->saved_origin, value);
- g_value_set_pointer (value, &origin);
- gnome_scan_settings_set (settings, "origin", value);
- g_value_unset (value);
-
g_free (value);
+ /* asking preview mode */
+ gnome_scan_settings_set_boolean (settings, "preview", TRUE);
gnome_scan_job_configure (priv->preview_job);
+ /* TRIGGER */
g_timeout_add (42, (GSourceFunc) gsd_preview_monitor, gsd);
g_thread_create ((GThreadFunc) gnome_scan_job_run_once,
priv->preview_job, FALSE, &error);
Modified: trunk/modules/gsane-meta-param.c
==============================================================================
--- trunk/modules/gsane-meta-param.c (original)
+++ trunk/modules/gsane-meta-param.c Wed Feb 27 19:14:34 2008
@@ -400,7 +400,6 @@
/* setup translator for integer/double handling */
GValue *real = g_new0 (GValue, 1);
GValue *trans = g_new0 (GValue, 1);
- GValue *v;
g_value_init (real, G_TYPE_DOUBLE);
g_value_init (trans, G_PARAM_SPEC_VALUE_TYPE (mpps->tl_x));
g_param_value_set_default (mpps->tl_x, trans);
@@ -444,6 +443,9 @@
MetaParamPaperSize *mpps = GSANE_META_PARAM_PAPER_SIZE (mp);
gint w, h;
guint unit;
+
+ if (gnome_scan_settings_get_boolean(mp->settings, "preview"))
+ return 0;
const gchar*name = g_param_spec_get_name (spec);
mpps->rotation = gnome_scan_settings_get_int (mp->settings,
@@ -721,3 +723,104 @@
{
return NULL;
}
+
+
+/* PREVIEW */
+/* TODO: handle speed */
+GSANE_DEFINE_META_PARAM(Preview, preview, "preview", "preview");
+
+static void
+meta_param_preview_init (MetaParam *mp)
+{
+ MetaParamPreview *mpp = GSANE_META_PARAM_PREVIEW (mp);
+ mpp->emulate = TRUE;
+}
+
+static void
+meta_param_preview_finalize (MetaParam *mp)
+{
+ /*MetaParamPreview *mpp = GSANE_META_PARAM_PREVIEW (mp);*/
+}
+
+static void
+meta_param_preview_add_param (MetaParam *mp, GParamSpec *spec)
+{
+ MetaParamPreview *mpp = GSANE_META_PARAM_PREVIEW (mp);
+ mpp->preview = spec;
+ mpp->emulate = FALSE;
+}
+
+static gboolean
+meta_param_preview_get_params (MetaParam *mp)
+{
+ MetaParamPreview *mpp = GSANE_META_PARAM_PREVIEW (mp);
+ g_debug(__FUNCTION__);
+ if (!mpp->preview) {
+ g_debug(G_STRLOC ": Emulate preview");
+ mpp->preview = gs_param_spec_boolean ("preview",
+ N_("Preview"),
+ N_("Preview mode"),
+ g_quark_from_static_string ("Temporary"),
+ FALSE,
+ G_PARAM_READABLE
+ | G_PARAM_WRITABLE);
+ gs_param_spec_set_index (mpp->preview, 64); /* always last ? */
+
+ }
+ gs_param_spec_set_unit (mpp->preview, GS_UNIT_NONE);
+ g_param_spec_set_qdata (mpp->preview, GSANE_META_PARAM_QUARK, mp);
+ gnome_scan_plugin_params_add (GNOME_SCAN_PLUGIN (mp->gss),
+ mpp->preview);
+ return TRUE;
+}
+
+static SANE_Int
+meta_param_preview_set_value (MetaParam *mp, GParamSpec *spec, GValue *value)
+{
+ MetaParamPreview *mpp = GSANE_META_PARAM_PREVIEW (mp);
+ MetaParamPaperSize *mpps = GSANE_META_PARAM_PAPER_SIZE (gsane_scanner_get_meta_param(mp->gss,
+ "paper_size"));
+ SANE_Int i = 0;
+ mpp->preview_mode = g_value_get_boolean (value);
+
+ if (mpp->preview_mode) {
+ if (mpp->emulate) {
+ g_debug("emulating preview");
+ /* area */
+#define set_opt(opt, borne) i=i|gsane_scanner_option_set_value (mp->gss, opt,GS_PARAM_SPEC_RANGE(opt)->borne)
+
+ set_opt(mpps->tl_x, minimum);
+ set_opt(mpps->tl_y, minimum);
+ set_opt(mpps->br_x, maximum);
+ set_opt(mpps->br_y, maximum);
+
+#undef set_opt
+
+ /* TODO: speed */
+ }
+ else {
+ g_debug("passing preview");
+ gsane_scanner_option_set_value (mp->gss, spec, value);
+ }
+ }
+
+ return i;
+}
+
+static GValue*
+meta_param_preview_get_value (MetaParam *mp, GParamSpec *spec)
+{
+ MetaParamPreview *mpp = GSANE_META_PARAM_PREVIEW (mp);
+ GValue *value;
+
+ if (mpp->emulate) {
+ value = g_new0(GValue, 1);
+ g_value_init(value, G_TYPE_BOOLEAN);
+ g_value_set_boolean (value, mpp->preview_mode);
+ }
+ else {
+ value = gsane_scanner_option_get_value (mp->gss, spec);
+ }
+
+ return value;
+}
Modified: trunk/modules/gsane-meta-param.h
==============================================================================
--- trunk/modules/gsane-meta-param.h (original)
+++ trunk/modules/gsane-meta-param.h Wed Feb 27 19:14:34 2008
@@ -153,6 +153,26 @@
GType meta_param_source_get_type (void) G_GNUC_CONST;
MetaParam* meta_param_source (GSaneScanner *gss);
+/* PREVIEW */
+/* emulate preview option for backend not having it.
+ */
+#define GSANE_TYPE_META_PARAM_PREVIEW (meta_param_preview_get_type ())
+#define GSANE_META_PARAM_PREVIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSANE_TYPE_META_PARAM_PREVIEW, MetaParamPreview))
+
+typedef struct _MetaParamPreview MetaParamPreview;
+struct _MetaParamPreview
+{
+ MetaParam parent_instance;
+ gboolean emulate;
+ gboolean preview_mode;
+
+ /* saved option */
+ GParamSpec* preview;
+};
+
+GType meta_param_preview_get_type (void) G_GNUC_CONST;
+MetaParam* meta_param_preview (GSaneScanner *gss);
+
G_END_DECLS
Modified: trunk/modules/gsane-scanner.c
==============================================================================
--- trunk/modules/gsane-scanner.c (original)
+++ trunk/modules/gsane-scanner.c Wed Feb 27 19:14:34 2008
@@ -641,7 +641,6 @@
g_object_unref (priv->buffer);
g_free (priv->format);
priv->format = NULL;
-
priv->buffer = NULL;
}
@@ -663,6 +662,7 @@
gss_mp_new(paper_size, gss);
gss_mp_new(source, gss);
+ gss_mp_new(preview, gss);
#undef gss_mp_new
@@ -686,7 +686,6 @@
NULL
};
static const gchar*hidden_options[] = {
- "preview",
NULL
};
@@ -1102,6 +1101,14 @@
return value;
}
+gpointer*
+gsane_scanner_get_meta_param(GSaneScanner *gss,
+ gchar *name)
+{
+ GSaneScannerPrivate *priv = GET_PRIVATE(gss);
+ return g_hash_table_lookup (priv->meta_params, name);
+}
+
/* returns TRUE if we need to reload options. */
SANE_Int
gsane_scanner_option_set_value (GSaneScanner *gss, GParamSpec *spec, GValue *value)
@@ -1191,7 +1198,8 @@
guint n = gs_param_spec_get_index (pspec);
desc = sane_get_option_descriptor(priv->handle, n);
- if (SANE_OPTION_IS_ACTIVE (desc->cap)) {
+
+ if (desc && SANE_OPTION_IS_ACTIVE (desc->cap)) {
flags = flags | G_PARAM_WRITABLE;
g_param_spec_set_qdata (pspec, GSANE_OPTION_DESC_QUARK, (gpointer) desc);
}
Modified: trunk/modules/gsane-scanner.h
==============================================================================
--- trunk/modules/gsane-scanner.h (original)
+++ trunk/modules/gsane-scanner.h Wed Feb 27 19:14:34 2008
@@ -61,6 +61,8 @@
SANE_Int gsane_scanner_option_set_value (GSaneScanner *gss,
GParamSpec *spec,
GValue *value);
+gpointer* gsane_scanner_get_meta_param(GSaneScanner *gss,
+ gchar *name);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]