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
|
|
|
|
|
|
|
struct _KonaImage {
|
2016-08-29 17:34:52 +02:00
|
|
|
GObject parent_instance; // Struct of parent (inherit)
|
|
|
|
kona_image_meta meta; // Meta info of the picture
|
|
|
|
GString* preview_file; // Local URL of the preview image
|
|
|
|
GString* full_file; // Local URL of the full image
|
2016-06-04 13:15:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-06-08 22:05:13 +02:00
|
|
|
G_DEFINE_TYPE(KonaImage, kona_image, G_TYPE_OBJECT)
|
2016-06-04 13:15:38 +02:00
|
|
|
|
|
|
|
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:
|
2016-08-29 17:34:52 +02:00
|
|
|
g_value_set_string(value, (const gchar*) self->preview_file);
|
2016-06-04 13:15:38 +02:00
|
|
|
break;
|
2016-06-04 20:55:28 +02:00
|
|
|
case PROP_FILE_FULL:
|
2016-08-29 17:34:52 +02:00
|
|
|
g_value_set_string(value, (const gchar*) self->full_file);
|
2016-06-04 20:55:28 +02:00
|
|
|
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;
|
2016-06-08 22:05:13 +02:00
|
|
|
kona_image_meta *meta;
|
2016-06-04 13:15:38 +02:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2016-06-04 20:55:28 +02:00
|
|
|
case PROP_FILE_FULL:
|
2016-08-29 17:34:52 +02:00
|
|
|
g_free(self->full_file);
|
|
|
|
self->full_file = (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:
|
2016-08-29 17:34:52 +02:00
|
|
|
g_free(self->preview_file);
|
|
|
|
self->preview_file = (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:
|
2016-06-08 22:05:13 +02:00
|
|
|
meta = g_value_get_pointer(value);
|
2016-08-29 17:34:52 +02:00
|
|
|
|
2016-06-08 22:05:13 +02:00
|
|
|
self->meta.id = meta->id;
|
|
|
|
self->meta.width= meta->width;
|
|
|
|
self->meta.height = meta->height;
|
2016-08-29 17:34:52 +02:00
|
|
|
|
|
|
|
// Free URLs (strings)
|
|
|
|
g_free(self->meta.image_url);
|
2016-06-08 22:05:13 +02:00
|
|
|
self->meta.image_url = g_strdup(meta->image_url);
|
2016-08-29 17:34:52 +02:00
|
|
|
g_free(self->meta.preview_url);
|
2016-06-08 22:05:13 +02:00
|
|
|
self->meta.preview_url = g_strdup(meta->preview_url);
|
2016-08-29 17:34:52 +02:00
|
|
|
// Free tag list (string list)
|
|
|
|
g_list_free_full(self->meta.tags, g_free);
|
2016-06-08 22:05:13 +02:00
|
|
|
self->meta.tags = g_list_copy_deep(meta->tags, (GCopyFunc) g_strdup, NULL);
|
2016-08-29 17:34:52 +02:00
|
|
|
|
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-08 22:05:13 +02:00
|
|
|
object_class->dispose = kona_image_dispose;
|
|
|
|
object_class->finalize = kona_image_finalize;
|
2016-06-04 13:15:38 +02:00
|
|
|
|
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) {
|
2016-06-08 22:05:13 +02:00
|
|
|
self->meta.tags = NULL;
|
2016-06-04 13:15:38 +02:00
|
|
|
}
|
|
|
|
|
2016-06-08 22:05:13 +02:00
|
|
|
static void kona_image_dispose(GObject *self) {
|
|
|
|
//KonaImage *ki = (KonaImage*) self;
|
|
|
|
|
2016-06-04 13:15:38 +02:00
|
|
|
G_OBJECT_CLASS (kona_image_parent_class)->dispose((GObject*) self);
|
|
|
|
}
|
|
|
|
|
2016-06-08 22:05:13 +02:00
|
|
|
static void kona_image_finalize(GObject *self) {
|
|
|
|
KonaImage *ki = (KonaImage*) self;
|
|
|
|
|
2016-08-29 17:34:52 +02:00
|
|
|
// Free strings
|
|
|
|
g_free(ki->full_file);
|
|
|
|
g_free(ki->preview_file);
|
|
|
|
|
2016-06-08 22:05:13 +02:00
|
|
|
// Free dynamic meta fields
|
|
|
|
g_free(ki->meta.image_url);
|
|
|
|
g_free(ki->meta.preview_url);
|
2016-06-08 22:06:40 +02:00
|
|
|
g_list_free_full(ki->meta.tags, g_free);
|
2016-06-08 22:05:13 +02:00
|
|
|
G_OBJECT_CLASS (kona_image_parent_class)->finalize (self);
|
2016-06-04 13:15:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|