Tried adding some soup

This commit is contained in:
Markus Koch 2015-09-26 14:01:51 +02:00
parent 8b20ac0461
commit f96afaf355
4 changed files with 76 additions and 7 deletions

View File

@ -3,17 +3,15 @@ project(konaclient-gtk)
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)
# Use the package PkgConfig to detect GTK+ headers/library files
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
# Setup CMake to use GTK+, tell the compiler where to look for headers
# and to the linker where to look for libraries
include_directories(${GTK3_INCLUDE_DIRS})
link_directories(${GTK3_LIBRARY_DIRS})
# Add other flags to the compiler
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})
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})
target_link_libraries(${PROJECT_NAME} ${GTK3_LIBRARIES} ${PC_LIBSOUP_LIBRARIES})

40
kona_search.c Normal file
View File

@ -0,0 +1,40 @@
#include "kona_search.h"
kona_search *kona_search_session_new() {
kona_search *search;
search = malloc(sizeof(kona_search));
if (search) {
search->session = soup_session_new();
search->msg = NULL;
}
return search;
}
int kona_search_new(kona_search *ks, gchar *tags) {
GString *url;
url = g_string_new("http://konachan.com/post.json?tags=");
g_string_append(url, tags);
if (ks->msg == NULL) {
g_print("Message creating\n");
ks->msg = soup_message_new ("GET", url);
g_print("Message created\n");
soup_session_send_async (ks->session,
ks->msg,
NULL, // TODO?
kona_search_callback,
NULL);
g_print("Message sent\n");
}
g_string_free(url, TRUE);
}
static void kona_search_callback (GObject *object, GAsyncResult *result, gpointer user_data)
{
GInputStream *stream;
GError *error = NULL;
stream = soup_session_send_finish (SOUP_SESSION (object), result, &error);
g_print(stream);
}

20
kona_search.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef KONA_SEARCH_H
#define KONA_SEARCH_H
#include <libsoup/soup.h>
#include <stdlib.h>
typedef struct _kona_search kona_search;
struct _kona_search {
SoupSession *session;
SoupMessage *msg;
};
// PUBLIC
kona_search *kona_search_session_new();
int kona_search_new(kona_search *ks, gchar *tags);
// DO NOT CALL
static void kona_search_callback (GObject *object, GAsyncResult *result, gpointer user_data);
#endif // KONA_SEARCH_H

11
main.c
View File

@ -1,5 +1,8 @@
// USE: libsoup (http), json-glib
#include <gtk/gtk.h>
#include "previewwidget.h"
#include "kona_search.h"
int buildWindow();
@ -39,6 +42,14 @@ int buildWindow() {
gtk_widget_show(GTK_WIDGET(mainWindow));
// TTESTT
kona_search *search;
search = kona_search_session_new();
//kona_search_new(search, "yuri");
}
int main(int argc, char **argv)