GTK marks several functions as deprecated
[geeqie.git] / src / collect-table.c
index cc4c11f..745eeca 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Geeqie
  * (C) 2004 John Ellis
- * Copyright (C) 2008 The Geeqie Team
+ * Copyright (C) 2008 - 2010 The Geeqie Team
  *
  * Author: John Ellis
  *
 #include "cellrenderericon.h"
 #include "collect-dlg.h"
 #include "collect-io.h"
-#include "debug.h"
 #include "dnd.h"
 #include "dupe.h"
 #include "editors.h"
 #include "filedata.h"
 #include "img-view.h"
-#include "info.h"
 #include "layout.h"
 #include "layout_image.h"
 #include "menu.h"
 #include "print.h"
 #include "utilops.h"
-#include "ui_bookmark.h"
 #include "ui_fileops.h"
 #include "ui_menu.h"
 #include "ui_tree_edit.h"
+#include "uri_utils.h"
 
 #include "icons/marker.xpm"
 #define MARKER_WIDTH 26
@@ -67,7 +65,7 @@ typedef enum {
 #define INFO_SELECTED(x) (x->flag_mask & SELECTION_SELECTED)
 
 
-static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint h, gint force);
+static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint h, gboolean force);
 
 
 /*
@@ -76,7 +74,7 @@ static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint
  *-------------------------------------------------------------------
  */
 
-static gint collection_table_find_position(CollectTable *ct, CollectInfo *info, gint *row, gint *col)
+static gboolean collection_table_find_position(CollectTable *ct, CollectInfo *info, gint *row, gint *col)
 {
        gint n;
 
@@ -90,7 +88,7 @@ static gint collection_table_find_position(CollectTable *ct, CollectInfo *info,
        return TRUE;
 }
 
-static gint collection_table_find_iter(CollectTable *ct, CollectInfo *info, GtkTreeIter *iter, gint *column)
+static gboolean collection_table_find_iter(CollectTable *ct, CollectInfo *info, GtkTreeIter *iter, gint *column)
 {
        GtkTreeModel *store;
        gint row, col;
@@ -130,69 +128,118 @@ static CollectInfo *collection_table_find_data_by_coord(CollectTable *ct, gint x
 {
        GtkTreePath *tpath;
        GtkTreeViewColumn *column;
+       GtkTreeModel *store;
+       GtkTreeIter row;
+       GList *list;
+       gint n;
 
-       if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(ct->listview), x, y,
-                                         &tpath, &column, NULL, NULL))
-               {
-               GtkTreeModel *store;
-               GtkTreeIter row;
-               GList *list;
-               gint n;
+       if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(ct->listview), x, y,
+                                          &tpath, &column, NULL, NULL))
+               return NULL;
 
-               store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
-               gtk_tree_model_get_iter(store, &row, tpath);
-               gtk_tree_path_free(tpath);
+       store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
+       gtk_tree_model_get_iter(store, &row, tpath);
+       gtk_tree_path_free(tpath);
 
-               gtk_tree_model_get(store, &row, CTABLE_COLUMN_POINTER, &list, -1);
+       gtk_tree_model_get(store, &row, CTABLE_COLUMN_POINTER, &list, -1);
+       if (!list) return NULL;
 
-               n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_number"));
-               if (list)
+       n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_number"));
+       if (iter) *iter = row;
+       return g_list_nth_data(list, n);
+}
+
+static guint collection_table_list_count(CollectTable *ct, gint64 *bytes)
+{
+       if (bytes)
+               {
+               gint64 b = 0;
+               GList *work;
+
+               work = ct->cd->list;
+               while (work)
                        {
-                       if (iter) *iter = row;
-                       return g_list_nth_data(list, n);
+                       CollectInfo *ci = work->data;
+                       work = work->next;
+                       b += ci->fd->size;
                        }
+
+               *bytes = b;
                }
 
-       return NULL;
+       return g_list_length(ct->cd->list);
 }
 
-static void collection_table_update_status(CollectTable *ct)
+static guint collection_table_selection_count(CollectTable *ct, gint64 *bytes)
 {
-       if (ct->status_label)
+       if (bytes)
                {
-               gchar *buf;
+               gint64 b = 0;
+               GList *work;
 
-               if (!ct->cd->list)
-                       {
-                       buf = g_strdup(_("Empty"));
-                       }
-               else if (ct->selection)
-                       {
-                       buf = g_strdup_printf(_("%d images (%d)"), g_list_length(ct->cd->list), g_list_length(ct->selection));
-                       }
-               else
+               work = ct->selection;
+               while (work)
                        {
-                       buf = g_strdup_printf(_("%d images"), g_list_length(ct->cd->list));
+                       CollectInfo *ci = work->data;
+                       work = work->next;
+                       b += ci->fd->size;
                        }
 
-               gtk_label_set_text(GTK_LABEL(ct->status_label), buf);
-               g_free(buf);
+               *bytes = b;
                }
+
+       return g_list_length(ct->selection);
 }
 
-static void collection_table_update_extras(CollectTable *ct, gint loading, gdouble value)
+static void collection_table_update_status(CollectTable *ct)
 {
-       if (ct->extra_label)
-               {
-               gchar *text;
-               if (loading)
-                       text = _("Loading thumbs...");
-               else
-                       text = " ";
+       gchar *buf;
+       guint n;
+       gint64 n_bytes = 0;
+       guint s;
+       gint64 s_bytes = 0;
+
+       if (!ct->status_label) return;
+
+       n = collection_table_list_count(ct, &n_bytes);
+       s = collection_table_selection_count(ct, &s_bytes);
 
-               gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ct->extra_label), value);
-               gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ct->extra_label), text);
+       if (s > 0)
+               {
+               gchar *b = text_from_size_abrev(n_bytes);
+               gchar *sb = text_from_size_abrev(s_bytes);
+               buf = g_strdup_printf(_("%s, %d images (%s, %d)"), b, n, sb, s);
+               g_free(b);
+               g_free(sb);
+               }
+       else if (n > 0)
+               {
+               gchar *b = text_from_size_abrev(n_bytes);
+               buf = g_strdup_printf(_("%s, %d images"), b, n);
+               g_free(b);
+               }
+       else
+               {
+               buf = g_strdup(_("Empty"));
                }
+
+       gtk_label_set_text(GTK_LABEL(ct->status_label), buf);
+       g_free(buf);
+}
+
+static void collection_table_update_extras(CollectTable *ct, gboolean loading, gdouble value)
+{
+       gchar *text;
+
+       if (!ct->extra_label) return;
+
+       if (loading)
+               text = _("Loading thumbs...");
+       else
+               text = " ";
+
+       gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ct->extra_label), value);
+       gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ct->extra_label), text);
 }
 
 static void collection_table_toggle_filenames(CollectTable *ct)
@@ -320,6 +367,37 @@ void collection_table_unselect_all(CollectTable *ct)
        collection_table_update_status(ct);
 }
 
+/* Invert the current collection's selection */
+static void collection_table_select_invert_all(CollectTable *ct)
+{
+       GList *work;
+       GList *new_selection = NULL;
+
+       work = ct->cd->list;
+       while (work)
+               {
+               CollectInfo *info = work->data;
+
+               if (INFO_SELECTED(info))
+                       {
+                       collection_table_selection_remove(ct, info, SELECTION_SELECTED, NULL);
+                       }
+               else
+                       {
+                       new_selection = g_list_append(new_selection, info);
+                       collection_table_selection_add(ct, info, SELECTION_SELECTED, NULL);
+
+                       }
+
+               work = work->next;
+               }
+
+       g_list_free(ct->selection);
+       ct->selection = new_selection;
+
+       collection_table_update_status(ct);
+}
+
 static void collection_table_select(CollectTable *ct, CollectInfo *info)
 {
        ct->prev_selection = info;
@@ -344,7 +422,7 @@ static void collection_table_unselect(CollectTable *ct, CollectInfo *info)
        collection_table_update_status(ct);
 }
 
-static void collection_table_select_util(CollectTable *ct, CollectInfo *info, gint select)
+static void collection_table_select_util(CollectTable *ct, CollectInfo *info, gboolean select)
 {
        if (select)
                {
@@ -356,7 +434,7 @@ static void collection_table_select_util(CollectTable *ct, CollectInfo *info, gi
                }
 }
 
-static void collection_table_select_region_util(CollectTable *ct, CollectInfo *start, CollectInfo *end, gint select)
+static void collection_table_select_region_util(CollectTable *ct, CollectInfo *start, CollectInfo *end, gboolean select)
 {
        gint row1, col1;
        gint row2, col2;
@@ -459,7 +537,11 @@ static void tip_show(CollectTable *ct)
 
        gdk_window_get_pointer(NULL, &x, &y, NULL);
 
+#if GTK_CHECK_VERSION(2,20,0)
+       if (!gtk_widget_get_realized(ct->tip_window)) gtk_widget_realize(ct->tip_window);
+#else
        if (!GTK_WIDGET_REALIZED(ct->tip_window)) gtk_widget_realize(ct->tip_window);
+#endif
        gtk_window_move(GTK_WINDOW(ct->tip_window), x + 16, y + 16);
        gtk_widget_show(ct->tip_window);
 }
@@ -470,15 +552,15 @@ static void tip_hide(CollectTable *ct)
        ct->tip_window = NULL;
 }
 
-static gint tip_schedule_cb(gpointer data)
+static gboolean tip_schedule_cb(gpointer data)
 {
        CollectTable *ct = data;
 
-       if (ct->tip_delay_id == -1) return FALSE;
+       if (!ct->tip_delay_id) return FALSE;
 
        tip_show(ct);
 
-       ct->tip_delay_id = -1;
+       ct->tip_delay_id = 0;
        return FALSE;
 }
 
@@ -486,10 +568,10 @@ static void tip_schedule(CollectTable *ct)
 {
        tip_hide(ct);
 
-       if (ct->tip_delay_id != -1)
+       if (ct->tip_delay_id)
                {
                g_source_remove(ct->tip_delay_id);
-               ct->tip_delay_id = -1;
+               ct->tip_delay_id = 0;
                }
 
        ct->tip_delay_id = g_timeout_add(ct->show_text ? COLLECT_TABLE_TIP_DELAY_PATH : COLLECT_TABLE_TIP_DELAY, tip_schedule_cb, ct);
@@ -499,8 +581,11 @@ static void tip_unschedule(CollectTable *ct)
 {
        tip_hide(ct);
 
-       if (ct->tip_delay_id != -1) g_source_remove(ct->tip_delay_id);
-       ct->tip_delay_id = -1;
+       if (ct->tip_delay_id)
+               {
+               g_source_remove(ct->tip_delay_id);
+               ct->tip_delay_id = 0;
+               }
 }
 
 static void tip_update(CollectTable *ct, CollectInfo *info)
@@ -556,7 +641,7 @@ static void collection_table_popup_save_cb(GtkWidget *widget, gpointer data)
 
        if (!collection_save(ct->cd, ct->cd->path))
                {
-               printf("failed saving to collection path: %s\n", ct->cd->path);
+               log_printf("failed saving to collection path: %s\n", ct->cd->path);
                }
 }
 
@@ -575,27 +660,13 @@ static GList *collection_table_popup_file_list(CollectTable *ct)
 static void collection_table_popup_edit_cb(GtkWidget *widget, gpointer data)
 {
        CollectTable *ct;
-       gint n;
-       GList *list;
+       const gchar *key = data;
 
        ct = submenu_item_get_data(widget);
 
        if (!ct) return;
-       n = GPOINTER_TO_INT(data);
 
-       list = collection_table_popup_file_list(ct);
-       if (list)
-               {
-               start_editor_from_filelist(n, list);
-               filelist_free(list);
-               }
-}
-
-static void collection_table_popup_info_cb(GtkWidget *widget, gpointer data)
-{
-       CollectTable *ct = data;
-
-       info_window_new(NULL, collection_table_popup_file_list(ct), NULL);
+       file_util_start_editor_from_filelist(key, collection_table_popup_file_list(ct), NULL, ct->listview);
 }
 
 static void collection_table_popup_copy_cb(GtkWidget *widget, gpointer data)
@@ -647,6 +718,17 @@ static void collection_table_popup_sort_cb(GtkWidget *widget, gpointer data)
        collection_set_sort_method(ct->cd, type);
 }
 
+static void collection_table_popup_randomize_cb(GtkWidget *widget, gpointer data)
+{
+       CollectTable *ct;
+
+       ct = submenu_item_get_data(widget);
+
+       if (!ct) return;
+
+       collection_randomize(ct->cd);
+}
+
 static void collection_table_popup_view_new_cb(GtkWidget *widget, gpointer data)
 {
        CollectTable *ct = data;
@@ -683,6 +765,14 @@ static void collection_table_popup_unselectall_cb(GtkWidget *widget, gpointer da
        ct->prev_selection= ct->click_info;
 }
 
+static void collection_table_popup_select_invert_cb(GtkWidget *widget, gpointer data)
+{
+       CollectTable *ct = data;
+
+       collection_table_select_invert_all(ct);
+       ct->prev_selection= ct->click_info;
+}
+
 static void collection_table_popup_remove_cb(GtkWidget *widget, gpointer data)
 {
        CollectTable *ct = data;
@@ -761,12 +851,16 @@ static void collection_table_popup_destroy_cb(GtkWidget *widget, gpointer data)
        filelist_free(ct->drop_list);
        ct->drop_list = NULL;
        ct->drop_info = NULL;
+
+       filelist_free(ct->editmenu_fd_list);
+       ct->editmenu_fd_list = NULL;
 }
 
-static GtkWidget *collection_table_popup_menu(CollectTable *ct, gint over_icon)
+static GtkWidget *collection_table_popup_menu(CollectTable *ct, gboolean over_icon)
 {
        GtkWidget *menu;
        GtkWidget *item;
+       GtkWidget *submenu;
 
        menu = popup_menu_short_lived();
 
@@ -786,18 +880,24 @@ static GtkWidget *collection_table_popup_menu(CollectTable *ct, gint over_icon)
        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);
-       menu_item_add(menu, _("Select all"),
+
+       item = menu_item_add(menu, _("_Selection"), NULL, NULL);
+       submenu = gtk_menu_new();
+       menu_item_add(submenu, _("Select all"),
                        G_CALLBACK(collection_table_popup_selectall_cb), ct);
-       menu_item_add(menu, _("Select none"),
+       menu_item_add(submenu, _("Select none"),
                        G_CALLBACK(collection_table_popup_unselectall_cb), ct);
+       menu_item_add(submenu, _("Invert selection"),
+                       G_CALLBACK(collection_table_popup_select_invert_cb), ct);
+       gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
        menu_item_add_divider(menu);
 
+       
+       ct->editmenu_fd_list = collection_table_selection_get_list(ct);
        submenu_add_edit(menu, &item,
-                       G_CALLBACK(collection_table_popup_edit_cb), ct);
+                       G_CALLBACK(collection_table_popup_edit_cb), ct, ct->editmenu_fd_list);
        gtk_widget_set_sensitive(item, over_icon);
 
-       menu_item_add_sensitive(menu, _("_Properties"), over_icon,
-                       G_CALLBACK(collection_table_popup_info_cb), ct);
        menu_item_add_divider(menu);
        menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, over_icon,
                        G_CALLBACK(collection_table_popup_copy_cb), ct);
@@ -807,12 +907,17 @@ static GtkWidget *collection_table_popup_menu(CollectTable *ct, gint 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);
-       if (options->show_copy_path)
-               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"), over_icon,
+                               G_CALLBACK(collection_table_popup_copy_path_cb), ct);
        menu_item_add_divider(menu);
 
-       submenu_add_sort(menu, G_CALLBACK(collection_table_popup_sort_cb), ct, FALSE, TRUE, FALSE, 0);
+       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"),
+                       G_CALLBACK(collection_table_popup_randomize_cb), ct);
+       item = menu_item_add(menu, _("_Sort"), NULL, NULL);
+       gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
+
        menu_item_add_check(menu, _("Show filename _text"), ct->show_text,
                        G_CALLBACK(collection_table_popup_show_names_cb), ct);
        menu_item_add_divider(menu);
@@ -881,7 +986,7 @@ static void collection_table_set_focus(CollectTable *ct, CollectInfo *info)
                }
 }
 
-static void collection_table_move_focus(CollectTable *ct, gint row, gint col, gint relative)
+static void collection_table_move_focus(CollectTable *ct, gint row, gint col, gboolean relative)
 {
        gint new_row;
        gint new_col;
@@ -1027,15 +1132,14 @@ static void collection_table_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboole
        popup_menu_position_clamp(menu, x, y, 0);
 }
 
-static gint collection_table_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
+static gboolean collection_table_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
 {
        CollectTable *ct = data;
        gint focus_row = 0;
        gint focus_col = 0;
        CollectInfo *info;
-       gint stop_signal;
+       gboolean stop_signal = TRUE;
 
-       stop_signal = TRUE;
        switch (event->keyval)
                {
                case GDK_Left: case GDK_KP_Left:
@@ -1152,8 +1256,8 @@ static gint collection_table_press_key_cb(GtkWidget *widget, GdkEventKey *event,
  *-------------------------------------------------------------------
  */
 
-static CollectInfo *collection_table_insert_find(CollectTable *ct, CollectInfo *source, gint *after, GdkRectangle *cell,
-                                                gint use_coord, gint x, gint y)
+static CollectInfo *collection_table_insert_find(CollectTable *ct, CollectInfo *source, gboolean *after, GdkRectangle *cell,
+                                                gboolean use_coord, gint x, gint y)
 {
        CollectInfo *info = NULL;
        GtkTreeModel *store;
@@ -1176,7 +1280,7 @@ static CollectInfo *collection_table_insert_find(CollectTable *ct, CollectInfo *
                        gtk_tree_path_free(tpath);
 
                        info = source;
-                       *after = (x > cell->x + (cell->width / 2));
+                       *after = !!(x > cell->x + (cell->width / 2));
                        }
                return info;
                }
@@ -1196,7 +1300,7 @@ static CollectInfo *collection_table_insert_find(CollectTable *ct, CollectInfo *
                if (info)
                        {
                        gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
-                       *after = (x > cell->x + (cell->width / 2));
+                       *after = !!(x > cell->x + (cell->width / 2));
                        }
 
                gtk_tree_path_free(tpath);
@@ -1231,7 +1335,7 @@ static CollectInfo *collection_table_insert_point(CollectTable *ct, gint x, gint
 {
        CollectInfo *info;
        GdkRectangle cell;
-       gint after = FALSE;
+       gboolean after = FALSE;
 
        info = collection_table_insert_find(ct, NULL, &after, &cell, TRUE, x, y);
 
@@ -1253,10 +1357,10 @@ static CollectInfo *collection_table_insert_point(CollectTable *ct, gint x, gint
        return info;
 }
 
-static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info, gint enable)
+static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info, gboolean enable)
 {
        gint row, col;
-       gint after = FALSE;
+       gboolean after = FALSE;
        GdkRectangle cell;
 
        if (!enable)
@@ -1287,9 +1391,9 @@ static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info,
 
                parent = gtk_tree_view_get_bin_window(GTK_TREE_VIEW(ct->listview));
 
-               pb = gdk_pixbuf_new_from_xpm_data((const char **)marker_xpm);
+               pb = gdk_pixbuf_new_from_xpm_data((const gchar **)marker_xpm);
                gdk_pixbuf_render_pixmap_and_mask(pb, &pixmap, &mask, 128);
-               gdk_pixbuf_unref(pb);
+               g_object_unref(pb);
 
                gdk_drawable_get_size(pixmap, &w, &h);
 
@@ -1342,7 +1446,7 @@ static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info,
  *-------------------------------------------------------------------
  */
 
-static void collection_table_motion_update(CollectTable *ct, gint x, gint y, gint drop_event)
+static void collection_table_motion_update(CollectTable *ct, gint x, gint y, gboolean drop_event)
 {
        CollectInfo *info;
 
@@ -1359,14 +1463,14 @@ static void collection_table_motion_update(CollectTable *ct, gint x, gint y, gin
                }
 }
 
-static gint collection_table_auto_scroll_idle_cb(gpointer data)
+static gboolean collection_table_auto_scroll_idle_cb(gpointer data)
 {
        CollectTable *ct = data;
        GdkWindow *window;
        gint x, y;
        gint w, h;
 
-       if (ct->drop_idle_id == -1) return FALSE;
+       if (!ct->drop_idle_id) return FALSE;
 
        window = ct->listview->window;
        gdk_window_get_pointer(window, &x, &y, NULL);
@@ -1376,27 +1480,30 @@ static gint collection_table_auto_scroll_idle_cb(gpointer data)
                collection_table_motion_update(ct, x, y, TRUE);
                }
 
-       ct->drop_idle_id = -1;
+       ct->drop_idle_id = 0;
        return FALSE;
 }
 
-static gint collection_table_auto_scroll_notify_cb(GtkWidget *widget, gint x, gint y, gpointer data)
+static gboolean collection_table_auto_scroll_notify_cb(GtkWidget *widget, gint x, gint y, gpointer data)
 {
        CollectTable *ct = data;
 
-       if (ct->drop_idle_id == -1) ct->drop_idle_id = g_idle_add(collection_table_auto_scroll_idle_cb, ct);
+       if (!ct->drop_idle_id)
+               {
+               ct->drop_idle_id = g_idle_add(collection_table_auto_scroll_idle_cb, ct);
+               }
 
        return TRUE;
 }
 
-static void collection_table_scroll(CollectTable *ct, gint scroll)
+static void collection_table_scroll(CollectTable *ct, gboolean scroll)
 {
        if (!scroll)
                {
-               if (ct->drop_idle_id != -1)
+               if (ct->drop_idle_id)
                        {
                        g_source_remove(ct->drop_idle_id);
-                       ct->drop_idle_id = -1;
+                       ct->drop_idle_id = 0;
                        }
                widget_auto_scroll_stop(ct->listview);
                collection_table_insert_marker(ct, NULL, FALSE);
@@ -1415,7 +1522,7 @@ static void collection_table_scroll(CollectTable *ct, gint scroll)
  *-------------------------------------------------------------------
  */
 
-static gint collection_table_motion_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
+static gboolean collection_table_motion_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
 {
        CollectTable *ct = data;
 
@@ -1424,7 +1531,7 @@ static gint collection_table_motion_cb(GtkWidget *widget, GdkEventButton *bevent
        return FALSE;
 }
 
-static gint collection_table_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
+static gboolean collection_table_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
 {
        CollectTable *ct = data;
        GtkTreeIter iter;
@@ -1447,7 +1554,11 @@ static gint collection_table_press_cb(GtkWidget *widget, GdkEventButton *bevent,
                                        layout_image_set_collection(NULL, ct->cd, info);
                                        }
                                }
+#if GTK_CHECK_VERSION(2,20,0)
+                       else if (!gtk_widget_has_focus(ct->listview))
+#else
                        else if (!GTK_WIDGET_HAS_FOCUS(ct->listview))
+#endif
                                {
                                gtk_widget_grab_focus(ct->listview);
                                }
@@ -1463,7 +1574,7 @@ static gint collection_table_press_cb(GtkWidget *widget, GdkEventButton *bevent,
        return TRUE;
 }
 
-static gint collection_table_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
+static gboolean collection_table_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
 {
        CollectTable *ct = data;
        GtkTreeIter iter;
@@ -1471,7 +1582,7 @@ static gint collection_table_release_cb(GtkWidget *widget, GdkEventButton *beven
 
        tip_schedule(ct);
 
-       if ((gint)bevent->x != 0 || (gint) bevent->y != 0)
+       if ((gint)bevent->x != 0 || (gint)bevent->y != 0)
                {
                info = collection_table_find_data_by_coord(ct, (gint)bevent->x, (gint)bevent->y, &iter);
                }
@@ -1488,9 +1599,8 @@ static gint collection_table_release_cb(GtkWidget *widget, GdkEventButton *beven
 
                if (bevent->state & GDK_CONTROL_MASK)
                        {
-                       gint select;
+                       gboolean select = !INFO_SELECTED(info);
 
-                       select = !INFO_SELECTED(info);
                        if ((bevent->state & GDK_SHIFT_MASK) && ct->prev_selection)
                                {
                                collection_table_select_region_util(ct, ct->prev_selection, info, select);
@@ -1524,7 +1634,7 @@ static gint collection_table_release_cb(GtkWidget *widget, GdkEventButton *beven
        return TRUE;
 }
 
-static gint collection_table_leave_cb(GtkWidget *widget, GdkEventCrossing *event, gpointer data)
+static gboolean collection_table_leave_cb(GtkWidget *widget, GdkEventCrossing *event, gpointer data)
 {
        CollectTable *ct = data;
 
@@ -1573,7 +1683,7 @@ static GList *collection_table_add_row(CollectTable *ct, GtkTreeIter *iter)
        return list;
 }
 
-static void collection_table_populate(CollectTable *ct, gint resize)
+static void collection_table_populate(CollectTable *ct, gboolean resize)
 {
        gint row;
        GList *work;
@@ -1599,7 +1709,11 @@ static void collection_table_populate(CollectTable *ct, gint resize)
                        gtk_tree_view_column_set_visible(column, (i < ct->columns));
                        gtk_tree_view_column_set_fixed_width(column, thumb_width + (THUMB_BORDER_PADDING * 6));
 
+#if GTK_CHECK_VERSION(2,18,0)
+                       list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(column));
+#else
                        list = gtk_tree_view_column_get_cell_renderers(column);
+#endif
                        cell = (list) ? list->data : NULL;
                        g_list_free(list);
 
@@ -1610,7 +1724,11 @@ static void collection_table_populate(CollectTable *ct, gint resize)
                                                             "show_text", ct->show_text, NULL);
                                }
                        }
+#if GTK_CHECK_VERSION(2,20,0)
+               if (gtk_widget_get_realized(ct->listview)) gtk_tree_view_columns_autosize(GTK_TREE_VIEW(ct->listview));
+#else
                if (GTK_WIDGET_REALIZED(ct->listview)) gtk_tree_view_columns_autosize(GTK_TREE_VIEW(ct->listview));
+#endif
                }
 
        row = -1;
@@ -1637,7 +1755,7 @@ static void collection_table_populate(CollectTable *ct, gint resize)
        collection_table_update_status(ct);
 }
 
-static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint h, gint force)
+static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint h, gboolean force)
 {
        gint new_cols;
        gint thumb_width;
@@ -1721,12 +1839,13 @@ static void collection_table_sync(CollectTable *ct)
        collection_table_update_status(ct);
 }
 
-static gint collection_table_sync_idle_cb(gpointer data)
+static gboolean collection_table_sync_idle_cb(gpointer data)
 {
        CollectTable *ct = data;
 
-       if (ct->sync_idle_id == -1) return FALSE;
-       ct->sync_idle_id = -1;
+       if (!ct->sync_idle_id) return FALSE;
+       g_source_remove(ct->sync_idle_id);
+       ct->sync_idle_id = 0;
 
        collection_table_sync(ct);
        return FALSE;
@@ -1734,7 +1853,7 @@ static gint collection_table_sync_idle_cb(gpointer data)
 
 static void collection_table_sync_idle(CollectTable *ct)
 {
-       if (ct->sync_idle_id == -1)
+       if (!ct->sync_idle_id)
                {
                /* high priority, the view needs to be resynced before a redraw
                 * may contain invalid pointers at this time
@@ -1905,42 +2024,42 @@ void collection_table_refresh(CollectTable *ct)
  *-------------------------------------------------------------------
  */
 
-static void collection_table_add_dir_recursive(CollectTable *ct, gchar *path, gint recursive)
+static void collection_table_add_dir_recursive(CollectTable *ct, FileData *dir_fd, gboolean recursive)
 {
-       GList *d = NULL;
-       GList *f = NULL;
+       GList *d;
+       GList *f;
+       GList *work;
 
-       if (filelist_read(path, &f, recursive ? &d : NULL))
-               {
-               GList *work;
+       if (!filelist_read(dir_fd, &f, recursive ? &d : NULL))
+               return;
 
-               f = filelist_filter(f, FALSE);
-               d = filelist_filter(d, TRUE);
+       f = filelist_filter(f, FALSE);
+       d = filelist_filter(d, TRUE);
 
-               f = filelist_sort_path(f);
-               d = filelist_sort_path(d);
+       f = filelist_sort_path(f);
+       d = filelist_sort_path(d);
 
-               collection_table_insert_filelist(ct, f, ct->marker_info);
+       collection_table_insert_filelist(ct, f, ct->marker_info);
 
-               work = g_list_last(d);
-               while (work)
-                       {
-                       collection_table_add_dir_recursive(ct, ((FileData *)work->data)->path, TRUE);
-                       work = work->prev;
-                       }
-               filelist_free(f);
-               filelist_free(d);
+       work = g_list_last(d);
+       while (work)
+               {
+               collection_table_add_dir_recursive(ct, (FileData *)work->data, TRUE);
+               work = work->prev;
                }
+
+       filelist_free(f);
+       filelist_free(d);
 }
 
-static void confirm_dir_list_do(CollectTable *ct, GList *list, gint recursive)
+static void confirm_dir_list_do(CollectTable *ct, GList *list, gboolean recursive)
 {
        GList *work = list;
        while (work)
                {
                FileData *fd = work->data;
                work = work->next;
-               if (isdir(fd->path)) collection_table_add_dir_recursive(ct, fd->path, recursive);
+               if (isdir(fd->path)) collection_table_add_dir_recursive(ct, fd, recursive);
                }
        collection_table_insert_filelist(ct, list, ct->marker_info);
 }
@@ -2014,7 +2133,7 @@ static void collection_table_dnd_get(GtkWidget *widget, GdkDragContext *context,
                                     guint time, gpointer data)
 {
        CollectTable *ct = data;
-       gint selected;
+       gboolean selected;
        GList *list = NULL;
        gchar *uri_text = NULL;
        gint total;
@@ -2331,7 +2450,7 @@ static void collection_table_destroy(GtkWidget *widget, gpointer data)
                gtk_widget_destroy(ct->popup);
                }
 
-       if (ct->sync_idle_id != -1) g_source_remove(ct->sync_idle_id);
+       if (ct->sync_idle_id) g_source_remove(ct->sync_idle_id);
 
        tip_unschedule(ct);
        collection_table_scroll(ct, FALSE);
@@ -2354,35 +2473,10 @@ CollectTable *collection_table_new(CollectionData *cd)
        gint i;
 
        ct = g_new0(CollectTable, 1);
+       
        ct->cd = cd;
-       ct->columns = 0;
-       ct->rows = 0;
-
-       ct->selection = NULL;
-       ct->prev_selection = NULL;
-
-       ct->tip_window = NULL;
-       ct->tip_delay_id = -1;
-
-       ct->marker_window = NULL;
-       ct->marker_info = NULL;
-
-       ct->status_label = NULL;
-       ct->extra_label = NULL;
-
-       ct->focus_row = 0;
-       ct->focus_column = 0;
-       ct->focus_info = NULL;
-
        ct->show_text = options->show_icon_names;
 
-       ct->sync_idle_id = -1;
-       ct->drop_idle_id = -1;
-
-       ct->popup = NULL;
-       ct->drop_info = NULL;
-       ct->drop_list = NULL;
-
        ct->scrolled = gtk_scrolled_window_new(NULL, NULL);
        gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(ct->scrolled), GTK_SHADOW_IN);
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(ct->scrolled),
@@ -2446,3 +2540,5 @@ CollectInfo *collection_table_get_focus_info(CollectTable *ct)
 {
        return collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
 }
+
+/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */