* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include "main.h"
#include "view-file-list.h"
+#include <config.h>
+
#include "collect.h"
+#include "debug.h"
#include "dnd.h"
#include "img-view.h"
-#include "layout.h"
+#include "intl.h"
#include "layout-image.h"
+#include "layout.h"
+#include "main-defines.h"
#include "metadata.h"
#include "misc.h"
-#include "utilops.h"
#include "ui-fileops.h"
#include "ui-misc.h"
#include "ui-tree-edit.h"
#include "uri-utils.h"
+#include "utilops.h"
#include "view-file.h"
+#include <vector>
+
/* Index to tree store */
enum {
FILE_COLUMN_POINTER = 0,
*-----------------------------------------------------------------------------
*/
struct ViewFileFindRowData {
- FileData *fd;
+ const FileData *fd;
GtkTreeIter *iter;
gboolean found;
gint row;
};
-static gboolean vflist_find_row_cb(GtkTreeModel *model, GtkTreePath *UNUSED(path), GtkTreeIter *iter, gpointer data)
+static gboolean vflist_find_row_cb(GtkTreeModel *model, GtkTreePath *, GtkTreeIter *iter, gpointer data)
{
auto find = static_cast<ViewFileFindRowData *>(data);
FileData *fd;
return FALSE;
}
-static gint vflist_find_row(ViewFile *vf, FileData *fd, GtkTreeIter *iter)
+static gint vflist_find_row(const ViewFile *vf, const FileData *fd, GtkTreeIter *iter)
{
GtkTreeModel *store;
ViewFileFindRowData data = {fd, iter, FALSE, 0};
return -1;
}
-static FileData *vflist_find_data_by_coord(ViewFile *vf, gint x, gint y, GtkTreeIter *UNUSED(iter))
+static FileData *vflist_find_data_by_coord(ViewFile *vf, gint x, gint y, GtkTreeIter *)
{
GtkTreePath *tpath;
GtkTreeViewColumn *column;
return nullptr;
}
-static gboolean vflist_store_clear_cb(GtkTreeModel *model, GtkTreePath *UNUSED(path), GtkTreeIter *iter, gpointer UNUSED(data))
+static gboolean vflist_store_clear_cb(GtkTreeModel *model, GtkTreePath *, GtkTreeIter *iter, gpointer)
{
FileData *fd;
gtk_tree_model_get(model, iter, FILE_COLUMN_POINTER, &fd, -1);
{
// unlock locked files in this directory
filelist_read(vf->dir_fd, &files, nullptr);
- while (files)
+ GList *work = files;
+ while (work)
{
- auto fd = static_cast<FileData *>(files->data);
- files = files->next;
+ auto fd = static_cast<FileData *>(work->data);
+ work = work->next;
file_data_unlock(fd);
file_data_unref(fd); // undo the ref that got added in filelist_read
}
*-----------------------------------------------------------------------------
*/
-static void vflist_dnd_get(GtkWidget *UNUSED(widget), GdkDragContext *UNUSED(context),
- GtkSelectionData *selection_data, guint UNUSED(info),
- guint UNUSED(time), gpointer data)
+static void vflist_dnd_get(GtkWidget *, GdkDragContext *,
+ GtkSelectionData *selection_data, guint,
+ guint, gpointer data)
{
auto vf = static_cast<ViewFile *>(data);
GList *list = nullptr;
}
}
-static void vflist_dnd_end(GtkWidget *UNUSED(widget), GdkDragContext *context, gpointer data)
+static void vflist_dnd_end(GtkWidget *, GdkDragContext *context, gpointer data)
{
auto vf = static_cast<ViewFile *>(data);
}
}
-static void vflist_drag_data_received(GtkWidget *UNUSED(entry_widget), GdkDragContext *UNUSED(context),
+static void vflist_drag_data_received(GtkWidget *, GdkDragContext *,
int x, int y, GtkSelectionData *selection,
- guint info, guint UNUSED(time), gpointer data)
+ guint info, guint, gpointer data)
{
auto vf = static_cast<ViewFile *>(data);
GList *kw_list = string_to_keywords_list(str);
metadata_append_list(fd, KEYWORD_KEY, kw_list);
- string_list_free(kw_list);
+ g_list_free_full(kw_list, g_free);
g_free(str);
}
}
GList *vflist_selection_get_one(ViewFile *vf, FileData *fd)
{
- GList *list = g_list_append(nullptr, file_data_ref(fd));
+ GList *list = nullptr;
if (fd->sidecar_files)
{
if (!gtk_tree_view_row_expanded(GTK_TREE_VIEW(vf->listview), tpath))
{
/* unexpanded - add whole group */
- GList *work = fd->sidecar_files;
- while (work)
- {
- auto sfd = static_cast<FileData *>(work->data);
- list = g_list_prepend(list, file_data_ref(sfd));
- work = work->next;
- }
+ list = filelist_copy(fd->sidecar_files);
}
gtk_tree_path_free(tpath);
}
- list = g_list_reverse(list);
}
- return list;
+ return g_list_prepend(list, file_data_ref(fd));
}
GList *vflist_pop_menu_file_list(ViewFile *vf)
}
-void vflist_pop_menu_view_cb(GtkWidget *UNUSED(widget), gpointer data)
+void vflist_pop_menu_view_cb(GtkWidget *, gpointer data)
{
auto vf = static_cast<ViewFile *>(data);
}
}
-void vflist_pop_menu_rename_cb(GtkWidget *UNUSED(widget), gpointer data)
+void vflist_pop_menu_rename_cb(GtkWidget *, gpointer data)
{
auto vf = static_cast<ViewFile *>(data);
GList *list;
file_util_rename(nullptr, list, vf->listview);
}
-void vflist_pop_menu_thumbs_cb(GtkWidget *UNUSED(widget), gpointer data)
+void vflist_pop_menu_thumbs_cb(GtkWidget *, gpointer data)
{
auto vf = static_cast<ViewFile *>(data);
void vflist_star_rating_set(ViewFile *vf, gboolean enable)
{
- GList *columns, *work;
+ GList *columns;
+ GList *work;
columns = gtk_tree_view_get_columns(GTK_TREE_VIEW(vf->listview));
g_list_free(columns);
}
-void vflist_pop_menu_show_star_rating_cb(GtkWidget *UNUSED(widget), gpointer data)
+void vflist_pop_menu_show_star_rating_cb(GtkWidget *, gpointer data)
{
auto vf = static_cast<ViewFile *>(data);
vflist_star_rating_set(vf, options->show_star_rating);
}
-void vflist_pop_menu_refresh_cb(GtkWidget *UNUSED(widget), gpointer data)
+void vflist_pop_menu_refresh_cb(GtkWidget *, gpointer data)
{
auto vf = static_cast<ViewFile *>(data);
gtk_tree_view_columns_autosize(GTK_TREE_VIEW(vf->listview));
}
-void vflist_popup_destroy_cb(GtkWidget *UNUSED(widget), gpointer data)
+void vflist_popup_destroy_cb(GtkWidget *, gpointer data)
{
auto vf = static_cast<ViewFile *>(data);
vflist_color_set(vf, VFLIST(vf)->click_fd, FALSE);
*-----------------------------------------------------------------------------
*/
-static gboolean vflist_row_rename_cb(TreeEditData *UNUSED(td), const gchar *old_name, const gchar *new_name, gpointer data)
+static gboolean vflist_row_rename_cb(TreeEditData *, const gchar *old_name, const gchar *new_name, gpointer data)
{
auto vf = static_cast<ViewFile *>(data);
gchar *new_path;
if (strchr(new_name, G_DIR_SEPARATOR) != nullptr)
{
gchar *text = g_strdup_printf(_("Invalid file name:\n%s"), new_name);
- file_util_warning_dialog(_("Error renaming file"), text, GTK_STOCK_DIALOG_ERROR, vf->listview);
+ file_util_warning_dialog(_("Error renaming file"), text, GQ_ICON_DIALOG_ERROR, vf->listview);
g_free(text);
}
else
}
}
-static gboolean vflist_select_cb(GtkTreeSelection *UNUSED(selection), GtkTreeModel *store, GtkTreePath *tpath, gboolean path_currently_selected, gpointer data)
+static gboolean vflist_select_cb(GtkTreeSelection *, GtkTreeModel *store, GtkTreePath *tpath, gboolean path_currently_selected, gpointer data)
{
auto vf = static_cast<ViewFile *>(data);
GtkTreeIter iter;
return TRUE;
}
-static void vflist_expand_cb(GtkTreeView *UNUSED(tree_view), GtkTreeIter *iter, GtkTreePath *UNUSED(path), gpointer data)
+static void vflist_expand_cb(GtkTreeView *, GtkTreeIter *iter, GtkTreePath *, gpointer data)
{
auto vf = static_cast<ViewFile *>(data);
vflist_set_expanded(vf, iter, TRUE);
}
-static void vflist_collapse_cb(GtkTreeView *UNUSED(tree_view), GtkTreeIter *iter, GtkTreePath *UNUSED(path), gpointer data)
+static void vflist_collapse_cb(GtkTreeView *, GtkTreeIter *iter, GtkTreePath *, gpointer data)
{
auto vf = static_cast<ViewFile *>(data);
vflist_set_expanded(vf, iter, FALSE);
/* move the prepended entries to the correct position */
if (num_prepended)
{
- gint i;
gint num_total = num_prepended + num_ordered;
- auto new_order = static_cast<gint *>(g_malloc(num_total * sizeof(gint)));
+ std::vector<gint> new_order;
+ new_order.reserve(num_total);
- for (i = 0; i < num_total; i++)
+ for (gint i = 0; i < num_ordered; i++)
{
- if (i < num_ordered)
- new_order[i] = num_prepended + i;
- else
- new_order[i] = num_total - 1 - i;
+ new_order.push_back(num_prepended + i);
}
- gtk_tree_store_reorder(store, parent_iter, new_order);
-
- g_free(new_order);
+ for (gint i = num_ordered; i < num_total; i++)
+ {
+ new_order.push_back(num_total - 1 - i);
+ }
+ gtk_tree_store_reorder(store, parent_iter, new_order.data());
}
}
-void vflist_sort_set(ViewFile *vf, SortType type, gboolean ascend)
+void vflist_sort_set(ViewFile *vf, SortType type, gboolean ascend, gboolean case_sensitive)
{
gint i;
GHashTable *fd_idx_hash = g_hash_table_new(nullptr, nullptr);
- gint *new_order;
GtkTreeStore *store;
GList *work;
- if (vf->sort_method == type && vf->sort_ascend == ascend) return;
+ if (vf->sort_method == type && vf->sort_ascend == ascend && vf->sort_case == case_sensitive) return;
if (!vf->list) return;
work = vf->list;
vf->sort_method = type;
vf->sort_ascend = ascend;
+ vf->sort_case = case_sensitive;
- vf->list = filelist_sort(vf->list, vf->sort_method, vf->sort_ascend);
+ vf->list = filelist_sort(vf->list, vf->sort_method, vf->sort_ascend, vf->sort_case);
- new_order = static_cast<gint *>(g_malloc(i * sizeof(gint)));
+ std::vector<gint> new_order;
+ new_order.reserve(i);
work = vf->list;
- i = 0;
while (work)
{
auto fd = static_cast<FileData *>(work->data);
- new_order[i] = GPOINTER_TO_INT(g_hash_table_lookup(fd_idx_hash, fd));
- i++;
+ new_order.push_back(GPOINTER_TO_INT(g_hash_table_lookup(fd_idx_hash, fd)));
work = work->next;
}
store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview)));
- gtk_tree_store_reorder(store, nullptr, new_order);
+ gtk_tree_store_reorder(store, nullptr, new_order.data());
- g_free(new_order);
g_hash_table_destroy(fd_idx_hash);
}
gint vflist_index_by_fd(ViewFile *vf, FileData *fd)
{
gint p = 0;
- GList *work, *work2;
+ GList *work;
+ GList *work2;
work = vf->list;
while (work)
if (fd_n == fd) found = TRUE;
work = work->next;
}
- g_list_foreach(slist, static_cast<GFunc>(tree_path_free_wrapper), nullptr);
- g_list_free(slist);
+ g_list_free_full(slist, reinterpret_cast<GDestroyNotify>(gtk_tree_path_free));
return found;
}
-//gboolean vflist_index_is_selected(ViewFile *vf, gint row)
-//{
- //FileData *fd;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+gboolean vflist_index_is_selected_unused(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);
+}
+#pragma GCC diagnostic pop
guint vflist_selection_count(ViewFile *vf, gint64 *bytes)
{
}
count = g_list_length(slist);
- g_list_foreach(slist, static_cast<GFunc>(tree_path_free_wrapper), nullptr);
- g_list_free(slist);
+ g_list_free_full(slist, reinterpret_cast<GDestroyNotify>(gtk_tree_path_free));
return count;
}
GtkTreeSelection *selection;
GList *slist;
GList *list = nullptr;
- GList *work;
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vf->listview));
slist = gtk_tree_selection_get_selected_rows(selection, &store);
- work = slist;
- while (work)
+ for (GList *work = g_list_last(slist); work; work = work->prev)
{
auto tpath = static_cast<GtkTreePath *>(work->data);
FileData *fd;
gtk_tree_model_get_iter(store, &iter, tpath);
gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1);
- list = g_list_prepend(list, file_data_ref(fd));
-
if (!fd->parent && !gtk_tree_view_row_expanded(GTK_TREE_VIEW(vf->listview), tpath))
{
/* unexpanded - add whole group */
- GList *work2 = fd->sidecar_files;
- while (work2)
- {
- auto sfd = static_cast<FileData *>(work2->data);
- list = g_list_prepend(list, file_data_ref(sfd));
- work2 = work2->next;
- }
+ list = g_list_concat(filelist_copy(fd->sidecar_files), list);
}
- work = work->next;
+ list = g_list_prepend(list, file_data_ref(fd));
}
- g_list_foreach(slist, static_cast<GFunc>(tree_path_free_wrapper), nullptr);
- g_list_free(slist);
+ g_list_free_full(slist, reinterpret_cast<GDestroyNotify>(gtk_tree_path_free));
- return g_list_reverse(list);
+ return list;
}
GList *vflist_selection_get_list_by_index(ViewFile *vf)
work = work->next;
}
- g_list_foreach(slist, static_cast<GFunc>(tree_path_free_wrapper), nullptr);
- g_list_free(slist);
+ g_list_free_full(slist, reinterpret_cast<GDestroyNotify>(gtk_tree_path_free));
return g_list_reverse(list);
}
while (valid)
{
FileData *fd;
- gboolean mark_val, selected;
+ gboolean mark_val;
+ gboolean selected;
gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, FILE_COLUMN_POINTER, &fd, -1);
mark_val = file_data_get_mark(fd, n);
work = work->next;
}
- g_list_foreach(slist, static_cast<GFunc>(tree_path_free_wrapper), nullptr);
- g_list_free(slist);
+ g_list_free_full(slist, reinterpret_cast<GDestroyNotify>(gtk_tree_path_free));
}
/*
ret = filelist_read(vf->dir_fd, &vf->list, nullptr);
if (vf->marks_enabled)
- {
- // When marks are enabled, lock FileDatas so that we don't end up re-parsing XML
- // each time a mark is changed.
- file_data_lock_list(vf->list);
- }
- else
+ {
+ // When marks are enabled, lock FileDatas so that we don't end up re-parsing XML
+ // each time a mark is changed.
+ file_data_lock_list(vf->list);
+ }
+ else
{
/** @FIXME only do this when needed (aka when we just switched from */
/** @FIXME marks-enabled to marks-disabled) */
file_data_register_notify_func(vf_notify_cb, vf, NOTIFY_PRIORITY_MEDIUM);
DEBUG_1("%s vflist_refresh: sort", get_exec_time());
- vf->list = filelist_sort(vf->list, vf->sort_method, vf->sort_ascend);
+ vf->list = filelist_sort(vf->list, vf->sort_method, vf->sort_ascend, vf->sort_case);
}
DEBUG_1("%s vflist_refresh: populate view", get_exec_time());
/* this overrides the low default of a GtkCellRenderer from 100 to CELL_HEIGHT_OVERRIDE, something sane for our purposes */
-#define CELL_HEIGHT_OVERRIDE 512
+enum {
+ CELL_HEIGHT_OVERRIDE = 512
+};
static void cell_renderer_height_override(GtkCellRenderer *renderer)
{
}
}
-static GdkColor *vflist_listview_color_shifted(GtkWidget *widget)
+static GdkRGBA *vflist_listview_color_shifted(GtkWidget *widget)
{
- static GdkColor color;
+ static GdkRGBA color;
+ static GdkRGBA color_style;
static GtkWidget *done = nullptr;
if (done != widget)
GtkStyle *style;
style = gtk_widget_get_style(widget);
- memcpy(&color, &style->base[GTK_STATE_NORMAL], sizeof(color));
+ convert_gdkcolor_to_gdkrgba(&style->base[GTK_STATE_NORMAL], &color_style);
+
+ memcpy(&color, &color_style, sizeof(color));
shift_color(&color, -1, 0);
done = widget;
}
return &color;
}
-static void vflist_listview_color_cb(GtkTreeViewColumn *UNUSED(tree_column), GtkCellRenderer *cell,
+static void vflist_listview_color_cb(GtkTreeViewColumn *, GtkCellRenderer *cell,
GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
{
auto vf = static_cast<ViewFile *>(data);
gtk_tree_model_get(tree_model, iter, FILE_COLUMN_COLOR, &set, -1);
g_object_set(G_OBJECT(cell),
- "cell-background-gdk", vflist_listview_color_shifted(vf->listview),
+ "cell-background-rgba", vflist_listview_color_shifted(vf->listview),
"cell-background-set", set, NULL);
}
return ret;
}
-void vflist_destroy_cb(GtkWidget *UNUSED(widget), gpointer data)
+void vflist_destroy_cb(GtkWidget *, gpointer data)
{
auto vf = static_cast<ViewFile *>(data);
filelist_free(vf->list);
}
-ViewFile *vflist_new(ViewFile *vf, FileData *UNUSED(dir_fd))
+ViewFile *vflist_new(ViewFile *vf, FileData *)
{
GtkTreeStore *store;
GtkTreeSelection *selection;
void vflist_marks_set(ViewFile *vf, gboolean enable)
{
- GList *columns, *work;
+ GList *columns;
+ GList *work;
columns = gtk_tree_view_get_columns(GTK_TREE_VIEW(vf->listview));