Improving the image logic.

This commit is contained in:
sergiotarxz 2022-01-23 10:53:46 +01:00
parent a17f9c1f25
commit 2c2e1d550e
5 changed files with 40 additions and 7 deletions

View File

@ -9,6 +9,8 @@ typedef struct {
AdwHeaderBar *header;
AdwLeaflet *views_leaflet;
AdwViewStack *view_stack;
GCancellable **image_threads;
size_t image_threads_len;
GtkButton *previous;
gboolean is_set_previous;
} ControlsAdwaita;

1
sqlite

@ -1 +0,0 @@
Subproject commit 855a165fecc25da50cb20525ddf5b9e60a67d18f

View File

@ -26,6 +26,14 @@ manga_selected (GtkListView *list_view,
guint position,
gpointer user_data) {
ControlsAdwaita *controls = (ControlsAdwaita *) user_data;
for (size_t i = 0; i < controls->image_threads_len; i++) {
g_cancellable_cancel (controls->image_threads[i]);
}
if (controls->image_threads) {
g_free (controls->image_threads);
}
controls->image_threads = NULL;
controls->image_threads_len = 0;
AdwLeaflet *views_leaflet = controls->views_leaflet;
GtkSingleSelection *selection = GTK_SINGLE_SELECTION
(gtk_list_view_get_model (list_view));
@ -65,6 +73,7 @@ static void
setup_list_view_mangas (GtkSignalListItemFactory *factory,
GtkListItem *list_item,
gpointer user_data) {
ControlsAdwaita *controls = (ControlsAdwaita *) user_data;
MgManga *manga = gtk_list_item_get_item (list_item);
GtkBox *box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0));
char *manga_title = mg_manga_get_title (manga);
@ -72,8 +81,13 @@ setup_list_view_mangas (GtkSignalListItemFactory *factory,
GtkWidget *label = gtk_label_new (manga_title);
#ifdef LIST_IMAGES
GCancellable *cancellable = g_cancellable_new ();
GtkPicture *picture = create_picture_from_url (image_url, 100,
picture_ready_manga_preview, box, NULL);
picture_ready_manga_preview, box, cancellable);
controls->image_threads_len++;
controls->image_threads = g_realloc (controls->image_threads,
controls->image_threads_len * sizeof *(controls->image_threads));
controls->image_threads[controls->image_threads_len-1] = cancellable;
#endif
g_object_set_property_int (G_OBJECT(box), "height-request", 100);
@ -91,14 +105,13 @@ setup_list_view_mangas (GtkSignalListItemFactory *factory,
GtkListView *
create_list_view_mangas (GListStore *mangas, ControlsAdwaita *controls) {
AdwLeaflet *views_leaflet = controls->views_leaflet;
GtkSingleSelection *selection = gtk_single_selection_new (G_LIST_MODEL (mangas));
GtkListItemFactory *factory = gtk_signal_list_item_factory_new ();
GtkListView *list_view_manga = NULL;
g_signal_connect (G_OBJECT (factory), "bind",
G_CALLBACK (setup_list_view_mangas),
views_leaflet);
controls);
list_view_manga = GTK_LIST_VIEW (gtk_list_view_new (GTK_SELECTION_MODEL (selection),
factory));

View File

@ -54,7 +54,8 @@ activate (AdwApplication *app,
controls->is_set_previous = 0;
controls->header = NULL;
controls->view_stack = view_stack;
controls->image_threads_len = 0;
controls->image_threads = NULL;
views_leaflet_explore = create_explore_leaflet (controls, swipe_back);
views_leaflet_search = create_search_leaflet (controls, swipe_back);

View File

@ -9,6 +9,11 @@ static void
search_text_changed (GtkEntry *entry,
gpointer user_data);
typedef struct {
GtkListView *list_view_mangas;
ControlsAdwaita *controls;
} SearchTextData;
GtkWidget *
create_search_view (ControlsAdwaita *controls) {
GtkWidget *search_view = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
@ -17,12 +22,15 @@ create_search_view (ControlsAdwaita *controls) {
GtkWidget *scroll = gtk_scrolled_window_new ();
GListStore *mangas = g_list_store_new(MG_TYPE_MANGA);
GtkListView *list_view_mangas;
SearchTextData *search_text_data = g_malloc (sizeof *search_text_data);
gtk_box_append (GTK_BOX (search_view), search_entry);
list_view_mangas = create_list_view_mangas (mangas, controls);
search_text_data->list_view_mangas = list_view_mangas;
search_text_data ->controls = controls;
g_signal_connect (search_entry, "activate",
G_CALLBACK (search_text_changed), list_view_mangas);
G_CALLBACK (search_text_changed), search_text_data);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scroll),
GTK_WIDGET (list_view_mangas));
@ -36,11 +44,21 @@ create_search_view (ControlsAdwaita *controls) {
static void
search_text_changed (GtkEntry *entry,
gpointer user_data) {
GtkListView *list_view_mangas = GTK_LIST_VIEW (user_data);
SearchTextData *search_text_data = (SearchTextData *) user_data;
ControlsAdwaita *controls = search_text_data->controls;
GtkListView *list_view_mangas = search_text_data->list_view_mangas;
GtkEntryBuffer *buffer = gtk_entry_get_buffer (entry);
MgBackendReadmng *readmng = mg_backend_readmng_new ();
const char *search_string = gtk_entry_buffer_get_text (buffer);
GListStore *mangas = mg_backend_readmng_search (readmng, search_string);
for (size_t i = 0; i < controls->image_threads_len; i++) {
g_cancellable_cancel (controls->image_threads[i]);
}
if (controls->image_threads) {
g_free (controls->image_threads);
}
controls->image_threads = NULL;
controls->image_threads_len = 0;
if (!mangas) return;
GtkSingleSelection *selection = GTK_SINGLE_SELECTION (
gtk_list_view_get_model (list_view_mangas));