summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SConstruct4
-rw-r--r--wallpapers.c60
-rw-r--r--wallpapers.h4
-rw-r--r--walls.ui2
-rw-r--r--window_main.c35
5 files changed, 83 insertions, 22 deletions
diff --git a/SConstruct b/SConstruct
index 4aae244..31244fb 100644
--- a/SConstruct
+++ b/SConstruct
@@ -1,7 +1,7 @@
env = Environment()
conf = Configure(env)
-for lib, h in (('Imlib2', 'Imlib2.h'), ('glib-2.0', None), ('sqlite3', 'sqlite3.h'), ('gtk-x11-2.0', None)):
+for lib, h in (('glib-2.0', None), ('sqlite3', 'sqlite3.h'), ('gtk-x11-2.0', None), ('gthread-2.0', None)):
if h:
libfound = conf.CheckLibWithHeader(lib, h, 'c')
else:
@@ -13,10 +13,10 @@ env = conf.Finish()
env.Append(CCFLAGS = ['-std=gnu99', '-g'])
env.Append(LINKFLAGS = ['-Wl,--export-dynamic'])
-env.ParseConfig('imlib2-config --cflags --libs')
env.ParseConfig('pkg-config --cflags --libs glib-2.0')
env.ParseConfig('pkg-config --cflags --libs sqlite3')
env.ParseConfig('pkg-config --cflags --libs gtk+-2.0')
+env.ParseConfig('pkg-config --cflags --libs gthread-2.0')
def build_ui(target, source, env):
f = open(str(target[0]), 'w')
diff --git a/wallpapers.c b/wallpapers.c
index 53ea102..5e09742 100644
--- a/wallpapers.c
+++ b/wallpapers.c
@@ -6,7 +6,6 @@
#include <string.h>
#include <errno.h>
-#include <Imlib2.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <glib/gprintf.h>
@@ -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();
}
diff --git a/wallpapers.h b/wallpapers.h
index 174b34f..ce4430c 100644
--- a/wallpapers.h
+++ b/wallpapers.h
@@ -1,8 +1,10 @@
#ifndef _WALLPAPERS_H_
#define _WALLPAPERS_H_
+#include <gtk/gtk.h>
+
#include "db.h"
-void add_dir_recursive(const char*, sqlite_uint64);
+void add_dir_recursive(const gchar*, sqlite_uint64, GtkStatusbar*);
#endif
diff --git a/walls.ui b/walls.ui
index f7350f8..bbc024b 100644
--- a/walls.ui
+++ b/walls.ui
@@ -141,7 +141,7 @@
</packing>
</child>
<child>
- <object class="GtkStatusbar" id="statusbar2">
+ <object class="GtkStatusbar" id="statusbar">
<property name="visible">True</property>
<property name="spacing">2</property>
</object>
diff --git a/window_main.c b/window_main.c
index 96a596b..9ebacde 100644
--- a/window_main.c
+++ b/window_main.c
@@ -15,6 +15,9 @@ gint last_width = 0,
GtkImage *image = NULL;
GtkWidget *layout = NULL;
+GtkStatusbar *statusbar;
+
+GThread *add_thread = NULL;
void on_filetree_selection_changed(GtkTreeSelection *treeselection, gpointer user_data);
@@ -160,15 +163,35 @@ void on_filetree_selection_changed(GtkTreeSelection *treeselection, gpointer use
}
}
+gpointer add_dir_thread(gpointer data) {
+ gchar *directory;
+
+ directory = (gchar*)data;
+
+ add_dir_recursive(directory, 0, statusbar);
+
+ g_free(directory);
+
+ return NULL;
+}
+
void on_add_dir_action_activate(GtkAction *action, gpointer user_data) {
GtkWidget *dialog;
+ GError *error;
- dialog = gtk_file_chooser_dialog_new("Choose Directory", NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, "_Select");
+ if(add_thread) return;
+
+ dialog = gtk_file_chooser_dialog_new("Choose Directory", NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
char *directory;
directory = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
- add_dir_recursive(directory, 0);
- }
+ add_thread = g_thread_create(add_dir_thread, strdup(directory), FALSE, &error);
+ if(!add_thread) {
+ g_warning("%s", error->message);
+ }
+ } else
+ printf("no directory selected\n");
gtk_widget_destroy(dialog);
}
@@ -179,6 +202,10 @@ int gui_main(int argc, char **argv) {
GtkBuilder *builder ;
GError *error = NULL;
+ g_thread_init(NULL);
+
+ gdk_threads_init();
+
if(!db_open())
return 1;
@@ -202,6 +229,8 @@ int gui_main(int argc, char **argv) {
window_hpane = GTK_WIDGET(gtk_builder_get_object(builder, "window_hpane"));
g_signal_connect(window_hpane, "notify::position", G_CALLBACK(on_window_hpane_resized), window_hpane);
+ statusbar = GTK_STATUSBAR(gtk_builder_get_object(builder, "statusbar"));
+
gtk_builder_connect_signals(builder, NULL);
g_object_unref(G_OBJECT(builder));