Bug 539427 - Save print resolution (DPI) and duplex settings between print jobs, if they're available. r=roc, sr=smaug
authorJan Horak <jhorak@redhat.com>
Thu, 11 Apr 2013 09:10:42 -0400
changeset 140221 2bb26d742f5ffd2d946291fd3c688dc3d6d34f67
parent 140220 bfcd471a1ed9d6237a6a0af369a4d85e1cdbd9c1
child 140222 85f1d207f52546e0e5fe78990cdefe6efae485fb
push id350
push userbbajaj@mozilla.com
push dateMon, 29 Jul 2013 23:00:49 +0000
treeherdermozilla-release@064965b37dbd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, smaug
bugs539427
milestone23.0a1
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 539427 - Save print resolution (DPI) and duplex settings between print jobs, if they're available. r=roc, sr=smaug
widget/gtk2/nsPrintSettingsGTK.cpp
widget/gtk2/nsPrintSettingsGTK.h
widget/nsIPrintSettings.idl
widget/xpwidgets/nsPrintOptionsImpl.cpp
widget/xpwidgets/nsPrintSettingsImpl.cpp
widget/xpwidgets/nsPrintSettingsImpl.h
--- a/widget/gtk2/nsPrintSettingsGTK.cpp
+++ b/widget/gtk2/nsPrintSettingsGTK.cpp
@@ -733,8 +733,43 @@ nsPrintSettingsGTK::GetPageRanges(nsTArr
       aPages.AppendElement(lstRanges[i].end+1);
     }
   }
 
   g_free(lstRanges);
   return NS_OK;
 }
 
+NS_IMETHODIMP
+nsPrintSettingsGTK::GetResolution(int32_t *aResolution)
+{
+  if (!gtk_print_settings_has_key(mPrintSettings, GTK_PRINT_SETTINGS_RESOLUTION))
+    return NS_ERROR_FAILURE;
+  *aResolution = gtk_print_settings_get_resolution(mPrintSettings);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsPrintSettingsGTK::SetResolution(int32_t aResolution)
+{
+  gtk_print_settings_set_resolution(mPrintSettings, aResolution);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsPrintSettingsGTK::GetDuplex(int32_t *aDuplex)
+{
+  if (!gtk_print_settings_has_key(mPrintSettings, GTK_PRINT_SETTINGS_DUPLEX))
+    return NS_ERROR_FAILURE;
+  *aDuplex = gtk_print_settings_get_duplex(mPrintSettings);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsPrintSettingsGTK::SetDuplex(int32_t aDuplex)
+{
+  MOZ_ASSERT(aDuplex >= GTK_PRINT_DUPLEX_SIMPLEX &&
+             aDuplex <= GTK_PRINT_DUPLEX_VERTICAL,
+             "value is out of bounds for GtkPrintDuplex enum");
+  gtk_print_settings_set_duplex(mPrintSettings, static_cast<GtkPrintDuplex>(aDuplex));
+  return NS_OK;
+}
+
--- a/widget/gtk2/nsPrintSettingsGTK.h
+++ b/widget/gtk2/nsPrintSettingsGTK.h
@@ -108,16 +108,22 @@ public:
   NS_IMETHOD SetPaperSizeUnit(int16_t aPaperSizeUnit);
 
   NS_IMETHOD GetEffectivePageSize(double *aWidth, double *aHeight);
 
   NS_IMETHOD SetupSilentPrinting();
 
   NS_IMETHOD GetPageRanges(nsTArray<int32_t> &aPages);
 
+  NS_IMETHOD GetResolution(int32_t *aResolution);
+  NS_IMETHOD SetResolution(int32_t aResolution);
+
+  NS_IMETHOD GetDuplex(int32_t *aDuplex);
+  NS_IMETHOD SetDuplex(int32_t aDuplex);
+
 protected:
   nsPrintSettingsGTK(const nsPrintSettingsGTK& src);
   nsPrintSettingsGTK& operator=(const nsPrintSettingsGTK& rhs);
 
   virtual nsresult _Clone(nsIPrintSettings **_retval);
   virtual nsresult _Assign(nsIPrintSettings *aPS);
 
   GtkUnit GetGTKUnit(int16_t aGeckoUnit);
--- a/widget/nsIPrintSettings.idl
+++ b/widget/nsIPrintSettings.idl
@@ -17,35 +17,35 @@
   [ref] native nsNativeIntMarginRef(nsIntMargin);
   [ref] native IntegerArray(nsTArray<int32_t>);
   
 interface nsIPrintSession;
 
 /**
  * Simplified graphics interface for JS rendering.
  */
-[scriptable, uuid(a65cfa37-b381-4fe9-81b7-db08853f54ad)]
+[scriptable, uuid(1bcfc611-8941-4c39-9e06-7116e564a1ce)]
 
 interface nsIPrintSettings : nsISupports
 {
   /**
    * PrintSettings to be Saved Navigation Constants
    */
   const unsigned long kInitSaveOddEvenPages   = 0x00000001;
   const unsigned long kInitSaveHeaderLeft     = 0x00000002;
   const unsigned long kInitSaveHeaderCenter   = 0x00000004;
   const unsigned long kInitSaveHeaderRight    = 0x00000008;
   const unsigned long kInitSaveFooterLeft     = 0x00000010;
   const unsigned long kInitSaveFooterCenter   = 0x00000020;
   const unsigned long kInitSaveFooterRight    = 0x00000040;
   const unsigned long kInitSaveBGColors       = 0x00000080;
   const unsigned long kInitSaveBGImages       = 0x00000100;
   const unsigned long kInitSavePaperSize      = 0x00000200;
-  /* Flag 0x00000400 is unused */
-  /* Flag 0x00000800 is unused */
+  const unsigned long kInitSaveResolution     = 0x00000400;
+  const unsigned long kInitSaveDuplex         = 0x00000800;
   /* Flag 0x00001000 is unused */
   const unsigned long kInitSavePaperData      = 0x00002000;
   const unsigned long kInitSaveUnwriteableMargins = 0x00004000;
   const unsigned long kInitSaveEdges          = 0x00008000;
 
   const unsigned long kInitSaveReversed       = 0x00010000;
   const unsigned long kInitSaveInColor        = 0x00020000;
   const unsigned long kInitSaveOrientation    = 0x00040000;
@@ -243,17 +243,21 @@ interface nsIPrintSettings : nsISupports
 
   attribute wstring printerName;   /* name of destination printer */
 
   attribute boolean printToFile;
   attribute wstring toFileName;
   attribute short   outputFormat;
 
   attribute long    printPageDelay; /* in milliseconds */
-  
+
+  attribute long    resolution;     /* print resolution (dpi) */
+
+  attribute long    duplex;         /* duplex mode */
+
   /* initialize helpers */
   /**
    * This attribute tracks whether the PS has been initialized 
    * from a printer specified by the "printerName" attr. 
    * If a different name is set into the "printerName" 
    * attribute than the one it was initialized with the PS
    * will then get intialized from that printer.
    */
--- a/widget/xpwidgets/nsPrintOptionsImpl.cpp
+++ b/widget/xpwidgets/nsPrintOptionsImpl.cpp
@@ -69,16 +69,18 @@ static const char kPrintCommand[]       
 static const char kPrinterName[]        = "print_printer";
 static const char kPrintToFile[]        = "print_to_file";
 static const char kPrintToFileName[]    = "print_to_filename";
 static const char kPrintPageDelay[]     = "print_page_delay";
 static const char kPrintBGColors[]      = "print_bgcolor";
 static const char kPrintBGImages[]      = "print_bgimages";
 static const char kPrintShrinkToFit[]   = "print_shrink_to_fit";
 static const char kPrintScaling[]       = "print_scaling";
+static const char kPrintResolution[]    = "print_resolution";
+static const char kPrintDuplex[]        = "print_duplex";
 
 static const char kJustLeft[]   = "left";
 static const char kJustCenter[] = "center";
 static const char kJustRight[]  = "right";
 
 #define NS_PRINTER_ENUMERATOR_CONTRACTID "@mozilla.org/gfx/printerenumerator;1"
 
 nsPrintOptions::nsPrintOptions()
@@ -488,16 +490,30 @@ nsPrintOptions::ReadPrefs(nsIPrintSettin
 
   if (aFlags & nsIPrintSettings::kInitSaveScaling) {
     if (GETDBLPREF(kPrintScaling, dbl)) {
       aPS->SetScaling(dbl);
       DUMP_DBL(kReadStr, kPrintScaling, dbl);
     }
   }
 
+  if (aFlags & nsIPrintSettings::kInitSaveResolution) {
+    if (GETINTPREF(kPrintResolution, &iVal)) {
+      aPS->SetResolution(iVal);
+      DUMP_INT(kReadStr, kPrintResolution, iVal);
+    }
+  }
+
+  if (aFlags & nsIPrintSettings::kInitSaveDuplex) {
+    if (GETINTPREF(kPrintDuplex, &iVal)) {
+      aPS->SetDuplex(iVal);
+      DUMP_INT(kReadStr, kPrintDuplex, iVal);
+    }
+  }
+
   // Not Reading In:
   //   Number of Copies
 
   return NS_OK;
 }
 
 /** ---------------------------------------------------
  *  See documentation in nsPrintOptionsImpl.h
@@ -784,16 +800,30 @@ nsPrintOptions::WritePrefs(nsIPrintSetti
 
   if (aFlags & nsIPrintSettings::kInitSaveScaling) {
     if (NS_SUCCEEDED(aPS->GetScaling(&dbl))) {
       DUMP_DBL(kWriteStr, kPrintScaling, dbl);
       WritePrefDouble(GetPrefName(kPrintScaling, aPrinterName), dbl);
     }
   }
 
+  if (aFlags & nsIPrintSettings::kInitSaveResolution) {
+    if (NS_SUCCEEDED(aPS->GetResolution(&iVal))) {
+      DUMP_INT(kWriteStr, kPrintResolution, iVal);
+      Preferences::SetInt(GetPrefName(kPrintResolution, aPrinterName), iVal);
+    }
+  }
+
+  if (aFlags & nsIPrintSettings::kInitSaveDuplex) {
+    if (NS_SUCCEEDED(aPS->GetDuplex(&iVal))) {
+      DUMP_INT(kWriteStr, kPrintDuplex, iVal);
+      Preferences::SetInt(GetPrefName(kPrintDuplex, aPrinterName), iVal);
+    }
+  }
+
   // Not Writing Out:
   //   Number of Copies
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsPrintOptions::DisplayJobProperties(const PRUnichar *aPrinter,
--- a/widget/xpwidgets/nsPrintSettingsImpl.cpp
+++ b/widget/xpwidgets/nsPrintSettingsImpl.cpp
@@ -213,16 +213,42 @@ NS_IMETHODIMP nsPrintSettings::SetResolu
   if (aResolutionName) {
     mResolutionName = aResolutionName;
   } else {
     mResolutionName.SetLength(0);
   }
   return NS_OK;
 }
 
+/* attribute wstring resolution; */
+NS_IMETHODIMP nsPrintSettings::GetResolution(int32_t *aResolution)
+{
+  NS_ENSURE_ARG_POINTER(aResolution);
+  *aResolution = mResolution;
+  return NS_OK;
+}
+NS_IMETHODIMP nsPrintSettings::SetResolution(const int32_t aResolution)
+{
+  mResolution = aResolution;
+  return NS_OK;
+}
+
+/* attribute wstring duplex; */
+NS_IMETHODIMP nsPrintSettings::GetDuplex(int32_t *aDuplex)
+{
+  NS_ENSURE_ARG_POINTER(aDuplex);
+  *aDuplex = mDuplex;
+  return NS_OK;
+}
+NS_IMETHODIMP nsPrintSettings::SetDuplex(const int32_t aDuplex)
+{
+  mDuplex = aDuplex;
+  return NS_OK;
+}
+
 /* attribute boolean downloadFonts; */
 NS_IMETHODIMP nsPrintSettings::GetDownloadFonts(bool *aDownloadFonts)
 {
   //NS_ENSURE_ARG_POINTER(aDownloadFonts);
   *aDownloadFonts = mDownloadFonts;
   return NS_OK;
 }
 NS_IMETHODIMP nsPrintSettings::SetDownloadFonts(bool aDownloadFonts)
--- a/widget/xpwidgets/nsPrintSettingsImpl.h
+++ b/widget/xpwidgets/nsPrintSettingsImpl.h
@@ -87,16 +87,18 @@ protected:
   double        mPaperHeight;
   int16_t       mPaperSizeUnit;
 
   bool          mPrintReversed;
   bool          mPrintInColor; // a false means grayscale
   int32_t       mOrientation;  // see orientation consts
   nsString      mColorspace;
   nsString      mResolutionName;
+  int32_t       mResolution;
+  int32_t       mDuplex;
   bool          mDownloadFonts;
   nsString      mPrintCommand;
   int32_t       mNumCopies;
   nsXPIDLString mPrinter;
   bool          mPrintToFile;
   nsString      mToFileName;
   int16_t       mOutputFormat;
   bool          mIsInitedFromPrinter;