summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wallpapers.c5
-rw-r--r--wallpapers.h2
-rw-r--r--window_main.c36
3 files changed, 35 insertions, 8 deletions
diff --git a/wallpapers.c b/wallpapers.c
index 25a6578..67c9cef 100644
--- a/wallpapers.c
+++ b/wallpapers.c
@@ -13,7 +13,7 @@
#include "wallpapers.h"
-void add_dir_recursive(const gchar *path, sqlite_uint64 parent, GtkStatusbar *statusbar) {
+void wallpapers_add_dir(const gchar *path, sqlite_uint64 parent, GtkStatusbar *statusbar, gboolean recursive ) {
static guint context_id = 0;
GDir *dir;
const gchar *filename;
@@ -73,7 +73,8 @@ void add_dir_recursive(const gchar *path, sqlite_uint64 parent, GtkStatusbar *st
g_free(filepath);
continue;
}
- add_dir_recursive(filepath, dirid, statusbar);
+ if(recursive)
+ wallpapers_add_dir(filepath, dirid, statusbar, recursive);
g_free(filepath);
gdk_threads_enter();
gtk_statusbar_pop(statusbar, context_id);
diff --git a/wallpapers.h b/wallpapers.h
index d97d6c8..356360d 100644
--- a/wallpapers.h
+++ b/wallpapers.h
@@ -6,7 +6,7 @@
#include "db.h"
-void add_dir_recursive(const gchar*, sqlite_uint64, GtkStatusbar*);
+void wallpapers_add_dir(const gchar*, sqlite_uint64, GtkStatusbar*, gboolean);
void wallpapers_remove_missing(struct directory_t*, GtkStatusbar*, gboolean);
GdkPixbuf *resize_pixbuf(GdkPixbuf*, gint, gint, gint*, gint*, gdouble*);
diff --git a/window_main.c b/window_main.c
index 955c380..539dd73 100644
--- a/window_main.c
+++ b/window_main.c
@@ -426,14 +426,31 @@ void on_main_tagview_cell_toggled(GtkCellRendererToggle *cell_renderer, gchar *p
}
/**
- * Thread function for recursive directory adding.
+ * Thread function for directory adding.
*/
gpointer add_dir_thread(gpointer data) {
gchar *directory;
directory = (gchar*)data;
- add_dir_recursive(directory, 0, statusbar);
+ wallpapers_add_dir(directory, 0, statusbar, FALSE);
+
+ g_free(directory);
+
+ wallpaper_thread = NULL;
+
+ return NULL;
+}
+
+/**
+ * Thread function for recursive directory adding.
+ */
+gpointer add_dir_rec_thread(gpointer data) {
+ gchar *directory;
+
+ directory = (gchar*)data;
+
+ wallpapers_add_dir(directory, 0, statusbar, TRUE);
g_free(directory);
@@ -442,6 +459,9 @@ gpointer add_dir_thread(gpointer data) {
return NULL;
}
+/**
+ * Thread function for removing missing files.
+ */
gpointer remove_missing_thread(gpointer data) {
struct directory_t *dir, temp;
@@ -491,7 +511,8 @@ void on_foldtree_update_activate(GtkMenuItem *menuitem, gpointer user_data) {
if(gtk_tree_selection_get_selected(treeselection, &model, &iter)) {
browse_model_get_dir_record(model, &iter, &dir);
- wallpaper_thread = g_thread_create(add_dir_thread, g_strdup(dir->name), FALSE, &error);
+ /* Using user_data as a gboolean for recursive calls. */
+ wallpaper_thread = g_thread_create(user_data == NULL ? add_dir_thread : add_dir_rec_thread, g_strdup(dir->name), FALSE, &error);
if(!wallpaper_thread) {
g_warning("%s", error->message);
@@ -524,23 +545,28 @@ void on_foldtree_remove_missing_activate(GtkMenuItem *menuitem, gpointer user_da
}
inline static void foldtree_popup_add_items(GtkWidget *menu) {
- GtkWidget *update, *remove_missing;
+ GtkWidget *update, *update_rec, *remove_missing;
GtkTreeSelection *selection;
update = gtk_menu_item_new_with_label("Update");
+ update_rec = gtk_menu_item_new_with_label("Update (recursive)");
remove_missing = gtk_menu_item_new_with_label("Remove missing files");
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(foldtree));
gtk_widget_set_sensitive(update, (gtk_tree_selection_count_selected_rows(selection) == 1 ? TRUE : FALSE));
+ gtk_widget_set_sensitive(update_rec, (gtk_tree_selection_count_selected_rows(selection) == 1 ? TRUE : FALSE));
gtk_widget_set_sensitive(remove_missing, (gtk_tree_selection_count_selected_rows(selection) == 1 ? TRUE : FALSE));
gtk_menu_shell_append(GTK_MENU_SHELL(menu), update);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), update_rec);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), remove_missing);
- g_signal_connect(G_OBJECT(update), "activate", G_CALLBACK(on_foldtree_update_activate), NULL);
+ g_signal_connect(G_OBJECT(update), "activate", G_CALLBACK(on_foldtree_update_activate), (gpointer)FALSE);
+ g_signal_connect(G_OBJECT(update_rec), "activate", G_CALLBACK(on_foldtree_update_activate), (gpointer)TRUE);
g_signal_connect(G_OBJECT(remove_missing), "activate", G_CALLBACK(on_foldtree_remove_missing_activate), NULL);
gtk_widget_show(update);
+ gtk_widget_show(update_rec);
gtk_widget_show(remove_missing);
}