diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e807d44 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +CC := gcc +LIBS := libadwaita-1 gtk4 libsoup-2.4 libxml-2.0 +INCDIR := -I ./include +CFLAGS := $(shell pkg-config --cflags ${LIBS}) -Wall +LDFLAGS := $(shell pkg-config --libs ${LIBS}) +CC_COMMAND := ${CC} ${INCDIR} ${CFLAGS} +all: build +build: + ${CC_COMMAND} mangafox.c main.c -o main ${LDFLAGS} diff --git a/include/manga.h b/include/manga.h new file mode 100644 index 0000000..c08dcaf --- /dev/null +++ b/include/manga.h @@ -0,0 +1,4 @@ +struct Manga { + char *title; + char *image_url; +}; diff --git a/include/mangafox.h b/include/mangafox.h new file mode 100644 index 0000000..1b4b439 --- /dev/null +++ b/include/mangafox.h @@ -0,0 +1,2 @@ +void +retrieve_mangafox_title(); diff --git a/main.c b/main.c new file mode 100644 index 0000000..ce235bd --- /dev/null +++ b/main.c @@ -0,0 +1,63 @@ +#include +#include + +#include + +AdwHeaderBar * +create_headerbar (GtkBox *box); +GtkBox * +create_main_box (AdwApplicationWindow *window); + +static void +activate (AdwApplication *app, + gpointer user_data) +{ + GtkWidget *window = + adw_application_window_new (GTK_APPLICATION (app)); + GtkBox *box = create_main_box( + ADW_APPLICATION_WINDOW + (window)); + create_headerbar (box); + + gtk_widget_show (window); +} + +GtkBox * +create_main_box (AdwApplicationWindow *window) { + GtkWidget *box = gtk_box_new( + GTK_ORIENTATION_VERTICAL, + 10); + adw_application_window_set_content( + window, + box); + return GTK_BOX (box); +} + +AdwHeaderBar * +create_headerbar (GtkBox *box) { + GtkWidget *title = + adw_window_title_new ("Window", NULL); + GtkWidget *header = + adw_header_bar_new(); + adw_header_bar_set_title_widget( + ADW_HEADER_BAR (header), + GTK_WIDGET (title)); + gtk_box_append (GTK_BOX (box), header); + + + return ADW_HEADER_BAR (header); +} + +int +main (int argc, + char **argv) +{ + AdwApplication *app; + retrieve_mangafox_title(); + int status; + app = adw_application_new ("org.mangareader", G_APPLICATION_FLAGS_NONE); + g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); + status = g_application_run (G_APPLICATION (app), argc, argv); + g_object_unref (app); + return status; +} diff --git a/mangafox.c b/mangafox.c new file mode 100644 index 0000000..91d42d8 --- /dev/null +++ b/mangafox.c @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include + +const char *mangafox_url = + "https://mangafox.fun"; + +struct Manga * +parse_main_mangafox_page ( + const xmlDocPtr html_document, + const size_t *size); +xmlXPathObjectPtr +get_nodes_xpath_expression ( + const xmlDocPtr document, + char *xpath); +void +retrieve_mangafox_title() { + SoupSession + *soup_session; + SoupMessage *msg; + GValue response = G_VALUE_INIT; + guint status; + gsize size_response_text; + xmlDocPtr html_response; + + g_value_init (&response, G_TYPE_BYTES); + + soup_session = + soup_session_new(); + msg = + soup_message_new( + "GET", + mangafox_url + ); + status = + soup_session_send_message (soup_session, msg); + g_object_get_property( + G_OBJECT (msg), + "response-body-data", + &response); + const char *response_text = + g_bytes_get_data ( + (GBytes *) + g_value_peek_pointer + (&response), + &size_response_text + ); + html_response = htmlReadMemory (response_text, + size_response_text, + NULL, + NULL, + HTML_PARSE_RECOVER | HTML_PARSE_NODEFDTD + | HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING + ); + size_t manga_size; + parse_main_mangafox_page (html_response, &manga_size); + printf("%u\n", status); +} + + +struct Manga * +parse_main_mangafox_page ( + const xmlDocPtr html_document, + const size_t *size) { + xmlIndentTreeOutput = 1; +// xmlDocDump (stderr, html_document); + xmlXPathObjectPtr xpath_result = get_nodes_xpath_expression (html_document, + "//a"); + if (!xpath_result) { + fprintf(stderr, "Empty xpath result\n"); + return NULL; + } + xmlNodeSetPtr node_set = xpath_result->nodesetval; + printf("%d\n", node_set->nodeNr); + for (int i = 0; i < node_set->nodeNr; i++) { + xmlNodePtr node = node_set->nodeTab[i]; + for (xmlAttr *attrs = node->properties; attrs->next; attrs=attrs->next) { + if (!xmlStrcmp(attrs->name, (const xmlChar *)"href")) { + printf("%s\n", (const char *)attrs->children->content); + } + } + + } +} + +xmlXPathObjectPtr +get_nodes_xpath_expression ( + const xmlDocPtr document, + char *xpath) { + xmlXPathContextPtr context; + xmlXPathObjectPtr result; + + context = xmlXPathNewContext (document); + if (!context) { + fprintf(stderr, "Error in xmlXpathNewContext\n"); + return NULL; + } + result = xmlXPathEvalExpression ((const xmlChar *)xpath, context); + return result; +} +