summaryrefslogtreecommitdiff
path: root/arch/common/printers.h
diff options
context:
space:
mode:
Diffstat (limited to 'arch/common/printers.h')
-rw-r--r--arch/common/printers.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/arch/common/printers.h b/arch/common/printers.h
new file mode 100644
index 00000000..8632ea18
--- /dev/null
+++ b/arch/common/printers.h
@@ -0,0 +1,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");
+ }
+}