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



Author: bersace
Date: Wed Jan  7 21:07:23 2009
New Revision: 761
URL: http://svn.gnome.org/viewvc/gnome-scan?rev=761&view=rev

Log:
Added support for page orientation in GSane.

Modified:
   trunk/ChangeLog
   trunk/modules/gsane/gsane-option-area.c

Modified: trunk/modules/gsane/gsane-option-area.c
==============================================================================
--- trunk/modules/gsane/gsane-option-area.c	(original)
+++ trunk/modules/gsane/gsane-option-area.c	Wed Jan  7 21:07:23 2009
@@ -64,15 +64,27 @@
 	GnomeScanEnumValue* value;
 	gdouble tl_x, tl_y, br_x, br_y;
 	GnomeScanPoint *origin;
-	
+	GtkPageOrientation orientation;
+
 	gnome_scan_option_enum_get_value(GNOME_SCAN_OPTION_ENUM(self->priv->paper_size), &value);
 	ps = g_value_get_boxed(&value->value);
+	gnome_scan_option_enum_get_value(GNOME_SCAN_OPTION_ENUM(self->priv->page_orientation), &value);
+	orientation = g_value_get_enum(&value->value);
 	origin = gnome_scan_option_pointer_get_value(GNOME_SCAN_OPTION_POINTER(self->priv->origin));
-
+	
 	tl_x = origin->x;
 	tl_y = origin->y;
-	br_x = origin->x + gtk_paper_size_get_width(ps, GTK_UNIT_MM);
-	br_y = origin->x + gtk_paper_size_get_height(ps, GTK_UNIT_MM);
+	if (orientation == GTK_PAGE_ORIENTATION_PORTRAIT
+	    || g_str_equal(gtk_paper_size_get_name(ps), "max")) {
+		br_x = origin->x + gtk_paper_size_get_width(ps, GTK_UNIT_MM);
+		br_y = origin->y + gtk_paper_size_get_height(ps, GTK_UNIT_MM);
+	}
+	else {
+		br_x = origin->x + gtk_paper_size_get_height(ps, GTK_UNIT_MM);
+		br_y = origin->y + gtk_paper_size_get_width(ps, GTK_UNIT_MM);
+	}
+
+	g_debug("Scan (%.2f ; %.2f) (%.2f ; %.2f)", tl_x, tl_y, br_x, br_y);
 
 	/* TODO: convert to non MM unit */
 	gsane_option_handler_set_double(handler, self->priv->tl_x_desc, self->priv->tl_x_index, tl_x, NULL);
@@ -82,7 +94,7 @@
 }
 
 static void
-gsane_option_area_paper_size_changed(GSaneOptionArea* self, GParamSpec* pspec, GObject* option)
+gsane_option_area_option_changed(GSaneOptionArea* self, GParamSpec* pspec, GObject* option)
 {
 	gsane_option_area_update(self);
 }
@@ -169,7 +181,49 @@
 	self->priv->paper_size = GNOME_SCAN_OPTION(gnome_scan_option_enum_new("paper-size", _("Paper-Size"), _("Paper-Size"), GNOME_SCAN_OPTION_GROUP_FORMAT, GETTEXT_PACKAGE,
 									      values->data, values, GNOME_SCAN_OPTION_HINT_PRIMARY));
 	gnome_scan_node_install_option(GNOME_SCAN_NODE(handler->scanner), self->priv->paper_size);
-	g_signal_connect_swapped(self->priv->paper_size, "notify::value", G_CALLBACK(gsane_option_area_paper_size_changed), self);
+	g_signal_connect_swapped(self->priv->paper_size, "notify::value", G_CALLBACK(gsane_option_area_option_changed), self);
+}
+
+
+static GSList*
+gsane_option_area_add_orientation(GSaneOptionArea* self, GSList* values, GtkPageOrientation orientation, const gchar* stock_id)
+{
+	GnomeScanEnumValue evalue;
+	GValue* value;
+
+	value = g_new0(GValue, 1);
+	g_value_init(value, GTK_TYPE_PAGE_ORIENTATION);
+	g_value_set_enum(value, orientation);
+	gnome_scan_enum_value_init(&evalue, value, stock_id, NULL);
+	values = g_slist_append(values, gnome_scan_enum_value_dup(&evalue));
+	gnome_scan_enum_value_destroy(&evalue);
+	g_value_reset(value);
+	g_free(value);
+
+	return values;
+}
+
+static void
+gsane_option_area_install_page_orientation(GSaneOptionArea *self)
+{
+	GSaneOptionHandler* handler = (GSaneOptionHandler*)self;
+	GSList* values = NULL;
+	GnomeScanEnumValue*value;
+	GtkPaperSize *ps;
+	gdouble width, height;
+
+	gnome_scan_option_enum_get_value(GNOME_SCAN_OPTION_ENUM(self->priv->paper_size), &value);
+	ps = g_value_get_boxed(&value->value);
+	width = gtk_paper_size_get_width(ps, GTK_UNIT_MM);
+	height= gtk_paper_size_get_height(ps, GTK_UNIT_MM);
+
+	values = gsane_option_area_add_orientation(self, values, GTK_PAGE_ORIENTATION_PORTRAIT, GTK_STOCK_ORIENTATION_PORTRAIT);
+	values = gsane_option_area_add_orientation(self, values, GTK_PAGE_ORIENTATION_LANDSCAPE, GTK_STOCK_ORIENTATION_LANDSCAPE);
+	value = width <= height ? values->data : values->next->data;
+	self->priv->page_orientation = GNOME_SCAN_OPTION(gnome_scan_option_enum_new("page-orientation", _("Page Orientation"), _("Page orientation"), GNOME_SCAN_OPTION_GROUP_FORMAT, GETTEXT_PACKAGE,
+										    value, values, GNOME_SCAN_OPTION_HINT_PRIMARY));
+	gnome_scan_node_install_option(GNOME_SCAN_NODE(handler->scanner), self->priv->page_orientation);
+	g_signal_connect_swapped(self->priv->page_orientation, "notify::value", G_CALLBACK(gsane_option_area_option_changed), self);
 }
 
 static void
@@ -185,6 +239,7 @@
 	/* we have matched all SANE option, actually install high level options */
 	gsane_option_area_install_origin(self);
 	gsane_option_area_install_paper_size(self);
+	gsane_option_area_install_page_orientation(self);
 }
 
 static void



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