From 4c492a579184396015041208b8af53cc45cea647 Mon Sep 17 00:00:00 2001 From: sergiotarxz Date: Sun, 31 Oct 2021 20:42:58 +0100 Subject: [PATCH] Making listviewitems on clicked to send us to a new screen. --- include/openmg/view/list_view_manga.h | 3 +- src/view/list_view_manga.c | 48 ++++++++++++++++++++++----- src/view/main_view.c | 3 +- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/include/openmg/view/list_view_manga.h b/include/openmg/view/list_view_manga.h index de02eb1..54b3ad5 100644 --- a/include/openmg/view/list_view_manga.h +++ b/include/openmg/view/list_view_manga.h @@ -1,4 +1,5 @@ #include +#include GtkListView * -create_list_view_mangas (GListStore *mangas); +create_list_view_mangas (GListStore *mangas, AdwLeaflet *views_leaflet); diff --git a/src/view/list_view_manga.c b/src/view/list_view_manga.c index 2abfbd3..9a49798 100644 --- a/src/view/list_view_manga.c +++ b/src/view/list_view_manga.c @@ -1,4 +1,6 @@ #include +#include +#include #include #include @@ -12,12 +14,30 @@ setup_list_view_mangas (GtkSignalListItemFactory *factory, GtkListItem *list_item, gpointer user_data); +typedef struct { + GListStore *mangas; + AdwLeaflet *views_leaflet; +} MangaPressedValues; + +static void +manga_selected (GtkListView *list_view, + guint position, + gpointer user_data) { + MangaPressedValues *manga_pressed_values = (MangaPressedValues *) user_data; + AdwLeaflet *views_leaflet = manga_pressed_values->views_leaflet; + GtkBox *box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 0)); + printf ("hello world\n"); + adw_leaflet_append (views_leaflet, GTK_WIDGET (box)); + adw_leaflet_navigate (views_leaflet, ADW_NAVIGATION_DIRECTION_FORWARD); +} + static void setup_list_view_mangas (GtkSignalListItemFactory *factory, GtkListItem *list_item, gpointer user_data) { MgManga *manga = gtk_list_item_get_item (list_item); GtkBox *box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0)); + GtkWidget *label = gtk_label_new (mg_manga_get_title (manga)); GtkWidget *picture; @@ -33,15 +53,15 @@ setup_list_view_mangas (GtkSignalListItemFactory *factory, &size_downloaded_image); tmp_image = g_file_new_tmp ("mangareadertmpfileXXXXXX", &iostream, - &error - ); + &error + ); if (error) { fprintf (stderr, "Unable to read file: %s\n", error->message); return; } error = NULL; g_output_stream_write (g_io_stream_get_output_stream (G_IO_STREAM (iostream)), - downloaded_image, size_downloaded_image, NULL, &error); + downloaded_image, size_downloaded_image, NULL, &error); if (error) { fprintf (stderr, "Unable to write file: %s\n", error->message); return; @@ -54,14 +74,26 @@ setup_list_view_mangas (GtkSignalListItemFactory *factory, } GtkListView * -create_list_view_mangas (GListStore *mangas) { +create_list_view_mangas (GListStore *mangas, AdwLeaflet *views_leaflet) { GtkSingleSelection *selection = gtk_single_selection_new (G_LIST_MODEL (mangas)); GtkListItemFactory *factory = gtk_signal_list_item_factory_new (); + MangaPressedValues *manga_pressed_values = NULL; + GtkListView *list_view_manga = NULL; + + manga_pressed_values = g_malloc (sizeof *manga_pressed_values); + manga_pressed_values->mangas = mangas; + manga_pressed_values->views_leaflet = views_leaflet; + g_signal_connect (G_OBJECT (factory), "bind", - G_CALLBACK (setup_list_view_mangas), - NULL); - return GTK_LIST_VIEW (gtk_list_view_new (GTK_SELECTION_MODEL (selection), - factory)); + G_CALLBACK (setup_list_view_mangas), + views_leaflet); + + list_view_manga = GTK_LIST_VIEW (gtk_list_view_new (GTK_SELECTION_MODEL (selection), + factory)); + + g_signal_connect (G_OBJECT (list_view_manga), "activate", + G_CALLBACK (manga_selected), manga_pressed_values); + return list_view_manga; } static void diff --git a/src/view/main_view.c b/src/view/main_view.c index b47564a..3b219fb 100644 --- a/src/view/main_view.c +++ b/src/view/main_view.c @@ -28,7 +28,7 @@ activate (AdwApplication *app, create_headerbar (box); mangas = mg_backend_readmng_get_featured_manga (readmng); - list_view = create_list_view_mangas (mangas); + list_view = create_list_view_mangas (mangas, views_leaflet); scroll = gtk_scrolled_window_new (); gtk_widget_set_valign (scroll, GTK_ALIGN_FILL); @@ -37,7 +37,6 @@ activate (AdwApplication *app, adw_leaflet_append (views_leaflet, scroll); adw_leaflet_set_can_unfold (views_leaflet, false); -// adw_leaflet_set_visible_child (views_leaflet, scroll); gtk_box_append (box, GTK_WIDGET (views_leaflet));