forked from sergiotarxz/mangareader
Adding non-threaded search.
This commit is contained in:
parent
f22ef00a2c
commit
b4372119c0
@ -6,16 +6,7 @@
|
||||
#include <openmg/view/list_view_manga.h>
|
||||
|
||||
static void
|
||||
search_text_changed (GtkEditable *self,
|
||||
gpointer user_data);
|
||||
static void
|
||||
async_search_manga (GTask *task,
|
||||
gpointer source_object,
|
||||
gpointer task_data,
|
||||
GCancellable *cancellable);
|
||||
static void
|
||||
set_mangas_to_list_view (GObject *source_object,
|
||||
GAsyncResult *res,
|
||||
search_text_changed (GtkEntry *entry,
|
||||
gpointer user_data);
|
||||
|
||||
GtkWidget *
|
||||
@ -30,7 +21,7 @@ create_search_view (ControlsAdwaita *controls) {
|
||||
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_signal_connect (search_entry, "activate",
|
||||
G_CALLBACK (search_text_changed), list_view_mangas);
|
||||
|
||||
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scroll),
|
||||
@ -42,43 +33,17 @@ create_search_view (ControlsAdwaita *controls) {
|
||||
return search_view;
|
||||
}
|
||||
|
||||
static GCancellable *cancellable = NULL;
|
||||
|
||||
static void
|
||||
search_text_changed (GtkEditable *editable,
|
||||
search_text_changed (GtkEntry *entry,
|
||||
gpointer user_data) {
|
||||
if (cancellable) {
|
||||
g_cancellable_cancel (cancellable);
|
||||
}
|
||||
cancellable = g_cancellable_new ();
|
||||
GtkListView *list_view_mangas = GTK_LIST_VIEW (user_data);
|
||||
GTask *task = g_task_new (editable, cancellable, set_mangas_to_list_view,list_view_mangas);
|
||||
g_task_set_return_on_cancel (task, true);
|
||||
g_task_run_in_thread (task, async_search_manga);
|
||||
}
|
||||
|
||||
static void
|
||||
set_mangas_to_list_view (GObject *source_object,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data) {
|
||||
GListStore *mangas = G_LIST_STORE (g_task_propagate_pointer (G_TASK (res), NULL));
|
||||
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);
|
||||
if (!mangas) return;
|
||||
GtkListView *list_view_mangas = GTK_LIST_VIEW (user_data);
|
||||
GtkSingleSelection *selection = GTK_SINGLE_SELECTION (
|
||||
gtk_list_view_get_model (list_view_mangas));
|
||||
gtk_single_selection_set_model (selection,
|
||||
G_LIST_MODEL (mangas));
|
||||
}
|
||||
|
||||
static void
|
||||
async_search_manga (GTask *task,
|
||||
gpointer source_object,
|
||||
gpointer task_data,
|
||||
GCancellable *cancellable) {
|
||||
GtkEntry *entry = GTK_ENTRY (source_object);
|
||||
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);
|
||||
g_task_return_pointer (task, mangas, g_object_unref);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user