After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 344074 - Feature request: get printer list, and get default print
Feature request: get printer list, and get default print
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Printing
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2006-06-06 21:30 UTC by Felipe Heidrich
Modified: 2011-02-04 16:10 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
make gtkprintbacked.h semi-private (647 bytes, patch)
2006-06-18 13:57 UTC, Christian Persch
none Details | Review
gtk_printer_list_all (3.55 KB, patch)
2006-06-19 15:54 UTC, Matthias Clasen
none Details | Review
untested patch (1.56 KB, patch)
2006-06-24 16:03 UTC, Matthias Clasen
none Details | Review

Description Felipe Heidrich 2006-06-06 21:30:09 UTC
I'm testing printing with GTK 2.9.2 and there are a couple features I need in my application and I don't think GTK support it yet.

background: I'm not using the high level printer support (GtkPrintOperation), I'm using  gtk_page_setup_unix_dialog_new(), get printer, create the job, I'm doing the whole  thing by hand.

1) I would like simple way to get a list of all printers in the system.
Maybe something like
Glist backends = gtk_print_backend_load_modules ();
for (node = backends; node != NULL; node = next)  {
	next = node->next;
	printers = gtk_print_backend_get_printer_list (GTK_PRINT_BACKEND (node->data));
}

But it would be much better if the function was synchronous, I don't want to hook "printer-added" signals and run event loops.
In my case it doesn't need to returns instances of Printer, it could return only the printer name (char*), if that the application can create a Printer using:
gtk_printer_new (const gchar *name, GtkPrintBackend *backend, gboolean virtual_);

2) A simple way to get the system default printer.
Again, it doesn't need to return the printer, just the data:
name, backend, virtual(?)

Thanks
Comment 1 Alexander Larsson 2006-06-07 12:39:21 UTC
I do think you can do this with the current APIs, but yes, it might be nice with easy-to-use helper functions for this.
Comment 2 Felipe Heidrich 2006-06-07 16:58:39 UTC
(In reply to comment #1)
> I do think you can do this with the current APIs, but yes, it might be nice
> with easy-to-use helper functions for this.

Hmm, The only way I found to do it was pretty hacky. I had to include gtkprintbackend.h, which is not export by make install, so I had to add the following line to the code:
#include "/usr/local/src/v2.9/gtk+-2.9.1/gtk/gtkprintbackend.h"
I also had to compile passing in this flags:
gcc -DGTK_PRINT_BACKEND_ENABLE_UNSUPPORTED -g -o p `pkg-config --cflags --libs gtk+-2.0 gtk+-unix-print-2.0` printTest3.c

Is there a simpler way to do it whitout using the functions defined in gtkprintbackend.h, am I missing something simple here?
Comment 3 Matthias Clasen 2006-06-08 00:22:39 UTC
Right, I guess gtkprintbackend.h should be moved to 
gtk_semi_private_h_sources:

# Installed header files without compatibility guarantees
# that are not include in gtk/gtk.h
gtk_semi_private_h_sources =    \
        gtktextlayout.h         \
        gtkfilesystem.h

You will still have to include gtkprintbackend.h explicitly and
define GTK_PRINT_BACKEND_ENABLE_UNSUPPORTED.
Comment 4 Felipe Heidrich 2006-06-15 18:12:59 UTC
Please, provide an API to create a printer without using a dialog. I know there is a gtk_printer_new(name, backend), but no API to get a backend.
Comment 5 Christian Persch 2006-06-18 13:57:08 UTC
Created attachment 67575 [details] [review]
make gtkprintbacked.h semi-private
Comment 6 Christian Persch 2006-06-18 13:58:59 UTC
I realised I need this for Epiphany too, in case the print dialogues are disabled (lockdown mode!), since gtk_print_job_send requires a GtkPrinter.
Comment 7 Matthias Clasen 2006-06-18 17:29:56 UTC
Making gtkprintbackend.h installed does not really work though, since it
requires more headers to be installed, and alex was reluctant to declare all that
api semi-public. 

I meant to look into implementing a simple, synchronous
list-all-printers method (based on the find-printers stuff in gtkprintoperation-unix.c with a recursive mainloop), but haven't gotten around 
to it.
Comment 8 Matthias Clasen 2006-06-19 15:54:19 UTC
Created attachment 67638 [details] [review]
gtk_printer_list_all
Comment 9 Matthias Clasen 2006-06-19 17:21:50 UTC
I ended up doing something slightly different, which can also be used
async.

2006-06-19  Matthias Clasen  <mclasen@redhat.com>

	* gtk/gtk.symbols: 
	* gtk/gtkprinter.h: 
	* gtk/gtkprinter.c (gtk_enumerate_printers): New function
	to list all printers (#344074, Felipe Heidrich)
Comment 10 Felipe Heidrich 2006-06-19 20:26:16 UTC
Is that already available ? (in CVS)

I couldn't find it:
http://cvs.gnome.org/viewcvs/gtk%2B/gtk/
Comment 11 Matthias Clasen 2006-06-19 21:04:51 UTC
it should, in gtkprinter.h
Comment 12 Carolyn_MacLeod 2006-06-20 22:19:01 UTC
Will the 2.9.4 drop be available soon? I am hoping to try out this api before the api freeze, and our firewall won't let me get it from CVS.
Comment 13 Matthias Clasen 2006-06-21 03:06:26 UTC
I hope to get 2.9.4 out tomorrow
Comment 14 Felipe Heidrich 2006-06-22 21:26:22 UTC
The API is there but doesn't quite work.

I call the gtk_enumerate_printers with wait=TRUE but the call doesn't return unless I generate events (mouse down, key down, mouse enter/exit).
Comment 15 Felipe Heidrich 2006-06-23 21:23:13 UTC
I was trying to use gtk_enumerate_printers to find the default printer, the basic idea is to return TRUE in my (*GtkPrinterFunc) once the default printer is found, but it causes my app to crash.

here is the stack:
-sh-3.1$ ./c
        printer Print to File default 0
        printer PRT-IBM-1140-a default 1
*** glibc detected *** ./c: double free or corruption (fasttop): 0x08b00238 ***
======= Backtrace: =========
/lib/libc.so.6[0x379f18]
/lib/libc.so.6(__libc_free+0x79)[0x37d41d]
/usr/local/gtk-2.9.4/lib/libglib-2.0.so.0(g_free+0x31)[0x221931]
/usr/local/gtk-2.9.4/lib/libgtk-x11-2.0.so.0[0xd0343b]
/usr/local/gtk-2.9.4/lib/libgobject-2.0.so.0(g_cclosure_marshal_VOID__OBJECT+0x63)[0x1c7913]
/usr/local/gtk-2.9.4/lib/libgobject-2.0.so.0(g_closure_invoke+0x11d)[0x1b9f7d]
/usr/local/gtk-2.9.4/lib/libgobject-2.0.so.0[0x1cb9ab]
/usr/local/gtk-2.9.4/lib/libgobject-2.0.so.0(g_signal_emit_valist+0x823)[0x1cce23]
/usr/local/gtk-2.9.4/lib/libgobject-2.0.so.0(g_signal_emit_by_name+0xee)[0x1ced1e]
/usr/local/gtk-2.9.4/lib/gtk-2.0/2.10.0/printbackends/libprintbackend-cups.so[0xf840ab]
/usr/local/gtk-2.9.4/lib/gtk-2.0/2.10.0/printbackends/libprintbackend-cups.so[0xf835bc]
/usr/local/gtk-2.9.4/lib/libglib-2.0.so.0(g_main_context_dispatch+0x182)[0x21a622]
/usr/local/gtk-2.9.4/lib/libglib-2.0.so.0[0x21d5ef]
/usr/local/gtk-2.9.4/lib/libglib-2.0.so.0(g_main_loop_run+0x1a9)[0x21d999]
/usr/local/gtk-2.9.4/lib/libgtk-x11-2.0.so.0(gtk_enumerate_printers+0x14e)[0xd036ae]
./c[0x80489ac]


Here is the code:
gboolean  printerCB (GtkPrinter *printer, gpointer data) {
	printf ("\tprinter %s default %d\n", gtk_printer_get_name(printer), gtk_printer_is_default(printer));
	return gtk_printer_is_default(printer);
}

int clicked (GtkWidget* widget, gpointer data) {
	gtk_enumerate_printers (printerCB, NULL, NULL, TRUE);
}


Comment 16 Felipe Heidrich 2006-06-23 21:26:14 UTC
Personally, I think you guys should get rid of wait flag (the last arg of gtk_enumerate_printers) - i know it does hurt to have it but IMO it is pretty useless (it might be my ignorance only but I can't think of a usecase where it can be useful).
Comment 17 Matthias Clasen 2006-06-24 15:54:19 UTC
Hmm, didn't you ask for a synchronous way to obtain the list of printers ?

Anyway, I'll fix the crash.
Comment 18 Matthias Clasen 2006-06-24 16:03:33 UTC
Created attachment 67948 [details] [review]
untested patch

Felipe, does this patch work for you ?
Comment 19 Matthias Clasen 2006-06-25 08:25:07 UTC
Committed a better patch

2006-06-25  Matthias Clasen  <mclasen@redhat.com>

        * gtk/gtkprinter.c (gtk_enumerate_printers): Make
        this work when the enumeration is stopped early.  (#344074,
        Felipe Heidrich)

Comment 20 Carolyn_MacLeod 2006-06-29 17:59:53 UTC
Haven't been able to test this patch because neither Felipe nor I can get GTK+ from HEAD due to firewall restrictions. Does this patch also address comment 14, which says that in order for the enumeration to complete, events must be generated? I still have that problem in 2.9.4.
Comment 21 Caolan McNamara 2006-08-11 09:27:55 UTC
...