forked from sergiotarxz/mangareader
Adding a little of async to enhance load times.
This commit is contained in:
parent
afe558e676
commit
1ff3ba89dc
@ -8,6 +8,15 @@
|
|||||||
static void
|
static void
|
||||||
search_text_changed (GtkEditable *self,
|
search_text_changed (GtkEditable *self,
|
||||||
gpointer user_data);
|
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,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
GtkWidget *
|
GtkWidget *
|
||||||
create_search_view (ControlsAdwaita *controls) {
|
create_search_view (ControlsAdwaita *controls) {
|
||||||
@ -33,17 +42,43 @@ create_search_view (ControlsAdwaita *controls) {
|
|||||||
return search_view;
|
return search_view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GCancellable *cancellable = NULL;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
search_text_changed (GtkEditable *editable,
|
search_text_changed (GtkEditable *editable,
|
||||||
gpointer user_data) {
|
gpointer user_data) {
|
||||||
|
if (cancellable) {
|
||||||
|
g_cancellable_cancel (cancellable);
|
||||||
|
}
|
||||||
|
cancellable = g_cancellable_new ();
|
||||||
GtkListView *list_view_mangas = GTK_LIST_VIEW (user_data);
|
GtkListView *list_view_mangas = GTK_LIST_VIEW (user_data);
|
||||||
GtkEntry *entry = GTK_ENTRY (editable);
|
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));
|
||||||
|
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);
|
GtkEntryBuffer *buffer = gtk_entry_get_buffer (entry);
|
||||||
MgBackendReadmng *readmng = mg_backend_readmng_new ();
|
MgBackendReadmng *readmng = mg_backend_readmng_new ();
|
||||||
const char *search_string = gtk_entry_buffer_get_text (buffer);
|
const char *search_string = gtk_entry_buffer_get_text (buffer);
|
||||||
GListStore *mangas = mg_backend_readmng_search (readmng, search_string);
|
GListStore *mangas = mg_backend_readmng_search (readmng, search_string);
|
||||||
GtkSingleSelection *selection = GTK_SINGLE_SELECTION (
|
g_task_return_pointer (task, mangas, g_object_unref);
|
||||||
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