summaryrefslogtreecommitdiff
path: root/wallpapers.c
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-01-30 18:34:40 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2010-01-30 18:34:40 +0100
commitd1c5102c04a4f2745eb808682e575a4f12faa6e1 (patch)
tree9508f833b53d548d2236a026e41e46ef7f9775bb /wallpapers.c
parent91a89808f1f9a19c6703706f1859c870b9884d05 (diff)
Added option to remove missing files from a directory.
Diffstat (limited to 'wallpapers.c')
-rw-r--r--wallpapers.c55
1 files changed, 53 insertions, 2 deletions
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;