diff -Nur gnome-cups-manager-0.31/gnome-cups-add/add-printer.c gnome-cups-manager-0.31.new/gnome-cups-add/add-printer.c --- gnome-cups-manager-0.31/gnome-cups-add/add-printer.c 2006-05-12 11:08:09.000000000 +0200 +++ gnome-cups-add/add-printer.c 2006-05-12 11:08:12.000000000 +0200 @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -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: amos.brocco@unifr.ch + +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,41 +205,174 @@ 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,_("Printer name cannot be empty.")); + 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,_("Printer name contains invalid characters or spaces.")); + 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); if (add_cups_printer (xml, uri, ppd, name)) { 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[] = { @@ -226,6 +392,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 } }; diff -Nur gnome-cups-manager-0.31/gnome-cups-add/druid-helper.c gnome-cups-manager-0.31.new/gnome-cups-add/druid-helper.c --- gnome-cups-manager-0.31/gnome-cups-add/druid-helper.c 2004-08-19 01:48:44.000000000 +0200 +++ gnome-cups-add/druid-helper.c 2006-05-12 11:08:12.000000000 +0200 @@ -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 + + } } diff -Nur gnome-cups-manager-0.31/gnome-cups-add/gnome-cups-add.glade gnome-cups-manager-0.31.new/gnome-cups-add/gnome-cups-add.glade --- gnome-cups-manager-0.31/gnome-cups-add/gnome-cups-add.glade 2004-08-30 22:32:42.000000000 +0200 +++ gnome-cups-add/gnome-cups-add.glade 2006-05-12 11:08:12.000000000 +0200 @@ -18,6 +18,8 @@ False GDK_WINDOW_TYPE_HINT_NORMAL GDK_GRAVITY_NORTH_WEST + True + False @@ -28,7 +30,7 @@ True - Step 1 of 2: Printer Connection + Step 1 of 3: Printer Connection gnome-cups-add-druid.png @@ -51,6 +53,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 4 @@ -81,11 +87,11 @@ True - Step 2 of 2: Printer Driver + Step 2 of 3: Printer Driver gnome-cups-add-druid.png - + 16 True False @@ -109,6 +115,257 @@ + + + + True + Step 3 of 3: Printer Information + gnome-cups-add-druid.png + + + + 16 + True + False + 6 + + + + True + 5 + 2 + False + 4 + 4 + + + + True + + + 0 + 2 + 2 + 3 + + + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 2 + 0 + 1 + + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 2 + 3 + 4 + + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 2 + 4 + 5 + + + + + + + True + _Location: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + printer-location-entry + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 4 + 5 + fill + + + + + + + True + _Description: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + printer-description-entry + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 3 + 4 + fill + + + + + + + True + + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 1 + 2 + 1 + 2 + fill + + + + + + + True + _Name: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + printer-name-entry + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + 0 + False + False + + + + + +