summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Persch <chpe@svn.gnome.org>2007-01-23 17:42:11 +0000
committerChristian Persch <chpe@src.gnome.org>2007-01-23 17:42:11 +0000
commitb3d7c70a9f26826bc9928920c0d3d00806d8feaf (patch)
treedbce7e6d8e55ce77e648a763e0db05da57e0a32e
parent4a0880a50d9f330b03d0da66cecf424434225416 (diff)
downloadepiphany-b3d7c70a9f26826bc9928920c0d3d00806d8feaf.tar.gz
Clear some print settings in the settings we hand to the print job, so
2007-01-23 Christian Persch <chpe@svn.gnome.org> * embed/mozilla/EphyBrowser.cpp: * embed/mozilla/GeckoPrintService.cpp: * embed/mozilla/GeckoPrintService.h: * embed/mozilla/GeckoPrintSession.cpp: Clear some print settings in the settings we hand to the print job, so they don't get applied twice. Bug #394818. Prepare for printing to PDF (#if 0'd until the gecko bug is fixed). svn path=/branches/gnome-2-16/; revision=6845
-rw-r--r--embed/mozilla/EphyBrowser.cpp1
-rw-r--r--embed/mozilla/GeckoPrintService.cpp69
-rw-r--r--embed/mozilla/GeckoPrintService.h3
-rw-r--r--embed/mozilla/GeckoPrintSession.cpp2
4 files changed, 62 insertions, 13 deletions
diff --git a/embed/mozilla/EphyBrowser.cpp b/embed/mozilla/EphyBrowser.cpp
index aba1645eb..2048e67e4 100644
--- a/embed/mozilla/EphyBrowser.cpp
+++ b/embed/mozilla/EphyBrowser.cpp
@@ -715,6 +715,7 @@ nsresult EphyBrowser::SetPrintPreviewMode (PRBool previewMode)
EphyEmbedShell *shell = ephy_embed_shell_get_default ();
rv = GeckoPrintService::TranslateSettings (ephy_embed_shell_get_print_settings (shell),
ephy_embed_shell_get_page_setup (shell),
+ NULL,
nsCString(),
PR_FALSE,
settings);
diff --git a/embed/mozilla/GeckoPrintService.cpp b/embed/mozilla/GeckoPrintService.cpp
index 5a4ca358f..cd54c6a5a 100644
--- a/embed/mozilla/GeckoPrintService.cpp
+++ b/embed/mozilla/GeckoPrintService.cpp
@@ -153,14 +153,18 @@ GeckoPrintService::ShowPrintDialog (nsIDOMWindow *aParent,
GTK_WINDOW (parent));
GtkPrintUnixDialog *print_dialog = GTK_PRINT_UNIX_DIALOG (dialog);
- gtk_print_unix_dialog_set_manual_capabilities
- (print_dialog,
+ GtkPrintCapabilities capabilities =
GtkPrintCapabilities (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_GENERATE_PS);
+#if 0 //def HAVE_GECKO_1_9
+ capabilities = GtkPrintCapabilities (capabilities | GTK_PRINT_CAPABILITY_GENERATE_PDF);
+#endif
+ gtk_print_unix_dialog_set_manual_capabilities (print_dialog, capabilities);
+
gtk_print_unix_dialog_set_page_setup (print_dialog,
ephy_embed_shell_get_page_setup (shell));
gtk_print_unix_dialog_set_settings (print_dialog,
@@ -187,13 +191,22 @@ GeckoPrintService::ShowPrintDialog (nsIDOMWindow *aParent,
return NS_ERROR_ABORT;
}
- GtkPageSetup *pageSetup = gtk_print_unix_dialog_get_page_setup (print_dialog);
+ GtkPageSetup *pageSetup = gtk_print_unix_dialog_get_page_setup (print_dialog); /* no reference owned */
ephy_embed_shell_set_page_setup (shell, pageSetup);
GtkPrintSettings *settings = gtk_print_unix_dialog_get_settings (print_dialog);
ephy_embed_shell_set_print_settings (shell, settings);
- /* This adopts the refcount of |settings| */
+ /* We copy the setup and settings so we can modify them to unset
+ * options handled by gecko.
+ */
+ GtkPageSetup *pageSetupCopy = gtk_page_setup_copy (pageSetup);
+ pageSetup = pageSetupCopy;
+
+ GtkPrintSettings *settingsCopy = gtk_print_settings_copy (settings);
+ g_object_unref (settings);
+ settings = settingsCopy;
+
rv = session->SetSettings (settings, pageSetup, printer);
/* Now translate the settings to nsIPrintSettings */
@@ -201,7 +214,7 @@ GeckoPrintService::ShowPrintDialog (nsIDOMWindow *aParent,
nsCString sourceFile;
session->GetSourceFile (sourceFile);
if (!sourceFile.IsEmpty ()) {
- rv = TranslateSettings (settings, pageSetup, sourceFile, PR_TRUE, aSettings);
+ rv = TranslateSettings (settings, pageSetup, printer, sourceFile, PR_TRUE, aSettings);
} else {
rv = NS_ERROR_FAILURE;
}
@@ -209,6 +222,9 @@ GeckoPrintService::ShowPrintDialog (nsIDOMWindow *aParent,
gtk_widget_destroy (dialog);
+ g_object_unref (settings);
+ g_object_unref (pageSetup);
+
return rv;
}
@@ -469,6 +485,7 @@ GeckoPrintService::PrintUnattended (nsIDOMWindow *aParent,
/* static */ nsresult
GeckoPrintService::TranslateSettings (GtkPrintSettings *aGtkSettings,
GtkPageSetup *aPageSetup,
+ GtkPrinter *aPrinter,
const nsACString &aSourceFile,
PRBool aIsForPrinting,
nsIPrintSettings *aSettings)
@@ -518,6 +535,26 @@ GeckoPrintService::TranslateSettings (GtkPrintSettings *aGtkSettings,
aSettings->SetPrintPageDelay (50);
if (aIsForPrinting) {
+#if 0 //def HAVE_GECKO_1_9
+ NS_ENSURE_TRUE (aPrinter, NS_ERROR_FAILURE);
+
+ const char *format = gtk_print_settings_get (aGtkSettings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT);
+ if (!format)
+ format = "ps";
+
+ if (strcmp (format, "pdf") == 0 &&
+ gtk_printer_accepts_pdf (aPrinter)) {
+ aSettings->SetOutputFormat (nsIPrintSettings::kOutputFormatPDF);
+ } else if (strcmp (format, "ps") == 0 &&
+ gtk_printer_accepts_ps (aPrinter)) {
+ aSettings->SetOutputFormat (nsIPrintSettings::kOutputFormatPS);
+ } else {
+ g_warning ("Output format '%s' specified, but printer '%s' does not support it!",
+ format, gtk_printer_get_name (aPrinter));
+ return NS_ERROR_FAILURE;
+ }
+#endif
+
GtkPageSet pageSet = gtk_print_settings_get_page_set (aGtkSettings);
aSettings->SetPrintOptions (nsIPrintSettings::kPrintEvenPages,
pageSet != GTK_PAGE_SET_ODD);
@@ -539,8 +576,9 @@ GeckoPrintService::TranslateSettings (GtkPrintSettings *aGtkSettings,
aSettings->SetEndPageRange (pageRanges[0].end + 1);
g_free (pageRanges);
+ break;
}
- break;
+ /* Fall-through to PAGES_ALL */
}
case GTK_PRINT_PAGES_CURRENT:
/* not supported, fall through */
@@ -572,8 +610,6 @@ GeckoPrintService::TranslateSettings (GtkPrintSettings *aGtkSettings,
aSettings->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeMillimeters);
aSettings->SetPaperSize (nsIPrintSettings::kPaperSizeDefined);
- // FIXME for some reason this is always NULL ??
- // GtkPaperSize *paperSize = gtk_print_settings_get_paper_size (aGtkSettings);
GtkPaperSize *paperSize = gtk_page_setup_get_paper_size (aPageSetup);
if (!paperSize) {
return NS_ERROR_FAILURE;
@@ -622,8 +658,6 @@ GeckoPrintService::TranslateSettings (GtkPrintSettings *aGtkSettings,
}
#endif /* !HAVE_GECKO_1_9 */
- // gtk_paper_size_free (paperSize);
-
/* Sucky mozilla wants margins in inch! */
aSettings->SetMarginTop (gtk_page_setup_get_top_margin (aPageSetup, GTK_UNIT_INCH));
aSettings->SetMarginBottom (gtk_page_setup_get_bottom_margin (aPageSetup, GTK_UNIT_INCH));
@@ -657,5 +691,18 @@ GeckoPrintService::TranslateSettings (GtkPrintSettings *aGtkSettings,
/* aSettings->SetResolutionName (LITERAL ("default")); */
/* aSettings->SetDownloadFonts (PR_TRUE); */
+ /* Unset those setting that we can handle, so they don't get applied
+ * again for the print job.
+ */
+ gtk_print_settings_set_print_pages (aGtkSettings, GTK_PRINT_PAGES_ALL);
+ gtk_print_settings_set_page_ranges (aGtkSettings, NULL, 0);
+ gtk_print_settings_set_page_set (aGtkSettings, GTK_PAGE_SET_ALL);
+ gtk_print_settings_set_reverse (aGtkSettings, FALSE);
+ gtk_print_settings_set_scale (aGtkSettings, 1.0);
+ /* gtk_print_settings_set_collate (aGtkSettings, FALSE); not yet */
+ /* FIXME: Unset the orientation for the print job? */
+ /* gtk_print_settings_set_orientation (aGtkSettings, GTK_PAGE_ORIENTATION_PORTRAIT); */
+ /* FIXME: unset output format -> "ps" ? */
+
return NS_OK;
}
diff --git a/embed/mozilla/GeckoPrintService.h b/embed/mozilla/GeckoPrintService.h
index e77e00b6d..c5a2ae429 100644
--- a/embed/mozilla/GeckoPrintService.h
+++ b/embed/mozilla/GeckoPrintService.h
@@ -23,6 +23,7 @@
#include <gtk/gtkpagesetup.h>
#include <gtk/gtkprintsettings.h>
+#include <gtk/gtkprinter.h>
#include <nsIPrintingPromptService.h>
@@ -44,7 +45,7 @@ public:
GeckoPrintService();
virtual ~GeckoPrintService();
- static nsresult TranslateSettings (GtkPrintSettings*, GtkPageSetup *, const nsACString&, PRBool, nsIPrintSettings*);
+ static nsresult TranslateSettings (GtkPrintSettings*, GtkPageSetup *, GtkPrinter *, const nsACString&, PRBool, nsIPrintSettings*);
private:
nsresult PrintUnattended (nsIDOMWindow *, nsIPrintSettings *);
diff --git a/embed/mozilla/GeckoPrintSession.cpp b/embed/mozilla/GeckoPrintSession.cpp
index 290b0eb7a..50f050002 100644
--- a/embed/mozilla/GeckoPrintSession.cpp
+++ b/embed/mozilla/GeckoPrintSession.cpp
@@ -105,7 +105,7 @@ GeckoPrintSession::SetSettings (GtkPrintSettings *aSettings,
NS_ASSERTION (!mSettings && !mPageSetup && !mPrinter, "Already have settings!");
NS_ENSURE_ARG (aSettings);
- mSettings = aSettings; /* this one is adopted */
+ mSettings = (GtkPrintSettings *) g_object_ref (aSettings);
NS_ENSURE_ARG (aPageSetup);
NS_ENSURE_ARG (aPrinter);