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"
28 /*****************************************
29 * GtkPrinterOptionSet *
30 *****************************************/
37 static guint signals[LAST_SIGNAL] = { 0 };
39 /* ugly side-effect of aliasing */
40 #undef gtk_printer_option_set
42 G_DEFINE_TYPE (GtkPrinterOptionSet, gtk_printer_option_set, G_TYPE_OBJECT)
45 gtk_printer_option_set_finalize (GObject *object)
47 GtkPrinterOptionSet *set = GTK_PRINTER_OPTION_SET (object);
49 g_hash_table_destroy (set->hash);
50 g_ptr_array_foreach (set->array, (GFunc)g_object_unref, NULL);
51 g_ptr_array_free (set->array, TRUE);
53 G_OBJECT_CLASS (gtk_printer_option_set_parent_class)->finalize (object);
57 gtk_printer_option_set_init (GtkPrinterOptionSet *set)
59 set->array = g_ptr_array_new ();
60 set->hash = g_hash_table_new (g_str_hash, g_str_equal);
64 gtk_printer_option_set_class_init (GtkPrinterOptionSetClass *class)
66 GObjectClass *gobject_class = (GObjectClass *)class;
68 gobject_class->finalize = gtk_printer_option_set_finalize;
71 g_signal_new ("changed",
72 G_TYPE_FROM_CLASS (gobject_class),
74 G_STRUCT_OFFSET (GtkPrinterOptionSetClass, changed),
76 g_cclosure_marshal_VOID__VOID,
82 emit_changed (GtkPrinterOptionSet *set)
84 g_signal_emit (set, signals[CHANGED], 0);
88 gtk_printer_option_set_new (void)
90 return g_object_new (GTK_TYPE_PRINTER_OPTION_SET, NULL);
94 gtk_printer_option_set_remove (GtkPrinterOptionSet *set,
95 GtkPrinterOption *option)
99 for (i = 0; i < set->array->len; i++)
101 if (g_ptr_array_index (set->array, i) == option)
103 g_ptr_array_remove_index (set->array, i);
104 g_hash_table_remove (set->hash, option->name);
105 g_signal_handlers_disconnect_by_func (option, emit_changed, set);
107 g_object_unref (option);
114 gtk_printer_option_set_add (GtkPrinterOptionSet *set,
115 GtkPrinterOption *option)
117 g_object_ref (option);
119 if (gtk_printer_option_set_lookup (set, option->name))
120 gtk_printer_option_set_remove (set, option);
122 g_ptr_array_add (set->array, option);
123 g_hash_table_insert (set->hash, option->name, option);
124 g_signal_connect_object (option, "changed", G_CALLBACK (emit_changed), set, G_CONNECT_SWAPPED);
128 gtk_printer_option_set_lookup (GtkPrinterOptionSet *set,
133 ptr = g_hash_table_lookup (set->hash, name);
135 return GTK_PRINTER_OPTION (ptr);
139 gtk_printer_option_set_clear_conflicts (GtkPrinterOptionSet *set)
141 gtk_printer_option_set_foreach (set,
142 (GtkPrinterOptionSetFunc)gtk_printer_option_clear_has_conflict,
147 * gtk_printer_option_set_get_groups:
149 * Return value: (element-type utf8) (transfer full):
152 gtk_printer_option_set_get_groups (GtkPrinterOptionSet *set)
154 GtkPrinterOption *option;
158 for (i = 0; i < set->array->len; i++)
160 option = g_ptr_array_index (set->array, i);
162 if (g_list_find_custom (list, option->group, (GCompareFunc)g_strcmp0) == NULL)
163 list = g_list_prepend (list, g_strdup (option->group));
166 return g_list_reverse (list);
170 gtk_printer_option_set_foreach_in_group (GtkPrinterOptionSet *set,
172 GtkPrinterOptionSetFunc func,
175 GtkPrinterOption *option;
178 for (i = 0; i < set->array->len; i++)
180 option = g_ptr_array_index (set->array, i);
182 if (group == NULL || g_strcmp0 (group, option->group) == 0)
183 func (option, user_data);
188 gtk_printer_option_set_foreach (GtkPrinterOptionSet *set,
189 GtkPrinterOptionSetFunc func,
192 gtk_printer_option_set_foreach_in_group (set, NULL, func, user_data);