⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gtkprintbackendcups.c

📁 This GTK+ version 2.12.3. GTK+ is a multi-platform toolkit for creating graphical user interfaces.
💻 C
📖 第 1 页 / 共 5 页
字号:
      httpClose (http);      g_free (ppd_filename);      g_free (data);      g_signal_emit_by_name (printer, "details-acquired", FALSE);      return;    }      data->http = http;  fchmod (fd, S_IRUSR | S_IWUSR);  data->ppd_io = g_io_channel_unix_new (fd);  g_io_channel_set_encoding (data->ppd_io, NULL, NULL);  g_io_channel_set_close_on_unref (data->ppd_io, TRUE);  data->printer = g_object_ref (printer);  resource = g_strdup_printf ("/printers/%s.ppd",                               gtk_printer_cups_get_ppd_name (GTK_PRINTER_CUPS (printer)));  request = gtk_cups_request_new (data->http,                                  GTK_CUPS_GET,				  0,                                  data->ppd_io,				  cups_printer->hostname,				  resource);  GTK_NOTE (PRINTING,            g_print ("CUPS Backend: Requesting resource %s to be written to temp file %s\n", resource, ppd_filename));  g_free (resource);  g_free (ppd_filename);  cups_printer->reading_ppd = TRUE;  print_backend = gtk_printer_get_backend (printer);  cups_request_execute (GTK_PRINT_BACKEND_CUPS (print_backend),                        request,                        (GtkPrintCupsResponseCallbackFunc) cups_request_ppd_cb,                        data,                        (GDestroyNotify)get_ppd_data_free);}static voidcups_request_default_printer_cb (GtkPrintBackendCups *print_backend,				 GtkCupsResult       *result,				 gpointer             user_data){  ipp_t *response;  ipp_attribute_t *attr;  response = gtk_cups_result_get_response (result);    if ((attr = ippFindAttribute (response, "printer-name", IPP_TAG_NAME)) != NULL)    print_backend->default_printer = g_strdup (attr->values[0].string.text);  print_backend->got_default_printer = TRUE;  /* Make sure to kick off get_printers if we are polling it,    * as we could have blocked this reading the default printer    */  if (print_backend->list_printers_poll != 0)    cups_request_printer_list (print_backend);}static voidcups_request_default_printer (GtkPrintBackendCups *print_backend){  GtkCupsRequest *request;  const char *str;  if ((str = g_getenv ("LPDEST")) != NULL)    {      print_backend->default_printer = g_strdup (str);      print_backend->got_default_printer = TRUE;      return;    }  else if ((str = g_getenv ("PRINTER")) != NULL &&	   strcmp (str, "lp") != 0)    {      print_backend->default_printer = g_strdup (str);      print_backend->got_default_printer = TRUE;      return;    }    request = gtk_cups_request_new (NULL,                                  GTK_CUPS_POST,                                  CUPS_GET_DEFAULT,				  NULL,				  NULL,				  NULL);    cups_request_execute (print_backend,                        request,                        (GtkPrintCupsResponseCallbackFunc) cups_request_default_printer_cb,		        g_object_ref (print_backend),		        g_object_unref);}static voidcups_printer_request_details (GtkPrinter *printer){  GtkPrinterCups *cups_printer;  cups_printer = GTK_PRINTER_CUPS (printer);  if (!cups_printer->reading_ppd &&       gtk_printer_cups_get_ppd (cups_printer) == NULL)    cups_request_ppd (printer); }static char *ppd_text_to_utf8 (ppd_file_t *ppd_file, 		  const char *text){  const char *encoding = NULL;  char *res;    if (g_ascii_strcasecmp (ppd_file->lang_encoding, "UTF-8") == 0)    {      return g_strdup (text);    }  else if (g_ascii_strcasecmp (ppd_file->lang_encoding, "ISOLatin1") == 0)    {      encoding = "ISO-8859-1";    }  else if (g_ascii_strcasecmp (ppd_file->lang_encoding, "ISOLatin2") == 0)    {      encoding = "ISO-8859-2";    }  else if (g_ascii_strcasecmp (ppd_file->lang_encoding, "ISOLatin5") == 0)    {      encoding = "ISO-8859-5";    }  else if (g_ascii_strcasecmp (ppd_file->lang_encoding, "JIS83-RKSJ") == 0)    {      encoding = "SHIFT-JIS";    }  else if (g_ascii_strcasecmp (ppd_file->lang_encoding, "MacStandard") == 0)    {      encoding = "MACINTOSH";    }  else if (g_ascii_strcasecmp (ppd_file->lang_encoding, "WindowsANSI") == 0)    {      encoding = "WINDOWS-1252";    }  else     {      /* Fallback, try iso-8859-1... */      encoding = "ISO-8859-1";    }  res = g_convert (text, -1, "UTF-8", encoding, NULL, NULL, NULL);  if (res == NULL)    {      GTK_NOTE (PRINTING,                g_warning ("CUPS Backend: Unable to convert PPD text\n"));      res = g_strdup ("???");    }    return res;}/* TODO: Add more translations for common settings here */static const struct {  const char *keyword;  const char *translation;} cups_option_translations[] = {  { "Duplex", N_("Two Sided") },  { "MediaType", N_("Paper Type") },  { "InputSlot", N_("Paper Source") },  { "OutputBin", N_("Output Tray") },};static const struct {  const char *keyword;  const char *choice;  const char *translation;} cups_choice_translations[] = {  { "Duplex", "None", N_("One Sided") },  { "InputSlot", "Auto", N_("Auto Select") },  { "InputSlot", "AutoSelect", N_("Auto Select") },  { "InputSlot", "Default", N_("Printer Default") },  { "InputSlot", "None", N_("Printer Default") },  { "InputSlot", "PrinterDefault", N_("Printer Default") },  { "InputSlot", "Unspecified", N_("Auto Select") },};static const struct {  const char *ppd_keyword;  const char *name;} option_names[] = {  {"Duplex", "gtk-duplex" },  {"MediaType", "gtk-paper-type"},  {"InputSlot", "gtk-paper-source"},  {"OutputBin", "gtk-output-tray"},};/* keep sorted when changing */static const char *color_option_whitelist[] = {  "BRColorEnhancement",  "BRColorMatching",  "BRColorMatching",  "BRColorMode",  "BRGammaValue",  "BRImprovedGray",  "BlackSubstitution",  "ColorModel",  "HPCMYKInks",  "HPCSGraphics",  "HPCSImages",  "HPCSText",  "HPColorSmart",  "RPSBlackMode",  "RPSBlackOverPrint",  "Rcmyksimulation",};/* keep sorted when changing */static const char *color_group_whitelist[] = {  "ColorPage",  "FPColorWise1",  "FPColorWise2",  "FPColorWise3",  "FPColorWise4",  "FPColorWise5",  "HPColorOptionsPanel",};  /* keep sorted when changing */static const char *image_quality_option_whitelist[] = {  "BRDocument",  "BRHalfTonePattern",  "BRNormalPrt",  "BRPrintQuality",  "BitsPerPixel",  "Darkness",  "Dithering",  "EconoMode",  "Economode",  "HPEconoMode",  "HPEdgeControl",  "HPGraphicsHalftone",  "HPHalftone",  "HPLJDensity",  "HPPhotoHalftone",  "OutputMode",  "REt",  "RPSBitsPerPixel",  "RPSDitherType",  "Resolution",  "ScreenLock",  "Smoothing",  "TonerSaveMode",  "UCRGCRForImage",};/* keep sorted when changing */static const char *image_quality_group_whitelist[] = {  "FPImageQuality1",  "FPImageQuality2",  "FPImageQuality3",  "ImageQualityPage",};/* keep sorted when changing */static const char * finishing_option_whitelist[] = {  "BindColor",  "BindEdge",  "BindType",  "BindWhen",  "Booklet",  "FoldType",  "FoldWhen",  "HPStaplerOptions",  "Jog",  "Slipsheet",  "Sorter",  "StapleLocation",  "StapleOrientation",  "StapleWhen",  "StapleX",  "StapleY",};/* keep sorted when changing */static const char *finishing_group_whitelist[] = {  "FPFinishing1",  "FPFinishing2",  "FPFinishing3",  "FPFinishing4",  "FinishingPage",  "HPFinishingPanel",};/* keep sorted when changing */static const char *cups_option_blacklist[] = {  "Collate",  "Copies",   "OutputOrder",  "PageRegion",  "PageSize",};static char *get_option_text (ppd_file_t   *ppd_file, 		 ppd_option_t *option){  int i;  char *utf8;    for (i = 0; i < G_N_ELEMENTS (cups_option_translations); i++)    {      if (strcmp (cups_option_translations[i].keyword, option->keyword) == 0)	return g_strdup (_(cups_option_translations[i].translation));    }  utf8 = ppd_text_to_utf8 (ppd_file, option->text);  /* Some ppd files have spaces in the text before the colon */  g_strchomp (utf8);    return utf8;}static char *get_choice_text (ppd_file_t   *ppd_file, 		 ppd_choice_t *choice){  int i;  ppd_option_t *option = choice->option;  const char *keyword = option->keyword;    for (i = 0; i < G_N_ELEMENTS (cups_choice_translations); i++)    {      if (strcmp (cups_choice_translations[i].keyword, keyword) == 0 &&	  strcmp (cups_choice_translations[i].choice, choice->choice) == 0)	return g_strdup (_(cups_choice_translations[i].translation));    }  return ppd_text_to_utf8 (ppd_file, choice->text);}static gbooleangroup_has_option (ppd_group_t  *group, 		  ppd_option_t *option){  int i;  if (group == NULL)    return FALSE;    if (group->num_options > 0 &&      option >= group->options && option < group->options + group->num_options)    return TRUE;    for (i = 0; i < group->num_subgroups; i++)    {      if (group_has_option (&group->subgroups[i],option))	return TRUE;    }  return FALSE;}static voidset_option_off (GtkPrinterOption *option){  /* Any of these will do, _set only applies the value   * if its allowed of the option */  gtk_printer_option_set (option, "False");  gtk_printer_option_set (option, "Off");  gtk_printer_option_set (option, "None");}static gbooleanvalue_is_off (const char *value){  return  (strcasecmp (value, "None") == 0 ||	   strcasecmp (value, "Off") == 0 ||	   strcasecmp (value, "False") == 0);}static char *ppd_group_name (ppd_group_t *group){#if CUPS_VERSION_MAJOR > 1 || (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR > 1) || (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR == 1 && CUPS_VERSION_PATCH >= 18)   return group->name;#else  return group->text;#endif}static intavailable_choices (ppd_file_t     *ppd,		   ppd_option_t   *option,		   ppd_choice_t ***available,		   gboolean        keep_if_only_one_option){  ppd_option_t *other_option;  int i, j;  gchar *conflicts;  ppd_const_t *constraint;  const char *choice, *other_choice;  ppd_option_t *option1, *option2;  ppd_group_t *installed_options;  int num_conflicts;  gboolean all_default;  int add_auto;  if (available)    *available = NULL;  conflicts = g_new0 (char, option->num_choices);  installed_options = NULL;  for (i = 0; i < ppd->num_groups; i++)    {      char *name;       name = ppd_group_name (&ppd->groups[i]);      if (strcmp (name, "InstallableOptions") == 0)	{	  installed_options = &ppd->groups[i];	  break;	}    }  for (i = ppd->num_consts, constraint = ppd->consts; i > 0; i--, constraint++)    {      option1 = ppdFindOption (ppd, constraint->option1);      if (option1 == NULL)	continue;      option2 = ppdFindOption (ppd, constraint->option2);      if (option2 == NULL)	continue;      if (option == option1)	{	  choice = constraint->choice1;	  other_option = option2;	  other_choice = constraint->choice2;	}      else if (option == option2)	{	  choice = constraint->choice2;	  other_option = option1;	  other_choice = constraint->choice1;	}      else	continue;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -