Skip to content

Commit 74c11fc

Browse files
Always query current CUPS default printer
When asked for the default printer, always query and return the current CUPS default printer instead of whatever was the default last time this was done, to take into account that the CUPS default printer can change while the backend is running. Sample steps (without this commit in place) to reproduce an incorrect default printer being returned with cpdb-text-frontend from cpdb-libs, when the PDF printer is initially set as default: Run cpdb-text-frontend: $ cpdb-text-frontend Query for the default printer > get-default-printer PDF#CUPS Now, switch the CUPS user default printer to another one: $ lpoptions -d somedummy In the running cpdb-text-frontend instance, query the default printer again: > get-default-printer PDF#CUPS -> The outdated/previous default printer was returned. With this commit in place, the new default printer is now returned as expected: > get-default-printer somedummy#CUPS (This addresses part of issue 3) from comment [1] on the pending change to update CPDB support in LibreOffice.) [1] https://gerrit.libreoffice.org/c/core/+/169617/comments/3ef76e40_4f120b66
1 parent e070b86 commit 74c11fc

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/backend_helper.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ BackendObj *get_new_BackendObj()
3535
/** Don't free the returned value; it is owned by BackendObj */
3636
char *get_default_printer(BackendObj *b)
3737
{
38-
/** If it was previously querie, don't query again */
39-
if (b->default_printer)
40-
{
41-
return b->default_printer;
42-
}
43-
4438
/**first query to see if the user default printer is set**/
4539
int num_dests;
4640
cups_dest_t *dests;
@@ -51,6 +45,7 @@ char *get_default_printer(BackendObj *b)
5145
/** Return the user default printer */
5246
char *def = g_strdup(dest->name);
5347
cupsFreeDests(num_dests, dests);
48+
g_free(b->default_printer);
5449
b->default_printer = def;
5550
return def;
5651
}
@@ -65,12 +60,14 @@ char *get_default_printer(BackendObj *b)
6560
if ((attr = ippFindAttribute(response, "printer-name",
6661
IPP_TAG_NAME)) != NULL)
6762
{
63+
g_free(b->default_printer);
6864
b->default_printer = g_strdup(ippGetString(attr, 0, NULL));
6965
ippDelete(response);
7066
return b->default_printer;
7167
}
7268
}
7369
ippDelete(response);
70+
g_free(b->default_printer);
7471
b->default_printer = g_strdup("NA");
7572
return b->default_printer;
7673
}

0 commit comments

Comments
 (0)