зеркало из https://github.com/mozilla/pjs.git
Bug 324072 Paper size and printer selection in printdialog are reflected incorrectly in preferences
p=me/kherron r=kherron sr=roc
This commit is contained in:
Родитель
0bfae16813
Коммит
999fb60b94
|
@ -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,18 +90,21 @@ 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);
|
||||
|
|
|
@ -579,13 +579,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 +840,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,6 +941,12 @@ nsresult nsPrintOptions::_CreatePrintSettings(nsIPrintSettings **_retval)
|
|||
NS_ENSURE_TRUE(printSettings, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
NS_ADDREF(*_retval = printSettings); // ref count
|
||||
|
||||
nsXPIDLString printerName;
|
||||
nsresult rv = GetDefaultPrinterName(getter_Copies(printerName));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
(*_retval)->SetPrinterName(printerName.get());
|
||||
|
||||
(void)InitPrintSettingsFromPrefs(*_retval, PR_FALSE,
|
||||
nsIPrintSettings::kInitSaveAll);
|
||||
|
||||
|
@ -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 - 1; ii >= 0; --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);
|
||||
}
|
||||
|
||||
|
@ -1108,8 +1135,10 @@ nsPrintOptions::InitPrintSettingsFromPrefs(nsIPrintSettings* aPS,
|
|||
rv = GetAdjustedPrinterName(aPS, aUsePNP, 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);
|
||||
|
|
Загрузка…
Ссылка в новой задаче