Callback after receiving search results
parent
c696a369bd
commit
0951764836
|
@ -1,9 +1,10 @@
|
||||||
#include "konasearch.h"
|
#include "konasearch.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <libsoup/soup.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 ***/
|
/*** GLIB object start ***/
|
||||||
|
|
||||||
|
@ -12,7 +13,6 @@ struct _KonaSearch {
|
||||||
gchar *searchString;
|
gchar *searchString;
|
||||||
|
|
||||||
SoupSession *postsSession;
|
SoupSession *postsSession;
|
||||||
GCancellable *postsCancellable;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE(KonaSearch, kona_search, G_TYPE_OBJECT)
|
G_DEFINE_TYPE(KonaSearch, kona_search, G_TYPE_OBJECT)
|
||||||
|
@ -50,35 +50,29 @@ KonaSearch *kona_search_new(gchar *search)
|
||||||
KonaSearch *ks;
|
KonaSearch *ks;
|
||||||
ks = g_object_new(KONA_TYPE_SEARCH, 0);
|
ks = g_object_new(KONA_TYPE_SEARCH, 0);
|
||||||
ks->searchString = g_strdup(search);
|
ks->searchString = g_strdup(search);
|
||||||
return G_OBJECT(ks);
|
return ks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** GLIB object end ***/
|
/*** GLIB object end ***/
|
||||||
|
|
||||||
|
|
||||||
void kona_search_start(KonaSearch *self)
|
void kona_search_start(KonaSearch *self)
|
||||||
{
|
{
|
||||||
SoupMessage *msg;
|
SoupMessage *msg;
|
||||||
gchar *url;
|
gchar *url;
|
||||||
|
|
||||||
self->postsSession = soup_session_new();
|
self->postsSession = soup_session_new();
|
||||||
self->postsCancellable = g_cancellable_new();
|
|
||||||
|
|
||||||
url = g_strdup_printf("http://konachan.com/post.xml?tag=%s", self->searchString);
|
url = g_strdup_printf("http://konachan.com/post.xml?tag=%s", self->searchString);
|
||||||
msg = soup_message_new("GET", url);
|
msg = soup_message_new("GET", url);
|
||||||
g_free(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("RECEIVED!!\n");
|
||||||
|
printf("%s\n", *msg->response_body);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
// MSG will be unref'd automatically
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue