2008-07-01 22:57:50 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
2019-05-26 21:57:23 +00:00
|
|
|
* gtkprintbackendprivate.h: Abstract printer backend interfaces
|
2006-04-21 15:09:32 +00:00
|
|
|
* Copyright (C) 2006, Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2006-04-21 15:09:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <gmodule.h>
|
|
|
|
|
|
|
|
#include "gtkprinteroptionset.h"
|
2022-09-24 13:07:56 +00:00
|
|
|
#include "gtkprivate.h"
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
/*****************************************
|
|
|
|
* GtkPrinterOptionSet *
|
|
|
|
*****************************************/
|
|
|
|
|
|
|
|
enum {
|
|
|
|
CHANGED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
/* ugly side-effect of aliasing */
|
|
|
|
#undef gtk_printer_option_set
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GtkPrinterOptionSet, gtk_printer_option_set, G_TYPE_OBJECT)
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_printer_option_set_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkPrinterOptionSet *set = GTK_PRINTER_OPTION_SET (object);
|
|
|
|
|
|
|
|
g_hash_table_destroy (set->hash);
|
|
|
|
g_ptr_array_foreach (set->array, (GFunc)g_object_unref, NULL);
|
|
|
|
g_ptr_array_free (set->array, TRUE);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_printer_option_set_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_printer_option_set_init (GtkPrinterOptionSet *set)
|
|
|
|
{
|
|
|
|
set->array = g_ptr_array_new ();
|
|
|
|
set->hash = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_printer_option_set_class_init (GtkPrinterOptionSetClass *class)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = (GObjectClass *)class;
|
|
|
|
|
|
|
|
gobject_class->finalize = gtk_printer_option_set_finalize;
|
|
|
|
|
|
|
|
signals[CHANGED] =
|
2015-09-12 13:13:00 +00:00
|
|
|
g_signal_new (I_("changed"),
|
2006-04-21 15:09:32 +00:00
|
|
|
G_TYPE_FROM_CLASS (gobject_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GtkPrinterOptionSetClass, changed),
|
|
|
|
NULL, NULL,
|
2019-05-29 20:48:33 +00:00
|
|
|
NULL,
|
2006-04-21 15:09:32 +00:00
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
emit_changed (GtkPrinterOptionSet *set)
|
|
|
|
{
|
|
|
|
g_signal_emit (set, signals[CHANGED], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkPrinterOptionSet *
|
|
|
|
gtk_printer_option_set_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_PRINTER_OPTION_SET, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_printer_option_set_remove (GtkPrinterOptionSet *set,
|
|
|
|
GtkPrinterOption *option)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < set->array->len; i++)
|
|
|
|
{
|
|
|
|
if (g_ptr_array_index (set->array, i) == option)
|
|
|
|
{
|
|
|
|
g_ptr_array_remove_index (set->array, i);
|
|
|
|
g_hash_table_remove (set->hash, option->name);
|
|
|
|
g_signal_handlers_disconnect_by_func (option, emit_changed, set);
|
|
|
|
|
|
|
|
g_object_unref (option);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_printer_option_set_add (GtkPrinterOptionSet *set,
|
|
|
|
GtkPrinterOption *option)
|
|
|
|
{
|
|
|
|
g_object_ref (option);
|
|
|
|
|
|
|
|
if (gtk_printer_option_set_lookup (set, option->name))
|
|
|
|
gtk_printer_option_set_remove (set, option);
|
|
|
|
|
|
|
|
g_ptr_array_add (set->array, option);
|
|
|
|
g_hash_table_insert (set->hash, option->name, option);
|
|
|
|
g_signal_connect_object (option, "changed", G_CALLBACK (emit_changed), set, G_CONNECT_SWAPPED);
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkPrinterOption *
|
|
|
|
gtk_printer_option_set_lookup (GtkPrinterOptionSet *set,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
gpointer ptr;
|
|
|
|
|
|
|
|
ptr = g_hash_table_lookup (set->hash, name);
|
|
|
|
|
|
|
|
return GTK_PRINTER_OPTION (ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_printer_option_set_clear_conflicts (GtkPrinterOptionSet *set)
|
|
|
|
{
|
|
|
|
gtk_printer_option_set_foreach (set,
|
|
|
|
(GtkPrinterOptionSetFunc)gtk_printer_option_clear_has_conflict,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2009-12-10 10:23:40 +00:00
|
|
|
/**
|
|
|
|
* gtk_printer_option_set_get_groups:
|
2021-05-20 13:17:04 +00:00
|
|
|
* @set: a `GtkPrinterOptionSet`
|
2009-12-10 10:23:40 +00:00
|
|
|
*
|
2014-10-22 04:34:41 +00:00
|
|
|
* Gets the groups in this set.
|
|
|
|
*
|
|
|
|
* Returns: (element-type utf8) (transfer full): a list of group names.
|
2009-12-10 10:23:40 +00:00
|
|
|
*/
|
2006-04-21 15:09:32 +00:00
|
|
|
GList *
|
|
|
|
gtk_printer_option_set_get_groups (GtkPrinterOptionSet *set)
|
|
|
|
{
|
|
|
|
GtkPrinterOption *option;
|
|
|
|
GList *list = NULL;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < set->array->len; i++)
|
|
|
|
{
|
|
|
|
option = g_ptr_array_index (set->array, i);
|
|
|
|
|
2010-01-08 16:42:34 +00:00
|
|
|
if (g_list_find_custom (list, option->group, (GCompareFunc)g_strcmp0) == NULL)
|
2006-04-21 15:09:32 +00:00
|
|
|
list = g_list_prepend (list, g_strdup (option->group));
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_list_reverse (list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_printer_option_set_foreach_in_group (GtkPrinterOptionSet *set,
|
|
|
|
const char *group,
|
|
|
|
GtkPrinterOptionSetFunc func,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkPrinterOption *option;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < set->array->len; i++)
|
|
|
|
{
|
|
|
|
option = g_ptr_array_index (set->array, i);
|
|
|
|
|
2010-03-16 18:16:31 +00:00
|
|
|
if (group == NULL || g_strcmp0 (group, option->group) == 0)
|
2006-04-21 15:09:32 +00:00
|
|
|
func (option, user_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_printer_option_set_foreach (GtkPrinterOptionSet *set,
|
|
|
|
GtkPrinterOptionSetFunc func,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
gtk_printer_option_set_foreach_in_group (set, NULL, func, user_data);
|
|
|
|
}
|