printing: Get default number-up value from CUPS

Requests "number-up-default" attribute from CUPS and
uses its value for setting value of "gtk-n-up" option.
(#672993)
This commit is contained in:
Marek Kasik 2012-04-17 17:12:56 +02:00
parent 516fb89065
commit f6e2d0947d
3 changed files with 50 additions and 36 deletions

View File

@ -1737,6 +1737,7 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
gchar *default_cover_after = NULL;
gboolean remote_printer = FALSE;
gchar **auth_info_required = NULL;
gint default_number_up = 1;
/* Skip leading attributes until we hit a printer...
*/
@ -1864,6 +1865,10 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
auth_info_required[i] = g_strdup (attr->values[i].string.text);
}
}
else if (strcmp (attr->name, "number-up-default") == 0)
{
default_number_up = attr->values[0].integer;
}
else
{
GTK_NOTE (PRINTING,
@ -1988,6 +1993,8 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
cups_printer->default_cover_before = g_strdup (default_cover_before);
cups_printer->default_cover_after = g_strdup (default_cover_after);
cups_printer->default_number_up = default_number_up;
cups_printer->hostname = g_strdup (hostname);
cups_printer->port = port;
@ -2188,7 +2195,8 @@ cups_request_printer_list (GtkPrintBackendCups *cups_backend)
"job-sheets-supported",
"job-sheets-default",
"printer-type",
"auth-info-required"
"auth-info-required",
"number-up-default"
};
if (cups_backend->reading_ppds > 0 || cups_backend->list_printers_pending)
@ -3613,45 +3621,12 @@ cups_printer_get_options (GtkPrinter *printer,
#ifdef HAVE_COLORD
GtkPrintBackendCupsColordHelper *helper;
#endif
char *default_number_up;
set = gtk_printer_option_set_new ();
/* Cups specific, non-ppd related settings */
/* Translators, this string is used to label the pages-per-sheet option
* in the print dialog
*/
option = gtk_printer_option_new ("gtk-n-up", _("Pages per Sheet"), GTK_PRINTER_OPTION_TYPE_PICKONE);
gtk_printer_option_choices_from_array (option, G_N_ELEMENTS (n_up),
n_up, n_up);
gtk_printer_option_set (option, "1");
set_option_from_settings (option, settings);
gtk_printer_option_set_add (set, option);
g_object_unref (option);
if (cups_printer_get_capabilities (printer) & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT)
{
for (i = 0; i < G_N_ELEMENTS (n_up_layout_display); i++)
n_up_layout_display[i] = _(n_up_layout_display[i]);
/* Translators, this string is used to label the option in the print
* dialog that controls in what order multiple pages are arranged
*/
option = gtk_printer_option_new ("gtk-n-up-layout", _("Page Ordering"), GTK_PRINTER_OPTION_TYPE_PICKONE);
gtk_printer_option_choices_from_array (option, G_N_ELEMENTS (n_up_layout),
n_up_layout, n_up_layout_display);
text_direction = gtk_widget_get_default_direction ();
if (text_direction == GTK_TEXT_DIR_LTR)
gtk_printer_option_set (option, "lrtb");
else
gtk_printer_option_set (option, "rltb");
set_option_from_settings (option, settings);
gtk_printer_option_set_add (set, option);
g_object_unref (option);
}
for (i = 0; i < G_N_ELEMENTS(prio_display); i++)
prio_display[i] = _(prio_display[i]);
@ -3692,6 +3667,42 @@ cups_printer_get_options (GtkPrinter *printer,
gpointer value;
gint j;
/* Translators, this string is used to label the pages-per-sheet option
* in the print dialog
*/
option = gtk_printer_option_new ("gtk-n-up", _("Pages per Sheet"), GTK_PRINTER_OPTION_TYPE_PICKONE);
gtk_printer_option_choices_from_array (option, G_N_ELEMENTS (n_up),
n_up, n_up);
default_number_up = g_strdup_printf ("%d", cups_printer->default_number_up);
gtk_printer_option_set (option, default_number_up);
g_free (default_number_up);
set_option_from_settings (option, settings);
gtk_printer_option_set_add (set, option);
g_object_unref (option);
if (cups_printer_get_capabilities (printer) & GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT)
{
for (i = 0; i < G_N_ELEMENTS (n_up_layout_display); i++)
n_up_layout_display[i] = _(n_up_layout_display[i]);
/* Translators, this string is used to label the option in the print
* dialog that controls in what order multiple pages are arranged
*/
option = gtk_printer_option_new ("gtk-n-up-layout", _("Page Ordering"), GTK_PRINTER_OPTION_TYPE_PICKONE);
gtk_printer_option_choices_from_array (option, G_N_ELEMENTS (n_up_layout),
n_up_layout, n_up_layout_display);
text_direction = gtk_widget_get_default_direction ();
if (text_direction == GTK_TEXT_DIR_LTR)
gtk_printer_option_set (option, "lrtb");
else
gtk_printer_option_set (option, "rltb");
set_option_from_settings (option, settings);
gtk_printer_option_set_add (set, option);
g_object_unref (option);
}
num_of_covers = backend->number_of_covers;
cover = g_new (char *, num_of_covers + 1);
cover[num_of_covers] = NULL;

View File

@ -113,6 +113,7 @@ gtk_printer_cups_init (GtkPrinterCups *printer)
printer->get_remote_ppd_attempts = 0;
printer->remote_cups_connection_test = NULL;
printer->auth_info_required = NULL;
printer->default_number_up = 1;
}
static void

View File

@ -61,6 +61,8 @@ struct _GtkPrinterCups
gchar *default_cover_before;
gchar *default_cover_after;
gint default_number_up;
gboolean remote;
guint get_remote_ppd_poll;
gint get_remote_ppd_attempts;