konaclient-gtk/libkonaclient/konaimage.c

116 lines
3.1 KiB
C
Raw Normal View History

2016-06-04 13:15:38 +02:00
#include "konaimage.h"
#include <stdio.h>
2016-06-04 20:55:28 +02:00
#include <string.h>
2016-06-04 13:15:38 +02:00
typedef struct {
guint64 test;
} KonaImagePrivate;
struct _KonaImage {
GObject parent_instance; // struct of parent (inherit)
2016-06-04 20:55:28 +02:00
kona_image_meta meta;
GString* preview_url;
GString* full_url;
2016-06-04 13:15:38 +02:00
};
G_DEFINE_TYPE_WITH_PRIVATE(KonaImage, kona_image, G_TYPE_OBJECT)
enum {
2016-06-04 20:55:28 +02:00
PROP_META=1,
PROP_FILE_PREVIEW,
PROP_FILE_FULL,
2016-06-04 13:15:38 +02:00
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) {
2016-06-04 20:55:28 +02:00
case PROP_FILE_PREVIEW:
g_value_set_string(value, (const gchar*) self->preview_url);
2016-06-04 13:15:38 +02:00
break;
2016-06-04 20:55:28 +02:00
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);
2016-06-04 13:15:38 +02:00
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) {
2016-06-04 20:55:28 +02:00
case PROP_FILE_FULL:
g_free(self->full_url);
self->full_url = (GString*) g_strdup(g_value_get_string(value));
2016-06-04 13:15:38 +02:00
break;
2016-06-04 20:55:28 +02:00
case PROP_FILE_PREVIEW:
g_free(self->preview_url);
self->preview_url = (GString*) g_strdup(g_value_get_string(value));
2016-06-04 13:15:38 +02:00
break;
2016-06-04 20:55:28 +02:00
case PROP_META:
memcpy(&self->meta, g_value_get_pointer(value), sizeof(kona_image_meta));
2016-06-04 13:15:38 +02:00
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;
2016-06-04 20:55:28 +02:00
properties [PROP_META] =
g_param_spec_pointer("meta", "meta", "Meta info struct", G_PARAM_READWRITE);
2016-06-04 13:15:38 +02:00
2016-06-04 20:55:28 +02:00
properties [PROP_FILE_FULL] =
g_param_spec_string("fullFile", "fullFile", "Local URL to the file", "", G_PARAM_READWRITE);
2016-06-04 13:15:38 +02:00
2016-06-04 20:55:28 +02:00
properties [PROP_FILE_PREVIEW] =
g_param_spec_string("previewFile", "previewFile", "Local URL to the preview file", "", G_PARAM_READWRITE);
2016-06-04 13:15:38 +02:00
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
2016-06-04 20:55:28 +02:00
g_free(self->meta.image_url);
g_free(self->meta.preview_url);
g_free(self->meta.tags);
2016-06-04 13:15:38 +02:00
G_OBJECT_CLASS (kona_image_parent_class)->finalize ((GObject*) self);
}
KonaImage *kona_image_new()
{
return g_object_new(KONA_TYPE_IMAGE, 0);
}
2016-06-06 22:01:29 +02:00
kona_image_meta* kona_image_get_meta_from_konaimage(KonaImage *ki) {
kona_image_meta *meta;
GValue val = G_VALUE_INIT;
g_value_init(&val, G_TYPE_POINTER);
g_object_get_property(G_OBJECT(ki), "meta", &val);
meta = g_value_get_pointer(&val);
g_value_reset(&val);
return meta;
}