[gtk+] Parse lpoptions correctly
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Parse lpoptions correctly
- Date: Fri, 15 Oct 2010 21:02:07 +0000 (UTC)
commit 95e69afea83e6a43163a3c2b0d2928c9e646b77b
Author: Marek Kasik <mkasik redhat com>
Date: Fri Oct 15 12:08:12 2010 +0200
Parse lpoptions correctly
Parse options job-sheets, job-hold-until and sides correctly.
Add get_lpoption_name() for translation of lpoption names to
gtk option names. Usable for options which values don't need
conversion (e.g. number-up, number-up-layout, job-billing
and job-priority).
Rename array option_names to ppd_option_names to reflect its
purpose better. Rename get_option_name() to get_ppd_option_name()
because of the same reason.
gtk/gtkprintunixdialog.c | 7 ++
modules/printbackends/cups/gtkprintbackendcups.c | 102 +++++++++++++++++++---
2 files changed, 97 insertions(+), 12 deletions(-)
---
diff --git a/gtk/gtkprintunixdialog.c b/gtk/gtkprintunixdialog.c
index 9a1152b..23b4f20 100644
--- a/gtk/gtkprintunixdialog.c
+++ b/gtk/gtkprintunixdialog.c
@@ -2565,6 +2565,13 @@ dialog_get_number_up_layout (GtkPrintUnixDialog *dialog)
if (val == NULL)
return layout;
+ if (val[0] == '\0' && priv->options)
+ {
+ GtkPrinterOption *option = gtk_printer_option_set_lookup (priv->options, "gtk-n-up-layout");
+ if (option)
+ val = option->value;
+ }
+
enum_class = g_type_class_ref (GTK_TYPE_NUMBER_UP_LAYOUT);
enum_value = g_enum_get_value_by_nick (enum_class, val);
if (enum_value)
diff --git a/modules/printbackends/cups/gtkprintbackendcups.c b/modules/printbackends/cups/gtkprintbackendcups.c
index 7b0b0e2..2486c20 100644
--- a/modules/printbackends/cups/gtkprintbackendcups.c
+++ b/modules/printbackends/cups/gtkprintbackendcups.c
@@ -2828,13 +2828,23 @@ static const struct {
static const struct {
const char *ppd_keyword;
const char *name;
-} option_names[] = {
+} ppd_option_names[] = {
{"Duplex", "gtk-duplex" },
{"MediaType", "gtk-paper-type"},
{"InputSlot", "gtk-paper-source"},
{"OutputBin", "gtk-output-tray"},
};
+static const struct {
+ const char *lpoption;
+ const char *name;
+} lpoption_names[] = {
+ {"number-up", "gtk-n-up" },
+ {"number-up-layout", "gtk-n-up-layout"},
+ {"job-billing", "gtk-billing-info"},
+ {"job-priority", "gtk-job-prio"},
+};
+
/* keep sorted when changing */
static const char *color_option_whitelist[] = {
"BRColorEnhancement",
@@ -3350,17 +3360,33 @@ create_boolean_option (ppd_file_t *ppd_file,
}
static gchar *
-get_option_name (const gchar *keyword)
+get_ppd_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);
+ for (i = 0; i < G_N_ELEMENTS (ppd_option_names); i++)
+ if (strcmp (ppd_option_names[i].ppd_keyword, keyword) == 0)
+ return g_strdup (ppd_option_names[i].name);
return g_strdup_printf ("cups-%s", keyword);
}
+static gchar *
+get_lpoption_name (const gchar *lpoption)
+{
+ int i;
+
+ for (i = 0; i < G_N_ELEMENTS (ppd_option_names); i++)
+ if (strcmp (ppd_option_names[i].ppd_keyword, lpoption) == 0)
+ return g_strdup (ppd_option_names[i].name);
+
+ for (i = 0; i < G_N_ELEMENTS (lpoption_names); i++)
+ if (strcmp (lpoption_names[i].lpoption, lpoption) == 0)
+ return g_strdup (lpoption_names[i].name);
+
+ return g_strdup_printf ("cups-%s", lpoption);
+}
+
static int
strptr_cmp (const void *a,
const void *b)
@@ -3395,7 +3421,7 @@ handle_option (GtkPrinterOptionSet *set,
if (STRING_IN_TABLE (ppd_option->keyword, cups_option_blacklist))
return;
- name = get_option_name (ppd_option->keyword);
+ name = get_ppd_option_name (ppd_option->keyword);
option = NULL;
if (ppd_option->ui == PPD_UI_PICKONE)
@@ -3719,10 +3745,62 @@ cups_printer_get_options (GtkPrinter *printer,
if (STRING_IN_TABLE (opts[i].name, cups_option_blacklist))
continue;
- name = get_option_name (opts[i].name);
- option = gtk_printer_option_set_lookup (set, name);
- if (option)
- gtk_printer_option_set (option, opts[i].value);
+ name = get_lpoption_name (opts[i].name);
+ if (strcmp (name, "cups-job-sheets") == 0)
+ {
+ gchar **values;
+ gint num_values;
+
+ values = g_strsplit (opts[i].value, ",", 2);
+ num_values = g_strv_length (values);
+
+ option = gtk_printer_option_set_lookup (set, "gtk-cover-before");
+ if (option && num_values > 0)
+ gtk_printer_option_set (option, g_strstrip (values[0]));
+
+ option = gtk_printer_option_set_lookup (set, "gtk-cover-after");
+ if (option && num_values > 1)
+ gtk_printer_option_set (option, g_strstrip (values[1]));
+
+ g_strfreev (values);
+ }
+ else if (strcmp (name, "cups-job-hold-until") == 0)
+ {
+ GtkPrinterOption *option2 = NULL;
+
+ option = gtk_printer_option_set_lookup (set, "gtk-print-time-text");
+ if (option && opts[i].value)
+ {
+ option2 = gtk_printer_option_set_lookup (set, "gtk-print-time");
+ if (option2)
+ {
+ if (strcmp (opts[i].value, "indefinite") == 0)
+ gtk_printer_option_set (option2, "on-hold");
+ else
+ {
+ gtk_printer_option_set (option2, "at");
+ gtk_printer_option_set (option, opts[i].value);
+ }
+ }
+ }
+ }
+ else if (strcmp (name, "cups-sides") == 0)
+ {
+ option = gtk_printer_option_set_lookup (set, "gtk-duplex");
+ if (option && opts[i].value)
+ {
+ if (strcmp (opts[i].value, "two-sided-short-edge") == 0)
+ gtk_printer_option_set (option, "DuplexTumble");
+ else if (strcmp (opts[i].value, "two-sided-long-edge") == 0)
+ gtk_printer_option_set (option, "DuplexNoTumble");
+ }
+ }
+ else
+ {
+ option = gtk_printer_option_set_lookup (set, name);
+ if (option)
+ gtk_printer_option_set (option, opts[i].value);
+ }
g_free (name);
}
@@ -3738,7 +3816,7 @@ mark_option_from_set (GtkPrinterOptionSet *set,
ppd_option_t *ppd_option)
{
GtkPrinterOption *option;
- char *name = get_option_name (ppd_option->keyword);
+ char *name = get_ppd_option_name (ppd_option->keyword);
option = gtk_printer_option_set_lookup (set, name);
@@ -3773,7 +3851,7 @@ set_conflicts_from_option (GtkPrinterOptionSet *set,
if (ppd_option->conflicted)
{
- name = get_option_name (ppd_option->keyword);
+ name = get_ppd_option_name (ppd_option->keyword);
option = gtk_printer_option_set_lookup (set, name);
if (option)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]