Some cleanups + soup works
This commit is contained in:
parent
e3e35c2df3
commit
c696a369bd
@ -60,8 +60,8 @@ void test_kona_search() {
|
||||
|
||||
kona_search_start(ks);
|
||||
|
||||
//GMainLoop *loop = g_main_loop_new(NULL, FALSE);
|
||||
//g_main_loop_run(loop);
|
||||
GMainLoop *loop = g_main_loop_new(NULL, FALSE);
|
||||
g_main_loop_run(loop);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
@ -3,10 +3,10 @@
|
||||
#include <string.h>
|
||||
|
||||
struct _KonaImage {
|
||||
GObject parent_instance; // struct of parent (inherit)
|
||||
kona_image_meta meta;
|
||||
GString* preview_url;
|
||||
GString* full_url;
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
@ -26,10 +26,10 @@ static void kona_image_get_property(GObject *object, guint prop_id, GValue *valu
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_FILE_PREVIEW:
|
||||
g_value_set_string(value, (const gchar*) self->preview_url);
|
||||
g_value_set_string(value, (const gchar*) self->preview_file);
|
||||
break;
|
||||
case PROP_FILE_FULL:
|
||||
g_value_set_string(value, (const gchar*) self->full_url);
|
||||
g_value_set_string(value, (const gchar*) self->full_file);
|
||||
break;
|
||||
case PROP_META:
|
||||
g_value_set_pointer(value, &self->meta);
|
||||
@ -45,21 +45,29 @@ static void kona_image_set_property(GObject *object, guint prop_id, const GValue
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_FILE_FULL:
|
||||
g_free(self->full_url);
|
||||
self->full_url = (GString*) g_strdup(g_value_get_string(value));
|
||||
g_free(self->full_file);
|
||||
self->full_file = (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));
|
||||
g_free(self->preview_file);
|
||||
self->preview_file = (GString*) g_strdup(g_value_get_string(value));
|
||||
break;
|
||||
case PROP_META:
|
||||
meta = g_value_get_pointer(value);
|
||||
|
||||
self->meta.id = meta->id;
|
||||
self->meta.width= meta->width;
|
||||
self->meta.height = meta->height;
|
||||
|
||||
// Free URLs (strings)
|
||||
g_free(self->meta.image_url);
|
||||
self->meta.image_url = g_strdup(meta->image_url);
|
||||
g_free(self->meta.preview_url);
|
||||
self->meta.preview_url = g_strdup(meta->preview_url);
|
||||
// Free tag list (string list)
|
||||
g_list_free_full(self->meta.tags, g_free);
|
||||
self->meta.tags = g_list_copy_deep(meta->tags, (GCopyFunc) g_strdup, NULL);
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -99,6 +107,10 @@ static void kona_image_dispose(GObject *self) {
|
||||
static void kona_image_finalize(GObject *self) {
|
||||
KonaImage *ki = (KonaImage*) self;
|
||||
|
||||
// Free strings
|
||||
g_free(ki->full_file);
|
||||
g_free(ki->preview_file);
|
||||
|
||||
// Free dynamic meta fields
|
||||
g_free(ki->meta.image_url);
|
||||
g_free(ki->meta.preview_url);
|
||||
|
@ -41,6 +41,7 @@ static void kona_search_finalize(GObject *self)
|
||||
{
|
||||
KonaSearch *ks = (KonaSearch*) self;
|
||||
//g_free(ks->postsSession);
|
||||
g_free(ks->searchString);
|
||||
G_OBJECT_CLASS (kona_search_parent_class)->finalize ((GObject*) self);
|
||||
}
|
||||
|
||||
@ -60,25 +61,24 @@ void kona_search_start(KonaSearch *self)
|
||||
gchar *url;
|
||||
|
||||
self->postsSession = soup_session_new();
|
||||
//self->postsCancellable = g_cancellable_new();
|
||||
self->postsCancellable = g_cancellable_new();
|
||||
|
||||
url = g_strdup_printf("http://konachan.com/post.xml?tag=%s", self->searchString);
|
||||
msg = soup_message_new("GET", url);
|
||||
g_free(url);
|
||||
|
||||
//soup_session_send_async(self->postsSession, msg, self->postsCancellable, kona_search_posts_soup_cb, self);
|
||||
printf("C"); fflush(stdout);
|
||||
soup_session_send_message (self->postsSession, msg);
|
||||
printf("D"); fflush(stdout);
|
||||
soup_session_send_async(self->postsSession, msg, self->postsCancellable, kona_search_posts_soup_cb, self);
|
||||
}
|
||||
|
||||
static void kona_search_posts_soup_cb(GObject *object, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
GInputStream *stream;
|
||||
GError *error = NULL;
|
||||
printf("D"); fflush(stdout);
|
||||
|
||||
stream = soup_session_send_finish (SOUP_SESSION (object), result, &error);
|
||||
|
||||
printf("RECEIVED!!\n");
|
||||
fflush(stdout);
|
||||
|
||||
// MSG will be unref'd automatically
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user