changeset 2788:1d65d7ce3132

Adl fix #323: Rating system https://github.com/BestImageViewer/geeqie/issues/323 Display star rating in collection window
author Colin Clark <colin.clark@cclark.uk>
date Fri, 29 Jun 2018 12:19:26 +0100
parents 3ff45da4e250
children 194f2e0719ba 4b0c49aa8c7b a9225aa1d93c
files src/collect-table.c src/typedefs.h
diffstat 2 files changed, 62 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/collect-table.c	Fri Jun 29 11:27:49 2018 +0100
+++ b/src/collect-table.c	Fri Jun 29 12:19:26 2018 +0100
@@ -33,6 +33,7 @@
 #include "layout.h"
 #include "layout_image.h"
 #include "menu.h"
+#include "metadata.h"
 #include "print.h"
 #include "utilops.h"
 #include "ui_fileops.h"
@@ -253,6 +254,16 @@
 	collection_table_populate_at_new_size(ct, allocation.width, allocation.height, TRUE);
 }
 
+static void collection_table_toggle_stars(CollectTable *ct)
+{
+	GtkAllocation allocation;
+	ct->show_stars = !ct->show_stars;
+	options->show_star_rating = ct->show_stars;
+
+	gtk_widget_get_allocation(ct->listview, &allocation);
+	collection_table_populate_at_new_size(ct, allocation.width, allocation.height, TRUE);
+}
+
 static gint collection_table_get_icon_width(CollectTable *ct)
 {
 	gint width;
@@ -903,6 +914,13 @@
 	collection_table_toggle_filenames(ct);
 }
 
+static void collection_table_popup_show_stars_cb(GtkWidget *widget, gpointer data)
+{
+	CollectTable *ct = data;
+
+	collection_table_toggle_stars(ct);
+}
+
 static void collection_table_popup_destroy_cb(GtkWidget *widget, gpointer data)
 {
 	CollectTable *ct = data;
@@ -989,6 +1007,8 @@
 
 	menu_item_add_check(menu, _("Show filename _text"), ct->show_text,
 			G_CALLBACK(collection_table_popup_show_names_cb), ct);
+	menu_item_add_check(menu, _("Show star rating"), ct->show_stars,
+				G_CALLBACK(collection_table_popup_show_stars_cb), ct);
 	menu_item_add_divider(menu);
 	menu_item_add_stock(menu, _("_Save collection"), GTK_STOCK_SAVE,
 			G_CALLBACK(collection_table_popup_save_cb), ct);
@@ -1817,7 +1837,7 @@
 				{
 				g_object_set(G_OBJECT(cell), "fixed_width", thumb_width,
 							     "fixed_height", options->thumbnails.max_height,
-							     "show_text", ct->show_text, NULL);
+							     "show_text", ct->show_text || ct->show_stars, NULL);
 				}
 			}
 		if (gtk_widget_get_realized(ct->listview)) gtk_tree_view_columns_autosize(GTK_TREE_VIEW(ct->listview));
@@ -2447,6 +2467,8 @@
 	CollectInfo *info;
 	GdkColor color_fg;
 	GdkColor color_bg;
+	gchar *star_rating = NULL;
+	gchar *display_text = NULL;
 
 	ct = cd->ct;
 
@@ -2479,12 +2501,45 @@
 		shift_color(&color_bg, -1, 0);
 		}
 
+	if (ct->show_stars && info && info->fd)
+		{
+		star_rating = metadata_read_rating_stars(info->fd);
+		}
+	else
+		{
+		star_rating = g_strdup("");
+		}
+
+	if (info && info->fd)
+		{
+		if (ct->show_text && ct->show_stars)
+			{
+			display_text = g_strconcat(info->fd->name, "\n", star_rating, NULL);
+			}
+		else if (ct->show_text)
+			{
+			display_text = g_strdup(info->fd->name);
+			}
+		else if (ct->show_stars)
+			{
+			display_text = g_strdup(star_rating);
+			}
+		else
+			{
+			display_text = g_strdup("");
+			}
+		}
+	else
+		{
+		display_text = g_strdup("");
+		}
+
 	if (GQV_IS_CELL_RENDERER_ICON(cell))
 		{
 		if (info)
 			{
 			g_object_set(cell,	"pixbuf", info->pixbuf,
-						"text", info->fd->name,
+						"text",  display_text,
 						"cell-background-gdk", &color_bg,
 						"cell-background-set", TRUE,
 						"foreground-gdk", &color_fg,
@@ -2500,6 +2555,9 @@
 						"has-focus", FALSE,  NULL);
 			}
 		}
+
+	g_free(display_text);
+	g_free(star_rating);
 }
 
 static void collection_table_append_column(CollectTable *ct, gint n)
@@ -2583,6 +2641,7 @@
 
 	ct->cd = cd;
 	ct->show_text = options->show_icon_names;
+	ct->show_stars = options->show_star_rating;
 
 	ct->scrolled = gtk_scrolled_window_new(NULL, NULL);
 	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(ct->scrolled), GTK_SHADOW_IN);
--- a/src/typedefs.h	Fri Jun 29 11:27:49 2018 +0100
+++ b/src/typedefs.h	Fri Jun 29 12:19:26 2018 +0100
@@ -439,6 +439,7 @@
 	guint drop_idle_id; /* event source id */
 
 	gboolean show_text;
+	gboolean show_stars;
 
 	/* file list for edit menu */
 	GList *editmenu_fd_list;