commit c41b9c0c628182affcb8633f14fb29c0401585eb
Author: Hib Eris <hib@hiberis.nl>
Date:   Wed Jun 3 17:26:49 2009 +0200

    Make use of gtk+-unix-print optional.

diff --git a/configure.ac b/configure.ac
index 0c9e38a..7d757e6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -99,15 +99,7 @@ esac
 AC_MSG_RESULT([$os_win32])
 AM_CONDITIONAL(OS_WIN32, test "$os_win32" = "yes")
 
-dnl Check dependencies
-
-# LIB_CFLAGS       for helpers and generic widgets. (libdocument, cut-and-paste)
-# BACKEND_CFLAGS   for backend implementations.
-# FRONTEND_CFLAGS  for frontend implementations. (properties, thumbnailer)
-# FRONTEND_LIBS
-# SHELL_CFLAGS     for shell implementation.
-# SHELL_LIBS
-
+dnl Specify required versions of dependencies
 DBUS_GLIB_REQUIRED=0.70
 GTK_REQUIRED=2.14.0
 GLIB_REQUIRED=2.18.0
@@ -118,12 +110,50 @@ AC_SUBST([GTK_REQUIRED])
 GNOME_ICON_THEME_REQUIRED=2.17.1
 LIBXML_REQUIRED=2.5.0
 
+dnl check for gtk+-unix-print
+gtk_unix_print_reqs="gtk+-unix-print-2.0 >= $GTK_REQUIRED"
+AC_ARG_ENABLE(
+	[gtk-unix-print],
+	AC_HELP_STRING([--disable-gtk-unix-print],
+			[Disable gtk-unix-print]),
+	[],
+	[enable_gtk_unix_print=check]
+)
+if test "x$enable_gtk_unix_print" != xno
+then
+	PKG_CHECK_MODULES(GTKUNIXPRINT, $gtk_unix_print_reqs,
+		enable_gtk_unix_print=yes,
+		if test "x$enable_gtk_unix_print" = xcheck
+		then
+			enable_gtk_unix_print=no
+			AC_MSG_WARN(The use of gtk+-unix-print is disabled since required library $gtk_unix_print_reqs was not found.)
+		else
+			AC_MSG_FAILURE(Gtk+-unix-print test failed: $GTKUNIXPRINT_PKG_ERRORS (--without-gtk-unix-print to disable))
+		fi
+	)
+fi
+if test "x$enable_gtk_unix_print" != xno
+then
+	AC_DEFINE([GTKUNIXPRINT_ENABLED], [1], [Enable gtk+-unix-print.])
+else
+	gtk_unix_print_reqs=""
+fi
+
+dnl Check dependencies
+
+# LIB_CFLAGS       for helpers and generic widgets. (libdocument, cut-and-paste)
+# BACKEND_CFLAGS   for backend implementations.
+# FRONTEND_CFLAGS  for frontend implementations. (properties, thumbnailer)
+# FRONTEND_LIBS
+# SHELL_CFLAGS     for shell implementation.
+# SHELL_LIBS
+
 PKG_CHECK_MODULES(LIBDOCUMENT, gtk+-2.0 >= $GTK_REQUIRED gio-2.0 >= $GLIB_REQUIRED)
 PKG_CHECK_MODULES(LIBVIEW, gtk+-2.0 >= $GTK_REQUIRED gthread-2.0 gio-2.0 >= $GLIB_REQUIRED)
 PKG_CHECK_MODULES(BACKEND, gtk+-2.0 >= $GTK_REQUIRED)
 PKG_CHECK_MODULES(FRONTEND_CORE, gtk+-2.0 >= $GTK_REQUIRED gthread-2.0 gio-2.0 >= $GLIB_REQUIRED)
-PKG_CHECK_MODULES(PREVIEWER, gtk+-2.0 >= $GTK_REQUIRED gtk+-unix-print-2.0 >= $GTK_REQUIRED gthread-2.0 gio-2.0 >= $GLIB_REQUIRED)
-PKG_CHECK_MODULES(SHELL_CORE, libxml-2.0 >= $LIBXML_REQUIRED gtk+-2.0 >= $GTK_REQUIRED gtk+-unix-print-2.0 >= $GTK_REQUIRED gio-2.0 >= $GLIB_REQUIRED gnome-icon-theme >= $GNOME_ICON_THEME_REQUIRED gthread-2.0)
+PKG_CHECK_MODULES(PREVIEWER, gtk+-2.0 >= $GTK_REQUIRED $gtk_unix_print_reqs gthread-2.0 gio-2.0 >= $GLIB_REQUIRED)
+PKG_CHECK_MODULES(SHELL_CORE, libxml-2.0 >= $LIBXML_REQUIRED gtk+-2.0 >= $GTK_REQUIRED $gtk_unix_print_reqs gio-2.0 >= $GLIB_REQUIRED gnome-icon-theme >= $GNOME_ICON_THEME_REQUIRED gthread-2.0)
 
 if test "$os_win32" = no; then
 	PKG_CHECK_MODULES(SMCLIENT, gtk+-2.0 gthread-2.0 sm >= 1.0.0)
@@ -295,11 +325,10 @@ AC_ARG_ENABLE(previewer,
 	esac],
 	[ENABLE_PREVIEWER=yes]) dnl Default value
 if test x$ENABLE_PREVIEWER = "xyes" ; then
-   PKG_CHECK_MODULES(PREVIEWER, gtk+-2.0 >= $GTK_REQUIRED gtk+-unix-print-2.0 >= $GTK_REQUIRED gthread-2.0 gio-2.0 >= $GLIB_REQUIRED,
-	             [ENABLE_PREVIEWER=yes],[ENABLE_PREVIEWER=no])
-   if test x$ENABLE_PREVIEWER = "xno" ; then
-      AC_MSG_WARN([Previewer support is disabled since gtk+-unix-print $GTK_REQUIRED or higher was not found])
-   fi
+	if test "x$enable_gtk_unix_print" != xyes; then
+		ENABLE_PREVIEWER=no
+		AC_MSG_WARN([Previewer support is disabled since no gtk+-unix-print is available.])
+	fi
 fi
 AM_CONDITIONAL(ENABLE_PREVIEWER, test x$ENABLE_PREVIEWER = "xyes")
 PREVIEWER_CFLAGS="$PREVIEWER_CFLAGS $DEBUG_FLAGS"
@@ -648,6 +677,7 @@ AC_OUTPUT
 echo "
 Configure summary:
         GConf Support......:  $with_gconf
+	GTK+ Unix Print....:  $enable_gtk_unix_print
 	Keyring Support....:  $WITH_KEYRING
 	DBUS Support.......:  $enable_dbus
 	Nautilus Plugin....:  $HAVE_NAUTILUS
diff --git a/shell/ev-print-operation.c b/shell/ev-print-operation.c
index 9f34fd7..664b5dc 100644
--- a/shell/ev-print-operation.c
+++ b/shell/ev-print-operation.c
@@ -21,7 +21,9 @@
 
 #include "ev-print-operation.h"
 
+#if GTKUNIXPRINT_ENABLED
 #include <gtk/gtkunixprint.h>
+#endif
 #include <glib/gi18n.h>
 #include <glib/gstdio.h>
 #include <unistd.h>
@@ -297,6 +299,7 @@ ev_print_operation_get_progress (EvPrintOperation *op)
 	return op->progress;
 }
 
+#if GTK_CHECK_VERSION (2, 17, 1) | GTKUNIXPRINT_ENABLED
 static void
 ev_print_operation_update_status (EvPrintOperation *op,
 				  gint              page,
@@ -322,6 +325,9 @@ ev_print_operation_update_status (EvPrintOperation *op,
 
 	g_signal_emit (op, signals[STATUS_CHANGED], 0);
 }
+#endif
+
+#if GTKUNIXPRINT_ENABLED
 
 /* Export interface */
 #define EV_TYPE_PRINT_OPERATION_EXPORT         (ev_print_operation_export_get_type())
@@ -1372,6 +1378,8 @@ ev_print_operation_export_class_init (EvPrintOperationExportClass *klass)
 	g_object_class->finalize = ev_print_operation_export_finalize;
 }
 
+#endif /* GTKUNIXPRINT_ENABLED */
+
 #if GTK_CHECK_VERSION (2, 17, 1)
 /* Print to cairo interface */
 #define EV_TYPE_PRINT_OPERATION_PRINT         (ev_print_operation_print_get_type())
@@ -1637,18 +1645,31 @@ ev_print_operation_print_class_init (EvPrintOperationPrintClass *klass)
 
 /* Factory method */
 EvPrintOperation *
-ev_print_operation_new (EvDocument *document)
+ev_print_operation_new (EvDocument *document, GError **err)
 {
 	EvPrintOperation *op;
 
+	g_return_val_if_fail (err == NULL || *err == NULL, NULL);
+
 #if GTK_CHECK_VERSION (2, 17, 1)
 	if (EV_IS_DOCUMENT_PRINT (document))
 		op = EV_PRINT_OPERATION (g_object_new (EV_TYPE_PRINT_OPERATION_PRINT,
 						       "document", document, NULL));
 	else
 #endif
+	{
+#if GTKUNIXPRINT_ENABLED
 		op = EV_PRINT_OPERATION (g_object_new (EV_TYPE_PRINT_OPERATION_EXPORT,
 						       "document", document, NULL));
+#else
+		g_set_error_literal (err,
+				     GTK_PRINT_ERROR,
+				     GTK_PRINT_ERROR_GENERAL,
+				     _("No print operation implemented for document type."));
+		op = NULL;
+#endif
+	}
 
 	return op;
+
 }
diff --git a/shell/ev-print-operation.h b/shell/ev-print-operation.h
index 6930f80..fa9befe 100644
--- a/shell/ev-print-operation.h
+++ b/shell/ev-print-operation.h
@@ -38,7 +38,8 @@ typedef struct _EvPrintOperationClass EvPrintOperationClass;
 
 GType             ev_print_operation_get_type               (void) G_GNUC_CONST;
 
-EvPrintOperation *ev_print_operation_new                    (EvDocument       *document);
+EvPrintOperation *ev_print_operation_new                    (EvDocument       *document,
+							     GError           **error);
 void              ev_print_operation_set_current_page       (EvPrintOperation *op,
 							     gint              current_page);
 void              ev_print_operation_set_print_settings     (EvPrintOperation *op,
diff --git a/shell/ev-window.c b/shell/ev-window.c
index ded233d..7f4db5f 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -2974,6 +2974,7 @@ ev_window_print_range (EvWindow *ev_window,
 		       gint      first_page,
 		       gint      last_page)
 {
+	GError  *error = NULL;
 	EvPrintOperation *op;
 	EvPageCache      *page_cache;
 	gint              current_page;
@@ -2985,7 +2986,13 @@ ev_window_print_range (EvWindow *ev_window,
 	if (!ev_window->priv->print_queue)
 		ev_window->priv->print_queue = g_queue_new ();
 
-	op = ev_print_operation_new (ev_window->priv->document);
+	op = ev_print_operation_new (ev_window->priv->document, &error);
+	if (error) {
+		ev_window_error_message (ev_window, error, "%s", _("Printing failed"));
+		g_error_free (error);
+		return;
+	}
+
 	g_signal_connect (op, "begin_print",
 			  G_CALLBACK (ev_window_print_operation_begin_print),
 			  (gpointer)ev_window);
