1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/*
* HardInfo - Displays System Information
* Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
void
scan_printers(void)
{
GModule *cups;
static int (*cupsGetPrinters) (char ***printers) = NULL;
static char *(*cupsGetDefault) (void) = NULL;
if (printer_list)
g_free(printer_list);
if (!(cupsGetPrinters && cupsGetDefault)) {
cups = g_module_open("libcups", G_MODULE_BIND_LAZY);
if (!cups) {
printer_list = g_strdup("[Printers]\n"
"CUPS libraries cannot be found=");
return;
}
if (!g_module_symbol(cups, "cupsGetPrinters", (gpointer) & cupsGetPrinters)
|| !g_module_symbol(cups, "cupsGetDefault",
(gpointer) & cupsGetDefault)) {
printer_list =
g_strdup("[Printers]\n" "No suitable CUPS library found=");
g_module_close(cups);
return;
}
}
gchar **printers;
int noprinters, i;
const char *default_printer;
noprinters = cupsGetPrinters(&printers);
default_printer = cupsGetDefault();
if (noprinters > 0) {
printer_list = g_strdup_printf("[Printers (CUPS)]\n");
for (i = 0; i < noprinters; i++) {
printer_list = g_strconcat(printer_list, printers[i],
!strcmp(default_printer,
printers[i]) ?
"=<i>(Default)</i>\n" : "=\n",
NULL);
g_free(printers[i]);
}
} else {
printer_list = g_strdup("[Printers]\n" "No printers found");
}
}
|