Better yet image download.

This commit is contained in:
sergiotarxz 2022-01-23 11:35:31 +01:00
parent 84c47861ad
commit e0c837642b
8 changed files with 16 additions and 7 deletions

View File

@ -11,6 +11,7 @@ typedef struct {
AdwViewStack *view_stack;
GCancellable **image_threads;
size_t image_threads_len;
bool avoid_list_image_downloads;
GtkButton *previous;
gboolean is_set_previous;
} ControlsAdwaita;

View File

@ -3,4 +3,4 @@
GtkPicture *
create_picture_from_url (const char *const url, gint picture_size,
GAsyncReadyCallback ready, gpointer source_object,
gpointer callback_data);
gpointer callback_data, bool do_not_download);

View File

@ -168,7 +168,7 @@ set_image_zoomable_picture_container (ChapterVisorData *chapter_visor_data) {
strlen (url_image_not_owned));
GtkPicture *picture = create_picture_from_url (url_image, 0, picture_ready_manga_page,
zoomable_picture_container, chapter_visor_data);
zoomable_picture_container, chapter_visor_data, false);
if (picture) {
chapter_visor_data->current_picture = GTK_PICTURE (picture);
g_signal_connect (G_OBJECT (picture), "map",

View File

@ -90,7 +90,7 @@ create_detail_view (MgManga *manga, ControlsAdwaita *controls) {
GtkListView *chapter_list = NULL;
char *url_image = mg_manga_get_image_url(manga);
GtkPicture *picture = create_picture_from_url (url_image, 200,
picture_ready_manga_detail, avatar_title_box, NULL);
picture_ready_manga_detail, avatar_title_box, NULL, false);
char *manga_title_text = mg_manga_get_title (manga);
char *title_text = mg_util_xml_get_title_text (
xml_util, manga_title_text);

View File

@ -26,6 +26,7 @@ manga_selected (GtkListView *list_view,
guint position,
gpointer user_data) {
ControlsAdwaita *controls = (ControlsAdwaita *) user_data;
controls->avoid_list_image_downloads = true;;
for (size_t i = 0; i < controls->image_threads_len; i++) {
g_cancellable_cancel (controls->image_threads[i]);
}
@ -52,6 +53,7 @@ manga_selected (GtkListView *list_view,
GtkBox *detail_view = create_detail_view (manga, controls);
adw_leaflet_append (views_leaflet, GTK_WIDGET (detail_view));
adw_leaflet_navigate (views_leaflet, ADW_NAVIGATION_DIRECTION_FORWARD);
controls->avoid_list_image_downloads = false;
}
#ifdef LIST_IMAGES
@ -80,10 +82,13 @@ setup_list_view_mangas (GtkSignalListItemFactory *factory,
char *image_url = mg_manga_get_image_url (manga);
GtkWidget *label = gtk_label_new (manga_title);
GtkPicture *picture = NULL;
#ifdef LIST_IMAGES
printf ("%d\n", controls->avoid_list_image_downloads);
GCancellable *cancellable = g_cancellable_new ();
GtkPicture *picture = create_picture_from_url (image_url, 100,
picture_ready_manga_preview, box, cancellable);
picture = create_picture_from_url (image_url, 100,
picture_ready_manga_preview, box, cancellable,
controls->avoid_list_image_downloads);
controls->image_threads_len++;
controls->image_threads = g_realloc (controls->image_threads,
controls->image_threads_len * sizeof *(controls->image_threads));

View File

@ -56,6 +56,7 @@ activate (AdwApplication *app,
controls->view_stack = view_stack;
controls->image_threads_len = 0;
controls->image_threads = NULL;
controls->avoid_list_image_downloads = false;
views_leaflet_explore = create_explore_leaflet (controls, swipe_back);
views_leaflet_search = create_search_leaflet (controls, swipe_back);

View File

@ -96,7 +96,7 @@ free_picture_thread_attributes (gpointer user_data) {
GtkPicture *
create_picture_from_url (const char *const url, gint picture_size,
GAsyncReadyCallback ready, gpointer source_object,
gpointer callback_data) {
gpointer callback_data, bool do_not_download) {
GtkPicture *picture = NULL;
GFile *image = NULL;
GdkTexture *texture = NULL;
@ -118,7 +118,7 @@ create_picture_from_url (const char *const url, gint picture_size,
g_object_set_property_int (G_OBJECT(picture), "width-request", picture_size);
}
} else {
} else if (!do_not_download) {
GTask *task = g_task_new (source_object, NULL, ready, callback_data);
PictureThreadAttributes *attrs = g_malloc (sizeof *attrs);
attrs->url = g_malloc (url_len * sizeof *url);

View File

@ -59,9 +59,11 @@ search_text_changed (GtkEntry *entry,
}
controls->image_threads = NULL;
controls->image_threads_len = 0;
controls->avoid_list_image_downloads = true;
if (!mangas) return;
GtkSingleSelection *selection = GTK_SINGLE_SELECTION (
gtk_list_view_get_model (list_view_mangas));
gtk_single_selection_set_model (selection,
G_LIST_MODEL (mangas));
controls->avoid_list_image_downloads = false;
}