Documentation: Use G_SOURCE_CONTINUE and G_SOURCE_REMOVE
[geeqie.git] / src / view-file / view-file-list.cc
index 04871a9..73ceb5a 100644 (file)
 #include "main.h"
 #include "view-file-list.h"
 
-#include "bar.h"
-#include "cache-maint.h"
 #include "collect.h"
 #include "dnd.h"
-#include "editors.h"
 #include "img-view.h"
 #include "layout.h"
 #include "layout-image.h"
-#include "menu.h"
 #include "metadata.h"
 #include "misc.h"
-#include "thumb.h"
 #include "utilops.h"
 #include "ui-fileops.h"
-#include "ui-menu.h"
 #include "ui-misc.h"
 #include "ui-tree-edit.h"
 #include "uri-utils.h"
 #include "view-file.h"
 
-
-#include <gdk/gdkkeysyms.h> /* for keyboard values */
-
 /* Index to tree store */
 enum {
        FILE_COLUMN_POINTER = 0,
@@ -101,7 +92,7 @@ typedef struct {
 
 static gboolean vflist_find_row_cb(GtkTreeModel *model, GtkTreePath *UNUSED(path), GtkTreeIter *iter, gpointer data)
 {
-       ViewFileFindRowData *find = data;
+       ViewFileFindRowData *find = (ViewFileFindRowData *)data;
        FileData *fd;
        gtk_tree_model_get(model, iter, FILE_COLUMN_POINTER, &fd, -1);
        if (fd == find->fd)
@@ -176,7 +167,7 @@ static void vflist_store_clear(ViewFile *vf, gboolean unlock_files)
                filelist_read(vf->dir_fd, &files, NULL);
                while (files)
                        {
-                       FileData *fd = files->data;
+                       FileData *fd = static_cast<FileData *>(files->data);
                        files = files->next;
                        file_data_unlock(fd);
                        file_data_unref(fd);  // undo the ref that got added in filelist_read
@@ -222,7 +213,7 @@ static void vflist_dnd_get(GtkWidget *UNUSED(widget), GdkDragContext *UNUSED(con
                           GtkSelectionData *selection_data, guint UNUSED(info),
                           guint UNUSED(time), gpointer data)
 {
-       ViewFile *vf = data;
+       ViewFile *vf = (ViewFile *)data;
        GList *list = NULL;
 
        if (!VFLIST(vf)->click_fd) return;
@@ -243,7 +234,7 @@ static void vflist_dnd_get(GtkWidget *UNUSED(widget), GdkDragContext *UNUSED(con
 
 static void vflist_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data)
 {
-       ViewFile *vf = data;
+       ViewFile *vf = (ViewFile *)data;
 
        vflist_color_set(vf, VFLIST(vf)->click_fd, TRUE);
 
@@ -263,7 +254,7 @@ static void vflist_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointe
 
 static void vflist_dnd_end(GtkWidget *UNUSED(widget), GdkDragContext *context, gpointer data)
 {
-       ViewFile *vf = data;
+       ViewFile *vf = (ViewFile *)data;
 
        vflist_color_set(vf, VFLIST(vf)->click_fd, FALSE);
 
@@ -277,7 +268,7 @@ static void vflist_drag_data_received(GtkWidget *UNUSED(entry_widget), GdkDragCo
                                      int x, int y, GtkSelectionData *selection,
                                      guint info, guint UNUSED(time), gpointer data)
 {
-       ViewFile *vf = data;
+       ViewFile *vf = (ViewFile *)data;
 
        if (info == TARGET_TEXT_PLAIN) {
                FileData *fd = vflist_find_data_by_coord(vf, x, y, NULL);
@@ -296,12 +287,12 @@ static void vflist_drag_data_received(GtkWidget *UNUSED(entry_widget), GdkDragCo
 
 void vflist_dnd_init(ViewFile *vf)
 {
-       gtk_drag_source_set(vf->listview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
+       gtk_drag_source_set(vf->listview, static_cast<GdkModifierType>(GDK_BUTTON1_MASK | GDK_BUTTON2_MASK),
                            dnd_file_drag_types, dnd_file_drag_types_count,
-                           GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
+                           static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK));
        gtk_drag_dest_set(vf->listview, GTK_DEST_DEFAULT_ALL,
                            dnd_file_drag_types, dnd_file_drag_types_count,
-                           GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
+                           static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK));
 
        g_signal_connect(G_OBJECT(vf->listview), "drag_data_get",
                         G_CALLBACK(vflist_dnd_get), vf);
@@ -341,7 +332,7 @@ GList *vflist_selection_get_one(ViewFile *vf, FileData *fd)
                                GList *work = fd->sidecar_files;
                                while (work)
                                        {
-                                       FileData *sfd = work->data;
+                                       FileData *sfd = (FileData *)work->data;
                                        list = g_list_prepend(list, file_data_ref(sfd));
                                        work = work->next;
                                        }
@@ -368,7 +359,7 @@ GList *vflist_pop_menu_file_list(ViewFile *vf)
 
 void vflist_pop_menu_view_cb(GtkWidget *UNUSED(widget), gpointer data)
 {
-       ViewFile *vf = data;
+       ViewFile *vf = (ViewFile *)data;
 
        if (vflist_row_is_selected(vf, VFLIST(vf)->click_fd))
                {
@@ -386,7 +377,7 @@ void vflist_pop_menu_view_cb(GtkWidget *UNUSED(widget), gpointer data)
 
 void vflist_pop_menu_rename_cb(GtkWidget *UNUSED(widget), gpointer data)
 {
-       ViewFile *vf = data;
+       ViewFile *vf = (ViewFile *)data;
        GList *list;
 
        list = vf_pop_menu_file_list(vf);
@@ -417,7 +408,7 @@ void vflist_pop_menu_rename_cb(GtkWidget *UNUSED(widget), gpointer data)
 
 void vflist_pop_menu_thumbs_cb(GtkWidget *UNUSED(widget), gpointer data)
 {
-       ViewFile *vf = data;
+       ViewFile *vf = (ViewFile *)data;
 
        vflist_color_set(vf, VFLIST(vf)->click_fd, FALSE);
        if (vf->layout)
@@ -439,7 +430,7 @@ void vflist_star_rating_set(ViewFile *vf, gboolean enable)
        work = columns;
        while (work)
                {
-               GtkTreeViewColumn *column = work->data;
+               GtkTreeViewColumn *column = (GtkTreeViewColumn *)work->data;
                gint col_idx = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_store_idx"));
                work = work->next;
 
@@ -467,7 +458,7 @@ void vflist_star_rating_set(ViewFile *vf, gboolean enable)
 
 void vflist_pop_menu_show_star_rating_cb(GtkWidget *UNUSED(widget), gpointer data)
 {
-       ViewFile *vf = data;
+       ViewFile *vf = (ViewFile *)data;
 
        options->show_star_rating = !options->show_star_rating;
 
@@ -479,7 +470,7 @@ void vflist_pop_menu_show_star_rating_cb(GtkWidget *UNUSED(widget), gpointer dat
 
 void vflist_pop_menu_refresh_cb(GtkWidget *UNUSED(widget), gpointer data)
 {
-       ViewFile *vf = data;
+       ViewFile *vf = (ViewFile *)data;
 
        vflist_color_set(vf, VFLIST(vf)->click_fd, FALSE);
        vf_refresh(vf);
@@ -488,7 +479,7 @@ void vflist_pop_menu_refresh_cb(GtkWidget *UNUSED(widget), gpointer data)
 
 void vflist_popup_destroy_cb(GtkWidget *UNUSED(widget), gpointer data)
 {
-       ViewFile *vf = data;
+       ViewFile *vf = (ViewFile *)data;
        vflist_color_set(vf, VFLIST(vf)->click_fd, FALSE);
        VFLIST(vf)->click_fd = NULL;
        vf->popup = NULL;
@@ -503,7 +494,7 @@ void vflist_popup_destroy_cb(GtkWidget *UNUSED(widget), gpointer data)
 
 static gboolean vflist_row_rename_cb(TreeEditData *UNUSED(td), const gchar *old_name, const gchar *new_name, gpointer data)
 {
-       ViewFile *vf = data;
+       ViewFile *vf = (ViewFile *)data;
        gchar *new_path;
 
        if (!new_name || !new_name[0]) return FALSE;
@@ -532,7 +523,7 @@ static gboolean vflist_row_rename_cb(TreeEditData *UNUSED(td), const gchar *old_
 
 gboolean vflist_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
 {
-       ViewFile *vf = data;
+       ViewFile *vf = (ViewFile *)data;
        GtkTreePath *tpath;
 
        if (event->keyval != GDK_KEY_Menu) return FALSE;
@@ -561,7 +552,7 @@ gboolean vflist_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer dat
 
 gboolean vflist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
 {
-       ViewFile *vf = data;
+       ViewFile *vf = (ViewFile *)data;
        GtkTreePath *tpath;
        GtkTreeIter iter;
        FileData *fd = NULL;
@@ -645,7 +636,7 @@ gboolean vflist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer dat
 
 gboolean vflist_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
 {
-       ViewFile *vf = data;
+       ViewFile *vf = (ViewFile *)data;
        GtkTreePath *tpath;
        GtkTreeIter iter;
        FileData *fd = NULL;
@@ -744,12 +735,12 @@ static void vflist_select_image(ViewFile *vf, FileData *sel_fd)
 
 static gboolean vflist_select_idle_cb(gpointer data)
 {
-       ViewFile *vf = data;
+       ViewFile *vf = (ViewFile *)data;
 
        if (!vf->layout)
                {
                VFLIST(vf)->select_idle_id = 0;
-               return FALSE;
+               return G_SOURCE_REMOVE;
                }
 
        vf_send_update(vf);
@@ -761,7 +752,7 @@ static gboolean vflist_select_idle_cb(gpointer data)
                }
 
        VFLIST(vf)->select_idle_id = 0;
-       return FALSE;
+       return G_SOURCE_REMOVE;
 }
 
 static void vflist_select_idle_cancel(ViewFile *vf)
@@ -775,7 +766,7 @@ static void vflist_select_idle_cancel(ViewFile *vf)
 
 static gboolean vflist_select_cb(GtkTreeSelection *UNUSED(selection), GtkTreeModel *store, GtkTreePath *tpath, gboolean path_currently_selected, gpointer data)
 {
-       ViewFile *vf = data;
+       ViewFile *vf = (ViewFile *)data;
        GtkTreeIter iter;
        GtkTreePath *cursor_path;
 
@@ -803,13 +794,13 @@ static gboolean vflist_select_cb(GtkTreeSelection *UNUSED(selection), GtkTreeMod
 
 static void vflist_expand_cb(GtkTreeView *UNUSED(tree_view), GtkTreeIter *iter, GtkTreePath *UNUSED(path), gpointer data)
 {
-       ViewFile *vf = data;
+       ViewFile *vf = (ViewFile *)data;
        vflist_set_expanded(vf, iter, TRUE);
 }
 
 static void vflist_collapse_cb(GtkTreeView *UNUSED(tree_view), GtkTreeIter *iter, GtkTreePath *UNUSED(path), gpointer data)
 {
-       ViewFile *vf = data;
+       ViewFile *vf = (ViewFile *)data;
        vflist_set_expanded(vf, iter, FALSE);
 }
 
@@ -886,7 +877,7 @@ static void vflist_setup_iter(ViewFile *vf, GtkTreeStore *store, GtkTreeIter *it
        gchar *sidecars = NULL;
        gchar *name;
        const gchar *time = text_from_time(fd->date);
-       gchar *link = islink(fd->path) ? GQ_LINK_STR : "";
+       const gchar *link = islink(fd->path) ? GQ_LINK_STR : "";
        const gchar *disabled_grouping;
        gchar *formatted;
        gchar *formatted_with_stars;
@@ -972,7 +963,7 @@ static void vflist_setup_iter_recursive(ViewFile *vf, GtkTreeStore *store, GtkTr
        while (work)
                {
                gint match;
-               FileData *fd = work->data;
+               FileData *fd = (FileData *)work->data;
                gboolean done = FALSE;
 
                while (!done)
@@ -1075,7 +1066,7 @@ static void vflist_setup_iter_recursive(ViewFile *vf, GtkTreeStore *store, GtkTr
                {
                gint i;
                gint num_total = num_prepended + num_ordered;
-               gint *new_order = g_malloc(num_total * sizeof(gint));
+               gint *new_order = static_cast<gint *>(g_malloc(num_total * sizeof(gint)));
 
                for (i = 0; i < num_total; i++)
                        {
@@ -1105,7 +1096,7 @@ void vflist_sort_set(ViewFile *vf, SortType type, gboolean ascend)
        i = 0;
        while (work)
                {
-               FileData *fd = work->data;
+               FileData *fd = (FileData *)work->data;
                g_hash_table_insert(fd_idx_hash, fd, GINT_TO_POINTER(i));
                i++;
                work = work->next;
@@ -1116,13 +1107,13 @@ void vflist_sort_set(ViewFile *vf, SortType type, gboolean ascend)
 
        vf->list = filelist_sort(vf->list, vf->sort_method, vf->sort_ascend);
 
-       new_order = g_malloc(i * sizeof(gint));
+       new_order = static_cast<gint *>(g_malloc(i * sizeof(gint)));
 
        work = vf->list;
        i = 0;
        while (work)
                {
-               FileData *fd = work->data;
+               FileData *fd = (FileData *)work->data;
                new_order[i] = GPOINTER_TO_INT(g_hash_table_lookup(fd_idx_hash, fd));
                i++;
                work = work->next;
@@ -1147,7 +1138,7 @@ void vflist_thumb_progress_count(GList *list, gint *count, gint *done)
        GList *work = list;
        while (work)
                {
-               FileData *fd = work->data;
+               FileData *fd = (FileData *)work->data;
                work = work->next;
 
                if (fd->thumb_pixbuf) (*done)++;
@@ -1165,7 +1156,7 @@ void vflist_read_metadata_progress_count(GList *list, gint *count, gint *done)
        GList *work = list;
        while (work)
                {
-               FileData *fd = work->data;
+               FileData *fd = (FileData *)work->data;
                work = work->next;
 
                if (fd->metadata_in_idle_loaded) (*done)++;
@@ -1226,7 +1217,7 @@ FileData *vflist_thumb_next_fd(ViewFile *vf)
                GList *work = vf->list;
                while (work && !fd)
                        {
-                       FileData *fd_p = work->data;
+                       FileData *fd_p = (FileData *)work->data;
                        if (!fd_p->thumb_pixbuf)
                                fd = fd_p;
                        else
@@ -1235,7 +1226,7 @@ FileData *vflist_thumb_next_fd(ViewFile *vf)
 
                                while (work2 && !fd)
                                        {
-                                       fd_p = work2->data;
+                                       fd_p = static_cast<FileData *>(work2->data);
                                        if (!fd_p->thumb_pixbuf) fd = fd_p;
                                        work2 = work2->next;
                                        }
@@ -1334,7 +1325,7 @@ FileData *vflist_star_next_fd(ViewFile *vf)
 
                while (work && !fd)
                        {
-                       FileData *fd_p = work->data;
+                       FileData *fd_p = (FileData *)work->data;
 
                        if (fd_p && fd_p->rating == STAR_RATING_NOT_READ)
                                {
@@ -1376,7 +1367,7 @@ gint vflist_index_by_fd(ViewFile *vf, FileData *fd)
        work = vf->list;
        while (work)
                {
-               FileData *list_fd = work->data;
+               FileData *list_fd = (FileData *)work->data;
                if (list_fd == fd) return p;
 
                work2 = list_fd->sidecar_files;
@@ -1386,7 +1377,7 @@ gint vflist_index_by_fd(ViewFile *vf, FileData *fd)
                           it is sufficient for next/prev navigation but it should be rewritten
                           without using indexes at all
                        */
-                       FileData *sidecar_fd = work2->data;
+                       FileData *sidecar_fd = static_cast<FileData *>(work2->data);
                        if (sidecar_fd == fd) return p;
                        work2 = work2->next;
                        }
@@ -1417,7 +1408,7 @@ static gboolean vflist_row_is_selected(ViewFile *vf, FileData *fd)
        work = slist;
        while (!found && work)
                {
-               GtkTreePath *tpath = work->data;
+               GtkTreePath *tpath = (GtkTreePath *)work->data;
                FileData *fd_n;
                GtkTreeIter iter;
 
@@ -1432,13 +1423,13 @@ static gboolean vflist_row_is_selected(ViewFile *vf, FileData *fd)
        return found;
 }
 
-gboolean vflist_index_is_selected(ViewFile *vf, gint row)
-{
-       FileData *fd;
+//gboolean vflist_index_is_selected(ViewFile *vf, gint row)
+//{
+       //FileData *fd;
 
-       fd = vf_index_get_data(vf, row);
-       return vflist_row_is_selected(vf, fd);
-}
+       //fd = vf_index_get_data(vf, row);
+       //return vflist_row_is_selected(vf, fd);
+//}
 
 guint vflist_selection_count(ViewFile *vf, gint64 *bytes)
 {
@@ -1458,7 +1449,7 @@ guint vflist_selection_count(ViewFile *vf, gint64 *bytes)
                work = slist;
                while (work)
                        {
-                       GtkTreePath *tpath = work->data;
+                       GtkTreePath *tpath = (GtkTreePath *)work->data;
                        GtkTreeIter iter;
                        FileData *fd;
 
@@ -1492,7 +1483,7 @@ GList *vflist_selection_get_list(ViewFile *vf)
        work = slist;
        while (work)
                {
-               GtkTreePath *tpath = work->data;
+               GtkTreePath *tpath = (GtkTreePath *)work->data;
                FileData *fd;
                GtkTreeIter iter;
 
@@ -1507,7 +1498,7 @@ GList *vflist_selection_get_list(ViewFile *vf)
                        GList *work2 = fd->sidecar_files;
                        while (work2)
                                {
-                               FileData *sfd = work2->data;
+                               FileData *sfd = static_cast<FileData *>(work2->data);
                                list = g_list_prepend(list, file_data_ref(sfd));
                                work2 = work2->next;
                                }
@@ -1534,7 +1525,7 @@ GList *vflist_selection_get_list_by_index(ViewFile *vf)
        work = slist;
        while (work)
                {
-               GtkTreePath *tpath = work->data;
+               GtkTreePath *tpath = (GtkTreePath *)work->data;
                FileData *fd;
                GtkTreeIter iter;
 
@@ -1666,7 +1657,7 @@ void vflist_select_list(ViewFile *vf, GList *list)
                {
                FileData *fd;
 
-               fd = work->data;
+               fd = static_cast<FileData *>(work->data);
 
                if (vflist_find_row(vf, fd, &iter) < 0) return;
                if (!vflist_row_is_selected(vf, fd))
@@ -1691,7 +1682,7 @@ static void vflist_select_closest(ViewFile *vf, FileData *sel_fd)
        while (work)
                {
                gint match;
-               fd = work->data;
+               fd = static_cast<FileData *>(work->data);
                work = work->next;
 
                match = filelist_sort_compare_filedata_full(fd, sel_fd, vf->sort_method, vf->sort_ascend);
@@ -1762,7 +1753,7 @@ void vflist_selection_to_mark(ViewFile *vf, gint mark, SelectionToMarkMode mode)
        work = slist;
        while (work)
                {
-               GtkTreePath *tpath = work->data;
+               GtkTreePath *tpath = (GtkTreePath *)work->data;
                FileData *fd;
                GtkTreeIter iter;
 
@@ -1823,7 +1814,7 @@ static void vflist_listview_set_columns(GtkWidget *listview, gboolean thumb, gbo
 
        list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(column));
        if (!list) return;
-       cell = list->data;
+       cell = static_cast<GtkCellRenderer *>(list->data);
        g_list_free(list);
 
        g_object_set(G_OBJECT(cell), "height", options->thumbnails.max_height, NULL);
@@ -1897,7 +1888,7 @@ static void vflist_populate_view(ViewFile *vf, gboolean force)
        if (selected && vflist_selection_count(vf, NULL) == 0)
                {
                /* all selected files disappeared */
-               vflist_select_closest(vf, selected->data);
+               vflist_select_closest(vf, static_cast<FileData *>(selected->data));
                }
 
        filelist_free(selected);
@@ -2001,7 +1992,7 @@ static GdkColor *vflist_listview_color_shifted(GtkWidget *widget)
 static void vflist_listview_color_cb(GtkTreeViewColumn *UNUSED(tree_column), GtkCellRenderer *cell,
                                     GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
 {
-       ViewFile *vf = data;
+       ViewFile *vf = (ViewFile *)data;
        gboolean set;
 
        gtk_tree_model_get(tree_model, iter, FILE_COLUMN_COLOR, &set, -1);
@@ -2050,7 +2041,7 @@ static void vflist_listview_add_column(ViewFile *vf, gint n, const gchar *title,
 
 static void vflist_listview_mark_toggled_cb(GtkCellRendererToggle *cell, gchar *path_str, gpointer data)
 {
-       ViewFile *vf = data;
+       ViewFile *vf = (ViewFile *)data;
        GtkTreeStore *store;
        GtkTreePath *path = gtk_tree_path_new_from_string(path_str);
        GtkTreeIter iter;
@@ -2137,7 +2128,7 @@ gboolean vflist_set_fd(ViewFile *vf, FileData *dir_fd)
 
 void vflist_destroy_cb(GtkWidget *UNUSED(widget), gpointer data)
 {
-       ViewFile *vf = data;
+       ViewFile *vf = (ViewFile *)data;
 
        file_data_unregister_notify_func(vf_notify_cb, vf);
 
@@ -2257,7 +2248,7 @@ void vflist_marks_set(ViewFile *vf, gboolean enable)
        work = columns;
        while (work)
                {
-               GtkTreeViewColumn *column = work->data;
+               GtkTreeViewColumn *column = (GtkTreeViewColumn *)work->data;
                gint col_idx = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_store_idx"));
                work = work->next;