1 /* GTK - The GIMP Toolkit
2 * gtkprinteroption.c: Handling possible settings for a specific printer setting
3 * Copyright (C) 2006, Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
24 #include "gtkprivate.h"
25 #include "gtkprinteroption.h"
27 /*****************************************
29 *****************************************/
41 static guint signals[LAST_SIGNAL] = { 0 };
43 static void gtk_printer_option_set_property (GObject *object,
47 static void gtk_printer_option_get_property (GObject *object,
52 G_DEFINE_TYPE (GtkPrinterOption, gtk_printer_option, G_TYPE_OBJECT)
55 gtk_printer_option_finalize (GObject *object)
57 GtkPrinterOption *option = GTK_PRINTER_OPTION (object);
60 g_free (option->name);
61 g_free (option->display_text);
62 g_free (option->value);
63 for (i = 0; i < option->num_choices; i++)
65 g_free (option->choices[i]);
66 g_free (option->choices_display[i]);
68 g_free (option->choices);
69 g_free (option->choices_display);
70 g_free (option->group);
72 G_OBJECT_CLASS (gtk_printer_option_parent_class)->finalize (object);
76 gtk_printer_option_init (GtkPrinterOption *option)
78 option->value = g_strdup ("");
79 option->activates_default = FALSE;
83 gtk_printer_option_class_init (GtkPrinterOptionClass *class)
85 GObjectClass *gobject_class = (GObjectClass *)class;
87 gobject_class->finalize = gtk_printer_option_finalize;
88 gobject_class->set_property = gtk_printer_option_set_property;
89 gobject_class->get_property = gtk_printer_option_get_property;
92 g_signal_new ("changed",
93 G_TYPE_FROM_CLASS (class),
95 G_STRUCT_OFFSET (GtkPrinterOptionClass, changed),
97 g_cclosure_marshal_VOID__VOID,
100 g_object_class_install_property (G_OBJECT_CLASS (class),
102 g_param_spec_string ("value",
104 P_("Value of the option"),
106 GTK_PARAM_READWRITE));
110 gtk_printer_option_new (const char *name, const char *display_text,
111 GtkPrinterOptionType type)
113 GtkPrinterOption *option;
115 option = g_object_new (GTK_TYPE_PRINTER_OPTION, NULL);
117 option->name = g_strdup (name);
118 option->display_text = g_strdup (display_text);
125 gtk_printer_option_set_property (GObject *object,
130 GtkPrinterOption *option = GTK_PRINTER_OPTION (object);
135 gtk_printer_option_set (option, g_value_get_string (value));
138 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
144 gtk_printer_option_get_property (GObject *object,
149 GtkPrinterOption *option = GTK_PRINTER_OPTION (object);
154 g_value_set_string (value, option->value);
157 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
163 emit_changed (GtkPrinterOption *option)
165 g_signal_emit (option, signals[CHANGED], 0);
169 gtk_printer_option_set (GtkPrinterOption *option,
175 if (strcmp (option->value, value) == 0)
178 if ((option->type == GTK_PRINTER_OPTION_TYPE_PICKONE ||
179 option->type == GTK_PRINTER_OPTION_TYPE_ALTERNATIVE))
183 for (i = 0; i < option->num_choices; i++)
185 if (g_ascii_strcasecmp (value, option->choices[i]) == 0)
187 value = option->choices[i];
192 if (i == option->num_choices)
193 return; /* Not found in available choices */
196 g_free (option->value);
197 option->value = g_strdup (value);
199 emit_changed (option);
203 gtk_printer_option_set_boolean (GtkPrinterOption *option,
206 gtk_printer_option_set (option, value ? "True" : "False");
210 gtk_printer_option_set_has_conflict (GtkPrinterOption *option,
211 gboolean has_conflict)
213 has_conflict = has_conflict != 0;
215 if (option->has_conflict == has_conflict)
218 option->has_conflict = has_conflict;
219 emit_changed (option);
223 gtk_printer_option_clear_has_conflict (GtkPrinterOption *option)
225 gtk_printer_option_set_has_conflict (option, FALSE);
229 gtk_printer_option_allocate_choices (GtkPrinterOption *option,
232 g_free (option->choices);
233 g_free (option->choices_display);
235 option->num_choices = num;
238 option->choices = NULL;
239 option->choices_display = NULL;
243 option->choices = g_new0 (char *, num);
244 option->choices_display = g_new0 (char *, num);
249 gtk_printer_option_choices_from_array (GtkPrinterOption *option,
252 char *choices_display[])
256 gtk_printer_option_allocate_choices (option, num_choices);
257 for (i = 0; i < num_choices; i++)
259 option->choices[i] = g_strdup (choices[i]);
260 option->choices_display[i] = g_strdup (choices_display[i]);
265 gtk_printer_option_has_choice (GtkPrinterOption *option,
270 for (i = 0; i < option->num_choices; i++)
272 if (strcmp (option->choices[i], choice) == 0)
280 gtk_printer_option_set_activates_default (GtkPrinterOption *option,
283 g_return_if_fail (GTK_IS_PRINTER_OPTION (option));
285 option->activates_default = activates;
289 gtk_printer_option_get_activates_default (GtkPrinterOption *option)
291 g_return_val_if_fail (GTK_IS_PRINTER_OPTION (option), FALSE);
293 return option->activates_default;