mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 22:32:46 +00:00
Bug 1651532 - Change systemDefaultPrinter to systemDefaultPrinterName r=jwatt
The `systemDefaultPrinter` attribute in `nsIPrinterList` currently has only one usage: to retrieve the printer's name. This patch changes the attribute to be the name instead of the whole printer until such funcationality is needed. Differential Revision: https://phabricator.services.mozilla.com/D82951
This commit is contained in:
parent
699043a34c
commit
ce70595b23
@ -47,19 +47,14 @@ static LazyLogModule sDeviceContextSpecXLog("DeviceContextSpecX");
|
||||
NS_IMPL_ISUPPORTS(nsPrinterListX, nsIPrinterList);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPrinterListX::GetSystemDefaultPrinter(nsIPrinter** aDefaultPrinter) {
|
||||
nsPrinterListX::GetSystemDefaultPrinterName(nsAString& aName) {
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
NS_ENSURE_ARG_POINTER(aDefaultPrinter);
|
||||
*aDefaultPrinter = nullptr;
|
||||
|
||||
aName.Truncate();
|
||||
NSArray<NSString*>* printerNames = [NSPrinter printerNames];
|
||||
if ([printerNames count] > 0) {
|
||||
NSString* name = [printerNames objectAtIndex:0];
|
||||
nsAutoString printerName;
|
||||
nsCocoaUtils::GetStringForNSString(name, printerName);
|
||||
*aDefaultPrinter = new nsPrinter(printerName);
|
||||
NS_ADDREF(*aDefaultPrinter);
|
||||
nsCocoaUtils::GetStringForNSString(name, aName);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -372,13 +372,8 @@ nsPrinterListGTK::GetPrinters(nsTArray<RefPtr<nsIPrinter>>& aPrinters) {
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPrinterListGTK::GetSystemDefaultPrinter(nsIPrinter** aDefaultPrinter) {
|
||||
nsAutoString printerName;
|
||||
GlobalPrinters::GetInstance()->GetSystemDefaultPrinterName(printerName);
|
||||
|
||||
*aDefaultPrinter = new nsPrinter(printerName);
|
||||
NS_ADDREF(*aDefaultPrinter);
|
||||
|
||||
nsPrinterListGTK::GetSystemDefaultPrinterName(nsAString& aName) {
|
||||
GlobalPrinters::GetInstance()->GetSystemDefaultPrinterName(aName);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -23,12 +23,11 @@ interface nsIPrinterList : nsISupports
|
||||
in nsIPrintSettings aPrintSettings);
|
||||
|
||||
/**
|
||||
* The system default printer. This should also be
|
||||
* present in printers below. This is not necessarily gecko's
|
||||
* The system default printer name. This is not necessarily gecko's
|
||||
* default printer; see nsIPrintSettingsService.lastUsedPrinterName
|
||||
* for that.
|
||||
*/
|
||||
readonly attribute nsIPrinter systemDefaultPrinter;
|
||||
readonly attribute AString systemDefaultPrinterName;
|
||||
|
||||
/**
|
||||
* The list of printers.
|
||||
|
@ -921,11 +921,7 @@ nsPrintSettingsService::GetLastUsedPrinterName(
|
||||
|
||||
// There is no last printer preference, or it doesn't name a valid printer.
|
||||
// Return the system default from the printer list.
|
||||
RefPtr<nsIPrinter> defaultPrinter;
|
||||
printerList->GetSystemDefaultPrinter(getter_AddRefs(defaultPrinter));
|
||||
if (defaultPrinter) {
|
||||
defaultPrinter->GetName(aLastUsedPrinterName);
|
||||
}
|
||||
printerList->GetSystemDefaultPrinterName(aLastUsedPrinterName);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -514,13 +514,8 @@ nsresult nsDeviceContextSpecWin::GetDataFromPrinter(const nsAString& aName,
|
||||
NS_IMPL_ISUPPORTS(nsPrinterListWin, nsIPrinterList)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPrinterListWin::GetSystemDefaultPrinter(nsIPrinter** aDefaultPrinter) {
|
||||
NS_ENSURE_ARG_POINTER(aDefaultPrinter);
|
||||
*aDefaultPrinter = nullptr;
|
||||
nsAutoString printerName;
|
||||
GlobalPrinters::GetInstance()->GetDefaultPrinterName(printerName);
|
||||
*aDefaultPrinter = new nsPrinter(printerName);
|
||||
NS_ADDREF(*aDefaultPrinter);
|
||||
nsPrinterListWin::GetSystemDefaultPrinterName(nsAString& aName) {
|
||||
GlobalPrinters::GetInstance()->GetDefaultPrinterName(aName);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -136,14 +136,11 @@ static nsReturnRef<nsHGLOBAL> CreateGlobalDevModeAndInit(
|
||||
//------------------------------------------------------------------
|
||||
// helper
|
||||
static void GetDefaultPrinterNameFromGlobalPrinters(nsAString& aPrinterName) {
|
||||
aPrinterName.Truncate();
|
||||
nsCOMPtr<nsIPrinterList> printerList =
|
||||
do_GetService("@mozilla.org/gfx/printerlist;1");
|
||||
if (printerList) {
|
||||
nsIPrinter* printer = nullptr;
|
||||
printerList->GetSystemDefaultPrinter(&printer);
|
||||
if (printer) {
|
||||
printer->GetName(aPrinterName);
|
||||
}
|
||||
printerList->GetSystemDefaultPrinterName(aPrinterName);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user