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



Author: bersace
Date: Sun Dec 14 13:26:02 2008
New Revision: 672
URL: http://svn.gnome.org/viewvc/gnome-scan?rev=672&view=rev

Log:
Implemented SANE_Status -> GError translation.

Modified:
   trunk/ChangeLog
   trunk/modules/gsane/gsane-common.c
   trunk/modules/gsane/gsane-common.h

Modified: trunk/modules/gsane/gsane-common.c
==============================================================================
--- trunk/modules/gsane/gsane-common.c	(original)
+++ trunk/modules/gsane/gsane-common.c	Sun Dec 14 13:26:02 2008
@@ -20,8 +20,59 @@
  * 	Boston, MA  02110-1301, USA.
  */
 
+#if	HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib/gi18n-lib.h>
 #include "gsane-common.h"
 
+GQuark
+gsane_sane_error_quark()
+{
+	return g_quark_from_static_string("gsane-sane-error");
+}
+
+GError*
+gsane_error_new_from_status(SANE_Status status)
+{
+	if (status == SANE_STATUS_GOOD)
+		return NULL;
+
+	return g_error_new_literal(GSANE_ERROR, status, S_(sane_strstatus(status)));
+}
+
+void
+gsane_propagate_status(GError **dest, SANE_Status status)
+{
+	if (dest == NULL) {
+		g_warning("Unhandled SANE error : %s", S_(sane_strstatus(status)));
+		return;
+	}
+
+	g_propagate_error(dest, gsane_error_new_from_status(status));
+}
+
+void
+gsane_propagate_prefixed_status(GError **dest, SANE_Status status, const gchar* format, ...)
+{
+	gchar* prefix;
+
+	va_list ap;
+	va_start (ap, format);
+	prefix = g_strdup_vprintf(format, ap);
+	va_end (ap);
+
+	if (dest == NULL) {
+		g_warning("%s: Unhandled SANE error : %s", prefix, S_(sane_strstatus(status)));
+		return;
+	}
+
+	g_propagate_error(dest, gsane_error_new_from_status(status));
+	g_prefix_error(dest, prefix);
+}
+
+
 gboolean
 gsane_str_matches_strv (const gchar *name, const gchar **names)
 {

Modified: trunk/modules/gsane/gsane-common.h
==============================================================================
--- trunk/modules/gsane/gsane-common.h	(original)
+++ trunk/modules/gsane/gsane-common.h	Sun Dec 14 13:26:02 2008
@@ -24,18 +24,44 @@
 #define _GSANE_COMMON_H_
 
 #include <glib.h>
+#include <sane/sane.h>
 
 G_BEGIN_DECLS
 
+#define	SANE_GETTEXT_PACKAGE	"sane-backends"
+#define S_(s)					dgettext(SANE_GETTEXT_PACKAGE, s)
+
 #if	DEBUG
 #define	gs_debug(...)	g_debug (__VA_ARGS__)
 #else
 #define gs_debug(...)
 #endif
 
-#define	SANE_GETTEXT_PACKAGE	"sane-backends"
+#define	GSANE_BOOLEAN_TO_STRING(b)	(b ? "TRUE" : "FALSE")
+#define GSANE_ACTION_TO_STRING(a)	(a == SANE_ACTION_GET_VALUE ? "get" : (a == SANE_ACTION_SET_VALUE ? "set" : (a == SANE_ACTION_SET_AUTO ? "auto-set" : "<unknown>")))
+
+#define GSANE_ERROR	gsane_sane_error_quark()
 
-gboolean	gsane_str_matches_strv (const gchar *name, const gchar **names);
+typedef enum {
+	GSANE_ERROR_UNSUPPORTED		= SANE_STATUS_UNSUPPORTED,
+	GSANE_ERROR_CANCELLED		= SANE_STATUS_CANCELLED,
+    GSANE_ERROR_BUSY			= SANE_STATUS_DEVICE_BUSY,
+    GSANE_ERROR_INVALID_VALUE	= SANE_STATUS_INVAL,
+    GSANE_ERROR_JAMMED			= SANE_STATUS_JAMMED,
+    GSANE_ERROR_NO_DOCS			= SANE_STATUS_NO_DOCS,
+    GSANE_ERROR_COVER_OPEN		= SANE_STATUS_COVER_OPEN,
+    GSANE_ERROR_IO_ERROR		= SANE_STATUS_IO_ERROR,
+    GSANE_ERROR_NO_MEM			= SANE_STATUS_NO_MEM,
+    GSANE_ERROR_DENIED			= SANE_STATUS_ACCESS_DENIED,
+	GSANE_ERROR_OPTION_INACTIVE,
+	GSANE_ERROR_OPTION_READONLY,
+} GSaneError;
+
+GQuark gsane_sane_error_quark(void) G_GNUC_CONST;
+GError* gsane_error_new_from_status(SANE_Status status);
+void gsane_propagate_status(GError **dest, SANE_Status status);
+void gsane_propagate_prefixed_status(GError **dest, SANE_Status status, const gchar* format, ...);
+gboolean gsane_str_matches_strv (const gchar *name, const gchar **names);
 
 G_END_DECLS
 



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