toolkit/components/printing/content/printjoboptions.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 // -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 var dialog;
     8 var gPrintBundle;
     9 var gPrintSettings = null;
    10 var gPrintSettingsInterface  = Components.interfaces.nsIPrintSettings;
    11 var gPaperArray;
    12 var gPlexArray;
    13 var gResolutionArray;
    14 var gColorSpaceArray;
    15 var gPrefs;
    17 var default_command    = "lpr";
    18 var gPrintSetInterface = Components.interfaces.nsIPrintSettings;
    19 var doDebug            = true;
    21 //---------------------------------------------------
    22 function checkDouble(element, maxVal)
    23 {
    24   var value = element.value;
    25   if (value && value.length > 0) {
    26     value = value.replace(/[^\.|^0-9]/g,"");
    27     if (!value) {
    28       element.value = "";
    29     } else {
    30       if (value > maxVal) {
    31         element.value = maxVal;
    32       } else {
    33         element.value = value;
    34       }
    35     }
    36   }
    37 }
    39 //---------------------------------------------------
    40 function isListOfPrinterFeaturesAvailable()
    41 {
    42   var has_printerfeatures = false;
    44   try {
    45     has_printerfeatures = gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".has_special_printerfeatures");
    46   } catch(ex) {
    47   }
    49   return has_printerfeatures;
    50 }
    52 //---------------------------------------------------
    53 function getDoubleStr(val, dec)
    54 {
    55   var str = val.toString();
    56   var inx = str.indexOf(".");
    57   return str.substring(0, inx+dec+1);
    58 }
    60 //---------------------------------------------------
    61 function initDialog()
    62 {
    63   gPrintBundle = document.getElementById("printBundle");
    65   dialog = new Object;
    67   dialog.paperList       = document.getElementById("paperList");
    68   dialog.paperGroup      = document.getElementById("paperGroup");
    70   dialog.plexList        = document.getElementById("plexList");
    71   dialog.plexGroup       = document.getElementById("plexGroup");
    73   dialog.resolutionList  = document.getElementById("resolutionList");
    74   dialog.resolutionGroup = document.getElementById("resolutionGroup");
    76   dialog.jobTitleLabel   = document.getElementById("jobTitleLabel");
    77   dialog.jobTitleGroup   = document.getElementById("jobTitleGroup");
    78   dialog.jobTitleInput   = document.getElementById("jobTitleInput");
    80   dialog.cmdLabel        = document.getElementById("cmdLabel");
    81   dialog.cmdGroup        = document.getElementById("cmdGroup");
    82   dialog.cmdInput        = document.getElementById("cmdInput");
    84   dialog.colorspaceList  = document.getElementById("colorspaceList");
    85   dialog.colorspaceGroup = document.getElementById("colorspaceGroup");
    87   dialog.colorGroup      = document.getElementById("colorGroup");
    88   dialog.colorRadioGroup = document.getElementById("colorRadioGroup");
    89   dialog.colorRadio      = document.getElementById("colorRadio");
    90   dialog.grayRadio       = document.getElementById("grayRadio");
    92   dialog.fontsGroup      = document.getElementById("fontsGroup");
    93   dialog.downloadFonts   = document.getElementById("downloadFonts");
    95   dialog.topInput        = document.getElementById("topInput");
    96   dialog.bottomInput     = document.getElementById("bottomInput");
    97   dialog.leftInput       = document.getElementById("leftInput");
    98   dialog.rightInput      = document.getElementById("rightInput");
    99 }
   101 //---------------------------------------------------
   102 function round10(val)
   103 {
   104   return Math.round(val * 10) / 10;
   105 }
   108 //---------------------------------------------------
   109 function paperListElement(aPaperListElement)
   110   {
   111     this.paperListElement = aPaperListElement;
   112   }
   114 paperListElement.prototype =
   115   {
   116     clearPaperList:
   117       function ()
   118         {
   119           // remove the menupopup node child of the menulist.
   120           this.paperListElement.removeChild(this.paperListElement.firstChild);
   121         },
   123     appendPaperNames: 
   124       function (aDataObject) 
   125         { 
   126           var popupNode = document.createElement("menupopup"); 
   127           for (var i=0;i<aDataObject.length;i++)  {
   128             var paperObj = aDataObject[i];
   129             var itemNode = document.createElement("menuitem");
   130             var label;
   131             try {
   132               label = gPrintBundle.getString(paperObj.name);
   133             } 
   134             catch (e) {
   135               /* No name in string bundle ? Then build one manually (this
   136                * usually happens when gPaperArray was build by createPaperArrayFromPrinterFeatures() ...) */              
   137               if (paperObj.inches) {
   138                 label = paperObj.name + " (" + round10(paperObj.width) + "x" + round10(paperObj.height) + " inch)";
   139               }  
   140               else {
   141                 label = paperObj.name + " (" + paperObj.width + "x" + paperObj.height + " mm)";
   142               }
   143             }
   144             itemNode.setAttribute("label", label);
   145             itemNode.setAttribute("value", i);
   146             popupNode.appendChild(itemNode);            
   147           }
   148           this.paperListElement.appendChild(popupNode); 
   149         } 
   150   };
   152 //---------------------------------------------------
   153 function createPaperArrayFromDefaults()
   154 {
   155   var paperNames   = ["letterSize", "legalSize", "exectiveSize", "a5Size", "a4Size", "a3Size", "a2Size", "a1Size", "a0Size"];
   156   //var paperNames   = ["&letterRadio.label;", "&legalRadio.label;", "&exectiveRadio.label;", "&a4Radio.label;", "&a3Radio.label;"];
   157   var paperWidths  = [ 8.5,  8.5,  7.25, 148.0, 210.0, 287.0, 420.0, 594.0,  841.0];
   158   var paperHeights = [11.0, 14.0, 10.50, 210.0, 297.0, 420.0, 594.0, 841.0, 1189.0];
   159   var paperInches  = [true, true, true,  false, false, false, false, false, false];
   160   // this is deprecated
   161   var paperEnums  = [0, 1, 2, 3, 4, 5, 6, 7, 8];
   163   gPaperArray = new Array();
   165   for (var i=0;i<paperNames.length;i++) {
   166     var obj    = new Object();
   167     obj.name   = paperNames[i];
   168     obj.width  = paperWidths[i];
   169     obj.height = paperHeights[i];
   170     obj.inches = paperInches[i];
   172     /* Calculate the width/height in millimeters */
   173     if (paperInches[i]) {
   174       obj.width_mm  = paperWidths[i]  * 25.4;
   175       obj.height_mm = paperHeights[i] * 25.4; 
   176     }
   177     else {
   178       obj.width_mm  = paperWidths[i];
   179       obj.height_mm = paperHeights[i];        
   180     }
   181     gPaperArray[i] = obj;
   182   }
   183 }
   185 //---------------------------------------------------
   186 function createPaperArrayFromPrinterFeatures()
   187 {
   188   var printername = gPrintSettings.printerName;
   189   if (doDebug) {
   190     dump("createPaperArrayFromPrinterFeatures for " + printername + ".\n");
   191   }
   193   gPaperArray = new Array();
   195   var numPapers = gPrefs.getIntPref("print.tmp.printerfeatures." + printername + ".paper.count");
   197   if (doDebug) {
   198     dump("processing " + numPapers + " entries...\n");
   199   }    
   201   for (var i=0;i<numPapers;i++) {
   202     var obj    = new Object();
   203     obj.name      = gPrefs.getCharPref("print.tmp.printerfeatures." + printername + ".paper." + i + ".name");
   204     obj.width_mm  = gPrefs.getIntPref("print.tmp.printerfeatures."  + printername + ".paper." + i + ".width_mm");
   205     obj.height_mm = gPrefs.getIntPref("print.tmp.printerfeatures."  + printername + ".paper." + i + ".height_mm");
   206     obj.inches    = gPrefs.getBoolPref("print.tmp.printerfeatures." + printername + ".paper." + i + ".is_inch");
   208     /* Calculate the width/height in paper's native units (either inches or millimeters) */
   209     if (obj.inches) {
   210       obj.width  = obj.width_mm  / 25.4;
   211       obj.height = obj.height_mm / 25.4; 
   212     }
   213     else {
   214       obj.width  = obj.width_mm;
   215       obj.height = obj.height_mm;
   216     }
   218     gPaperArray[i] = obj;
   220     if (doDebug) {
   221       dump("paper index=" + i + ", name=" + obj.name + ", width=" + obj.width + ", height=" + obj.height + ".\n");
   222     }
   223   }  
   224 }
   226 //---------------------------------------------------
   227 function createPaperArray()
   228 {  
   229   if (isListOfPrinterFeaturesAvailable()) {
   230     createPaperArrayFromPrinterFeatures();    
   231   }
   232   else {
   233     createPaperArrayFromDefaults();
   234   }
   235 }
   237 //---------------------------------------------------
   238 function createPaperSizeList(selectedInx)
   239 {
   240   var selectElement = new paperListElement(dialog.paperList);
   241   selectElement.clearPaperList();
   243   selectElement.appendPaperNames(gPaperArray);
   245   if (selectedInx > -1) {
   246     selectElement.paperListElement.selectedIndex = selectedInx;
   247   }
   249   //dialog.paperList = selectElement;
   250 }
   252 //---------------------------------------------------
   253 function plexListElement(aPlexListElement)
   254   {
   255     this.plexListElement = aPlexListElement;
   256   }
   258 plexListElement.prototype =
   259   {
   260     clearPlexList:
   261       function ()
   262         {
   263           // remove the menupopup node child of the menulist.
   264           this.plexListElement.removeChild(this.plexListElement.firstChild);
   265         },
   267     appendPlexNames: 
   268       function (aDataObject) 
   269         { 
   270           var popupNode = document.createElement("menupopup"); 
   271           for (var i=0;i<aDataObject.length;i++)  {
   272             var plexObj = aDataObject[i];
   273             var itemNode = document.createElement("menuitem");
   274             var label;
   275             try {
   276               label = gPrintBundle.getString(plexObj.name);
   277             } 
   278             catch (e) {
   279               /* No name in string bundle ? Then build one manually (this
   280                * usually happens when gPlexArray was build by createPlexArrayFromPrinterFeatures() ...) */              
   281               label = plexObj.name;
   282             }
   283             itemNode.setAttribute("label", label);
   284             itemNode.setAttribute("value", i);
   285             popupNode.appendChild(itemNode);            
   286           }
   287           this.plexListElement.appendChild(popupNode); 
   288         } 
   289   };
   292 //---------------------------------------------------
   293 function createPlexArrayFromDefaults()
   294 {
   295   var plexNames = ["default"];
   297   gPlexArray = new Array();
   299   for (var i=0;i<plexNames.length;i++) {
   300     var obj    = new Object();
   301     obj.name   = plexNames[i];
   303     gPlexArray[i] = obj;
   304   }
   305 }
   307 //---------------------------------------------------
   308 function createPlexArrayFromPrinterFeatures()
   309 {
   310   var printername = gPrintSettings.printerName;
   311   if (doDebug) {
   312     dump("createPlexArrayFromPrinterFeatures for " + printername + ".\n");
   313   }
   315   gPlexArray = new Array();
   317   var numPlexs = gPrefs.getIntPref("print.tmp.printerfeatures." + printername + ".plex.count");
   319   if (doDebug) {
   320     dump("processing " + numPlexs + " entries...\n");
   321   }    
   323   for ( var i=0 ; i < numPlexs ; i++ ) {
   324     var obj = new Object();
   325     obj.name = gPrefs.getCharPref("print.tmp.printerfeatures." + printername + ".plex." + i + ".name");
   327     gPlexArray[i] = obj;
   329     if (doDebug) {
   330       dump("plex index=" + i + ", name='" + obj.name + "'.\n");
   331     }
   332   }  
   333 }
   335 //---------------------------------------------------
   336 function createPlexArray()
   337 {  
   338   if (isListOfPrinterFeaturesAvailable()) {
   339     createPlexArrayFromPrinterFeatures();    
   340   }
   341   else {
   342     createPlexArrayFromDefaults();
   343   }
   344 }
   346 //---------------------------------------------------
   347 function createPlexNameList(selectedInx)
   348 {
   349   var selectElement = new plexListElement(dialog.plexList);
   350   selectElement.clearPlexList();
   352   selectElement.appendPlexNames(gPlexArray);
   354   if (selectedInx > -1) {
   355     selectElement.plexListElement.selectedIndex = selectedInx;
   356   }
   358   //dialog.plexList = selectElement;
   359 }   
   361 //---------------------------------------------------
   362 function resolutionListElement(aResolutionListElement)
   363   {
   364     this.resolutionListElement = aResolutionListElement;
   365   }
   367 resolutionListElement.prototype =
   368   {
   369     clearResolutionList:
   370       function ()
   371         {
   372           // remove the menupopup node child of the menulist.
   373           this.resolutionListElement.removeChild(this.resolutionListElement.firstChild);
   374         },
   376     appendResolutionNames: 
   377       function (aDataObject) 
   378         { 
   379           var popupNode = document.createElement("menupopup"); 
   380           for (var i=0;i<aDataObject.length;i++)  {
   381             var resolutionObj = aDataObject[i];
   382             var itemNode = document.createElement("menuitem");
   383             var label;
   384             try {
   385               label = gPrintBundle.getString(resolutionObj.name);
   386             } 
   387             catch (e) {
   388               /* No name in string bundle ? Then build one manually (this
   389                * usually happens when gResolutionArray was build by createResolutionArrayFromPrinterFeatures() ...) */              
   390               label = resolutionObj.name;
   391             }
   392             itemNode.setAttribute("label", label);
   393             itemNode.setAttribute("value", i);
   394             popupNode.appendChild(itemNode);            
   395           }
   396           this.resolutionListElement.appendChild(popupNode); 
   397         } 
   398   };
   401 //---------------------------------------------------
   402 function createResolutionArrayFromDefaults()
   403 {
   404   var resolutionNames = ["default"];
   406   gResolutionArray = new Array();
   408   for (var i=0;i<resolutionNames.length;i++) {
   409     var obj    = new Object();
   410     obj.name   = resolutionNames[i];
   412     gResolutionArray[i] = obj;
   413   }
   414 }
   416 //---------------------------------------------------
   417 function createResolutionArrayFromPrinterFeatures()
   418 {
   419   var printername = gPrintSettings.printerName;
   420   if (doDebug) {
   421     dump("createResolutionArrayFromPrinterFeatures for " + printername + ".\n");
   422   }
   424   gResolutionArray = new Array();
   426   var numResolutions = gPrefs.getIntPref("print.tmp.printerfeatures." + printername + ".resolution.count");
   428   if (doDebug) {
   429     dump("processing " + numResolutions + " entries...\n");
   430   }    
   432   for ( var i=0 ; i < numResolutions ; i++ ) {
   433     var obj = new Object();
   434     obj.name = gPrefs.getCharPref("print.tmp.printerfeatures." + printername + ".resolution." + i + ".name");
   436     gResolutionArray[i] = obj;
   438     if (doDebug) {
   439       dump("resolution index=" + i + ", name='" + obj.name + "'.\n");
   440     }
   441   }  
   442 }
   444 //---------------------------------------------------
   445 function createResolutionArray()
   446 {  
   447   if (isListOfPrinterFeaturesAvailable()) {
   448     createResolutionArrayFromPrinterFeatures();    
   449   }
   450   else {
   451     createResolutionArrayFromDefaults();
   452   }
   453 }
   455 //---------------------------------------------------
   456 function createResolutionNameList(selectedInx)
   457 {
   458   var selectElement = new resolutionListElement(dialog.resolutionList);
   459   selectElement.clearResolutionList();
   461   selectElement.appendResolutionNames(gResolutionArray);
   463   if (selectedInx > -1) {
   464     selectElement.resolutionListElement.selectedIndex = selectedInx;
   465   }
   467   //dialog.resolutionList = selectElement;
   468 }  
   470 //---------------------------------------------------
   471 function colorspaceListElement(aColorspaceListElement)
   472   {
   473     this.colorspaceListElement = aColorspaceListElement;
   474   }
   476 colorspaceListElement.prototype =
   477   {
   478     clearColorspaceList:
   479       function ()
   480         {
   481           // remove the menupopup node child of the menulist.
   482           this.colorspaceListElement.removeChild(this.colorspaceListElement.firstChild);
   483         },
   485     appendColorspaceNames: 
   486       function (aDataObject) 
   487         { 
   488           var popupNode = document.createElement("menupopup"); 
   489           for (var i=0;i<aDataObject.length;i++)  {
   490             var colorspaceObj = aDataObject[i];
   491             var itemNode = document.createElement("menuitem");
   492             var label;
   493             try {
   494               label = gPrintBundle.getString(colorspaceObj.name);
   495             } 
   496             catch (e) {
   497               /* No name in string bundle ? Then build one manually (this
   498                * usually happens when gColorspaceArray was build by createColorspaceArrayFromPrinterFeatures() ...) */              
   499               label = colorspaceObj.name;
   500             }
   501             itemNode.setAttribute("label", label);
   502             itemNode.setAttribute("value", i);
   503             popupNode.appendChild(itemNode);            
   504           }
   505           this.colorspaceListElement.appendChild(popupNode); 
   506         } 
   507   };
   510 //---------------------------------------------------
   511 function createColorspaceArrayFromDefaults()
   512 {
   513   var colorspaceNames = ["default"];
   515   gColorspaceArray = new Array();
   517   for (var i=0;i<colorspaceNames.length;i++) {
   518     var obj    = new Object();
   519     obj.name   = colorspaceNames[i];
   521     gColorspaceArray[i] = obj;
   522   }
   523 }
   525 //---------------------------------------------------
   526 function createColorspaceArrayFromPrinterFeatures()
   527 {
   528   var printername = gPrintSettings.printerName;
   529   if (doDebug) {
   530     dump("createColorspaceArrayFromPrinterFeatures for " + printername + ".\n");
   531   }
   533   gColorspaceArray = new Array();
   535   var numColorspaces = gPrefs.getIntPref("print.tmp.printerfeatures." + printername + ".colorspace.count");
   537   if (doDebug) {
   538     dump("processing " + numColorspaces + " entries...\n");
   539   }    
   541   for ( var i=0 ; i < numColorspaces ; i++ ) {
   542     var obj = new Object();
   543     obj.name = gPrefs.getCharPref("print.tmp.printerfeatures." + printername + ".colorspace." + i + ".name");
   545     gColorspaceArray[i] = obj;
   547     if (doDebug) {
   548       dump("colorspace index=" + i + ", name='" + obj.name + "'.\n");
   549     }
   550   }  
   551 }
   553 //---------------------------------------------------
   554 function createColorspaceArray()
   555 {  
   556   if (isListOfPrinterFeaturesAvailable()) {
   557     createColorspaceArrayFromPrinterFeatures();    
   558   }
   559   else {
   560     createColorspaceArrayFromDefaults();
   561   }
   562 }
   564 //---------------------------------------------------
   565 function createColorspaceNameList(selectedInx)
   566 {
   567   var selectElement = new colorspaceListElement(dialog.colorspaceList);
   568   selectElement.clearColorspaceList();
   570   selectElement.appendColorspaceNames(gColorspaceArray);
   572   if (selectedInx > -1) {
   573     selectElement.colorspaceListElement.selectedIndex = selectedInx;
   574   }
   576   //dialog.colorspaceList = selectElement;
   577 }  
   579 //---------------------------------------------------
   580 function loadDialog()
   581 {
   582   var print_paper_type       = 0;
   583   var print_paper_unit       = 0;
   584   var print_paper_width      = 0.0;
   585   var print_paper_height     = 0.0;
   586   var print_paper_name       = "";
   587   var print_plex_name        = "";
   588   var print_resolution_name  = "";
   589   var print_colorspace       = "";
   590   var print_color            = true;
   591   var print_downloadfonts    = true;
   592   var print_command          = default_command;
   593   var print_jobtitle         = "";
   595   gPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
   597   if (gPrintSettings) {
   598     print_paper_type       = gPrintSettings.paperSizeType;
   599     print_paper_unit       = gPrintSettings.paperSizeUnit;
   600     print_paper_width      = gPrintSettings.paperWidth;
   601     print_paper_height     = gPrintSettings.paperHeight;
   602     print_paper_name       = gPrintSettings.paperName;
   603     print_plex_name        = gPrintSettings.plexName;
   604     print_resolution_name  = gPrintSettings.resolutionName;
   605     print_colorspace       = gPrintSettings.colorspace;
   606     print_color            = gPrintSettings.printInColor;
   607     print_downloadfonts    = gPrintSettings.downloadFonts;
   608     print_command          = gPrintSettings.printCommand;
   609     print_jobtitle         = gPrintSettings.title;
   610   }
   612   if (doDebug) {
   613     dump("loadDialog******************************\n");
   614     dump("paperSizeType   "+print_paper_unit+"\n");
   615     dump("paperWidth      "+print_paper_width+"\n");
   616     dump("paperHeight     "+print_paper_height+"\n");
   617     dump("paperName       "+print_paper_name+"\n");
   618     dump("plexName        "+print_plex_name+"\n");
   619     dump("resolutionName  "+print_resolution_name+"\n");
   620     dump("colorspace      "+print_colorspace+"\n");
   621     dump("print_color     "+print_color+"\n");
   622     dump("print_downloadfonts "+print_downloadfonts+"\n");
   623     dump("print_command    "+print_command+"\n");
   624     dump("print_jobtitle   "+print_jobtitle+"\n");
   625   }
   627   createPaperArray();
   629   var paperSelectedInx = 0;
   630   for (var i=0;i<gPaperArray.length;i++) { 
   631     if (print_paper_name == gPaperArray[i].name) {
   632       paperSelectedInx = i;
   633       break;
   634     }
   635   }
   637   if (doDebug) {
   638     if (i == gPaperArray.length)
   639       dump("loadDialog: No paper found.\n");
   640     else
   641       dump("loadDialog: found paper '"+gPaperArray[paperSelectedInx].name+"'.\n");
   642   }
   644   createPaperSizeList(paperSelectedInx);
   646   createPlexArray();
   647   var plexSelectedInx = 0;
   648   for (var i=0;i<gPlexArray.length;i++) { 
   649     if (print_plex_name == gPlexArray[i].name) {
   650       plexSelectedInx = i;
   651       break;
   652     }
   653   }
   655   if (doDebug) {
   656     if (i == gPlexArray.length)
   657       dump("loadDialog: No plex found.\n");
   658     else
   659       dump("loadDialog: found plex '"+gPlexArray[plexSelectedInx].name+"'.\n");
   660   }
   662   createResolutionArray();
   663   var resolutionSelectedInx = 0;
   664   for (var i=0;i<gResolutionArray.length;i++) { 
   665     if (print_resolution_name == gResolutionArray[i].name) {
   666       resolutionSelectedInx = i;
   667       break;
   668     }
   669   }
   671   if (doDebug) {
   672     if (i == gResolutionArray.length)
   673       dump("loadDialog: No resolution found.\n");
   674     else
   675       dump("loadDialog: found resolution '"+gResolutionArray[resolutionSelectedInx].name+"'.\n");
   676   }
   678   createColorspaceArray();
   679   var colorspaceSelectedInx = 0;
   680   for (var i=0;i<gColorspaceArray.length;i++) { 
   681     if (print_colorspace == gColorspaceArray[i].name) {
   682       colorspaceSelectedInx = i;
   683       break;
   684     }
   685   }
   687   if (doDebug) {
   688     if (i == gColorspaceArray.length)
   689       dump("loadDialog: No colorspace found.\n");
   690     else
   691       dump("loadDialog: found colorspace '"+gColorspaceArray[colorspaceSelectedInx].name+"'.\n");
   692   }
   694   createPlexNameList(plexSelectedInx);
   695   createResolutionNameList(resolutionSelectedInx);
   696   createColorspaceNameList(colorspaceSelectedInx);
   698   /* Enable/disable and/or hide/unhide widgets based in the information
   699    * whether the selected printer and/or print module supports the matching
   700    * feature or not */
   701   if (isListOfPrinterFeaturesAvailable()) {
   702     // job title
   703     if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".can_change_jobtitle"))
   704       dialog.jobTitleInput.removeAttribute("disabled");
   705     else
   706       dialog.jobTitleInput.setAttribute("disabled","true");
   707     if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".supports_jobtitle_change"))
   708       dialog.jobTitleGroup.removeAttribute("hidden");
   709     else
   710       dialog.jobTitleGroup.setAttribute("hidden","true");
   712     // spooler command
   713     if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".can_change_spoolercommand"))
   714       dialog.cmdInput.removeAttribute("disabled");
   715     else
   716       dialog.cmdInput.setAttribute("disabled","true");
   717     if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".supports_spoolercommand_change"))
   718       dialog.cmdGroup.removeAttribute("hidden");
   719     else
   720       dialog.cmdGroup.setAttribute("hidden","true");
   722     // paper size
   723     if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".can_change_paper_size"))
   724       dialog.paperList.removeAttribute("disabled");
   725     else
   726       dialog.paperList.setAttribute("disabled","true");
   727     if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".supports_paper_size_change"))
   728       dialog.paperGroup.removeAttribute("hidden");
   729     else
   730       dialog.paperGroup.setAttribute("hidden","true");
   732     // plex mode
   733     if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".can_change_plex"))
   734       dialog.plexList.removeAttribute("disabled");
   735     else
   736       dialog.plexList.setAttribute("disabled","true");
   737     if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".supports_plex_change"))
   738       dialog.plexGroup.removeAttribute("hidden");
   739     else
   740       dialog.plexGroup.setAttribute("hidden","true");
   742     // resolution
   743     if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".can_change_resolution"))
   744       dialog.resolutionList.removeAttribute("disabled");
   745     else
   746       dialog.resolutionList.setAttribute("disabled","true");
   747     if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".supports_resolution_change"))
   748       dialog.resolutionGroup.removeAttribute("hidden");
   749     else
   750       dialog.resolutionGroup.setAttribute("hidden","true");
   752     // color/grayscale radio
   753     if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".can_change_printincolor"))
   754       dialog.colorRadioGroup.removeAttribute("disabled");
   755     else
   756       dialog.colorRadioGroup.setAttribute("disabled","true");
   757     if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".supports_printincolor_change"))
   758       dialog.colorGroup.removeAttribute("hidden");
   759     else
   760       dialog.colorGroup.setAttribute("hidden","true");
   762     // colorspace
   763     if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".can_change_colorspace"))
   764       dialog.colorspaceList.removeAttribute("disabled");
   765     else
   766       dialog.colorspaceList.setAttribute("disabled","true");
   767     if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".supports_colorspace_change"))
   768       dialog.colorspaceGroup.removeAttribute("hidden");
   769     else
   770       dialog.colorspaceGroup.setAttribute("hidden","true");
   772     // font download
   773     if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".can_change_downloadfonts"))
   774       dialog.downloadFonts.removeAttribute("disabled");
   775     else
   776       dialog.downloadFonts.setAttribute("disabled","true");
   777     if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".supports_downloadfonts_change"))
   778       dialog.fontsGroup.removeAttribute("hidden");
   779     else
   780       dialog.fontsGroup.setAttribute("hidden","true");
   781   }
   783   if (print_command == "") {
   784     print_command = default_command;
   785   }
   787   if (print_color) {
   788     dialog.colorRadioGroup.selectedItem = dialog.colorRadio;
   789   } else {
   790     dialog.colorRadioGroup.selectedItem = dialog.grayRadio;
   791   }
   793   dialog.downloadFonts.checked = print_downloadfonts;
   795   dialog.cmdInput.value      = print_command;
   796   dialog.jobTitleInput.value = print_jobtitle;
   798   dialog.topInput.value    = gPrintSettings.edgeTop.toFixed(2);
   799   dialog.bottomInput.value = gPrintSettings.edgeBottom.toFixed(2);
   800   dialog.leftInput.value   = gPrintSettings.edgeLeft.toFixed(2);
   801   dialog.rightInput.value  = gPrintSettings.edgeRight.toFixed(2);
   802 }
   804 //---------------------------------------------------
   805 function onLoad()
   806 {
   807   // Init dialog.
   808   initDialog();
   810   gPrintSettings = window.arguments[0].QueryInterface(gPrintSetInterface);
   811   paramBlock = window.arguments[1].QueryInterface(Components.interfaces.nsIDialogParamBlock);
   813   if (doDebug) {
   814     if (gPrintSettings == null) alert("PrintSettings is null!");
   815     if (paramBlock == null) alert("nsIDialogParam is null!");
   816   }
   818   // default return value is "cancel"
   819   paramBlock.SetInt(0, 0);
   821   loadDialog();
   822 }
   824 //---------------------------------------------------
   825 function onAccept()
   826 {
   827   var print_paper_type        = gPrintSettingsInterface.kPaperSizeDefined;
   828   var print_paper_unit        = gPrintSettingsInterface.kPaperSizeInches;
   829   var print_paper_width       = 0.0;
   830   var print_paper_height      = 0.0;
   831   var print_paper_name        = "";
   832   var print_plex_name         = "";
   833   var print_resolution_name   = "";
   834   var print_colorspace        = "";
   836   if (gPrintSettings != null) {
   837     var paperSelectedInx = dialog.paperList.selectedIndex;
   838     var plexSelectedInx  = dialog.plexList.selectedIndex;
   839     var resolutionSelectedInx = dialog.resolutionList.selectedIndex;
   840     var colorspaceSelectedInx = dialog.colorspaceList.selectedIndex;
   841     if (gPaperArray[paperSelectedInx].inches) {
   842       print_paper_unit = gPrintSettingsInterface.kPaperSizeInches;
   843     } else {
   844       print_paper_unit = gPrintSettingsInterface.kPaperSizeMillimeters;
   845     }
   846     print_paper_width      = gPaperArray[paperSelectedInx].width;
   847     print_paper_height     = gPaperArray[paperSelectedInx].height;
   848     print_paper_name       = gPaperArray[paperSelectedInx].name;
   849     print_plex_name        = gPlexArray[plexSelectedInx].name;
   850     print_resolution_name  = gResolutionArray[resolutionSelectedInx].name;
   851     print_colorspace       = gColorspaceArray[colorspaceSelectedInx].name;
   853     gPrintSettings.paperSizeType   = print_paper_type;
   854     gPrintSettings.paperSizeUnit   = print_paper_unit;
   855     gPrintSettings.paperWidth      = print_paper_width;
   856     gPrintSettings.paperHeight     = print_paper_height;
   857     gPrintSettings.paperName       = print_paper_name;
   858     gPrintSettings.plexName        = print_plex_name;
   859     gPrintSettings.resolutionName  = print_resolution_name;
   860     gPrintSettings.colorspace      = print_colorspace;
   862     // save these out so they can be picked up by the device spec
   863     gPrintSettings.printInColor     = dialog.colorRadio.selected;
   864     gPrintSettings.downloadFonts    = dialog.downloadFonts.checked;
   865     gPrintSettings.printCommand     = dialog.cmdInput.value;
   866     gPrintSettings.title            = dialog.jobTitleInput.value;
   868     gPrintSettings.edgeTop          = dialog.topInput.value;
   869     gPrintSettings.edgeBottom       = dialog.bottomInput.value;
   870     gPrintSettings.edgeLeft         = dialog.leftInput.value;
   871     gPrintSettings.edgeRight        = dialog.rightInput.value;
   873     if (doDebug) {
   874       dump("onAccept******************************\n");
   875       dump("paperSizeType    "+print_paper_type+" (should be 1)\n");
   876       dump("paperSizeUnit    "+print_paper_unit+"\n");
   877       dump("paperWidth       "+print_paper_width+"\n");
   878       dump("paperHeight      "+print_paper_height+"\n");
   879       dump("paperName       '"+print_paper_name+"'\n");
   880       dump("plexName        '"+print_plex_name+"'\n");
   881       dump("resolutionName  '"+print_resolution_name+"'\n");
   882       dump("colorspace      '"+print_colorspace+"'\n");
   884       dump("printInColor     "+gPrintSettings.printInColor+"\n");
   885       dump("downloadFonts    "+gPrintSettings.downloadFonts+"\n");
   886       dump("printCommand    '"+gPrintSettings.printCommand+"'\n");
   887     }
   888   } else {
   889     dump("************ onAccept gPrintSettings: "+gPrintSettings+"\n");
   890   }
   892   if (paramBlock) {
   893     // set return value to "ok"
   894     paramBlock.SetInt(0, 1);
   895   } else {
   896     dump("*** FATAL ERROR: paramBlock missing\n");
   897   }
   899   return true;
   900 }

mercurial