1 /* GTK - The GIMP Toolkit
2 * gtkprintbackend.h: Abstract printer backend interfaces
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 "gtkprinteroptionset.h"
29 /*****************************************
30 * GtkPrinterOptionSet *
31 *****************************************/
38 static guint signals[LAST_SIGNAL] = { 0 };
40 /* ugly side-effect of aliasing */
41 #undef gtk_printer_option_set
43 G_DEFINE_TYPE (GtkPrinterOptionSet, gtk_printer_option_set, G_TYPE_OBJECT)
46 gtk_printer_option_set_finalize (GObject *object)
48 GtkPrinterOptionSet *set = GTK_PRINTER_OPTION_SET (object);
50 g_hash_table_destroy (set->hash);
51 g_ptr_array_foreach (set->array, (GFunc)g_object_unref, NULL);
52 g_ptr_array_free (set->array, TRUE);
54 G_OBJECT_CLASS (gtk_printer_option_set_parent_class)->finalize (object);
58 gtk_printer_option_set_init (GtkPrinterOptionSet *set)
60 set->array = g_ptr_array_new ();
61 set->hash = g_hash_table_new (g_str_hash, g_str_equal);
65 gtk_printer_option_set_class_init (GtkPrinterOptionSetClass *class)
67 GObjectClass *gobject_class = (GObjectClass *)class;
69 gobject_class->finalize = gtk_printer_option_set_finalize;
72 g_signal_new ("changed",
73 G_TYPE_FROM_CLASS (gobject_class),
75 G_STRUCT_OFFSET (GtkPrinterOptionSetClass, changed),
77 g_cclosure_marshal_VOID__VOID,
83 emit_changed (GtkPrinterOptionSet *set)
85 g_signal_emit (set, signals[CHANGED], 0);
89 gtk_printer_option_set_new (void)
91 return g_object_new (GTK_TYPE_PRINTER_OPTION_SET, NULL);
95 gtk_printer_option_set_remove (GtkPrinterOptionSet *set,
96 GtkPrinterOption *option)
100 for (i = 0; i < set->array->len; i++)
102 if (g_ptr_array_index (set->array, i) == option)
104 g_ptr_array_remove_index (set->array, i);
105 g_hash_table_remove (set->hash, option->name);
106 g_signal_handlers_disconnect_by_func (option, emit_changed, set);
108 g_object_unref (option);
115 gtk_printer_option_set_add (GtkPrinterOptionSet *set,
116 GtkPrinterOption *option)
118 g_object_ref (option);
120 if (gtk_printer_option_set_lookup (set, option->name))
121 gtk_printer_option_set_remove (set, option);
123 g_ptr_array_add (set->array, option);
124 g_hash_table_insert (set->hash, option->name, option);
125 g_signal_connect_object (option, "changed", G_CALLBACK (emit_changed), set, G_CONNECT_SWAPPED);
129 gtk_printer_option_set_lookup (GtkPrinterOptionSet *set,
134 ptr = g_hash_table_lookup (set->hash, name);
136 return GTK_PRINTER_OPTION (ptr);
140 gtk_printer_option_set_clear_conflicts (GtkPrinterOptionSet *set)
142 gtk_printer_option_set_foreach (set,
143 (GtkPrinterOptionSetFunc)gtk_printer_option_clear_has_conflict,
148 safe_strcmp (const char *a, const char *b)
155 return strcmp (a, b);
159 gtk_printer_option_set_get_groups (GtkPrinterOptionSet *set)
161 GtkPrinterOption *option;
165 for (i = 0; i < set->array->len; i++)
167 option = g_ptr_array_index (set->array, i);
169 if (g_list_find_custom (list, option->group, (GCompareFunc)safe_strcmp) == NULL)
170 list = g_list_prepend (list, g_strdup (option->group));
173 return g_list_reverse (list);
177 gtk_printer_option_set_foreach_in_group (GtkPrinterOptionSet *set,
179 GtkPrinterOptionSetFunc func,
182 GtkPrinterOption *option;
185 for (i = 0; i < set->array->len; i++)
187 option = g_ptr_array_index (set->array, i);
190 (option->group != NULL && strcmp (group, option->group) == 0))
191 func (option, user_data);
196 gtk_printer_option_set_foreach (GtkPrinterOptionSet *set,
197 GtkPrinterOptionSetFunc func,
200 gtk_printer_option_set_foreach_in_group (set, NULL, func, user_data);
204 #define __GTK_PRINTER_OPTION_SET_C__
205 #include "gtkaliasdef.c"