Callback after receiving search results

master
Markus Koch 2016-09-05 18:41:34 +02:00
parent c696a369bd
commit 0951764836
1 changed files with 8 additions and 14 deletions

View File

@ -1,9 +1,10 @@
#include "konasearch.h"
#include <stdio.h>
#include <libsoup/soup.h>
static void kona_search_posts_soup_cb(GObject *object, GAsyncResult *result, gpointer user_data);
// Function prototypes for local functions
static void kona_search_posts_soup_cb (SoupSession *session, SoupMessage *msg, gpointer user_data);
/*** GLIB object start ***/
@ -12,7 +13,6 @@ struct _KonaSearch {
gchar *searchString;
SoupSession *postsSession;
GCancellable *postsCancellable;
};
G_DEFINE_TYPE(KonaSearch, kona_search, G_TYPE_OBJECT)
@ -50,35 +50,29 @@ KonaSearch *kona_search_new(gchar *search)
KonaSearch *ks;
ks = g_object_new(KONA_TYPE_SEARCH, 0);
ks->searchString = g_strdup(search);
return G_OBJECT(ks);
return ks;
}
/*** GLIB object end ***/
void kona_search_start(KonaSearch *self)
{
SoupMessage *msg;
gchar *url;
self->postsSession = soup_session_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);
soup_session_queue_message(self->postsSession, msg, kona_search_posts_soup_cb, self);
}
static void kona_search_posts_soup_cb(GObject *object, GAsyncResult *result, gpointer user_data)
static void kona_search_posts_soup_cb (SoupSession *session, SoupMessage *msg, gpointer user_data)
{
GInputStream *stream;
GError *error = NULL;
stream = soup_session_send_finish (SOUP_SESSION (object), result, &error);
printf("RECEIVED!!\n");
printf("%s\n", *msg->response_body);
fflush(stdout);
// MSG will be unref'd automatically
}