diff --git a/konaclient-gtk/main.c b/konaclient-gtk/main.c index c0599e1..9c49560 100644 --- a/konaclient-gtk/main.c +++ b/konaclient-gtk/main.c @@ -46,6 +46,8 @@ int buildWindow() { /*** TESTING LIB ***/ GValue val = G_VALUE_INIT; + GValue sval = G_VALUE_INIT; + KonaImage *ki; kona_image_meta meta; ki = kona_image_new(); @@ -60,7 +62,14 @@ int buildWindow() { g_object_set_property((GObject*) ki, "meta", &val); + g_value_init(&sval, G_TYPE_STRING); + g_value_set_string(&sval, "Hello world!"); + g_object_set_property((GObject*) ki, "fullFile", &sval); + + g_value_reset(&val); + g_value_reset(&sval); + meta.height = 0; meta.width = 1; @@ -70,6 +79,10 @@ int buildWindow() { metret = g_value_get_pointer(&val); printf("WIDTH=%i\n", metret->width); printf("HEIGHT=%i\n", metret->height); + + g_object_get_property((GObject*) ki, "fullFile", &sval); + printf("STRING=%s\n", g_value_get_string(&sval)); + } int main(int argc, char **argv) diff --git a/libkonaclient/konaimage.c b/libkonaclient/konaimage.c index f982c87..0e01ff2 100644 --- a/libkonaclient/konaimage.c +++ b/libkonaclient/konaimage.c @@ -1,5 +1,6 @@ #include "konaimage.h" #include +#include typedef struct { guint64 test; @@ -7,18 +8,18 @@ typedef struct { struct _KonaImage { GObject parent_instance; // struct of parent (inherit) - guint64 id; - GList *tags; - GString *url; + kona_image_meta meta; + GString* preview_url; + GString* full_url; }; G_DEFINE_TYPE_WITH_PRIVATE(KonaImage, kona_image, G_TYPE_OBJECT) enum { - PROP_ID = 1, - PROP_TAGS, - PROP_URL, + PROP_META=1, + PROP_FILE_PREVIEW, + PROP_FILE_FULL, PROP_COUNT }; @@ -28,14 +29,15 @@ static void kona_image_get_property(GObject *object, guint prop_id, GValue *valu KonaImage *self = (KonaImage*)object; switch (prop_id) { - case PROP_ID: - g_value_set_uint64(value, *kona_image_get_id(self)); + case PROP_FILE_PREVIEW: + g_value_set_string(value, (const gchar*) self->preview_url); 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? + case PROP_FILE_FULL: + g_value_set_string(value, (const gchar*) self->full_url); + break; + case PROP_META: + g_value_set_pointer(value, &self->meta); break; - case PROP_URL: - g_value_set_string(value, (const gchar*) self->url); default: break; } @@ -45,16 +47,16 @@ static void kona_image_set_property(GObject *object, guint prop_id, const GValue KonaImage *self = (KonaImage*)object; switch (prop_id) { - case PROP_ID: - kona_image_set_id(self, g_value_get_uint64(value)); + case PROP_FILE_FULL: + g_free(self->full_url); + self->full_url = (GString*) g_strdup(g_value_get_string(value)); break; - case PROP_TAGS: - g_list_free(self->tags); - self->tags = g_list_copy((GList*) g_value_get_gtype(value)); + case PROP_FILE_PREVIEW: + g_free(self->preview_url); + self->preview_url = (GString*) g_strdup(g_value_get_string(value)); break; - case PROP_URL: - g_free(self->url); - self->url = (GString*) g_strdup(g_value_get_string(value)); + case PROP_META: + memcpy(&self->meta, g_value_get_pointer(value), sizeof(kona_image_meta)); break; default: break; @@ -67,14 +69,14 @@ static void kona_image_class_init(KonaImageClass *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_META] = + g_param_spec_pointer("meta", "meta", "Meta info struct", 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_FILE_FULL] = + g_param_spec_string("fullFile", "fullFile", "Local URL to the file", "", G_PARAM_READWRITE); - properties [PROP_URL] = - g_param_spec_string("url", "url", "The URL to the full picture.", "", G_PARAM_READWRITE); + properties [PROP_FILE_PREVIEW] = + g_param_spec_string("previewFile", "previewFile", "Local URL to the preview file", "", G_PARAM_READWRITE); g_object_class_install_properties(object_class, PROP_COUNT, properties); } @@ -90,20 +92,12 @@ static void kona_image_dispose(KonaImage *self) { static void kona_image_finalize(KonaImage *self) { // Clear public vars here - g_free(self->tags); + g_free(self->meta.image_url); + g_free(self->meta.preview_url); + g_free(self->meta.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() { diff --git a/libkonaclient/konaimage.h b/libkonaclient/konaimage.h index 0e9a185..6ebd845 100644 --- a/libkonaclient/konaimage.h +++ b/libkonaclient/konaimage.h @@ -11,8 +11,15 @@ G_DECLARE_FINAL_TYPE (KonaImage, kona_image, KONA, IMAGE, GObject) // Struct nam KonaImage *kona_image_new (void); -const guint64 *kona_image_get_id(KonaImage *self); -void kona_image_set_id(KonaImage *self, const guint64 id); +struct kona_image_meta_struct { + int id; + GList *tags; + char* preview_url; + char* image_url; + int width; + int height; +}; +typedef struct kona_image_meta_struct kona_image_meta; G_END_DECLS