summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2009-12-23 20:31:11 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2009-12-23 20:31:11 +0100
commitd17a46454b3ff886b0a9834d1ee63056e1d007ba (patch)
tree522d15cd35e6ced82f64c87af1423afe97a3c659
parentd7c8c0381462d6f565d0c9eedfd02f61696a2fad (diff)
Show file name and image resolution in the status bar.
-rw-r--r--db.c31
-rw-r--r--db.h1
-rw-r--r--window_main.c35
3 files changed, 64 insertions, 3 deletions
diff --git a/db.c b/db.c
index 931767d..1215430 100644
--- a/db.c
+++ b/db.c
@@ -298,6 +298,35 @@ sqlite_uint64 db_get_wallpaper(const char *path) {
return 0;
}
+int db_get_wallpaper_data(sqlite_uint64 id, struct wallpaper_t *wall) {
+ sqlite3_stmt *stmt;
+ int rc;
+ sqlite_uint64 dirid;
+
+ rc = sqlite3_prepare_v2(db, "SELECT id, filepath, size, width, height FROM wallpaper WHERE id = ? LIMIT 1", -1, &stmt, NULL);
+ if(rc != SQLITE_OK) {
+ return 0;
+ }
+
+ rc = sqlite3_bind_int64(stmt, 1, id);
+ if(rc != SQLITE_OK) {
+ sqlite3_finalize(stmt);
+ return 0;
+ }
+
+ rc = sqlite3_step(stmt);
+ if(rc == SQLITE_ROW) {
+ wall->filepath = g_strdup(sqlite3_column_text(stmt, 1));
+ wall->id = sqlite3_column_int64(stmt, 0);
+ wall->size = sqlite3_column_int(stmt, 2);
+ wall->width = sqlite3_column_int(stmt, 3);
+ wall->height = sqlite3_column_int(stmt, 4);
+ }
+
+ sqlite3_finalize(stmt);
+ return 1;
+}
+
int db_get_wallpapers(sqlite_uint64 dirid, GArray **array) {
struct wallpaper_t temp, *temp2;
sqlite3_stmt *stmt;
@@ -318,7 +347,7 @@ int db_get_wallpapers(sqlite_uint64 dirid, GArray **array) {
*array = g_array_new(TRUE, FALSE, sizeof(struct wallpaper_t));
while((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
temp.filepath = g_strdup(sqlite3_column_text(stmt, 1));
- temp.id = sqlite3_column_int64(stmt, 1);
+ temp.id = sqlite3_column_int64(stmt, 0);
temp.size = sqlite3_column_int(stmt, 2);
temp.width = sqlite3_column_int(stmt, 3);
temp.height = sqlite3_column_int(stmt, 4);
diff --git a/db.h b/db.h
index 18d6cf2..e655f7c 100644
--- a/db.h
+++ b/db.h
@@ -25,6 +25,7 @@ int db_get_top_level_directories(GArray**);
int db_get_directories(sqlite_uint64, GArray**);
sqlite_uint64 db_add_wallpaper(const char*, sqlite_uint64, int, int, int);
sqlite_uint64 db_get_wallpaper(const char*);
+int db_get_wallpaper_data(sqlite_uint64, struct wallpaper_t*);
int db_get_wallpapers(sqlite_uint64, GArray**);
#endif
diff --git a/window_main.c b/window_main.c
index d7a8bf2..0ab12ce 100644
--- a/window_main.c
+++ b/window_main.c
@@ -12,6 +12,7 @@
#include "wallpapers.h"
#include "thumbnails.h"
+struct wallpaper_t *cur_wall = NULL;
GdkPixbuf *orig_pixbuf = NULL;
gint last_width = 0,
last_height = 0,
@@ -25,6 +26,8 @@ GtkIconView *thumbview;
GThread *add_thread = NULL,
*thumb_thread = NULL;
+guint image_context;
+
void on_foldtree_selection_changed(GtkTreeSelection *treeselection, gpointer user_data);
inline static void foldtree_create_model(GtkTreeView *foldtree) {
@@ -117,6 +120,9 @@ static void load_pixbuf(const gchar *filepath) {
GdkPixbuf *pb;
GError *error = NULL;
GdkWindow *window;
+ sqlite_uint64 wallid;
+ struct wallpaper_t *wall;
+ gchar *msg, *base;
if(orig_pixbuf)
g_object_unref(orig_pixbuf);
@@ -127,6 +133,31 @@ static void load_pixbuf(const gchar *filepath) {
return;
}
+ if(cur_wall) {
+ g_free(cur_wall->filepath);
+ g_free(cur_wall);
+ cur_wall = NULL;
+ }
+
+ wallid = db_get_wallpaper(filepath);
+ if(wallid) {
+ wall = g_malloc(sizeof(struct wallpaper_t));
+ if(db_get_wallpaper_data(wallid, wall)) {
+ cur_wall = wall;
+ } else {
+ g_free(wall->filepath);
+ g_free(wall);
+ }
+ }
+
+ if(cur_wall) {
+ base = g_path_get_basename(cur_wall->filepath);
+ msg = g_strdup_printf("%s: %dx%d", base, cur_wall->width, cur_wall->height);
+ gtk_statusbar_push(statusbar, image_context, msg);
+ g_free(base);
+ g_free(msg);
+ }
+
resize_pixbuf();
}
@@ -225,8 +256,7 @@ void on_add_dir_action_activate(GtkAction *action, gpointer user_data) {
g_warning("%s", error->message);
g_free(error);
}
- } else
- printf("no directory selected\n");
+ }
gtk_widget_destroy(dialog);
}
@@ -273,6 +303,7 @@ int gui_main(int argc, char **argv) {
g_signal_connect(window_hpane, "notify::position", G_CALLBACK(on_window_hpane_resized), window_hpane);
statusbar = GTK_STATUSBAR(gtk_builder_get_object(builder, "statusbar"));
+ image_context = gtk_statusbar_get_context_id(GTK_STATUSBAR(statusbar), "Image display");
gtk_builder_connect_signals(builder, NULL);