Add a 'value' GObject property to GtkPrinterOption so that it can be used with g_object_bind_property()

This commit is contained in:
Richard Hughes 2011-06-09 15:30:31 +01:00
parent 84b3d63838
commit 16d0fca4f5

View File

@ -22,6 +22,8 @@
#include <string.h>
#include <gmodule.h>
#include "gtkintl.h"
#include "gtkprivate.h"
#include "gtkprinteroption.h"
/*****************************************
@ -33,8 +35,22 @@ enum {
LAST_SIGNAL
};
enum {
PROP_0,
PROP_VALUE
};
static guint signals[LAST_SIGNAL] = { 0 };
static void gtk_printer_option_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void gtk_printer_option_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
G_DEFINE_TYPE (GtkPrinterOption, gtk_printer_option, G_TYPE_OBJECT)
static void
@ -71,6 +87,8 @@ gtk_printer_option_class_init (GtkPrinterOptionClass *class)
GObjectClass *gobject_class = (GObjectClass *)class;
gobject_class->finalize = gtk_printer_option_finalize;
gobject_class->set_property = gtk_printer_option_set_property;
gobject_class->get_property = gtk_printer_option_get_property;
signals[CHANGED] =
g_signal_new ("changed",
@ -80,6 +98,14 @@ gtk_printer_option_class_init (GtkPrinterOptionClass *class)
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
g_object_class_install_property (G_OBJECT_CLASS (class),
PROP_VALUE,
g_param_spec_string ("value",
P_("Option Value"),
P_("Value of the option"),
"",
GTK_PARAM_READWRITE));
}
GtkPrinterOption *
@ -97,6 +123,44 @@ gtk_printer_option_new (const char *name, const char *display_text,
return option;
}
static void
gtk_printer_option_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtkPrinterOption *option = GTK_PRINTER_OPTION (object);
switch (prop_id)
{
case PROP_VALUE:
gtk_printer_option_set (option, g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_printer_option_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkPrinterOption *option = GTK_PRINTER_OPTION (object);
switch (prop_id)
{
case PROP_VALUE:
g_value_set_string (value, option->value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
emit_changed (GtkPrinterOption *option)
{