mirror of
https://github.com/FreeRDP/FreeRDP.git
synced 2024-12-04 15:23:32 +08:00
Manage default printer for the win backend (#8177)
* printer_win: Retrieve default printer name * printer_win: Declare the local default printer as default * printer_cups: Retrieve default printer name * printer_cups: Declare the local default printer as default
This commit is contained in:
parent
fd96ed0acd
commit
06827774b6
@ -46,6 +46,7 @@ typedef struct
|
|||||||
|
|
||||||
int id_sequence;
|
int id_sequence;
|
||||||
size_t references;
|
size_t references;
|
||||||
|
char* defaultPrinter;
|
||||||
} rdpCupsPrinterDriver;
|
} rdpCupsPrinterDriver;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@ -276,7 +277,7 @@ static void printer_cups_release_ref_printer(rdpPrinter* printer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static rdpPrinter* printer_cups_new_printer(rdpCupsPrinterDriver* cups_driver, const char* name,
|
static rdpPrinter* printer_cups_new_printer(rdpCupsPrinterDriver* cups_driver, const char* name,
|
||||||
const char* driverName, BOOL is_default)
|
const char* driverName)
|
||||||
{
|
{
|
||||||
rdpCupsPrinter* cups_printer;
|
rdpCupsPrinter* cups_printer;
|
||||||
|
|
||||||
@ -298,7 +299,7 @@ static rdpPrinter* printer_cups_new_printer(rdpCupsPrinterDriver* cups_driver, c
|
|||||||
if (!cups_printer->printer.driver)
|
if (!cups_printer->printer.driver)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
cups_printer->printer.is_default = is_default;
|
cups_printer->printer.is_default = strcmp(name, cups_driver->defaultPrinter) == 0;
|
||||||
|
|
||||||
cups_printer->printer.CreatePrintJob = printer_cups_create_printjob;
|
cups_printer->printer.CreatePrintJob = printer_cups_create_printjob;
|
||||||
cups_printer->printer.FindPrintJob = printer_cups_find_printjob;
|
cups_printer->printer.FindPrintJob = printer_cups_find_printjob;
|
||||||
@ -351,8 +352,8 @@ static rdpPrinter** printer_cups_enum_printers(rdpPrinterDriver* driver)
|
|||||||
{
|
{
|
||||||
if (dest->instance == NULL)
|
if (dest->instance == NULL)
|
||||||
{
|
{
|
||||||
rdpPrinter* current = printer_cups_new_printer((rdpCupsPrinterDriver*)driver,
|
rdpPrinter* current =
|
||||||
dest->name, NULL, dest->is_default);
|
printer_cups_new_printer((rdpCupsPrinterDriver*)driver, dest->name, NULL);
|
||||||
if (!current)
|
if (!current)
|
||||||
{
|
{
|
||||||
printer_cups_release_enum_printers(printers);
|
printer_cups_release_enum_printers(printers);
|
||||||
@ -383,8 +384,7 @@ static rdpPrinter* printer_cups_get_printer(rdpPrinterDriver* driver, const char
|
|||||||
rdpCupsPrinterDriver* cups_driver = (rdpCupsPrinterDriver*)driver;
|
rdpCupsPrinterDriver* cups_driver = (rdpCupsPrinterDriver*)driver;
|
||||||
|
|
||||||
WINPR_ASSERT(cups_driver);
|
WINPR_ASSERT(cups_driver);
|
||||||
return printer_cups_new_printer(cups_driver, name, driverName,
|
return printer_cups_new_printer(cups_driver, name, driverName);
|
||||||
cups_driver->id_sequence == 1 ? TRUE : FALSE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void printer_cups_add_ref_driver(rdpPrinterDriver* driver)
|
static void printer_cups_add_ref_driver(rdpPrinterDriver* driver)
|
||||||
@ -407,6 +407,7 @@ static void printer_cups_release_ref_driver(rdpPrinterDriver* driver)
|
|||||||
{
|
{
|
||||||
if (uniq_cups_driver == cups_driver)
|
if (uniq_cups_driver == cups_driver)
|
||||||
uniq_cups_driver = NULL;
|
uniq_cups_driver = NULL;
|
||||||
|
free(cups_driver->defaultPrinter);
|
||||||
free(cups_driver);
|
free(cups_driver);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -430,6 +431,13 @@ rdpPrinterDriver* cups_freerdp_printer_client_subsystem_entry(void)
|
|||||||
uniq_cups_driver->driver.ReleaseRef = printer_cups_release_ref_driver;
|
uniq_cups_driver->driver.ReleaseRef = printer_cups_release_ref_driver;
|
||||||
|
|
||||||
uniq_cups_driver->id_sequence = 1;
|
uniq_cups_driver->id_sequence = 1;
|
||||||
|
uniq_cups_driver->defaultPrinter = _strdup(cupsGetDefault());
|
||||||
|
|
||||||
|
if (!uniq_cups_driver->defaultPrinter)
|
||||||
|
{
|
||||||
|
free(uniq_cups_driver);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WINPR_ASSERT(uniq_cups_driver->driver.AddRef);
|
WINPR_ASSERT(uniq_cups_driver->driver.AddRef);
|
||||||
|
@ -52,6 +52,7 @@ typedef struct
|
|||||||
|
|
||||||
size_t id_sequence;
|
size_t id_sequence;
|
||||||
size_t references;
|
size_t references;
|
||||||
|
LPWSTR defaultPrinter;
|
||||||
} rdpWinPrinterDriver;
|
} rdpWinPrinterDriver;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@ -233,7 +234,7 @@ static void printer_win_release_ref_printer(rdpPrinter* printer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static rdpPrinter* printer_win_new_printer(rdpWinPrinterDriver* win_driver, const WCHAR* name,
|
static rdpPrinter* printer_win_new_printer(rdpWinPrinterDriver* win_driver, const WCHAR* name,
|
||||||
const WCHAR* drivername, BOOL is_default)
|
const WCHAR* drivername)
|
||||||
{
|
{
|
||||||
rdpWinPrinter* win_printer;
|
rdpWinPrinter* win_printer;
|
||||||
DWORD needed = 0;
|
DWORD needed = 0;
|
||||||
@ -251,7 +252,7 @@ static rdpPrinter* printer_win_new_printer(rdpWinPrinterDriver* win_driver, cons
|
|||||||
|
|
||||||
if (!win_printer->printer.name)
|
if (!win_printer->printer.name)
|
||||||
goto fail;
|
goto fail;
|
||||||
win_printer->printer.is_default = is_default;
|
win_printer->printer.is_default = _wcscmp(name, win_driver->defaultPrinter) == 0;
|
||||||
|
|
||||||
win_printer->printer.CreatePrintJob = printer_win_create_printjob;
|
win_printer->printer.CreatePrintJob = printer_win_create_printjob;
|
||||||
win_printer->printer.FindPrintJob = printer_win_find_printjob;
|
win_printer->printer.FindPrintJob = printer_win_find_printjob;
|
||||||
@ -345,7 +346,7 @@ static rdpPrinter** printer_win_enum_printers(rdpPrinterDriver* driver)
|
|||||||
{
|
{
|
||||||
rdpPrinter* current = printers[num_printers];
|
rdpPrinter* current = printers[num_printers];
|
||||||
current = printer_win_new_printer((rdpWinPrinterDriver*)driver, prninfo[i].pPrinterName,
|
current = printer_win_new_printer((rdpWinPrinterDriver*)driver, prninfo[i].pPrinterName,
|
||||||
prninfo[i].pDriverName, 0);
|
prninfo[i].pDriverName);
|
||||||
if (!current)
|
if (!current)
|
||||||
{
|
{
|
||||||
printer_win_release_enum_printers(printers);
|
printer_win_release_enum_printers(printers);
|
||||||
@ -385,8 +386,7 @@ static rdpPrinter* printer_win_get_printer(rdpPrinterDriver* driver, const char*
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
myPrinter = printer_win_new_printer(win_driver, nameW, driverNameW,
|
myPrinter = printer_win_new_printer(win_driver, nameW, driverNameW);
|
||||||
win_driver->id_sequence == 1 ? TRUE : FALSE);
|
|
||||||
free(driverNameW);
|
free(driverNameW);
|
||||||
free(nameW);
|
free(nameW);
|
||||||
|
|
||||||
@ -408,6 +408,7 @@ static void printer_win_release_ref_driver(rdpPrinterDriver* driver)
|
|||||||
rdpWinPrinterDriver* win = (rdpWinPrinterDriver*)driver;
|
rdpWinPrinterDriver* win = (rdpWinPrinterDriver*)driver;
|
||||||
if (win->references <= 1)
|
if (win->references <= 1)
|
||||||
{
|
{
|
||||||
|
free(win->defaultPrinter);
|
||||||
free(win);
|
free(win);
|
||||||
win_driver = NULL;
|
win_driver = NULL;
|
||||||
}
|
}
|
||||||
@ -417,6 +418,8 @@ static void printer_win_release_ref_driver(rdpPrinterDriver* driver)
|
|||||||
|
|
||||||
rdpPrinterDriver* win_freerdp_printer_client_subsystem_entry(void)
|
rdpPrinterDriver* win_freerdp_printer_client_subsystem_entry(void)
|
||||||
{
|
{
|
||||||
|
DWORD size;
|
||||||
|
|
||||||
if (!win_driver)
|
if (!win_driver)
|
||||||
{
|
{
|
||||||
win_driver = (rdpWinPrinterDriver*)calloc(1, sizeof(rdpWinPrinterDriver));
|
win_driver = (rdpWinPrinterDriver*)calloc(1, sizeof(rdpWinPrinterDriver));
|
||||||
@ -432,6 +435,21 @@ rdpPrinterDriver* win_freerdp_printer_client_subsystem_entry(void)
|
|||||||
win_driver->driver.ReleaseRef = printer_win_release_ref_driver;
|
win_driver->driver.ReleaseRef = printer_win_release_ref_driver;
|
||||||
|
|
||||||
win_driver->id_sequence = 1;
|
win_driver->id_sequence = 1;
|
||||||
|
|
||||||
|
GetDefaultPrinter(NULL, &size);
|
||||||
|
if (size)
|
||||||
|
{
|
||||||
|
win_driver->defaultPrinter = (LPWSTR)calloc(size, sizeof(WCHAR));
|
||||||
|
|
||||||
|
if (!win_driver->defaultPrinter)
|
||||||
|
{
|
||||||
|
free(win_driver);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!GetDefaultPrinter(win_driver->defaultPrinter, &size))
|
||||||
|
win_driver->defaultPrinter[0] = "\0";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
win_driver->driver.AddRef(&win_driver->driver);
|
win_driver->driver.AddRef(&win_driver->driver);
|
||||||
|
Loading…
Reference in New Issue
Block a user