Bug 565013: Implement printing to PDF for qt builds. r=romaxa r=dholbert a=blocking-fennec
authorTom Brinkman <reportbase@gmail.com>
Thu, 07 Oct 2010 12:19:33 -0700
changeset 55144 40ea53a130a3de35849b99c762921762bbbfa3e1
parent 55143 ee9d604a8ed5fc1a41cfc058db7d16a7f535ccfd
child 55145 416db086984109c66012d94c75129a0b350fee08
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersromaxa, dholbert, blocking-fennec
bugs565013
milestone2.0b8pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 565013: Implement printing to PDF for qt builds. r=romaxa r=dholbert a=blocking-fennec
configure.in
gfx/cairo/cairo/src/Makefile.in
gfx/src/thebes/nsThebesDeviceContext.cpp
gfx/thebes/Makefile.in
widget/src/qt/Makefile.in
widget/src/qt/nsDeviceContextSpecQt.cpp
widget/src/qt/nsDeviceContextSpecQt.h
widget/src/qt/nsPrintDialogQt.cpp
widget/src/qt/nsPrintDialogQt.h
widget/src/qt/nsPrintOptionsQt.cpp
widget/src/qt/nsPrintOptionsQt.h
widget/src/qt/nsPrintSettingsQt.cpp
widget/src/qt/nsPrintSettingsQt.h
widget/src/qt/nsWidgetFactory.cpp
--- a/configure.in
+++ b/configure.in
@@ -5191,17 +5191,16 @@ cairo-gtk2-dfb)
 
 cairo-qt)
     MOZ_WIDGET_TOOLKIT=qt
     MOZ_ENABLE_QT=1
     MOZ_ENABLE_XREMOTE=1
     MOZ_WEBGL=1
     MOZ_WEBGL_GLX=1
     USE_ELF_DYNSTR_GC=
-    NS_PRINTING=
 
     AC_DEFINE(MOZ_X11)
     MOZ_X11=1
     USE_FC_FREETYPE=1
 
     TK_CFLAGS='$(MOZ_QT_CFLAGS)'
     TK_LIBS='$(MOZ_QT_LIBS)'
     AC_DEFINE(MOZ_WIDGET_QT)
@@ -5841,21 +5840,16 @@ fi
 dnl ========================================================
 dnl Disable printing
 dnl ========================================================
 MOZ_ARG_DISABLE_BOOL(printing,
 [  --disable-printing      Disable printing support],
     NS_PRINTING=,
     NS_PRINTING=1)
 
-if test "$MOZ_WIDGET_TOOLKIT" = "qt"; then
-    AC_MSG_WARN([Printing does not work with Qt at this time. Omitting printing support.])
-    NS_PRINTING=
-fi
-
 if test "$NS_PRINTING"; then
     AC_DEFINE(NS_PRINTING)
     AC_DEFINE(NS_PRINT_PREVIEW)
 fi
 dnl ========================================================
 dnl use native unicode converters
 dnl ========================================================
 MOZ_ARG_ENABLE_BOOL(native-uconv,
--- a/gfx/cairo/cairo/src/Makefile.in
+++ b/gfx/cairo/cairo/src/Makefile.in
@@ -205,17 +205,19 @@ endif
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
 CSRCS   += $(PSPDF_BASE_CSRCS) $(PDF_CSRCS) $(PS_CSRCS)
 EXPORTS_cairo += $(PDF_EXPORTS) $(PS_EXPORTS)
 endif
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),qt)
 CPPSRCS += cairo-qt-surface.cpp
+CSRCS   += $(PSPDF_BASE_CSRCS) $(PDF_CSRCS) 
 EXPORTS_cairo += cairo-qt.h
+EXPORTS_cairo += $(PDF_EXPORTS)
 OS_INCLUDES += $(MOZ_QT_CFLAGS)
 endif
 
 ifdef BUILD_CAIRO_SVG
 CSRCS	+= cairo-svg-surface.c
 EXPORTS_cairo += cairo-svg.h
 endif
 
--- a/gfx/src/thebes/nsThebesDeviceContext.cpp
+++ b/gfx/src/thebes/nsThebesDeviceContext.cpp
@@ -82,16 +82,17 @@ static nsSystemFontsOS2 *gSystemFonts = 
 static nsSystemFontsBeOS *gSystemFonts = nsnull;
 #elif XP_MACOSX
 #include "nsSystemFontsMac.h"
 #include "gfxQuartzSurface.h"
 #include "gfxImageSurface.h"
 static nsSystemFontsMac *gSystemFonts = nsnull;
 #elif defined(MOZ_WIDGET_QT)
 #include "nsSystemFontsQt.h"
+#include "gfxPDFSurface.h"
 static nsSystemFontsQt *gSystemFonts = nsnull;
 #elif defined(ANDROID)
 #include "nsSystemFontsAndroid.h"
 static nsSystemFontsAndroid *gSystemFonts = nsnull;
 #else
 #error Need to declare gSystemFonts!
 #endif
 
@@ -1103,17 +1104,17 @@ nsThebesDeviceContext::CalcPrintingSize(
 
     gfxSize size;
     switch (mPrintingSurface->GetType()) {
     case gfxASurface::SurfaceTypeImage:
         inPoints = PR_FALSE;
         size = reinterpret_cast<gfxImageSurface*>(mPrintingSurface.get())->GetSize();
         break;
 
-#if defined(MOZ_ENABLE_GTK2) || defined(XP_WIN) || defined(XP_OS2)
+#if defined(MOZ_ENABLE_GTK2) || defined(XP_WIN) || defined(XP_OS2) || defined(MOZ_WIDGET_QT)
     case gfxASurface::SurfaceTypePDF:
         inPoints = PR_TRUE;
         size = reinterpret_cast<gfxPDFSurface*>(mPrintingSurface.get())->GetSize();
         break;
 #endif
 
 #ifdef MOZ_ENABLE_GTK2
     case gfxASurface::SurfaceTypePS:
--- a/gfx/thebes/Makefile.in
+++ b/gfx/thebes/Makefile.in
@@ -117,16 +117,17 @@ EXPORTS	+= \
 endif
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),qt)
 EXPORTS += \
 	gfxFT2FontBase.h \
 	gfxQPainterSurface.h \
 	gfxQtNativeRenderer.h \
 	gfxQtPlatform.h \
+	gfxPDFSurface.h \
 	$(NULL)
 
 ifdef MOZ_X11
 EXPORTS += \
 	gfxXlibSurface.h \
 	GLXLibrary.h \
 	$(NULL)
 endif
@@ -345,16 +346,17 @@ ifdef MOZ_PANGO
 CPPSRCS += gfxPangoFonts.cpp
 else
 CPPSRCS += gfxFT2Fonts.cpp
 endif
 CPPSRCS +=	gfxFT2FontBase.cpp
 CPPSRCS +=	gfxFT2Utils.cpp
 CPPSRCS +=	gfxFontconfigUtils.cpp
 CPPSRCS +=	nsUnicodeRange.cpp
+CPPSRCS +=	gfxPDFSurface.cpp
 EXTRA_DSO_LDOPTS += $(MOZ_PANGO_LIBS) $(ZLIB_LIBS) $(XLDFLAGS) $(XLIBS) $(CAIRO_FT_LIBS) $(XEXT_LIBS)
 endif
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),beos)
 CPPSRCS	+= 	gfxBeOSSurface.cpp gfxBeOSPlatform.cpp
 CPPSRCS +=	gfxPangoFonts.cpp 
 CPPSRCS +=	gfxFT2FontBase.cpp
 CPPSRCS +=	gfxFT2Utils.cpp
--- a/widget/src/qt/Makefile.in
+++ b/widget/src/qt/Makefile.in
@@ -70,16 +70,20 @@ CPPSRCS	= \
 		nsClipboard.cpp \
 		nsBidiKeyboard.cpp \
 		nsIdleServiceQt.cpp \
 		nsDragService.cpp \
 		nsNativeThemeQt.cpp \
 		mozqwidget.cpp \
 		nsSound.cpp \
 		nsFilePicker.cpp \
+		nsPrintOptionsQt.cpp \
+		nsPrintSettingsQt.cpp \
+		nsPrintDialogQt.cpp \
+		nsDeviceContextSpecQt.cpp \
 		$(NULL)
 
 SHARED_LIBRARY_LIBS = ../xpwidgets/libxpwidgets_s.a
 
 EXTRA_DSO_LDOPTS = \
 		$(MOZ_COMPONENT_LIBS) \
 		-lgkgfx \
 		-lthebes \
copy from widget/src/gtk2/nsDeviceContextSpecG.cpp
copy to widget/src/qt/nsDeviceContextSpecQt.cpp
--- a/widget/src/gtk2/nsDeviceContextSpecG.cpp
+++ b/widget/src/qt/nsDeviceContextSpecQt.cpp
@@ -1,9 +1,9 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
@@ -19,1010 +19,298 @@
  * Portions created by the Initial Developer are Copyright (C) 1998
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
  *   Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
  *   Ken Herron <kherron+mozilla@fmailbox.com>
  *   Julien Lafon <julien.lafon@gmail.com>
  *   Michael Ventnor <m.ventnor@gmail.com>
+ *   Florian Hänel <heeen@gmx.de>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either of the GNU General Public License Version 2 or later (the "GPL"),
  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
- 
-/* Store per-printer features in temp. prefs vars that the
- * print dialog can pick them up... */
-#define SET_PRINTER_FEATURES_VIA_PREFS 1 
+
+
+#include <QTemporaryFile>
+#include <QPrinterInfo>
+
+#define SET_PRINTER_FEATURES_VIA_PREFS 1
 #define PRINTERFEATURES_PREF "print.tmp.printerfeatures"
 
 #ifdef MOZ_LOGGING
 #define FORCE_PR_LOG 1 /* Allow logging in the release build */
 #endif /* MOZ_LOGGING */
 #include "prlog.h"
 
 #include "plstr.h"
 
-#include "nsDeviceContextSpecG.h"
+#include "nsDeviceContextSpecQt.h"
 
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
 #include "prenv.h" /* for PR_GetEnv */
 
 #include "nsPrintfCString.h"
 #include "nsReadableUtils.h"
 #include "nsStringEnumerator.h"
-#include "nsIServiceManager.h" 
-
-#include "nsPSPrinters.h"
-#include "nsPaperPS.h"  /* Paper size list */
-
-#include "nsPrintSettingsGTK.h"
-
+#include "nsIServiceManager.h"
+#include "nsPrintSettingsQt.h"
 #include "nsIFileStreams.h"
 #include "nsILocalFile.h"
 #include "nsTArray.h"
 
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 
+#include "gfxPDFSurface.h"
+ 
 /* Ensure that the result is always equal to either PR_TRUE or PR_FALSE */
 #define MAKE_PR_BOOL(val) ((val)?(PR_TRUE):(PR_FALSE))
 
-#ifdef PR_LOGGING 
-static PRLogModuleInfo *DeviceContextSpecGTKLM = PR_NewLogModule("DeviceContextSpecGTK");
+#ifdef PR_LOGGING
+static PRLogModuleInfo* DeviceContextSpecQtLM =
+    PR_NewLogModule("DeviceContextSpecQt");
 #endif /* PR_LOGGING */
 /* Macro to make lines shorter */
-#define DO_PR_DEBUG_LOG(x) PR_LOG(DeviceContextSpecGTKLM, PR_LOG_DEBUG, x)
-
-//----------------------------------------------------------------------------------
-// The printer data is shared between the PrinterEnumerator and the nsDeviceContextSpecGTK
-// The PrinterEnumerator creates the printer info
-// but the nsDeviceContextSpecGTK cleans it up
-// If it gets created (via the Page Setup Dialog) but the user never prints anything
-// then it will never be delete, so this class takes care of that.
-class GlobalPrinters {
-public:
-  static GlobalPrinters* GetInstance()   { return &mGlobalPrinters; }
-  ~GlobalPrinters()                      { FreeGlobalPrinters(); }
-
-  void      FreeGlobalPrinters();
-  nsresult  InitializeGlobalPrinters();
-
-  PRBool    PrintersAreAllocated()       { return mGlobalPrinterList != nsnull; }
-  PRUint32  GetNumPrinters()
-    { return mGlobalPrinterList ? mGlobalPrinterList->Length() : 0; }
-  nsString* GetStringAt(PRInt32 aInx)    { return &mGlobalPrinterList->ElementAt(aInx); }
-  void      GetDefaultPrinterName(PRUnichar **aDefaultPrinterName);
-
-protected:
-  GlobalPrinters() {}
-
-  static GlobalPrinters mGlobalPrinters;
-  static nsTArray<nsString>* mGlobalPrinterList;
-};
-
-#ifdef SET_PRINTER_FEATURES_VIA_PREFS
-/* "Prototype" for the new nsPrinterFeatures service */
-class nsPrinterFeatures {
-public:
-  nsPrinterFeatures( const char *printername );
-  ~nsPrinterFeatures() {}
-
-  /* Does this printer allow to set/change the paper size ? */
-  void SetCanChangePaperSize( PRBool aCanSetPaperSize );
-  /* Does this Mozilla print module allow set/change the paper size ? */
-  void SetSupportsPaperSizeChange( PRBool aSupportsPaperSizeChange );
-  /* Set number of paper size records and the records itself */
-  void SetNumPaperSizeRecords( PRInt32 aCount );
-  void SetPaperRecord( PRInt32 aIndex, const char *aName, PRInt32 aWidthMM, PRInt32 aHeightMM, PRBool aIsInch );
-
-  /* Does this printer allow to set/change the content orientation ? */
-  void SetCanChangeOrientation( PRBool aCanSetOrientation );
-  /* Does this Mozilla print module allow set/change the content orientation ? */
-  void SetSupportsOrientationChange( PRBool aSupportsOrientationChange );
-  /* Set number of orientation records and the records itself */
-  void SetNumOrientationRecords( PRInt32 aCount );
-  void SetOrientationRecord( PRInt32 aIndex, const char *aName );
-
-  /* Does this printer allow to set/change the plex mode ? */
-  void SetCanChangePlex( PRBool aCanSetPlex );
-  /* Does this Mozilla print module allow set/change the plex mode ? */
-  void SetSupportsPlexChange( PRBool aSupportsPlexChange );
-  /* Set number of plex records and the records itself */
-  void SetNumPlexRecords( PRInt32 aCount );
-  void SetPlexRecord( PRInt32 aIndex, const char *aName );
+#define DO_PR_DEBUG_LOG(x) PR_LOG(DeviceContextSpecQtLM, PR_LOG_DEBUG, x)
 
-  /* Does this printer allow to set/change the resolution name ? */
-  void SetCanChangeResolutionName( PRBool aCanSetResolutionName );
-  /* Does this Mozilla print module allow set/change the resolution name ? */
-  void SetSupportsResolutionNameChange( PRBool aSupportsResolutionChange );
-  /* Set number of resolution records and the records itself */
-  void SetNumResolutionNameRecords( PRInt32 aCount );
-  void SetResolutionNameRecord( PRInt32 aIndex, const char *aName );
-
-  /* Does this printer allow to set/change the colorspace ? */
-  void SetCanChangeColorspace( PRBool aCanSetColorspace );
-  /* Does this Mozilla print module allow set/change the colorspace ? */
-  void SetSupportsColorspaceChange( PRBool aSupportsColorspace );
-  /* Set number of colorspace records and the records itself */
-  void SetNumColorspaceRecords( PRInt32 aCount );
-  void SetColorspaceRecord( PRInt32 aIndex, const char *aName );
-
-  /* Does this device allow to set/change the usage of the internal grayscale mode ? */
-  void SetCanChangePrintInColor( PRBool aCanSetPrintInColor );
-  /* Does this printer allow to set/change the usage of the internal grayscale mode ? */
-  void SetSupportsPrintInColorChange( PRBool aSupportPrintInColorChange );
-
-  /* Does this device allow to set/change the usage of font download to the printer? */
-  void SetCanChangeDownloadFonts( PRBool aCanSetDownloadFonts );
-  /* Does this printer allow to set/change the usage of font download to the printer? */
-  void SetSupportsDownloadFontsChange( PRBool aSupportDownloadFontsChange );
-
-  /* Does this device allow to set/change the job title ? */
-  void SetCanChangeJobTitle( PRBool aCanSetJobTitle );
-  /* Does this printer allow to set/change the job title ? */
-  void SetSupportsJobTitleChange( PRBool aSupportJobTitleChange );
-    
-  /* Does this device allow to set/change the spooler command ? */
-  void SetCanChangeSpoolerCommand( PRBool aCanSetSpoolerCommand );
-  /* Does this printer allow to set/change the spooler command ? */
-  void SetSupportsSpoolerCommandChange( PRBool aSupportSpoolerCommandChange );
-  
-  /* Does this device allow to set/change number of copies for an document ? */
-  void SetCanChangeNumCopies( PRBool aCanSetNumCopies );
-
-  /* Does this device allow multiple devicecontext instances to be used in
-   * parallel (e.g. print while the device is already in use by print-preview
-   * or printing while another print job is in progress) ? */
-  void SetMultipleConcurrentDeviceContextsSupported( PRBool aCanUseMultipleInstances );
-  
-private:
-  /* private helper methods */
-  void SetBoolValue( const char *tagname, PRBool value );
-  void SetIntValue(  const char *tagname, PRInt32 value );
-  void SetCharValue(  const char *tagname, const char *value );
-
-  nsXPIDLCString          mPrinterName;
-  nsCOMPtr<nsIPrefBranch> mPrefs;
-};
-
-void nsPrinterFeatures::SetBoolValue( const char *tagname, PRBool value )
+nsDeviceContextSpecQt::nsDeviceContextSpecQt()
 {
-  mPrefs->SetBoolPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.%s", mPrinterName.get(), tagname).get(), value);
-}
-
-void nsPrinterFeatures::SetIntValue(  const char *tagname, PRInt32 value )
-{
-  mPrefs->SetIntPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.%s", mPrinterName.get(), tagname).get(), value);
+    DO_PR_DEBUG_LOG(("nsDeviceContextSpecQt::nsDeviceContextSpecQt()\n"));
 }
 
-void nsPrinterFeatures::SetCharValue(  const char *tagname, const char *value )
-{
-  mPrefs->SetCharPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.%s", mPrinterName.get(), tagname).get(), value);
-}
-
-nsPrinterFeatures::nsPrinterFeatures( const char *printername )
-{
-  DO_PR_DEBUG_LOG(("nsPrinterFeatures::nsPrinterFeatures('%s')\n", printername));
-  mPrinterName.Assign(printername);
-  mPrefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
- 
-  SetBoolValue("has_special_printerfeatures", PR_TRUE);
-}
-
-void nsPrinterFeatures::SetCanChangePaperSize( PRBool aCanSetPaperSize )
-{
-  SetBoolValue("can_change_paper_size", aCanSetPaperSize);
-}
-
-void nsPrinterFeatures::SetSupportsPaperSizeChange( PRBool aSupportsPaperSizeChange )
-{
-  SetBoolValue("supports_paper_size_change", aSupportsPaperSizeChange);
-}
-
-/* Set number of paper size records and the records itself */
-void nsPrinterFeatures::SetNumPaperSizeRecords( PRInt32 aCount )
-{
-  SetIntValue("paper.count", aCount);          
-}
-
-void nsPrinterFeatures::SetPaperRecord(PRInt32 aIndex, const char *aPaperName, PRInt32 aWidthMM, PRInt32 aHeightMM, PRBool aIsInch)
-{
-  SetCharValue(nsPrintfCString(256, "paper.%d.name",      aIndex).get(), aPaperName);
-  SetIntValue( nsPrintfCString(256, "paper.%d.width_mm",  aIndex).get(), aWidthMM);
-  SetIntValue( nsPrintfCString(256, "paper.%d.height_mm", aIndex).get(), aHeightMM);
-  SetBoolValue(nsPrintfCString(256, "paper.%d.is_inch",   aIndex).get(), aIsInch);
-}
-
-void nsPrinterFeatures::SetCanChangeOrientation( PRBool aCanSetOrientation )
-{
-  SetBoolValue("can_change_orientation", aCanSetOrientation);
-}
-
-void nsPrinterFeatures::SetSupportsOrientationChange( PRBool aSupportsOrientationChange )
-{
-  SetBoolValue("supports_orientation_change", aSupportsOrientationChange);
-}
-
-void nsPrinterFeatures::SetNumOrientationRecords( PRInt32 aCount )
-{
-  SetIntValue("orientation.count", aCount);          
-}
-
-void nsPrinterFeatures::SetOrientationRecord( PRInt32 aIndex, const char *aOrientationName )
-{
-  SetCharValue(nsPrintfCString(256, "orientation.%d.name", aIndex).get(), aOrientationName);
-}
-
-void nsPrinterFeatures::SetCanChangePlex( PRBool aCanSetPlex )
-{
-  SetBoolValue("can_change_plex", aCanSetPlex);
-}
-
-void nsPrinterFeatures::SetSupportsPlexChange( PRBool aSupportsPlexChange )
+nsDeviceContextSpecQt::~nsDeviceContextSpecQt()
 {
-  SetBoolValue("supports_plex_change", aSupportsPlexChange);
-}
-
-void nsPrinterFeatures::SetNumPlexRecords( PRInt32 aCount )
-{
-  SetIntValue("plex.count", aCount);          
-}
-
-void nsPrinterFeatures::SetPlexRecord( PRInt32 aIndex, const char *aPlexName )
-{
-  SetCharValue(nsPrintfCString(256, "plex.%d.name", aIndex).get(), aPlexName);
-}
-
-void nsPrinterFeatures::SetCanChangeResolutionName( PRBool aCanSetResolutionName )
-{
-  SetBoolValue("can_change_resolution", aCanSetResolutionName);
-}
-
-void nsPrinterFeatures::SetSupportsResolutionNameChange( PRBool aSupportsResolutionNameChange )
-{
-  SetBoolValue("supports_resolution_change", aSupportsResolutionNameChange);
-}
-
-void nsPrinterFeatures::SetNumResolutionNameRecords( PRInt32 aCount )
-{
-  SetIntValue("resolution.count", aCount);          
-}
-
-void nsPrinterFeatures::SetResolutionNameRecord( PRInt32 aIndex, const char *aResolutionName )
-{
-  SetCharValue(nsPrintfCString(256, "resolution.%d.name", aIndex).get(), aResolutionName);
-}
-
-void nsPrinterFeatures::SetCanChangeColorspace( PRBool aCanSetColorspace )
-{
-  SetBoolValue("can_change_colorspace", aCanSetColorspace);
-}
-
-void nsPrinterFeatures::SetSupportsColorspaceChange( PRBool aSupportsColorspaceChange )
-{
-  SetBoolValue("supports_colorspace_change", aSupportsColorspaceChange);
-}
-
-void nsPrinterFeatures::SetNumColorspaceRecords( PRInt32 aCount )
-{
-  SetIntValue("colorspace.count", aCount);          
-}
-
-void nsPrinterFeatures::SetColorspaceRecord( PRInt32 aIndex, const char *aColorspace )
-{
-  SetCharValue(nsPrintfCString(256, "colorspace.%d.name", aIndex).get(), aColorspace);
-}
-
-void nsPrinterFeatures::SetCanChangeDownloadFonts( PRBool aCanSetDownloadFonts )
-{
-  SetBoolValue("can_change_downloadfonts", aCanSetDownloadFonts);
-}
-
-void nsPrinterFeatures::SetSupportsDownloadFontsChange( PRBool aSupportDownloadFontsChange )
-{
-  SetBoolValue("supports_downloadfonts_change", aSupportDownloadFontsChange);
-}
-
-void nsPrinterFeatures::SetCanChangePrintInColor( PRBool aCanSetPrintInColor )
-{
-  SetBoolValue("can_change_printincolor", aCanSetPrintInColor);
-}
-
-void nsPrinterFeatures::SetSupportsPrintInColorChange( PRBool aSupportPrintInColorChange )
-{
-  SetBoolValue("supports_printincolor_change", aSupportPrintInColorChange);
+    DO_PR_DEBUG_LOG(("nsDeviceContextSpecQt::~nsDeviceContextSpecQt()\n"));
 }
 
-void nsPrinterFeatures::SetCanChangeSpoolerCommand( PRBool aCanSetSpoolerCommand )
-{
-  SetBoolValue("can_change_spoolercommand", aCanSetSpoolerCommand);
-}
-
-void nsPrinterFeatures::SetSupportsSpoolerCommandChange( PRBool aSupportSpoolerCommandChange )
-{
-  SetBoolValue("supports_spoolercommand_change", aSupportSpoolerCommandChange);
-}
+NS_IMPL_ISUPPORTS1(nsDeviceContextSpecQt,
+        nsIDeviceContextSpec)
 
-void nsPrinterFeatures::SetCanChangeJobTitle( PRBool aCanSetJobTitle )
-{
-  SetBoolValue("can_change_jobtitle", aCanSetJobTitle);
-}
-
-void nsPrinterFeatures::SetSupportsJobTitleChange( PRBool aSupportsJobTitle )
-{
-  SetBoolValue("supports_jobtitle_change", aSupportsJobTitle);
-}
-
-void nsPrinterFeatures::SetCanChangeNumCopies( PRBool aCanSetNumCopies )
-{
-  SetBoolValue("can_change_num_copies", aCanSetNumCopies);
-}
-
-void nsPrinterFeatures::SetMultipleConcurrentDeviceContextsSupported( PRBool aCanUseMultipleInstances )
+NS_IMETHODIMP nsDeviceContextSpecQt::GetSurfaceForPrinter(
+        gfxASurface** aSurface)
 {
-  SetBoolValue("can_use_multiple_devicecontexts_concurrently", aCanUseMultipleInstances);
-}
+    NS_ENSURE_ARG_POINTER(aSurface);
+    *aSurface = nsnull;
+
+    double width, height;
+    mPrintSettings->GetEffectivePageSize(&width, &height);
 
-#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
+    // If we're in landscape mode, we'll be rotating the output --
+    // need to swap width & height.
+    PRInt32 orientation;
+    mPrintSettings->GetOrientation(&orientation);
+    if (nsIPrintSettings::kLandscapeOrientation == orientation) {
+        double tmp = width;
+        width = height;
+        height = tmp;
+    }
 
-//---------------
-// static members
-GlobalPrinters GlobalPrinters::mGlobalPrinters;
-nsTArray<nsString>* GlobalPrinters::mGlobalPrinterList = nsnull;
-//---------------
+    // convert twips to points
+    width  /= TWIPS_PER_POINT_FLOAT;
+    height /= TWIPS_PER_POINT_FLOAT;
+
+    DO_PR_DEBUG_LOG(("\"%s\", %f, %f\n", mPath, width, height));
+
+    QTemporaryFile file;
+    if(!file.open()) {
+        return NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE;
+    }
+    file.setAutoRemove(false);
+
+    nsresult rv = NS_NewNativeLocalFile(
+            nsDependentCString(file.fileName().toAscii().constData()),
+            PR_FALSE,
+            getter_AddRefs(mSpoolFile));
+    if (NS_FAILED(rv)) {
+        file.remove();
+        return NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE;
+    }
 
-nsDeviceContextSpecGTK::nsDeviceContextSpecGTK()
-  : mPrintJob(NULL)
-  , mGtkPrinter(NULL)
-  , mGtkPrintSettings(NULL)
-  , mGtkPageSetup(NULL)
-{
-  DO_PR_DEBUG_LOG(("nsDeviceContextSpecGTK::nsDeviceContextSpecGTK()\n"));
-}
+    mSpoolName = file.fileName().toUtf8().constData();
+
+    mSpoolFile->SetPermissions(0600);
+
+    nsCOMPtr<nsIFileOutputStream> stream =
+        do_CreateInstance("@mozilla.org/network/file-output-stream;1");
+
+    rv = stream->Init(mSpoolFile, -1, -1, 0);
+    if (NS_FAILED(rv))
+        return rv;
+
+    PRInt16 format;
+    mPrintSettings->GetOutputFormat(&format);
+
+    nsRefPtr<gfxASurface> surface;
+    gfxSize surfaceSize(width, height);
 
-nsDeviceContextSpecGTK::~nsDeviceContextSpecGTK()
-{
-  DO_PR_DEBUG_LOG(("nsDeviceContextSpecGTK::~nsDeviceContextSpecGTK()\n"));
+    if (format == nsIPrintSettings::kOutputFormatNative) {
+        if (mIsPPreview) {
+            // There is nothing to detect on Print Preview, use PS.
+            // TODO: implement for Qt?
+            //format = nsIPrintSettings::kOutputFormatPS;
+            return NS_ERROR_NOT_IMPLEMENTED;
+        }
+        format = nsIPrintSettings::kOutputFormatPDF;
+    }
+    if (format == nsIPrintSettings::kOutputFormatPDF) {
+        surface = new gfxPDFSurface(stream, surfaceSize);
+    } else {
+        return NS_ERROR_NOT_IMPLEMENTED;
+    }
 
-  if (mGtkPageSetup) {
-    g_object_unref(mGtkPageSetup);
-  }
+    NS_ABORT_IF_FALSE(surface, "valid address expected");
 
-  if (mGtkPrintSettings) {
-    g_object_unref(mGtkPrintSettings);
-  }
+    surface.swap(*aSurface);
+    return NS_OK;
 }
 
-NS_IMPL_ISUPPORTS1(nsDeviceContextSpecGTK,
-                   nsIDeviceContextSpec)
-
-#include "gfxPDFSurface.h"
-#include "gfxPSSurface.h"
-NS_IMETHODIMP nsDeviceContextSpecGTK::GetSurfaceForPrinter(gfxASurface **aSurface)
+NS_IMETHODIMP nsDeviceContextSpecQt::Init(nsIWidget* aWidget,
+        nsIPrintSettings* aPS,
+        PRBool aIsPrintPreview)
 {
-  *aSurface = nsnull;
-
-  const char *path;
-  GetPath(&path);
-
-  double width, height;
-  mPrintSettings->GetEffectivePageSize(&width, &height);
+    DO_PR_DEBUG_LOG(("nsDeviceContextSpecQt::Init(aPS=%p)\n", aPS));
 
-  // If we're in landscape mode, we'll be rotating the output --
-  // need to swap width & height.
-  PRInt32 orientation;
-  mPrintSettings->GetOrientation(&orientation);
-  if (nsIPrintSettings::kLandscapeOrientation == orientation) {
-    double tmp = width;
-    width = height;
-    height = tmp;
-  }
-
-  // convert twips to points
-  width  /= TWIPS_PER_POINT_FLOAT;
-  height /= TWIPS_PER_POINT_FLOAT;
-
-  DO_PR_DEBUG_LOG(("\"%s\", %f, %f\n", path, width, height));
-  nsresult rv;
-
-  // Spool file. Use Glib's temporary file function since we're
-  // already dependent on the gtk software stack.
-  gchar *buf;
-  gint fd = g_file_open_tmp("XXXXXX.tmp", &buf, nsnull);
-  if (-1 == fd)
-    return NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE;
-  close(fd);
-
-  rv = NS_NewNativeLocalFile(nsDependentCString(buf), PR_FALSE,
-                             getter_AddRefs(mSpoolFile));
-  if (NS_FAILED(rv)) {
-    unlink(buf);
-    return NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE;
-  }
+    mPrintSettings = aPS;
+    mIsPPreview = aIsPrintPreview;
 
-  mSpoolName = buf;
-  g_free(buf);
-
-  mSpoolFile->SetPermissions(0600);
-
-  nsCOMPtr<nsIFileOutputStream> stream = do_CreateInstance("@mozilla.org/network/file-output-stream;1");
-  rv = stream->Init(mSpoolFile, -1, -1, 0);
-  if (NS_FAILED(rv))
-    return rv;
-
-  PRInt16 format;
-  mPrintSettings->GetOutputFormat(&format);
-
-  nsRefPtr<gfxASurface> surface;
-  gfxSize surfaceSize(width, height);
+    // This is only set by embedders
+    PRBool toFile;
+    aPS->GetPrintToFile(&toFile);
 
-  // Determine the real format with some GTK magic
-  if (format == nsIPrintSettings::kOutputFormatNative) {
-    if (mIsPPreview) {
-      // There is nothing to detect on Print Preview, use PS.
-      format = nsIPrintSettings::kOutputFormatPS;
-    } else {
-      const gchar* fmtGTK = gtk_print_settings_get(mGtkPrintSettings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT);
-      if (!fmtGTK && GTK_IS_PRINTER(mGtkPrinter)) {
-        // Likely not print-to-file, check printer's capabilities
-        format = (gtk_printer_accepts_ps(mGtkPrinter)) ? nsIPrintSettings::kOutputFormatPS
-                                                       : nsIPrintSettings::kOutputFormatPDF;
-      } else if (nsDependentCString(fmtGTK).EqualsIgnoreCase("pdf")) {
-          format = nsIPrintSettings::kOutputFormatPDF;
-      } else {
-          format = nsIPrintSettings::kOutputFormatPS;
-      }
-    }
-  }
+    mToPrinter = !toFile && !aIsPrintPreview;
 
-  if (format == nsIPrintSettings::kOutputFormatPDF) {
-    surface = new gfxPDFSurface(stream, surfaceSize);
-  } else {
-    surface = new gfxPSSurface(stream, surfaceSize);
-  }
-
-  if (!surface)
-    return NS_ERROR_OUT_OF_MEMORY;
-
-  surface.swap(*aSurface);
-
-  return NS_OK;
+    nsCOMPtr<nsPrintSettingsQt> printSettingsQt(do_QueryInterface(aPS));
+    if (!printSettingsQt)
+        return NS_ERROR_NO_INTERFACE;
+    return NS_OK;
 }
 
-/** -------------------------------------------------------
- *  Initialize the nsDeviceContextSpecGTK
- *  @update   dc 2/15/98
- *  @update   syd 3/2/99
- */
-NS_IMETHODIMP nsDeviceContextSpecGTK::Init(nsIWidget *aWidget,
-                                           nsIPrintSettings* aPS,
-                                           PRBool aIsPrintPreview)
+NS_IMETHODIMP nsDeviceContextSpecQt::GetPath(const char** aPath)
 {
-  DO_PR_DEBUG_LOG(("nsDeviceContextSpecGTK::Init(aPS=%p)\n", aPS));
-
-  if (gtk_major_version < 2 ||
-      (gtk_major_version == 2 && gtk_minor_version < 10))
-    return NS_ERROR_NOT_AVAILABLE;  // I'm so sorry bz
-
-  mPrintSettings = aPS;
-  mIsPPreview = aIsPrintPreview;
-
-  // This is only set by embedders
-  PRBool toFile;
-  aPS->GetPrintToFile(&toFile);
-
-  mToPrinter = !toFile && !aIsPrintPreview;
-
-  nsCOMPtr<nsPrintSettingsGTK> printSettingsGTK(do_QueryInterface(aPS));
-  if (!printSettingsGTK)
-    return NS_ERROR_NO_INTERFACE;
-
-  mGtkPrinter = printSettingsGTK->GetGtkPrinter();
-  mGtkPrintSettings = printSettingsGTK->GetGtkPrintSettings();
-  mGtkPageSetup = printSettingsGTK->GetGtkPageSetup();
-
-  // This is a horrible workaround for some printer driver bugs that treat custom page sizes different
-  // to standard ones. If our paper object matches one of a standard one, use a standard paper size
-  // object instead. See bug 414314 for more info.
-  GtkPaperSize* geckosHackishPaperSize = gtk_page_setup_get_paper_size(mGtkPageSetup);
-  GtkPaperSize* standardGtkPaperSize = gtk_paper_size_new(gtk_paper_size_get_name(geckosHackishPaperSize));
-
-  mGtkPageSetup = gtk_page_setup_copy(mGtkPageSetup);
-  mGtkPrintSettings = gtk_print_settings_copy(mGtkPrintSettings);
-
-  GtkPaperSize* properPaperSize;
-  if (gtk_paper_size_is_equal(geckosHackishPaperSize, standardGtkPaperSize)) {
-    properPaperSize = standardGtkPaperSize;
-  } else {
-    properPaperSize = geckosHackishPaperSize;
-    gtk_paper_size_free(standardGtkPaperSize);
-  }
-  gtk_print_settings_set_paper_size(mGtkPrintSettings, properPaperSize);
-  gtk_page_setup_set_paper_size_and_default_margins(mGtkPageSetup, properPaperSize);
-
-  return NS_OK;
+    *aPath = mPath;
+    return NS_OK;
 }
 
-NS_IMETHODIMP nsDeviceContextSpecGTK::GetPath(const char **aPath)      
-{
-  *aPath = mPath;
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsDeviceContextSpecGTK::GetPrintMethod(PrintMethod &aMethod)
+NS_IMETHODIMP nsDeviceContextSpecQt::BeginDocument(
+        PRUnichar* aTitle,
+        PRUnichar* aPrintToFileName,
+        PRInt32 aStartPage,
+        PRInt32 aEndPage)
 {
-  return GetPrintMethod(mPrinter, aMethod);
-}
-/* static !! */
-nsresult nsDeviceContextSpecGTK::GetPrintMethod(const char *aPrinter, PrintMethod &aMethod)
-{
-  aMethod = pmPostScript;
-  return NS_OK;
-}
-
-static void
-print_callback(GtkPrintJob *aJob, gpointer aData, GError *aError) {
-  g_object_unref(aJob);
-  ((nsILocalFile*) aData)->Remove(PR_FALSE);
+    if (mToPrinter) {
+        return NS_ERROR_NOT_IMPLEMENTED;
+    }
+    return NS_OK;
 }
 
-static void
-ns_release_macro(gpointer aData) {
-  nsILocalFile* spoolFile = (nsILocalFile*) aData;
-  NS_RELEASE(spoolFile);
-}
-
-NS_IMETHODIMP nsDeviceContextSpecGTK::BeginDocument(PRUnichar * aTitle, PRUnichar * aPrintToFileName,
-                                                    PRInt32 aStartPage, PRInt32 aEndPage)
+NS_IMETHODIMP nsDeviceContextSpecQt::EndDocument()
 {
-  if (mToPrinter) {
-    if (!GTK_IS_PRINTER(mGtkPrinter))
-      return NS_ERROR_FAILURE;
-
-    mPrintJob = gtk_print_job_new(NS_ConvertUTF16toUTF8(aTitle).get(), mGtkPrinter,
-                                  mGtkPrintSettings, mGtkPageSetup);
-  }
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsDeviceContextSpecGTK::EndDocument()
-{
-  if (mToPrinter) {
-    if (!mPrintJob)
-      return NS_OK; // The operation was aborted.
-
-    if (!gtk_print_job_set_source_file(mPrintJob, mSpoolName.get(), nsnull))
-      return NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE;
-
-    NS_ADDREF(mSpoolFile.get());
-    gtk_print_job_send(mPrintJob, print_callback, mSpoolFile, ns_release_macro);
-  } else {
+    if (mToPrinter) {
+        return NS_ERROR_NOT_IMPLEMENTED;
+    }
     // Handle print-to-file ourselves for the benefit of embedders
     nsXPIDLString targetPath;
     nsCOMPtr<nsILocalFile> destFile;
     mPrintSettings->GetToFileName(getter_Copies(targetPath));
 
     nsresult rv = NS_NewNativeLocalFile(NS_ConvertUTF16toUTF8(targetPath),
-                                        PR_FALSE, getter_AddRefs(destFile));
+            PR_FALSE, getter_AddRefs(destFile));
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsAutoString destLeafName;
     rv = destFile->GetLeafName(destLeafName);
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsIFile> destDir;
     rv = destFile->GetParent(getter_AddRefs(destDir));
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = mSpoolFile->MoveTo(destDir, destLeafName);
     NS_ENSURE_SUCCESS(rv, rv);
 
     // This is the standard way to get the UNIX umask. Ugh.
     mode_t mask = umask(0);
     umask(mask);
-    // If you're not familiar with umasks, they contain the bits of what NOT to set in the permissions
-    // (thats because files and directories have different numbers of bits for their permissions)
+    // If you're not familiar with umasks, they contain the bits of what NOT
+    // to set in the permissions
+    // (thats because files and directories have different numbers of bits
+    // for their permissions)
     destFile->SetPermissions(0666 & ~(mask));
-  }
-  return NS_OK;
-}
-
-/* Get prefs for printer
- * Search order:
- * - Get prefs per printer name and module name
- * - Get prefs per printer name
- * - Get prefs per module name
- * - Get prefs
- */
-static
-nsresult CopyPrinterCharPref(nsIPrefBranch *pref, const char *modulename, const char *printername,
-                             const char *prefname, nsXPIDLCString &return_buf)
-{
-  DO_PR_DEBUG_LOG(("CopyPrinterCharPref('%s', '%s', '%s')\n", modulename, printername, prefname));
 
-  nsresult rv = NS_ERROR_FAILURE;
- 
-  if (printername && modulename) {
-    /* Get prefs per printer name and module name */
-    nsPrintfCString name(512, "print.%s.printer_%s.%s", modulename, printername, prefname);
-    DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get()));
-    rv = pref->GetCharPref(name.get(), getter_Copies(return_buf));
-  }
-  
-  if (NS_FAILED(rv)) { 
-    if (printername) {
-      /* Get prefs per printer name */
-      nsPrintfCString name(512, "print.printer_%s.%s", printername, prefname);
-      DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get()));
-      rv = pref->GetCharPref(name.get(), getter_Copies(return_buf));
-    }
-
-    if (NS_FAILED(rv)) {
-      if (modulename) {
-        /* Get prefs per module name */
-        nsPrintfCString name(512, "print.%s.%s", modulename, prefname);
-        DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get()));
-        rv = pref->GetCharPref(name.get(), getter_Copies(return_buf));
-      }
-      
-      if (NS_FAILED(rv)) {
-        /* Get prefs */
-        nsPrintfCString name(512, "print.%s", prefname);
-        DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get()));
-        rv = pref->GetCharPref(name.get(), getter_Copies(return_buf));
-      }
-    }
-  }
-
-#ifdef PR_LOG  
-  if (NS_SUCCEEDED(rv)) {
-    DO_PR_DEBUG_LOG(("CopyPrinterCharPref returning '%s'.\n", return_buf.get()));
-  }
-  else
-  {
-    DO_PR_DEBUG_LOG(("CopyPrinterCharPref failure.\n"));
-  }
-#endif /* PR_LOG */
-
-  return rv;
+    return NS_OK;
 }
 
 //  Printer Enumerator
-nsPrinterEnumeratorGTK::nsPrinterEnumeratorGTK()
+nsPrinterEnumeratorQt::nsPrinterEnumeratorQt()
 {
 }
 
-NS_IMPL_ISUPPORTS1(nsPrinterEnumeratorGTK, nsIPrinterEnumerator)
-
-NS_IMETHODIMP nsPrinterEnumeratorGTK::GetPrinterNameList(nsIStringEnumerator **aPrinterNameList)
-{
-  NS_ENSURE_ARG_POINTER(aPrinterNameList);
-  *aPrinterNameList = nsnull;
-  
-  nsresult rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters();
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  PRUint32 numPrinters = GlobalPrinters::GetInstance()->GetNumPrinters();
-  nsTArray<nsString> *printers = new nsTArray<nsString>(numPrinters);
-  if (!printers) {
-    GlobalPrinters::GetInstance()->FreeGlobalPrinters();
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-  
-  PRUint32 count = 0;
-  while( count < numPrinters )
-  {
-    printers->AppendElement(*GlobalPrinters::GetInstance()->GetStringAt(count++));
-  }
-  GlobalPrinters::GetInstance()->FreeGlobalPrinters();
+NS_IMPL_ISUPPORTS1(nsPrinterEnumeratorQt, nsIPrinterEnumerator)
 
-  return NS_NewAdoptingStringEnumerator(aPrinterNameList, printers);
-}
-
-/* readonly attribute wstring defaultPrinterName; */
-NS_IMETHODIMP nsPrinterEnumeratorGTK::GetDefaultPrinterName(PRUnichar **aDefaultPrinterName)
+NS_IMETHODIMP nsPrinterEnumeratorQt::GetPrinterNameList(
+        nsIStringEnumerator** aPrinterNameList)
 {
-  DO_PR_DEBUG_LOG(("nsPrinterEnumeratorGTK::GetDefaultPrinterName()\n"));
-  NS_ENSURE_ARG_POINTER(aDefaultPrinterName);
-
-  GlobalPrinters::GetInstance()->GetDefaultPrinterName(aDefaultPrinterName);
-
-  DO_PR_DEBUG_LOG(("GetDefaultPrinterName(): default printer='%s'.\n", NS_ConvertUTF16toUTF8(*aDefaultPrinterName).get()));
-  return NS_OK;
-}
-
-/* void initPrintSettingsFromPrinter (in wstring aPrinterName, in nsIPrintSettings aPrintSettings); */
-NS_IMETHODIMP nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter(const PRUnichar *aPrinterName, nsIPrintSettings *aPrintSettings)
-{
-  DO_PR_DEBUG_LOG(("nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter()"));
-  nsresult rv;
-
-  NS_ENSURE_ARG_POINTER(aPrinterName);
-  NS_ENSURE_ARG_POINTER(aPrintSettings);
-  
-  NS_ENSURE_TRUE(*aPrinterName, NS_ERROR_FAILURE);
-  NS_ENSURE_TRUE(aPrintSettings, NS_ERROR_FAILURE);
-
-  nsCOMPtr<nsIPrefBranch> pPrefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
-  if (NS_FAILED(rv))
-    return rv;
+    NS_ENSURE_ARG_POINTER(aPrinterNameList);
+    *aPrinterNameList = nsnull;
 
-  nsXPIDLCString fullPrinterName, /* Full name of printer incl. driver-specific prefix */ 
-                 printerName;     /* "Stripped" name of printer */
-  fullPrinterName.Assign(NS_ConvertUTF16toUTF8(aPrinterName));
-  printerName.Assign(NS_ConvertUTF16toUTF8(aPrinterName));
-  DO_PR_DEBUG_LOG(("printerName='%s'\n", printerName.get()));
-  
-  PrintMethod type = pmInvalid;
-  rv = nsDeviceContextSpecGTK::GetPrintMethod(printerName, type);
-  if (NS_FAILED(rv))
-    return rv;
-
-  /* "Demangle" postscript printer name */
-  if (type == pmPostScript) {
-    /* Strip the printing method name from the printer,
-     * e.g. turn "PostScript/foobar" to "foobar" */
-    PRInt32 slash = printerName.FindChar('/');
-    if (kNotFound != slash)
-      printerName.Cut(0, slash + 1);
-  }
-
-#ifdef SET_PRINTER_FEATURES_VIA_PREFS
-  /* Defaults to FALSE */
-  pPrefs->SetBoolPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.has_special_printerfeatures", fullPrinterName.get()).get(), PR_FALSE);
-#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
+    QList<QPrinterInfo> qprinters = QPrinterInfo::availablePrinters();
+    if (qprinters.size() == 0)
+        return NS_ERROR_NOT_AVAILABLE;
 
-  
-  /* Set filename */
-  nsXPIDLCString filename;
-  if (NS_FAILED(CopyPrinterCharPref(pPrefs, nsnull, printerName, "filename", filename))) {
-    const char *path;
-  
-    if (!(path = PR_GetEnv("PWD")))
-      path = PR_GetEnv("HOME");
-  
-    if (path)
-      filename = nsPrintfCString(PATH_MAX, "%s/mozilla.ps", path);
-    else
-      filename.AssignLiteral("mozilla.ps");
-  }  
-  DO_PR_DEBUG_LOG(("Setting default filename to '%s'\n", filename.get()));
-  aPrintSettings->SetToFileName(NS_ConvertUTF8toUTF16(filename).get());
-
-  aPrintSettings->SetIsInitializedFromPrinter(PR_TRUE);
-
-  if (type == pmPostScript) {
-    DO_PR_DEBUG_LOG(("InitPrintSettingsFromPrinter() for PostScript printer\n"));
-
-#ifdef SET_PRINTER_FEATURES_VIA_PREFS
-    nsPrinterFeatures printerFeatures(fullPrinterName);
+    nsTArray<nsString>* printers =
+        new nsTArray<nsString>(qprinters.size()); 
 
-    printerFeatures.SetSupportsPaperSizeChange(PR_TRUE);
-    printerFeatures.SetSupportsOrientationChange(PR_TRUE);
-    printerFeatures.SetSupportsPlexChange(PR_FALSE);
-    printerFeatures.SetSupportsResolutionNameChange(PR_FALSE);
-    printerFeatures.SetSupportsColorspaceChange(PR_FALSE);
-#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ 
-      
-#ifdef SET_PRINTER_FEATURES_VIA_PREFS
-    printerFeatures.SetCanChangeOrientation(PR_TRUE);
-#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
-
-    nsXPIDLCString orientation;
-    if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "orientation", orientation))) {
-      if (orientation.LowerCaseEqualsLiteral("portrait")) {
-        DO_PR_DEBUG_LOG(("setting default orientation to 'portrait'\n"));
-        aPrintSettings->SetOrientation(nsIPrintSettings::kPortraitOrientation);
-      }
-      else if (orientation.LowerCaseEqualsLiteral("landscape")) {
-        DO_PR_DEBUG_LOG(("setting default orientation to 'landscape'\n"));
-        aPrintSettings->SetOrientation(nsIPrintSettings::kLandscapeOrientation);  
-      }
-      else {
-        DO_PR_DEBUG_LOG(("Unknown default orientation '%s'\n", orientation.get()));
-      }
+    for (PRInt32 i = 0; i < qprinters.size(); ++i) {
+        printers->AppendElement(
+                nsDependentString(
+                    (const PRUnichar*)qprinters[i].printerName().constData()));
     }
 
-#ifdef SET_PRINTER_FEATURES_VIA_PREFS
-    printerFeatures.SetOrientationRecord(0, "portrait");
-    printerFeatures.SetOrientationRecord(1, "landscape");
-    printerFeatures.SetNumOrientationRecords(2);
-#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
-
-    /* PostScript module does not support changing the plex mode... */
-#ifdef SET_PRINTER_FEATURES_VIA_PREFS
-    printerFeatures.SetCanChangePlex(PR_FALSE);
-#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
-    DO_PR_DEBUG_LOG(("setting default plex to '%s'\n", "default"));
-    aPrintSettings->SetPlexName(NS_LITERAL_STRING("default").get());
-#ifdef SET_PRINTER_FEATURES_VIA_PREFS
-    printerFeatures.SetPlexRecord(0, "default");
-    printerFeatures.SetNumPlexRecords(1);
-#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
-
-    /* PostScript module does not support changing the resolution mode... */
-#ifdef SET_PRINTER_FEATURES_VIA_PREFS
-    printerFeatures.SetCanChangeResolutionName(PR_FALSE);
-#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
-    DO_PR_DEBUG_LOG(("setting default resolution to '%s'\n", "default"));
-    aPrintSettings->SetResolutionName(NS_LITERAL_STRING("default").get());
-#ifdef SET_PRINTER_FEATURES_VIA_PREFS
-    printerFeatures.SetResolutionNameRecord(0, "default");
-    printerFeatures.SetNumResolutionNameRecords(1);
-#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
-
-    /* PostScript module does not support changing the colorspace... */
-#ifdef SET_PRINTER_FEATURES_VIA_PREFS
-    printerFeatures.SetCanChangeColorspace(PR_FALSE);
-#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
-    DO_PR_DEBUG_LOG(("setting default colorspace to '%s'\n", "default"));
-    aPrintSettings->SetColorspace(NS_LITERAL_STRING("default").get());
-#ifdef SET_PRINTER_FEATURES_VIA_PREFS
-    printerFeatures.SetColorspaceRecord(0, "default");
-    printerFeatures.SetNumColorspaceRecords(1);
-#endif /* SET_PRINTER_FEATURES_VIA_PREFS */   
-
-#ifdef SET_PRINTER_FEATURES_VIA_PREFS
-    printerFeatures.SetCanChangePaperSize(PR_TRUE);
-#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
-    nsXPIDLCString papername;
-    if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "paper_size", papername))) {
-      nsPaperSizePS paper;
-
-      if (paper.Find(papername)) {
-        DO_PR_DEBUG_LOG(("setting default paper size to '%s' (%g mm/%g mm)\n",
-              paper.Name(), paper.Width_mm(), paper.Height_mm()));
-	aPrintSettings->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeMillimeters);
-        aPrintSettings->SetPaperWidth(paper.Width_mm());
-        aPrintSettings->SetPaperHeight(paper.Height_mm());
-        aPrintSettings->SetPaperName(NS_ConvertASCIItoUTF16(paper.Name()).get());
-      }
-      else {
-        DO_PR_DEBUG_LOG(("Unknown paper size '%s' given.\n", papername.get()));
-      }
-#ifdef SET_PRINTER_FEATURES_VIA_PREFS
-      paper.First();
-      int count = 0;
-      while (!paper.AtEnd())
-      {
-        printerFeatures.SetPaperRecord(count++, paper.Name(),
-            (int)paper.Width_mm(), (int)paper.Height_mm(), !paper.IsMetric());
-        paper.Next();
-      }
-      printerFeatures.SetNumPaperSizeRecords(count);
-#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
-    }
-
-    PRBool hasSpoolerCmd = (nsPSPrinterList::kTypePS ==
-        nsPSPrinterList::GetPrinterType(fullPrinterName));
-#ifdef SET_PRINTER_FEATURES_VIA_PREFS
-    printerFeatures.SetSupportsSpoolerCommandChange(hasSpoolerCmd);
-    printerFeatures.SetCanChangeSpoolerCommand(hasSpoolerCmd);
-
-    /* Postscript module does not pass the job title to lpr */
-    printerFeatures.SetSupportsJobTitleChange(PR_FALSE);
-    printerFeatures.SetCanChangeJobTitle(PR_FALSE);
-    /* Postscript module has no control over builtin fonts yet */
-    printerFeatures.SetSupportsDownloadFontsChange(PR_FALSE);
-    printerFeatures.SetCanChangeDownloadFonts(PR_FALSE);
-    /* Postscript module does not support multiple colorspaces
-     * so it has to use the old way */
-    printerFeatures.SetSupportsPrintInColorChange(PR_TRUE);
-    printerFeatures.SetCanChangePrintInColor(PR_TRUE);
-#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
-
-    if (hasSpoolerCmd) {
-      nsXPIDLCString command;
-      if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript",
-            printerName, "print_command", command))) {
-        DO_PR_DEBUG_LOG(("setting default print command to '%s'\n",
-            command.get()));
-        aPrintSettings->SetPrintCommand(NS_ConvertUTF8toUTF16(command).get());
-      }
-    }
-    
-#ifdef SET_PRINTER_FEATURES_VIA_PREFS
-    printerFeatures.SetCanChangeNumCopies(PR_TRUE);   
-#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
-
-    return NS_OK;    
-  }
-
-  return NS_ERROR_UNEXPECTED;
+    return NS_NewAdoptingStringEnumerator(aPrinterNameList, printers);
 }
 
-NS_IMETHODIMP nsPrinterEnumeratorGTK::DisplayPropertiesDlg(const PRUnichar *aPrinter, nsIPrintSettings *aPrintSettings)
+NS_IMETHODIMP nsPrinterEnumeratorQt::GetDefaultPrinterName(
+        PRUnichar** aDefaultPrinterName)
 {
-  return NS_OK;
+    DO_PR_DEBUG_LOG(("nsPrinterEnumeratorQt::GetDefaultPrinterName()\n"));
+    NS_ENSURE_ARG_POINTER(aDefaultPrinterName);
+
+    QString defprinter = QPrinterInfo::defaultPrinter().printerName();
+    *aDefaultPrinterName = ToNewUnicode(nsDependentString(
+        (const PRUnichar*)defprinter.constData()));
+
+    DO_PR_DEBUG_LOG(("GetDefaultPrinterName(): default printer='%s'.\n",
+        NS_ConvertUTF16toUTF8(*aDefaultPrinterName).get()));
+
+    return NS_OK;
 }
 
-//----------------------------------------------------------------------
-nsresult GlobalPrinters::InitializeGlobalPrinters ()
+NS_IMETHODIMP nsPrinterEnumeratorQt::InitPrintSettingsFromPrinter(
+        const PRUnichar* aPrinterName,
+        nsIPrintSettings* aPrintSettings)
 {
-  if (PrintersAreAllocated()) {
+    DO_PR_DEBUG_LOG(("nsPrinterEnumeratorQt::InitPrintSettingsFromPrinter()"));
+    // XXX Leave NS_OK for now
+    // Probably should use NS_ERROR_NOT_IMPLEMENTED
     return NS_OK;
-  }
-
-  mGlobalPrinterList = new nsTArray<nsString>();
-  if (!mGlobalPrinterList) 
-    return NS_ERROR_OUT_OF_MEMORY;
-
-  nsresult rv;
-  nsCOMPtr<nsIPrefBranch> pPrefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
-  if (NS_FAILED(rv))
-    return rv;
-      
-  nsPSPrinterList psMgr;
-  if (NS_SUCCEEDED(psMgr.Init()) && psMgr.Enabled()) {
-    /* Get the list of PostScript-module printers */
-    // XXX: this function is the only user of GetPrinterList
-    // So it may be interesting to convert the nsCStrings
-    // in this function, we would save one loop here
-    nsTArray<nsCString> printerList;
-    psMgr.GetPrinterList(printerList);
-    for (PRUint32 i = 0; i < printerList.Length(); i++)
-    {
-      mGlobalPrinterList->AppendElement(NS_ConvertUTF8toUTF16(printerList[i]));
-    }
-  }
-
-  /* If there are no printers available after all checks, return an error */
-  if (!mGlobalPrinterList->Length())
-  {
-    /* Make sure we do not cache an empty printer list */
-    FreeGlobalPrinters();
-
-    return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE;
-  }
-
-  return NS_OK;
 }
 
-//----------------------------------------------------------------------
-void GlobalPrinters::FreeGlobalPrinters()
+NS_IMETHODIMP nsPrinterEnumeratorQt::DisplayPropertiesDlg(
+        const PRUnichar* aPrinter,
+        nsIPrintSettings* aPrintSettings)
 {
-  if (mGlobalPrinterList) {
-    delete mGlobalPrinterList;
-    mGlobalPrinterList = nsnull;
-  }  
+    return NS_ERROR_NOT_IMPLEMENTED;
 }
 
-void 
-GlobalPrinters::GetDefaultPrinterName(PRUnichar **aDefaultPrinterName)
-{
-  *aDefaultPrinterName = nsnull;
-  
-  PRBool allocate = !GlobalPrinters::GetInstance()->PrintersAreAllocated();
-  
-  if (allocate) {
-    nsresult rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters();
-    if (NS_FAILED(rv)) {
-      return;
-    }
-  }
-  NS_ASSERTION(GlobalPrinters::GetInstance()->PrintersAreAllocated(), "no GlobalPrinters");
-
-  if (GlobalPrinters::GetInstance()->GetNumPrinters() == 0)
-    return;
-  
-  *aDefaultPrinterName = ToNewUnicode(*GlobalPrinters::GetInstance()->GetStringAt(0));
-
-  if (allocate) {  
-    GlobalPrinters::GetInstance()->FreeGlobalPrinters();
-  }  
-}
-
copy from widget/src/gtk2/nsDeviceContextSpecG.h
copy to widget/src/qt/nsDeviceContextSpecQt.h
--- a/widget/src/gtk2/nsDeviceContextSpecG.h
+++ b/widget/src/qt/nsDeviceContextSpecQt.h
@@ -1,9 +1,9 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
@@ -16,95 +16,78 @@
  *
  * The Initial Developer of the Original Code is
  * Netscape Communications Corporation.
  * Portions created by the Initial Developer are Copyright (C) 1998
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
  *   Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
+ *   Florian Hänel <heeen@gmx.de>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either of the GNU General Public License Version 2 or later (the "GPL"),
  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#ifndef nsDeviceContextSpecGTK_h___
-#define nsDeviceContextSpecGTK_h___
+
+#ifndef nsDeviceContextSpecQt_h___
+#define nsDeviceContextSpecQt_h___
 
 #include "nsIDeviceContextSpec.h"
 #include "nsIPrintSettings.h"
-#include "nsIPrintOptions.h" 
+#include "nsIPrintOptions.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
 
 #include "nsCRT.h" /* should be <limits.h>? */
 
-#include <gtk/gtk.h>
-#include <gtk/gtkprinter.h>
-#include <gtk/gtkprintjob.h>
-
-#define NS_PORTRAIT  0
-#define NS_LANDSCAPE 1
-
-typedef enum
-{
-  pmInvalid = 0,
-  pmPostScript
-} PrintMethod;
-
-class nsDeviceContextSpecGTK : public nsIDeviceContextSpec
+class nsDeviceContextSpecQt : public nsIDeviceContextSpec
 {
 public:
-  nsDeviceContextSpecGTK();
-
-  NS_DECL_ISUPPORTS
-
-  NS_IMETHOD GetSurfaceForPrinter(gfxASurface **surface);
+    nsDeviceContextSpecQt();
+    virtual ~nsDeviceContextSpecQt();
 
-  NS_IMETHOD Init(nsIWidget *aWidget, nsIPrintSettings* aPS, PRBool aIsPrintPreview);
-  NS_IMETHOD BeginDocument(PRUnichar * aTitle, PRUnichar * aPrintToFileName, PRInt32 aStartPage, PRInt32 aEndPage);
-  NS_IMETHOD EndDocument();
-  NS_IMETHOD BeginPage() { return NS_OK; }
-  NS_IMETHOD EndPage() { return NS_OK; }
+    NS_DECL_ISUPPORTS
+
+    NS_IMETHOD GetSurfaceForPrinter(gfxASurface** surface);
 
-  NS_IMETHOD GetPath (const char **aPath);    
-  NS_IMETHOD GetPrintMethod(PrintMethod &aMethod);
-  static nsresult GetPrintMethod(const char *aPrinter, PrintMethod &aMethod);
-  virtual ~nsDeviceContextSpecGTK();
-  
+    NS_IMETHOD Init(nsIWidget* aWidget,
+                    nsIPrintSettings* aPS,
+                    PRBool aIsPrintPreview);
+    NS_IMETHOD BeginDocument(PRUnichar* aTitle,
+                             PRUnichar* aPrintToFileName,
+                             PRInt32 aStartPage,
+                             PRInt32 aEndPage);
+    NS_IMETHOD EndDocument();
+    NS_IMETHOD BeginPage() { return NS_OK; }
+    NS_IMETHOD EndPage() { return NS_OK; }
+
+    NS_IMETHOD GetPath (const char** aPath);
+
 protected:
-  nsCOMPtr<nsIPrintSettings> mPrintSettings;
-  PRPackedBool mToPrinter : 1;      /* If PR_TRUE, print to printer */
-  PRPackedBool mIsPPreview : 1;     /* If PR_TRUE, is print preview */
-  char   mPath[PATH_MAX];     /* If toPrinter = PR_FALSE, dest file */
-  char   mPrinter[256];       /* Printer name */
-  GtkPrintJob*      mPrintJob;
-  GtkPrinter*       mGtkPrinter;
-  GtkPrintSettings* mGtkPrintSettings;
-  GtkPageSetup*     mGtkPageSetup;
-
-  nsCString              mSpoolName;
-  nsCOMPtr<nsILocalFile> mSpoolFile;
-
+    nsCOMPtr<nsIPrintSettings> mPrintSettings;
+    PRPackedBool mToPrinter : 1;      /* If PR_TRUE, print to printer */
+    PRPackedBool mIsPPreview : 1;     /* If PR_TRUE, is print preview */
+    char   mPath[PATH_MAX];     /* If toPrinter = PR_FALSE, dest file */
+    char   mPrinter[256];       /* Printer name */
+    nsCString              mSpoolName;
+    nsCOMPtr<nsILocalFile> mSpoolFile;
 };
 
-//-------------------------------------------------------------------------
-// Printer Enumerator
-//-------------------------------------------------------------------------
-class nsPrinterEnumeratorGTK : public nsIPrinterEnumerator
+class nsPrinterEnumeratorQt : public nsIPrinterEnumerator
 {
 public:
-  nsPrinterEnumeratorGTK();
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIPRINTERENUMERATOR
+    nsPrinterEnumeratorQt();
+    NS_DECL_ISUPPORTS
+    NS_DECL_NSIPRINTERENUMERATOR
 };
 
-#endif /* !nsDeviceContextSpecGTK_h___ */
+#endif /* !nsDeviceContextSpecQt_h___ */
copy from widget/src/gtk2/nsPrintDialogGTK.cpp
copy to widget/src/qt/nsPrintDialogQt.cpp
--- a/widget/src/gtk2/nsPrintDialogGTK.cpp
+++ b/widget/src/qt/nsPrintDialogQt.cpp
@@ -1,10 +1,11 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
  * Software distributed under the License is distributed on an "AS IS" basis,
@@ -16,628 +17,61 @@
  *
  * The Initial Developer of the Original Code is
  * Kenneth Herron <kherron@fmailbox.com>
  * Portions created by the Initial Developer are Copyright (C) 2007
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
  *   Michael Ventnor <m.ventnor@gmail.com>
+ *   Florian Hänel <heeen@gmx.de>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either the GNU General Public License Version 2 or later (the "GPL"), or
  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#include <gtk/gtk.h>
-#include <gtk/gtkprintunixdialog.h>
-#include <stdlib.h>
-
-#include "mozcontainer.h"
-#include "nsAccessibilityHelper.h"
-#include "nsIPrintSettings.h"
-#include "nsIWidget.h"
-#include "nsPrintDialogGTK.h"
-#include "nsPrintSettingsGTK.h"
-#include "nsString.h"
-#include "nsReadableUtils.h"
-#include "nsILocalFile.h"
-#include "nsNetUtil.h"
-#include "nsIStringBundle.h"
-#include "nsIPrintSettingsService.h"
-#include "nsIDOMWindow.h"
-#include "nsPIDOMWindow.h"
-#include "nsIBaseWindow.h"
-#include "nsIDocShellTreeItem.h"
-#include "nsIDocShell.h"
-#include "WidgetUtils.h"
-
-using namespace mozilla::widget;
-
-static const char header_footer_tags[][4] =  {"", "&T", "&U", "&D", "&P", "&PT"};
-
-#define CUSTOM_VALUE_INDEX NS_ARRAY_LENGTH(header_footer_tags)
-
-// XXXdholbert Duplicated from widget/src/gtk2/nsFilePicker.cpp
-// Needs to be unified in some generic utility class.
-static GtkWindow *
-get_gtk_window_for_nsiwidget(nsIWidget *widget)
-{
-  // Get native GdkWindow
-  GdkWindow *gdk_win = GDK_WINDOW(widget->GetNativeData(NS_NATIVE_WIDGET));
-  if (!gdk_win)
-    return NULL;
-
-  // Get the container
-  gpointer user_data = NULL;
-  gdk_window_get_user_data(gdk_win, &user_data);
-  if (!user_data)
-    return NULL;
-
-  // Make sure its really a container
-  MozContainer *parent_container = MOZ_CONTAINER(user_data);
-  if (!parent_container)
-    return NULL;
-
-  // Get its toplevel
-  return GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(parent_container)));
-}
-
-static void
-ShowCustomDialog(GtkComboBox *changed_box, gpointer user_data)
-{
-  if (gtk_combo_box_get_active(changed_box) != CUSTOM_VALUE_INDEX) {
-    g_object_set_data(G_OBJECT(changed_box), "previous-active", GINT_TO_POINTER(gtk_combo_box_get_active(changed_box)));
-    return;
-  }
-
-  GtkWindow* printDialog = GTK_WINDOW(user_data);
-  nsCOMPtr<nsIStringBundleService> bundleSvc =
-       do_GetService(NS_STRINGBUNDLE_CONTRACTID);
-
-  nsCOMPtr<nsIStringBundle> printBundle;
-  bundleSvc->CreateBundle("chrome://global/locale/printdialog.properties", getter_AddRefs(printBundle));
-  nsXPIDLString intlString;
-
-  printBundle->GetStringFromName(NS_LITERAL_STRING("headerFooterCustom").get(), getter_Copies(intlString));
-  GtkWidget* prompt_dialog = gtk_dialog_new_with_buttons(NS_ConvertUTF16toUTF8(intlString).get(), printDialog,
-                                                         (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR),
-                                                         GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
-                                                         GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
-                                                         NULL);
-  gtk_dialog_set_default_response(GTK_DIALOG(prompt_dialog), GTK_RESPONSE_ACCEPT);
-  gtk_dialog_set_alternative_button_order(GTK_DIALOG(prompt_dialog),
-                                          GTK_RESPONSE_ACCEPT,
-                                          GTK_RESPONSE_REJECT,
-                                          -1);
-
-  printBundle->GetStringFromName(NS_LITERAL_STRING("customHeaderFooterPrompt").get(), getter_Copies(intlString));
-  GtkWidget* custom_label = gtk_label_new(NS_ConvertUTF16toUTF8(intlString).get());
-  GtkWidget* custom_entry = gtk_entry_new();
-  GtkWidget* question_icon = gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG);
-
-  // To be convenient, prefill the textbox with the existing value, if any, and select it all so they can easily
-  // both edit it and type in a new one.
-  const char* current_text = (const char*) g_object_get_data(G_OBJECT(changed_box), "custom-text");
-  if (current_text) {
-    gtk_entry_set_text(GTK_ENTRY(custom_entry), current_text);
-    gtk_editable_select_region(GTK_EDITABLE(custom_entry), 0, -1);
-  }
-  gtk_entry_set_activates_default(GTK_ENTRY(custom_entry), TRUE);
-
-  GtkWidget* custom_vbox = gtk_vbox_new(TRUE, 2);
-  gtk_box_pack_start(GTK_BOX(custom_vbox), custom_label, FALSE, FALSE, 0);
-  gtk_box_pack_start(GTK_BOX(custom_vbox), custom_entry, FALSE, FALSE, 5); // Make entry 5px underneath label
-  GtkWidget* custom_hbox = gtk_hbox_new(FALSE, 2);
-  gtk_box_pack_start(GTK_BOX(custom_hbox), question_icon, FALSE, FALSE, 0);
-  gtk_box_pack_start(GTK_BOX(custom_hbox), custom_vbox, FALSE, FALSE, 10); // Make question icon 10px away from content
-  gtk_container_set_border_width(GTK_CONTAINER(custom_hbox), 2);
-  gtk_widget_show_all(custom_hbox);
-
-  gtk_box_pack_start(GTK_BOX(GTK_DIALOG(prompt_dialog)->vbox), custom_hbox, FALSE, FALSE, 0);
-  gint diag_response = gtk_dialog_run(GTK_DIALOG(prompt_dialog));
-
-  if (diag_response == GTK_RESPONSE_ACCEPT) {
-    const gchar* response_text = gtk_entry_get_text(GTK_ENTRY(custom_entry));
-    g_object_set_data_full(G_OBJECT(changed_box), "custom-text", strdup(response_text), (GDestroyNotify) free);
-    g_object_set_data(G_OBJECT(changed_box), "previous-active", GINT_TO_POINTER(CUSTOM_VALUE_INDEX));
-  } else {
-    // Go back to the previous index
-    gint previous_active = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(changed_box), "previous-active"));
-    gtk_combo_box_set_active(changed_box, previous_active);
-  }
-
-  gtk_widget_destroy(prompt_dialog);
-}
-
-class nsPrintDialogWidgetGTK {
-  public:
-    nsPrintDialogWidgetGTK(nsIDOMWindow *aParent, nsIPrintSettings *aPrintSettings);
-    ~nsPrintDialogWidgetGTK() { gtk_widget_destroy(dialog); }
-    NS_ConvertUTF16toUTF8 GetUTF8FromBundle(const char* aKey);
-    const gint Run();
-
-    nsresult ImportSettings(nsIPrintSettings *aNSSettings);
-    nsresult ExportSettings(nsIPrintSettings *aNSSettings);
-
-  private:
-    GtkWidget* dialog;
-    GtkWidget* radio_as_laid_out;
-    GtkWidget* radio_selected_frame;
-    GtkWidget* radio_separate_frames;
-    GtkWidget* shrink_to_fit_toggle;
-    GtkWidget* print_bg_colors_toggle;
-    GtkWidget* print_bg_images_toggle;
-    GtkWidget* selection_only_toggle;
-    GtkWidget* header_dropdown[3];  // {left, center, right}
-    GtkWidget* footer_dropdown[3];
-
-    nsCOMPtr<nsIStringBundle> printBundle;
-
-    PRPackedBool useNativeSelection;
-
-    GtkWidget* ConstructHeaderFooterDropdown(const PRUnichar *currentString);
-    const char* OptionWidgetToString(GtkWidget *dropdown);
-
-    /* Code to copy between GTK and NS print settings structures.
-     * In the following, 
-     *   "Import" means to copy from NS to GTK
-     *   "Export" means to copy from GTK to NS
-     */
-    void ExportFramePrinting(nsIPrintSettings *aNS, GtkPrintSettings *aSettings);
-    void ExportHeaderFooter(nsIPrintSettings *aNS);
-};
-
-nsPrintDialogWidgetGTK::nsPrintDialogWidgetGTK(nsIDOMWindow *aParent, nsIPrintSettings *aSettings)
-{
-  nsCOMPtr<nsIWidget> widget = WidgetUtils::DOMWindowToWidget(aParent);
-  NS_ASSERTION(widget, "Need a widget for dialog to be modal.");
-  GtkWindow* gtkParent = get_gtk_window_for_nsiwidget(widget);
-  NS_ASSERTION(gtkParent, "Need a GTK window for dialog to be modal.");
-
-  nsCOMPtr<nsIStringBundleService> bundleSvc = do_GetService(NS_STRINGBUNDLE_CONTRACTID);
-  bundleSvc->CreateBundle("chrome://global/locale/printdialog.properties", getter_AddRefs(printBundle));
-
-  dialog = gtk_print_unix_dialog_new(GetUTF8FromBundle("printTitleGTK").get(), gtkParent);
-
-  gtk_print_unix_dialog_set_manual_capabilities(GTK_PRINT_UNIX_DIALOG(dialog),
-                    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_PDF
-                      | GTK_PRINT_CAPABILITY_GENERATE_PS
-                    )
-                  );
-
-  // The vast majority of magic numbers in this widget construction are padding. e.g. for
-  // the set_border_width below, 12px matches that of just about every other window.
-  GtkWidget* custom_options_tab = gtk_vbox_new(FALSE, 0);
-  gtk_container_set_border_width(GTK_CONTAINER(custom_options_tab), 12);
-  GtkWidget* tab_label = gtk_label_new(GetUTF8FromBundle("optionsTabLabelGTK").get());
-
-  PRInt16 frameUIFlag;
-  aSettings->GetHowToEnableFrameUI(&frameUIFlag);
-  radio_as_laid_out = gtk_radio_button_new_with_mnemonic(NULL, GetUTF8FromBundle("asLaidOut").get());
-  if (frameUIFlag == nsIPrintSettings::kFrameEnableNone)
-    gtk_widget_set_sensitive(radio_as_laid_out, FALSE);
-
-  radio_selected_frame = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(radio_as_laid_out),
-                                                                        GetUTF8FromBundle("selectedFrame").get());
-  if (frameUIFlag == nsIPrintSettings::kFrameEnableNone ||
-      frameUIFlag == nsIPrintSettings::kFrameEnableAsIsAndEach)
-    gtk_widget_set_sensitive(radio_selected_frame, FALSE);
-
-  radio_separate_frames = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(radio_as_laid_out),
-                                                                         GetUTF8FromBundle("separateFrames").get());
-  if (frameUIFlag == nsIPrintSettings::kFrameEnableNone)
-    gtk_widget_set_sensitive(radio_separate_frames, FALSE);
-
-  // "Print Frames" options label, bold and center-aligned
-  GtkWidget* print_frames_label = gtk_label_new(NULL);
-  char* pangoMarkup = g_markup_printf_escaped("<b>%s</b>", GetUTF8FromBundle("printFramesTitleGTK").get());
-  gtk_label_set_markup(GTK_LABEL(print_frames_label), pangoMarkup);
-  g_free(pangoMarkup);
-  gtk_misc_set_alignment(GTK_MISC(print_frames_label), 0, 0);
-
-  // Align the radio buttons slightly so they appear to fall under the aforementioned label as per the GNOME HIG
-  GtkWidget* frames_radio_container = gtk_alignment_new(0, 0, 0, 0);
-  gtk_alignment_set_padding(GTK_ALIGNMENT(frames_radio_container), 8, 0, 12, 0);
-
-  // Radio buttons for the print frames options
-  GtkWidget* frames_radio_list = gtk_vbox_new(TRUE, 2);
-  gtk_box_pack_start(GTK_BOX(frames_radio_list), radio_as_laid_out, FALSE, FALSE, 0);
-  gtk_box_pack_start(GTK_BOX(frames_radio_list), radio_selected_frame, FALSE, FALSE, 0);
-  gtk_box_pack_start(GTK_BOX(frames_radio_list), radio_separate_frames, FALSE, FALSE, 0);
-  gtk_container_add(GTK_CONTAINER(frames_radio_container), frames_radio_list);
-
-  // Check buttons for shrink-to-fit and print selection
-  GtkWidget* check_buttons_container = gtk_vbox_new(TRUE, 2);
-  shrink_to_fit_toggle = gtk_check_button_new_with_mnemonic(GetUTF8FromBundle("shrinkToFit").get());
-  gtk_box_pack_start(GTK_BOX(check_buttons_container), shrink_to_fit_toggle, FALSE, FALSE, 0);
-
-  // GTK+2.18 and above allow us to add a "Selection" option to the main settings screen,
-  // rather than adding an option on a custom tab like we must do on older versions.
-  PRBool canSelectText;
-  aSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &canSelectText);
-  if (gtk_major_version > 2 ||
-      (gtk_major_version == 2 && gtk_minor_version >= 18)) {
-    useNativeSelection = PR_TRUE;
-    g_object_set(G_OBJECT(dialog),
-                 "support-selection", TRUE,
-                 "has-selection", canSelectText,
-                 "embed-page-setup", TRUE,
-                 NULL);
-  } else {
-    useNativeSelection = PR_FALSE;
-    selection_only_toggle = gtk_check_button_new_with_mnemonic(GetUTF8FromBundle("selectionOnly").get());
-    gtk_widget_set_sensitive(selection_only_toggle, canSelectText);
-    gtk_box_pack_start(GTK_BOX(check_buttons_container), selection_only_toggle, FALSE, FALSE, 0);
-  }
-
-  // Check buttons for printing background
-  GtkWidget* appearance_buttons_container = gtk_vbox_new(TRUE, 2);
-  print_bg_colors_toggle = gtk_check_button_new_with_mnemonic(GetUTF8FromBundle("printBGColors").get());
-  print_bg_images_toggle = gtk_check_button_new_with_mnemonic(GetUTF8FromBundle("printBGImages").get());
-  gtk_box_pack_start(GTK_BOX(appearance_buttons_container), print_bg_colors_toggle, FALSE, FALSE, 0);
-  gtk_box_pack_start(GTK_BOX(appearance_buttons_container), print_bg_images_toggle, FALSE, FALSE, 0);
+#include "nsPrintSettingsQt.h"
+#include "nsPrintDialogQt.h"
 
-  // "Appearance" options label, bold and center-aligned
-  GtkWidget* appearance_label = gtk_label_new(NULL);
-  pangoMarkup = g_markup_printf_escaped("<b>%s</b>", GetUTF8FromBundle("printBGOptions").get());
-  gtk_label_set_markup(GTK_LABEL(appearance_label), pangoMarkup);
-  g_free(pangoMarkup);
-  gtk_misc_set_alignment(GTK_MISC(appearance_label), 0, 0);
-
-  GtkWidget* appearance_container = gtk_alignment_new(0, 0, 0, 0);
-  gtk_alignment_set_padding(GTK_ALIGNMENT(appearance_container), 8, 0, 12, 0);
-  gtk_container_add(GTK_CONTAINER(appearance_container), appearance_buttons_container);
-
-  GtkWidget* appearance_vertical_squasher = gtk_vbox_new(FALSE, 0);
-  gtk_box_pack_start(GTK_BOX(appearance_vertical_squasher), appearance_label, FALSE, FALSE, 0);
-  gtk_box_pack_start(GTK_BOX(appearance_vertical_squasher), appearance_container, FALSE, FALSE, 0);
-
-  // "Header & Footer" options label, bold and center-aligned
-  GtkWidget* header_footer_label = gtk_label_new(NULL);
-  pangoMarkup = g_markup_printf_escaped("<b>%s</b>", GetUTF8FromBundle("headerFooter").get());
-  gtk_label_set_markup(GTK_LABEL(header_footer_label), pangoMarkup);
-  g_free(pangoMarkup);
-  gtk_misc_set_alignment(GTK_MISC(header_footer_label), 0, 0);
-
-  GtkWidget* header_footer_container = gtk_alignment_new(0, 0, 0, 0);
-  gtk_alignment_set_padding(GTK_ALIGNMENT(header_footer_container), 8, 0, 12, 0);
-
-
-  // --- Table for making the header and footer options ---
-  GtkWidget* header_footer_table = gtk_table_new(3, 3, FALSE); // 3x3 table
-  nsXPIDLString header_footer_str[3];
-
-  aSettings->GetHeaderStrLeft(getter_Copies(header_footer_str[0]));
-  aSettings->GetHeaderStrCenter(getter_Copies(header_footer_str[1]));
-  aSettings->GetHeaderStrRight(getter_Copies(header_footer_str[2]));
-
-  for (unsigned int i = 0; i < NS_ARRAY_LENGTH(header_dropdown); i++) {
-    header_dropdown[i] = ConstructHeaderFooterDropdown(header_footer_str[i].get());
-    // Those 4 magic numbers in the middle provide the position in the table.
-    // The last two numbers mean 2 px padding on every side.
-    gtk_table_attach(GTK_TABLE(header_footer_table), header_dropdown[i], i, (i + 1),
-                     0, 1, (GtkAttachOptions) 0, (GtkAttachOptions) 0, 2, 2);
-  }
-
-  const char labelKeys[][7] = {"left", "center", "right"};
-  for (unsigned int i = 0; i < NS_ARRAY_LENGTH(labelKeys); i++) {
-    gtk_table_attach(GTK_TABLE(header_footer_table),
-                     gtk_label_new(GetUTF8FromBundle(labelKeys[i]).get()),
-                     i, (i + 1), 1, 2, (GtkAttachOptions) 0, (GtkAttachOptions) 0, 2, 2);
-  }
-
-  aSettings->GetFooterStrLeft(getter_Copies(header_footer_str[0]));
-  aSettings->GetFooterStrCenter(getter_Copies(header_footer_str[1]));
-  aSettings->GetFooterStrRight(getter_Copies(header_footer_str[2]));
-
-  for (unsigned int i = 0; i < NS_ARRAY_LENGTH(footer_dropdown); i++) {
-    footer_dropdown[i] = ConstructHeaderFooterDropdown(header_footer_str[i].get());
-    gtk_table_attach(GTK_TABLE(header_footer_table), footer_dropdown[i], i, (i + 1),
-                     2, 3, (GtkAttachOptions) 0, (GtkAttachOptions) 0, 2, 2);
-  }
-  // ---
-
-  gtk_container_add(GTK_CONTAINER(header_footer_container), header_footer_table);
-
-  GtkWidget* header_footer_vertical_squasher = gtk_vbox_new(FALSE, 0);
-  gtk_box_pack_start(GTK_BOX(header_footer_vertical_squasher), header_footer_label, FALSE, FALSE, 0);
-  gtk_box_pack_start(GTK_BOX(header_footer_vertical_squasher), header_footer_container, FALSE, FALSE, 0);
-
-  // Construction of everything
-  gtk_box_pack_start(GTK_BOX(custom_options_tab), print_frames_label, FALSE, FALSE, 0);
-  gtk_box_pack_start(GTK_BOX(custom_options_tab), frames_radio_container, FALSE, FALSE, 0);
-  gtk_box_pack_start(GTK_BOX(custom_options_tab), check_buttons_container, FALSE, FALSE, 10); // 10px padding
-  gtk_box_pack_start(GTK_BOX(custom_options_tab), appearance_vertical_squasher, FALSE, FALSE, 10);
-  gtk_box_pack_start(GTK_BOX(custom_options_tab), header_footer_vertical_squasher, FALSE, FALSE, 0);
-
-  gtk_print_unix_dialog_add_custom_tab(GTK_PRINT_UNIX_DIALOG(dialog), custom_options_tab, tab_label);
-  gtk_widget_show_all(custom_options_tab);
-}
-
-NS_ConvertUTF16toUTF8
-nsPrintDialogWidgetGTK::GetUTF8FromBundle(const char *aKey)
-{
-  nsXPIDLString intlString;
-  printBundle->GetStringFromName(NS_ConvertUTF8toUTF16(aKey).get(), getter_Copies(intlString));
-  return NS_ConvertUTF16toUTF8(intlString);  // Return the actual object so we don't lose reference
-}
-
-const char*
-nsPrintDialogWidgetGTK::OptionWidgetToString(GtkWidget *dropdown)
-{
-  gint index = gtk_combo_box_get_active(GTK_COMBO_BOX(dropdown));
-
-  NS_ASSERTION(index <= CUSTOM_VALUE_INDEX, "Index of dropdown is higher than expected!");
-
-  if (index == CUSTOM_VALUE_INDEX)
-    return (const char*) g_object_get_data(G_OBJECT(dropdown), "custom-text");
-  else
-    return header_footer_tags[index];
-}
-
-const gint
-nsPrintDialogWidgetGTK::Run()
-{
-  const gint response = RunDialog(GTK_DIALOG(dialog));
-  gtk_widget_hide(dialog);
-  return response;
-}
-
-void
-nsPrintDialogWidgetGTK::ExportFramePrinting(nsIPrintSettings *aNS, GtkPrintSettings *aSettings)
-{
-  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio_as_laid_out)))
-    aNS->SetPrintFrameType(nsIPrintSettings::kFramesAsIs);
-  else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio_selected_frame)))
-    aNS->SetPrintFrameType(nsIPrintSettings::kSelectedFrame);
-  else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio_separate_frames)))
-    aNS->SetPrintFrameType(nsIPrintSettings::kEachFrameSep);
-  else
-    aNS->SetPrintFrameType(nsIPrintSettings::kNoFrames);
-}
-
-void
-nsPrintDialogWidgetGTK::ExportHeaderFooter(nsIPrintSettings *aNS)
-{
-  const char* header_footer_str;
-  header_footer_str = OptionWidgetToString(header_dropdown[0]);
-  aNS->SetHeaderStrLeft(NS_ConvertUTF8toUTF16(header_footer_str).get());
-
-  header_footer_str = OptionWidgetToString(header_dropdown[1]);
-  aNS->SetHeaderStrCenter(NS_ConvertUTF8toUTF16(header_footer_str).get());
+// For Qt, we only support printing to PDF, and that doesn't need a
+// print dialog at this point.  So, this class's methods are left
+// un-implemented for now.
 
-  header_footer_str = OptionWidgetToString(header_dropdown[2]);
-  aNS->SetHeaderStrRight(NS_ConvertUTF8toUTF16(header_footer_str).get());
-
-  header_footer_str = OptionWidgetToString(footer_dropdown[0]);
-  aNS->SetFooterStrLeft(NS_ConvertUTF8toUTF16(header_footer_str).get());
-
-  header_footer_str = OptionWidgetToString(footer_dropdown[1]);
-  aNS->SetFooterStrCenter(NS_ConvertUTF8toUTF16(header_footer_str).get());
-
-  header_footer_str = OptionWidgetToString(footer_dropdown[2]);
-  aNS->SetFooterStrRight(NS_ConvertUTF8toUTF16(header_footer_str).get());
-}
-
-nsresult
-nsPrintDialogWidgetGTK::ImportSettings(nsIPrintSettings *aNSSettings)
-{
-  NS_PRECONDITION(aNSSettings, "aSettings must not be null");
-  NS_ENSURE_TRUE(aNSSettings, NS_ERROR_FAILURE);
-
-  nsCOMPtr<nsPrintSettingsGTK> aNSSettingsGTK(do_QueryInterface(aNSSettings));
-  if (!aNSSettingsGTK)
-    return NS_ERROR_FAILURE;
-
-  GtkPrintSettings* settings = aNSSettingsGTK->GetGtkPrintSettings();
-  GtkPageSetup* setup = aNSSettingsGTK->GetGtkPageSetup();
-
-  PRBool geckoBool;
-  aNSSettings->GetShrinkToFit(&geckoBool);
-  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(shrink_to_fit_toggle), geckoBool);
-
-  aNSSettings->GetPrintBGColors(&geckoBool);
-  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(print_bg_colors_toggle), geckoBool);
-
-  aNSSettings->GetPrintBGImages(&geckoBool);
-  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(print_bg_images_toggle), geckoBool);
-
-  gtk_print_unix_dialog_set_settings(GTK_PRINT_UNIX_DIALOG(dialog), settings);
-  gtk_print_unix_dialog_set_page_setup(GTK_PRINT_UNIX_DIALOG(dialog), setup);
-  
-  return NS_OK;
-}
-
-nsresult
-nsPrintDialogWidgetGTK::ExportSettings(nsIPrintSettings *aNSSettings)
-{
-  NS_PRECONDITION(aNSSettings, "aSettings must not be null");
-  NS_ENSURE_TRUE(aNSSettings, NS_ERROR_FAILURE);
-
-  GtkPrintSettings* settings = gtk_print_unix_dialog_get_settings(GTK_PRINT_UNIX_DIALOG(dialog));
-  GtkPageSetup* setup = gtk_print_unix_dialog_get_page_setup(GTK_PRINT_UNIX_DIALOG(dialog));
-  GtkPrinter* printer = gtk_print_unix_dialog_get_selected_printer(GTK_PRINT_UNIX_DIALOG(dialog));
-  if (settings && setup && printer) {
-    ExportFramePrinting(aNSSettings, settings);
-    ExportHeaderFooter(aNSSettings);
-
-    aNSSettings->SetOutputFormat(nsIPrintSettings::kOutputFormatNative);
-
-    // Print-to-file is true by default. This must be turned off or else printing won't occur!
-    // (We manually copy the spool file when this flag is set, because we love our embedders)
-    // Even if it is print-to-file in GTK's case, GTK does The Right Thing when we send the job.
-    aNSSettings->SetPrintToFile(PR_FALSE);
-
-    aNSSettings->SetShrinkToFit(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(shrink_to_fit_toggle)));
+NS_IMPL_ISUPPORTS1(nsPrintDialogServiceQt, nsIPrintDialogService)
 
-    aNSSettings->SetPrintBGColors(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(print_bg_colors_toggle)));
-    aNSSettings->SetPrintBGImages(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(print_bg_images_toggle)));
-
-    // Try to save native settings in the session object
-    nsCOMPtr<nsPrintSettingsGTK> aNSSettingsGTK(do_QueryInterface(aNSSettings));
-    if (aNSSettingsGTK) {
-      aNSSettingsGTK->SetGtkPrintSettings(settings);
-      aNSSettingsGTK->SetGtkPageSetup(setup);
-      aNSSettingsGTK->SetGtkPrinter(printer);
-      PRBool printSelectionOnly;
-      if (useNativeSelection) {
-        _GtkPrintPages pageSetting = (_GtkPrintPages)gtk_print_settings_get_print_pages(settings);
-        printSelectionOnly = (pageSetting == _GTK_PRINT_PAGES_SELECTION);
-      } else {
-        printSelectionOnly = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(selection_only_toggle));
-      }
-      aNSSettingsGTK->SetForcePrintSelectionOnly(printSelectionOnly);
-    }
-  }
-
-  if (settings)
-    g_object_unref(settings);
-  return NS_OK;
-}
-
-GtkWidget*
-nsPrintDialogWidgetGTK::ConstructHeaderFooterDropdown(const PRUnichar *currentString)
-{
-  GtkWidget* dropdown = gtk_combo_box_new_text();
-  const char hf_options[][22] = {"headerFooterBlank", "headerFooterTitle",
-                                 "headerFooterURL", "headerFooterDate",
-                                 "headerFooterPage", "headerFooterPageTotal",
-                                 "headerFooterCustom"};
-
-  for (unsigned int i = 0; i < NS_ARRAY_LENGTH(hf_options); i++) {
-    gtk_combo_box_append_text(GTK_COMBO_BOX(dropdown), GetUTF8FromBundle(hf_options[i]).get());
-  }
-
-  PRPackedBool shouldBeCustom = PR_TRUE;
-  NS_ConvertUTF16toUTF8 currentStringUTF8(currentString);
-
-  for (unsigned int i = 0; i < NS_ARRAY_LENGTH(header_footer_tags); i++) {
-    if (!strcmp(currentStringUTF8.get(), header_footer_tags[i])) {
-      gtk_combo_box_set_active(GTK_COMBO_BOX(dropdown), i);
-      g_object_set_data(G_OBJECT(dropdown), "previous-active", GINT_TO_POINTER(i));
-      shouldBeCustom = PR_FALSE;
-      break;
-    }
-  }
-
-  if (shouldBeCustom) {
-    gtk_combo_box_set_active(GTK_COMBO_BOX(dropdown), CUSTOM_VALUE_INDEX);
-    g_object_set_data(G_OBJECT(dropdown), "previous-active", GINT_TO_POINTER(CUSTOM_VALUE_INDEX));
-    char* custom_string = strdup(currentStringUTF8.get());
-    g_object_set_data_full(G_OBJECT(dropdown), "custom-text", custom_string, (GDestroyNotify) free);
-  }
-
-  g_signal_connect(dropdown, "changed", (GCallback) ShowCustomDialog, dialog);
-  return dropdown;
-}
-
-NS_IMPL_ISUPPORTS1(nsPrintDialogServiceGTK, nsIPrintDialogService)
-
-nsPrintDialogServiceGTK::nsPrintDialogServiceGTK()
+nsPrintDialogServiceQt::nsPrintDialogServiceQt()
 {
 }
 
-nsPrintDialogServiceGTK::~nsPrintDialogServiceGTK()
+nsPrintDialogServiceQt::~nsPrintDialogServiceQt()
 {
 }
 
 NS_IMETHODIMP
-nsPrintDialogServiceGTK::Init()
-{
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsPrintDialogServiceGTK::Show(nsIDOMWindow *aParent, nsIPrintSettings *aSettings,
-                              nsIWebBrowserPrint *aWebBrowserPrint)
+nsPrintDialogServiceQt::Init()
 {
-  NS_PRECONDITION(aParent, "aParent must not be null");
-  NS_PRECONDITION(aSettings, "aSettings must not be null");
-
-  nsPrintDialogWidgetGTK printDialog(aParent, aSettings);
-  nsresult rv = printDialog.ImportSettings(aSettings);
-
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  const gint response = printDialog.Run();
-
-  // Handle the result
-  switch (response) {
-    case GTK_RESPONSE_OK:                // Proceed
-      rv = printDialog.ExportSettings(aSettings);
-      break;
-
-    case GTK_RESPONSE_CANCEL:
-    case GTK_RESPONSE_CLOSE:
-    case GTK_RESPONSE_DELETE_EVENT:
-    case GTK_RESPONSE_NONE:
-      rv = NS_ERROR_ABORT;
-      break;
-
-    case GTK_RESPONSE_APPLY:                // Print preview
-    default:
-      NS_WARNING("Unexpected response");
-      rv = NS_ERROR_ABORT;
-  }
-  return rv;
+    return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
-nsPrintDialogServiceGTK::ShowPageSetup(nsIDOMWindow *aParent,
-                                       nsIPrintSettings *aNSSettings)
+nsPrintDialogServiceQt::Show(nsIDOMWindow* aParent,
+                             nsIPrintSettings* aSettings,
+                             nsIWebBrowserPrint* aWebBrowserPrint)
 {
-  NS_PRECONDITION(aParent, "aParent must not be null");
-  NS_PRECONDITION(aNSSettings, "aSettings must not be null");
-  NS_ENSURE_TRUE(aNSSettings, NS_ERROR_FAILURE);
-
-  nsCOMPtr<nsIWidget> widget = WidgetUtils::DOMWindowToWidget(aParent);
-  NS_ASSERTION(widget, "Need a widget for dialog to be modal.");
-  GtkWindow* gtkParent = get_gtk_window_for_nsiwidget(widget);
-  NS_ASSERTION(gtkParent, "Need a GTK window for dialog to be modal.");
-
-  nsCOMPtr<nsPrintSettingsGTK> aNSSettingsGTK(do_QueryInterface(aNSSettings));
-  if (!aNSSettingsGTK)
-    return NS_ERROR_FAILURE;
+    return NS_ERROR_NOT_IMPLEMENTED;
+}
 
-  // We need to init the prefs here because aNSSettings in its current form is a dummy in both uses of the word
-  nsCOMPtr<nsIPrintSettingsService> psService = do_GetService("@mozilla.org/gfx/printsettings-service;1");
-  if (psService) {
-    nsXPIDLString printName;
-    aNSSettings->GetPrinterName(getter_Copies(printName));
-    if (!printName) {
-      psService->GetDefaultPrinterName(getter_Copies(printName));
-      aNSSettings->SetPrinterName(printName.get());
-    }
-    psService->InitPrintSettingsFromPrefs(aNSSettings, PR_TRUE, nsIPrintSettings::kInitSaveAll);
-  }
-
-  GtkPrintSettings* gtkSettings = aNSSettingsGTK->GetGtkPrintSettings();
-  GtkPageSetup* oldPageSetup = aNSSettingsGTK->GetGtkPageSetup();
-
-  GtkPageSetup* newPageSetup = gtk_print_run_page_setup_dialog(gtkParent, oldPageSetup, gtkSettings);
-
-  aNSSettingsGTK->SetGtkPageSetup(newPageSetup);
-
-  // Now newPageSetup has a refcount of 2 (SetGtkPageSetup will addref), put it to 1 so if
-  // this gets replaced we don't leak.
-  g_object_unref(newPageSetup);
-
-  if (psService)
-    psService->SavePrintSettingsToPrefs(aNSSettings, PR_TRUE, nsIPrintSettings::kInitSaveAll);
-
-  return NS_OK;
+NS_IMETHODIMP
+nsPrintDialogServiceQt::ShowPageSetup(nsIDOMWindow* aParent,
+                                      nsIPrintSettings* aNSSettings)
+{
+    return NS_ERROR_NOT_IMPLEMENTED;
 }
copy from widget/src/gtk2/nsPrintDialogGTK.h
copy to widget/src/qt/nsPrintDialogQt.h
--- a/widget/src/gtk2/nsPrintDialogGTK.h
+++ b/widget/src/qt/nsPrintDialogQt.h
@@ -1,10 +1,11 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
  * Software distributed under the License is distributed on an "AS IS" basis,
@@ -15,56 +16,48 @@
  * The Original Code is the Mozilla GTK2 print dialog interface.
  *
  * The Initial Developer of the Original Code is
  * Kenneth Herron <kherron@fmailbox.com>
  * Portions created by the Initial Developer are Copyright (C) 2007
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
+ *      Florian Hänel <heeen@gmx.de>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either the GNU General Public License Version 2 or later (the "GPL"), or
  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#ifndef nsPrintDialog_h__
-#define nsPrintDialog_h__
+#ifndef nsPrintDialogQt_h__
+#define nsPrintDialogQt_h__
 
 #include "nsIPrintDialogService.h"
 
 class nsIPrintSettings;
 
-// Copy the print pages enum here because not all versions
-// have SELECTION, which we will use
-typedef enum
-{
-  _GTK_PRINT_PAGES_ALL,
-  _GTK_PRINT_PAGES_CURRENT,
-  _GTK_PRINT_PAGES_RANGES,
-  _GTK_PRINT_PAGES_SELECTION
-} _GtkPrintPages;
-
-class nsPrintDialogServiceGTK : public nsIPrintDialogService
+class nsPrintDialogServiceQt : public nsIPrintDialogService
 {
 public:
-  nsPrintDialogServiceGTK();
-  virtual ~nsPrintDialogServiceGTK();
+    nsPrintDialogServiceQt();
+    virtual ~nsPrintDialogServiceQt();
 
-  NS_DECL_ISUPPORTS
+    NS_DECL_ISUPPORTS
 
-  NS_IMETHODIMP Init();
-  NS_IMETHODIMP Show(nsIDOMWindow *aParent, nsIPrintSettings *aSettings,
-                     nsIWebBrowserPrint *aWebBrowserPrint);
-  NS_IMETHODIMP ShowPageSetup(nsIDOMWindow *aParent,
-                              nsIPrintSettings *aSettings);
+    NS_IMETHODIMP Init();
+    NS_IMETHODIMP Show(nsIDOMWindow* aParent, 
+                       nsIPrintSettings* aSettings,
+                       nsIWebBrowserPrint* aWebBrowserPrint);
+    NS_IMETHODIMP ShowPageSetup(nsIDOMWindow* aParent,
+                                nsIPrintSettings* aSettings);
 };
 
 #endif
copy from widget/src/gtk2/nsPrintOptionsGTK.cpp
copy to widget/src/qt/nsPrintOptionsQt.cpp
--- a/widget/src/gtk2/nsPrintOptionsGTK.cpp
+++ b/widget/src/qt/nsPrintOptionsQt.cpp
@@ -1,10 +1,11 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
  * Software distributed under the License is distributed on an "AS IS" basis,
@@ -15,56 +16,41 @@
  * The Original Code is mozilla.org code.
  *
  * The Initial Developer of the Original Code is
  * Netscape Communications Corporation.
  * Portions created by the Initial Developer are Copyright (C) 1998
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
+ *     Florian Hänel <heeen@gmx.de>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either of the GNU General Public License Version 2 or later (the "GPL"),
  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
-#include "nsPrintOptionsGTK.h"
-#include "nsPrintSettingsGTK.h"
-
+#include "nsPrintSettingsQt.h"
+#include "nsPrintOptionsQt.h"
 
-/** ---------------------------------------------------
- *  See documentation in nsPrintOptionsWin.h
- *	@update 6/21/00 dwc
- */
-nsPrintOptionsGTK::nsPrintOptionsGTK()
-{
-
-}
-
-/** ---------------------------------------------------
- *  See documentation in nsPrintOptionsImpl.h
- *	@update 6/21/00 dwc
- */
-nsPrintOptionsGTK::~nsPrintOptionsGTK()
+nsPrintOptionsQt::nsPrintOptionsQt()
 {
 }
 
-/* nsIPrintSettings CreatePrintSettings (); */
-nsresult nsPrintOptionsGTK::_CreatePrintSettings(nsIPrintSettings **_retval)
+nsPrintOptionsQt::~nsPrintOptionsQt()
 {
-  *_retval = nsnull;
-  nsPrintSettingsGTK* printSettings = new nsPrintSettingsGTK(); // does not initially ref count
-  NS_ENSURE_TRUE(printSettings, NS_ERROR_OUT_OF_MEMORY);
-
-  NS_ADDREF(*_retval = printSettings); // ref count
-
-  return NS_OK;
 }
 
-
+nsresult nsPrintOptionsQt::_CreatePrintSettings(nsIPrintSettings** _retval)
+{
+    nsPrintSettingsQt* printSettings = 
+        new nsPrintSettingsQt(); // does not initially ref count
+    NS_ADDREF(*_retval = printSettings); // ref count
+    return NS_OK;
+}
copy from widget/src/gtk2/nsPrintOptionsGTK.h
copy to widget/src/qt/nsPrintOptionsQt.h
--- a/widget/src/gtk2/nsPrintOptionsGTK.h
+++ b/widget/src/qt/nsPrintOptionsQt.h
@@ -1,9 +1,9 @@
-/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  *
  * ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
@@ -17,45 +17,38 @@
  *
  * The Initial Developer of the Original Code is
  * Netscape Communications, Inc.
  * Portions created by the Initial Developer are Copyright (C) 1999
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
  *   Travis Bogard <travis@netscape.com>
+ *   Florian Hänel <heeen@gmx.de>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either of the GNU General Public License Version 2 or later (the "GPL"),
  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#ifndef nsPrintOptionsGTK_h__
-#define nsPrintOptionsGTK_h__
-
-#include "nsPrintOptionsImpl.h"  
+#ifndef nsPrintOptionsQt_h__
+#define nsPrintOptionsQt_h__
 
+#include "nsPrintOptionsImpl.h"
 
-//*****************************************************************************
-//***    nsPrintOptions
-//*****************************************************************************
-class nsPrintOptionsGTK : public nsPrintOptions
+class nsPrintOptionsQt : public nsPrintOptions
 {
 public:
-  nsPrintOptionsGTK();
-  virtual ~nsPrintOptionsGTK();
-
-  virtual nsresult _CreatePrintSettings(nsIPrintSettings **_retval);
-
+    nsPrintOptionsQt();
+    virtual ~nsPrintOptionsQt();
+    virtual nsresult _CreatePrintSettings(nsIPrintSettings** _retval);
 };
 
-
-
-#endif /* nsPrintOptions_h__ */
+#endif /* nsPrintOptionsQt_h__ */
copy from widget/src/gtk2/nsPrintSettingsGTK.cpp
copy to widget/src/qt/nsPrintSettingsQt.cpp
--- a/widget/src/gtk2/nsPrintSettingsGTK.cpp
+++ b/widget/src/qt/nsPrintSettingsQt.cpp
@@ -1,10 +1,11 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
  * Software distributed under the License is distributed on an "AS IS" basis,
@@ -15,737 +16,451 @@
  * The Original Code is mozilla.org code.
  *
  * The Initial Developer of the Original Code is Mozilla Foundation.
  * Portions created by the Initial Developer are Copyright (C) 2008
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
  *   Michael Ventnor <m.ventnor@gmail.com>
+ *   Florian Hänel <heeen@gmx.de>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either of the GNU General Public License Version 2 or later (the "GPL"),
  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#include "nsPrintSettingsGTK.h"
+#include <QPrinter>
+#include <QDebug>
+#include "nsPrintSettingsQt.h"
 #include "nsILocalFile.h"
-#include "nsNetUtil.h"
-#include <stdlib.h>
+#include "nsCRTGlue.h"
 
-static
-gboolean ref_printer(GtkPrinter *aPrinter, gpointer aData)
+NS_IMPL_ISUPPORTS_INHERITED1(nsPrintSettingsQt,
+                             nsPrintSettings,
+                             nsPrintSettingsQt)
+
+nsPrintSettingsQt::nsPrintSettingsQt():
+    mQPrinter(new QPrinter())
 {
-  ((nsPrintSettingsGTK*) aData)->SetGtkPrinter(aPrinter);
-  return TRUE;
 }
 
-static
-gboolean printer_enumerator(GtkPrinter *aPrinter, gpointer aData)
+nsPrintSettingsQt::~nsPrintSettingsQt()
 {
-  if (gtk_printer_is_default(aPrinter))
-    return ref_printer(aPrinter, aData);
-
-  return FALSE; // Keep 'em coming...
-}
-
-static
-GtkPaperSize* moz_gtk_paper_size_copy_to_new_custom(GtkPaperSize* oldPaperSize)
-{
-  // We make a "custom-ified" copy of the paper size so it can be changed later.
-  return gtk_paper_size_new_custom(gtk_paper_size_get_name(oldPaperSize),
-                                   gtk_paper_size_get_display_name(oldPaperSize),
-                                   gtk_paper_size_get_width(oldPaperSize, GTK_UNIT_INCH),
-                                   gtk_paper_size_get_height(oldPaperSize, GTK_UNIT_INCH),
-                                   GTK_UNIT_INCH);
+    //smart pointer should take care of cleanup
 }
 
-NS_IMPL_ISUPPORTS_INHERITED1(nsPrintSettingsGTK, 
-                             nsPrintSettings, 
-                             nsPrintSettingsGTK)
-
-/** ---------------------------------------------------
- */
-nsPrintSettingsGTK::nsPrintSettingsGTK() :
-  mPageSetup(NULL),
-  mPrintSettings(NULL),
-  mGTKPrinter(NULL),
-  mPrintSelectionOnly(PR_FALSE)
+nsPrintSettingsQt::nsPrintSettingsQt(const nsPrintSettingsQt& aPS):
+    mQPrinter(aPS.mQPrinter)
 {
-  // The aim here is to set up the objects enough that silent printing works well.
-  // These will be replaced anyway if the print dialog is used.
-  mPrintSettings = gtk_print_settings_new();
-  mPageSetup = gtk_page_setup_new();
-  InitUnwriteableMargin();
-
-  SetOutputFormat(nsIPrintSettings::kOutputFormatNative);
-
-  GtkPaperSize* defaultPaperSize = gtk_paper_size_new(NULL);
-  mPaperSize = moz_gtk_paper_size_copy_to_new_custom(defaultPaperSize);
-  gtk_paper_size_free(defaultPaperSize);
-  SaveNewPageSize();
 }
 
-/** ---------------------------------------------------
- */
-nsPrintSettingsGTK::~nsPrintSettingsGTK()
+nsPrintSettingsQt& 
+nsPrintSettingsQt::operator=(const nsPrintSettingsQt& rhs)
 {
-  if (mPageSetup) {
-    g_object_unref(mPageSetup);
-    mPageSetup = NULL;
-  }
-  if (mPrintSettings) {
-    g_object_unref(mPrintSettings);
-    mPrintSettings = NULL;
-  }
-  if (mGTKPrinter) {
-    g_object_unref(mGTKPrinter);
-    mGTKPrinter = NULL;
-  }
-  gtk_paper_size_free(mPaperSize);
+    if (this == &rhs) {
+        return *this;
+    }
+
+    nsPrintSettings::operator=(rhs);
+    mQPrinter = rhs.mQPrinter;
+    return *this;
 }
 
-/** ---------------------------------------------------
- */
-nsPrintSettingsGTK::nsPrintSettingsGTK(const nsPrintSettingsGTK& aPS) :
-  mPageSetup(NULL),
-  mPrintSettings(NULL),
-  mGTKPrinter(NULL),
-  mPrintSelectionOnly(PR_FALSE)
+nsresult 
+nsPrintSettingsQt::_Clone(nsIPrintSettings** _retval)
 {
-  *this = aPS;
+    NS_ENSURE_ARG_POINTER(_retval);
+
+    nsPrintSettingsQt* newSettings = new nsPrintSettingsQt(*this);
+    *_retval = newSettings;
+    NS_ADDREF(*_retval);
+    return NS_OK;
 }
 
-/** ---------------------------------------------------
- */
-nsPrintSettingsGTK& nsPrintSettingsGTK::operator=(const nsPrintSettingsGTK& rhs)
+NS_IMETHODIMP
+nsPrintSettingsQt::_Assign(nsIPrintSettings* aPS)
 {
-  if (this == &rhs) {
-    return *this;
-  }
-  
-  nsPrintSettings::operator=(rhs);
-
-  if (mPageSetup)
-    g_object_unref(mPageSetup);
-  mPageSetup = gtk_page_setup_copy(rhs.mPageSetup);
-  // NOTE: No need to re-initialize mUnwriteableMargin here (even
-  // though mPageSetup is changing). It'll be copied correctly by
-  // nsPrintSettings::operator=.
-
-  if (mPrintSettings)
-    g_object_unref(mPrintSettings);
-  mPrintSettings = gtk_print_settings_copy(rhs.mPrintSettings);
-
-  if (mGTKPrinter)
-    g_object_unref(mGTKPrinter);
-  mGTKPrinter = (GtkPrinter*) g_object_ref(rhs.mGTKPrinter);
-
-  mPrintSelectionOnly = rhs.mPrintSelectionOnly;
-
-  return *this;
-}
-
-/** -------------------------------------------
- */
-nsresult nsPrintSettingsGTK::_Clone(nsIPrintSettings **_retval)
-{
-  NS_ENSURE_ARG_POINTER(_retval);
-  *_retval = nsnull;
-  
-  nsPrintSettingsGTK *newSettings = new nsPrintSettingsGTK(*this);
-  if (!newSettings)
-    return NS_ERROR_FAILURE;
-  *_retval = newSettings;
-  NS_ADDREF(*_retval);
-  return NS_OK;
+    nsPrintSettingsQt* printSettingsQt = static_cast<nsPrintSettingsQt*>(aPS);
+    if (!printSettingsQt)
+        return NS_ERROR_UNEXPECTED;
+    *this = *printSettingsQt;
+    return NS_OK;
 }
 
-
-/** -------------------------------------------
- */
 NS_IMETHODIMP
-nsPrintSettingsGTK::_Assign(nsIPrintSettings *aPS)
+nsPrintSettingsQt::GetPrintRange(PRInt16* aPrintRange)
 {
-  nsPrintSettingsGTK *printSettingsGTK = static_cast<nsPrintSettingsGTK*>(aPS);
-  if (!printSettingsGTK)
-    return NS_ERROR_UNEXPECTED;
-  *this = *printSettingsGTK;
-  return NS_OK;
+    NS_ENSURE_ARG_POINTER(aPrintRange);
+
+    QPrinter::PrintRange range = mQPrinter->printRange();
+    if (range == QPrinter::PageRange) {
+        *aPrintRange = kRangeSpecifiedPageRange;
+    } else if (range == QPrinter::Selection) {
+        *aPrintRange = kRangeSelection;
+    } else {
+        *aPrintRange = kRangeAllPages;
+    }
+
+    return NS_OK;
 }
 
-/** ---------------------------------------------------
- */
-void
-nsPrintSettingsGTK::SetGtkPageSetup(GtkPageSetup *aPageSetup)
+NS_IMETHODIMP 
+nsPrintSettingsQt::SetPrintRange(PRInt16 aPrintRange)
 {
-  if (mPageSetup)
-    g_object_unref(mPageSetup);
-  
-  mPageSetup = (GtkPageSetup*) g_object_ref(aPageSetup);
-  InitUnwriteableMargin();
-
-  // We make a custom copy of the GtkPaperSize so it can be mutable. If a
-  // GtkPaperSize wasn't made as custom, its properties are immutable.
-  GtkPaperSize* newPaperSize = gtk_page_setup_get_paper_size(aPageSetup);
-  if (newPaperSize) { // Yes, this can be null
-    gtk_paper_size_free(mPaperSize);
-    mPaperSize = moz_gtk_paper_size_copy_to_new_custom(newPaperSize);
-  }
-  // If newPaperSize was not null, we must update our twin too (GtkPrintSettings).
-  // If newPaperSize was null, we must set this object to use mPaperSize.
-  SaveNewPageSize();
+    if (aPrintRange == kRangeSelection) {
+        mQPrinter->setPrintRange(QPrinter::Selection);
+    } else if (aPrintRange == kRangeSpecifiedPageRange) {
+        mQPrinter->setPrintRange(QPrinter::PageRange);
+    } else {
+        mQPrinter->setPrintRange(QPrinter::AllPages);
+    }
+    return NS_OK;
 }
 
-/** ---------------------------------------------------
- */
-void
-nsPrintSettingsGTK::SetGtkPrintSettings(GtkPrintSettings *aPrintSettings)
+NS_IMETHODIMP
+nsPrintSettingsQt::GetStartPageRange(PRInt32* aStartPageRange)
 {
-  if (mPrintSettings)
-    g_object_unref(mPrintSettings);
-  
-  mPrintSettings = (GtkPrintSettings*) g_object_ref(aPrintSettings);
-
-  GtkPaperSize* newPaperSize = gtk_print_settings_get_paper_size(aPrintSettings);
-  if (newPaperSize) {
-    gtk_paper_size_free(mPaperSize);
-    mPaperSize = moz_gtk_paper_size_copy_to_new_custom(newPaperSize);
-  }
-  SaveNewPageSize();
-}
-
-/** ---------------------------------------------------
- */
-void
-nsPrintSettingsGTK::SetGtkPrinter(GtkPrinter *aPrinter)
-{
-  if (mGTKPrinter)
-    g_object_unref(mGTKPrinter);
-  
-  mGTKPrinter = (GtkPrinter*) g_object_ref(aPrinter);
+    NS_ENSURE_ARG_POINTER(aStartPageRange);
+    PRInt32 start = mQPrinter->fromPage();
+    *aStartPageRange = start;
+    return NS_OK;
 }
 
-/**
- * Reimplementation of nsPrintSettings functions so that we get the values
- * from the GTK objects rather than our own variables.
- */
-
-/* attribute long printRange; */
-NS_IMETHODIMP nsPrintSettingsGTK::GetPrintRange(PRInt16 *aPrintRange)
+NS_IMETHODIMP
+nsPrintSettingsQt::SetStartPageRange(PRInt32 aStartPageRange)
 {
-  NS_ENSURE_ARG_POINTER(aPrintRange);
-  if (mPrintSelectionOnly) {
-    *aPrintRange = kRangeSelection;
+    PRInt32 endRange = mQPrinter->toPage();
+    mQPrinter->setFromTo(aStartPageRange, endRange);
     return NS_OK;
-  }
+}
 
-  GtkPrintPages gtkRange = gtk_print_settings_get_print_pages(mPrintSettings);
-  if (gtkRange == GTK_PRINT_PAGES_RANGES)
-    *aPrintRange = kRangeSpecifiedPageRange;
-  else
-    *aPrintRange = kRangeAllPages;
-
-  return NS_OK;
-}
-NS_IMETHODIMP nsPrintSettingsGTK::SetPrintRange(PRInt16 aPrintRange)
+NS_IMETHODIMP
+nsPrintSettingsQt::GetEndPageRange(PRInt32* aEndPageRange)
 {
-  if (aPrintRange == kRangeSelection) {
-    mPrintSelectionOnly = PR_TRUE;
+    NS_ENSURE_ARG_POINTER(aEndPageRange);
+    PRInt32 end = mQPrinter->toPage();
+    *aEndPageRange = end;
     return NS_OK;
-  }
+}
 
-  mPrintSelectionOnly = PR_FALSE;
-  if (aPrintRange == kRangeSpecifiedPageRange)
-    gtk_print_settings_set_print_pages(mPrintSettings, GTK_PRINT_PAGES_RANGES);
-  else
-    gtk_print_settings_set_print_pages(mPrintSettings, GTK_PRINT_PAGES_ALL);
-  return NS_OK;
+NS_IMETHODIMP
+nsPrintSettingsQt::SetEndPageRange(PRInt32 aEndPageRange)
+{
+    PRInt32 startRange = mQPrinter->fromPage();
+    mQPrinter->setFromTo(startRange, aEndPageRange);
+    return NS_OK;
 }
 
-/* attribute long startPageRange; */
 NS_IMETHODIMP
-nsPrintSettingsGTK::GetStartPageRange(PRInt32 *aStartPageRange)
+nsPrintSettingsQt::GetPrintReversed(PRBool* aPrintReversed)
 {
-  gint ctRanges;
-  GtkPageRange* lstRanges = gtk_print_settings_get_page_ranges(mPrintSettings, &ctRanges);
-
-  // Make sure we got a range.
-  if (ctRanges < 1) {
-    *aStartPageRange = 1;
-  } else {
-    // GTK supports multiple page ranges; gecko only supports 1. So find
-    // the lowest start page.
-    PRInt32 start(lstRanges[0].start);
-    for (gint ii = 1; ii < ctRanges; ii++) {
-      start = PR_MIN(lstRanges[ii].start, start);
+    NS_ENSURE_ARG_POINTER(aPrintReversed);
+    if (mQPrinter->pageOrder() == QPrinter::LastPageFirst) {
+        *aPrintReversed = PR_TRUE;
+    } else {
+        *aPrintReversed = PR_FALSE;
     }
-    *aStartPageRange = start + 1;
-  }
-
-  g_free(lstRanges);
-  return NS_OK;
-}
-NS_IMETHODIMP
-nsPrintSettingsGTK::SetStartPageRange(PRInt32 aStartPageRange)
-{
-  PRInt32 endRange;
-  GetEndPageRange(&endRange);
-
-  GtkPageRange gtkRange;
-  gtkRange.start = aStartPageRange - 1;
-  gtkRange.end = endRange - 1;
-
-  gtk_print_settings_set_page_ranges(mPrintSettings, &gtkRange, 1);
-
-  return NS_OK;
+    return NS_OK;
 }
 
-/* attribute long endPageRange; */
 NS_IMETHODIMP
-nsPrintSettingsGTK::GetEndPageRange(PRInt32 *aEndPageRange)
+nsPrintSettingsQt::SetPrintReversed(PRBool aPrintReversed)
 {
-  gint ctRanges;
-  GtkPageRange* lstRanges = gtk_print_settings_get_page_ranges(mPrintSettings, &ctRanges);
+    if (aPrintReversed) {
+        mQPrinter->setPageOrder(QPrinter::LastPageFirst);
+    } else {
+        mQPrinter->setPageOrder(QPrinter::FirstPageFirst);
+    }
+    return NS_OK;
+}
 
-  if (ctRanges < 1) {
-    *aEndPageRange = 1;
-  } else {
-    PRInt32 end(lstRanges[0].end);
-    for (gint ii = 1; ii < ctRanges; ii++) {
-      end = PR_MAX(lstRanges[ii].end, end);
+NS_IMETHODIMP
+nsPrintSettingsQt::GetPrintInColor(PRBool* aPrintInColor)
+{
+    NS_ENSURE_ARG_POINTER(aPrintInColor);
+    if (mQPrinter->colorMode() == QPrinter::Color) {
+        *aPrintInColor = PR_TRUE;
+    } else {
+        *aPrintInColor = PR_FALSE;
     }
-    *aEndPageRange = end + 1;
-  }
-
-  g_free(lstRanges);
-  return NS_OK;
+    return NS_OK;
 }
 NS_IMETHODIMP
-nsPrintSettingsGTK::SetEndPageRange(PRInt32 aEndPageRange)
-{
-  PRInt32 startRange;
-  GetStartPageRange(&startRange);
-
-  GtkPageRange gtkRange;
-  gtkRange.start = startRange - 1;
-  gtkRange.end = aEndPageRange - 1;
-
-  gtk_print_settings_set_page_ranges(mPrintSettings, &gtkRange, 1);
-
-  return NS_OK;
-}
-
-/* attribute boolean printReversed; */
-NS_IMETHODIMP
-nsPrintSettingsGTK::GetPrintReversed(PRBool *aPrintReversed)
+nsPrintSettingsQt::SetPrintInColor(PRBool aPrintInColor)
 {
-  *aPrintReversed = gtk_print_settings_get_reverse(mPrintSettings);
-  return NS_OK;
-}
-NS_IMETHODIMP
-nsPrintSettingsGTK::SetPrintReversed(PRBool aPrintReversed)
-{
-  gtk_print_settings_set_reverse(mPrintSettings, aPrintReversed);
-  return NS_OK;
-}
-
-/* attribute boolean printInColor; */
-NS_IMETHODIMP
-nsPrintSettingsGTK::GetPrintInColor(PRBool *aPrintInColor)
-{
-  *aPrintInColor = gtk_print_settings_get_use_color(mPrintSettings);
-  return NS_OK;
-}
-NS_IMETHODIMP
-nsPrintSettingsGTK::SetPrintInColor(PRBool aPrintInColor)
-{
-  gtk_print_settings_set_use_color(mPrintSettings, aPrintInColor);
-  return NS_OK;
+    if (aPrintInColor) {
+        mQPrinter->setColorMode(QPrinter::Color);
+    } else {
+        mQPrinter->setColorMode(QPrinter::GrayScale);
+    }
+    return NS_OK;
 }
 
-/* attribute short orientation; */
 NS_IMETHODIMP
-nsPrintSettingsGTK::GetOrientation(PRInt32 *aOrientation)
+nsPrintSettingsQt::GetOrientation(PRInt32* aOrientation)
 {
-  NS_ENSURE_ARG_POINTER(aOrientation);
-
-  GtkPageOrientation gtkOrient = gtk_page_setup_get_orientation(mPageSetup);
-  switch (gtkOrient) {
-    case GTK_PAGE_ORIENTATION_LANDSCAPE:
-    case GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE:
-      *aOrientation = kLandscapeOrientation;
-      break;
-
-    case GTK_PAGE_ORIENTATION_PORTRAIT:
-    case GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT:
-    default:
-      *aOrientation = kPortraitOrientation;
-  }
-  return NS_OK;
-}
-NS_IMETHODIMP
-nsPrintSettingsGTK::SetOrientation(PRInt32 aOrientation)
-{
-  GtkPageOrientation gtkOrient;
-  if (aOrientation == kLandscapeOrientation)
-    gtkOrient = GTK_PAGE_ORIENTATION_LANDSCAPE;
-  else
-    gtkOrient = GTK_PAGE_ORIENTATION_PORTRAIT;
-
-  gtk_print_settings_set_orientation(mPrintSettings, gtkOrient);
-  gtk_page_setup_set_orientation(mPageSetup, gtkOrient);
-  return NS_OK;
+    NS_ENSURE_ARG_POINTER(aOrientation);
+    QPrinter::Orientation orientation = mQPrinter->orientation();
+    if (orientation == QPrinter::Landscape) {
+        *aOrientation = kLandscapeOrientation;
+    } else {
+        *aOrientation = kPortraitOrientation;
+    }
+    return NS_OK;
 }
 
-/* attribute wstring toFileName; */
 NS_IMETHODIMP
-nsPrintSettingsGTK::GetToFileName(PRUnichar * *aToFileName)
+nsPrintSettingsQt::SetOrientation(PRInt32 aOrientation)
 {
-  // Get the gtk output filename
-  const char* gtk_output_uri = gtk_print_settings_get(mPrintSettings, GTK_PRINT_SETTINGS_OUTPUT_URI);
-  if (!gtk_output_uri) {
-    *aToFileName = ToNewUnicode(mToFileName);
+    if (aOrientation == kLandscapeOrientation) {
+        mQPrinter->setOrientation(QPrinter::Landscape);
+    } else {
+        mQPrinter->setOrientation(QPrinter::Portrait);
+    }
     return NS_OK;
-  }
+}
 
-  // Convert to an nsIFile
-  nsCOMPtr<nsIFile> file;
-  nsresult rv = NS_GetFileFromURLSpec(nsDependentCString(gtk_output_uri),
-                                      getter_AddRefs(file));
-  if (NS_FAILED(rv))
-    return rv;
-
-  // Extract the path
-  nsAutoString path;
-  rv = file->GetPath(path);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  *aToFileName = ToNewUnicode(path);
-  return NS_OK;
+NS_IMETHODIMP
+nsPrintSettingsQt::GetToFileName(PRUnichar** aToFileName)
+{
+    NS_ENSURE_ARG_POINTER(aToFileName);
+    QString filename;
+    filename = mQPrinter->outputFileName();
+    *aToFileName = ToNewUnicode(
+            nsDependentString((PRUnichar*)filename.data()));
+    return NS_OK;
 }
 
 NS_IMETHODIMP
-nsPrintSettingsGTK::SetToFileName(const PRUnichar * aToFileName)
+nsPrintSettingsQt::SetToFileName(const PRUnichar* aToFileName)
 {
-  if (aToFileName[0] == 0) {
-    mToFileName.SetLength(0);
-    gtk_print_settings_set(mPrintSettings, GTK_PRINT_SETTINGS_OUTPUT_URI, NULL);
+    nsCOMPtr<nsILocalFile> file;
+    nsresult rv = NS_NewLocalFile(nsDependentString(aToFileName), PR_TRUE,
+                                getter_AddRefs(file));
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    QString filename((const QChar*)aToFileName, NS_strlen(aToFileName));
+    mQPrinter->setOutputFileName(filename);
+
     return NS_OK;
-  }
+}
 
-  if (StringEndsWith(nsDependentString(aToFileName), NS_LITERAL_STRING(".ps"))) {
-    gtk_print_settings_set(mPrintSettings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT, "ps");
-  } else {
-    gtk_print_settings_set(mPrintSettings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT, "pdf");
-  }
+NS_IMETHODIMP
+nsPrintSettingsQt::GetPrinterName(PRUnichar** aPrinter)
+{
+    NS_ENSURE_ARG_POINTER(aPrinter);
+    *aPrinter = ToNewUnicode(nsDependentString(
+                (const PRUnichar*)mQPrinter->printerName().constData()));
+    return NS_OK;
+}
 
-  nsCOMPtr<nsILocalFile> file;
-  nsresult rv = NS_NewLocalFile(nsDependentString(aToFileName), PR_TRUE,
-                                getter_AddRefs(file));
-  NS_ENSURE_SUCCESS(rv, rv);
+NS_IMETHODIMP
+nsPrintSettingsQt::SetPrinterName(const PRUnichar* aPrinter)
+{
+    QString printername((const QChar*)aPrinter, NS_strlen(aPrinter));
+    mQPrinter->setPrinterName(printername);
+    return NS_OK;
+}
 
-  // Convert the nsIFile to a URL
-  nsCAutoString url;
-  rv = NS_GetURLSpecFromFile(file, url);
-  NS_ENSURE_SUCCESS(rv, rv);
+NS_IMETHODIMP
+nsPrintSettingsQt::GetNumCopies(PRInt32* aNumCopies)
+{
+    NS_ENSURE_ARG_POINTER(aNumCopies);
+    *aNumCopies = mQPrinter->numCopies();
+    return NS_OK;
+}
 
-  gtk_print_settings_set(mPrintSettings, GTK_PRINT_SETTINGS_OUTPUT_URI, url.get());
-  mToFileName = aToFileName;
-
-  return NS_OK;
+NS_IMETHODIMP
+nsPrintSettingsQt::SetNumCopies(PRInt32 aNumCopies)
+{
+    mQPrinter->setNumCopies(aNumCopies);
+    return NS_OK;
 }
 
 NS_IMETHODIMP
-nsPrintSettingsGTK::GetPrinterName(PRUnichar * *aPrinter)
+nsPrintSettingsQt::GetScaling(double* aScaling)
 {
-  const char* gtkPrintName = gtk_print_settings_get_printer(mPrintSettings);
-  if (!gtkPrintName) {
-    if (GTK_IS_PRINTER(mGTKPrinter)) {
-      gtkPrintName = gtk_printer_get_name(mGTKPrinter);
-    } else {
-      // This mimics what nsPrintSettingsImpl does when we try to Get before we Set
-      nsXPIDLString nullPrintName;
-      *aPrinter = ToNewUnicode(nullPrintName);
-      return NS_OK;
-    }
-  }
-  *aPrinter = ToNewUnicode(nsDependentCString(gtkPrintName));
-  return NS_OK;
+    NS_ENSURE_ARG_POINTER(aScaling);
+    qDebug()<<Q_FUNC_INFO;
+    qDebug()<<"Scaling not implemented in Qt port";
+    *aScaling = 1.0; //FIXME
+    return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
-nsPrintSettingsGTK::SetPrinterName(const PRUnichar * aPrinter)
+nsPrintSettingsQt::SetScaling(double aScaling)
 {
-  NS_ConvertUTF16toUTF8 gtkPrinter(aPrinter);
-
-  if (StringBeginsWith(gtkPrinter, NS_LITERAL_CSTRING("CUPS/"))) {
-    // Strip off "CUPS/"; GTK might recognize the rest
-    gtkPrinter.Cut(0, strlen("CUPS/"));
-  }
-
-  // Give mPrintSettings the passed-in printer name if either...
-  // - it has no printer name stored yet
-  // - it has an existing printer name that's different from
-  //   the name passed to this function.
-  const char* oldPrinterName = gtk_print_settings_get_printer(mPrintSettings);
-  if (!oldPrinterName || !gtkPrinter.Equals(oldPrinterName)) {
-    mIsInitedFromPrinter = PR_FALSE;
-    mIsInitedFromPrefs = PR_FALSE;
-    gtk_print_settings_set_printer(mPrintSettings, gtkPrinter.get());
-  }
-
-  return NS_OK;
+    qDebug()<<Q_FUNC_INFO;
+    qDebug()<<"Scaling not implemented in Qt port"; //FIXME
+    return NS_ERROR_NOT_IMPLEMENTED;
 }
 
-/* attribute long numCopies; */
-NS_IMETHODIMP
-nsPrintSettingsGTK::GetNumCopies(PRInt32 *aNumCopies)
-{
-  NS_ENSURE_ARG_POINTER(aNumCopies);
-  *aNumCopies = gtk_print_settings_get_n_copies(mPrintSettings);
-  return NS_OK;
-}
-NS_IMETHODIMP
-nsPrintSettingsGTK::SetNumCopies(PRInt32 aNumCopies)
+static const char* const indexToPaperName[] =
+{ "A4", "B5", "Letter", "Legal", "Executive",
+  "A0", "A1", "A2", "A3", "A5", "A6", "A7", "A8", "A9",
+  "B0", "B1", "B10", "B2", "B3", "B4", "B6", "B7", "B8", "B9",
+  "C5E", "Comm10E", "DLE", "Folio", "Ledger", "Tabloid"
+};
+
+static const QPrinter::PageSize indexToQtPaperEnum[] =
 {
-  gtk_print_settings_set_n_copies(mPrintSettings, aNumCopies);
-  return NS_OK;
-}
+    QPrinter::A4, QPrinter::B5, QPrinter::Letter, QPrinter::Legal,
+    QPrinter::Executive, QPrinter::A0, QPrinter::A1, QPrinter::A2, QPrinter::A3,
+    QPrinter::A5, QPrinter::A6, QPrinter::A7, QPrinter::A8, QPrinter::A9,
+    QPrinter::B0, QPrinter::B1, QPrinter::B10, QPrinter::B2, QPrinter::B3,
+    QPrinter::B4, QPrinter::B6, QPrinter::B7, QPrinter::B8, QPrinter::B9,
+    QPrinter::C5E, QPrinter::Comm10E, QPrinter::DLE, QPrinter::Folio,
+    QPrinter::Ledger, QPrinter::Tabloid
+};
 
-/* attribute double scaling; */
 NS_IMETHODIMP
-nsPrintSettingsGTK::GetScaling(double *aScaling)
+nsPrintSettingsQt::GetPaperName(PRUnichar** aPaperName)
 {
-  *aScaling = gtk_print_settings_get_scale(mPrintSettings) / 100.0;
-  return NS_OK;
+    PR_STATIC_ASSERT(sizeof(indexToPaperName)/
+        sizeof(char*) == QPrinter::NPageSize);
+    PR_STATIC_ASSERT(sizeof(indexToQtPaperEnum)/
+        sizeof(QPrinter::PageSize) == QPrinter::NPageSize);
+
+    QPrinter::PaperSize size = mQPrinter->paperSize();
+    QString name(indexToPaperName[size]);
+    *aPaperName = ToNewUnicode(nsDependentString
+        ((const PRUnichar*)name.constData()));
+    return NS_OK;
 }
 
 NS_IMETHODIMP
-nsPrintSettingsGTK::SetScaling(double aScaling)
+nsPrintSettingsQt::SetPaperName(const PRUnichar* aPaperName)
 {
-  gtk_print_settings_set_scale(mPrintSettings, aScaling * 100.0);
-  return NS_OK;
+    QString ref((QChar*)aPaperName, NS_strlen(aPaperName));
+    for (PRUint32 i = 0; i < QPrinter::NPageSize; i++)
+    {
+        if (ref == QString(indexToPaperName[i])) {
+            mQPrinter->setPageSize(indexToQtPaperEnum[i]);
+            return NS_OK;
+        }
+    }
+    return NS_ERROR_FAILURE;
 }
 
-/* attribute wstring paperName; */
-NS_IMETHODIMP
-nsPrintSettingsGTK::GetPaperName(PRUnichar * *aPaperName)
-{
-  NS_ENSURE_ARG_POINTER(aPaperName);
-  *aPaperName = ToNewUnicode(NS_ConvertUTF8toUTF16(gtk_paper_size_get_name(mPaperSize)));
-  return NS_OK;
-}
-NS_IMETHODIMP
-nsPrintSettingsGTK::SetPaperName(const PRUnichar * aPaperName)
+QPrinter::Unit GetQtUnit(PRInt16 aGeckoUnit)
 {
-  NS_ConvertUTF16toUTF8 gtkPaperName(aPaperName);
-
-  // Convert these Gecko names to GTK names
-  if (gtkPaperName.EqualsIgnoreCase("letter"))
-    gtkPaperName.AssignLiteral(GTK_PAPER_NAME_LETTER);
-  else if (gtkPaperName.EqualsIgnoreCase("legal"))
-    gtkPaperName.AssignLiteral(GTK_PAPER_NAME_LEGAL);
-
-  // Try to get the display name from the name so our paper size fits in the Page Setup dialog.
-  GtkPaperSize* paperSize = gtk_paper_size_new(gtkPaperName.get());
-  char* displayName = strdup(gtk_paper_size_get_display_name(paperSize));
-  gtk_paper_size_free(paperSize);
-
-  paperSize = gtk_paper_size_new_custom(gtkPaperName.get(), displayName,
-                                        gtk_paper_size_get_width(mPaperSize, GTK_UNIT_INCH),
-                                        gtk_paper_size_get_height(mPaperSize, GTK_UNIT_INCH),
-                                        GTK_UNIT_INCH);
-
-  free(displayName);
-  gtk_paper_size_free(mPaperSize);
-  mPaperSize = paperSize;
-  SaveNewPageSize();
-  return NS_OK;
-}
-
-GtkUnit
-nsPrintSettingsGTK::GetGTKUnit(PRInt16 aGeckoUnit)
-{
-  if (aGeckoUnit == kPaperSizeMillimeters)
-    return GTK_UNIT_MM;
-  else
-    return GTK_UNIT_INCH;
-}
-
-void
-nsPrintSettingsGTK::SaveNewPageSize()
-{
-  gtk_print_settings_set_paper_size(mPrintSettings, mPaperSize);
-  gtk_page_setup_set_paper_size(mPageSetup, mPaperSize);
-}
-
-void
-nsPrintSettingsGTK::InitUnwriteableMargin()
-{
-  mUnwriteableMargin.SizeTo(
-   NS_INCHES_TO_INT_TWIPS(gtk_page_setup_get_left_margin(mPageSetup, GTK_UNIT_INCH)),
-   NS_INCHES_TO_INT_TWIPS(gtk_page_setup_get_top_margin(mPageSetup, GTK_UNIT_INCH)),
-   NS_INCHES_TO_INT_TWIPS(gtk_page_setup_get_right_margin(mPageSetup, GTK_UNIT_INCH)),
-   NS_INCHES_TO_INT_TWIPS(gtk_page_setup_get_bottom_margin(mPageSetup, GTK_UNIT_INCH))
-  );
+    if (aGeckoUnit == nsIPrintSettings::kPaperSizeMillimeters) {
+        return QPrinter::Millimeter;
+    } else {
+        return QPrinter::Inch;
+    }
 }
 
-/**
- * NOTE: Need a custom set of SetUnwriteableMargin functions, because
- * whenever we change mUnwriteableMargin, we must pass the change
- * down to our GTKPageSetup object.  (This is needed in order for us
- * to give the correct default values in nsPrintDialogGTK.)
- *
- * It's important that the following functions pass 
- * mUnwriteableMargin values rather than aUnwriteableMargin values
- * to gtk_page_setup_set_[blank]_margin, because the two may not be
- * the same.  (Specifically, negative values of aUnwriteableMargin
- * are ignored by the nsPrintSettings::SetUnwriteableMargin functions.)
- */
-NS_IMETHODIMP 
-nsPrintSettingsGTK::SetUnwriteableMarginInTwips(nsIntMargin& aUnwriteableMargin)
+#define SETUNWRITEABLEMARGIN\
+    mQPrinter->setPageMargins(\
+            NS_TWIPS_TO_INCHES(mUnwriteableMargin.left),\
+            NS_TWIPS_TO_INCHES(mUnwriteableMargin.top),\
+            NS_TWIPS_TO_INCHES(mUnwriteableMargin.right),\
+            NS_TWIPS_TO_INCHES(mUnwriteableMargin.bottom),\
+            QPrinter::Inch);
+
+NS_IMETHODIMP
+nsPrintSettingsQt::SetUnwriteableMarginInTwips(nsIntMargin& aUnwriteableMargin)
 {
-  nsPrintSettings::SetUnwriteableMarginInTwips(aUnwriteableMargin);
-  gtk_page_setup_set_top_margin(mPageSetup,
-           NS_TWIPS_TO_INCHES(mUnwriteableMargin.top), GTK_UNIT_INCH);
-  gtk_page_setup_set_left_margin(mPageSetup,
-           NS_TWIPS_TO_INCHES(mUnwriteableMargin.left), GTK_UNIT_INCH);
-  gtk_page_setup_set_bottom_margin(mPageSetup,
-           NS_TWIPS_TO_INCHES(mUnwriteableMargin.bottom), GTK_UNIT_INCH);
-  gtk_page_setup_set_right_margin(mPageSetup,
-           NS_TWIPS_TO_INCHES(mUnwriteableMargin.right), GTK_UNIT_INCH);
-  return NS_OK;
-}
-
-/* attribute double unwriteableMarginTop; */
-NS_IMETHODIMP
-nsPrintSettingsGTK::SetUnwriteableMarginTop(double aUnwriteableMarginTop)
-{
-  nsPrintSettings::SetUnwriteableMarginTop(aUnwriteableMarginTop);
-  gtk_page_setup_set_top_margin(mPageSetup,
-           NS_TWIPS_TO_INCHES(mUnwriteableMargin.top), GTK_UNIT_INCH);
-  return NS_OK;
-}
-
-/* attribute double unwriteableMarginLeft; */
-NS_IMETHODIMP
-nsPrintSettingsGTK::SetUnwriteableMarginLeft(double aUnwriteableMarginLeft)
-{
-  nsPrintSettings::SetUnwriteableMarginLeft(aUnwriteableMarginLeft);
-  gtk_page_setup_set_left_margin(mPageSetup,
-           NS_TWIPS_TO_INCHES(mUnwriteableMargin.left), GTK_UNIT_INCH);
-  return NS_OK;
+    nsPrintSettings::SetUnwriteableMarginInTwips(aUnwriteableMargin);
+    SETUNWRITEABLEMARGIN
+    return NS_OK;
 }
 
-/* attribute double unwriteableMarginBottom; */
 NS_IMETHODIMP
-nsPrintSettingsGTK::SetUnwriteableMarginBottom(double aUnwriteableMarginBottom)
+nsPrintSettingsQt::SetUnwriteableMarginTop(double aUnwriteableMarginTop)
 {
-  nsPrintSettings::SetUnwriteableMarginBottom(aUnwriteableMarginBottom);
-  gtk_page_setup_set_bottom_margin(mPageSetup,
-           NS_TWIPS_TO_INCHES(mUnwriteableMargin.bottom), GTK_UNIT_INCH);
-  return NS_OK;
-}
-
-/* attribute double unwriteableMarginRight; */
-NS_IMETHODIMP
-nsPrintSettingsGTK::SetUnwriteableMarginRight(double aUnwriteableMarginRight)
-{
-  nsPrintSettings::SetUnwriteableMarginRight(aUnwriteableMarginRight);
-  gtk_page_setup_set_right_margin(mPageSetup,
-           NS_TWIPS_TO_INCHES(mUnwriteableMargin.right), GTK_UNIT_INCH);
-  return NS_OK;
+    nsPrintSettings::SetUnwriteableMarginTop(aUnwriteableMarginTop);
+    SETUNWRITEABLEMARGIN
+    return NS_OK;
 }
 
-/* attribute double paperWidth; */
 NS_IMETHODIMP
-nsPrintSettingsGTK::GetPaperWidth(double *aPaperWidth)
+nsPrintSettingsQt::SetUnwriteableMarginLeft(double aUnwriteableMarginLeft)
 {
-  NS_ENSURE_ARG_POINTER(aPaperWidth);
-  *aPaperWidth = gtk_paper_size_get_width(mPaperSize, GetGTKUnit(mPaperSizeUnit));
-  return NS_OK;
-}
-NS_IMETHODIMP
-nsPrintSettingsGTK::SetPaperWidth(double aPaperWidth)
-{
-  gtk_paper_size_set_size(mPaperSize,
-                          aPaperWidth,
-                          gtk_paper_size_get_height(mPaperSize, GetGTKUnit(mPaperSizeUnit)),
-                          GetGTKUnit(mPaperSizeUnit));
-  SaveNewPageSize();
-  return NS_OK;
+    nsPrintSettings::SetUnwriteableMarginLeft(aUnwriteableMarginLeft);
+    SETUNWRITEABLEMARGIN
+    return NS_OK;
 }
 
-/* attribute double paperHeight; */
 NS_IMETHODIMP
-nsPrintSettingsGTK::GetPaperHeight(double *aPaperHeight)
+nsPrintSettingsQt::SetUnwriteableMarginBottom(double aUnwriteableMarginBottom)
 {
-  NS_ENSURE_ARG_POINTER(aPaperHeight);
-  *aPaperHeight = gtk_paper_size_get_height(mPaperSize, GetGTKUnit(mPaperSizeUnit));
-  return NS_OK;
-}
-NS_IMETHODIMP
-nsPrintSettingsGTK::SetPaperHeight(double aPaperHeight)
-{
-  gtk_paper_size_set_size(mPaperSize,
-                          gtk_paper_size_get_width(mPaperSize, GetGTKUnit(mPaperSizeUnit)),
-                          aPaperHeight,
-                          GetGTKUnit(mPaperSizeUnit));
-  SaveNewPageSize();
-  return NS_OK;
+    nsPrintSettings::SetUnwriteableMarginBottom(aUnwriteableMarginBottom);
+    SETUNWRITEABLEMARGIN
+    return NS_OK;
 }
 
 NS_IMETHODIMP
-nsPrintSettingsGTK::SetPaperSizeUnit(PRInt16 aPaperSizeUnit)
+nsPrintSettingsQt::SetUnwriteableMarginRight(double aUnwriteableMarginRight)
+{
+    nsPrintSettings::SetUnwriteableMarginRight(aUnwriteableMarginRight);
+    SETUNWRITEABLEMARGIN
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsPrintSettingsQt::GetPaperWidth(double* aPaperWidth)
 {
-  // Convert units internally. e.g. they might have set the values while we're still in mm but
-  // they change to inch just afterwards, expecting that their sizes are in inches.
-  gtk_paper_size_set_size(mPaperSize,
-                          gtk_paper_size_get_width(mPaperSize, GetGTKUnit(mPaperSizeUnit)),
-                          gtk_paper_size_get_height(mPaperSize, GetGTKUnit(mPaperSizeUnit)),
-                          GetGTKUnit(aPaperSizeUnit));
-  SaveNewPageSize();
+    NS_ENSURE_ARG_POINTER(aPaperWidth);
+    QSizeF papersize = mQPrinter->paperSize(GetQtUnit(mPaperSizeUnit));
+    *aPaperWidth = papersize.width();
+    return NS_OK;
+}
 
-  mPaperSizeUnit = aPaperSizeUnit;
-  return NS_OK;
+NS_IMETHODIMP
+nsPrintSettingsQt::SetPaperWidth(double aPaperWidth)
+{
+    QSizeF papersize = mQPrinter->paperSize(GetQtUnit(mPaperSizeUnit));
+    papersize.setWidth(aPaperWidth);
+    mQPrinter->setPaperSize(papersize, GetQtUnit(mPaperSizeUnit));
+    return NS_OK;
 }
 
 NS_IMETHODIMP
-nsPrintSettingsGTK::GetEffectivePageSize(double *aWidth, double *aHeight)
+nsPrintSettingsQt::GetPaperHeight(double* aPaperHeight)
 {
-  *aWidth  = NS_INCHES_TO_INT_TWIPS(gtk_paper_size_get_width(mPaperSize, GTK_UNIT_INCH));
-  *aHeight = NS_INCHES_TO_INT_TWIPS(gtk_paper_size_get_height(mPaperSize, GTK_UNIT_INCH));
-
-  GtkPageOrientation gtkOrient = gtk_page_setup_get_orientation(mPageSetup);
+    NS_ENSURE_ARG_POINTER(aPaperHeight);
+    QSizeF papersize = mQPrinter->paperSize(GetQtUnit(mPaperSizeUnit));
+    *aPaperHeight = papersize.height();
+    return NS_OK;
+}
 
-  if (gtkOrient == GTK_PAGE_ORIENTATION_LANDSCAPE ||
-      gtkOrient == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE) {
-    double temp = *aWidth;
-    *aWidth = *aHeight;
-    *aHeight = temp;
-  }
-  return NS_OK;
+NS_IMETHODIMP
+nsPrintSettingsQt::SetPaperHeight(double aPaperHeight)
+{
+    QSizeF papersize = mQPrinter->paperSize(GetQtUnit(mPaperSizeUnit));
+    papersize.setHeight(aPaperHeight);
+    mQPrinter->setPaperSize(papersize, GetQtUnit(mPaperSizeUnit));
+    return NS_OK;
 }
 
 NS_IMETHODIMP
-nsPrintSettingsGTK::SetupSilentPrinting()
+nsPrintSettingsQt::SetPaperSizeUnit(PRInt16 aPaperSizeUnit)
 {
-  // We have to get a printer here, rather than when the print settings are constructed.
-  // This is because when we request sync, GTK makes us wait in the *event loop* while waiting
-  // for the enumeration to finish. We must do this when event loop runs are expected.
-  gtk_enumerate_printers(printer_enumerator, this, NULL, TRUE);
+    mPaperSizeUnit = aPaperSizeUnit;
+    return NS_OK;
+}
 
-  // XXX If no default printer set, get the first one.
-  if (!GTK_IS_PRINTER(mGTKPrinter))
-    gtk_enumerate_printers(ref_printer, this, NULL, TRUE);
+NS_IMETHODIMP
+nsPrintSettingsQt::GetEffectivePageSize(double* aWidth, double* aHeight)
+{
+    QSizeF papersize = mQPrinter->paperSize(QPrinter::Inch);
+    if (mQPrinter->orientation() == QPrinter::Landscape) {
+        *aWidth  = NS_INCHES_TO_INT_TWIPS(papersize.height());
+        *aHeight = NS_INCHES_TO_INT_TWIPS(papersize.width());
+    } else {
+        *aWidth  = NS_INCHES_TO_INT_TWIPS(papersize.width());
+        *aHeight = NS_INCHES_TO_INT_TWIPS(papersize.height());
+    }
+    return NS_OK;
+}
 
-  return NS_OK;
-}
copy from widget/src/gtk2/nsPrintSettingsGTK.h
copy to widget/src/qt/nsPrintSettingsQt.h
--- a/widget/src/gtk2/nsPrintSettingsGTK.h
+++ b/widget/src/qt/nsPrintSettingsQt.h
@@ -1,9 +1,9 @@
-/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  *
  * ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
@@ -16,159 +16,102 @@
  * The Original Code is the Mozilla browser.
  *
  * The Initial Developer of the Original Code is Mozilla Foundation.
  * Portions created by the Initial Developer are Copyright (C) 2008
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
  *   Michael Ventnor <m.ventnor@gmail.com>
+ *   Florian Hänel <heeen@gmx.de>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either of the GNU General Public License Version 2 or later (the "GPL"),
  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#ifndef nsPrintSettingsGTK_h_
-#define nsPrintSettingsGTK_h_
-
-#include "nsPrintSettingsImpl.h"
+#ifndef nsPrintSettingsQt_h_
+#define nsPrintSettingsQt_h_
 
-extern "C" {
-#include <gtk/gtk.h>
-#include <gtk/gtkprinter.h>
-#include <gtk/gtkprintjob.h>
-}
+#include <QSharedPointer>
+#include "nsPrintSettingsImpl.h"
+#define NS_PRINTSETTINGSQT_IID \
+{0x5bc4c746, 0x8970, 0x43a3, {0xbf, 0xb1, 0x5d, 0xe1, 0x74, 0xaf, 0x7c, 0xea}}
 
-#define NS_PRINTSETTINGSGTK_IID \
-{ 0x758df520, 0xc7c3, 0x11dc, { 0x95, 0xff, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 } }
- 
-
-//*****************************************************************************
-//***    nsPrintSettingsGTK
-//*****************************************************************************
-
-class nsPrintSettingsGTK : public nsPrintSettings
+class QPrinter;
+class nsPrintSettingsQt : public nsPrintSettings
 {
 public:
-  NS_DECL_ISUPPORTS_INHERITED
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_PRINTSETTINGSGTK_IID)
-
-  nsPrintSettingsGTK();
-  virtual ~nsPrintSettingsGTK();
+    NS_DECL_ISUPPORTS_INHERITED
+        NS_DECLARE_STATIC_IID_ACCESSOR(NS_PRINTSETTINGSQT_IID)
 
-  // We're overriding these methods because we want to read/write with GTK objects,
-  // not local variables. This allows a simpler settings implementation between
-  // Gecko and GTK.
+    nsPrintSettingsQt();
+    virtual ~nsPrintSettingsQt();
 
-  GtkPageSetup* GetGtkPageSetup() { return mPageSetup; };
-  void SetGtkPageSetup(GtkPageSetup *aPageSetup);
-
-  GtkPrintSettings* GetGtkPrintSettings() { return mPrintSettings; };
-  void SetGtkPrintSettings(GtkPrintSettings *aPrintSettings);
-
-  GtkPrinter* GetGtkPrinter() { return mGTKPrinter; };
-  void SetGtkPrinter(GtkPrinter *aPrinter);
+    NS_IMETHOD GetPrintRange(PRInt16* aPrintRange);
+    NS_IMETHOD SetPrintRange(PRInt16 aPrintRange);
 
-  PRBool GetForcePrintSelectionOnly() { return mPrintSelectionOnly; };
-  void SetForcePrintSelectionOnly(PRBool aPrintSelectionOnly) { mPrintSelectionOnly = aPrintSelectionOnly; };
+    NS_IMETHOD GetStartPageRange(PRInt32* aStartPageRange);
+    NS_IMETHOD SetStartPageRange(PRInt32 aStartPageRange);
+    NS_IMETHOD GetEndPageRange(PRInt32* aEndPageRange);
+    NS_IMETHOD SetEndPageRange(PRInt32 aEndPageRange);
 
-  // If not printing the selection, this is stored in the GtkPrintSettings. Printing the
-  // selection is stored as a protected boolean (mPrintSelectionOnly).
-  NS_IMETHOD GetPrintRange(PRInt16 *aPrintRange);
-  NS_IMETHOD SetPrintRange(PRInt16 aPrintRange);
+    NS_IMETHOD GetPrintReversed(PRBool* aPrintReversed);
+    NS_IMETHOD SetPrintReversed(PRBool aPrintReversed);
 
-  // The page range is stored as as single range in the GtkPrintSettings object.
-  NS_IMETHOD GetStartPageRange(PRInt32 *aStartPageRange);
-  NS_IMETHOD SetStartPageRange(PRInt32 aStartPageRange);
-  NS_IMETHOD GetEndPageRange(PRInt32 *aEndPageRange);
-  NS_IMETHOD SetEndPageRange(PRInt32 aEndPageRange);
+    NS_IMETHOD GetPrintInColor(PRBool* aPrintInColor);
+    NS_IMETHOD SetPrintInColor(PRBool aPrintInColor);
 
-  // Reversed, color, orientation and file name are all stored in the GtkPrintSettings.
-  // Orientation is also stored in the GtkPageSetup and its setting takes priority when getting the orientation.
-  NS_IMETHOD GetPrintReversed(PRBool *aPrintReversed);
-  NS_IMETHOD SetPrintReversed(PRBool aPrintReversed);
+    NS_IMETHOD GetOrientation(PRInt32* aOrientation);
+    NS_IMETHOD SetOrientation(PRInt32 aOrientation);
+
+    NS_IMETHOD GetToFileName(PRUnichar** aToFileName);
+    NS_IMETHOD SetToFileName(const PRUnichar* aToFileName);
 
-  NS_IMETHOD GetPrintInColor(PRBool *aPrintInColor);
-  NS_IMETHOD SetPrintInColor(PRBool aPrintInColor);
+    NS_IMETHOD GetPrinterName(PRUnichar** aPrinter);
+    NS_IMETHOD SetPrinterName(const PRUnichar* aPrinter);
 
-  NS_IMETHOD GetOrientation(PRInt32 *aOrientation);
-  NS_IMETHOD SetOrientation(PRInt32 aOrientation);
-
-  NS_IMETHOD GetToFileName(PRUnichar * *aToFileName);
-  NS_IMETHOD SetToFileName(const PRUnichar * aToFileName);
+    NS_IMETHOD GetNumCopies(PRInt32* aNumCopies);
+    NS_IMETHOD SetNumCopies(PRInt32 aNumCopies);
 
-  // Gets/Sets the printer name in the GtkPrintSettings. If no printer name is specified there,
-  // you will get back the name of the current internal GtkPrinter.
-  NS_IMETHOD GetPrinterName(PRUnichar * *aPrinter);
-  NS_IMETHOD SetPrinterName(const PRUnichar * aPrinter);
+    NS_IMETHOD GetScaling(double* aScaling);
+    NS_IMETHOD SetScaling(double aScaling);
 
-  // Number of copies is stored/gotten from the GtkPrintSettings.
-  NS_IMETHOD GetNumCopies(PRInt32 *aNumCopies);
-  NS_IMETHOD SetNumCopies(PRInt32 aNumCopies);
-
-  NS_IMETHOD GetScaling(double *aScaling);
-  NS_IMETHOD SetScaling(double aScaling);
+    NS_IMETHOD GetPaperName(PRUnichar** aPaperName);
+    NS_IMETHOD SetPaperName(const PRUnichar* aPaperName);
 
-  // A name recognised by GTK is strongly advised here, as this is used to create a GtkPaperSize.
-  NS_IMETHOD GetPaperName(PRUnichar * *aPaperName);
-  NS_IMETHOD SetPaperName(const PRUnichar * aPaperName);
-
-  NS_IMETHOD SetUnwriteableMarginInTwips(nsIntMargin& aUnwriteableMargin);
-  NS_IMETHOD SetUnwriteableMarginTop(double aUnwriteableMarginTop);
-  NS_IMETHOD SetUnwriteableMarginLeft(double aUnwriteableMarginLeft);
-  NS_IMETHOD SetUnwriteableMarginBottom(double aUnwriteableMarginBottom);
-  NS_IMETHOD SetUnwriteableMarginRight(double aUnwriteableMarginRight);
+    NS_IMETHOD SetUnwriteableMarginInTwips(nsIntMargin& aUnwriteableMargin);
+    NS_IMETHOD SetUnwriteableMarginTop(double aUnwriteableMarginTop);
+    NS_IMETHOD SetUnwriteableMarginLeft(double aUnwriteableMarginLeft);
+    NS_IMETHOD SetUnwriteableMarginBottom(double aUnwriteableMarginBottom);
+    NS_IMETHOD SetUnwriteableMarginRight(double aUnwriteableMarginRight);
 
-  NS_IMETHOD GetPaperWidth(double *aPaperWidth);
-  NS_IMETHOD SetPaperWidth(double aPaperWidth);
-
-  NS_IMETHOD GetPaperHeight(double *aPaperHeight);
-  NS_IMETHOD SetPaperHeight(double aPaperHeight);
+    NS_IMETHOD GetPaperWidth(double* aPaperWidth);
+    NS_IMETHOD SetPaperWidth(double aPaperWidth);
 
-  NS_IMETHOD SetPaperSizeUnit(PRInt16 aPaperSizeUnit);
+    NS_IMETHOD GetPaperHeight(double* aPaperHeight);
+    NS_IMETHOD SetPaperHeight(double aPaperHeight);
 
-  NS_IMETHOD GetEffectivePageSize(double *aWidth, double *aHeight);
+    NS_IMETHOD SetPaperSizeUnit(PRInt16 aPaperSizeUnit);
 
-  NS_IMETHOD SetupSilentPrinting();
+    NS_IMETHOD GetEffectivePageSize(double* aWidth, double* aHeight);
 
 protected:
-  nsPrintSettingsGTK(const nsPrintSettingsGTK& src);
-  nsPrintSettingsGTK& operator=(const nsPrintSettingsGTK& rhs);
-
-  virtual nsresult _Clone(nsIPrintSettings **_retval);
-  virtual nsresult _Assign(nsIPrintSettings *aPS);
-
-  GtkUnit GetGTKUnit(PRInt16 aGeckoUnit);
-  void SaveNewPageSize();
+    nsPrintSettingsQt(const nsPrintSettingsQt& src);
+    nsPrintSettingsQt& operator=(const nsPrintSettingsQt& rhs);
 
-  /**
-   * Re-initialize mUnwriteableMargin with values from mPageSetup.
-   * Should be called whenever mPageSetup is initialized or overwritten.
-   */
-  void InitUnwriteableMargin();
+    virtual nsresult _Clone(nsIPrintSettings** _retval);
+    virtual nsresult _Assign(nsIPrintSettings* aPS);
 
-  /**
-   * On construction:
-   * - mPrintSettings, mPageSetup and mPaperSize are just new objects with defaults determined by GTK.
-   * - mGTKPrinter is NULL!!! Remember to be careful when accessing this property.
-   */
-  GtkPageSetup* mPageSetup;
-  GtkPrintSettings* mPrintSettings;
-  GtkPrinter* mGTKPrinter;
-  GtkPaperSize* mPaperSize;
-
-  PRBool mPrintSelectionOnly;
+    QSharedPointer<QPrinter> mQPrinter;
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsPrintSettingsGTK, NS_PRINTSETTINGSGTK_IID)
-
-
-#endif // nsPrintSettingsGTK_h_
+NS_DEFINE_STATIC_IID_ACCESSOR(nsPrintSettingsQt, NS_PRINTSETTINGSQT_IID)
+#endif // nsPrintSettingsQt_h_
--- a/widget/src/qt/nsWidgetFactory.cpp
+++ b/widget/src/qt/nsWidgetFactory.cpp
@@ -56,17 +56,22 @@
 #include "nsFilePicker.h"
 #include "nsClipboard.h"
 #include "nsClipboardHelper.h"
 #include "nsIdleServiceQt.h"
 #include "nsDragService.h"
 #include "nsSound.h"
 #include "nsBidiKeyboard.h"
 #include "nsNativeThemeQt.h"
-
+#ifdef NS_PRINTING
+#include "nsDeviceContextSpecQt.h"
+#include "nsPrintSession.h"
+#include "nsPrintOptionsQt.h"
+#include "nsPrintDialogQt.h"
+#endif
 // from nsWindow.cpp
 extern PRBool gDisableNativeTheme;
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindow)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsChildWindow)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsPopupWindow)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter)
@@ -76,16 +81,24 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenM
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsIdleServiceQt)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePicker)
 
+#ifdef NS_PRINTING
+NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecQt)
+NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintOptionsQt, Init)
+NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrinterEnumeratorQt)
+NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintSession, Init)
+NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintDialogServiceQt, Init)
+#endif
+
 static nsresult
 nsNativeThemeQtConstructor(nsISupports *aOuter, REFNSIID aIID,
                             void **aResult)
 {
     nsresult rv;
     nsNativeThemeQt *inst;
 
     if (gDisableNativeTheme)
@@ -118,16 +131,23 @@ NS_DEFINE_NAMED_CID(NS_CLIPBOARDHELPER_C
 NS_DEFINE_NAMED_CID(NS_DRAGSERVICE_CID);
 NS_DEFINE_NAMED_CID(NS_HTMLFORMATCONVERTER_CID);
 NS_DEFINE_NAMED_CID(NS_BIDIKEYBOARD_CID);
 NS_DEFINE_NAMED_CID(NS_SCREENMANAGER_CID);
 NS_DEFINE_NAMED_CID(NS_THEMERENDERER_CID);
 NS_DEFINE_NAMED_CID(NS_IDLE_SERVICE_CID);
 NS_DEFINE_NAMED_CID(NS_POPUP_CID);
 NS_DEFINE_NAMED_CID(NS_TOOLKIT_CID);
+#ifdef NS_PRINTING
+NS_DEFINE_NAMED_CID(NS_PRINTSETTINGSSERVICE_CID);
+NS_DEFINE_NAMED_CID(NS_PRINTER_ENUMERATOR_CID);
+NS_DEFINE_NAMED_CID(NS_PRINTSESSION_CID);
+NS_DEFINE_NAMED_CID(NS_DEVICE_CONTEXT_SPEC_CID);
+NS_DEFINE_NAMED_CID(NS_PRINTDIALOGSERVICE_CID);
+#endif 
 
 static const mozilla::Module::CIDEntry kWidgetCIDs[] = {
     { &kNS_WINDOW_CID, false, NULL, nsWindowConstructor },
     { &kNS_CHILD_CID, false, NULL, nsChildWindowConstructor },
     { &kNS_APPSHELL_CID, false, NULL, nsAppShellConstructor },
     { &kNS_LOOKANDFEEL_CID, false, NULL, nsLookAndFeelConstructor },
     { &kNS_FILEPICKER_CID, false, NULL, nsFilePickerConstructor },
     { &kNS_SOUND_CID, false, NULL, nsSoundConstructor },
@@ -137,16 +157,23 @@ static const mozilla::Module::CIDEntry k
     { &kNS_DRAGSERVICE_CID, false, NULL, nsDragServiceConstructor },
     { &kNS_HTMLFORMATCONVERTER_CID, false, NULL, nsHTMLFormatConverterConstructor },
     { &kNS_BIDIKEYBOARD_CID, false, NULL, nsBidiKeyboardConstructor },
     { &kNS_SCREENMANAGER_CID, false, NULL, nsScreenManagerQtConstructor },
     { &kNS_THEMERENDERER_CID, false, NULL, nsNativeThemeQtConstructor },
     { &kNS_IDLE_SERVICE_CID, false, NULL, nsIdleServiceQtConstructor },
     { &kNS_POPUP_CID, false, NULL, nsPopupWindowConstructor },
     { &kNS_TOOLKIT_CID, false, NULL, nsToolkitConstructor },
+#ifdef NS_PRINTING
+    { &kNS_PRINTSETTINGSSERVICE_CID, false, NULL, nsPrintOptionsQtConstructor },
+    { &kNS_PRINTER_ENUMERATOR_CID, false, NULL, nsPrinterEnumeratorQtConstructor },
+    { &kNS_PRINTSESSION_CID, false, NULL, nsPrintSessionConstructor },
+    { &kNS_DEVICE_CONTEXT_SPEC_CID, false, NULL, nsDeviceContextSpecQtConstructor },
+    { &kNS_PRINTDIALOGSERVICE_CID, false, NULL, nsPrintDialogServiceQtConstructor },
+#endif 
     { NULL }
 };
 
 static const mozilla::Module::ContractIDEntry kWidgetContracts[] = {
     { "@mozilla.org/widget/window/qt;1", &kNS_WINDOW_CID },
     { "@mozilla.org/widgets/child_window/qt;1", &kNS_CHILD_CID },
     { "@mozilla.org/widget/appshell/qt;1", &kNS_APPSHELL_CID },
     { "@mozilla.org/widget/lookandfeel;1", &kNS_LOOKANDFEEL_CID },
@@ -158,16 +185,23 @@ static const mozilla::Module::ContractID
     { "@mozilla.org/widget/dragservice;1", &kNS_DRAGSERVICE_CID },
     { "@mozilla.org/widget/htmlformatconverter;1", &kNS_HTMLFORMATCONVERTER_CID },
     { "@mozilla.org/widget/bidikeyboard;1", &kNS_BIDIKEYBOARD_CID },
     { "@mozilla.org/gfx/screenmanager;1", &kNS_SCREENMANAGER_CID },
     { "@mozilla.org/chrome/chrome-native-theme;1", &kNS_THEMERENDERER_CID },
     { "@mozilla.org/widget/idleservice;1", &kNS_IDLE_SERVICE_CID },
     { "@mozilla.org/widgets/popup_window/qt;1", &kNS_POPUP_CID },
     { "@mozilla.org/widget/toolkit/qt;1", &kNS_TOOLKIT_CID },
+#ifdef NS_PRINTING
+    { "@mozilla.org/gfx/printsettings-service;1", &kNS_PRINTSETTINGSSERVICE_CID },
+    { "@mozilla.org/gfx/printerenumerator;1", &kNS_PRINTER_ENUMERATOR_CID },
+    { "@mozilla.org/gfx/printsession;1", &kNS_PRINTSESSION_CID },
+    { "@mozilla.org/gfx/devicecontextspec;1", &kNS_DEVICE_CONTEXT_SPEC_CID },
+    { NS_PRINTDIALOGSERVICE_CONTRACTID, &kNS_PRINTDIALOGSERVICE_CID },
+#endif 
     { NULL }
 };
 
 static void
 nsWidgetQtModuleDtor()
 {
     nsSound::Shutdown();
     nsWindow::ReleaseGlobals();