/*
* Geeqie
- * Copyright (C) 2008 - 2009 The Geeqie Team
+ * Copyright (C) 2008 - 2012 The Geeqie Team
*
* Author: Laurent Monin
*
#include "editors.h"
#include "layout.h"
#include "menu.h"
+#include "thumb.h"
#include "ui_menu.h"
#include "ui_fileops.h"
#include "utilops.h"
return fd;
}
-gint vf_index_by_path(ViewFile *vf, const gchar *path)
+gint vf_index_by_fd(ViewFile *vf, FileData *fd)
{
gint index = -1;
switch (vf->type)
{
- case FILEVIEW_LIST: index = vflist_index_by_path(vf, path); break;
- case FILEVIEW_ICON: index = vficon_index_by_path(vf, path); break;
+ case FILEVIEW_LIST: index = vflist_index_by_fd(vf, fd); break;
+ case FILEVIEW_ICON: index = vficon_index_by_fd(vf, fd); break;
}
return index;
return ret;
}
+GList *vf_selection_get_one(ViewFile *vf, FileData *fd)
+{
+ GList *ret = NULL;
+
+ switch (vf->type)
+ {
+ case FILEVIEW_LIST: ret = vflist_selection_get_one(vf, fd); break;
+ case FILEVIEW_ICON: ret = vficon_selection_get_one(vf, fd); break;
+ }
+
+ return ret;
+}
+
static void vf_pop_menu_edit_cb(GtkWidget *widget, gpointer data)
{
ViewFile *vf;
const gchar *key = data;
- GList *list;
vf = submenu_item_get_data(widget);
if (!vf) return;
- list = vf_pop_menu_file_list(vf);
- file_util_start_editor_from_filelist(key, list, vf->listview);
- filelist_free(list);
+ file_util_start_editor_from_filelist(key, vf_pop_menu_file_list(vf), vf->dir_fd->path, vf->listview);
}
static void vf_pop_menu_view_cb(GtkWidget *widget, gpointer data)
file_util_copy_path_list_to_clipboard(vf_pop_menu_file_list(vf));
}
+static void vf_pop_menu_enable_grouping_cb(GtkWidget *widget, gpointer data)
+{
+ ViewFile *vf = data;
+
+ file_data_disable_grouping_list(vf_pop_menu_file_list(vf), FALSE);
+}
+
+static void vf_pop_menu_disable_grouping_cb(GtkWidget *widget, gpointer data)
+{
+ ViewFile *vf = data;
+
+ file_data_disable_grouping_list(vf_pop_menu_file_list(vf), TRUE);
+}
+
static void vf_pop_menu_sort_cb(GtkWidget *widget, gpointer data)
{
ViewFile *vf;
static void vf_pop_menu_toggle_view_type_cb(GtkWidget *widget, gpointer data)
{
ViewFile *vf = data;
-
+ FileViewType new_type = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "menu_item_radio_data"));
if (!vf->layout) return;
- switch (vf->type)
- {
- case FILEVIEW_LIST:
- layout_views_set(vf->layout, vf->layout->options.dir_view_type, FILEVIEW_ICON);
- break;
- case FILEVIEW_ICON:
- layout_views_set(vf->layout, vf->layout->options.dir_view_type, FILEVIEW_LIST);
- break;
- }
+ layout_views_set(vf->layout, vf->layout->options.dir_view_type, new_type);
}
static void vf_pop_menu_refresh_cb(GtkWidget *widget, gpointer data)
g_free(str_sel_mark_minus);
}
- vf->editmenu_fd_list = vf_selection_get_list(vf);
+ vf->editmenu_fd_list = vf_pop_menu_file_list(vf);
submenu_add_edit(menu, &item, G_CALLBACK(vf_pop_menu_edit_cb), vf, vf->editmenu_fd_list);
gtk_widget_set_sensitive(item, active);
G_CALLBACK(vf_pop_menu_rename_cb), vf);
menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, active,
G_CALLBACK(vf_pop_menu_delete_cb), vf);
- if (options->show_copy_path)
- menu_item_add_sensitive(menu, _("_Copy path"), active,
- G_CALLBACK(vf_pop_menu_copy_path_cb), vf);
+ menu_item_add_sensitive(menu, _("_Copy path"), active,
+ G_CALLBACK(vf_pop_menu_copy_path_cb), vf);
+
+ menu_item_add_sensitive(menu, _("Enable file _grouping"), active,
+ G_CALLBACK(vf_pop_menu_enable_grouping_cb), vf);
+ menu_item_add_sensitive(menu, _("Disable file groupi_ng"), active,
+ G_CALLBACK(vf_pop_menu_disable_grouping_cb), vf);
menu_item_add_divider(menu);
item = menu_item_add(menu, _("_Sort"), NULL, NULL);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
- menu_item_add_check(menu, _("View as _icons"), (vf->type == FILEVIEW_ICON),
- G_CALLBACK(vf_pop_menu_toggle_view_type_cb), vf);
+ item = menu_item_add_radio(menu, _("View as _List"), GINT_TO_POINTER(FILEVIEW_LIST), vf->type == FILEVIEW_LIST,
+ G_CALLBACK(vf_pop_menu_toggle_view_type_cb), vf);
+
+ item = menu_item_add_radio(menu, _("View as _Icons"), GINT_TO_POINTER(FILEVIEW_ICON), vf->type == FILEVIEW_ICON,
+ G_CALLBACK(vf_pop_menu_toggle_view_type_cb), vf);
switch (vf->type)
{
return frame;
}
+void vf_mark_filter_toggle(ViewFile *vf, gint mark)
+{
+ gint n = mark - 1;
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(vf->filter_check[n]),
+ !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(vf->filter_check[n])));
+}
+
ViewFile *vf_new(FileViewType type, FileData *dir_fd)
{
ViewFile *vf;
vf->type = type;
vf->sort_method = SORT_NAME;
vf->sort_ascend = TRUE;
- vf->refresh_idle_id = -1;
vf->scrolled = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(vf->scrolled), GTK_SHADOW_IN);
}
}
+
+static gboolean vf_thumb_next(ViewFile *vf);
+
+static gdouble vf_thumb_progress(ViewFile *vf)
+{
+ gint count = 0;
+ gint done = 0;
+
+ switch (vf->type)
+ {
+ case FILEVIEW_LIST: vflist_thumb_progress_count(vf->list, &count, &done); break;
+ case FILEVIEW_ICON: vficon_thumb_progress_count(vf->list, &count, &done); break;
+ }
+
+ DEBUG_1("thumb progress: %d of %d", done, count);
+ return (gdouble)done / count;
+}
+
+static void vf_set_thumb_fd(ViewFile *vf, FileData *fd)
+{
+ switch (vf->type)
+ {
+ case FILEVIEW_LIST: vflist_set_thumb_fd(vf, fd); break;
+ case FILEVIEW_ICON: vficon_set_thumb_fd(vf, fd); break;
+ }
+}
+
+static void vf_thumb_status(ViewFile *vf, gdouble val, const gchar *text)
+{
+ if (vf->func_thumb_status)
+ {
+ vf->func_thumb_status(vf, val, text, vf->data_thumb_status);
+ }
+}
+
+static void vf_thumb_do(ViewFile *vf, FileData *fd)
+{
+ if (!fd) return;
+
+ vf_set_thumb_fd(vf, fd);
+ vf_thumb_status(vf, vf_thumb_progress(vf), _("Loading thumbs..."));
+}
+
+void vf_thumb_cleanup(ViewFile *vf)
+{
+ vf_thumb_status(vf, 0.0, NULL);
+
+ vf->thumbs_running = FALSE;
+
+ thumb_loader_free(vf->thumbs_loader);
+ vf->thumbs_loader = NULL;
+
+ vf->thumbs_filedata = NULL;
+}
+
+void vf_thumb_stop(ViewFile *vf)
+{
+ if (vf->thumbs_running) vf_thumb_cleanup(vf);
+}
+
+static void vf_thumb_common_cb(ThumbLoader *tl, gpointer data)
+{
+ ViewFile *vf = data;
+
+ if (vf->thumbs_filedata && vf->thumbs_loader == tl)
+ {
+ vf_thumb_do(vf, vf->thumbs_filedata);
+ }
+
+ while (vf_thumb_next(vf));
+}
+
+static void vf_thumb_error_cb(ThumbLoader *tl, gpointer data)
+{
+ vf_thumb_common_cb(tl, data);
+}
+
+static void vf_thumb_done_cb(ThumbLoader *tl, gpointer data)
+{
+ vf_thumb_common_cb(tl, data);
+}
+
+static gboolean vf_thumb_next(ViewFile *vf)
+{
+ FileData *fd = NULL;
+
+ if (!gtk_widget_get_realized(vf->listview))
+ {
+ vf_thumb_status(vf, 0.0, NULL);
+ return FALSE;
+ }
+
+ switch (vf->type)
+ {
+ case FILEVIEW_LIST: fd = vflist_thumb_next_fd(vf); break;
+ case FILEVIEW_ICON: fd = vficon_thumb_next_fd(vf); break;
+ }
+
+ if (!fd)
+ {
+ /* done */
+ vf_thumb_cleanup(vf);
+ return FALSE;
+ }
+
+ vf->thumbs_filedata = fd;
+
+ thumb_loader_free(vf->thumbs_loader);
+
+ vf->thumbs_loader = thumb_loader_new(options->thumbnails.max_width, options->thumbnails.max_height);
+ thumb_loader_set_callbacks(vf->thumbs_loader,
+ vf_thumb_done_cb,
+ vf_thumb_error_cb,
+ NULL,
+ vf);
+
+ if (!thumb_loader_start(vf->thumbs_loader, fd))
+ {
+ /* set icon to unknown, continue */
+ DEBUG_1("thumb loader start failed %s", fd->path);
+ vf_thumb_do(vf, fd);
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void vf_thumb_reset_all(ViewFile *vf)
+{
+ switch (vf->type)
+ {
+ case FILEVIEW_LIST: vflist_thumb_reset_all(vf); break;
+ case FILEVIEW_ICON: vficon_thumb_reset_all(vf); break;
+ }
+}
+
+void vf_thumb_update(ViewFile *vf)
+{
+ vf_thumb_stop(vf);
+
+ if (vf->type == FILEVIEW_LIST && !VFLIST(vf)->thumbs_enabled) return;
+
+ vf_thumb_status(vf, 0.0, _("Loading thumbs..."));
+ vf->thumbs_running = TRUE;
+
+ if (thumb_format_changed)
+ {
+ vf_thumb_reset_all(vf);
+ thumb_format_changed = FALSE;
+ }
+
+ while (vf_thumb_next(vf));
+}
+
+
void vf_marks_set(ViewFile *vf, gboolean enable)
{
if (vf->marks_enabled == enable) return;
ViewFile *vf = data;
vf_refresh(vf);
- vf->refresh_idle_id = -1;
+ vf->refresh_idle_id = 0;
return FALSE;
}
void vf_refresh_idle_cancel(ViewFile *vf)
{
- if (vf->refresh_idle_id != -1) g_source_remove(vf->refresh_idle_id);
- vf->refresh_idle_id = -1;
+ if (vf->refresh_idle_id)
+ {
+ g_source_remove(vf->refresh_idle_id);
+ vf->refresh_idle_id = 0;
+ }
}
void vf_refresh_idle(ViewFile *vf)
{
- if (vf->refresh_idle_id == -1)
+ if (!vf->refresh_idle_id)
+ {
+ vf->time_refresh_set = time(NULL);
+ /* file operations run with G_PRIORITY_DEFAULT_IDLE */
+ vf->refresh_idle_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE + 50, vf_refresh_idle_cb, vf, NULL);
+ }
+ else if (time(NULL) - vf->time_refresh_set > 1)
{
- vf->refresh_idle_id = g_idle_add(vf_refresh_idle_cb, vf);
+ /* more than 1 sec since last update - increase priority */
+ vf_refresh_idle_cancel(vf);
+ vf->time_refresh_set = time(NULL);
+ vf->refresh_idle_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE - 50, vf_refresh_idle_cb, vf, NULL);
}
}
if (vf->marks_enabled) interested |= NOTIFY_MARKS | NOTIFY_METADATA;
/* FIXME: NOTIFY_METADATA should be checked by the keyword-to-mark functions and converted to NOTIFY_MARKS only if there was a change */
- if (!(type & interested) || vf->refresh_idle_id != -1 || !vf->dir_fd) return;
+ if (!(type & interested) || vf->refresh_idle_id || !vf->dir_fd) return;
refresh = (fd == vf->dir_fd);