* 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,
* misc
*-----------------------------------------------------------------------------
*/
-typedef struct {
- FileData *fd;
+struct ViewFileFindRowData {
+ const FileData *fd;
GtkTreeIter *iter;
gboolean found;
gint row;
-} ViewFileFindRowData;
+};
-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)
{
- ViewFileFindRowData *find = data;
+ auto find = static_cast<ViewFileFindRowData *>(data);
FileData *fd;
gtk_tree_model_get(model, iter, FILE_COLUMN_POINTER, &fd, -1);
if (fd == find->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;
if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vf->listview), x, y,
- &tpath, &column, NULL, NULL))
+ &tpath, &column, nullptr, nullptr))
{
GtkTreeModel *store;
GtkTreeIter row;
return fd;
}
- return NULL;
+ 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);
static void vflist_store_clear(ViewFile *vf, gboolean unlock_files)
{
GtkTreeModel *store;
- GList *files = NULL;
+ GList *files = nullptr;
if (unlock_files && vf->marks_enabled)
{
// unlock locked files in this directory
- filelist_read(vf->dir_fd, &files, NULL);
- while (files)
+ filelist_read(vf->dir_fd, &files, nullptr);
+ GList *work = files;
+ while (work)
{
- FileData *fd = 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
}
g_list_free(files);
store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
- gtk_tree_model_foreach(store, vflist_store_clear_cb, NULL);
+ gtk_tree_model_foreach(store, vflist_store_clear_cb, nullptr);
gtk_tree_store_clear(GTK_TREE_STORE(store));
}
store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
tpath = gtk_tree_model_get_path(store, iter);
- gtk_tree_view_set_cursor(GTK_TREE_VIEW(vf->listview), tpath, NULL, FALSE);
+ gtk_tree_view_set_cursor(GTK_TREE_VIEW(vf->listview), tpath, nullptr, FALSE);
gtk_tree_path_free(tpath);
}
*-----------------------------------------------------------------------------
*/
-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)
{
- ViewFile *vf = data;
- GList *list = NULL;
+ auto vf = static_cast<ViewFile *>(data);
+ GList *list = nullptr;
if (!VFLIST(vf)->click_fd) return;
}
else
{
- list = g_list_append(NULL, file_data_ref(VFLIST(vf)->click_fd));
+ list = g_list_append(nullptr, file_data_ref(VFLIST(vf)->click_fd));
}
if (!list) return;
static void vflist_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data)
{
- ViewFile *vf = data;
+ auto vf = static_cast<ViewFile *>(data);
vflist_color_set(vf, VFLIST(vf)->click_fd, TRUE);
guint items;
if (vflist_row_is_selected(vf, VFLIST(vf)->click_fd))
- items = vf_selection_count(vf, NULL);
+ items = vf_selection_count(vf, nullptr);
else
items = 1;
}
}
-static void vflist_dnd_end(GtkWidget *UNUSED(widget), GdkDragContext *context, gpointer data)
+static void vflist_dnd_end(GtkWidget *, GdkDragContext *context, gpointer data)
{
- ViewFile *vf = data;
+ auto vf = static_cast<ViewFile *>(data);
vflist_color_set(vf, VFLIST(vf)->click_fd, FALSE);
}
}
-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)
{
- ViewFile *vf = data;
+ auto vf = static_cast<ViewFile *>(data);
if (info == TARGET_TEXT_PLAIN) {
- FileData *fd = vflist_find_data_by_coord(vf, x, y, NULL);
+ FileData *fd = vflist_find_data_by_coord(vf, x, y, nullptr);
if (fd) {
/* Add keywords to file */
- gchar *str = (gchar *) gtk_selection_data_get_text(selection);
+ auto str = reinterpret_cast<gchar *>(gtk_selection_data_get_text(selection));
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);
}
}
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);
GList *vflist_selection_get_one(ViewFile *vf, FileData *fd)
{
- GList *list = g_list_append(NULL, 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)
- {
- FileData *sfd = 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)
{
- if (!VFLIST(vf)->click_fd) return NULL;
+ if (!VFLIST(vf)->click_fd) return nullptr;
if (vflist_row_is_selected(vf, VFLIST(vf)->click_fd))
{
}
-void vflist_pop_menu_view_cb(GtkWidget *UNUSED(widget), gpointer data)
+void vflist_pop_menu_view_cb(GtkWidget *, gpointer data)
{
- ViewFile *vf = data;
+ auto vf = static_cast<ViewFile *>(data);
if (vflist_row_is_selected(vf, VFLIST(vf)->click_fd))
{
}
}
-void vflist_pop_menu_rename_cb(GtkWidget *UNUSED(widget), gpointer data)
+void vflist_pop_menu_rename_cb(GtkWidget *, gpointer data)
{
- ViewFile *vf = data;
+ auto vf = static_cast<ViewFile *>(data);
GList *list;
list = vf_pop_menu_file_list(vf);
return;
}
- file_util_rename(NULL, list, vf->listview);
+ 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)
{
- ViewFile *vf = data;
+ auto vf = static_cast<ViewFile *>(data);
vflist_color_set(vf, VFLIST(vf)->click_fd, FALSE);
if (vf->layout)
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));
work = columns;
while (work)
{
- GtkTreeViewColumn *column = work->data;
+ auto column = static_cast<GtkTreeViewColumn *>(work->data);
gint col_idx = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_store_idx"));
work = work->next;
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)
{
- ViewFile *vf = data;
+ auto vf = static_cast<ViewFile *>(data);
options->show_star_rating = !options->show_star_rating;
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)
{
- ViewFile *vf = data;
+ auto vf = static_cast<ViewFile *>(data);
vflist_color_set(vf, VFLIST(vf)->click_fd, FALSE);
vf_refresh(vf);
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)
{
- ViewFile *vf = data;
+ auto vf = static_cast<ViewFile *>(data);
vflist_color_set(vf, VFLIST(vf)->click_fd, FALSE);
- VFLIST(vf)->click_fd = NULL;
- vf->popup = NULL;
+ VFLIST(vf)->click_fd = nullptr;
+ vf->popup = nullptr;
}
*-----------------------------------------------------------------------------
*/
-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)
{
- ViewFile *vf = data;
+ auto vf = static_cast<ViewFile *>(data);
gchar *new_path;
if (!new_name || !new_name[0]) return FALSE;
new_path = g_build_filename(vf->dir_fd->path, new_name, NULL);
- if (strchr(new_name, G_DIR_SEPARATOR) != NULL)
+ 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
gboolean vflist_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
- ViewFile *vf = data;
+ auto vf = static_cast<ViewFile *>(data);
GtkTreePath *tpath;
if (event->keyval != GDK_KEY_Menu) return FALSE;
- gtk_tree_view_get_cursor(GTK_TREE_VIEW(vf->listview), &tpath, NULL);
+ gtk_tree_view_get_cursor(GTK_TREE_VIEW(vf->listview), &tpath, nullptr);
if (tpath)
{
GtkTreeModel *store;
}
else
{
- VFLIST(vf)->click_fd = NULL;
+ VFLIST(vf)->click_fd = nullptr;
}
vf->popup = vf_pop_menu(vf);
- gtk_menu_popup_at_widget(GTK_MENU(vf->popup), widget, GDK_GRAVITY_EAST, GDK_GRAVITY_CENTER, NULL);
+ gtk_menu_popup_at_widget(GTK_MENU(vf->popup), widget, GDK_GRAVITY_EAST, GDK_GRAVITY_CENTER, nullptr);
return TRUE;
}
gboolean vflist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
{
- ViewFile *vf = data;
+ auto vf = static_cast<ViewFile *>(data);
GtkTreePath *tpath;
GtkTreeIter iter;
- FileData *fd = NULL;
+ FileData *fd = nullptr;
GtkTreeViewColumn *column;
vf->clicked_mark = 0;
if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y,
- &tpath, &column, NULL, NULL))
+ &tpath, &column, nullptr, nullptr))
{
GtkTreeModel *store;
gint col_idx = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_store_idx"));
if (bevent->button == MOUSE_BUTTON_RIGHT)
{
vf->popup = vf_pop_menu(vf);
- gtk_menu_popup_at_pointer(GTK_MENU(vf->popup), NULL);
+ gtk_menu_popup_at_pointer(GTK_MENU(vf->popup), nullptr);
return TRUE;
}
gboolean vflist_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
{
- ViewFile *vf = data;
+ auto vf = static_cast<ViewFile *>(data);
GtkTreePath *tpath;
GtkTreeIter iter;
- FileData *fd = NULL;
+ FileData *fd = nullptr;
if (defined_mouse_buttons(widget, bevent, vf->layout))
{
if ((bevent->x != 0 || bevent->y != 0) &&
gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y,
- &tpath, NULL, NULL, NULL))
+ &tpath, nullptr, nullptr, nullptr))
{
GtkTreeModel *store;
static void vflist_select_image(ViewFile *vf, FileData *sel_fd)
{
- FileData *read_ahead_fd = NULL;
+ FileData *read_ahead_fd = nullptr;
gint row;
FileData *cur_fd;
if (sel_fd && options->image.enable_read_ahead && row >= 0)
{
if (row > g_list_index(vf->list, cur_fd) &&
- (guint) (row + 1) < vf_count(vf, NULL))
+ static_cast<guint>(row + 1) < vf_count(vf, nullptr))
{
read_ahead_fd = vf_index_get_data(vf, row + 1);
}
static gboolean vflist_select_idle_cb(gpointer data)
{
- ViewFile *vf = data;
+ auto vf = static_cast<ViewFile *>(data);
if (!vf->layout)
{
VFLIST(vf)->select_idle_id = 0;
- return FALSE;
+ return G_SOURCE_REMOVE;
}
vf_send_update(vf);
if (VFLIST(vf)->select_fd)
{
vflist_select_image(vf, VFLIST(vf)->select_fd);
- VFLIST(vf)->select_fd = NULL;
+ VFLIST(vf)->select_fd = nullptr;
}
VFLIST(vf)->select_idle_id = 0;
- return FALSE;
+ return G_SOURCE_REMOVE;
}
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)
+static gboolean vflist_select_cb(GtkTreeSelection *, GtkTreeModel *store, GtkTreePath *tpath, gboolean path_currently_selected, gpointer data)
{
- ViewFile *vf = data;
+ auto vf = static_cast<ViewFile *>(data);
GtkTreeIter iter;
GtkTreePath *cursor_path;
- VFLIST(vf)->select_fd = NULL;
+ VFLIST(vf)->select_fd = nullptr;
if (!path_currently_selected && gtk_tree_model_get_iter(store, &iter, tpath))
{
- gtk_tree_view_get_cursor(GTK_TREE_VIEW(vf->listview), &cursor_path, NULL);
+ gtk_tree_view_get_cursor(GTK_TREE_VIEW(vf->listview), &cursor_path, nullptr);
if (cursor_path)
{
gtk_tree_model_get_iter(store, &iter, cursor_path);
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)
{
- ViewFile *vf = 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)
{
- ViewFile *vf = data;
+ auto vf = static_cast<ViewFile *>(data);
vflist_set_expanded(vf, iter, FALSE);
}
FILE_COLUMN_STAR_RATING, &star_rating,
-1);
- formatted = vflist_get_formatted(vf, name, sidecars, size, time, expanded, FALSE, NULL);
+ formatted = vflist_get_formatted(vf, name, sidecars, size, time, expanded, FALSE, nullptr);
formatted_with_stars = vflist_get_formatted(vf, name, sidecars, size, time, expanded, TRUE, star_rating);
gtk_tree_store_set(store, iter, FILE_COLUMN_FORMATTED, formatted,
static void vflist_setup_iter(ViewFile *vf, GtkTreeStore *store, GtkTreeIter *iter, FileData *fd)
{
gchar *size;
- gchar *sidecars = NULL;
+ gchar *sidecars = nullptr;
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;
}
else
{
- star_rating = NULL;
+ star_rating = nullptr;
}
if (fd->sidecar_files) /* expanded has no effect on files without sidecars */
name = g_strdup_printf("%s%s%s", link, fd->name, disabled_grouping);
size = text_from_size(fd->size);
- formatted = vflist_get_formatted(vf, name, sidecars, size, time, expanded, FALSE, NULL);
+ formatted = vflist_get_formatted(vf, name, sidecars, size, time, expanded, FALSE, nullptr);
formatted_with_stars = vflist_get_formatted(vf, name, sidecars, size, time, expanded, TRUE, star_rating);
gtk_tree_store_set(store, iter, FILE_COLUMN_POINTER, fd,
while (work)
{
gint match;
- FileData *fd = work->data;
+ auto fd = static_cast<FileData *>(work->data);
gboolean done = FALSE;
while (!done)
{
- FileData *old_fd = NULL;
+ FileData *old_fd = nullptr;
gint old_version = 0;
if (valid)
/* move the prepended entries to the correct position */
if (num_prepended)
{
- gint i;
gint num_total = num_prepended + num_ordered;
- gint *new_order = 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(NULL, NULL);
- gint *new_order;
+ GHashTable *fd_idx_hash = g_hash_table_new(nullptr, nullptr);
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;
i = 0;
while (work)
{
- FileData *fd = work->data;
+ auto fd = static_cast<FileData *>(work->data);
g_hash_table_insert(fd_idx_hash, fd, GINT_TO_POINTER(i));
i++;
work = work->next;
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 = g_malloc(i * sizeof(gint));
+ std::vector<gint> new_order;
+ new_order.reserve(i);
work = vf->list;
- i = 0;
while (work)
{
- FileData *fd = work->data;
- new_order[i] = GPOINTER_TO_INT(g_hash_table_lookup(fd_idx_hash, fd));
- i++;
+ auto fd = static_cast<FileData *>(work->data);
+ 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, NULL, new_order);
+ gtk_tree_store_reorder(store, nullptr, new_order.data());
- g_free(new_order);
g_hash_table_destroy(fd_idx_hash);
}
GList *work = list;
while (work)
{
- FileData *fd = work->data;
+ auto fd = static_cast<FileData *>(work->data);
work = work->next;
if (fd->thumb_pixbuf) (*done)++;
GList *work = list;
while (work)
{
- FileData *fd = work->data;
+ auto fd = static_cast<FileData *>(work->data);
work = work->next;
if (fd->metadata_in_idle_loaded) (*done)++;
FileData *vflist_thumb_next_fd(ViewFile *vf)
{
GtkTreePath *tpath;
- FileData *fd = NULL;
+ FileData *fd = nullptr;
/* first check the visible files */
- if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vf->listview), 0, 0, &tpath, NULL, NULL, NULL))
+ if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vf->listview), 0, 0, &tpath, nullptr, nullptr, nullptr))
{
GtkTreeModel *store;
GtkTreeIter iter;
store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
gtk_tree_model_get_iter(store, &iter, tpath);
gtk_tree_path_free(tpath);
- tpath = NULL;
+ tpath = nullptr;
while (!fd && valid && tree_view_row_get_visibility(GTK_TREE_VIEW(vf->listview), &iter, FALSE) == 0)
{
GList *work = vf->list;
while (work && !fd)
{
- FileData *fd_p = work->data;
+ auto fd_p = static_cast<FileData *>(work->data);
if (!fd_p->thumb_pixbuf)
fd = fd_p;
else
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;
}
FileData *vflist_star_next_fd(ViewFile *vf)
{
GtkTreePath *tpath;
- FileData *fd = NULL;
- FileData *nfd = NULL;
+ FileData *fd = nullptr;
+ FileData *nfd = nullptr;
/* first check the visible files */
- if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vf->listview), 0, 0, &tpath, NULL, NULL, NULL))
+ if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vf->listview), 0, 0, &tpath, nullptr, nullptr, nullptr))
{
GtkTreeModel *store;
GtkTreeIter iter;
store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
gtk_tree_model_get_iter(store, &iter, tpath);
gtk_tree_path_free(tpath);
- tpath = NULL;
+ tpath = nullptr;
while (!fd && valid && tree_view_row_get_visibility(GTK_TREE_VIEW(vf->listview), &iter, FALSE) == 0)
{
if (vf->stars_id == 0)
{
- vf->stars_id = g_idle_add_full(G_PRIORITY_LOW, vf_stars_cb, vf, NULL);
+ vf->stars_id = g_idle_add_full(G_PRIORITY_LOW, vf_stars_cb, vf, nullptr);
}
}
}
while (work && !fd)
{
- FileData *fd_p = work->data;
+ auto fd_p = static_cast<FileData *>(work->data);
if (fd_p && fd_p->rating == STAR_RATING_NOT_READ)
{
}
else
{
- fd = NULL;
+ fd = nullptr;
}
work = work->next;
if (vf->stars_id == 0)
{
- vf->stars_id = g_idle_add_full(G_PRIORITY_LOW, vf_stars_cb, vf, NULL);
+ vf->stars_id = g_idle_add_full(G_PRIORITY_LOW, vf_stars_cb, vf, nullptr);
}
}
}
gint vflist_index_by_fd(ViewFile *vf, FileData *fd)
{
gint p = 0;
- GList *work, *work2;
+ GList *work;
+ GList *work2;
work = vf->list;
while (work)
{
- FileData *list_fd = work->data;
+ auto list_fd = static_cast<FileData *>(work->data);
if (list_fd == fd) return p;
work2 = list_fd->sidecar_files;
it is sufficient for next/prev navigation but it should be rewritten
without using indexes at all
*/
- FileData *sidecar_fd = work2->data;
+ auto sidecar_fd = static_cast<FileData *>(work2->data);
if (sidecar_fd == fd) return p;
work2 = work2->next;
}
work = slist;
while (!found && work)
{
- GtkTreePath *tpath = work->data;
+ auto tpath = static_cast<GtkTreePath *>(work->data);
FileData *fd_n;
GtkTreeIter iter;
if (fd_n == fd) found = TRUE;
work = work->next;
}
- g_list_foreach(slist, (GFunc)tree_path_free_wrapper, NULL);
- 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)
+#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);
}
+#pragma GCC diagnostic pop
guint vflist_selection_count(ViewFile *vf, gint64 *bytes)
{
work = slist;
while (work)
{
- GtkTreePath *tpath = work->data;
+ auto tpath = static_cast<GtkTreePath *>(work->data);
GtkTreeIter iter;
FileData *fd;
}
count = g_list_length(slist);
- g_list_foreach(slist, (GFunc)tree_path_free_wrapper, NULL);
- g_list_free(slist);
+ g_list_free_full(slist, reinterpret_cast<GDestroyNotify>(gtk_tree_path_free));
return count;
}
GtkTreeModel *store;
GtkTreeSelection *selection;
GList *slist;
- GList *list = NULL;
- GList *work;
+ GList *list = nullptr;
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)
{
- GtkTreePath *tpath = work->data;
+ auto tpath = static_cast<GtkTreePath *>(work->data);
FileData *fd;
GtkTreeIter iter;
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)
- {
- FileData *sfd = 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, (GFunc)tree_path_free_wrapper, NULL);
- 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)
GtkTreeModel *store;
GtkTreeSelection *selection;
GList *slist;
- GList *list = NULL;
+ GList *list = nullptr;
GList *work;
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vf->listview));
work = slist;
while (work)
{
- GtkTreePath *tpath = work->data;
+ auto tpath = static_cast<GtkTreePath *>(work->data);
FileData *fd;
GtkTreeIter iter;
work = work->next;
}
- g_list_foreach(slist, (GFunc)tree_path_free_wrapper, NULL);
- g_list_free(slist);
+ g_list_free_full(slist, reinterpret_cast<GDestroyNotify>(gtk_tree_path_free));
return g_list_reverse(list);
}
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vf->listview));
gtk_tree_selection_select_all(selection);
- VFLIST(vf)->select_fd = NULL;
+ VFLIST(vf)->select_fd = nullptr;
}
void vflist_select_none(ViewFile *vf)
store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
tpath = gtk_tree_model_get_path(store, &iter);
- gtk_tree_view_set_cursor(GTK_TREE_VIEW(vf->listview), tpath, NULL, FALSE);
+ gtk_tree_view_set_cursor(GTK_TREE_VIEW(vf->listview), tpath, nullptr, FALSE);
gtk_tree_path_free(tpath);
}
}
{
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))
static void vflist_select_closest(ViewFile *vf, FileData *sel_fd)
{
GList *work;
- FileData *fd = NULL;
+ FileData *fd = nullptr;
if (sel_fd->parent) sel_fd = sel_fd->parent;
work = vf->list;
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);
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 = slist;
while (work)
{
- GtkTreePath *tpath = work->data;
+ auto tpath = static_cast<GtkTreePath *>(work->data);
FileData *fd;
GtkTreeIter iter;
/* mark functions can have various side effects - update all columns to be sure */
vflist_setup_iter(vf, GTK_TREE_STORE(store), &iter, fd);
/* mark functions can change sidecars too */
- vflist_setup_iter_recursive(vf, GTK_TREE_STORE(store), &iter, fd->sidecar_files, NULL, FALSE);
+ vflist_setup_iter_recursive(vf, GTK_TREE_STORE(store), &iter, fd->sidecar_files, nullptr, FALSE);
}
work = work->next;
}
- g_list_foreach(slist, (GFunc)tree_path_free_wrapper, NULL);
- g_list_free(slist);
+ g_list_free_full(slist, reinterpret_cast<GDestroyNotify>(gtk_tree_path_free));
}
/*
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);
selected = vflist_selection_get_list(vf);
- vflist_setup_iter_recursive(vf, store, NULL, vf->list, selected, force);
+ vflist_setup_iter_recursive(vf, store, nullptr, vf->list, selected, force);
- if (selected && vflist_selection_count(vf, NULL) == 0)
+ if (selected && vflist_selection_count(vf, nullptr) == 0)
{
/* all selected files disappeared */
- vflist_select_closest(vf, selected->data);
+ vflist_select_closest(vf, static_cast<FileData *>(selected->data));
}
filelist_free(selected);
gboolean ret = TRUE;
old_list = vf->list;
- vf->list = NULL;
+ vf->list = nullptr;
DEBUG_1("%s vflist_refresh: read dir", get_exec_time());
if (vf->dir_fd)
{
file_data_unregister_notify_func(vf_notify_cb, vf); /* we don't need the notification of changes detected by filelist_read */
- ret = filelist_read(vf->dir_fd, &vf->list, NULL);
+ 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 GtkWidget *done = NULL;
+ 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)
{
- ViewFile *vf = data;
+ auto vf = static_cast<ViewFile *>(data);
gboolean set;
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);
}
gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", n);
}
- gtk_tree_view_column_set_cell_data_func(column, renderer, vflist_listview_color_cb, vf, NULL);
+ gtk_tree_view_column_set_cell_data_func(column, renderer, vflist_listview_color_cb, vf, nullptr);
g_object_set_data(G_OBJECT(column), "column_store_idx", GUINT_TO_POINTER(n));
g_object_set_data(G_OBJECT(renderer), "column_store_idx", GUINT_TO_POINTER(n));
static void vflist_listview_mark_toggled_cb(GtkCellRendererToggle *cell, gchar *path_str, gpointer data)
{
- ViewFile *vf = data;
+ auto vf = static_cast<ViewFile *>(data);
GtkTreeStore *store;
GtkTreePath *path = gtk_tree_path_new_from_string(path_str);
GtkTreeIter iter;
/* mark functions can have various side effects - update all columns to be sure */
vflist_setup_iter(vf, GTK_TREE_STORE(store), &iter, fd);
/* mark functions can change sidecars too */
- vflist_setup_iter_recursive(vf, GTK_TREE_STORE(store), &iter, fd->sidecar_files, NULL, FALSE);
+ vflist_setup_iter_recursive(vf, GTK_TREE_STORE(store), &iter, fd->sidecar_files, nullptr, FALSE);
}
file_data_register_notify_func(vf_notify_cb, vf, NOTIFY_PRIORITY_MEDIUM);
vflist_store_clear(vf, TRUE);
filelist_free(vf->list);
- vf->list = NULL;
+ vf->list = nullptr;
ret = vf_refresh(vf);
gtk_tree_view_columns_autosize(GTK_TREE_VIEW(vf->listview));
return ret;
}
-void vflist_destroy_cb(GtkWidget *UNUSED(widget), gpointer data)
+void vflist_destroy_cb(GtkWidget *, gpointer data)
{
- ViewFile *vf = data;
+ auto vf = static_cast<ViewFile *>(data);
file_data_unregister_notify_func(vf_notify_cb, vf);
filelist_free(vf->list);
}
-ViewFile *vflist_new(ViewFile *vf, FileData *UNUSED(dir_fd))
+ViewFile *vflist_new(ViewFile *vf, FileData *)
{
GtkTreeStore *store;
GtkTreeSelection *selection;
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vf->listview));
gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_MULTIPLE);
- gtk_tree_selection_set_select_function(selection, vflist_select_cb, vf, NULL);
+ gtk_tree_selection_set_select_function(selection, vflist_select_cb, vf, nullptr);
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(vf->listview), FALSE);
gtk_tree_view_set_enable_search(GTK_TREE_VIEW(vf->listview), FALSE);
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));
work = columns;
while (work)
{
- GtkTreeViewColumn *column = work->data;
+ auto column = static_cast<GtkTreeViewColumn *>(work->data);
gint col_idx = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_store_idx"));
work = work->next;