#include "konaimage.h" #include typedef struct { guint64 test; } KonaImagePrivate; struct _KonaImage { GObject parent_instance; // struct of parent (inherit) guint64 id; GList *tags; GString *url; }; G_DEFINE_TYPE_WITH_PRIVATE(KonaImage, kona_image, G_TYPE_OBJECT) enum { PROP_ID = 1, PROP_TAGS, PROP_URL, PROP_COUNT }; static GParamSpec *properties [PROP_COUNT]; static void kona_image_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { KonaImage *self = (KonaImage*)object; switch (prop_id) { case PROP_ID: g_value_set_uint64(value, *kona_image_get_id(self)); break; case PROP_TAGS: g_value_set_gtype(value, (GType) self->tags); // Returning the pointer itself may be dangerous... Rather copy it to the target value? break; case PROP_URL: g_value_set_string(value, (const gchar*) self->url); default: break; } } static void kona_image_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { KonaImage *self = (KonaImage*)object; switch (prop_id) { case PROP_ID: kona_image_set_id(self, g_value_get_uint64(value)); break; case PROP_TAGS: g_list_free(self->tags); self->tags = g_list_copy((GList*) g_value_get_gtype(value)); break; case PROP_URL: g_free(self->url); self->url = (GString*) g_strdup(g_value_get_string(value)); break; default: break; } } static void kona_image_class_init(KonaImageClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS(klass); object_class->set_property = kona_image_set_property; object_class->get_property = kona_image_get_property; properties [PROP_ID] = g_param_spec_uint64("id", "id", "The ID of the image.", 0, G_MAXINT64, 22, G_PARAM_READWRITE); properties [PROP_TAGS] = g_param_spec_gtype("tags", "tags", "A list of tags.", G_TYPE_NONE, G_PARAM_READWRITE); // TODO: G_TYPE_NONE for a GList(GString) a parameter? properties [PROP_URL] = g_param_spec_string("url", "url", "The URL to the full picture.", "", G_PARAM_READWRITE); g_object_class_install_properties(object_class, PROP_COUNT, properties); } static void kona_image_init (KonaImage *self) { } static void kona_image_dispose(KonaImage *self) { // Clear privates here G_OBJECT_CLASS (kona_image_parent_class)->dispose((GObject*) self); } static void kona_image_finalize(KonaImage *self) { // Clear public vars here g_free(self->tags); G_OBJECT_CLASS (kona_image_parent_class)->finalize ((GObject*) self); } const guint64 *kona_image_get_id(KonaImage *self) { return &(self->id); } void kona_image_set_id(KonaImage *self, const guint64 id) { self->id = id; } KonaImage *kona_image_new() { return g_object_new(KONA_TYPE_IMAGE, 0); }