From 0f1c07f4835992f3d5b9c2378e0527a633eea225 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Mon, 4 Jan 2010 02:43:19 +0100 Subject: Moved thumb thread start code to its own function. --- window_main.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'window_main.c') diff --git a/window_main.c b/window_main.c index 5183c57..7a95761 100644 --- a/window_main.c +++ b/window_main.c @@ -26,8 +26,7 @@ GtkStatusbar *statusbar; GtkIconView *thumbview; GtkWidget *window_hpane, *window_vpane, *foldtree, *tagview; -GThread *add_thread = NULL, - *thumb_thread = NULL; +GThread *add_thread = NULL; gchar *cur_wall_msg = NULL; @@ -269,13 +268,28 @@ static void fill_wall_list(GtkListStore *liststore, GArray *array) { g_array_free(array, TRUE); } +static void start_thumb_thread(GtkListStore *liststore) { + GError *error = NULL; + + if(thumb_thread) { + thumb_thread_exit = TRUE; + g_thread_join(thumb_thread); + } + + thumb_thread = g_thread_create(add_thumbs_thread, liststore, TRUE, &error); + + if(!thumb_thread) { + g_warning("Failed to start the thumbnail thread: %s", error->message); + g_error_free(error); + } +} + static void display_from_foldtree(GtkTreeSelection *treeselection) { GtkTreeModel *model; GtkTreeIter iter; struct directory_t *dir; GArray *array; GtkListStore *liststore; - GError *error = NULL; if(treeselection == NULL) treeselection = gtk_tree_view_get_selection(GTK_TREE_VIEW(foldtree)); @@ -290,12 +304,7 @@ static void display_from_foldtree(GtkTreeSelection *treeselection) { fill_wall_list(liststore, array); gtk_icon_view_set_model(thumbview, GTK_TREE_MODEL(liststore)); - thumb_thread = g_thread_create(add_thumbs_thread, liststore, FALSE, &error); - - if(!thumb_thread) { - g_warning("%s", error->message); - g_error_free(error); - } + start_thumb_thread(liststore); } } @@ -339,7 +348,6 @@ void display_from_tagview() { gboolean active; GArray *tagarray, *wallarray; guint64 id; - GError *error = NULL; model = gtk_tree_view_get_model(GTK_TREE_VIEW(tagview)); @@ -373,12 +381,7 @@ void display_from_tagview() { fill_wall_list(liststore, wallarray); gtk_icon_view_set_model(thumbview, GTK_TREE_MODEL(liststore)); - thumb_thread = g_thread_create(add_thumbs_thread, liststore, FALSE, &error); - - if(!thumb_thread) { - g_warning("%s\n", error->message); - g_error_free(error); - } + start_thumb_thread(liststore); } void on_main_tagview_cell_toggled(GtkCellRendererToggle *cell_renderer, gchar *path_string, gpointer user_data) { -- cgit v1.2.3