Moving Yelp to Gtk printing framework



Hey all,

This is the second thing I've been working on of late: Moving Yelp to
use Gtk printing.

Despite running into a few wrinkles, the attached patch does this.
There are still a few minor problems to be ironed out (like, saving the
settings between instances), but the patch works apart from these.

The work is pretty much a straight port, only changing what is
absolutely necessary to make it work (which, it turns out, is quite a
lot).  A lot of the mozilla-interface code is adapted from Epiphany's
work again.

The patch removes the gnomeprint checks from configure and bumps the min
gtk version up to 2.10.  It (as before) doesn't print pdf (despite the
default filename - see bug #348236 [1]) and removes the annoying option
from the print dialog.

I'm planning on committing both this and the search patch Real Soon Now,
and definitely by Sunday (feature freeze), unless there are any
objecting.  If there are, speak up now.

Don
Index: configure.in
===================================================================
RCS file: /cvs/gnome/yelp/configure.in,v
retrieving revision 1.232
diff -u -r1.232 configure.in
--- configure.in	11 Jul 2006 00:03:41 -0000	1.232
+++ configure.in	21 Jul 2006 14:06:01 -0000
@@ -67,10 +67,9 @@
 [
 	gconf-2.0
 	gnome-doc-utils >= 0.3.1
-        libgnomeprint-2.2
-        libgnomeprintui-2.2
+	gtk+-unix-print-2.0
 	gnome-vfs-2.0 >= 1.1
-	gtk+-2.0 >= 2.5.3
+	gtk+-2.0 >= 2.10.0
 	libglade-2.0 >= 2.0.0
 	libgnome-2.0 >= 2.14.0
 	libgnomeui-2.0 >= 2.14.0
Index: src/Yelper.cpp
===================================================================
RCS file: /cvs/gnome/yelp/src/Yelper.cpp,v
retrieving revision 1.5
diff -u -r1.5 Yelper.cpp
--- src/Yelper.cpp	12 Jun 2006 04:39:59 -0000	1.5
+++ src/Yelper.cpp	21 Jul 2006 14:06:01 -0000
@@ -224,7 +224,9 @@
   rv = print->GetGlobalPrintSettings (getter_AddRefs (settings));
   NS_ENSURE_SUCCESS (rv, rv);
 
-  PrintListener::SetPrintSettings (print_info, settings);
+  rv = PrintListener::SetPrintSettings (print_info, preview, settings);
+
+  NS_ENSURE_SUCCESS (rv, rv);
 
   nsCOMPtr<PrintListener> listener = new PrintListener (print_info, print);
 
Index: src/yelp-gecko-services.cpp
===================================================================
RCS file: /cvs/gnome/yelp/src/yelp-gecko-services.cpp,v
retrieving revision 1.2
diff -u -r1.2 yelp-gecko-services.cpp
--- src/yelp-gecko-services.cpp	10 Jun 2006 23:19:28 -0000	1.2
+++ src/yelp-gecko-services.cpp	21 Jul 2006 14:06:02 -0000
@@ -42,23 +42,23 @@
 /* Implementation file */
 NS_IMPL_ISUPPORTS3(GPrintingPromptService, nsIPrintingPromptService, nsIWebProgressListener, nsIPrintProgressParams)
 
-GPrintingPromptService::GPrintingPromptService()
+  GPrintingPromptService::GPrintingPromptService()
 {
-	mPrintInfo = NULL;
+  mPrintInfo = NULL;
 }
 
 GPrintingPromptService::~GPrintingPromptService()
 {
-	if (mPrintInfo != NULL)
-	{
-		yelp_print_info_free (mPrintInfo);
-	}
+  if (mPrintInfo != NULL)
+    {
+      yelp_print_info_free (mPrintInfo);
+    }
 }
 
 /* void showPrintDialog (in nsIDOMWindow parent, in nsIWebBrowserPrint webBrowserPrint, in nsIPrintSettings printSettings); */
 NS_IMETHODIMP GPrintingPromptService::ShowPrintDialog(nsIDOMWindow *parent, nsIWebBrowserPrint *webBrowserPrint, nsIPrintSettings *printSettings)
 {
-	return NS_OK;
+  return NS_OK;
   
 }
 
@@ -78,58 +78,58 @@
 /* void showPrinterProperties (in nsIDOMWindow parent, in wstring printerName, in nsIPrintSettings printSettings); */
 NS_IMETHODIMP GPrintingPromptService::ShowPrinterProperties(nsIDOMWindow *parent, const PRUnichar *printerName, nsIPrintSettings *printSettings)
 {
-    return NS_ERROR_NOT_IMPLEMENTED;
+  return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 
 /* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aStateFlags, in nsresult aStatus); */
 NS_IMETHODIMP GPrintingPromptService::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, nsresult aStatus)
 {
-	return NS_OK;
+  return NS_OK;
 }
 
 /* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */
 NS_IMETHODIMP GPrintingPromptService::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress)
 {
-    return NS_OK;
+  return NS_OK;
 }
 
 /* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
 NS_IMETHODIMP GPrintingPromptService::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location)
 {
-    return NS_ERROR_NOT_IMPLEMENTED;
+  return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 /* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
 NS_IMETHODIMP GPrintingPromptService::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage)
 {
-    return NS_ERROR_NOT_IMPLEMENTED;
+  return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 /* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */
 NS_IMETHODIMP GPrintingPromptService::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state)
 {
-    return NS_ERROR_NOT_IMPLEMENTED;
+  return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 /* attribute wstring docTitle; */
 NS_IMETHODIMP GPrintingPromptService::GetDocTitle(PRUnichar * *aDocTitle)
 {
-    return NS_ERROR_NOT_IMPLEMENTED;
+  return NS_ERROR_NOT_IMPLEMENTED;
 }
 NS_IMETHODIMP GPrintingPromptService::SetDocTitle(const PRUnichar * aDocTitle)
 {
-    return NS_ERROR_NOT_IMPLEMENTED;
+  return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 /* attribute wstring docURL; */
 NS_IMETHODIMP GPrintingPromptService::GetDocURL(PRUnichar * *aDocURL)
 {
-    return NS_ERROR_NOT_IMPLEMENTED;
+  return NS_ERROR_NOT_IMPLEMENTED;
 }
 NS_IMETHODIMP GPrintingPromptService::SetDocURL(const PRUnichar * aDocURL)
 {
-    return NS_ERROR_NOT_IMPLEMENTED;
+  return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMPL_ISUPPORTS1(PrintListener, nsIWebProgressListener)
@@ -151,14 +151,14 @@
 /* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aStateFlags, in nsresult aStatus); */
 NS_IMETHODIMP PrintListener::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, nsresult aStatus)
 {
-    return NS_ERROR_NOT_IMPLEMENTED;
+  return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 /* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */
 NS_IMETHODIMP PrintListener::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress)
 {
   yelp_print_update_progress (info, 
-		      (1.0 * aCurTotalProgress) / (aMaxTotalProgress * 1.0));
+			      (1.0 * aCurTotalProgress) / (aMaxTotalProgress * 1.0));
 
   if (info->cancelled && !cancel_happened) {
     /* This doesn't seem to actually cancel anything.
@@ -177,127 +177,60 @@
 /* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
 NS_IMETHODIMP PrintListener::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location)
 {
-    return NS_ERROR_NOT_IMPLEMENTED;
+  return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 /* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
 NS_IMETHODIMP PrintListener::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage)
 {
-    return NS_ERROR_NOT_IMPLEMENTED;
+  return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 /* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */
 NS_IMETHODIMP PrintListener::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state)
 {
-    return NS_ERROR_NOT_IMPLEMENTED;
+  return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 /* static functions */
 
-/* static */void
+/* static */nsresult
 PrintListener::SetPrintSettings (YelpPrintInfo *settings,
+				 PRBool preview,
 				 nsIPrintSettings * target)
 {
-    char *base;
-    const char *temp_dir;
-    int fd;
-    const GnomePrintUnit *unit, *inch, *mm;
-    double value;
-    nsString tmp;
-    
-    target->SetPrinterName(NS_LITERAL_STRING("PostScript/default").get());
-    
-    const static int frame_types[] = {
-	nsIPrintSettings::kFramesAsIs,
-	nsIPrintSettings::kSelectedFrame,
-	nsIPrintSettings::kEachFrameSep
-    };
+  nsString tmp;
+
+  /* This is a bastard mix of old Yelp stuff, old epiphany stuff
+   * and new epiphany stuff.  It does work though.
+   */
+  /* Initialisation */
+  target->SetIsInitializedFromPrinter (PR_FALSE);
+  target->SetIsInitializedFromPrefs (PR_FALSE);
+  target->SetPrintSilent (PR_FALSE);
+  target->SetShowPrintProgress (PR_TRUE);
+  target->SetNumCopies (1);
+
+  /* We always print PS to a file and then hand that off to gtk-print */
+  target->SetPrinterName (NS_LITERAL_STRING ("PostScript/default").get());
+  target->SetPrintToFile (PR_FALSE);
+
+  /* This is the time between printing each page, in ms.
+   * It 'gives the user more time to press cancel' !
+   * We don't want any of this nonsense, so set this to a low value,
+   * just enough to update the print dialogue.
+   */
+  target->SetPrintPageDelay (50);
+
+  if (!preview) {
+    gchar *base;
+    const gchar *temp_dir;
+    gint fd;
+    GtkPageSet pageSet;
+    GtkPrintPages printPages;
+
+    target->SetPrintToFile (PR_TRUE);
 
-    switch (settings->range)
-	{
-	case GNOME_PRINT_RANGE_CURRENT:
-	case GNOME_PRINT_RANGE_SELECTION_UNSENSITIVE:
-	case GNOME_PRINT_RANGE_ALL:
-	    target->SetPrintRange (nsIPrintSettings::kRangeAllPages);
-	    break;
-	case GNOME_PRINT_RANGE_RANGE:
-	    target->SetPrintRange (nsIPrintSettings::kRangeSpecifiedPageRange);
-	    target->SetStartPageRange (settings->from_page);
-	    target->SetEndPageRange (settings->to_page);
-	    break;
-	case GNOME_PRINT_RANGE_SELECTION:
-	    target->SetPrintRange (nsIPrintSettings::kRangeSelection);
-	    break;
-	}
-    
-    mm = gnome_print_unit_get_by_abbreviation ((const guchar *) "mm");
-    inch = gnome_print_unit_get_by_abbreviation ((const guchar *) "in");
-    g_assert (mm != NULL && inch != NULL);
-    
-    /* top margin */
-    if (gnome_print_config_get_length (settings->config,
-				       (const guchar *) GNOME_PRINT_KEY_PAGE_MARGIN_TOP,
-				       &value, &unit)
-	&& gnome_print_convert_distance (&value, unit, inch))
-	{
-	    target->SetMarginTop (value);
-	}
-    
-    /* bottom margin */
-    if (gnome_print_config_get_length (settings->config,
-				       (const guchar *) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM,
-				       &value, &unit)
-	&& gnome_print_convert_distance (&value, unit, inch))
-	{
-	    target->SetMarginBottom (value);
-	}
-    
-    /* left margin */
-    if (gnome_print_config_get_length (settings->config,
-				       (const guchar *) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT,
-				       &value, &unit)
-	&& gnome_print_convert_distance (&value, unit, inch))
-	{
-	    target->SetMarginLeft (value);
-	}
-    
-    /* right margin */
-    if (gnome_print_config_get_length (settings->config,
-				       (const guchar *) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT,
-				       &value, &unit)
-	&& gnome_print_convert_distance (&value, unit, inch))
-	{
-	    target->SetMarginRight (value);
-	}
-    
-    
-    
-    NS_CStringToUTF16 (nsDependentCString(settings->header_left_string),
-		       NS_CSTRING_ENCODING_UTF8, tmp);
-    target->SetHeaderStrLeft (tmp.get());
-    
-    NS_CStringToUTF16 (nsDependentCString(settings->header_center_string),
-		       NS_CSTRING_ENCODING_UTF8, tmp);
-    target->SetHeaderStrCenter (tmp.get());
-    
-    NS_CStringToUTF16 (nsDependentCString(settings->header_right_string),
-		       NS_CSTRING_ENCODING_UTF8, tmp);
-    target->SetHeaderStrRight (tmp.get());
-    
-    NS_CStringToUTF16 (nsDependentCString(settings->footer_left_string),
-		       NS_CSTRING_ENCODING_UTF8, tmp); 
-    target->SetFooterStrLeft (tmp.get());
-    
-    NS_CStringToUTF16 (nsDependentCString(settings->footer_center_string),
-		       NS_CSTRING_ENCODING_UTF8, tmp);
-    target->SetFooterStrCenter(tmp.get());
-    
-    NS_CStringToUTF16 (nsDependentCString(settings->footer_right_string),
-		       NS_CSTRING_ENCODING_UTF8, tmp);
-    target->SetFooterStrRight(tmp.get());
-    
-    
-    
     temp_dir = g_get_tmp_dir ();
     base = g_build_filename (temp_dir, "printXXXXXX", NULL);
     fd = g_mkstemp (base);
@@ -311,86 +244,172 @@
 		       NS_CSTRING_ENCODING_UTF8, tmp);
     target->SetPrintToFile (PR_TRUE);
     target->SetToFileName (tmp.get());
-    
-    
-    /* paper size */
-    target->SetPaperSize (nsIPrintSettings::kPaperSizeDefined);
-    target->SetPaperSizeUnit (nsIPrintSettings::kPaperSizeMillimeters);
-    
-    if (gnome_print_config_get_length (settings->config,
-				       (const guchar *) GNOME_PRINT_KEY_PAPER_WIDTH,
-				       &value, &unit)
-	&& gnome_print_convert_distance (&value, unit, mm))
-	{
-	    target->SetPaperWidth (value);	
-	}
-    
-    if (gnome_print_config_get_length (settings->config,
-				       (const guchar *) GNOME_PRINT_KEY_PAPER_HEIGHT,
-				       &value, &unit)
-	&& gnome_print_convert_distance (&value, unit, mm))
-	{
-	    target->SetPaperHeight (value);	
-	}
-    
+
+    pageSet = gtk_print_settings_get_page_set (settings->config);
+    target->SetPrintOptions (nsIPrintSettings::kPrintEvenPages,
+			     pageSet != GTK_PAGE_SET_ODD);
+    target->SetPrintOptions (nsIPrintSettings::kPrintEvenPages,
+			     pageSet != GTK_PAGE_SET_EVEN);
+
+    target->SetPrintReversed (gtk_print_settings_get_reverse (settings->config));
+
+    printPages = gtk_print_settings_get_print_pages (settings->config);
+    switch (printPages) {
+    case GTK_PRINT_PAGES_RANGES: {
+      int numRanges = 0;
+      GtkPageRange *pageRanges = gtk_print_settings_get_page_ranges (settings->config, &numRanges);
+      if (numRanges > 0) {
+	/* FIXME: We can only support one range, 
+	 * For now, ignore more ranges */
+	target->SetPrintRange (nsIPrintSettings::kRangeSpecifiedPageRange);
+	target->SetStartPageRange (pageRanges[0].start);
+	target->SetEndPageRange (pageRanges[1].end);
+
+	g_free (pageRanges);
+      }
+      break;
+    }
+    case GTK_PRINT_PAGES_CURRENT:
+      /* not supported, fall through */
+    case GTK_PRINT_PAGES_ALL:
+      target->SetPrintRange (nsIPrintSettings::kRangeAllPages);
+      break;
+      /* FIXME: we need some custom ranges here, "Selection" and 
+       * "Focused Frame" */
+    }
+  } else {
+    target->SetPrintOptions (nsIPrintSettings::kPrintEvenPages, PR_TRUE);
+    target->SetPrintOptions (nsIPrintSettings::kPrintEvenPages, PR_TRUE);
+    target->SetPrintReversed (PR_FALSE);
+    target->SetPrintRange (nsIPrintSettings::kRangeAllPages);
+  }
+
+  switch (gtk_print_settings_get_orientation (settings->config)) {
+  case GTK_PAGE_ORIENTATION_PORTRAIT:
+  case GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT: /* not supported */
+    target->SetOrientation (nsIPrintSettings::kPortraitOrientation);
+    break;
+  case GTK_PAGE_ORIENTATION_LANDSCAPE:
+  case GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE: /* not supported */
+    target->SetOrientation (nsIPrintSettings::kLandscapeOrientation);
+    break;
+  }
+
+  target->SetPrintInColor (gtk_print_settings_get_use_color (settings->config));
+
+  target->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeMillimeters);
+  target->SetPaperSize (nsIPrintSettings::kPaperSizeDefined);
+
+  GtkPaperSize *paperSize = gtk_page_setup_get_paper_size (settings->setup);
+  if (!paperSize) {
+    g_warning ("Paper size not set.  Aborting!\n");
+    return NS_ERROR_FAILURE;
+  }
+
+  target->SetPaperSizeType (nsIPrintSettings::kPaperSizeDefined);
+  target->SetPaperWidth (gtk_paper_size_get_width (paperSize, GTK_UNIT_MM));
+  target->SetPaperHeight (gtk_paper_size_get_height (paperSize, GTK_UNIT_MM));
+
+#ifdef HAVE_GECKO_1_9
+  target->SetPaperName (NS_ConvertUTF8toUTF16 (gtk_paper_size_get_name (paperSize)).get ());
+#else
+  {
     /* Mozilla bug https://bugzilla.mozilla.org/show_bug.cgi?id=307404
      * means that we cannot actually use any paper sizes except mozilla's
      * builtin list, and we must refer to them *by name*!
      */
-#ifndef HAVE_GECKO_1_9
-    /* Gnome-Print names some papers differently than what moz understands */
-    static const struct
-    {
-	const char *gppaper;
-	const char *mozpaper;
+    static const struct {
+      const char gtkPaperName[13];
+      const char mozPaperName[10];
+    } paperTable [] = {
+      { GTK_PAPER_NAME_A5, "A5" },
+      { GTK_PAPER_NAME_A4, "A4" },
+      { GTK_PAPER_NAME_A3, "A3" },
+      { GTK_PAPER_NAME_LETTER, "Letter" },
+      { GTK_PAPER_NAME_LEGAL, "Legal" },
+      { GTK_PAPER_NAME_EXECUTIVE, "Executive" },
+    };
+  
+    const char *paperName = gtk_paper_size_get_name (paperSize);
+  
+    PRUint32 i;
+    for (i = 0; i < G_N_ELEMENTS (paperTable); i++) {
+      if (g_ascii_strcasecmp (paperTable[i].gtkPaperName, paperName) == 0) {
+	paperName = paperTable[i].mozPaperName;
+	break;
+      }
     }
-    paper_table [] =
-	{
-	    { "USLetter", "Letter" },
-	    { "USLegal", "Legal" }
-	};
-#endif /* !HAVE_GECKO_1_9 */
-    
-    /* paper name */
-    char *string = (char *) gnome_print_config_get (settings->config,
-						    (const guchar *) GNOME_PRINT_KEY_PAPER_SIZE);
-    const char *paper = string;
-    
-#ifndef HAVE_GECKO_1_9
-    for (PRUint32 i = 0; i < G_N_ELEMENTS (paper_table); i++)
-	{
-	    if (string != NULL &&
-		g_ascii_strcasecmp (paper_table[i].gppaper, string) == 0)
-		{
-		    paper = paper_table[i].mozpaper;
-		    break;
-		}
-	}
+    if (i == G_N_ELEMENTS (paperTable)) {
+      /* Not in table, fall back to A4 */
+      g_warning ("Unknown paper name '%s', falling back to A4", 
+		 gtk_paper_size_get_name (paperSize));
+      paperName = paperTable[1].mozPaperName;
+    }
+  
+    target->SetPaperName (NS_ConvertUTF8toUTF16 (paperName).get ());
+  }
 #endif /* !HAVE_GECKO_1_9 */
-    
-    NS_CStringToUTF16 (nsDependentCString(paper),
-		       NS_CSTRING_ENCODING_UTF8, tmp);
-    target->SetPaperName (tmp.get());
-    g_free (string);
-    
-    /* paper orientation */
-    string = (char *) gnome_print_config_get (settings->config,
-					      (const guchar *) GNOME_PRINT_KEY_ORIENTATION);
-    if (string == NULL) string = g_strdup ("R0");
-    
-    if (strncmp (string, "R90", 3) == 0 || strncmp (string, "R270", 4) == 0)
-	{
-	    target->SetOrientation (nsIPrintSettings::kLandscapeOrientation);
-	}
-    else
-	{
-	    target->SetOrientation (nsIPrintSettings::kPortraitOrientation);
-	}
-    g_free (string);
-    
-    target->SetPrintInColor (TRUE);
-    target->SetPrintFrameType (frame_types[settings->frame_type]);
-}
+ 
+  /* Sucky mozilla wants margins in inch! */
+  target->SetMarginTop (gtk_page_setup_get_top_margin (settings->setup, GTK_UNIT_INCH));
+  target->SetMarginBottom (gtk_page_setup_get_bottom_margin (settings->setup, GTK_UNIT_INCH));
+  target->SetMarginLeft (gtk_page_setup_get_left_margin (settings->setup, GTK_UNIT_INCH));
+  target->SetMarginRight (gtk_page_setup_get_right_margin (settings->setup, GTK_UNIT_INCH));
+
+  
+  NS_CStringToUTF16 (nsDependentCString(settings->header_left_string),
+		     NS_CSTRING_ENCODING_UTF8, tmp);
+  target->SetHeaderStrLeft (tmp.get());
+    
+  NS_CStringToUTF16 (nsDependentCString(settings->header_center_string),
+		     NS_CSTRING_ENCODING_UTF8, tmp);
+  target->SetHeaderStrCenter (tmp.get());
+    
+  NS_CStringToUTF16 (nsDependentCString(settings->header_right_string),
+		     NS_CSTRING_ENCODING_UTF8, tmp);
+  target->SetHeaderStrRight (tmp.get());
+    
+  NS_CStringToUTF16 (nsDependentCString(settings->footer_left_string),
+		     NS_CSTRING_ENCODING_UTF8, tmp); 
+  target->SetFooterStrLeft (tmp.get());
+    
+  NS_CStringToUTF16 (nsDependentCString(settings->footer_center_string),
+		     NS_CSTRING_ENCODING_UTF8, tmp);
+  target->SetFooterStrCenter(tmp.get());
+    
+  NS_CStringToUTF16 (nsDependentCString(settings->footer_right_string),
+		     NS_CSTRING_ENCODING_UTF8, tmp);
+  target->SetFooterStrRight(tmp.get());
+
+  /* FIXME I think this is the right default, but this prevents the user
+   * from cancelling the print immediately, see the stupid comment in 
+   * nsPrintEngine:
+   *  "DO NOT allow the print job to be cancelled if it is Print FrameAsIs
+   *   because it is only printing one page."
+   * We work around this by just not sending the job to the printer then.
+   */
+  target->SetPrintFrameType(nsIPrintSettings::kFramesAsIs); /* FIXME setting */
+  target->SetPrintFrameTypeUsage (nsIPrintSettings::kUseSettingWhenPossible);
+
+  target->SetScaling (gtk_print_settings_get_scale (settings->config) / 100.0);
+
+  /* FIXME: What do these do?  Need to learn to fix them properly
+   * For now, leave at Epiphany type defaults 
+   */
+
+  target->SetShrinkToFit (PR_FALSE); /* FIXME setting */
+    
+  target->SetPrintBGColors (PR_FALSE); /* FIXME setting */
+  target->SetPrintBGImages (PR_FALSE); /* FIXME setting */
+
+  /* target->SetPlexName (LITERAL ("default")); */
+  /* target->SetColorspace (LITERAL ("default")); */
+  /* target->SetResolutionName (LITERAL ("default")); */
+  /* target->SetDownloadFonts (PR_TRUE); */
+
+  return NS_OK;
+
+};
 
 /* component registration */
 
@@ -398,44 +417,42 @@
 
 static const nsModuleComponentInfo sAppComps[] = {
     {
-	G_PRINTINGPROMPTSERVICE_CLASSNAME,
-	G_PRINTINGPROMPTSERVICE_CID,
-	G_PRINTINGPROMPTSERVICE_CONTRACTID,
-	GPrintingPromptServiceConstructor
+        G_PRINTINGPROMPTSERVICE_CLASSNAME,
+        G_PRINTINGPROMPTSERVICE_CID,
+        G_PRINTINGPROMPTSERVICE_CONTRACTID,
+        GPrintingPromptServiceConstructor
     },
 };
 
-
-
 void
 yelp_register_printing ()
 {
-    nsresult rv;
-    nsCOMPtr<nsIComponentRegistrar> cr;
-    rv = NS_GetComponentRegistrar(getter_AddRefs(cr));
-    NS_ENSURE_SUCCESS (rv, );
-
-    nsCOMPtr<nsIComponentManager> cm;
-    rv = NS_GetComponentManager (getter_AddRefs (cm));
-    NS_ENSURE_SUCCESS (rv, );
-
-    nsCOMPtr<nsIGenericFactory> componentFactory;
-    rv = NS_NewGenericFactory(getter_AddRefs(componentFactory),
-			      &(sAppComps[0]));
+  nsresult rv;
+  nsCOMPtr<nsIComponentRegistrar> cr;
+  rv = NS_GetComponentRegistrar(getter_AddRefs(cr));
+  NS_ENSURE_SUCCESS (rv, );
+
+  nsCOMPtr<nsIComponentManager> cm;
+  rv = NS_GetComponentManager (getter_AddRefs (cm));
+  NS_ENSURE_SUCCESS (rv, );
+
+  nsCOMPtr<nsIGenericFactory> componentFactory;
+  rv = NS_NewGenericFactory(getter_AddRefs(componentFactory),
+			    &(sAppComps[0]));
     
-    if (NS_FAILED(rv) || !componentFactory)
-	{
-	    g_warning ("Failed to make a factory for %s\n", sAppComps[0].mDescription);
-	    return;
-	}
+  if (NS_FAILED(rv) || !componentFactory)
+    {
+      g_warning ("Failed to make a factory for %s\n", sAppComps[0].mDescription);
+      return;
+    }
    
-    rv = cr->RegisterFactory(sAppComps[0].mCID,
-			     sAppComps[0].mDescription,
-			     sAppComps[0].mContractID,
-			     componentFactory);
-    if (NS_FAILED(rv))
-	{
-	    g_warning ("Failed to register %s\n", sAppComps[0].mDescription);
-	}
+  rv = cr->RegisterFactory(sAppComps[0].mCID,
+			   sAppComps[0].mDescription,
+			   sAppComps[0].mContractID,
+			   componentFactory);
+  if (NS_FAILED(rv))
+    {
+      g_warning ("Failed to register %s\n", sAppComps[0].mDescription);
+    }
     
 }
Index: src/yelp-gecko-services.h
===================================================================
RCS file: /cvs/gnome/yelp/src/yelp-gecko-services.h,v
retrieving revision 1.2
diff -u -r1.2 yelp-gecko-services.h
--- src/yelp-gecko-services.h	10 Jun 2006 23:19:28 -0000	1.2
+++ src/yelp-gecko-services.h	21 Jul 2006 14:06:02 -0000
@@ -67,7 +67,8 @@
   NS_DECL_ISUPPORTS
   NS_DECL_NSIWEBPROGRESSLISTENER
     
-  static void SetPrintSettings (YelpPrintInfo *settings, nsIPrintSettings *target);
+    static nsresult SetPrintSettings (YelpPrintInfo *settings, PRBool preview, 
+				      nsIPrintSettings *target);
 
 protected:
   YelpPrintInfo *info;
Index: src/yelp-print.c
===================================================================
RCS file: /cvs/gnome/yelp/src/yelp-print.c,v
retrieving revision 1.4
diff -u -r1.4 yelp-print.c
--- src/yelp-print.c	15 Feb 2006 17:12:29 -0000	1.4
+++ src/yelp-print.c	21 Jul 2006 14:06:02 -0000
@@ -30,9 +30,10 @@
 #include "yelp-print.h"
 #include "yelp-html.h"
 #include "yelp-utils.h"
+#include <gtk/gtkprintunixdialog.h>
 
-static GnomePrintConfig * yelp_print_load_config_from_file ( void );
-static void               yelp_print_save_config_to_file   (GnomePrintConfig *config);
+static GtkPrintSettings * yelp_print_load_config_from_file ( void );
+static void               yelp_print_save_config_to_file   (GtkPrintSettings *config);
 static void               cancel_print_cb                  (GtkDialog *dialog, 
 							    gint arg1, 
 							    YelpPrintInfo *info);
@@ -41,18 +42,11 @@
 static gboolean           print_jobs_run                   ( void );
 void                      print_present_config_dialog      (YelpPrintInfo *info);
 static YelpPrintInfo    * yelp_print_get_print_info        ( void );
-GtkWidget               * yelp_print_dialog_new            (YelpPrintInfo *info);
 void                      yelp_print_info_free             (YelpPrintInfo *info);
-gboolean                  yelp_print_verify_postscript     (GnomePrintDialog *print_dialog);
+gboolean                  yelp_print_verify_postscript     (GtkPrinter *printer,
+							    GtkWidget *print_dialog);
 void                      yelp_print_present_status_dialog (YelpWindow *window,
 							    YelpPrintInfo *info);
-void                      yelp_print_dialog_response_cb    (GtkDialog *dialog,
-							    int response,
-							    YelpPrintInfo *info);
-static void               print_construct_range_page       (GnomePrintDialog *gpd, 
-							    gint flags,
-							    const guchar *currentlabel, 
-							    const guchar *rangelabel);
 gboolean                 yelp_print_preview                (YelpPrintInfo *info);
 
 gboolean                 print_preview_finished_cb         (GtkWindow     *win,
@@ -69,6 +63,9 @@
 void                     preview_close                     (GtkToolButton *b,
 							    YelpPrintInfo *info);
 gboolean                 print_free_idle_cb                (YelpPrintInfo *info);
+void                     yelp_finish_printing              (GtkPrintJob *job,
+							   YelpPrintInfo *info,
+							    GError *error);
 
 static GSList * current_jobs = NULL;
 
@@ -85,6 +82,7 @@
     info->html_frame = html;
     info->fake_win = fake_win;
     info->content_box = content_box;
+    info->previewed = FALSE;
 
     print_present_config_dialog (info);
     
@@ -93,32 +91,63 @@
 void
 print_present_config_dialog (YelpPrintInfo *info)
 {
-    GtkWidget *dialog;
     int ret;
 
-    dialog = yelp_print_dialog_new (info);
-    while (TRUE) {
-	ret = gtk_dialog_run (GTK_DIALOG (dialog));
+    if (!info->print_dialog) {
+	info->print_dialog = gtk_print_unix_dialog_new ("Print Dialog", 
+							GTK_WINDOW (info->owner));
+	gtk_print_unix_dialog_set_settings (
+				  GTK_PRINT_UNIX_DIALOG (info->print_dialog), 
+				  info->config);
+	gtk_print_unix_dialog_set_page_setup (
+					GTK_PRINT_UNIX_DIALOG (info->print_dialog),
+					info->setup);
+	gtk_print_unix_dialog_set_manual_capabilities (
+				       GTK_PRINT_UNIX_DIALOG (info->print_dialog), 
+				       GTK_PRINT_CAPABILITY_PAGE_SET |
+				       GTK_PRINT_CAPABILITY_COPIES   |
+				       GTK_PRINT_CAPABILITY_COLLATE  |
+				       GTK_PRINT_CAPABILITY_REVERSE  |
+				       GTK_PRINT_CAPABILITY_SCALE |
+				       GTK_PRINT_CAPABILITY_GENERATE_PS |
+				       GTK_PRINT_CAPABILITY_PREVIEW);
+    }
+    while (1) {
 	
-	if (ret != GNOME_PRINT_DIALOG_RESPONSE_PRINT)
+	ret = gtk_dialog_run (GTK_DIALOG (info->print_dialog));
+	info->config = 
+	   gtk_print_unix_dialog_get_settings (
+				   GTK_PRINT_UNIX_DIALOG (info->print_dialog));
+	info->setup = 
+	    gtk_print_unix_dialog_get_page_setup (GTK_PRINT_UNIX_DIALOG 
+						  (info->print_dialog));
+	info->printer = 
+	    gtk_print_unix_dialog_get_selected_printer (GTK_PRINT_UNIX_DIALOG 
+							(info->print_dialog));
+	g_object_ref (info->printer);
+	if (ret != GTK_RESPONSE_OK)
 	    break;
-	if (yelp_print_verify_postscript (GNOME_PRINT_DIALOG (dialog)))
+	if (yelp_print_verify_postscript (info->printer, info->print_dialog)) 
 	    break;
+
     }
-    gtk_widget_destroy (dialog);
-    if (ret == GNOME_PRINT_DIALOG_RESPONSE_PREVIEW) {
+
+    gtk_widget_hide (info->print_dialog);
+    if (ret == GTK_RESPONSE_APPLY) {
 	g_idle_add ((GSourceFunc) yelp_print_preview, info);
 	return;
     }
-    if (ret != GNOME_PRINT_DIALOG_RESPONSE_PRINT) {
+    if (ret != GTK_RESPONSE_OK) {
 	yelp_print_info_free (info);
 	return;
     }
+    yelp_print_save_config_to_file (info->config);
     yelp_print_present_status_dialog (info->owner, info);
     info->cancel_print_id = g_signal_connect (info->owner, "destroy",
 					      G_CALLBACK (parent_destroyed_cb), 
 					      info);
-    
+
+
     current_jobs = g_slist_append (current_jobs, info);
 
     if (!currently_running) {
@@ -142,40 +171,22 @@
     return FALSE;
 }
 
-static GnomePrintConfig * 
+static GtkPrintSettings * 
 yelp_print_load_config_from_file ()
 {
-  GnomePrintConfig *config = NULL;
-  gchar *filename, *contents = NULL;
+    GtkPrintSettings *settings;
 
-  filename = g_build_filename (yelp_dot_dir(), "yelp-printing.xml", NULL);
-  if (g_file_get_contents (filename, &contents, NULL, NULL)) {
-      config = gnome_print_config_from_string (contents, 0);
-      g_free (contents);
-  } else {
-      config = gnome_print_config_default ();
-      
-  }
-  
-  g_free (filename);
-  
-  return config;
+    settings = gtk_print_settings_new ();
+    
+    /* TODO: Load settings from a file somehow */
+    return settings;
 }
 
 static void
-yelp_print_save_config_to_file (GnomePrintConfig *config)
+yelp_print_save_config_to_file (GtkPrintSettings *config)
 {
-  gchar *filename, *str;
-
-  str = gnome_print_config_to_string (config, 0);
-  if (str == NULL) return;
-
-  filename = g_build_filename ( yelp_dot_dir (), "yelp-printing.xml", NULL);
-  g_file_set_contents (filename, str, -1, NULL);
-
-  g_free (str);
-  g_free (filename);
-
+    /* TODO: Save settings to a file somehow */
+    return;
 }
 
 void
@@ -183,10 +194,14 @@
 {
     if (info) {
 	g_object_unref (info->config);
+	g_object_unref (info->setup);
+	g_object_unref (info->printer);
+	gtk_widget_destroy (info->print_dialog);
 	if (info->tempfile) {
 	    g_unlink (info->tempfile);
 	    g_free (info->tempfile);
 	}
+
 	g_free (info->header_left_string);
 	g_free (info->header_center_string);
 	g_free (info->header_right_string);
@@ -216,17 +231,13 @@
 
   info->config = yelp_print_load_config_from_file ();
 
-  info->range = GNOME_PRINT_RANGE_ALL;
-  info->from_page = 1;
-  info->to_page = 1;
-
-  info->frame_type = 0;
-  info->print_color = FALSE;
+  info->setup = gtk_page_setup_new ();
 
   info->cancelled = FALSE;
   info->moz_finished = FALSE;
 
   info->dialog = NULL;
+  info->print_dialog = NULL;
 
   info->header_left_string = g_strdup ("&T");
   info->header_center_string = g_strdup ("");
@@ -235,189 +246,49 @@
   info->footer_center_string = g_strdup ("&PT");
   info->footer_right_string = g_strdup ("");
 
-
   return info;
 }
 
-void
-yelp_print_dialog_response_cb (GtkDialog *dialog,
-			       int response,
-			       YelpPrintInfo *info)
-{
-  if (response == GNOME_PRINT_DIALOG_RESPONSE_PRINT ||
-      response == GNOME_PRINT_DIALOG_RESPONSE_PREVIEW) {
-      info->range = gnome_print_dialog_get_range_page (GNOME_PRINT_DIALOG (dialog),
-						       &info->from_page,
-						       &info->to_page);
-      yelp_print_save_config_to_file (info->config);
-  }
-
-}
-
-
-GtkWidget *
-yelp_print_dialog_new (YelpPrintInfo *info)
-{
-  GtkWidget *dialog;
-
-  dialog= g_object_new (GNOME_TYPE_PRINT_DIALOG, "print_config",
-			info->config, NULL);
-
-  gnome_print_dialog_construct (GNOME_PRINT_DIALOG (dialog),
-				(const guchar *) "Print",
-				GNOME_PRINT_DIALOG_RANGE |
-				GNOME_PRINT_DIALOG_COPIES);
-
-  print_construct_range_page (GNOME_PRINT_DIALOG (dialog),
-			      GNOME_PRINT_RANGE_ALL |
-			      GNOME_PRINT_RANGE_RANGE |
-			      GNOME_PRINT_RANGE_SELECTION,
-			      NULL, (const guchar *) _("Pages"));
-
-  g_signal_connect (G_OBJECT (dialog), "response",
-		    G_CALLBACK (yelp_print_dialog_response_cb), info);
-
-  return dialog;
-
-}
-
-static gboolean
-using_pdf_printer (GnomePrintConfig *config)
-{
-  const gchar *driver;
-  
-  driver = (gchar *) gnome_print_config_get (config,
-					     (const guchar *) 
-					     "Settings.Engine.Backend.Driver");
-
-  if (driver) {
-    if (!strcmp ((const gchar *)driver, "gnome-print-pdf"))
-      return TRUE;
-    else
-      return FALSE; 
-  }
-  return FALSE;
-
-}
-
-static gboolean
-using_postscript_printer (GnomePrintConfig *config)
-{
-  const guchar *driver;
-  const guchar *transport;
-
-  driver = gnome_print_config_get ( config,
-				    (const guchar *) "Settings.Engine.Backend.Driver");
-
-  transport = gnome_print_config_get ( config,
-				       (const guchar *) "Settings.Transport.Backend");
-
-  if (driver) {
-    if (strcmp ((const gchar *) driver, "gnome-print-ps") == 0)
-      return TRUE;
-    else
-      return FALSE;
-
-  } else if (transport) {
-    if (strcmp ((const gchar *) transport, "CUPS") == 0)
-      return TRUE;
-    else if (strcmp ((const gchar *) transport, "LPD") == 0)
-      return TRUE;
-
-  }
-  return FALSE;
-
-}
-
 gboolean
-yelp_print_verify_postscript (GnomePrintDialog *print_dialog)
+yelp_print_verify_postscript (GtkPrinter *printer, GtkWidget *print_dialog)
 {
-  GnomePrintConfig *config;
-  GtkWidget *dialog;
-
-  config = gnome_print_dialog_get_config (print_dialog);
+    if (!gtk_printer_accepts_ps (printer)) {
+	GtkDialog *dialog;
+	dialog = gtk_message_dialog_new ( GTK_WINDOW (print_dialog),
+					  GTK_DIALOG_MODAL,
+					  GTK_MESSAGE_ERROR,
+					  GTK_BUTTONS_OK,
+					  _("Printing is not supported on this"
+					    " printer"));
+	gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+						  _("Printer %s does not"
+						    " support postscript "
+						    "printing."), 
+						  gtk_printer_get_description (printer));
+	  gtk_dialog_run (GTK_DIALOG (dialog));
+	  gtk_widget_destroy (GTK_WIDGET (dialog));
+	  
+	  return FALSE;
+    }
 
-  if (using_postscript_printer (config))
     return TRUE;
-
-  if (using_pdf_printer (config)) {
-    dialog = gtk_message_dialog_new ( GTK_WINDOW (print_dialog),
-				      GTK_DIALOG_MODAL,
-				      GTK_MESSAGE_ERROR,
-				      GTK_BUTTONS_OK,
-				      _("Generating PDF is not "
-					"currently supported"));
-
-  } else {
-    dialog = gtk_message_dialog_new ( GTK_WINDOW (print_dialog),
-				      GTK_DIALOG_MODAL,
-				      GTK_MESSAGE_ERROR,
-				      GTK_BUTTONS_OK,
-				      _("Printing is not supported on this "
-					"printer"));
-    gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
-					      _("You were trying to print "
-						"to a printer using the \""
-						"%s\" driver.  This program "
-						"requires a PostScript "
-						"printer driver."),
-					      gnome_print_config_get (config,
-								      (guchar *) "Settings.Engine.Backend.Driver"));
-
-  }
-  gtk_dialog_run (GTK_DIALOG (dialog));
-  gtk_widget_destroy (dialog);
-
-  return FALSE;
 }
 
 static gboolean
 print_idle_cb (YelpPrintInfo *info)
 {
-  GnomePrintJob *job;
-  gint result;
-
-  if (g_file_test (info->tempfile, G_FILE_TEST_EXISTS) == FALSE) return FALSE;
-  
-  /* FIXME: is this actually necessary? libc docs say all streams
-   * are flushed when reading from any stream.
-   */
-  fflush(NULL);
-  
-  job = gnome_print_job_new (info->config);
-  
-  gnome_print_job_set_file (job, info->tempfile);
-  result = gnome_print_job_print (job);
-  g_object_unref (job);
-
-  if (result != GNOME_PRINT_OK) {
-    /*There was an error printing.  Panic.*/
-    GtkWidget *dialog;
-
-    dialog = gtk_message_dialog_new          (NULL,
-					      GTK_DIALOG_MODAL |
-					      GTK_DIALOG_DESTROY_WITH_PARENT,
-					      GTK_MESSAGE_WARNING,
-					      GTK_BUTTONS_OK,
-					      _("An error "
-						"occurred while printing")
-					      );
-    gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
-					      _("It was not possible to "
-						"print your document"));
-    gtk_dialog_run (GTK_DIALOG (dialog));
-    gtk_widget_hide (dialog);
-    gtk_widget_destroy (dialog);
-  }
-  
-  yelp_print_info_free (info);
-
-  if (g_slist_length (current_jobs) > 0)
-      g_idle_add ((GSourceFunc) print_jobs_run, NULL);
-  else
-      currently_running = FALSE;
+    GtkPrintJob *job;
+    
+    if (g_file_test (info->tempfile, G_FILE_TEST_EXISTS) == FALSE) 
+	return FALSE;
+    job = gtk_print_job_new (gtk_window_get_title (GTK_WINDOW (info->owner)), 
+			     info->printer,
+			     info->config, info->setup);
+    gtk_print_job_set_source_file (job, info->tempfile, NULL);
+    gtk_print_job_send (job, (GtkPrintJobCompleteFunc) yelp_finish_printing,
+			info, NULL);
 
-  return FALSE;
+    return FALSE;
 
 }
 
@@ -536,60 +407,6 @@
 
 }
 
-/* Ranges page when we don't actually know the length of the
- * document
- */
-static void
-print_construct_range_page (GnomePrintDialog *gpd, gint flags,
-			    const guchar *currentlabel, 
-			    const guchar *rangelabel)
-{
-	GtkWidget *hbox;
-
-	hbox = NULL;
-
-	if (flags & GNOME_PRINT_RANGE_RANGE) {
-		GtkWidget *l, *sb;
-		GtkObject *a;
-		AtkObject *atko;
-
-		hbox = gtk_hbox_new (FALSE, 3);
-		gtk_widget_show (hbox);
-
-		l = gtk_label_new_with_mnemonic (_("_From:"));
-		gtk_widget_show (l);
-		gtk_box_pack_start (GTK_BOX (hbox), l, FALSE, FALSE, 0);
-
-		a = gtk_adjustment_new (1, 1, 9999, 1, 10, 10);
-		g_object_set_data (G_OBJECT (hbox), "from", a);
-		sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1, 0.0);
-		gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (sb), TRUE);
-		gtk_widget_show (sb);
-		gtk_box_pack_start (GTK_BOX (hbox), sb, FALSE, FALSE, 0);
-		gtk_label_set_mnemonic_widget ((GtkLabel *) l, sb);
-
-		atko = gtk_widget_get_accessible (sb);
-		atk_object_set_description (atko, _("Sets the start of the range of pages to be printed"));
-
-		l = gtk_label_new_with_mnemonic (_("_To:"));
-		gtk_widget_show (l);
-		gtk_box_pack_start (GTK_BOX (hbox), l, FALSE, FALSE, 0);
-
-		a = gtk_adjustment_new (1, 1, 9999, 1, 10, 10);
-		g_object_set_data (G_OBJECT (hbox), "to", a);
-		sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1, 0.0);
-		gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (sb), TRUE);
-		gtk_widget_show (sb);
-		gtk_box_pack_start (GTK_BOX (hbox), sb, FALSE, FALSE, 0);
-		gtk_label_set_mnemonic_widget ((GtkLabel *) l, sb);
-
-		atko = gtk_widget_get_accessible (sb);
-		atk_object_set_description (atko, _("Sets the end of the range of pages to be printed"));
-	}
-
-	gnome_print_dialog_construct_range_any (gpd, flags, hbox, currentlabel, rangelabel);
-}
-
 gboolean
 yelp_print_preview (YelpPrintInfo *info)
 {
@@ -599,7 +416,6 @@
      */
     if (!info->previewed) {
 	GtkWidget *box;
-
 	info->previewed = TRUE;
 	box = gtk_toolbar_new ();
 	
@@ -745,4 +561,37 @@
 {
     yelp_print_info_free (info);
     return FALSE;
+}
+
+void
+yelp_finish_printing (GtkPrintJob *job, YelpPrintInfo *info, GError *error)
+{
+    if (error) {
+	/*There was an error printing.  Panic.*/
+	GtkWidget *dialog;
+
+	dialog = gtk_message_dialog_new          (NULL,
+						  GTK_DIALOG_MODAL |
+						  GTK_DIALOG_DESTROY_WITH_PARENT,
+						  GTK_MESSAGE_WARNING,
+						  GTK_BUTTONS_OK,
+						  _("An error "
+						    "occurred while printing")
+						  );
+	gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+						  _("It was not possible to "
+						    "print your document: %s"),
+						  error->message);
+	gtk_dialog_run (GTK_DIALOG (dialog));
+	gtk_widget_hide (dialog);
+	gtk_widget_destroy (dialog);
+    }
+    
+    yelp_print_info_free (info);
+    
+    if (g_slist_length (current_jobs) > 0)
+	g_idle_add ((GSourceFunc) print_jobs_run, NULL);
+    else
+	currently_running = FALSE;
+    
 }
Index: src/yelp-print.h
===================================================================
RCS file: /cvs/gnome/yelp/src/yelp-print.h,v
retrieving revision 1.1
diff -u -r1.1 yelp-print.h
--- src/yelp-print.h	11 Dec 2005 22:28:54 -0000	1.1
+++ src/yelp-print.h	21 Jul 2006 14:06:02 -0000
@@ -24,9 +24,10 @@
 #define YELP_PRINT_H
 
 #include <glib.h>
-#define GNOME_PRINT_UNSTABLE_API
-#include <libgnomeprint/gnome-print-config.h>
-#include <libgnomeprintui/gnome-print-dialog.h>
+
+/* Needed to fill the struct */
+#include <gtk/gtkprinter.h>
+#include <gtk/gtkprintsettings.h>
 
 #include "yelp-window.h"
 
@@ -35,17 +36,15 @@
 
 typedef struct _YelpPrintInfo
 {
-    GnomePrintConfig *config;
-    
+    GtkPrintSettings *config;
+    GtkPageSetup     *setup;
+    GtkPrinter       *printer;
+    GtkWidget        *print_dialog;
+
     char *tempfile;
     guint print_idle_id;
     guint cancel_print_id;
 
-    GnomePrintDialogRangeFlags range;
-    int from_page;
-    int to_page;
-    int frame_type;
-    gboolean print_color;
     gboolean cancelled;
     gboolean moz_finished;
     gboolean started;


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