Multiple fixes, allowing to compile without images in lists. (Too expensive for some

computers) Logging image writes.
This commit is contained in:
sergiotarxz 2022-01-19 00:29:44 +01:00
parent 10e7ccab2b
commit 03ca046180
5 changed files with 31 additions and 9 deletions

View File

@ -40,10 +40,17 @@ link_arguments = [
'-lm' '-lm'
] ]
images_on_lists = get_option('images')
cArgs = ''
if images_on_lists
cArgs = cArgs + '-DLIST_IMAGES'
endif
executable('openmg', executable('openmg',
sources, sources,
dependencies : openmgdeps, dependencies : openmgdeps,
include_directories : inc, include_directories : inc,
install : true, install : true,
link_args : link_arguments link_args : link_arguments,
c_args: cArgs
) )

1
meson_options.txt Normal file
View File

@ -0,0 +1 @@
option('images', type : 'boolean', value : true)

View File

@ -66,7 +66,8 @@ mg_backend_readmng_loop_li_chapter (
MgBackendReadmng *self, MgBackendReadmng *self,
xmlNodePtr li); xmlNodePtr li);
static char * static char *
mg_backend_readmng_fetch_search (MgBackendReadmng *self, const char *search_query); mg_backend_readmng_fetch_search (MgBackendReadmng *self,
const char *search_query, size_t *response_len);
static GListModel * static GListModel *
mg_backend_readmng_parse_page (MgBackendReadmng *self, mg_backend_readmng_parse_page (MgBackendReadmng *self,
xmlDocPtr html_document); xmlDocPtr html_document);
@ -235,15 +236,21 @@ mg_backend_readmng_fetch_page_url (MgBackendReadmng *self,
GListStore * GListStore *
mg_backend_readmng_search (MgBackendReadmng *self, mg_backend_readmng_search (MgBackendReadmng *self,
const char *search_query) { const char *search_query) {
char *response = mg_backend_readmng_fetch_search (self, search_query); size_t response_len = 0;
char *response = mg_backend_readmng_fetch_search (self, search_query,
&response_len);
JsonParser *parser = json_parser_new (); JsonParser *parser = json_parser_new ();
GListStore *mangas = g_list_store_new(MG_TYPE_MANGA); GListStore *mangas = g_list_store_new (MG_TYPE_MANGA);
GError *error = NULL; GError *error = NULL;
JsonNode *root = NULL; JsonNode *root = NULL;
JsonArray *mangas_json_array = NULL; JsonArray *mangas_json_array = NULL;
guint mangas_json_array_len = 0; guint mangas_json_array_len = 0;
json_parser_load_from_data (parser, response, -1, &error); if (!response) {
g_warning ("Json search response is null.");
goto cleanup_mg_backend_readmng_search;
}
json_parser_load_from_data (parser, response, response_len, &error);
if (error) { if (error) {
g_warning ("Unable to parse json: %s.", error->message); g_warning ("Unable to parse json: %s.", error->message);
g_clear_error (&error); g_clear_error (&error);
@ -280,14 +287,14 @@ cleanup_mg_backend_readmng_search:
} }
static char * static char *
mg_backend_readmng_fetch_search (MgBackendReadmng *self, const char *search_query) { mg_backend_readmng_fetch_search (MgBackendReadmng *self,
const char *search_query, size_t *response_len) {
MgUtilSoup *util_soup; MgUtilSoup *util_soup;
MgUtilString *string_util; MgUtilString *string_util;
char *request_url; char *request_url;
size_t request_url_len; size_t request_url_len;
size_t response_len = 0;
util_soup = mg_util_soup_new (); util_soup = mg_util_soup_new ();
string_util = mg_util_string_new (); string_util = mg_util_string_new ();
@ -328,7 +335,7 @@ mg_backend_readmng_fetch_search (MgBackendReadmng *self, const char *search_quer
size_t body_len = sizeof body / sizeof *body; size_t body_len = sizeof body / sizeof *body;
char *text_response = mg_util_soup_post_request_url_encoded (util_soup, char *text_response = mg_util_soup_post_request_url_encoded (util_soup,
request_url, body, body_len, headers, headers_len, &response_len); request_url, body, body_len, headers, headers_len, response_len);
g_free (request_url); g_free (request_url);
g_free (phrase); g_free (phrase);

View File

@ -46,6 +46,7 @@ manga_selected (GtkListView *list_view,
adw_leaflet_navigate (views_leaflet, ADW_NAVIGATION_DIRECTION_FORWARD); adw_leaflet_navigate (views_leaflet, ADW_NAVIGATION_DIRECTION_FORWARD);
} }
#ifdef LIST_IMAGES
static void static void
picture_ready_manga_preview (GObject *source_object, picture_ready_manga_preview (GObject *source_object,
GAsyncResult *res, GAsyncResult *res,
@ -58,6 +59,7 @@ picture_ready_manga_preview (GObject *source_object,
gtk_box_prepend (box, picture); gtk_box_prepend (box, picture);
} }
} }
#endif
static void static void
setup_list_view_mangas (GtkSignalListItemFactory *factory, setup_list_view_mangas (GtkSignalListItemFactory *factory,
@ -69,13 +71,17 @@ setup_list_view_mangas (GtkSignalListItemFactory *factory,
char *image_url = mg_manga_get_image_url (manga); char *image_url = mg_manga_get_image_url (manga);
GtkWidget *label = gtk_label_new (manga_title); GtkWidget *label = gtk_label_new (manga_title);
#ifdef LIST_IMAGES
GtkPicture *picture = create_picture_from_url (image_url, 100, GtkPicture *picture = create_picture_from_url (image_url, 100,
picture_ready_manga_preview, box, NULL); picture_ready_manga_preview, box, NULL);
#endif
g_object_set_property_int (G_OBJECT(box), "height-request", 100); g_object_set_property_int (G_OBJECT(box), "height-request", 100);
#ifdef LIST_IMAGES
if (picture) { if (picture) {
gtk_box_append (box, GTK_WIDGET (picture)); gtk_box_append (box, GTK_WIDGET (picture));
} }
#endif
gtk_box_append (box, label); gtk_box_append (box, label);
gtk_list_item_set_child (list_item, GTK_WIDGET (box)); gtk_list_item_set_child (list_item, GTK_WIDGET (box));

View File

@ -45,6 +45,7 @@ threaded_picture_recover (GTask *task, gpointer source_object,
static GMutex mutex; static GMutex mutex;
g_mutex_lock (&mutex); g_mutex_lock (&mutex);
if (!g_file_query_exists (image, NULL)) { if (!g_file_query_exists (image, NULL)) {
g_warning ("Storing %s", url);
iostream = g_file_create_readwrite (image, G_FILE_CREATE_NONE, iostream = g_file_create_readwrite (image, G_FILE_CREATE_NONE,
NULL, &error); NULL, &error);
if (error) { if (error) {