Bug 324072 - Printer properties dialog shows properties for the wrong printer. r+sr=roc.

git-svn-id: svn://10.0.0.236/trunk@189267 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
kjh-5727%comcast.net 2006-02-07 01:15:22 +00:00
parent 488fa0a223
commit ee7cad3229
2 changed files with 54 additions and 24 deletions

View File

@ -43,7 +43,7 @@
interface nsIPrintSettings;
[scriptable, uuid(841387C8-72E6-484b-9296-BF6EEA80D58A)]
[scriptable, uuid(1a64316f-402d-4b0d-a434-ba419dbe539e)]
interface nsIPrintSettingsService : nsISupports
{
/**
@ -72,7 +72,7 @@ interface nsIPrintSettingsService : nsISupports
readonly attribute nsIPrintSettings newPrintSettings;
/**
* The name of the default printer
* The name of the last printer used, or else the system default printer.
*/
readonly attribute wstring defaultPrinterName;
@ -90,21 +90,23 @@ interface nsIPrintSettingsService : nsISupports
* Reads PrintSettings values from Prefs,
* the values to be read are indicated by the "flags" arg.
*
* First it reads in the "generic" set of PrintSetings not associated with any printer
* then it uses the PrinterName in the PrinterSettings to read any settings that were saved
* aPrintSettings should be initialized with the name of a printer. First
* it reads in the PrintSettings from the last print job. Then it uses the
* PrinterName in the PrinterSettings to read any settings that were saved
* just for that printer.
*
* aPS - PrintSettings to have its settings read
* aUsePrinterNamePrefix - indicates whether to use the printer name as a prefix
* aFlags - indicates which prefs to read, see nsIPrintSettings.idl for the const values.
* aFlags - indicates which prefs to read, see nsIPrintSettings.idl for the
* const values.
*
* Items not read:
* startPageRange, endPageRange, scaling, printRange, title
* docURL, howToEnableFrameUI, isCancelled, printFrameTypeUsage
* printFrameType, printSilent, shrinkToFit, numCopies
* printFrameType, printSilent, shrinkToFit, numCopies,
* printerName
*
*/
void initPrintSettingsFromPrefs(in nsIPrintSettings aPrintSettings, in boolean aUsePrinterNamePrefix, in unsigned long aFlags);
void initPrintSettingsFromPrefs(in nsIPrintSettings aPrintSettings, in unsigned long aFlags);
/**
* Writes PrintSettings values to Prefs,

View File

@ -1,4 +1,5 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ex: set tabstop=8 softtabstop=2 shiftwidth=2 expandtab: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
@ -579,13 +580,6 @@ nsPrintOptions::ReadPrefs(nsIPrintSettings* aPS, const nsAString& aPrinterName,
}
}
if (aFlags & nsIPrintSettings::kInitSavePrinterName) {
if (GETSTRPREF(kPrinterName, str)) {
aPS->SetPrinterName(str.get());
DUMP_STR(kReadStr, kPrinterName, str.get());
}
}
if (aFlags & nsIPrintSettings::kInitSavePrintToFile) {
if (GETBOOLPREF(kPrintToFile, &b)) {
aPS->SetPrintToFile(b);
@ -847,10 +841,12 @@ nsPrintOptions::WritePrefs(nsIPrintSettings *aPS, const nsAString& aPrinterName,
}
}
if (aFlags & nsIPrintSettings::kInitSavePrinterName) {
// Only the general version of this pref is saved
if ((aFlags & nsIPrintSettings::kInitSavePrinterName)
&& aPrinterName.IsEmpty()) {
if (NS_SUCCEEDED(aPS->GetPrinterName(&uStr))) {
DUMP_STR(kWriteStr, kPrinterName, uStr);
WritePrefString(uStr, GetPrefName(kPrinterName, aPrinterName));
WritePrefString(uStr, kPrinterName);
}
}
@ -946,8 +942,13 @@ nsresult nsPrintOptions::_CreatePrintSettings(nsIPrintSettings **_retval)
NS_ENSURE_TRUE(printSettings, NS_ERROR_OUT_OF_MEMORY);
NS_ADDREF(*_retval = printSettings); // ref count
(void)InitPrintSettingsFromPrefs(*_retval, PR_FALSE,
nsIPrintSettings::kInitSaveAll);
nsXPIDLString printerName;
nsresult rv = GetDefaultPrinterName(getter_Copies(printerName));
NS_ENSURE_SUCCESS(rv, rv);
(*_retval)->SetPrinterName(printerName.get());
(void)InitPrintSettingsFromPrefs(*_retval, nsIPrintSettings::kInitSaveAll);
return NS_OK;
}
@ -984,6 +985,32 @@ nsPrintOptions::GetDefaultPrinterName(PRUnichar * *aDefaultPrinterName)
&rv);
NS_ENSURE_SUCCESS(rv, rv);
// Look up the printer from the last print job
nsAutoString lastPrinterName;
ReadPrefString(kPrinterName, lastPrinterName);
if (!lastPrinterName.IsEmpty()) {
// Verify it's still a valid printer
PRUnichar **printers;
PRUint32 ctPrinters;
rv = prtEnum->EnumeratePrinters(&ctPrinters, &printers);
if (NS_SUCCEEDED(rv)) {
PRBool isValid = PR_FALSE;
for (PRUint32 ii = ctPrinters; ii--; ) {
if (lastPrinterName.Equals(printers[ii])) {
isValid = PR_TRUE;
break;
}
}
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(ctPrinters, printers);
if (isValid) {
*aDefaultPrinterName = ToNewUnicode(lastPrinterName);
return NS_OK;
}
}
}
// There is no last printer preference, or it doesn't name a valid printer.
// Return the default from the printer enumeration.
return prtEnum->GetDefaultPrinterName(aDefaultPrinterName);
}
@ -1087,7 +1114,7 @@ nsPrintOptions::GetPrinterPrefInt(nsIPrintSettings *aPrintSettings,
NS_IMETHODIMP
nsPrintOptions::InitPrintSettingsFromPrefs(nsIPrintSettings* aPS,
PRBool aUsePNP, PRUint32 aFlags)
PRUint32 aFlags)
{
NS_ENSURE_ARG_POINTER(aPS);
@ -1105,11 +1132,13 @@ nsPrintOptions::InitPrintSettingsFromPrefs(nsIPrintSettings* aPS,
// Get the Printer Name from the PrintSettings
// to use as a prefix for Pref Names
rv = GetAdjustedPrinterName(aPS, aUsePNP, prtName);
rv = GetAdjustedPrinterName(aPS, PR_TRUE, prtName);
NS_ENSURE_SUCCESS(rv, rv);
if (prtName.IsEmpty())
if (prtName.IsEmpty()) {
NS_WARNING("Caller should supply a printer name.");
return NS_OK;
}
// Now read any printer specific prefs
rv = ReadPrefs(aPS, prtName, aFlags);
@ -1388,8 +1417,7 @@ Tester::Tester()
printf("------------------------------------------------\n");
printf("%d) %s -> 0x%X\n", i, gSettings[i].mName, gSettings[i].mFlag);
printService->SavePrintSettingsToPrefs(ps, PR_TRUE, gSettings[i].mFlag);
printService->InitPrintSettingsFromPrefs(ps, PR_TRUE,
gSettings[i].mFlag);
printService->InitPrintSettingsFromPrefs(ps, gSettings[i].mFlag);
i++;
}
}