aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog33
-rw-r--r--data/glade/print.glade35
-rw-r--r--embed/ephy-embed-single.c7
-rw-r--r--embed/ephy-embed-single.h15
-rw-r--r--embed/mozilla/ContentHandler.cpp6
-rw-r--r--embed/mozilla/EphyBrowser.cpp3
-rw-r--r--embed/mozilla/EphyHeaderSniffer.cpp1
-rw-r--r--embed/mozilla/EphyUtils.cpp142
-rw-r--r--embed/mozilla/EphyUtils.h18
-rw-r--r--embed/mozilla/FilePicker.cpp4
-rw-r--r--embed/mozilla/GtkNSSClientAuthDialogs.cpp4
-rw-r--r--embed/mozilla/GtkNSSDialogs.cpp18
-rw-r--r--embed/mozilla/GtkNSSKeyPairDialogs.cpp4
-rw-r--r--embed/mozilla/MozillaPrivate.cpp177
-rw-r--r--embed/mozilla/MozillaPrivate.h16
-rw-r--r--embed/mozilla/PrintingPromptService.cpp8
-rw-r--r--embed/mozilla/mozilla-embed-single.cpp9
-rw-r--r--embed/mozilla/mozilla-embed.cpp1
-rwxr-xr-xembed/print-dialog.c53
-rw-r--r--lib/ephy-dialog.c8
20 files changed, 342 insertions, 220 deletions
diff --git a/ChangeLog b/ChangeLog
index 02e059ac0..d461f8781 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,36 @@
+2004-10-10 Marco Pesenti Gritti <marco@gnome.org>
+
+ reviewed by: Christian Persch <chpe@cvs.gnome.org>
+
+ * data/glade/print.glade:
+ * embed/ephy-embed-single.c: (ephy_embed_single_get_printer_list):
+ * embed/ephy-embed-single.h:
+ * embed/mozilla/ContentHandler.cpp:
+ * embed/mozilla/EphyBrowser.cpp:
+ * embed/mozilla/EphyHeaderSniffer.cpp:
+ * embed/mozilla/EphyUtils.cpp:
+ * embed/mozilla/EphyUtils.h:
+ * embed/mozilla/FilePicker.cpp:
+ * embed/mozilla/GtkNSSClientAuthDialogs.cpp:
+ * embed/mozilla/GtkNSSDialogs.cpp:
+ * embed/mozilla/GtkNSSKeyPairDialogs.cpp:
+ * embed/mozilla/MozillaPrivate.cpp:
+ * embed/mozilla/MozillaPrivate.h:
+ * embed/mozilla/PrintingPromptService.cpp:
+ * embed/mozilla/mozilla-embed-single.cpp:
+ * embed/mozilla/mozilla-embed.cpp:
+ * embed/print-dialog.c: (ephy_print_dialog_new):
+ * lib/ephy-dialog.c: (set_combo_box_from_value):
+
+ Move current MozillaPrivate helpers to EphyUtils.
+ Use MozillaPrivate for stuff that needs mozilla
+ internal strings.
+
+ Support multiple printers in the print dialog.
+ This is actually a bug fix because on several
+ distributions using hardcoded Poscript/default
+ will simply not work at all.
+
2004-10-10 Christian Persch <chpe@cvs.gnome.org>
* configure.in:
diff --git a/data/glade/print.glade b/data/glade/print.glade
index 781242f6b..e8b32699f 100644
--- a/data/glade/print.glade
+++ b/data/glade/print.glade
@@ -1305,27 +1305,6 @@
</child>
<child>
- <widget class="GtkEntry" id="printer_entry">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="editable">True</property>
- <property name="visibility">True</property>
- <property name="max_length">0</property>
- <property name="text" translatable="yes">lpr</property>
- <property name="has_frame">True</property>
- <property name="invisible_char" translatable="yes">*</property>
- <property name="activates_default">False</property>
- </widget>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">0</property>
- <property name="bottom_attach">1</property>
- <property name="y_options"></property>
- </packing>
- </child>
-
- <child>
<widget class="GtkHBox" id="hbox92">
<property name="visible">True</property>
<property name="homogeneous">False</property>
@@ -1376,6 +1355,20 @@
<property name="y_options">fill</property>
</packing>
</child>
+
+ <child>
+ <widget class="GtkComboBox" id="printer_combobox">
+ <property name="visible">True</property>
+ </widget>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">0</property>
+ <property name="bottom_attach">1</property>
+ <property name="x_options">fill</property>
+ <property name="y_options">fill</property>
+ </packing>
+ </child>
</widget>
<packing>
<property name="padding">0</property>
diff --git a/embed/ephy-embed-single.c b/embed/ephy-embed-single.c
index 80788dada..22765f738 100644
--- a/embed/ephy-embed-single.c
+++ b/embed/ephy-embed-single.c
@@ -213,3 +213,10 @@ ephy_embed_single_open_window (EphyEmbedSingle *single,
EphyEmbedSingleIface *iface = EPHY_EMBED_SINGLE_GET_IFACE (single);
return iface->open_window (single, parent, address, name, features);
}
+
+GList *
+ephy_embed_single_get_printer_list (EphyEmbedSingle *single)
+{
+ EphyEmbedSingleIface *iface = EPHY_EMBED_SINGLE_GET_IFACE (single);
+ return iface->get_printer_list (single);
+}
diff --git a/embed/ephy-embed-single.h b/embed/ephy-embed-single.h
index 1b8894592..f37460a82 100644
--- a/embed/ephy-embed-single.h
+++ b/embed/ephy-embed-single.h
@@ -50,18 +50,19 @@ struct _EphyEmbedSingleIface
/* Methods */
- GtkWidget * (* open_window) (EphyEmbedSingle *single,
+ GtkWidget * (* open_window) (EphyEmbedSingle *single,
EphyEmbed *parent,
const char *address,
const char *name,
const char *features);
- void (* clear_cache) (EphyEmbedSingle *shell);
- void (* clear_auth_cache) (EphyEmbedSingle *shell);
- void (* set_offline_mode) (EphyEmbedSingle *shell,
+ void (* clear_cache) (EphyEmbedSingle *shell);
+ void (* clear_auth_cache) (EphyEmbedSingle *shell);
+ void (* set_offline_mode) (EphyEmbedSingle *shell,
gboolean offline);
- gboolean (* get_offline_mode) (EphyEmbedSingle *single);
- GList * (* get_font_list) (EphyEmbedSingle *shell,
+ gboolean (* get_offline_mode) (EphyEmbedSingle *single);
+ GList * (* get_font_list) (EphyEmbedSingle *shell,
const char *langGroup);
+ GList * (* get_printer_list) (EphyEmbedSingle *shell);
};
GType ephy_embed_single_get_type (void);
@@ -84,6 +85,8 @@ gboolean ephy_embed_single_get_offline_mode (EphyEmbedSingle *single);
GList *ephy_embed_single_get_font_list (EphyEmbedSingle *single,
const char *lang_group);
+GList *ephy_embed_single_get_printer_list (EphyEmbedSingle *single);
+
G_END_DECLS
#endif
diff --git a/embed/mozilla/ContentHandler.cpp b/embed/mozilla/ContentHandler.cpp
index 422597d03..48ba7951e 100644
--- a/embed/mozilla/ContentHandler.cpp
+++ b/embed/mozilla/ContentHandler.cpp
@@ -54,8 +54,8 @@
#include "eel-gconf-extensions.h"
#include "ContentHandler.h"
-#include "MozillaPrivate.h"
#include "MozDownload.h"
+#include "EphyUtils.h"
class GContentHandler;
@@ -143,7 +143,7 @@ NS_IMETHODIMP GContentHandler::PromptForSaveToFile(
}
nsCOMPtr<nsIDOMWindow> parentDOMWindow = do_GetInterface (aWindowContext);
- GtkWidget *parentWindow = GTK_WIDGET (MozillaFindGtkParent (parentDOMWindow));
+ GtkWidget *parentWindow = GTK_WIDGET (EphyUtils::FindGtkParent (parentDOMWindow));
dialog = ephy_file_chooser_new (_("Save"), parentWindow,
GTK_FILE_CHOOSER_ACTION_SAVE,
@@ -267,7 +267,7 @@ NS_METHOD GContentHandler::MIMEConfirmAction ()
int response;
nsCOMPtr<nsIDOMWindow> parentDOMWindow = do_GetInterface (mContext);
- GtkWindow *parentWindow = GTK_WINDOW (MozillaFindGtkParent(parentDOMWindow));
+ GtkWindow *parentWindow = GTK_WINDOW (EphyUtils::FindGtkParent(parentDOMWindow));
action_label = (mAction == CONTENT_ACTION_OPEN) ||
(mAction == CONTENT_ACTION_OPEN_TMP) ?
diff --git a/embed/mozilla/EphyBrowser.cpp b/embed/mozilla/EphyBrowser.cpp
index 655c3b110..040b7615f 100644
--- a/embed/mozilla/EphyBrowser.cpp
+++ b/embed/mozilla/EphyBrowser.cpp
@@ -26,7 +26,6 @@
#include "EphyBrowser.h"
#include "EphyUtils.h"
-#include "MozillaPrivate.h"
#include "ephy-embed.h"
#include "ephy-string.h"
#include "ephy-debug.h"
@@ -330,7 +329,7 @@ nsresult EphyBrowser::SetPrintPreviewMode (PRBool previewMode)
print->GetGlobalPrintSettings (getter_AddRefs(settings));
info = ephy_print_get_print_info ();
- MozillaCollatePrintSettings (info, settings, TRUE);
+ EphyUtils::CollatePrintSettings (info, settings, TRUE);
ephy_print_info_free (info);
rv = print->PrintPreview (nsnull, mDOMWindow, nsnull);
diff --git a/embed/mozilla/EphyHeaderSniffer.cpp b/embed/mozilla/EphyHeaderSniffer.cpp
index 955d8ed00..95636f98d 100644
--- a/embed/mozilla/EphyHeaderSniffer.cpp
+++ b/embed/mozilla/EphyHeaderSniffer.cpp
@@ -45,7 +45,6 @@
#include "config.h"
#endif
-#include "MozillaPrivate.h"
#include "MozDownload.h"
#include "EphyHeaderSniffer.h"
diff --git a/embed/mozilla/EphyUtils.cpp b/embed/mozilla/EphyUtils.cpp
index 9b271abaf..c5e0bf666 100644
--- a/embed/mozilla/EphyUtils.cpp
+++ b/embed/mozilla/EphyUtils.cpp
@@ -25,9 +25,15 @@
#endif
#include "EphyUtils.h"
+#include "ephy-embed-shell.h"
+#include "ephy-embed-single.h"
#include <nsIServiceManager.h>
#include <nsEmbedString.h>
+#include <nsIWindowWatcher.h>
+#include <nsIEmbeddingSiteWindow.h>
+#include <nsIWebBrowserChrome.h>
+#include <gtkmozembed.h>
nsresult
EphyUtils::GetIOService (nsIIOService **ioService)
@@ -64,3 +70,139 @@ nsresult EphyUtils::NewURI (nsIURI **result, const nsACString &spec)
return rv;
}
+
+GtkWidget *
+EphyUtils::FindEmbed (nsIDOMWindow *aDOMWindow)
+{
+ if (!aDOMWindow) return nsnull;
+
+ nsCOMPtr<nsIWindowWatcher> wwatch
+ (do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
+ NS_ENSURE_TRUE (wwatch, nsnull);
+
+ /* this DOM window may belong to some inner frame, we need
+ * to get the topmost DOM window to get the embed
+ */
+ nsCOMPtr<nsIDOMWindow> topWindow;
+ aDOMWindow->GetTop (getter_AddRefs (topWindow));
+ if (!topWindow) return nsnull;
+
+ nsCOMPtr<nsIWebBrowserChrome> windowChrome;
+ wwatch->GetChromeForWindow (topWindow, getter_AddRefs(windowChrome));
+ NS_ENSURE_TRUE (windowChrome, nsnull);
+
+ nsCOMPtr<nsIEmbeddingSiteWindow> window (do_QueryInterface(windowChrome));
+ NS_ENSURE_TRUE (window, nsnull);
+
+ nsresult rv;
+ GtkWidget *mozembed;
+ rv = window->GetSiteWindow ((void **)&mozembed);
+ NS_ENSURE_SUCCESS (rv, nsnull);
+
+ return mozembed;
+}
+
+GtkWidget *
+EphyUtils::FindGtkParent (nsIDOMWindow *aDOMWindow)
+{
+ GtkWidget *embed = FindEmbed (aDOMWindow);
+ NS_ENSURE_TRUE (embed, nsnull);
+
+ return gtk_widget_get_toplevel (GTK_WIDGET (embed));
+}
+
+#define MM_TO_INCH(x) (((double) x) / 25.4)
+
+nsresult
+EphyUtils::CollatePrintSettings (const EmbedPrintInfo *info,
+ nsIPrintSettings *options,
+ gboolean preview)
+{
+ const static int frame_types[] = {
+ nsIPrintSettings::kFramesAsIs,
+ nsIPrintSettings::kSelectedFrame,
+ nsIPrintSettings::kEachFrameSep
+ };
+
+ switch (info->pages)
+ {
+ case 0:
+ options->SetPrintRange (nsIPrintSettings::kRangeAllPages);
+ break;
+ case 1:
+ options->SetPrintRange (nsIPrintSettings::kRangeSpecifiedPageRange);
+ options->SetStartPageRange (info->from_page);
+ options->SetEndPageRange (info->to_page);
+ break;
+ case 2:
+ options->SetPrintRange (nsIPrintSettings::kRangeSelection);
+ break;
+ }
+
+ options->SetMarginTop (MM_TO_INCH (info->top_margin));
+ options->SetMarginBottom (MM_TO_INCH (info->bottom_margin));
+ options->SetMarginLeft (MM_TO_INCH (info->left_margin));
+ options->SetMarginRight (MM_TO_INCH (info->right_margin));
+
+ nsEmbedString tmp;
+
+ NS_CStringToUTF16 (nsEmbedCString(info->header_left_string),
+ NS_CSTRING_ENCODING_UTF8, tmp);
+ options->SetHeaderStrLeft (tmp.get());
+
+ NS_CStringToUTF16 (nsEmbedCString(info->header_center_string),
+ NS_CSTRING_ENCODING_UTF8, tmp);
+ options->SetHeaderStrCenter (tmp.get());
+
+ NS_CStringToUTF16 (nsEmbedCString(info->header_right_string),
+ NS_CSTRING_ENCODING_UTF8, tmp);
+ options->SetHeaderStrRight (tmp.get());
+
+ NS_CStringToUTF16 (nsEmbedCString(info->footer_left_string),
+ NS_CSTRING_ENCODING_UTF8, tmp);
+ options->SetFooterStrLeft (tmp.get());
+
+ NS_CStringToUTF16 (nsEmbedCString(info->footer_center_string),
+ NS_CSTRING_ENCODING_UTF8, tmp);
+ options->SetFooterStrCenter(tmp.get());
+
+ NS_CStringToUTF16 (nsEmbedCString(info->footer_right_string),
+ NS_CSTRING_ENCODING_UTF8, tmp);
+ options->SetFooterStrRight(tmp.get());
+
+ NS_CStringToUTF16 (nsEmbedCString(info->file),
+ NS_CSTRING_ENCODING_UTF8, tmp);
+ options->SetToFileName (tmp.get());
+
+ NS_CStringToUTF16 (nsEmbedCString(info->printer),
+ NS_CSTRING_ENCODING_UTF8, tmp);
+ options->SetPrinterName (tmp.get());
+
+ /**
+ * Work around a mozilla bug where paper size & orientation are ignored
+ * and the specified file is created (containing invalid postscript)
+ * in print preview mode if we set "print to file" to true.
+ * See epiphany bug #119818.
+ */
+ if (preview)
+ {
+ options->SetPrintToFile (PR_FALSE);
+ }
+ else
+ {
+ options->SetPrintToFile (info->print_to_file);
+ }
+
+ /* native paper size formats. Our dialog does not support custom yet */
+ options->SetPaperSize (nsIPrintSettings::kPaperSizeNativeData);
+
+ NS_CStringToUTF16 (nsEmbedCString(info->paper),
+ NS_CSTRING_ENCODING_UTF8, tmp);
+ options->SetPaperName (tmp.get());
+
+ options->SetPrintInColor (info->print_color);
+ options->SetOrientation (info->orientation);
+ options->SetPrintFrameType (frame_types[info->frame_type]);
+
+ return NS_OK;
+}
diff --git a/embed/mozilla/EphyUtils.h b/embed/mozilla/EphyUtils.h
index 0fcbe488a..2f81e0b4d 100644
--- a/embed/mozilla/EphyUtils.h
+++ b/embed/mozilla/EphyUtils.h
@@ -22,14 +22,26 @@
#include <nsIIOService.h>
#include <nsIURI.h>
+#include <nsIDOMWindow.h>
+#include <nsIPrintSettings.h>
+
+#include "print-dialog.h"
namespace EphyUtils
{
- nsresult GetIOService (nsIIOService **ioService);
+ nsresult GetIOService (nsIIOService **ioService);
+
+ nsresult NewURI (nsIURI **result, const nsAString &spec);
+
+ nsresult NewURI (nsIURI **result, const nsACString &spec);
+
+ GtkWidget *FindEmbed (nsIDOMWindow *aDOMWindow);
- nsresult NewURI (nsIURI **result, const nsAString &spec);
+ GtkWidget *FindGtkParent (nsIDOMWindow *aDOMWindow);
- nsresult NewURI (nsIURI **result, const nsACString &spec);
+ nsresult CollatePrintSettings (const EmbedPrintInfo *info,
+ nsIPrintSettings *settings,
+ gboolean preview);
}
#endif
diff --git a/embed/mozilla/FilePicker.cpp b/embed/mozilla/FilePicker.cpp
index a0e90f781..2a4c39ce5 100644
--- a/embed/mozilla/FilePicker.cpp
+++ b/embed/mozilla/FilePicker.cpp
@@ -26,7 +26,7 @@
#endif
#include "FilePicker.h"
-#include "MozillaPrivate.h"
+#include "EphyUtils.h"
#include <nsCOMPtr.h>
#include <nsEmbedString.h>
@@ -82,7 +82,7 @@ NS_IMETHODIMP GFilePicker::Init(nsIDOMWindowInternal *parent, const PRUnichar *t
{
LOG ("GFilePicker::Init")
- GtkWidget *gtkparent = MozillaFindGtkParent (parent);
+ GtkWidget *gtkparent = EphyUtils::FindGtkParent (parent);
#if defined(MOZ_NSIFILEPICKER_NSASTRING_)
NS_ENSURE_TRUE (gtkparent, NS_ERROR_FAILURE);
#endif
diff --git a/embed/mozilla/GtkNSSClientAuthDialogs.cpp b/embed/mozilla/GtkNSSClientAuthDialogs.cpp
index d95988111..74176e4f1 100644
--- a/embed/mozilla/GtkNSSClientAuthDialogs.cpp
+++ b/embed/mozilla/GtkNSSClientAuthDialogs.cpp
@@ -28,7 +28,7 @@
#ifdef HAVE_MOZILLA_PSM
-#include "MozillaPrivate.h"
+#include "EphyUtils.h"
#include <nsIServiceManager.h>
#include <nsIInterfaceRequestor.h>
@@ -146,7 +146,7 @@ GtkNSSClientAuthDialogs::ChooseCertificate (nsIInterfaceRequestor *ctx,
PRUint32 i;
nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx);
- GtkWidget *gparent = MozillaFindGtkParent (parent);
+ GtkWidget *gparent = EphyUtils::FindGtkParent (parent);
dialog = gtk_dialog_new_with_buttons ("",
GTK_WINDOW (gparent),
diff --git a/embed/mozilla/GtkNSSDialogs.cpp b/embed/mozilla/GtkNSSDialogs.cpp
index 1f8926760..035b044e6 100644
--- a/embed/mozilla/GtkNSSDialogs.cpp
+++ b/embed/mozilla/GtkNSSDialogs.cpp
@@ -34,7 +34,7 @@
#ifdef HAVE_MOZILLA_PSM
-#include "MozillaPrivate.h"
+#include "EphyUtils.h"
#include <nsCOMPtr.h>
#include <nsMemory.h>
@@ -209,7 +209,7 @@ display_cert_warning_box (nsIInterfaceRequestor *ctx,
int res;
nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx);
- GtkWidget *gparent = MozillaFindGtkParent (parent);
+ GtkWidget *gparent = EphyUtils::FindGtkParent (parent);
g_return_val_if_fail (markup_text, GTK_RESPONSE_CANCEL);
g_return_val_if_fail (!checkbox_text || checkbox_value, GTK_RESPONSE_CANCEL);
@@ -478,7 +478,7 @@ GtkNSSDialogs::NotifyCrlNextupdate (nsIInterfaceRequestor *ctx,
char *ttCommonName, *ttTargetUrl, *msg, *primary, *secondary;
nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx);
- GtkWidget *gparent = MozillaFindGtkParent (parent);
+ GtkWidget *gparent = EphyUtils::FindGtkParent (parent);
dialog = gtk_dialog_new_with_buttons ("",
GTK_WINDOW (gparent),
@@ -541,7 +541,7 @@ GtkNSSDialogs::ConfirmDownloadCACert(nsIInterfaceRequestor *ctx,
char *ttCommonName, *msg, *tertiary;
nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx);
- GtkWidget *gparent = MozillaFindGtkParent (parent);
+ GtkWidget *gparent = EphyUtils::FindGtkParent (parent);
dialog = gtk_dialog_new_with_buttons ("",
GTK_WINDOW (gparent),
@@ -638,7 +638,7 @@ GtkNSSDialogs::NotifyCACertExists (nsIInterfaceRequestor *ctx)
char * msg;
nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx);
- GtkWidget *gparent = MozillaFindGtkParent (parent);
+ GtkWidget *gparent = EphyUtils::FindGtkParent (parent);
dialog = gtk_dialog_new_with_buttons ("",
GTK_WINDOW (gparent),
@@ -758,7 +758,7 @@ GtkNSSDialogs::SetPKCS12FilePassword(nsIInterfaceRequestor *ctx,
char *msg;
nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx);
- GtkWidget *gparent = MozillaFindGtkParent (parent);
+ GtkWidget *gparent = EphyUtils::FindGtkParent (parent);
dialog = gtk_dialog_new_with_buttons ("",
@@ -869,7 +869,7 @@ GtkNSSDialogs::GetPKCS12FilePassword(nsIInterfaceRequestor *ctx,
char *msg;
nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx);
- GtkWidget *gparent = MozillaFindGtkParent (parent);
+ GtkWidget *gparent = EphyUtils::FindGtkParent (parent);
dialog = gtk_dialog_new_with_buttons ("",
GTK_WINDOW (gparent),
@@ -951,7 +951,7 @@ GtkNSSDialogs::CrlImportStatusDialog(nsIInterfaceRequestor *ctx, nsICRLInfo *crl
char *msg;
nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx);
- GtkWidget *gparent = MozillaFindGtkParent (parent);
+ GtkWidget *gparent = EphyUtils::FindGtkParent (parent);
dialog = gtk_dialog_new_with_buttons ("",
GTK_WINDOW (gparent),
@@ -1297,7 +1297,7 @@ GtkNSSDialogs::ViewCert(nsIInterfaceRequestor *ctx,
&dialog, NULL, NULL);
nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx);
- GtkWidget *gparent = MozillaFindGtkParent (parent);
+ GtkWidget *gparent = EphyUtils::FindGtkParent (parent);
gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(gparent));
gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
diff --git a/embed/mozilla/GtkNSSKeyPairDialogs.cpp b/embed/mozilla/GtkNSSKeyPairDialogs.cpp
index 55fa5968c..03a6f881e 100644
--- a/embed/mozilla/GtkNSSKeyPairDialogs.cpp
+++ b/embed/mozilla/GtkNSSKeyPairDialogs.cpp
@@ -43,7 +43,7 @@
#ifdef HAVE_MOZILLA_PSM
-#include "MozillaPrivate.h"
+#include "EphyUtils.h"
#include <nsIServiceManager.h>
#include <nsIInterfaceRequestor.h>
@@ -169,7 +169,7 @@ GtkNSSKeyPairDialogs::DisplayGeneratingKeypairInfo (nsIInterfaceRequestor *ctx,
nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx);
- GtkWidget *gparent = MozillaFindGtkParent (parent);
+ GtkWidget *gparent = EphyUtils::FindGtkParent (parent);
dialog = gtk_dialog_new_with_buttons ("", GTK_WINDOW (gparent),
GTK_DIALOG_NO_SEPARATOR, NULL);
diff --git a/embed/mozilla/MozillaPrivate.cpp b/embed/mozilla/MozillaPrivate.cpp
index fdece6738..74afc615e 100644
--- a/embed/mozilla/MozillaPrivate.cpp
+++ b/embed/mozilla/MozillaPrivate.cpp
@@ -18,159 +18,56 @@
* $Id$
*/
-#include "mozilla-config.h"
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "ephy-embed.h"
-#include "mozilla-embed.h"
-
#include "MozillaPrivate.h"
-#include <nsEmbedString.h>
-#include <nsIServiceManagerUtils.h>
-#include <nsIWindowWatcher.h>
-#include <nsIEmbeddingSiteWindow.h>
-#include <nsIWebBrowserChrome.h>
-#include <gtkmozembed.h>
-
-GtkWidget *MozillaFindEmbed (nsIDOMWindow *aDOMWindow)
-{
- if (!aDOMWindow) return nsnull;
-
- nsCOMPtr<nsIWindowWatcher> wwatch
- (do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
- NS_ENSURE_TRUE (wwatch, nsnull);
-
- /* this DOM window may belong to some inner frame, we need
- * to get the topmost DOM window to get the embed
- */
- nsCOMPtr<nsIDOMWindow> topWindow;
- aDOMWindow->GetTop (getter_AddRefs (topWindow));
- if (!topWindow) return nsnull;
-
- nsCOMPtr<nsIWebBrowserChrome> windowChrome;
- wwatch->GetChromeForWindow (topWindow, getter_AddRefs(windowChrome));
- NS_ENSURE_TRUE (windowChrome, nsnull);
-
- nsCOMPtr<nsIEmbeddingSiteWindow> window (do_QueryInterface(windowChrome));
- NS_ENSURE_TRUE (window, nsnull);
-
- nsresult rv;
- GtkWidget *mozembed;
- rv = window->GetSiteWindow ((void **)&mozembed);
- NS_ENSURE_SUCCESS (rv, nsnull);
-
- return mozembed;
-}
-
-GtkWidget *MozillaFindGtkParent (nsIDOMWindow *aDOMWindow)
-{
- GtkWidget *embed = MozillaFindEmbed (aDOMWindow);
- NS_ENSURE_TRUE (embed, nsnull);
-
- return gtk_widget_get_toplevel (GTK_WIDGET (embed));
-}
+#include <nsIPrintSettingsService.h>
+#include <nsIPrintOptions.h>
+#include <nsIServiceManager.h>
+#include <nsISimpleEnumerator.h>
+#include <nsISupportsPrimitives.h>
-#define MM_TO_INCH(x) (((double) x) / 25.4)
+/* IMPORTANT. Put only code that use internal mozilla strings (nsAutoString for
+ * example) in this file. Note that you cannot use embed strings here,
+ * the header inclusions will conflict.
+ */
-NS_METHOD MozillaCollatePrintSettings (const EmbedPrintInfo *info,
- nsIPrintSettings *options,
- gboolean preview)
+GList *
+MozillaPrivate::GetPrinterList ()
{
- const static int frame_types[] = {
- nsIPrintSettings::kFramesAsIs,
- nsIPrintSettings::kSelectedFrame,
- nsIPrintSettings::kEachFrameSep
- };
-
-
- switch (info->pages)
- {
- case 0:
- options->SetPrintRange (nsIPrintSettings::kRangeAllPages);
- break;
- case 1:
- options->SetPrintRange (nsIPrintSettings::kRangeSpecifiedPageRange);
- options->SetStartPageRange (info->from_page);
- options->SetEndPageRange (info->to_page);
- break;
- case 2:
- options->SetPrintRange (nsIPrintSettings::kRangeSelection);
- break;
- }
-
- options->SetMarginTop (MM_TO_INCH (info->top_margin));
- options->SetMarginBottom (MM_TO_INCH (info->bottom_margin));
- options->SetMarginLeft (MM_TO_INCH (info->left_margin));
- options->SetMarginRight (MM_TO_INCH (info->right_margin));
-
- PRUnichar postscript[] = { 'P', 'o', 's', 't', 'S', 'c', 'r', 'i',
- 'p', 't', '/', 'd', 'e', 'f', 'a', 'u',
- 'l', 't', '\0' };
- options->SetPrinterName(postscript);
-
- nsEmbedString tmp;
-
- NS_CStringToUTF16 (nsEmbedCString(info->header_left_string),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetHeaderStrLeft (tmp.get());
+ GList *printers = NULL;
+ nsresult rv = NS_OK;
- NS_CStringToUTF16 (nsEmbedCString(info->header_center_string),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetHeaderStrCenter (tmp.get());
+ nsCOMPtr<nsIPrintSettingsService> pss =
+ do_GetService("@mozilla.org/gfx/printsettings-service;1", &rv);
+ NS_ENSURE_SUCCESS(rv, nsnull);
- NS_CStringToUTF16 (nsEmbedCString(info->header_right_string),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetHeaderStrRight (tmp.get());
+ nsCOMPtr<nsIPrintOptions> po = do_QueryInterface(pss, &rv);
+ NS_ENSURE_SUCCESS(rv, nsnull);
- NS_CStringToUTF16 (nsEmbedCString(info->footer_left_string),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetFooterStrLeft (tmp.get());
+ nsCOMPtr<nsISimpleEnumerator> avPrinters;
+ rv = po->AvailablePrinters(getter_AddRefs(avPrinters));
+ NS_ENSURE_SUCCESS(rv, nsnull);
- NS_CStringToUTF16 (nsEmbedCString(info->footer_center_string),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetFooterStrCenter(tmp.get());
+ PRBool more = PR_FALSE;
- NS_CStringToUTF16 (nsEmbedCString(info->footer_right_string),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetFooterStrRight(tmp.get());
-
- NS_CStringToUTF16 (nsEmbedCString(info->file),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetToFileName (tmp.get());
-
- NS_CStringToUTF16 (nsEmbedCString(info->printer),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetPrintCommand (tmp.get());
-
- /**
- * Work around a mozilla bug where paper size & orientation are ignored
- * and the specified file is created (containing invalid postscript)
- * in print preview mode if we set "print to file" to true.
- * See epiphany bug #119818.
- */
- if (preview)
+ for (avPrinters->HasMoreElements(&more);
+ more == PR_TRUE;
+ avPrinters->HasMoreElements(&more))
{
- options->SetPrintToFile (PR_FALSE);
- }
- else
- {
- options->SetPrintToFile (info->print_to_file);
- }
+ nsCOMPtr<nsISupports> i;
+ rv = avPrinters->GetNext(getter_AddRefs(i));
+ NS_ENSURE_SUCCESS(rv, nsnull);
- /* native paper size formats. Our dialog does not support custom yet */
- options->SetPaperSize (nsIPrintSettings::kPaperSizeNativeData);
+ nsCOMPtr<nsISupportsString> printer = do_QueryInterface(i, &rv);
+ NS_ENSURE_SUCCESS(rv, nsnull);
- NS_CStringToUTF16 (nsEmbedCString(info->paper),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetPaperName (tmp.get());
+ nsAutoString data;
+ rv = printer->GetData(data);
+ NS_ENSURE_SUCCESS(rv, nsnull);
- options->SetPrintInColor (info->print_color);
- options->SetOrientation (info->orientation);
- options->SetPrintFrameType (frame_types[info->frame_type]);
+ const char *name = NS_ConvertUCS2toUTF8 (data).get();
+ printers = g_list_prepend (printers, g_strdup (name));
+ }
- return NS_OK;
+ return g_list_reverse (printers);
}
diff --git a/embed/mozilla/MozillaPrivate.h b/embed/mozilla/MozillaPrivate.h
index 83966097a..fb0fc83d1 100644
--- a/embed/mozilla/MozillaPrivate.h
+++ b/embed/mozilla/MozillaPrivate.h
@@ -17,15 +17,9 @@
*
*/
-#include <nsIPrintSettings.h>
-#include <nsIDOMWindow.h>
+#include <glib.h>
-#include "print-dialog.h"
-
-GtkWidget *MozillaFindEmbed (nsIDOMWindow *aDOMWindow);
-
-GtkWidget *MozillaFindGtkParent (nsIDOMWindow *aDOMWindow);
-
-NS_METHOD MozillaCollatePrintSettings (const EmbedPrintInfo *info,
- nsIPrintSettings *settings,
- gboolean preview);
+namespace MozillaPrivate
+{
+ GList *GetPrinterList ();
+}
diff --git a/embed/mozilla/PrintingPromptService.cpp b/embed/mozilla/PrintingPromptService.cpp
index 3eb4886ec..05138e86d 100644
--- a/embed/mozilla/PrintingPromptService.cpp
+++ b/embed/mozilla/PrintingPromptService.cpp
@@ -30,7 +30,7 @@
#include "print-dialog.h"
#include "ephy-embed.h"
#include "ephy-command-manager.h"
-#include "MozillaPrivate.h"
+#include "EphyUtils.h"
#include "PrintingPromptService.h"
#include "eel-gconf-extensions.h"
#include "ephy-prefs.h"
@@ -63,13 +63,13 @@ NS_IMETHODIMP GPrintingPromptService::ShowPrintDialog(nsIDOMWindow *parent, nsIW
return NS_ERROR_ABORT;
}
- EphyEmbed *embed = EPHY_EMBED (MozillaFindEmbed (parent));
+ EphyEmbed *embed = EPHY_EMBED (EphyUtils::FindEmbed (parent));
NS_ENSURE_TRUE (embed, NS_ERROR_FAILURE);
if (!(eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_PRINT_SETUP) ||
eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_COMMAND_LINE)))
{
- GtkWidget *gtkParent = MozillaFindGtkParent(parent);
+ GtkWidget *gtkParent = EphyUtils::FindGtkParent(parent);
NS_ENSURE_TRUE (gtkParent, NS_ERROR_FAILURE);
dialog = ephy_print_dialog_new (gtkParent, embed);
@@ -96,7 +96,7 @@ NS_IMETHODIMP GPrintingPromptService::ShowPrintDialog(nsIDOMWindow *parent, nsIW
info->pages = 0;
}
- MozillaCollatePrintSettings (info, printSettings, FALSE);
+ EphyUtils::CollatePrintSettings (info, printSettings, FALSE);
ephy_print_info_free (info);
diff --git a/embed/mozilla/mozilla-embed-single.cpp b/embed/mozilla/mozilla-embed-single.cpp
index e6af11890..91b27dcce 100644
--- a/embed/mozilla/mozilla-embed-single.cpp
+++ b/embed/mozilla/mozilla-embed-single.cpp
@@ -628,6 +628,12 @@ impl_get_offline_mode (EphyEmbedSingle *shell)
}
static GList *
+impl_get_printer_list (EphyEmbedSingle *shell)
+{
+ return MozillaPrivate::GetPrinterList ();
+}
+
+static GList *
impl_get_font_list (EphyEmbedSingle *shell,
const char *langGroup)
{
@@ -959,7 +965,7 @@ impl_open_window (EphyEmbedSingle *single,
wWatch->OpenWindow (domWindow, address, name, features, nsnull,
getter_AddRefs (newWindow));
- return MozillaFindEmbed (newWindow);
+ return EphyUtils::FindEmbed (newWindow);
}
static void
@@ -984,6 +990,7 @@ ephy_embed_single_iface_init (EphyEmbedSingleIface *iface)
iface->get_offline_mode = impl_get_offline_mode;
iface->get_font_list = impl_get_font_list;
iface->open_window = impl_open_window;
+ iface->get_printer_list = impl_get_printer_list;
}
static void
diff --git a/embed/mozilla/mozilla-embed.cpp b/embed/mozilla/mozilla-embed.cpp
index 7d98478cf..bf71f361e 100644
--- a/embed/mozilla/mozilla-embed.cpp
+++ b/embed/mozilla/mozilla-embed.cpp
@@ -32,7 +32,6 @@
#include "ephy-string.h"
#include "ephy-debug.h"
-#include "MozillaPrivate.h"
#include "EphyBrowser.h"
#include "EventContext.h"
#include "EphyUtils.h"
diff --git a/embed/print-dialog.c b/embed/print-dialog.c
index c36bd3d8a..db25e54f7 100755
--- a/embed/print-dialog.c
+++ b/embed/print-dialog.c
@@ -25,6 +25,8 @@
#include "print-dialog.h"
#include "ephy-embed-dialog.h"
+#include "ephy-embed-single.h"
+#include "ephy-embed-shell.h"
#include "ephy-file-chooser.h"
#include "ephy-file-helpers.h"
#include "ephy-stock-icons.h"
@@ -36,10 +38,13 @@
#include <gtk/gtkdialog.h>
#include <gtk/gtkentry.h>
#include <gtk/gtkstock.h>
+#include <gtk/gtkcombobox.h>
+#include <gtk/gtkcellrenderertext.h>
+#include <gtk/gtkcelllayout.h>
#include <libgnomevfs/gnome-vfs-utils.h>
#include <glib/gi18n.h>
-#define CONF_PRINT_PRINTER "/apps/epiphany/dialogs/print_printer"
+#define CONF_PRINT_PRINTER "/apps/epiphany/dialogs/print_printer_name"
#define CONF_PRINT_FILE "/apps/epiphany/dialogs/print_file"
#define CONF_PRINT_DIR "/apps/epiphany/directories/print_to_file"
#define CONF_PRINT_PRINTON "/apps/epiphany/dialogs/print_on"
@@ -72,12 +77,18 @@ enum
FROM_PROP
};
+enum
+{
+ COL_PRINTER_DISPLAY_NAME,
+ COL_PRINTER_NAME
+};
+
static const
EphyDialogProperty print_props [] =
{
{ "print_dialog", NULL, PT_NORMAL, 0 },
{ "printer_radiobutton", CONF_PRINT_PRINTON, PT_AUTOAPPLY, 0 },
- { "printer_entry", CONF_PRINT_PRINTER, PT_AUTOAPPLY, 0 },
+ { "printer_combobox", CONF_PRINT_PRINTER, PT_AUTOAPPLY, G_TYPE_STRING },
{ "file_entry", CONF_PRINT_FILE, PT_AUTOAPPLY, 0 },
{ "browse_button", NULL, PT_NORMAL, 0 },
{ "all_pages_radiobutton", CONF_PRINT_ALL_PAGES, PT_AUTOAPPLY, 0 },
@@ -356,8 +367,13 @@ ephy_print_dialog_new (GtkWidget *parent,
EphyEmbed *embed)
{
EphyDialog *dialog;
- GtkWidget *window, *button;
GdkPixbuf *icon;
+ GtkWidget *widget, *window;
+ GList *printers, *l;
+ GtkListStore *store;
+ GtkTreeIter iter;
+ GtkCellRenderer *renderer;
+ EphyEmbedSingle *single;
dialog = EPHY_DIALOG (g_object_new (EPHY_TYPE_EMBED_DIALOG,
"embed", embed,
@@ -382,8 +398,35 @@ ephy_print_dialog_new (GtkWidget *parent,
gtk_window_set_icon (GTK_WINDOW (window), icon);
g_object_unref (icon);
- button = ephy_dialog_get_control (dialog, print_props[BROWSE_PROP].id);
- gtk_widget_set_sensitive (button, eel_gconf_key_is_writable (CONF_PRINT_FILE));
+ widget = ephy_dialog_get_control (dialog, print_props[BROWSE_PROP].id);
+ gtk_widget_set_sensitive (widget, eel_gconf_key_is_writable (CONF_PRINT_FILE));
+
+ widget = ephy_dialog_get_control (dialog, print_props[PRINTER_PROP].id);
+ single = EPHY_EMBED_SINGLE (ephy_embed_shell_get_embed_single (embed_shell));
+ store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
+
+ printers = ephy_embed_single_get_printer_list (single);
+ for (l = printers; l != NULL; l = l->next)
+ {
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ COL_PRINTER_DISPLAY_NAME, l->data,
+ COL_PRINTER_NAME, l->data,
+ -1);
+ }
+ g_list_foreach (printers, (GFunc)g_free, NULL);
+ g_list_free (printers);
+
+ gtk_combo_box_set_model (GTK_COMBO_BOX (widget), GTK_TREE_MODEL (store));
+ g_object_unref (store);
+
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (widget), renderer, TRUE);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (widget), renderer,
+ "text", COL_PRINTER_DISPLAY_NAME,
+ NULL);
+ ephy_dialog_set_data_column (dialog, print_props[PRINTER_PROP].id,
+ COL_PRINTER_NAME);
return dialog;
}
diff --git a/lib/ephy-dialog.c b/lib/ephy-dialog.c
index 15e5c5aad..09ead6a75 100644
--- a/lib/ephy-dialog.c
+++ b/lib/ephy-dialog.c
@@ -587,13 +587,7 @@ set_combo_box_from_value (PropertyInfo *info, const GValue *value)
}
else
{
- char *v;
-
- gtk_combo_box_set_active (GTK_COMBO_BOX (info->widget), -1);
-
- v = g_strdup_value_contents (value);
- g_warning ("Value '%s' not found in model for combo %s\n", v, info->id);
- g_free (v);
+ gtk_combo_box_set_active (GTK_COMBO_BOX (info->widget), 0);
}
info->sane_state = found;