konaclient-gtk/libkonaclient/konaimage.c
2016-06-04 20:55:28 +02:00

106 lines
2.8 KiB
C

#include "konaimage.h"
#include <stdio.h>
#include <string.h>
typedef struct {
guint64 test;
} KonaImagePrivate;
struct _KonaImage {
GObject parent_instance; // struct of parent (inherit)
kona_image_meta meta;
GString* preview_url;
GString* full_url;
};
G_DEFINE_TYPE_WITH_PRIVATE(KonaImage, kona_image, G_TYPE_OBJECT)
enum {
PROP_META=1,
PROP_FILE_PREVIEW,
PROP_FILE_FULL,
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_FILE_PREVIEW:
g_value_set_string(value, (const gchar*) self->preview_url);
break;
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;
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_FILE_FULL:
g_free(self->full_url);
self->full_url = (GString*) g_strdup(g_value_get_string(value));
break;
case PROP_FILE_PREVIEW:
g_free(self->preview_url);
self->preview_url = (GString*) g_strdup(g_value_get_string(value));
break;
case PROP_META:
memcpy(&self->meta, g_value_get_pointer(value), sizeof(kona_image_meta));
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_META] =
g_param_spec_pointer("meta", "meta", "Meta info struct", G_PARAM_READWRITE);
properties [PROP_FILE_FULL] =
g_param_spec_string("fullFile", "fullFile", "Local URL to the file", "", 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);
}
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->meta.image_url);
g_free(self->meta.preview_url);
g_free(self->meta.tags);
G_OBJECT_CLASS (kona_image_parent_class)->finalize ((GObject*) self);
}
KonaImage *kona_image_new()
{
return g_object_new(KONA_TYPE_IMAGE, 0);
}