1 /* GTK - The GTK+ 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.
25 #include "gtkprinteroption.h"
28 /*****************************************
30 *****************************************/
37 static guint signals[LAST_SIGNAL] = { 0 };
39 G_DEFINE_TYPE (GtkPrinterOption, gtk_printer_option, G_TYPE_OBJECT)
42 gtk_printer_option_finalize (GObject *object)
44 GtkPrinterOption *option = GTK_PRINTER_OPTION (object);
47 g_free (option->name);
48 g_free (option->display_text);
49 g_free (option->value);
50 for (i = 0; i < option->num_choices; i++)
52 g_free (option->choices[i]);
53 g_free (option->choices_display[i]);
55 g_free (option->choices);
56 g_free (option->choices_display);
57 g_free (option->group);
59 G_OBJECT_CLASS (gtk_printer_option_parent_class)->finalize (object);
63 gtk_printer_option_init (GtkPrinterOption *option)
65 option->value = g_strdup ("");
69 gtk_printer_option_class_init (GtkPrinterOptionClass *class)
71 GObjectClass *gobject_class = (GObjectClass *)class;
73 gobject_class->finalize = gtk_printer_option_finalize;
76 g_signal_new ("changed",
77 G_TYPE_FROM_CLASS (class),
79 G_STRUCT_OFFSET (GtkPrinterOptionClass, changed),
81 g_cclosure_marshal_VOID__VOID,
86 gtk_printer_option_new (const char *name, const char *display_text,
87 GtkPrinterOptionType type)
89 GtkPrinterOption *option;
91 option = g_object_new (GTK_TYPE_PRINTER_OPTION, NULL);
93 option->name = g_strdup (name);
94 option->display_text = g_strdup (display_text);
101 emit_changed (GtkPrinterOption *option)
103 g_signal_emit (option, signals[CHANGED], 0);
107 gtk_printer_option_set (GtkPrinterOption *option,
113 if (strcmp (option->value, value) == 0)
116 if ((option->type == GTK_PRINTER_OPTION_TYPE_PICKONE ||
117 option->type == GTK_PRINTER_OPTION_TYPE_ALTERNATIVE) &&
122 for (i = 0; i < option->num_choices; i++)
124 if (g_ascii_strcasecmp (value, option->choices[i]) == 0)
126 value = option->choices[i];
131 if (i == option->num_choices)
132 return; /* Not found in available choices */
135 g_free (option->value);
136 option->value = g_strdup (value);
138 emit_changed (option);
142 gtk_printer_option_set_boolean (GtkPrinterOption *option,
145 gtk_printer_option_set (option, value ? "True" : "False");
149 gtk_printer_option_set_has_conflict (GtkPrinterOption *option,
150 gboolean has_conflict)
152 has_conflict = has_conflict != 0;
154 if (option->has_conflict == has_conflict)
157 option->has_conflict = has_conflict;
158 emit_changed (option);
162 gtk_printer_option_clear_has_conflict (GtkPrinterOption *option)
164 gtk_printer_option_set_has_conflict (option, FALSE);
168 gtk_printer_option_allocate_choices (GtkPrinterOption *option,
171 g_free (option->choices);
172 g_free (option->choices_display);
174 option->num_choices = num;
177 option->choices = NULL;
178 option->choices_display = NULL;
182 option->choices = g_new0 (char *, num);
183 option->choices_display = g_new0 (char *, num);
188 gtk_printer_option_choices_from_array (GtkPrinterOption *option,
191 char *choices_display[])
195 gtk_printer_option_allocate_choices (option, num_choices);
196 for (i = 0; i < num_choices; i++)
198 option->choices[i] = g_strdup (choices[i]);
199 option->choices_display[i] = g_strdup (choices_display[i]);
204 gtk_printer_option_has_choice (GtkPrinterOption *option,
209 for (i = 0; i < option->num_choices; i++)
211 if (strcmp (option->choices[i], choice) == 0)
219 #define __GTK_PRINTER_OPTION_C__
220 #include "gtkaliasdef.c"