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, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
26 #include "gtkprivate.h"
27 #include "gtkprinteroption.h"
29 /*****************************************
31 *****************************************/
43 static guint signals[LAST_SIGNAL] = { 0 };
45 static void gtk_printer_option_set_property (GObject *object,
49 static void gtk_printer_option_get_property (GObject *object,
54 G_DEFINE_TYPE (GtkPrinterOption, gtk_printer_option, G_TYPE_OBJECT)
57 gtk_printer_option_finalize (GObject *object)
59 GtkPrinterOption *option = GTK_PRINTER_OPTION (object);
62 g_free (option->name);
63 g_free (option->display_text);
64 g_free (option->value);
65 for (i = 0; i < option->num_choices; i++)
67 g_free (option->choices[i]);
68 g_free (option->choices_display[i]);
70 g_free (option->choices);
71 g_free (option->choices_display);
72 g_free (option->group);
74 G_OBJECT_CLASS (gtk_printer_option_parent_class)->finalize (object);
78 gtk_printer_option_init (GtkPrinterOption *option)
80 option->value = g_strdup ("");
81 option->activates_default = FALSE;
85 gtk_printer_option_class_init (GtkPrinterOptionClass *class)
87 GObjectClass *gobject_class = (GObjectClass *)class;
89 gobject_class->finalize = gtk_printer_option_finalize;
90 gobject_class->set_property = gtk_printer_option_set_property;
91 gobject_class->get_property = gtk_printer_option_get_property;
94 g_signal_new ("changed",
95 G_TYPE_FROM_CLASS (class),
97 G_STRUCT_OFFSET (GtkPrinterOptionClass, changed),
99 g_cclosure_marshal_VOID__VOID,
102 g_object_class_install_property (G_OBJECT_CLASS (class),
104 g_param_spec_string ("value",
106 P_("Value of the option"),
108 GTK_PARAM_READWRITE));
112 gtk_printer_option_new (const char *name, const char *display_text,
113 GtkPrinterOptionType type)
115 GtkPrinterOption *option;
117 option = g_object_new (GTK_TYPE_PRINTER_OPTION, NULL);
119 option->name = g_strdup (name);
120 option->display_text = g_strdup (display_text);
127 gtk_printer_option_set_property (GObject *object,
132 GtkPrinterOption *option = GTK_PRINTER_OPTION (object);
137 gtk_printer_option_set (option, g_value_get_string (value));
140 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
146 gtk_printer_option_get_property (GObject *object,
151 GtkPrinterOption *option = GTK_PRINTER_OPTION (object);
156 g_value_set_string (value, option->value);
159 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
165 emit_changed (GtkPrinterOption *option)
167 g_signal_emit (option, signals[CHANGED], 0);
171 gtk_printer_option_set (GtkPrinterOption *option,
177 if (strcmp (option->value, value) == 0)
180 if ((option->type == GTK_PRINTER_OPTION_TYPE_PICKONE ||
181 option->type == GTK_PRINTER_OPTION_TYPE_ALTERNATIVE) &&
186 for (i = 0; i < option->num_choices; i++)
188 if (g_ascii_strcasecmp (value, option->choices[i]) == 0)
190 value = option->choices[i];
195 if (i == option->num_choices)
196 return; /* Not found in available choices */
199 g_free (option->value);
200 option->value = g_strdup (value);
202 emit_changed (option);
206 gtk_printer_option_set_boolean (GtkPrinterOption *option,
209 gtk_printer_option_set (option, value ? "True" : "False");
213 gtk_printer_option_set_has_conflict (GtkPrinterOption *option,
214 gboolean has_conflict)
216 has_conflict = has_conflict != 0;
218 if (option->has_conflict == has_conflict)
221 option->has_conflict = has_conflict;
222 emit_changed (option);
226 gtk_printer_option_clear_has_conflict (GtkPrinterOption *option)
228 gtk_printer_option_set_has_conflict (option, FALSE);
232 gtk_printer_option_allocate_choices (GtkPrinterOption *option,
235 g_free (option->choices);
236 g_free (option->choices_display);
238 option->num_choices = num;
241 option->choices = NULL;
242 option->choices_display = NULL;
246 option->choices = g_new0 (char *, num);
247 option->choices_display = g_new0 (char *, num);
252 gtk_printer_option_choices_from_array (GtkPrinterOption *option,
255 char *choices_display[])
259 gtk_printer_option_allocate_choices (option, num_choices);
260 for (i = 0; i < num_choices; i++)
262 option->choices[i] = g_strdup (choices[i]);
263 option->choices_display[i] = g_strdup (choices_display[i]);
268 gtk_printer_option_has_choice (GtkPrinterOption *option,
273 for (i = 0; i < option->num_choices; i++)
275 if (strcmp (option->choices[i], choice) == 0)
283 gtk_printer_option_set_activates_default (GtkPrinterOption *option,
286 g_return_if_fail (GTK_IS_PRINTER_OPTION (option));
288 option->activates_default = activates;
292 gtk_printer_option_get_activates_default (GtkPrinterOption *option)
294 g_return_val_if_fail (GTK_IS_PRINTER_OPTION (option), FALSE);
296 return option->activates_default;