#include <gtk/gtk.h>
#include <glib-object.h>

typedef struct
{
  GObject parent_instance;
  gchar *prop;
} GtkBuilderCustom;

typedef struct
{
  GObjectClass parent_class;
} GtkBuilderCustomClass;

static void      gtk_builder_custom_finalize     (GtkBuilderCustom      *custom);
static GObject * gtk_builder_custom_constructor  (GType                  type,
						  guint                  n_construct_properties,
						  GObjectConstructParam *construct_properties);
static void      gtk_builder_custom_set_property (GObject               *object,
					    	  guint                  prop_id,
					    	  const GValue          *value,
					    	  GParamSpec            *pspec);
static void      gtk_builder_custom_get_property (GObject               *object,
					    	  guint                  prop_id,
					    	  GValue                *value,
					    	  GParamSpec            *pspec);

#define GTK_TYPE_BUILDER_CUSTOM                 (gtk_builder_custom_get_type ())
#define GTK_BUILDER_CUSTOM(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_BUILDER_CUSTOM, GtkBuilderCustom))

G_DEFINE_TYPE (GtkBuilderCustom, gtk_builder_custom, G_TYPE_OBJECT)

enum {
  PROP_0,
  PROP,
};

static void
gtk_builder_custom_class_init (GtkBuilderCustomClass *klass)
{
  GObjectClass *gobject_class;

  gobject_class = G_OBJECT_CLASS (klass);

  gobject_class->finalize = gtk_builder_custom_finalize;
  gobject_class->constructor = gtk_builder_custom_constructor;
  gobject_class->set_property = gtk_builder_custom_set_property;
  gobject_class->get_property = gtk_builder_custom_get_property;

  g_object_class_install_property (gobject_class,
                                   PROP,
                                   g_param_spec_string ("prop",
                                                        "prop",
                                                        "prop",
                                                        NULL,
                                                        G_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY));
}

static void
gtk_builder_custom_init (GtkBuilderCustom *custom)
{
  custom->prop = NULL;
}

static void
gtk_builder_custom_finalize (GtkBuilderCustom *custom)
{
  g_free (custom->prop);
}

static void
gtk_builder_custom_set_property (GObject      *object,
				 guint         prop_id,
				 const GValue *value,
				 GParamSpec   *pspec)
{
  GtkBuilderCustom *custom = GTK_BUILDER_CUSTOM (object);

  switch (prop_id)
    {
    case PROP:
      custom->prop = g_value_dup_string (value);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

static void
gtk_builder_custom_get_property (GObject    *object,
				 guint       prop_id,
				 GValue     *value,
				 GParamSpec *pspec)
{
  switch (prop_id)
    {
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

static GObject *
gtk_builder_custom_constructor (GType                  type,
				guint                  n_construct_properties,
				GObjectConstructParam *construct_properties)
{
  GObject *custom, *obj;
  
  custom = G_OBJECT_CLASS (gtk_builder_custom_parent_class)->constructor (type,
									  n_construct_properties,
									  construct_properties);
  obj = G_OBJECT (gtk_label_new ("test"));
  g_object_unref (custom);
  return obj;
}

int main(int argc, char **argv)
{
  GObject *obj;
  
  gtk_init (&argc, &argv);

  obj = g_object_new (GTK_TYPE_BUILDER_CUSTOM,
		      "prop", "foo",
		      NULL);
  g_return_val_if_fail(obj != NULL, 1);
  g_print ("%s\n", g_type_name (G_OBJECT_TYPE (obj)));
    
  return 0;
}
