From 91e6eecfd4d75dcb2943203ca9739711a9a888ce Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Wed, 23 Dec 2009 02:57:31 +0100 Subject: Fixed recursive adding. Removed Imlib2 dependency. --- wallpapers.c | 60 +++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 15 deletions(-) (limited to 'wallpapers.c') diff --git a/wallpapers.c b/wallpapers.c index 53ea102..5e09742 100644 --- a/wallpapers.c +++ b/wallpapers.c @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -14,16 +13,32 @@ #include "wallpapers.h" -void add_dir_recursive(const char *path, sqlite_uint64 parent) { +static guint context_id = 0; + +void add_dir_recursive(const gchar *path, sqlite_uint64 parent, GtkStatusbar *statusbar) { int pathlen = strlen(path); GDir *dir; - const char *filename; + const gchar *filename; sqlite_uint64 dir_temp; sqlite_uint64 dirid; - char *filepath; + gchar *filepath; + gchar *msg; struct stat st; GdkPixbuf *pixbuf; GError *error; + + gdk_threads_enter(); + + if(context_id == 0) + context_id = gtk_statusbar_get_context_id(statusbar, "Recursive directory adding"); + + gtk_statusbar_pop(statusbar, context_id); + + msg = g_strdup_printf("Adding directory: %s", path); + gtk_statusbar_push(statusbar, context_id, msg); + g_free(msg); + + gdk_threads_leave(); dirid = db_get_directory(path); if(dirid == 0) { @@ -44,48 +59,63 @@ void add_dir_recursive(const char *path, sqlite_uint64 parent) { } if(g_access(filepath, R_OK) == -1) { - fprintf(stderr, "Can't read %s: \n", filepath, strerror(errno)); + g_warning("Can't read %s: \n", filepath, strerror(errno)); g_free(filepath); continue; } if(g_stat(filepath, &st) == -1) { - fprintf(stderr, "Failed to stat file %s\n", filepath); + g_warning("Failed to stat file %s\n", filepath); g_free(filepath); continue; } switch(st.st_mode & S_IFMT) { case S_IFDIR: - if(strcmp(filepath, ".") == 0 || strcmp(filepath, "..") == 0) { + if(strcmp(filename, ".") == 0 || strcmp(filename, "..") == 0) { g_free(filepath); continue; } - printf("Directory: %s\n", filepath); - add_dir_recursive(filepath, dirid); + add_dir_recursive(filepath, dirid, statusbar); g_free(filepath); + gdk_threads_enter(); + gtk_statusbar_pop(statusbar, context_id); + gdk_threads_leave(); continue; case S_IFLNK: case S_IFREG: break; default: - printf("Skipping %s\n", filepath); g_free(filepath); continue; } + error = NULL; pixbuf = gdk_pixbuf_new_from_file(filepath, &error); if(!pixbuf) { g_warning("%s", error->message); continue; } - printf("%s loaded: %dx%d\n", filepath, gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf)); - if(db_add_wallpaper(filepath, dirid, st.st_size, gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf))) - printf("added\n"); - else - printf("failed to add\n"); + if(db_add_wallpaper(filepath, dirid, st.st_size, gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf))) { + msg = g_strdup_printf("%s loaded: %dx%d", filepath, gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf)); + } else { + msg = g_strdup_printf("Failed to load %s", filepath); + } + gdk_threads_enter(); + gtk_statusbar_pop(statusbar, context_id); + gtk_statusbar_push(statusbar, context_id, msg); + gdk_threads_leave(); + + g_free(msg); g_object_unref(pixbuf); g_free(filepath); } g_dir_close(dir); + + gdk_threads_enter(); + gtk_statusbar_pop(statusbar, context_id); + msg = g_strdup_printf("Done adding %s", path); + gtk_statusbar_push(statusbar, context_id, msg); + g_free(msg); + gdk_threads_leave(); } -- cgit v1.2.3