Skip to content

Commit 69fd708

Browse files
Always query current CUPS default printer (#33)
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 3c3fc98 commit 69fd708

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

src/backend_helper.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@ BackendObj *get_new_BackendObj()
4646
/** Don't free the returned value; it is owned by BackendObj */
4747
char *get_default_printer(BackendObj *b)
4848
{
49-
/** If it was previously querie, don't query again */
50-
if (b->default_printer)
51-
{
52-
return b->default_printer;
53-
}
54-
5549
/**first query to see if the user default printer is set**/
5650
int num_dests;
5751
cups_dest_t *dests;
@@ -62,6 +56,7 @@ char *get_default_printer(BackendObj *b)
6256
/** Return the user default printer */
6357
char *def = get_printer_name_for_cups_dest(dest);
6458
cupsFreeDests(num_dests, dests);
59+
g_free(b->default_printer);
6560
b->default_printer = def;
6661
return def;
6762
}
@@ -76,12 +71,14 @@ char *get_default_printer(BackendObj *b)
7671
if ((attr = ippFindAttribute(response, "printer-name",
7772
IPP_TAG_NAME)) != NULL)
7873
{
74+
g_free(b->default_printer);
7975
b->default_printer = g_strdup(ippGetString(attr, 0, NULL));
8076
ippDelete(response);
8177
return b->default_printer;
8278
}
8379
}
8480
ippDelete(response);
81+
g_free(b->default_printer);
8582
b->default_printer = g_strdup("NA");
8683
return b->default_printer;
8784
}

0 commit comments

Comments
 (0)