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

@ -39,11 +39,18 @@ link_arguments = [
'-ldl',
'-lm'
]
images_on_lists = get_option('images')
cArgs = ''
if images_on_lists
cArgs = cArgs + '-DLIST_IMAGES'
endif
executable('openmg',
sources,
dependencies : openmgdeps,
include_directories : inc,
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,
xmlNodePtr li);
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 *
mg_backend_readmng_parse_page (MgBackendReadmng *self,
xmlDocPtr html_document);
@ -235,15 +236,21 @@ mg_backend_readmng_fetch_page_url (MgBackendReadmng *self,
GListStore *
mg_backend_readmng_search (MgBackendReadmng *self,
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 ();
GListStore *mangas = g_list_store_new(MG_TYPE_MANGA);
GListStore *mangas = g_list_store_new (MG_TYPE_MANGA);
GError *error = NULL;
JsonNode *root = NULL;
JsonArray *mangas_json_array = NULL;
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) {
g_warning ("Unable to parse json: %s.", error->message);
g_clear_error (&error);
@ -280,14 +287,14 @@ cleanup_mg_backend_readmng_search:
}
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;
MgUtilString *string_util;
char *request_url;
size_t request_url_len;
size_t response_len = 0;
util_soup = mg_util_soup_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;
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 (phrase);

View File

@ -46,6 +46,7 @@ manga_selected (GtkListView *list_view,
adw_leaflet_navigate (views_leaflet, ADW_NAVIGATION_DIRECTION_FORWARD);
}
#ifdef LIST_IMAGES
static void
picture_ready_manga_preview (GObject *source_object,
GAsyncResult *res,
@ -58,6 +59,7 @@ picture_ready_manga_preview (GObject *source_object,
gtk_box_prepend (box, picture);
}
}
#endif
static void
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);
GtkWidget *label = gtk_label_new (manga_title);
#ifdef LIST_IMAGES
GtkPicture *picture = create_picture_from_url (image_url, 100,
picture_ready_manga_preview, box, NULL);
#endif
g_object_set_property_int (G_OBJECT(box), "height-request", 100);
#ifdef LIST_IMAGES
if (picture) {
gtk_box_append (box, GTK_WIDGET (picture));
}
#endif
gtk_box_append (box, label);
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;
g_mutex_lock (&mutex);
if (!g_file_query_exists (image, NULL)) {
g_warning ("Storing %s", url);
iostream = g_file_create_readwrite (image, G_FILE_CREATE_NONE,
NULL, &error);
if (error) {