Index: gnome-panel-screenshot.c
===================================================================
RCS file: /cvs/gnome/gnome-panel/gnome-panel/gnome-panel-screenshot.c,v
retrieving revision 1.73
diff -u -r1.73 gnome-panel-screenshot.c
--- gnome-panel-screenshot.c	8 Aug 2004 22:21:58 -0000	1.73
+++ gnome-panel-screenshot.c	22 Sep 2004 09:23:59 -0000
@@ -40,6 +40,11 @@
 #include <X11/Xutil.h>
 #include <X11/cursorfont.h>
 #include <X11/Xmu/WinUtil.h>
+#include <libgnomeprint/gnome-print.h>
+#include <libgnomeprint/gnome-print-config.h>
+#include <libgnomeprint/gnome-print-job.h>
+#include <libgnomeprintui/gnome-print-job-preview.h>
+#include <libgnomeprintui/gnome-print-dialog.h>
 
 #ifdef HAVE_X11_EXTENSIONS_SHAPE_H
 #include <X11/extensions/shape.h>
@@ -81,6 +86,7 @@
 void on_ok_button_clicked (GtkWidget *widget, gpointer data);
 void on_cancel_button_clicked (GtkWidget *widget, gpointer data);
 void on_help_button_clicked (GtkWidget *widget, gpointer data);
+void on_print_button_clicked (GtkWidget *widget, gpointer data);
 int on_save_entry_key_press_event (GtkWidget *widget, GdkEventKey *key);
 int on_toplevel_key_press_event (GtkWidget *widget, GdkEventKey *key);
 
@@ -719,6 +725,147 @@
 
 }
 
+#define PRINT_CONFIG_FILE "screenshot-print-config"
+
+static GnomePrintConfig *
+load_print_config_from_file ()
+{
+        gchar *file_name;
+        gboolean res;
+        gchar *contents;
+        GnomePrintConfig *config;
+                                                                                
+        file_name = gnome_util_home_file (PRINT_CONFIG_FILE);
+                                                                                
+        res = g_file_get_contents (file_name, &contents, NULL, NULL);
+        g_free (file_name);
+                                                                                
+        if (res)
+        {
+                config = gnome_print_config_from_string (contents, 0);
+                g_free (contents);
+        }
+        else
+                config = gnome_print_config_default ();
+                                                                                
+        return config;
+}
+                                                                                
+static void
+save_print_config_to_file (GnomePrintConfig *config)
+{
+        gint fd;
+        gchar *str;
+        gint bytes;
+        gchar *file_name;
+        gboolean res;
+                                                                                
+        g_return_if_fail (config != NULL);
+                                                                                
+        str = gnome_print_config_to_string (config, 0);
+        g_return_if_fail (str != NULL);
+                                                                                
+        file_name = gnome_util_home_file (PRINT_CONFIG_FILE);
+                                                                                
+        fd = open (file_name, O_WRONLY | O_CREAT | O_TRUNC, 0600);
+        g_free (file_name);
+                                                                                
+        if (fd == -1)
+                goto save_error;
+                                                                                
+        bytes = strlen (str);
+                                                                                
+        /* Save the file content */
+        res = (write (fd, str, bytes) == bytes);
+                                                                                
+        close (fd);
+                                                                                
+        if (!res)
+                goto save_error;
+                                                                                
+        g_free (str);
+                                                                                
+        return;
+                                                                                
+save_error:
+                                                                                
+        g_message ("cannot save print config file.");
+                                                                                
+        g_free (str);
+}
+                                                                                
+void
+on_print_button_clicked (GtkWidget *widget, gpointer data) 
+{
+        GnomePrintConfig *config;
+        GnomePrintJob *job;
+        GnomePrintContext *gpc;
+        guchar *p;
+        int pw, ph, rs;
+        gdouble ppw, pph, rw, rh, rmin;
+        gboolean has_alpha;
+        GtkWidget *dialog;
+        gint response;
+        gchar *orientation;
+        
+        config = load_print_config_from_file ();
+        job = gnome_print_job_new (config);
+        dialog = gnome_print_dialog_new (job, "Print Setup", 0);
+        gpc = gnome_print_job_get_context (job);
+
+        response = gnome_print_dialog_run (GNOME_PRINT_DIALOG (dialog));
+        gtk_widget_destroy (dialog);
+        if (response == GNOME_PRINT_DIALOG_RESPONSE_CANCEL) {
+                g_print ("Printing was canceled\n");
+                return;
+        }
+
+        save_print_config_to_file (config);
+        gnome_print_beginpage (gpc, NULL);
+
+        p = gdk_pixbuf_get_pixels (screenshot);
+        pw = gdk_pixbuf_get_width (screenshot);
+        ph = gdk_pixbuf_get_height (screenshot);
+        rs = gdk_pixbuf_get_rowstride (screenshot);
+        has_alpha = gdk_pixbuf_get_has_alpha (screenshot);
+
+        gnome_print_config_get_length (config,
+                        GNOME_PRINT_KEY_PAPER_WIDTH, &ppw, NULL);
+        gnome_print_config_get_length (config,
+                        GNOME_PRINT_KEY_PAPER_HEIGHT, &pph, NULL);
+        orientation = gnome_print_config_get (config, 
+                        GNOME_PRINT_KEY_ORIENTATION);
+        if (!strcmp (orientation, "R90") || !strcmp (orientation, "R270")) {
+                gdouble tmp;
+                tmp = ppw; ppw = pph; pph = tmp;
+        }
+
+        rw = ppw / pw;
+        rh = pph / ph;
+        rmin = rw < rh ? rw : rh;
+
+        gnome_print_gsave (gpc);
+        gnome_print_translate (gpc, 30, 30);
+        gnome_print_scale (gpc, pw * rmin - 60, ph * rmin - 60);
+        if (has_alpha)
+                gnome_print_rgbaimage(gpc, p, pw, ph, rs);
+        else
+                gnome_print_rgbimage(gpc, p, pw, ph, rs);
+
+        gnome_print_grestore (gpc);
+        gnome_print_showpage (gpc);
+        gnome_print_job_close (job);
+
+        if (response == GNOME_PRINT_DIALOG_RESPONSE_PRINT)
+                gnome_print_job_print (job);
+        else
+                gtk_widget_show (gnome_print_job_preview_new (job, "Preview"));
+
+        g_object_unref (G_OBJECT (gpc));
+        g_object_unref (G_OBJECT (job));
+        g_object_unref (G_OBJECT (config));
+}
+
 int
 on_save_entry_key_press_event (GtkWidget    	*widget, 
 			       GdkEventKey	*key)
Index: gnome-panel-screenshot.glade
===================================================================
RCS file: /cvs/gnome/gnome-panel/gnome-panel/gnome-panel-screenshot.glade,v
retrieving revision 1.16
diff -u -r1.16 gnome-panel-screenshot.glade
--- gnome-panel-screenshot.glade	13 Mar 2004 14:16:50 -0000	1.16
+++ gnome-panel-screenshot.glade	22 Sep 2004 09:23:59 -0000
@@ -39,6 +39,20 @@
 	    </widget>
 	  </child>
 
+          <child>
+            <widget class="GtkButton" id="print_button">
+              <property name="visible">True</property>
+              <property name="can_default">True</property>
+              <property name="can_focus">True</property>
+              <property name="label">gtk-print</property>
+              <property name="use_stock">True</property>
+              <property name="relief">GTK_RELIEF_NORMAL</property>
+              <property name="focus_on_click">True</property>
+              <property name="response_id">-51</property>
+              <signal name="clicked" handler="on_print_button_clicked" last_modification_time="Mon, 20 Sep 2004 09:49:17 GMT"/>
+            </widget>
+          </child>
+
 	  <child>
 	    <widget class="GtkButton" id="cancel_button">
 	      <property name="visible">True</property>
