Imported g_object experiments for lib

This commit is contained in:
Markus Koch 2016-06-04 13:15:38 +02:00
parent f96afaf355
commit 59af4da430
16 changed files with 157 additions and 10 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
*.user
*~
Makefile

View File

@ -1,17 +1,15 @@
project(konaclient-gtk)
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)
set(CMAKE_BUILD_TYPE Release)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
pkg_check_modules(PC_LIBSOUP REQUIRED libsoup-2.4)
pkg_check_modules(GLIB2 REQUIRED glib-2.0)
pkg_check_modules(GOBJECT2 REQUIRED gobject-2.0)
include_directories(${GTK3_INCLUDE_DIRS} ${PC_LIBSOUP_INCLUDE_DIRS})
link_directories(${GTK3_LIBRARY_DIRS} ${PC_LIBSOUP_LIBRARY_DIRS})
add_definitions(${GTK3_CFLAGS_OTHER})
INCLUDE_DIRECTORIES (${GLIB2_INCLUDE_DIRS} ${GOBJECT2_INCLUDE_DIRS} libkonaclient)
LINK_DIRECTORIES (${GLIB2_LIBRARY_DIRS} ${GOBJECT2_LIBRARY_DIRS})
add_definitions(${GLIB2_CFLAGS_OTHER} ${GOBJECT2_CFLAGS_OTHER})
add_executable(${PROJECT_NAME} ${SRC_LIST})
add_subdirectory(libkonaclient)
add_subdirectory(konaclient-gtk)
# Link the target to the GTK+ libraries
target_link_libraries(${PROJECT_NAME} ${GTK3_LIBRARIES} ${PC_LIBSOUP_LIBRARIES})

View File

@ -0,0 +1,14 @@
aux_source_directory(. SRC_LIST)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
pkg_check_modules(PC_LIBSOUP REQUIRED libsoup-2.4)
include_directories(${GTK3_INCLUDE_DIRS} ${PC_LIBSOUP_INCLUDE_DIRS})
link_directories(${GTK3_LIBRARY_DIRS} ${PC_LIBSOUP_LIBRARY_DIRS} libkonaclient)
add_definitions(${GTK3_CFLAGS_OTHER})
add_executable(${PROJECT_NAME} ${SRC_LIST})
# Link the target to the GTK+ libraries
target_link_libraries(${PROJECT_NAME} ${GTK3_LIBRARIES} ${PC_LIBSOUP_LIBRARIES} konaclient)

BIN
konaclient-gtk/konaclient-gtk Executable file

Binary file not shown.

View File

@ -0,0 +1,4 @@
# Build library
aux_source_directory(. LIBSRC_LIST)
add_library(konaclient SHARED ${LIBSRC_LIST})
target_link_libraries(konaclient ${GLIB2_LIBRARIES} ${GOBJECT2_LIBRARIES})

111
libkonaclient/konaimage.c Normal file
View File

@ -0,0 +1,111 @@
#include "konaimage.h"
#include <stdio.h>
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);
}

19
libkonaclient/konaimage.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef KONAIMAGE_H
#define KONAIMAGE_H
#include <glib-object.h>
G_BEGIN_DECLS
#define KONA_TYPE_IMAGE (kona_image_get_type())
G_DECLARE_FINAL_TYPE (KonaImage, kona_image, KONA, IMAGE, GObject) // Struct name, function prefix, Namespace, name, inherits
KonaImage *kona_image_new (void);
const guint64 *kona_image_get_id(KonaImage *self);
void kona_image_set_id(KonaImage *self, const guint64 id);
G_END_DECLS
#endif // KONAIMAGE_H

BIN
libkonaclient/libkonalib.so Executable file

Binary file not shown.