From d1c5102c04a4f2745eb808682e575a4f12faa6e1 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sat, 30 Jan 2010 18:34:40 +0100 Subject: Added option to remove missing files from a directory. --- wallpapers.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) (limited to 'wallpapers.c') diff --git a/wallpapers.c b/wallpapers.c index fd893f3..25a6578 100644 --- a/wallpapers.c +++ b/wallpapers.c @@ -13,9 +13,8 @@ #include "wallpapers.h" -static guint context_id = 0; - void add_dir_recursive(const gchar *path, sqlite_uint64 parent, GtkStatusbar *statusbar) { + static guint context_id = 0; GDir *dir; const gchar *filename; sqlite_uint64 dirid; @@ -119,6 +118,58 @@ void add_dir_recursive(const gchar *path, sqlite_uint64 parent, GtkStatusbar *st gdk_threads_leave(); } +void wallpapers_remove_missing(struct directory_t *dir, GtkStatusbar *statusbar, gboolean recursive) { + static guint context_id = 0; + gchar *msg; + GArray *array; + struct wallpaper_t *wall; + + gdk_threads_enter(); + + if(context_id == 0) + context_id = gtk_statusbar_get_context_id(statusbar, "Removal of missing files"); + + msg = g_strdup_printf("Removing missing files from %s", dir->name); + gtk_statusbar_push(statusbar, context_id, msg); + g_free(msg); + + gdk_threads_leave(); + + if(!db_get_wallpapers(dir->dirid, &array)) { + gdk_threads_enter(); + gtk_statusbar_pop(statusbar, context_id); + gtk_statusbar_push(statusbar, context_id, "Failed to get directory wallpapers"); + gdk_threads_leave(); + g_free(dir->name); + return; + } + + for(int i = 0; i < array->len; i++) { + wall = &g_array_index(array, struct wallpaper_t, i); + + if(g_access(wall->filepath, F_OK) == -1) { + msg = g_strdup_printf("Removing %s", wall->filepath); + gdk_threads_enter(); + gtk_statusbar_pop(statusbar, context_id); + gtk_statusbar_push(statusbar, context_id, msg); + gdk_threads_leave(); + g_printf("%s\n", msg); + g_free(msg); + + db_remove_wallpaper(wall->id); + } + + g_free(wall->filepath); + } + g_array_free(array, TRUE); + + gdk_threads_enter(); + gtk_statusbar_pop(statusbar, context_id); + gdk_threads_leave(); + + g_free(dir->name); +} + GdkPixbuf *resize_pixbuf(GdkPixbuf *orig, gint win_width, gint win_height, gint *_width, gint *_height, gdouble *ratio) { GdkPixbuf *pb; gint img_width, img_height, width, height; -- cgit v1.2.3