1 /* GtkPrinterOptionWidget
2 * Copyright (C) 2006 Alexander Larsson <alexl@redhat.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
25 #include "gtkcheckbutton.h"
26 #include "gtkcelllayout.h"
27 #include "gtkcellrenderertext.h"
28 #include "gtkcombobox.h"
29 #include "gtkfilechooserdialog.h"
32 #include "gtkliststore.h"
33 #include "gtkradiobutton.h"
36 #include "gtktogglebutton.h"
37 #include "gtkorientable.h"
38 #include "gtkprivate.h"
40 #include "gtkprinteroptionwidget.h"
42 #define GTK_PRINTER_OPTION_WIDGET_GET_PRIVATE(o) \
43 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_PRINTER_OPTION_WIDGET, GtkPrinterOptionWidgetPrivate))
45 /* This defines the max file length that the file chooser
46 * button should display. The total length will be
47 * FILENAME_LENGTH_MAX+3 because the truncated name is prefixed
50 #define FILENAME_LENGTH_MAX 27
52 static void gtk_printer_option_widget_finalize (GObject *object);
54 static void deconstruct_widgets (GtkPrinterOptionWidget *widget);
55 static void construct_widgets (GtkPrinterOptionWidget *widget);
56 static void update_widgets (GtkPrinterOptionWidget *widget);
58 static gchar *trim_long_filename (const gchar *filename);
60 struct GtkPrinterOptionWidgetPrivate
62 GtkPrinterOption *source;
63 gulong source_changed_handler;
70 GtkWidget *info_label;
74 /* the last location for save to file, that the user selected */
88 static guint signals[LAST_SIGNAL] = { 0 };
90 G_DEFINE_TYPE (GtkPrinterOptionWidget, gtk_printer_option_widget, GTK_TYPE_BOX)
92 static void gtk_printer_option_widget_set_property (GObject *object,
96 static void gtk_printer_option_widget_get_property (GObject *object,
100 static gboolean gtk_printer_option_widget_mnemonic_activate (GtkWidget *widget,
101 gboolean group_cycling);
104 gtk_printer_option_widget_class_init (GtkPrinterOptionWidgetClass *class)
106 GObjectClass *object_class;
107 GtkWidgetClass *widget_class;
109 object_class = (GObjectClass *) class;
110 widget_class = (GtkWidgetClass *) class;
112 object_class->finalize = gtk_printer_option_widget_finalize;
113 object_class->set_property = gtk_printer_option_widget_set_property;
114 object_class->get_property = gtk_printer_option_widget_get_property;
116 widget_class->mnemonic_activate = gtk_printer_option_widget_mnemonic_activate;
118 g_type_class_add_private (class, sizeof (GtkPrinterOptionWidgetPrivate));
121 g_signal_new ("changed",
122 G_TYPE_FROM_CLASS (class),
124 G_STRUCT_OFFSET (GtkPrinterOptionWidgetClass, changed),
126 g_cclosure_marshal_VOID__VOID,
129 g_object_class_install_property (object_class,
131 g_param_spec_object ("source",
133 P_("The PrinterOption backing this widget"),
134 GTK_TYPE_PRINTER_OPTION,
135 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
140 gtk_printer_option_widget_init (GtkPrinterOptionWidget *widget)
142 widget->priv = GTK_PRINTER_OPTION_WIDGET_GET_PRIVATE (widget);
144 gtk_box_set_spacing (GTK_BOX (widget), 12);
148 gtk_printer_option_widget_finalize (GObject *object)
150 GtkPrinterOptionWidget *widget = GTK_PRINTER_OPTION_WIDGET (object);
151 GtkPrinterOptionWidgetPrivate *priv = widget->priv;
155 g_object_unref (priv->source);
159 G_OBJECT_CLASS (gtk_printer_option_widget_parent_class)->finalize (object);
163 gtk_printer_option_widget_set_property (GObject *object,
168 GtkPrinterOptionWidget *widget;
170 widget = GTK_PRINTER_OPTION_WIDGET (object);
175 gtk_printer_option_widget_set_source (widget, g_value_get_object (value));
178 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
184 gtk_printer_option_widget_get_property (GObject *object,
189 GtkPrinterOptionWidget *widget = GTK_PRINTER_OPTION_WIDGET (object);
190 GtkPrinterOptionWidgetPrivate *priv = widget->priv;
195 g_value_set_object (value, priv->source);
198 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
204 gtk_printer_option_widget_mnemonic_activate (GtkWidget *widget,
205 gboolean group_cycling)
207 GtkPrinterOptionWidget *powidget = GTK_PRINTER_OPTION_WIDGET (widget);
208 GtkPrinterOptionWidgetPrivate *priv = powidget->priv;
211 return gtk_widget_mnemonic_activate (priv->check, group_cycling);
213 return gtk_widget_mnemonic_activate (priv->combo, group_cycling);
215 return gtk_widget_mnemonic_activate (priv->entry, group_cycling);
217 return gtk_widget_mnemonic_activate (priv->button, group_cycling);
223 emit_changed (GtkPrinterOptionWidget *widget)
225 g_signal_emit (widget, signals[CHANGED], 0);
229 gtk_printer_option_widget_new (GtkPrinterOption *source)
231 return g_object_new (GTK_TYPE_PRINTER_OPTION_WIDGET, "source", source, NULL);
235 source_changed_cb (GtkPrinterOption *source,
236 GtkPrinterOptionWidget *widget)
238 update_widgets (widget);
239 emit_changed (widget);
243 gtk_printer_option_widget_set_source (GtkPrinterOptionWidget *widget,
244 GtkPrinterOption *source)
246 GtkPrinterOptionWidgetPrivate *priv = widget->priv;
249 g_object_ref (source);
253 g_signal_handler_disconnect (priv->source,
254 priv->source_changed_handler);
255 g_object_unref (priv->source);
258 priv->source = source;
261 priv->source_changed_handler =
262 g_signal_connect (source, "changed", G_CALLBACK (source_changed_cb), widget);
264 construct_widgets (widget);
265 update_widgets (widget);
267 g_object_notify (G_OBJECT (widget), "source");
277 combo_box_set_model (GtkWidget *combo_box)
281 store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING);
282 gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), GTK_TREE_MODEL (store));
283 g_object_unref (store);
287 combo_box_set_view (GtkWidget *combo_box)
289 GtkCellRenderer *cell;
291 cell = gtk_cell_renderer_text_new ();
292 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE);
293 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell,
299 combo_box_entry_new (void)
301 GtkWidget *combo_box;
302 combo_box = g_object_new (GTK_TYPE_COMBO_BOX, "has-entry", TRUE, NULL);
304 combo_box_set_model (combo_box);
306 gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (combo_box), NAME_COLUMN);
314 GtkWidget *combo_box;
315 combo_box = gtk_combo_box_new ();
317 combo_box_set_model (combo_box);
318 combo_box_set_view (combo_box);
324 combo_box_append (GtkWidget *combo,
325 const gchar *display_text,
332 model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
333 store = GTK_LIST_STORE (model);
335 gtk_list_store_append (store, &iter);
336 gtk_list_store_set (store, &iter,
337 NAME_COLUMN, display_text,
348 set_cb (GtkTreeModel *model,
353 struct ComboSet *set_data = data;
357 gtk_tree_model_get (model, iter, VALUE_COLUMN, &value, -1);
358 found = (strcmp (value, set_data->value) == 0);
362 gtk_combo_box_set_active_iter (set_data->combo, iter);
368 combo_box_set (GtkWidget *combo,
372 struct ComboSet set_data;
374 model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
376 set_data.combo = GTK_COMBO_BOX (combo);
377 set_data.value = value;
378 gtk_tree_model_foreach (model, set_cb, &set_data);
382 combo_box_get (GtkWidget *combo, gboolean *custom)
388 model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
391 if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter))
393 gtk_tree_model_get (model, &iter, VALUE_COLUMN, &value, -1);
398 if (gtk_combo_box_get_has_entry (GTK_COMBO_BOX (combo)))
400 value = g_strdup (gtk_entry_get_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (combo)))));
404 if (!value || !gtk_tree_model_get_iter_first (model, &iter))
407 /* If the user entered an item from the dropdown list manually, return
408 * the non-custom option instead. */
412 gtk_tree_model_get (model, &iter, VALUE_COLUMN, &val,
413 NAME_COLUMN, &name, -1);
414 if (g_str_equal (value, name))
425 while (gtk_tree_model_iter_next (model, &iter));
433 deconstruct_widgets (GtkPrinterOptionWidget *widget)
435 GtkPrinterOptionWidgetPrivate *priv = widget->priv;
439 gtk_widget_destroy (priv->check);
445 gtk_widget_destroy (priv->combo);
451 gtk_widget_destroy (priv->entry);
457 gtk_widget_destroy (priv->image);
463 gtk_widget_destroy (priv->label);
466 if (priv->info_label)
468 gtk_widget_destroy (priv->info_label);
469 priv->info_label = NULL;
474 check_toggled_cb (GtkToggleButton *toggle_button,
475 GtkPrinterOptionWidget *widget)
477 GtkPrinterOptionWidgetPrivate *priv = widget->priv;
479 g_signal_handler_block (priv->source, priv->source_changed_handler);
480 gtk_printer_option_set_boolean (priv->source,
481 gtk_toggle_button_get_active (toggle_button));
482 g_signal_handler_unblock (priv->source, priv->source_changed_handler);
483 emit_changed (widget);
487 dialog_response_callback (GtkDialog *dialog,
489 GtkPrinterOptionWidget *widget)
491 GtkPrinterOptionWidgetPrivate *priv = widget->priv;
493 gchar *new_location = NULL;
495 if (response_id == GTK_RESPONSE_ACCEPT)
498 gchar *filename_utf8;
499 gchar *filename_short;
501 new_location = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
503 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
504 filename_utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
505 filename_short = trim_long_filename (filename_utf8);
506 gtk_button_set_label (GTK_BUTTON (priv->button), filename_short);
507 g_free (filename_short);
508 g_free (filename_utf8);
512 gtk_widget_destroy (GTK_WIDGET (dialog));
517 uri = priv->last_location;
521 gtk_printer_option_set (priv->source, uri);
522 emit_changed (widget);
525 g_free (new_location);
526 g_free (priv->last_location);
527 priv->last_location = NULL;
529 /* unblock the handler which was blocked in the filesave_choose_cb function */
530 g_signal_handler_unblock (priv->source, priv->source_changed_handler);
534 filesave_choose_cb (GtkWidget *button,
535 GtkPrinterOptionWidget *widget)
537 GtkPrinterOptionWidgetPrivate *priv = widget->priv;
538 gchar *last_location = NULL;
542 /* this will be unblocked in the dialog_response_callback function */
543 g_signal_handler_block (priv->source, priv->source_changed_handler);
545 toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (widget)));
546 dialog = gtk_file_chooser_dialog_new (_("Select a filename"),
548 GTK_FILE_CHOOSER_ACTION_SAVE,
549 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
550 _("_Select"), GTK_RESPONSE_ACCEPT,
553 /* The confirmation dialog will appear, when the user clicks print */
554 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), FALSE);
556 /* select the current filename in the dialog */
557 if (priv->source != NULL)
559 priv->last_location = last_location = g_strdup (priv->source->value);
564 gchar *basename_utf8;
566 gtk_file_chooser_select_uri (GTK_FILE_CHOOSER (dialog), last_location);
567 file = g_file_new_for_uri (last_location);
568 basename = g_file_get_basename (file);
569 basename_utf8 = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL);
570 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), basename_utf8);
571 g_free (basename_utf8);
573 g_object_unref (file);
577 g_signal_connect (dialog, "response",
578 G_CALLBACK (dialog_response_callback), widget);
579 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
580 gtk_window_present (GTK_WINDOW (dialog));
584 filter_numeric (const gchar *val,
587 gboolean *changed_out)
591 int len = strlen (val);
592 gboolean dec_set = FALSE;
594 filtered_val = g_malloc (len + 1);
596 for (i = 0, j = 0; i < len; i++)
598 if (isdigit (val[i]))
600 filtered_val[j] = val[i];
603 else if (allow_dec && !dec_set &&
604 (val[i] == '.' || val[i] == ','))
606 /* allow one period or comma
607 * we should be checking locals
608 * but this is good enough for now
610 filtered_val[j] = val[i];
614 else if (allow_neg && i == 0 && val[0] == '-')
616 filtered_val[0] = val[0];
621 filtered_val[j] = '\0';
622 *changed_out = !(i == j);
628 combo_changed_cb (GtkWidget *combo,
629 GtkPrinterOptionWidget *widget)
631 GtkPrinterOptionWidgetPrivate *priv = widget->priv;
633 gchar *filtered_val = NULL;
635 gboolean custom = TRUE;
637 g_signal_handler_block (priv->source, priv->source_changed_handler);
639 value = combo_box_get (combo, &custom);
641 /* Handle constraints if the user entered a custom value. */
644 switch (priv->source->type)
646 case GTK_PRINTER_OPTION_TYPE_PICKONE_PASSCODE:
647 filtered_val = filter_numeric (value, FALSE, FALSE, &changed);
649 case GTK_PRINTER_OPTION_TYPE_PICKONE_INT:
650 filtered_val = filter_numeric (value, TRUE, FALSE, &changed);
652 case GTK_PRINTER_OPTION_TYPE_PICKONE_REAL:
653 filtered_val = filter_numeric (value, TRUE, TRUE, &changed);
668 entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (combo)));
670 gtk_entry_set_text (entry, filtered_val);
672 value = filtered_val;
676 gtk_printer_option_set (priv->source, value);
678 g_signal_handler_unblock (priv->source, priv->source_changed_handler);
679 emit_changed (widget);
683 entry_changed_cb (GtkWidget *entry,
684 GtkPrinterOptionWidget *widget)
686 GtkPrinterOptionWidgetPrivate *priv = widget->priv;
689 g_signal_handler_block (priv->source, priv->source_changed_handler);
690 value = gtk_entry_get_text (GTK_ENTRY (entry));
692 gtk_printer_option_set (priv->source, value);
693 g_signal_handler_unblock (priv->source, priv->source_changed_handler);
694 emit_changed (widget);
699 radio_changed_cb (GtkWidget *button,
700 GtkPrinterOptionWidget *widget)
702 GtkPrinterOptionWidgetPrivate *priv = widget->priv;
705 g_signal_handler_block (priv->source, priv->source_changed_handler);
706 value = g_object_get_data (G_OBJECT (button), "value");
708 gtk_printer_option_set (priv->source, value);
709 g_signal_handler_unblock (priv->source, priv->source_changed_handler);
710 emit_changed (widget);
714 select_maybe (GtkWidget *widget,
717 gchar *v = g_object_get_data (G_OBJECT (widget), "value");
719 if (strcmp (value, v) == 0)
720 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
724 alternative_set (GtkWidget *box,
727 gtk_container_foreach (GTK_CONTAINER (box),
728 (GtkCallback) select_maybe,
733 alternative_append (GtkWidget *box,
736 GtkPrinterOptionWidget *widget,
741 button = gtk_radio_button_new_with_label (group, label);
742 gtk_widget_show (button);
743 gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
745 g_object_set_data (G_OBJECT (button), "value", (gpointer)value);
746 g_signal_connect (button, "toggled",
747 G_CALLBACK (radio_changed_cb), widget);
749 return gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
753 construct_widgets (GtkPrinterOptionWidget *widget)
755 GtkPrinterOptionWidgetPrivate *priv = widget->priv;
756 GtkPrinterOption *source;
761 source = priv->source;
763 deconstruct_widgets (widget);
765 gtk_widget_set_sensitive (GTK_WIDGET (widget), TRUE);
769 priv->combo = combo_box_new ();
770 combo_box_append (priv->combo,_("Not available"), "None");
771 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combo), 0);
772 gtk_widget_set_sensitive (GTK_WIDGET (widget), FALSE);
773 gtk_widget_show (priv->combo);
774 gtk_box_pack_start (GTK_BOX (widget), priv->combo, TRUE, TRUE, 0);
776 else switch (source->type)
778 case GTK_PRINTER_OPTION_TYPE_BOOLEAN:
779 priv->check = gtk_check_button_new_with_mnemonic (source->display_text);
780 g_signal_connect (priv->check, "toggled", G_CALLBACK (check_toggled_cb), widget);
781 gtk_widget_show (priv->check);
782 gtk_box_pack_start (GTK_BOX (widget), priv->check, TRUE, TRUE, 0);
784 case GTK_PRINTER_OPTION_TYPE_PICKONE:
785 case GTK_PRINTER_OPTION_TYPE_PICKONE_PASSWORD:
786 case GTK_PRINTER_OPTION_TYPE_PICKONE_PASSCODE:
787 case GTK_PRINTER_OPTION_TYPE_PICKONE_REAL:
788 case GTK_PRINTER_OPTION_TYPE_PICKONE_INT:
789 case GTK_PRINTER_OPTION_TYPE_PICKONE_STRING:
790 if (source->type == GTK_PRINTER_OPTION_TYPE_PICKONE)
792 priv->combo = combo_box_new ();
796 priv->combo = combo_box_entry_new ();
798 if (source->type == GTK_PRINTER_OPTION_TYPE_PICKONE_PASSWORD ||
799 source->type == GTK_PRINTER_OPTION_TYPE_PICKONE_PASSCODE)
803 entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->combo)));
805 gtk_entry_set_visibility (entry, FALSE);
809 for (i = 0; i < source->num_choices; i++)
810 combo_box_append (priv->combo,
811 source->choices_display[i],
813 gtk_widget_show (priv->combo);
814 gtk_box_pack_start (GTK_BOX (widget), priv->combo, TRUE, TRUE, 0);
815 g_signal_connect (priv->combo, "changed", G_CALLBACK (combo_changed_cb), widget);
817 text = g_strdup_printf ("%s:", source->display_text);
818 priv->label = gtk_label_new_with_mnemonic (text);
820 gtk_widget_show (priv->label);
823 case GTK_PRINTER_OPTION_TYPE_ALTERNATIVE:
825 priv->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
826 gtk_widget_show (priv->box);
827 gtk_box_pack_start (GTK_BOX (widget), priv->box, TRUE, TRUE, 0);
828 for (i = 0; i < source->num_choices; i++)
830 group = alternative_append (priv->box,
831 source->choices_display[i],
835 /* for mnemonic activation */
837 priv->button = group->data;
840 if (source->display_text)
842 text = g_strdup_printf ("%s:", source->display_text);
843 priv->label = gtk_label_new_with_mnemonic (text);
845 gtk_widget_show (priv->label);
849 case GTK_PRINTER_OPTION_TYPE_STRING:
850 priv->entry = gtk_entry_new ();
851 gtk_entry_set_activates_default (GTK_ENTRY (priv->entry),
852 gtk_printer_option_get_activates_default (source));
853 gtk_widget_show (priv->entry);
854 gtk_box_pack_start (GTK_BOX (widget), priv->entry, TRUE, TRUE, 0);
855 g_signal_connect (priv->entry, "changed", G_CALLBACK (entry_changed_cb), widget);
857 text = g_strdup_printf ("%s:", source->display_text);
858 priv->label = gtk_label_new_with_mnemonic (text);
860 gtk_widget_show (priv->label);
864 case GTK_PRINTER_OPTION_TYPE_FILESAVE:
865 priv->button = gtk_button_new ();
866 gtk_widget_show (priv->button);
867 gtk_box_pack_start (GTK_BOX (widget), priv->button, TRUE, TRUE, 0);
868 g_signal_connect (priv->button, "clicked", G_CALLBACK (filesave_choose_cb), widget);
870 text = g_strdup_printf ("%s:", source->display_text);
871 priv->label = gtk_label_new_with_mnemonic (text);
873 gtk_widget_show (priv->label);
877 case GTK_PRINTER_OPTION_TYPE_INFO:
878 priv->info_label = gtk_label_new (NULL);
879 gtk_label_set_selectable (GTK_LABEL (priv->info_label), TRUE);
880 gtk_widget_show (priv->info_label);
881 gtk_box_pack_start (GTK_BOX (widget), priv->info_label, FALSE, TRUE, 0);
883 text = g_strdup_printf ("%s:", source->display_text);
884 priv->label = gtk_label_new_with_mnemonic (text);
886 gtk_widget_show (priv->label);
894 priv->image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_MENU);
895 gtk_box_pack_start (GTK_BOX (widget), priv->image, FALSE, FALSE, 0);
899 * If the filename exceeds FILENAME_LENGTH_MAX, then trim it and replace
900 * the first three letters with three dots.
903 trim_long_filename (const gchar *filename)
909 home = g_get_home_dir ();
910 if (g_str_has_prefix (filename, home))
912 gchar *homeless_filename;
914 offset = g_utf8_strlen (home, -1);
915 len = g_utf8_strlen (filename, -1);
916 homeless_filename = g_utf8_substring (filename, offset, len);
917 result = g_strconcat ("~", homeless_filename, NULL);
918 g_free (homeless_filename);
921 result = g_strdup (filename);
923 len = g_utf8_strlen (result, -1);
924 if (len > FILENAME_LENGTH_MAX)
928 suffix = g_utf8_substring (result, len - FILENAME_LENGTH_MAX, len);
930 result = g_strconcat ("...", suffix, NULL);
938 update_widgets (GtkPrinterOptionWidget *widget)
940 GtkPrinterOptionWidgetPrivate *priv = widget->priv;
941 GtkPrinterOption *source;
943 source = priv->source;
947 gtk_widget_hide (priv->image);
951 switch (source->type)
953 case GTK_PRINTER_OPTION_TYPE_BOOLEAN:
954 if (g_ascii_strcasecmp (source->value, "True") == 0)
955 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->check), TRUE);
957 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->check), FALSE);
959 case GTK_PRINTER_OPTION_TYPE_PICKONE:
960 combo_box_set (priv->combo, source->value);
962 case GTK_PRINTER_OPTION_TYPE_ALTERNATIVE:
963 alternative_set (priv->box, source->value);
965 case GTK_PRINTER_OPTION_TYPE_STRING:
966 gtk_entry_set_text (GTK_ENTRY (priv->entry), source->value);
968 case GTK_PRINTER_OPTION_TYPE_PICKONE_PASSWORD:
969 case GTK_PRINTER_OPTION_TYPE_PICKONE_PASSCODE:
970 case GTK_PRINTER_OPTION_TYPE_PICKONE_REAL:
971 case GTK_PRINTER_OPTION_TYPE_PICKONE_INT:
972 case GTK_PRINTER_OPTION_TYPE_PICKONE_STRING:
976 entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->combo)));
977 if (gtk_printer_option_has_choice (source, source->value))
978 combo_box_set (priv->combo, source->value);
980 gtk_entry_set_text (entry, source->value);
984 case GTK_PRINTER_OPTION_TYPE_FILESAVE:
989 filename = g_filename_from_uri (source->value, NULL, NULL);
990 if (filename != NULL)
992 text = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
995 gchar *short_filename;
997 short_filename = trim_long_filename (text);
998 gtk_button_set_label (GTK_BUTTON (priv->button), short_filename);
999 g_free (short_filename);
1006 gtk_button_set_label (GTK_BUTTON (priv->button), source->value);
1009 case GTK_PRINTER_OPTION_TYPE_INFO:
1010 gtk_label_set_text (GTK_LABEL (priv->info_label), source->value);
1016 if (source->has_conflict)
1017 gtk_widget_show (priv->image);
1019 gtk_widget_hide (priv->image);
1023 gtk_printer_option_widget_has_external_label (GtkPrinterOptionWidget *widget)
1025 return widget->priv->label != NULL;
1029 gtk_printer_option_widget_get_external_label (GtkPrinterOptionWidget *widget)
1031 return widget->priv->label;
1035 gtk_printer_option_widget_get_value (GtkPrinterOptionWidget *widget)
1037 GtkPrinterOptionWidgetPrivate *priv = widget->priv;
1040 return priv->source->value;