зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1755153 p1 - Centralize saving of last used printer name. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D146943
This commit is contained in:
Родитель
be689a02d5
Коммит
17f8eb8dec
|
@ -398,7 +398,7 @@ var PrintEventHandler = {
|
|||
await window._initialized;
|
||||
|
||||
// This seems like it should be handled automatically but it isn't.
|
||||
Services.prefs.setStringPref("print_printer", settings.printerName);
|
||||
PSSVC.saveLastUsedPrinterNameToPrefs(settings.printerName);
|
||||
|
||||
try {
|
||||
// We'll provide our own progress indicator.
|
||||
|
@ -795,7 +795,7 @@ var PrintEventHandler = {
|
|||
},
|
||||
|
||||
saveSettingsToPrefs(flags) {
|
||||
PSSVC.savePrintSettingsToPrefs(this.settings, true, flags);
|
||||
PSSVC.savePrintSettingsToPrefs(this.settings, flags);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -522,7 +522,7 @@ function onAccept() {
|
|||
// XXX Should we do this in nsPrintDialogServiceWin::ShowPageSetup (the code
|
||||
// that invokes us), since ShowPageSetup is where we do the saving for the
|
||||
// other platforms?
|
||||
gPrintService.savePrintSettingsToPrefs(gPrintSettings, true, flags);
|
||||
gPrintService.savePrintSettingsToPrefs(gPrintSettings, flags);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------
|
||||
|
|
|
@ -115,14 +115,9 @@ var PrintUtils = {
|
|||
);
|
||||
if (!PSSVC.lastUsedPrinterName) {
|
||||
if (printSettings.printerName) {
|
||||
PSSVC.saveLastUsedPrinterNameToPrefs(printSettings.printerName);
|
||||
PSSVC.savePrintSettingsToPrefs(
|
||||
printSettings,
|
||||
false,
|
||||
Ci.nsIPrintSettings.kInitSavePrinterName
|
||||
);
|
||||
PSSVC.savePrintSettingsToPrefs(
|
||||
printSettings,
|
||||
true,
|
||||
Ci.nsIPrintSettings.kInitSaveAll
|
||||
);
|
||||
}
|
||||
|
@ -354,13 +349,12 @@ var PrintUtils = {
|
|||
}
|
||||
|
||||
// Update the saved last used printer name and print settings:
|
||||
Services.prefs.setStringPref("print_printer", settings.printerName);
|
||||
var PSSVC = Cc["@mozilla.org/gfx/printsettings-service;1"].getService(
|
||||
Ci.nsIPrintSettingsService
|
||||
);
|
||||
PSSVC.saveLastUsedPrinterNameToPrefs(settings.printerName);
|
||||
PSSVC.savePrintSettingsToPrefs(
|
||||
settings,
|
||||
true,
|
||||
Ci.nsIPrintSettings.kInitSaveAll
|
||||
);
|
||||
}
|
||||
|
|
|
@ -122,8 +122,7 @@ nsPrintDialogServiceX::ShowPrintDialog(mozIDOMWindowProxy* aParent, bool aHaveSe
|
|||
|
||||
// Save settings unless saving is pref'd off
|
||||
if (Preferences::GetBool("print.save_print_settings", false)) {
|
||||
printSettingsSvc->SavePrintSettingsToPrefs(settingsX, true,
|
||||
nsIPrintSettings::kInitSaveNativeData);
|
||||
printSettingsSvc->SavePrintSettingsToPrefs(settingsX, nsIPrintSettings::kInitSaveNativeData);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
@ -167,7 +166,7 @@ nsPrintDialogServiceX::ShowPageSetupDialog(mozIDOMWindowProxy* aParent,
|
|||
uint32_t flags = nsIPrintSettings::kInitSaveNativeData |
|
||||
nsIPrintSettings::kInitSavePaperSize |
|
||||
nsIPrintSettings::kInitSaveOrientation | nsIPrintSettings::kInitSaveScaling;
|
||||
printSettingsService->SavePrintSettingsToPrefs(aNSSettings, true, flags);
|
||||
printSettingsService->SavePrintSettingsToPrefs(aNSSettings, flags);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -599,10 +599,9 @@ nsPrintDialogServiceGTK::ShowPageSetupDialog(mozIDOMWindowProxy* aParent,
|
|||
|
||||
if (psService)
|
||||
psService->SavePrintSettingsToPrefs(
|
||||
aNSSettings, true,
|
||||
nsIPrintSettings::kInitSaveOrientation |
|
||||
nsIPrintSettings::kInitSavePaperSize |
|
||||
nsIPrintSettings::kInitSaveUnwriteableMargins);
|
||||
aNSSettings, nsIPrintSettings::kInitSaveOrientation |
|
||||
nsIPrintSettings::kInitSavePaperSize |
|
||||
nsIPrintSettings::kInitSaveUnwriteableMargins);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -93,7 +93,6 @@ interface nsIPrintSettingsService : nsISupports
|
|||
* If a PrinterName is there, then it saves the items qualified for that Printer
|
||||
*
|
||||
* aPS - PrintSettings to have its settings saved
|
||||
* aUsePrinterNamePrefix - indicates whether to use the printer name as a prefix
|
||||
* aFlags - indicates which prefs to save, see nsIPrintSettings.idl for the const values.
|
||||
*
|
||||
* Items not written:
|
||||
|
@ -102,7 +101,12 @@ interface nsIPrintSettingsService : nsISupports
|
|||
* printSilent, shrinkToFit, numCopies
|
||||
*
|
||||
*/
|
||||
void savePrintSettingsToPrefs(in nsIPrintSettings aPrintSettings, in boolean aUsePrinterNamePrefix, in unsigned long aFlags);
|
||||
void savePrintSettingsToPrefs(in nsIPrintSettings aPrintSettings, in unsigned long aFlags);
|
||||
|
||||
/**
|
||||
* Saves the given printer name as the last used printer name.
|
||||
*/
|
||||
void saveLastUsedPrinterNameToPrefs(in AString aPrinterName);
|
||||
|
||||
/**
|
||||
* Given some nsIPrintSettings,
|
||||
|
|
|
@ -930,14 +930,16 @@ nsPrintSettingsService::InitPrintSettingsFromPrefs(nsIPrintSettings* aPS,
|
|||
* Save all of the printer settings; if we can find a printer name, save
|
||||
* printer-specific preferences. Otherwise, save generic ones.
|
||||
*/
|
||||
nsresult nsPrintSettingsService::SavePrintSettingsToPrefs(
|
||||
nsIPrintSettings* aPS, bool aUsePrinterNamePrefix, uint32_t aFlags) {
|
||||
nsresult nsPrintSettingsService::SavePrintSettingsToPrefs(nsIPrintSettings* aPS,
|
||||
uint32_t aFlags) {
|
||||
NS_ENSURE_ARG_POINTER(aPS);
|
||||
MOZ_DIAGNOSTIC_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
||||
MOZ_ASSERT(!(aFlags & nsIPrintSettings::kInitSavePrinterName),
|
||||
"Use SaveLastUsedPrintNameToPrefs");
|
||||
|
||||
// Get the printer name from the PrinterSettings for an optional prefix.
|
||||
nsAutoString prtName;
|
||||
nsresult rv = GetAdjustedPrinterName(aPS, aUsePrinterNamePrefix, prtName);
|
||||
nsresult rv = GetAdjustedPrinterName(aPS, true, prtName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
#ifndef MOZ_WIDGET_ANDROID
|
||||
|
@ -946,7 +948,7 @@ nsresult nsPrintSettingsService::SavePrintSettingsToPrefs(
|
|||
// without a good way for us to fix things for them (unprefixed prefs act as
|
||||
// defaults and can result in values being inappropriately propagated to
|
||||
// prefixed prefs).
|
||||
if (prtName.IsEmpty() && aFlags != nsIPrintSettings::kInitSavePrinterName) {
|
||||
if (prtName.IsEmpty()) {
|
||||
MOZ_DIAGNOSTIC_ASSERT(false, "Print settings must be saved with a prefix");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -955,6 +957,16 @@ nsresult nsPrintSettingsService::SavePrintSettingsToPrefs(
|
|||
return WritePrefs(aPS, prtName, aFlags);
|
||||
}
|
||||
|
||||
nsresult nsPrintSettingsService::SaveLastUsedPrinterNameToPrefs(
|
||||
const nsAString& aPrinterName) {
|
||||
MOZ_DIAGNOSTIC_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
||||
|
||||
if (!aPrinterName.IsEmpty()) {
|
||||
Preferences::SetString(kPrinterName, aPrinterName);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------
|
||||
//-- Protected Methods --------------------------------
|
||||
//-----------------------------------------------------
|
||||
|
|
Загрузка…
Ссылка в новой задаче