aboutsummaryrefslogtreecommitdiff
path: root/modules/devices/printers.c
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2024-04-22 00:35:53 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2024-04-22 00:35:53 -0300
commit5f01c706267c595de92406a32e7f31ef5056c2d0 (patch)
treed1e74ef54efc41ada622900fe3e2a50dee44a237 /modules/devices/printers.c
parent09fcc751ef158898c315ebc9299a0fa3a722d914 (diff)
New upstream version 2.0.3preupstream/2.0.3pre
Diffstat (limited to 'modules/devices/printers.c')
-rw-r--r--modules/devices/printers.c70
1 files changed, 38 insertions, 32 deletions
diff --git a/modules/devices/printers.c b/modules/devices/printers.c
index 77b52a43..fb9389ac 100644
--- a/modules/devices/printers.c
+++ b/modules/devices/printers.c
@@ -1,10 +1,10 @@
/*
* HardInfo - Displays System Information
- * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@hardinfo.org>
+ * Copyright (C) 2003-2007 L. A. F. Pereira <l@tia.mat.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.
+ * the Free Software Foundation, version 2 or later.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -16,6 +16,10 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#ifndef _XOPEN_SOURCE
+ #define _XOPEN_SOURCE
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
@@ -33,7 +37,7 @@ struct _CUPSDest {
char *name, *instance;
int is_default;
int num_options;
- CUPSOption *options;
+ CUPSOption *options;
};
static int (*cups_dests_get) (CUPSDest **dests) = NULL;
@@ -49,13 +53,13 @@ init_cups(void)
if (!(cups_dests_get && cups_dests_free)) {
int i;
-
+
for (i = 0; libcups[i] != NULL; i++) {
cups = g_module_open(libcups[i], G_MODULE_BIND_LAZY);
if (cups)
- break;
+ break;
}
-
+
if (!cups) {
cups_init = FALSE;
return;
@@ -63,11 +67,11 @@ init_cups(void)
if (!g_module_symbol(cups, "cupsGetDests", (gpointer) & cups_dests_get)
|| !g_module_symbol(cups, "cupsFreeDests", (gpointer) & cups_dests_free)) {
- g_module_close(cups);
+ if(cups) g_module_close(cups);
cups_init = FALSE;
}
}
-
+
cups_init = TRUE;
}
@@ -76,7 +80,7 @@ gchar *__cups_callback_ptype(gchar *strvalue)
if (strvalue) {
unsigned value = atoi(strvalue);
gchar *output = g_strdup("\n");
-
+
if (value & 0x0004)
output = h_strdup_cprintf(_("\342\232\254 Can do black and white printing=\n"), output);
if (value & 0x0008)
@@ -121,7 +125,7 @@ gchar *__cups_callback_state_change_time(gchar *value)
{
struct tm tm;
char buf[255];
-
+
if (value) {
strptime(value, "%s", &tm);
strftime(buf, sizeof(buf), "%c", &tm);
@@ -144,29 +148,30 @@ gchar *__cups_callback_boolean(gchar *value)
const struct {
char *key, *name;
gchar *(*callback)(gchar *value);
+ gboolean maybe_vendor;
} cups_fields[] = {
{ "Printer Information", NULL, NULL },
{ "printer-info", "Destination Name", NULL },
- { "printer-make-and-model", "Make and Model", NULL },
-
+ { "printer-make-and-model", "Make and Model", NULL, TRUE },
+
{ "Capabilities", NULL, NULL },
{ "printer-type", "#", __cups_callback_ptype },
-
+
{ "Printer State", NULL, NULL },
{ "printer-state", "State", __cups_callback_state },
{ "printer-state-change-time", "Change Time", __cups_callback_state_change_time },
{ "printer-state-reasons", "State Reasons" },
-
+
{ "Sharing Information", NULL, NULL },
{ "printer-is-shared", "Shared?", __cups_callback_boolean },
{ "printer-location", "Physical Location" },
{ "auth-info-required", "Authentication Required", __cups_callback_boolean },
-
+
{ "Jobs", NULL, NULL },
{ "job-hold-until", "Hold Until", NULL },
{ "job-priority", "Priority", NULL },
{ "printer-is-accepting-jobs", "Accepting Jobs", __cups_callback_boolean },
-
+
{ "Media", NULL, NULL },
{ "media", "Media", NULL },
{ "finishings", "Finishings", NULL },
@@ -176,7 +181,7 @@ const struct {
void
scan_printers_do(void)
{
- int num_dests, i, j;
+ guint num_dests, j, i;
CUPSDest *dests;
gchar *prn_id, *prn_moreinfo;
@@ -185,7 +190,7 @@ scan_printers_do(void)
if (!cups_init) {
init_cups();
-
+
printer_icons = g_strdup("");
printer_list = g_strdup(_("[Printers]\n"
"No suitable CUPS library found="));
@@ -201,22 +206,22 @@ scan_printers_do(void)
printer_icons = g_strdup("");
for (i = 0; i < num_dests; i++) {
GHashTable *options;
-
+
options = g_hash_table_new(g_str_hash, g_str_equal);
-
- for (j = 0; j < dests[i].num_options; j++) {
+
+ for (j = 0; (int)j < dests[i].num_options; j++) {
g_hash_table_insert(options,
g_strdup(dests[i].options[j].name),
g_strdup(dests[i].options[j].value));
}
-
+
prn_id = g_strdup_printf("PRN%d", i);
-
+
printer_list = h_strdup_cprintf("\n$%s$%s=%s\n",
printer_list,
- prn_id,
+ prn_id,
dests[i].name,
- dests[i].is_default ? "<i>Default</i>" : "");
+ dests[i].is_default ? ((params.markup_ok) ? "<i>Default</i>" : "(Default)") : "");
printer_icons = h_strdup_cprintf("\nIcon$%s$%s=printer.png",
printer_icons,
prn_id,
@@ -230,9 +235,9 @@ scan_printers_do(void)
cups_fields[j].key);
} else {
gchar *temp;
-
+
temp = g_hash_table_lookup(options, cups_fields[j].key);
-
+
if (cups_fields[j].callback) {
temp = cups_fields[j].callback(temp);
} else {
@@ -243,21 +248,22 @@ scan_printers_do(void)
temp = g_strdup(_("Unknown"));
}
}
-
- prn_moreinfo = h_strdup_cprintf("%s=%s\n",
+
+ prn_moreinfo = h_strdup_cprintf("%s%s=%s\n",
prn_moreinfo,
+ cups_fields[j].maybe_vendor ? "$^$" : "",
cups_fields[j].name,
temp);
-
+
g_free(temp);
}
}
-
+
moreinfo_add_with_prefix("DEV", prn_id, prn_moreinfo);
g_free(prn_id);
g_hash_table_destroy(options);
}
-
+
cups_dests_free(num_dests, dests);
} else {
printer_list = g_strdup(_("[Printers]\n"