GNOME Bugzilla – Bug 344074
Feature request: get printer list, and get default print
Last modified: 2011-02-04 16:10:23 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
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.
(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?
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.
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.
Created attachment 67575 [details] [review] make gtkprintbacked.h semi-private
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.
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.
Created attachment 67638 [details] [review] gtk_printer_list_all
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)
Is that already available ? (in CVS) I couldn't find it: http://cvs.gnome.org/viewcvs/gtk%2B/gtk/
it should, in gtkprinter.h
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.
I hope to get 2.9.4 out tomorrow
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).
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); }
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).
Hmm, didn't you ask for a synchronous way to obtain the list of printers ? Anyway, I'll fix the crash.
Created attachment 67948 [details] [review] untested patch Felipe, does this patch work for you ?
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)
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.
...