//----------------------------------------------------------------------
nsresult GlobalPrinters::InitializeGlobalPrinters ()
{
  if (PrintersAreAllocated()) {
    return NS_OK;
  }

  mGlobalPrinterList = new nsStringArray();
  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;
      
#ifdef USE_POSTSCRIPT
  nsPSPrinterList psMgr;
  if (NS_SUCCEEDED(psMgr.Init()) && psMgr.Enabled()) {
    /* Get the list of PostScript-module printers */
    nsCStringArray printerList;
    psMgr.GetPrinterList(printerList);
    printerList.EnumerateForwards(GlobalPrinterEnumFunc, mGlobalPrinterList);
  }
#endif /* USE_POSTSCRIPT */  
      
  /* If there are no printers available after all checks, return an error */
  if (!mGlobalPrinterList->Count())
  {
    /* Make sure we do not cache an empty printer list */
    FreeGlobalPrinters();

    return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE;
  }

  return NS_OK;
}
 ~GlobalPrinters() { FreeGlobalPrinters(); }