Package: gnome-cups-manager Version: 0.31-3 Severity: wishlist Tags: patch
In some environments is extremely important specify the printer name because of the high number of printers wich are equal. For example, where I work we have five Lexmark Optra-E321 (all of them shared in the network) and frequently the users have troubles to find what printer they want use because gnome-cups-manager automatically specify the printer name. Is much more easy to user understands if the name of the printer is auto-clarifying: - E321-MarketingDept, E321-FinancialDept instead Optra-E321-1, Optra-E321-2, Optra-E321-3 etc. The attached patch, created by Amos Brocco, allow a 3rd step in gnome-cups-add to change the printer name. Currently its used by gnome-cups-manager from Ubuntu. I just added some changes on pt_BR language on original patch. Thanks Matheus Morais
--- gnome-cups-add/add-printer.c 2005-03-03 15:54:25.000000000 +0100 +++ gnome-cups-add/add-printer.c 2006-03-23 01:30:07.000000000 +0100 @@ -7,6 +7,7 @@ #include <cups/ipp.h> #include <unistd.h> #include <sys/types.h> +#include <glib.h> #include <gtk/gtkhbox.h> #include <gtk/gtkliststore.h> @@ -96,6 +97,7 @@ } set_selected_uri (xml, uri); + g_free (uri); return res; } @@ -113,23 +115,50 @@ static void driver_page_sensitivity (GladeXML *xml, gboolean *back, gboolean *next) { - GtkWidget *druid = glade_xml_get_widget (xml, "add_printer_druid"); *back = TRUE; *next = NULL != gcups_driver_selector_get (driver_selector (xml)); - /* see driver_page_prepare for an explanation of the druid hack */ - gnome_druid_set_show_finish (GNOME_DRUID (druid), *next); + GCupsPPD const *ppd = gcups_driver_selector_get (driver_selector (xml)); + + if (ppd && ppd->model) { + g_signal_handlers_block_by_func(glade_xml_get_widget (xml, "printer-name-entry"), G_CALLBACK (druid_update_sensitivities), xml); + GtkEntry *printer_name_entry = (GtkEntry*) glade_xml_get_widget(xml, "printer-name-entry"); + /* Clear invalid names (spaces + slashes) so that the default is always a valid one */ + char *name, *ptr; + name = g_strdup(ppd->model); + + for (ptr = name ; *ptr ; ptr++) + if (*ptr == ' ' || *ptr == '/') + *ptr = '-'; + + gtk_entry_set_text(printer_name_entry, name); + + g_free(name); + g_signal_handlers_unblock_by_func(glade_xml_get_widget (xml, "printer-name-entry"), G_CALLBACK (druid_update_sensitivities), xml); + } } + static GtkWidget * driver_page_back (GladeXML *xml) { return glade_xml_get_widget (xml, "connection_page"); } + +// This function is just a 'fake' to avoid conflicts during compilation with debian patch properties_on_add.patch static gboolean add_cups_printer (GladeXML *xml, char const *device_uri, GCupsPPD const *ppd, char const *printer_name) { + return FALSE; +} +// Note: The (debian/ubuntu) packager needs to fix this conflict by removing properties_on_add.patch +// and rename the function extended_add_cups_printer to add_cups_printer +// for questions feel free to contact me: [EMAIL PROTECTED] + +static gboolean +extended_add_cups_printer (GladeXML *xml, char const *device_uri, GCupsPPD const *ppd, char const *printer_name, char const *printer_info, char const *printer_location) +{ GError *err = NULL; char local_uri [HTTP_MAX_URI+1]; ipp_t *request = gnome_cups_request_new (CUPS_ADD_PRINTER); @@ -139,6 +168,10 @@ "printer-uri", NULL, local_uri); ippAddString (request, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-name", NULL, gnome_cups_strdup (printer_name)); + ippAddString (request, IPP_TAG_PRINTER, IPP_TAG_TEXT, + "printer-info", NULL, printer_info); + ippAddString (request, IPP_TAG_PRINTER, IPP_TAG_TEXT, + "printer-location", NULL, printer_location); ippAddString (request, IPP_TAG_PRINTER, IPP_TAG_NAME, "ppd-name", NULL, gnome_cups_strdup (ppd->filename)); ippAddString (request, IPP_TAG_PRINTER, IPP_TAG_URI, @@ -172,27 +205,138 @@ static GtkWidget * driver_page_next (GladeXML *xml) { - GList *existing; char *name, *uri, *ptr; - unsigned i = 0; GCupsPPD const *ppd = gcups_driver_selector_get (driver_selector (xml)); - + GtkWidget *res = NULL; + if (ppd == NULL) return NULL; uri = get_selected_uri (xml); - name = g_strdup (ppd->model); - /* strip out the spaces */ - for (ptr = name ; *ptr ; ptr++) - if (*ptr == ' ') - *ptr = '-'; + if (uri != NULL) { + res = glade_xml_get_widget (xml, "printer_info_page"); + } + + g_free (uri); + return res; +} + +/****************************************************************************/ + +static void +printer_info_page_setup (GladeXML *xml) +{ + GtkWidget *w = glade_xml_get_widget (xml, "printer-name-entry"); + g_signal_connect_swapped (w, + "changed", + G_CALLBACK (druid_update_sensitivities), xml); +} + +static gboolean +check_printer_name(GladeXML *xml) +{ + /* Checks whether the name is correctly filled */ + GtkEntry *printer_name_entry = (GtkEntry *)glade_xml_get_widget (xml, "printer-name-entry"); + GtkLabel *warnings_label = (GtkLabel *)glade_xml_get_widget (xml, "warnings-label"); + + char *printer_name, *ptr; + gboolean has_invalid_chars = FALSE; + unsigned i = 0; + + printer_name = g_strchomp(g_strdup(gtk_entry_get_text(printer_name_entry))); + + if(!strlen(printer_name)) { + gtk_label_set_markup(warnings_label,_("<i>Printer name cannot be empty.</i>")); + g_free (printer_name); + return FALSE; + } + + /* Checks that the name contains no spaces or slashes (cf. Ubuntu Bug #32085) */ + for (ptr = printer_name ; *ptr ; ptr++) + if (*ptr == ' ' || *ptr == '/') { + has_invalid_chars = TRUE; + break; + } + + + /* If the name is not valid show a warning message */ + if(has_invalid_chars) { + gtk_label_set_markup(warnings_label,_("<i>Printer name contains invalid characters or spaces.</i>")); + g_free (printer_name); + return FALSE; + } + + + g_free (printer_name); + gtk_label_set_markup(warnings_label,""); + return TRUE; +} + +static void +printer_info_page_sensitivity (GladeXML *xml, gboolean *back, gboolean *next) +{ + GtkWidget *druid = glade_xml_get_widget (xml, "add_printer_druid"); + *back = TRUE; + *next = FALSE != check_printer_name (xml); + + /* see driver_page_prepare for an explanation of the druid hack */ + gnome_druid_set_show_finish (GNOME_DRUID (druid), *next); +} + +static GtkWidget * +printer_info_page_back (GladeXML *xml) +{ + return glade_xml_get_widget (xml, "driver_page"); +} + + +static void +printer_info_page_prepare (GladeXML *xml) +{ + /* The printer name defaults to the printer model */ + GtkEntry *printer_name_entry = (GtkEntry*) glade_xml_get_widget(xml, "printer-name-entry"); + GCupsPPD const *ppd = gcups_driver_selector_get (driver_selector (xml)); + GtkLabel *warnings_label = (GtkLabel *)glade_xml_get_widget (xml, "warnings-label"); + char *name; + + gtk_misc_set_alignment(GTK_MISC(warnings_label), 0.0f, 0.0f); + + name = g_strdup(gtk_entry_get_text(printer_name_entry)); + + if(!strlen(name)) + gtk_entry_set_text(printer_name_entry, ppd->model); + + g_free(name); +} + +static GtkWidget * +printer_info_page_next (GladeXML *xml) +{ + GCupsPPD const *ppd = gcups_driver_selector_get (driver_selector (xml)); + char *original_name, *name, *uri, *description, *location; + GtkEntry *printer_name_entry = (GtkEntry*) glade_xml_get_widget(xml, "printer-name-entry"); + GtkEntry *printer_description_entry = (GtkEntry*) glade_xml_get_widget(xml, "printer-description-entry"); + GtkEntry *printer_location_entry = (GtkEntry*) glade_xml_get_widget(xml, "printer-location-entry"); + GtkWidget *parent_window = glade_xml_get_widget (xml, "add_printer_window"); + GList *existing; + unsigned i = 0; + gboolean name_changed = FALSE; + + uri = get_selected_uri (xml); + name = g_strchomp(g_strdup(gtk_entry_get_text(printer_name_entry))); + description = g_strchomp(g_strdup(gtk_entry_get_text(printer_description_entry))); + location = g_strchomp(g_strdup(gtk_entry_get_text(printer_location_entry))); + original_name = g_strchomp(g_strdup(gtk_entry_get_text(printer_name_entry))); existing = gnome_cups_get_printers (); + while (NULL != g_list_find_custom (existing, name, (GCompareFunc)strcasecmp )) { g_free (name); - name = g_strdup_printf ("%s-%d", ppd->model, ++i); - } + name = g_strdup_printf ("%s-%d", original_name, ++i); + name_changed = TRUE; + } + g_list_foreach (existing, (GFunc)g_free, NULL); g_list_free (existing); @@ -204,14 +348,36 @@ gtk_widget_destroy (toplevel); g_object_unref (xml); gtk_main_quit (); - } + } // The above code (in the if) will never be executed: leaved to make a patch happy (see explication above) + + if(name_changed) { + GtkWidget *dialog; + + dialog = gtk_message_dialog_new + (GTK_WINDOW (parent_window), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_INFO, GTK_BUTTONS_OK, + _("Printer '%s' is already installed on this system. This printer has been renamed to '%s'."), + original_name, + name); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + } + + if (extended_add_cups_printer (xml, uri, ppd, name, description, location)) { + g_object_unref (xml); + gtk_main_quit (); + } g_free (uri); g_free (name); - + g_free (description); + g_free (location); + g_free (original_name); return NULL; } + /****************************************************************************/ static DruidPageDescription pages[] = { @@ -231,6 +397,14 @@ driver_page_back, driver_page_next }, + { + "printer_info_page", + printer_info_page_setup, + printer_info_page_prepare, + printer_info_page_sensitivity, + printer_info_page_back, + printer_info_page_next + }, { NULL } }; --- gnome-cups-add/druid-helper.c 2004-08-19 01:48:44.000000000 +0200 +++ gnome-cups-add/druid-helper.c 2006-03-21 19:59:34.000000000 +0100 @@ -120,6 +120,7 @@ G_CALLBACK (druid_page_back_cb), p); } + if (p->next) { g_signal_connect (page, "next", G_CALLBACK (druid_page_next_cb), @@ -128,6 +129,22 @@ G_CALLBACK (druid_page_next_cb), p); } + +#if 0 + if (p->next) { + g_signal_connect (page, "next", + G_CALLBACK (druid_page_next_cb), + p); + } + + if (!p->next) { + g_signal_connect (page, "finish", + G_CALLBACK (druid_page_next_cb), + p); + } +#endif + + } } --- gnome-cups-add/gnome-cups-add.glade 2004-08-30 22:32:42.000000000 +0200 +++ gnome-cups-add/gnome-cups-add.glade 2006-03-23 01:38:43.000000000 +0100 @@ -18,6 +18,8 @@ <property name="skip_pager_hint">False</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property> + <property name="focus_on_map">True</property> + <property name="urgency_hint">False</property> <child> <widget class="GnomeDruid" id="add_printer_druid"> @@ -28,7 +30,7 @@ <child> <widget class="GnomeDruidPageStandard" id="connection_page"> <property name="visible">True</property> - <property name="title" translatable="yes">Step 1 of 2: Printer Connection</property> + <property name="title" translatable="yes">Step 1 of 3: Printer Connection</property> <property name="logo">gnome-cups-add-druid.png</property> <child internal-child="vbox"> @@ -51,6 +53,10 @@ <property name="yalign">0.5</property> <property name="xpad">0</property> <property name="ypad">0</property> + <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> + <property name="width_chars">-1</property> + <property name="single_line_mode">False</property> + <property name="angle">0</property> </widget> <packing> <property name="padding">4</property> @@ -81,11 +87,11 @@ <child> <widget class="GnomeDruidPageStandard" id="driver_page"> <property name="visible">True</property> - <property name="title" translatable="yes">Step 2 of 2: Printer Driver</property> + <property name="title" translatable="yes">Step 2 of 3: Printer Driver</property> <property name="logo">gnome-cups-add-druid.png</property> <child internal-child="vbox"> - <widget class="GtkVBox" id="druid-vbox101"> + <widget class="GtkVBox" id="druid-vbox103"> <property name="border_width">16</property> <property name="visible">True</property> <property name="homogeneous">False</property> @@ -109,6 +115,257 @@ </child> </widget> </child> + + <child> + <widget class="GnomeDruidPageStandard" id="printer_info_page"> + <property name="visible">True</property> + <property name="title" translatable="yes">Step 3 of 3: Printer Information</property> + <property name="logo">gnome-cups-add-druid.png</property> + + <child internal-child="vbox"> + <widget class="GtkVBox" id="druid-vbox2"> + <property name="border_width">16</property> + <property name="visible">True</property> + <property name="homogeneous">False</property> + <property name="spacing">6</property> + + <child> + <widget class="GtkTable" id="table1"> + <property name="visible">True</property> + <property name="n_rows">5</property> + <property name="n_columns">2</property> + <property name="homogeneous">False</property> + <property name="row_spacing">4</property> + <property name="column_spacing">4</property> + + <child> + <widget class="GtkHSeparator" id="hseparator1"> + <property name="visible">True</property> + </widget> + <packing> + <property name="left_attach">0</property> + <property name="right_attach">2</property> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> + </packing> + </child> + + <child> + <widget class="GtkLabel" id="label30"> + <property name="visible">True</property> + <property name="label" translatable="yes"></property> + <property name="use_underline">False</property> + <property name="use_markup">False</property> + <property name="justify">GTK_JUSTIFY_LEFT</property> + <property name="wrap">False</property> + <property name="selectable">False</property> + <property name="xalign">0</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> + <property name="width_chars">-1</property> + <property name="single_line_mode">False</property> + <property name="angle">0</property> + </widget> + <packing> + <property name="left_attach">0</property> + <property name="right_attach">1</property> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> + <property name="x_options">fill</property> + <property name="y_options"></property> + </packing> + </child> + + <child> + <widget class="GtkEntry" id="printer-name-entry"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="editable">True</property> + <property name="visibility">True</property> + <property name="max_length">0</property> + <property name="text" translatable="yes"></property> + <property name="has_frame">True</property> + <property name="invisible_char">*</property> + <property name="activates_default">False</property> + </widget> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">0</property> + <property name="bottom_attach">1</property> + <property name="y_options"></property> + </packing> + </child> + + <child> + <widget class="GtkEntry" id="printer-description-entry"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="editable">True</property> + <property name="visibility">True</property> + <property name="max_length">0</property> + <property name="text" translatable="yes"></property> + <property name="has_frame">True</property> + <property name="invisible_char">*</property> + <property name="activates_default">False</property> + </widget> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">3</property> + <property name="bottom_attach">4</property> + <property name="y_options"></property> + </packing> + </child> + + <child> + <widget class="GtkEntry" id="printer-location-entry"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="editable">True</property> + <property name="visibility">True</property> + <property name="max_length">0</property> + <property name="text" translatable="yes"></property> + <property name="has_frame">True</property> + <property name="invisible_char">*</property> + <property name="activates_default">False</property> + </widget> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">4</property> + <property name="bottom_attach">5</property> + <property name="y_options"></property> + </packing> + </child> + + <child> + <widget class="GtkLabel" id="label34"> + <property name="visible">True</property> + <property name="label" translatable="yes">_Location:</property> + <property name="use_underline">True</property> + <property name="use_markup">False</property> + <property name="justify">GTK_JUSTIFY_LEFT</property> + <property name="wrap">False</property> + <property name="selectable">False</property> + <property name="xalign">0</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + <property name="mnemonic_widget">printer-location-entry</property> + <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> + <property name="width_chars">-1</property> + <property name="single_line_mode">False</property> + <property name="angle">0</property> + </widget> + <packing> + <property name="left_attach">0</property> + <property name="right_attach">1</property> + <property name="top_attach">4</property> + <property name="bottom_attach">5</property> + <property name="x_options">fill</property> + <property name="y_options"></property> + </packing> + </child> + + <child> + <widget class="GtkLabel" id="label33"> + <property name="visible">True</property> + <property name="label" translatable="yes">_Description: </property> + <property name="use_underline">True</property> + <property name="use_markup">False</property> + <property name="justify">GTK_JUSTIFY_LEFT</property> + <property name="wrap">False</property> + <property name="selectable">False</property> + <property name="xalign">0</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + <property name="mnemonic_widget">printer-description-entry</property> + <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> + <property name="width_chars">-1</property> + <property name="single_line_mode">False</property> + <property name="angle">0</property> + </widget> + <packing> + <property name="left_attach">0</property> + <property name="right_attach">1</property> + <property name="top_attach">3</property> + <property name="bottom_attach">4</property> + <property name="x_options">fill</property> + <property name="y_options"></property> + </packing> + </child> + + <child> + <widget class="GtkLabel" id="warnings-label"> + <property name="visible">True</property> + <property name="label" translatable="yes"></property> + <property name="use_underline">False</property> + <property name="use_markup">True</property> + <property name="justify">GTK_JUSTIFY_LEFT</property> + <property name="wrap">False</property> + <property name="selectable">False</property> + <property name="xalign">0</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> + <property name="width_chars">-1</property> + <property name="single_line_mode">False</property> + <property name="angle">0</property> + </widget> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> + <property name="x_options">fill</property> + <property name="y_options"></property> + </packing> + </child> + + <child> + <widget class="GtkLabel" id="label31"> + <property name="visible">True</property> + <property name="label" translatable="yes">_Name:</property> + <property name="use_underline">True</property> + <property name="use_markup">False</property> + <property name="justify">GTK_JUSTIFY_LEFT</property> + <property name="wrap">False</property> + <property name="selectable">False</property> + <property name="xalign">0</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + <property name="mnemonic_widget">printer-name-entry</property> + <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> + <property name="width_chars">-1</property> + <property name="single_line_mode">False</property> + <property name="angle">0</property> + </widget> + <packing> + <property name="left_attach">0</property> + <property name="right_attach">1</property> + <property name="top_attach">0</property> + <property name="bottom_attach">1</property> + <property name="x_options">fill</property> + <property name="y_options"></property> + </packing> + </child> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + </widget> + </child> + </widget> + </child> </widget> </child> </widget> --- po/pt_BR.po 2005-03-07 13:55:33.000000000 -0300 +++ po/pt_BR.po 2007-02-27 10:58:12.000000000 -0300 @@ -27,17 +27,21 @@ msgstr "Adicionar impressora" #: gnome-cups-add/gnome-cups-add.glade.h:2 -msgid "Step 1 of 2: Printer Connection" -msgstr "Passo 1 de 2: Conexão da Impressora" +msgid "Step 1 of 3: Printer Connection" +msgstr "Passo 1 de 3: Conexão da Impressora" #: gnome-cups-add/gnome-cups-add.glade.h:3 -msgid "Step 2 of 2: Printer Driver" -msgstr "Passo 2 de 2: Driver da Impressora" +msgid "Step 2 of 3: Printer Driver" +msgstr "Passo 2 de 3: Driver da Impressora" #: gnome-cups-add/gnome-cups-add.glade.h:4 msgid "This assistant helps you set up a printer." msgstr "O assistente o ajudará a instalar uma impressora." +#: gnome-cups-add/gnome-cups-add.glade.h:5 +msgid "Step 3 of 3: Printer Information" +msgstr "Passo 3 de 3: Informações da Impressora" + #: gnome-cups-manager/gnome-cups-icon.c:72 msgid "" "Could not start the printer tray icon, because the CUPS server could not be "