📄 gtkprintbackendcups.c
字号:
/* We only care of conflicts with installed_options and PageSize */ if (!group_has_option (installed_options, other_option) && (strcmp (other_option->keyword, "PageSize") != 0)) continue; if (*other_choice == 0) { /* Conflict only if the installed option is not off */ if (value_is_off (other_option->defchoice)) continue; } /* Conflict if the installed option has the specified default */ else if (strcasecmp (other_choice, other_option->defchoice) != 0) continue; if (*choice == 0) { /* Conflict with all non-off choices */ for (j = 0; j < option->num_choices; j++) { if (!value_is_off (option->choices[j].choice)) conflicts[j] = 1; } } else { for (j = 0; j < option->num_choices; j++) { if (strcasecmp (option->choices[j].choice, choice) == 0) conflicts[j] = 1; } } } num_conflicts = 0; all_default = TRUE; for (j = 0; j < option->num_choices; j++) { if (conflicts[j]) num_conflicts++; else if (strcmp (option->choices[j].choice, option->defchoice) != 0) all_default = FALSE; } if ((all_default && !keep_if_only_one_option) || (num_conflicts == option->num_choices)) { g_free (conflicts); return 0; } /* Some ppds don't have a "use printer default" option for * InputSlot. This means you always have to select a particular slot, * and you can't auto-pick source based on the paper size. To support * this we always add an auto option if there isn't one already. If * the user chooses the generated option we don't send any InputSlot * value when printing. The way we detect existing auto-cases is based * on feedback from Michael Sweet of cups fame. */ add_auto = 0; if (strcmp (option->keyword, "InputSlot") == 0) { gboolean found_auto = FALSE; for (j = 0; j < option->num_choices; j++) { if (!conflicts[j]) { if (strcmp (option->choices[j].choice, "Auto") == 0 || strcmp (option->choices[j].choice, "AutoSelect") == 0 || strcmp (option->choices[j].choice, "Default") == 0 || strcmp (option->choices[j].choice, "None") == 0 || strcmp (option->choices[j].choice, "PrinterDefault") == 0 || strcmp (option->choices[j].choice, "Unspecified") == 0 || option->choices[j].code == NULL || option->choices[j].code[0] == 0) { found_auto = TRUE; break; } } } if (!found_auto) add_auto = 1; } if (available) { *available = g_new (ppd_choice_t *, option->num_choices - num_conflicts + add_auto); i = 0; for (j = 0; j < option->num_choices; j++) { if (!conflicts[j]) (*available)[i++] = &option->choices[j]; } if (add_auto) (*available)[i++] = NULL; } g_free (conflicts); return option->num_choices - num_conflicts + add_auto;}static GtkPrinterOption *create_pickone_option (ppd_file_t *ppd_file, ppd_option_t *ppd_option, const gchar *gtk_name){ GtkPrinterOption *option; ppd_choice_t **available; char *label; int n_choices; int i;#ifdef HAVE_CUPS_API_1_2 ppd_coption_t *coption;#endif g_assert (ppd_option->ui == PPD_UI_PICKONE); option = NULL; n_choices = available_choices (ppd_file, ppd_option, &available, g_str_has_prefix (gtk_name, "gtk-")); if (n_choices > 0) { /* right now only support one parameter per custom option * if more than one print warning and only offer the default choices */ label = get_option_text (ppd_file, ppd_option);#ifdef HAVE_CUPS_API_1_2 coption = ppdFindCustomOption (ppd_file, ppd_option->keyword); if (coption) { ppd_cparam_t *cparam; cparam = ppdFirstCustomParam (coption); if (ppdNextCustomParam (coption) == NULL) { switch (cparam->type) { case PPD_CUSTOM_INT: option = gtk_printer_option_new (gtk_name, label, GTK_PRINTER_OPTION_TYPE_PICKONE_INT); break; case PPD_CUSTOM_PASSCODE: option = gtk_printer_option_new (gtk_name, label, GTK_PRINTER_OPTION_TYPE_PICKONE_PASSCODE); break; case PPD_CUSTOM_PASSWORD: option = gtk_printer_option_new (gtk_name, label, GTK_PRINTER_OPTION_TYPE_PICKONE_PASSWORD); break; case PPD_CUSTOM_REAL: option = gtk_printer_option_new (gtk_name, label, GTK_PRINTER_OPTION_TYPE_PICKONE_REAL); break; case PPD_CUSTOM_STRING: option = gtk_printer_option_new (gtk_name, label, GTK_PRINTER_OPTION_TYPE_PICKONE_STRING); break;#ifdef PRINT_IGNORED_OPTIONS case PPD_CUSTOM_POINTS: g_warning ("CUPS Backend: PPD Custom Points Option not supported"); break; case PPD_CUSTOM_CURVE: g_warning ("CUPS Backend: PPD Custom Curve Option not supported"); break; case PPD_CUSTOM_INVCURVE: g_warning ("CUPS Backend: PPD Custom Inverse Curve Option not supported"); break;#endif default: break; } }#ifdef PRINT_IGNORED_OPTIONS else g_warning ("CUPS Backend: Multi-parameter PPD Custom Option not supported");#endif }#endif /* HAVE_CUPS_API_1_2 */ if (!option) option = gtk_printer_option_new (gtk_name, label, GTK_PRINTER_OPTION_TYPE_PICKONE); g_free (label); gtk_printer_option_allocate_choices (option, n_choices); for (i = 0; i < n_choices; i++) { if (available[i] == NULL) { /* This was auto-added */ option->choices[i] = g_strdup ("gtk-ignore-value"); option->choices_display[i] = g_strdup (_("Printer Default")); } else { option->choices[i] = g_strdup (available[i]->choice); option->choices_display[i] = get_choice_text (ppd_file, available[i]); } } gtk_printer_option_set (option, ppd_option->defchoice); }#ifdef PRINT_IGNORED_OPTIONS else g_warning ("CUPS Backend: Ignoring pickone %s\n", ppd_option->text);#endif g_free (available); return option;}static GtkPrinterOption *create_boolean_option (ppd_file_t *ppd_file, ppd_option_t *ppd_option, const gchar *gtk_name){ GtkPrinterOption *option; ppd_choice_t **available; char *label; int n_choices; g_assert (ppd_option->ui == PPD_UI_BOOLEAN); option = NULL; n_choices = available_choices (ppd_file, ppd_option, &available, g_str_has_prefix (gtk_name, "gtk-")); if (n_choices == 2) { label = get_option_text (ppd_file, ppd_option); option = gtk_printer_option_new (gtk_name, label, GTK_PRINTER_OPTION_TYPE_BOOLEAN); g_free (label); gtk_printer_option_allocate_choices (option, 2); option->choices[0] = g_strdup ("True"); option->choices_display[0] = g_strdup ("True"); option->choices[1] = g_strdup ("False"); option->choices_display[1] = g_strdup ("False"); gtk_printer_option_set (option, ppd_option->defchoice); }#ifdef PRINT_IGNORED_OPTIONS else g_warning ("CUPS Backend: Ignoring boolean %s\n", ppd_option->text);#endif g_free (available); return option;}static gchar *get_option_name (const gchar *keyword){ int i; for (i = 0; i < G_N_ELEMENTS (option_names); i++) if (strcmp (option_names[i].ppd_keyword, keyword) == 0) return g_strdup (option_names[i].name); return g_strdup_printf ("cups-%s", keyword);}static intstrptr_cmp (const void *a, const void *b){ char **aa = (char **)a; char **bb = (char **)b; return strcmp (*aa, *bb);}static gbooleanstring_in_table (gchar *str, const gchar *table[], gint table_len){ return bsearch (&str, table, table_len, sizeof (char *), (void *)strptr_cmp) != NULL;}#define STRING_IN_TABLE(_str, _table) (string_in_table (_str, _table, G_N_ELEMENTS (_table)))static voidhandle_option (GtkPrinterOptionSet *set, ppd_file_t *ppd_file, ppd_option_t *ppd_option, ppd_group_t *toplevel_group, GtkPrintSettings *settings){ GtkPrinterOption *option; char *name; if (STRING_IN_TABLE (ppd_option->keyword, cups_option_blacklist)) return; name = get_option_name (ppd_option->keyword); option = NULL; if (ppd_option->ui == PPD_UI_PICKONE) { option = create_pickone_option (ppd_file, ppd_option, name); } else if (ppd_option->ui == PPD_UI_BOOLEAN) { option = create_boolean_option (ppd_file, ppd_option, name); }#ifdef PRINT_IGNORED_OPTIONS else g_warning ("CUPS Backend: Ignoring pickmany setting %s\n", ppd_option->text);#endif if (option) { char *name; name = ppd_group_name (toplevel_group); if (STRING_IN_TABLE (name, color_group_whitelist) || STRING_IN_TABLE (ppd_option->keyword, color_option_whitelist)) { option->group = g_strdup ("ColorPage"); } else if (STRING_IN_TABLE (name, image_quality_group_whitelist) || STRING_IN_TABLE (ppd_option->keyword, image_quality_option_whitelist)) { option->group = g_strdup ("ImageQualityPage"); } else if (STRING_IN_TABLE (name, finishing_group_whitelist) || STRING_IN_TABLE (ppd_option->keyword, finishing_option_whitelist)) { option->group = g_strdup ("FinishingPage"); } else { option->group = g_strdup (toplevel_group->text); } set_option_from_settings (option, settings); gtk_printer_option_set_add (set, option); } g_free (name);}static voidhandle_group (GtkPrinterOptionSet *set, ppd_file_t *ppd_file, ppd_group_t *group, ppd_group_t *toplevel_group, GtkPrintSettings *settings){ gint i; gchar *name; /* Ignore installable options */ name = ppd_group_name (toplevel_group); if (strcmp (name, "InstallableOptions") == 0) return; for (i = 0; i < group->num_options; i++) handle_option (set, ppd_file, &group->options[i], toplevel_group, settings); for (i = 0; i < group->num_subgroups; i++) handle_group (set, ppd_file, &group->subgroups[i], toplevel_group, settings);}static GtkPrinterOptionSet *cups_printer_get_options (GtkPrinter *printer, GtkPrintSettings *settings, GtkPageSetup *page_setup, GtkPrintCapabilities capabilities){ GtkPrinterOptionSet *set; GtkPrinterOption *option; ppd_file_t *ppd_file; int i; char *print_at[] = { "now", "at", "on-hold" }; char *n_up[] = {"1", "2", "4", "6", "9", "16" }; char *prio[] = {"100", "80", "50", "30" }; char *prio_display[] = {N_("Urgent"), N_("High"), N_("Medium"), N_("Low") }; char *cover[] = {"none", "classified", "confidential", "secret", "standard", "topsecret", "unclassified" }; char *cover_display[] = {N_("None"), N_("Classified"), N_("Confidential"), N_("Secret"), N_("Standard"), N_("Top Secret"), N_("Unclassified"),}; set = gtk_printer_option_set_new (); /* Cups specific, non-ppd related settings */ 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); for (i = 0; i < G_N_ELEMENTS(prio_display); i++) prio_display[i] = _(prio_display[i]); option = gtk_printer_option_new ("gtk-job-prio", "Job Priority", GTK_PRINTER_OPTION_TYPE_PICKONE); gtk_printer_option_choices_from_array (option, G_N_ELEMENTS (prio), prio, prio_display); gtk_printer_option_set (option, "50"); set_option_from_settings (option, settings); gtk_printer_option_set_add (set, option); g_object_unref (option); option = gtk_printer_option_new ("gtk-billing-info", "Billing Info", GTK_PRINTER_OPTION_TYPE_STRING); gtk_printer_option_set (option, ""); set_option_from_settings (option, settings); gtk_printer_option_set_add (set, option); g_object_unref (option); for (i = 0; i < G_N_ELEMENTS(cover_display); i++) cover_display[i] = _(cover_display[i]); option = gtk_printer_option_new ("gtk-cover-before", "Before", GTK_PRINTER_OPTION_TYPE_PICKONE); gtk_printer_option_choices_from_array (option, G_N_ELEMENTS (cover), cover, cover_display); gtk_printer_option_set (option, "none"); set_option_from_settings (option, settings); gtk_printer_option_set_add (set, option); g_object_unref (option); option = gtk_printer_option_new ("gtk-cover-after", "After", GTK_PRINTER_OPTION_TYPE_PICKONE); gtk_printer_option_choices_from_array (option, G_N_ELEMENTS (cover), cover, cover_display); gtk_printer_option_set (option, "none"); set_option_from_settings (option, settings); gtk_printer_option_set_add (set, option); g_object_unref (option); option = gtk_prin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -