Include a Other Software section in Help file
[geeqie.git] / src / collect-table.c
index 757fa9f..6bf85df 100644 (file)
 #include "layout.h"
 #include "layout_image.h"
 #include "menu.h"
+#include "metadata.h"
+#include "pixbuf_util.h"
 #include "print.h"
 #include "utilops.h"
 #include "ui_fileops.h"
 #include "ui_menu.h"
 #include "ui_tree_edit.h"
 #include "uri_utils.h"
+#include "view_file.h"
 
 #include "icons/marker.xpm"
 #define MARKER_WIDTH 26
@@ -252,6 +255,16 @@ static void collection_table_toggle_filenames(CollectTable *ct)
        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;
@@ -400,7 +413,7 @@ static void collection_table_select_invert_all(CollectTable *ct)
        collection_table_update_status(ct);
 }
 
-static void collection_table_select(CollectTable *ct, CollectInfo *info)
+void collection_table_select(CollectTable *ct, CollectInfo *info)
 {
        ct->prev_selection = info;
 
@@ -721,6 +734,15 @@ static void collection_table_popup_delete_cb(GtkWidget *widget, gpointer data)
 {
        CollectTable *ct = data;
 
+       options->file_ops.safe_delete_enable = FALSE;
+       file_util_delete(NULL, collection_table_popup_file_list(ct), ct->listview);
+}
+
+static void collection_table_popup_move_to_trash_cb(GtkWidget *widget, gpointer data)
+{
+       CollectTable *ct = data;
+
+       options->file_ops.safe_delete_enable = TRUE;
        file_util_delete(NULL, collection_table_popup_file_list(ct), ct->listview);
 }
 
@@ -728,7 +750,14 @@ static void collection_table_popup_copy_path_cb(GtkWidget *widget, gpointer data
 {
        CollectTable *ct = data;
 
-       file_util_copy_path_list_to_clipboard(collection_table_popup_file_list(ct));
+       file_util_copy_path_list_to_clipboard(collection_table_popup_file_list(ct), TRUE);
+}
+
+static void collection_table_popup_copy_path_unquoted_cb(GtkWidget *widget, gpointer data)
+{
+       CollectTable *ct = data;
+
+       file_util_copy_path_list_to_clipboard(collection_table_popup_file_list(ct), FALSE);
 }
 
 static void collection_table_popup_sort_cb(GtkWidget *widget, gpointer data)
@@ -802,8 +831,6 @@ static void collection_table_popup_select_invert_cb(GtkWidget *widget, gpointer
 
 static void collection_table_popup_rectangular_selection_cb(GtkWidget *widget, gpointer data)
 {
-       CollectTable *ct = data;
-
        options->collections.rectangular_selection = !(options->collections.rectangular_selection);
 }
 
@@ -827,12 +854,15 @@ static void collection_table_popup_remove_cb(GtkWidget *widget, gpointer data)
        g_list_free(list);
 }
 
-static void collection_table_popup_add_filelist_cb(GtkWidget *widget, gpointer data)
+static void collection_table_popup_add_file_selection_cb(GtkWidget *widget, gpointer data)
 {
        CollectTable *ct = data;
        GList *list;
+       LayoutWindow *lw = NULL;
+
+       if (!layout_valid(&lw)) return;
 
-       list = layout_list(NULL);
+       list = vf_selection_get_list(lw->vf);
 
        if (list)
                {
@@ -848,6 +878,26 @@ static void collection_table_popup_add_collection_cb(GtkWidget *widget, gpointer
        collection_dialog_append(NULL, ct->cd);
 }
 
+static void collection_table_popup_goto_original_cb(GtkWidget *widget, gpointer data)
+{
+       CollectTable *ct = data;
+       GList *list;
+       LayoutWindow *lw = NULL;
+       FileData *fd;
+
+       if (!layout_valid(&lw)) return;
+       list = collection_table_selection_get_list(ct);
+       if (list)
+               {
+               fd = list->data;
+               if (fd)
+                       {
+                       layout_set_fd(lw, fd);
+                       }
+               }
+       g_list_free(list);
+}
+
 static void collection_table_popup_find_dupes_cb(GtkWidget *widget, gpointer data)
 {
        CollectTable *ct = data;
@@ -864,7 +914,7 @@ static void collection_table_popup_print_cb(GtkWidget *widget, gpointer data)
 
        fd = (ct->click_info) ? ct->click_info->fd : NULL;
 
-       print_window_new(fd, collection_table_selection_get_list(ct), collection_table_get_list(ct), ct->listview);
+       print_window_new(fd, collection_table_selection_get_list(ct), collection_table_get_list(ct), gtk_widget_get_toplevel(ct->listview));
 }
 
 static void collection_table_popup_show_names_cb(GtkWidget *widget, gpointer data)
@@ -874,6 +924,13 @@ static void collection_table_popup_show_names_cb(GtkWidget *widget, gpointer dat
        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;
@@ -905,12 +962,14 @@ static GtkWidget *collection_table_popup_menu(CollectTable *ct, gboolean over_ic
                        G_CALLBACK(collection_table_popup_view_cb), ct);
        menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, over_icon,
                        G_CALLBACK(collection_table_popup_view_new_cb), ct);
+       menu_item_add_stock(menu, _("Go to original"), GTK_STOCK_FIND,
+                       G_CALLBACK(collection_table_popup_goto_original_cb), ct);
        menu_item_add_divider(menu);
        menu_item_add_stock_sensitive(menu, _("Rem_ove"), GTK_STOCK_REMOVE, over_icon,
                        G_CALLBACK(collection_table_popup_remove_cb), ct);
 
-       menu_item_add_stock(menu, _("Append from file list"), GTK_STOCK_ADD,
-                       G_CALLBACK(collection_table_popup_add_filelist_cb), ct);
+       menu_item_add_stock(menu, _("Append from file selection"), GTK_STOCK_ADD,
+                       G_CALLBACK(collection_table_popup_add_file_selection_cb), ct);
        menu_item_add_stock(menu, _("Append from collection..."), GTK_STOCK_OPEN,
                        G_CALLBACK(collection_table_popup_add_collection_cb), ct);
        menu_item_add_divider(menu);
@@ -941,12 +1000,22 @@ static GtkWidget *collection_table_popup_menu(CollectTable *ct, gboolean over_ic
                        G_CALLBACK(collection_table_popup_move_cb), ct);
        menu_item_add_sensitive(menu, _("_Rename..."), over_icon,
                        G_CALLBACK(collection_table_popup_rename_cb), ct);
-       menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, over_icon,
-                       G_CALLBACK(collection_table_popup_delete_cb), ct);
        menu_item_add_sensitive(menu, _("_Copy path"), over_icon,
                                G_CALLBACK(collection_table_popup_copy_path_cb), ct);
+       menu_item_add_sensitive(menu, _("_Copy path unquoted"), over_icon,
+                               G_CALLBACK(collection_table_popup_copy_path_unquoted_cb), ct);
+
        menu_item_add_divider(menu);
+       menu_item_add_stock_sensitive(menu,
+                               options->file_ops.confirm_move_to_trash ? _("Move to Trash...") :
+                                       _("Move to Trash"), PIXBUF_INLINE_ICON_TRASH, over_icon,
+                               G_CALLBACK(collection_table_popup_move_to_trash_cb), ct);
+       menu_item_add_stock_sensitive(menu,
+                               options->file_ops.confirm_delete ? _("_Delete...") :
+                                       _("_Delete"), GTK_STOCK_DELETE, over_icon,
+                               G_CALLBACK(collection_table_popup_delete_cb), ct);
 
+       menu_item_add_divider(menu);
        submenu = submenu_add_sort(NULL, G_CALLBACK(collection_table_popup_sort_cb), ct, FALSE, TRUE, FALSE, 0);
        menu_item_add_divider(submenu);
        menu_item_add(submenu, _("Randomize"),
@@ -956,6 +1025,8 @@ static GtkWidget *collection_table_popup_menu(CollectTable *ct, gboolean over_ic
 
        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);
@@ -975,7 +1046,7 @@ static GtkWidget *collection_table_popup_menu(CollectTable *ct, gboolean over_ic
  *-------------------------------------------------------------------
  */
 
-static void collection_table_set_focus(CollectTable *ct, CollectInfo *info)
+void collection_table_set_focus(CollectTable *ct, CollectInfo *info)
 {
        GtkTreeIter iter;
        gint row, col;
@@ -1408,6 +1479,11 @@ static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info,
 {
        gboolean after = FALSE;
        GdkRectangle cell;
+       GdkWindow *parent;
+       gint x_parent, y_parent;
+
+       parent = gtk_widget_get_window(gtk_widget_get_toplevel(ct->listview));
+       gdk_window_get_position(parent, &x_parent, &y_parent);
 
        if (!enable)
                {
@@ -1424,7 +1500,6 @@ static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info,
 
        if (!ct->marker_window)
                {
-               GdkWindow *parent = gtk_tree_view_get_bin_window(GTK_TREE_VIEW(ct->listview));
                GdkWindowAttr attributes;
                gint attributes_mask;
                GdkPixbuf *pb = gdk_pixbuf_new_from_xpm_data((const gchar **)marker_xpm);
@@ -1438,7 +1513,7 @@ static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info,
                attributes.event_mask = gtk_widget_get_events(ct->listview);
                attributes_mask = 0;
 
-               ct->marker_window = gdk_window_new(parent, &attributes, attributes_mask);
+               ct->marker_window = gdk_window_new(NULL, &attributes, attributes_mask);
 
 #if GTK_CHECK_VERSION(3,0,0)
                cairo_region_t *mask;
@@ -1447,7 +1522,9 @@ static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info,
                cairo_t *cr = cairo_create(img);
                gdk_cairo_set_source_pixbuf(cr, pb, 0, 0);
                cairo_paint(cr);
-               pattern = cairo_pattern_create_for_surface(img);
+               /** @FIXME this is a hack to get the background color */
+               //~ pattern = cairo_pattern_create_for_surface(img);
+               pattern = cairo_pattern_create_rgb (1.0, 0.0, 0.0);
                mask = gdk_cairo_region_create_from_surface(img);
                gdk_window_shape_combine_region(ct->marker_window, mask, 0, 0);
                gdk_window_set_background_pattern(ct->marker_window, pattern);
@@ -1488,6 +1565,9 @@ static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info,
                x -= (w / 2);
                y = cell.y + (cell.height / 2) - (h / 2);
 
+               x = x + x_parent;
+               y = y + y_parent;
+
                gdk_window_move(ct->marker_window, x, y);
 #if !GTK_CHECK_VERSION(3,0,0)
                gdk_window_clear(ct->marker_window);
@@ -1784,7 +1864,7 @@ static void collection_table_populate(CollectTable *ct, gboolean resize)
                                {
                                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));
@@ -1966,7 +2046,7 @@ static void collection_table_move_by_info_list(CollectTable *ct, GList *info_lis
 
        if (info) insert_pos = g_list_find(ct->cd->list, info);
 
-       /* FIXME: this may get slow for large lists */
+       /** @FIXME this may get slow for large lists */
        work = info_list;
        while (insert_pos && work)
                {
@@ -2414,10 +2494,21 @@ static void collection_table_cell_data_cb(GtkTreeViewColumn *tree_column, GtkCel
        CollectInfo *info;
        GdkColor color_fg;
        GdkColor color_bg;
+       gchar *star_rating = NULL;
+       gchar *display_text = NULL;
 
        ct = cd->ct;
 
        gtk_tree_model_get(tree_model, iter, CTABLE_COLUMN_POINTER, &list, -1);
+
+#if GTK_CHECK_VERSION(3,0,0)
+       /** @FIXME this is a primitive hack to stop a crash.
+        * When compiled with GTK3, if a Collection window containing
+        * say, 50 or so, images has its width changed, there is a segfault
+        * https://github.com/BestImageViewer/geeqie/issues/531
+        */
+       if (cd->number == COLLECT_TABLE_MAX_COLUMNS) return;
+#endif
        info = g_list_nth_data(list, cd->number);
 
        style = gtk_widget_get_style(ct->listview);
@@ -2437,12 +2528,45 @@ static void collection_table_cell_data_cb(GtkTreeViewColumn *tree_column, GtkCel
                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,
@@ -2458,6 +2582,9 @@ static void collection_table_cell_data_cb(GtkTreeViewColumn *tree_column, GtkCel
                                                "has-focus", FALSE,  NULL);
                        }
                }
+
+       g_free(display_text);
+       g_free(star_rating);
 }
 
 static void collection_table_append_column(CollectTable *ct, gint n)
@@ -2498,6 +2625,16 @@ static void collection_table_destroy(GtkWidget *widget, gpointer data)
 {
        CollectTable *ct = data;
 
+       /* If there is no unsaved data, save the window geometry
+        */
+       if (!ct->cd->changed)
+               {
+               if (!collection_save(ct->cd, ct->cd->path))
+                       {
+                       log_printf("failed saving to collection path: %s\n", ct->cd->path);
+                       }
+               }
+
        if (ct->popup)
                {
                g_signal_handlers_disconnect_matched(G_OBJECT(ct->popup), G_SIGNAL_MATCH_DATA,
@@ -2531,6 +2668,7 @@ CollectTable *collection_table_new(CollectionData *cd)
 
        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);