summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-01-04 02:43:19 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2010-01-04 02:43:19 +0100
commit0f1c07f4835992f3d5b9c2378e0527a633eea225 (patch)
tree4f904327797726001aae87e2cd3fa1bc172ebfee
parent9120a30db940b4e2a4f08ff6436161810b4f8302 (diff)
Moved thumb thread start code to its own function.
-rw-r--r--thumbnails.c10
-rw-r--r--thumbnails.h2
-rw-r--r--window_main.c35
3 files changed, 31 insertions, 16 deletions
diff --git a/thumbnails.c b/thumbnails.c
index 0bffcf5..a684938 100644
--- a/thumbnails.c
+++ b/thumbnails.c
@@ -6,6 +6,9 @@
#include "db.h"
#include "thumbnails.h"
+GThread *thumb_thread = NULL;
+gboolean thumb_thread_exit = FALSE;
+
inline static gchar *get_wall_thumb_name(const gchar *filepath) {
GChecksum *ck;
gchar *s;
@@ -129,6 +132,8 @@ gpointer add_thumbs_thread(gpointer data) {
GdkPixbuf *pb = NULL;
const gchar *filepath;
+ thumb_thread_exit = FALSE;
+
liststore = GTK_LIST_STORE(data);
if(!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(liststore), &iter)) {
@@ -138,6 +143,9 @@ gpointer add_thumbs_thread(gpointer data) {
n = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(liststore), NULL);
for(int i = 0; i < n; i++) {
+ if(thumb_thread_exit == TRUE)
+ break;
+
gtk_tree_model_get_value(GTK_TREE_MODEL(liststore), &iter, 1, &value);
filepath = g_value_get_string(&value);
pb = get_thumbnail(filepath);
@@ -149,4 +157,6 @@ gpointer add_thumbs_thread(gpointer data) {
}
gtk_tree_model_iter_next(GTK_TREE_MODEL(liststore), &iter);
}
+
+ thumb_thread = NULL;
}
diff --git a/thumbnails.h b/thumbnails.h
index d4ab69f..8a0f055 100644
--- a/thumbnails.h
+++ b/thumbnails.h
@@ -4,5 +4,7 @@
#include <glib.h>
gpointer add_thumbs_thread(gpointer data);
+extern GThread *thumb_thread;
+extern gboolean thumb_thread_exit;
#endif
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) {