summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-02-06 20:54:52 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2010-02-06 20:54:52 +0100
commit4f9af8cdde092155c89a5d3764917b3d3fcfce58 (patch)
treec9ff8b3084a28d9cf0dd45e17332c95e2360735b
parent0fe9e596a638e0cbc7d75dda7154205e52475cba (diff)
Implemented tooltips in the thumbnail view.
-rw-r--r--walls.ui2
-rw-r--r--window_main.c63
2 files changed, 62 insertions, 3 deletions
diff --git a/walls.ui b/walls.ui
index 5309439..4200097 100644
--- a/walls.ui
+++ b/walls.ui
@@ -156,10 +156,12 @@
<object class="GtkIconView" id="thumbview">
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="has_tooltip">True</property>
<property name="selection_mode">multiple</property>
<property name="orientation">horizontal</property>
<signal name="button_press_event" handler="on_thumbview_button_press_event"/>
<signal name="selection_changed" handler="on_thumbview_selection_changed"/>
+ <signal name="query_tooltip" handler="on_thumbview_query_tooltip"/>
<signal name="popup_menu" handler="on_thumbview_popup_menu"/>
</object>
</child>
diff --git a/window_main.c b/window_main.c
index 2ee2441..be4207f 100644
--- a/window_main.c
+++ b/window_main.c
@@ -262,8 +262,12 @@ static void fill_wall_list(GtkListStore *liststore, GArray *array) {
struct wallpaper_t *wall;
wall = &g_array_index(array, struct wallpaper_t, i);
+ gchar *filesize = g_format_size_for_display(wall->size);
+ gchar *tooltip = g_strdup_printf("File: %s\nResolution: %dx%d\nFilesize: %s", wall->filepath, wall->width, wall->height, filesize);
+ g_free(filesize);
+
gtk_list_store_append(liststore, &iter);
- gtk_list_store_set(liststore, &iter, 0, NULL, 1, wall->filepath, 2, wall->id,-1);
+ gtk_list_store_set(liststore, &iter, 0, NULL, 1, wall->filepath, 2, wall->id, 3, tooltip, -1);
g_free(wall->filepath);
}
g_array_free(array, TRUE);
@@ -304,7 +308,7 @@ static void display_from_foldtree(GtkTreeSelection *treeselection) {
if(!db_get_wallpapers(dir->dirid, &array))
return;
- liststore = gtk_list_store_new(3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_UINT64);
+ liststore = gtk_list_store_new(4, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_STRING);
fill_wall_list(liststore, array);
old_model = gtk_icon_view_get_model(thumbview);
@@ -354,6 +358,59 @@ void on_thumbview_selection_changed(GtkIconView *iconview, gpointer user_data) {
}
}
+gboolean on_thumbview_query_tooltip(GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, GtkTooltip *tooltip, gpointer user_data) {
+ GtkTreeModel *model;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+
+ if(gtk_icon_view_get_tooltip_context(GTK_ICON_VIEW(widget), &x, &y, keyboard_mode, &model, &path, &iter)) {
+ GValue value = {0};
+
+ gtk_tree_model_get_value(model, &iter, 2, &value);
+ guint64 wallid = g_value_get_uint64(&value);
+ g_value_unset(&value);
+
+ GArray *tags;
+ gchar *tagstr = NULL;
+ if(db_get_wall_tags(wallid, &tags)) {
+ GString *str = g_string_new(NULL);
+
+ for(int i = 0; i < tags->len; i++) {
+ struct tag_t *tag = &g_array_index(tags, struct tag_t, i);
+ if(i > 0)
+ g_string_append_printf(str, ", %s", tag->name);
+ else
+ g_string_append(str, tag->name);
+ g_free(tag->name);
+ }
+ g_array_free(tags, TRUE);
+ if(str->len > 0) {
+ tagstr = g_string_free(str, FALSE);
+ } else {
+ g_string_free(str, TRUE);
+ }
+ }
+
+ gtk_tree_model_get_value(model, &iter, 3, &value);
+ const gchar *pretext = g_value_get_string(&value);
+ gchar *text;
+ if(tagstr) {
+ text = g_strdup_printf("%s\nTags: %s", pretext, tagstr);
+ g_free(tagstr);
+ } else {
+ text = g_strdup_printf("%s", pretext);
+ }
+ g_value_unset(&value);
+
+ gtk_tooltip_set_text(tooltip, text);
+ g_free(text);
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
/**
* Load wallpapers from the currently selected tags.
*/
@@ -394,7 +451,7 @@ void display_from_tagview() {
return;
}
- liststore = gtk_list_store_new(3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_UINT64);
+ liststore = gtk_list_store_new(4, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_STRING);
fill_wall_list(liststore, wallarray);
old_model = gtk_icon_view_get_model(thumbview);