forked from sergiotarxz/mangareader
Adding functional (almost) search.
This commit is contained in:
parent
31850456aa
commit
749d9e01ca
@ -39,5 +39,8 @@ mg_backend_readmng_retrieve_manga_details (MgBackendReadmng *self,
|
||||
MgManga *manga);
|
||||
GListModel *
|
||||
mg_backend_readmng_get_chapter_images (MgBackendReadmng *self, MgMangaChapter *chapter);
|
||||
GListStore *
|
||||
mg_backend_readmng_search (MgBackendReadmng *self,
|
||||
const char *search_query);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -1,4 +1,8 @@
|
||||
#pragma once
|
||||
#include <glib.h>
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS;
|
||||
|
@ -18,6 +18,8 @@ static AdwLeaflet *
|
||||
create_explore_leaflet (ControlsAdwaita *controls, swipe_back_t swipe_back);
|
||||
static AdwLeaflet *
|
||||
create_search_leaflet (ControlsAdwaita *controls, swipe_back_t swipe_back);
|
||||
static void
|
||||
map_leaflet (GtkWidget *leaflet_widget, gpointer user_data);
|
||||
|
||||
static void
|
||||
activate (AdwApplication *app,
|
||||
@ -60,6 +62,8 @@ activate (AdwApplication *app,
|
||||
AdwViewStackPage *search_page = adw_view_stack_add_titled (view_stack, GTK_WIDGET (views_leaflet_search),
|
||||
"search",
|
||||
"Search");
|
||||
g_signal_connect (G_OBJECT (views_leaflet_search), "map", G_CALLBACK (map_leaflet), controls);
|
||||
g_signal_connect (G_OBJECT (views_leaflet_explore), "map", G_CALLBACK (map_leaflet), controls);
|
||||
|
||||
adw_view_stack_page_set_icon_name (explore_page, "view-list-symbolic");
|
||||
adw_view_stack_page_set_icon_name (search_page, "system-search-symbolic");
|
||||
@ -69,6 +73,13 @@ activate (AdwApplication *app,
|
||||
gtk_widget_show (window);
|
||||
}
|
||||
|
||||
static void
|
||||
map_leaflet (GtkWidget *leaflet_widget, gpointer user_data) {
|
||||
ControlsAdwaita *controls = (ControlsAdwaita *) user_data;
|
||||
AdwLeaflet *leaflet = ADW_LEAFLET (leaflet_widget);
|
||||
controls->views_leaflet = leaflet;
|
||||
}
|
||||
|
||||
static AdwLeaflet *
|
||||
create_search_leaflet (ControlsAdwaita *controls, swipe_back_t swipe_back) {
|
||||
AdwLeaflet *views_leaflet = ADW_LEAFLET (adw_leaflet_new ());
|
||||
|
@ -1,11 +1,49 @@
|
||||
#include <openmg/manga.h>
|
||||
|
||||
#include <openmg/backend/readmng.h>
|
||||
|
||||
#include <openmg/view/search.h>
|
||||
#include <openmg/view/list_view_manga.h>
|
||||
|
||||
static void
|
||||
search_text_changed (GtkEditable *self,
|
||||
gpointer user_data);
|
||||
|
||||
GtkWidget *
|
||||
create_search_view (ControlsAdwaita *controls) {
|
||||
GtkWidget *search_view = gtk_box_new (
|
||||
GTK_ORIENTATION_VERTICAL, 10);
|
||||
GtkWidget *search_view = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
|
||||
|
||||
GtkWidget *search_entry = gtk_entry_new ();
|
||||
gtk_box_append (GTK_BOX (search_view), search_entry);;
|
||||
GtkWidget *scroll = gtk_scrolled_window_new ();
|
||||
GListStore *mangas = g_list_store_new(MG_TYPE_MANGA);
|
||||
GtkListView *list_view_mangas;
|
||||
|
||||
gtk_box_append (GTK_BOX (search_view), search_entry);
|
||||
|
||||
list_view_mangas = create_list_view_mangas (mangas, controls);
|
||||
g_signal_connect (search_entry, "changed",
|
||||
G_CALLBACK (search_text_changed), list_view_mangas);
|
||||
|
||||
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scroll),
|
||||
GTK_WIDGET (list_view_mangas));
|
||||
gtk_box_append (GTK_BOX (search_view), scroll);
|
||||
gtk_widget_set_valign (scroll, GTK_ALIGN_FILL);
|
||||
gtk_widget_set_vexpand (scroll, 1);
|
||||
|
||||
return search_view;
|
||||
}
|
||||
|
||||
static void
|
||||
search_text_changed (GtkEditable *editable,
|
||||
gpointer user_data) {
|
||||
GtkListView *list_view_mangas = GTK_LIST_VIEW (user_data);
|
||||
GtkEntry *entry = GTK_ENTRY (editable);
|
||||
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);
|
||||
GtkSingleSelection *selection = GTK_SINGLE_SELECTION (
|
||||
gtk_list_view_get_model (list_view_mangas));
|
||||
gtk_single_selection_set_model (selection, G_LIST_MODEL (mangas));
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user