Mercurial > geeqie
changeset 784:16b3a5c8aedc
new notification system (used only in vflist for now)
author | nadvornik |
---|---|
date | Wed, 04 Jun 2008 21:12:47 +0000 |
parents | d6a7fb4b8e7c |
children | 548b193c084c |
files | src/filedata.c src/filedata.h src/utilops.c src/view_file.c src/view_file_list.c src/view_file_list.h |
diffstat | 6 files changed, 99 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/src/filedata.c Tue Jun 03 19:44:19 2008 +0000 +++ b/src/filedata.c Wed Jun 04 21:12:47 2008 +0000 @@ -140,6 +140,8 @@ { fd->version++; if (fd->parent) fd->parent->version++; + + file_data_send_notification(fd); /* FIXME there are probably situations when we don't want to call this */ } @@ -1390,8 +1392,69 @@ FIXME do we need the ignore_list? It looks like a workaround for ineffective implementation in view_file_list.c */ + + + +typedef struct _NotifyData NotifyData; + +struct _NotifyData { + FileDataNotifyFunc func; + gpointer data; + }; + +static GList *notify_func_list = NULL; + +gint file_data_register_notify_func(FileDataNotifyFunc func, gpointer data) +{ + NotifyData *nd = g_new(NotifyData, 1); + nd->func = func; + nd->data = data; + notify_func_list = g_list_prepend(notify_func_list, nd); + DEBUG_1("Notify func registered: %p\n", nd); + return TRUE; +} + +gint file_data_unregister_notify_func(FileDataNotifyFunc func, gpointer data) +{ + GList *work = notify_func_list; + + while(work) + { + NotifyData *nd = (NotifyData *)work->data; + if (nd->func == func && nd->data == data) + { + notify_func_list = g_list_delete_link(notify_func_list, work); + g_free(nd); + DEBUG_1("Notify func unregistered: %p\n", nd); + return TRUE; + } + work = work->next; + } + return FALSE; +} + + +void file_data_send_notification(FileData *fd) +{ + GList *work = notify_func_list; + while(work) + { + NotifyData *nd = (NotifyData *)work->data; + DEBUG_1("Notify func calling: %p %s\n", nd, fd->path); + nd->func(fd, nd->data); + work = work->next; + } +} + void file_data_sc_send_notification(FileData *fd) { } + + + + + + +
--- a/src/filedata.h Tue Jun 03 19:44:19 2008 +0000 +++ b/src/filedata.h Wed Jun 04 21:12:47 2008 +0000 @@ -77,4 +77,8 @@ void file_data_sc_free_ci(FileData *fd); void file_data_sc_free_ci_list(GList *fd_list); +typedef void (*FileDataNotifyFunc)(FileData *fd, gpointer data); +gint file_data_register_notify_func(FileDataNotifyFunc func, gpointer data); +gint file_data_unregister_notify_func(FileDataNotifyFunc func, gpointer data); +void file_data_send_notification(FileData *fd); #endif
--- a/src/utilops.c Tue Jun 03 19:44:19 2008 +0000 +++ b/src/utilops.c Wed Jun 04 21:12:47 2008 +0000 @@ -276,6 +276,10 @@ /* FIXME */ break; } + + + /* this is the new way: */ + file_data_send_notification(fd); } void file_data_sc_notify_ci(FileData *fd)
--- a/src/view_file.c Tue Jun 03 19:44:19 2008 +0000 +++ b/src/view_file.c Wed Jun 04 21:12:47 2008 +0000 @@ -754,7 +754,7 @@ switch(vf->type) { - case FILEVIEW_LIST: ret = vflist_maint_renamed(vf, fd); break; +// case FILEVIEW_LIST: ret = vflist_maint_renamed(vf, fd); break; case FILEVIEW_ICON: ret = vficon_maint_renamed(vf, fd); break; } @@ -767,7 +767,7 @@ switch(vf->type) { - case FILEVIEW_LIST: ret = vflist_maint_removed(vf, fd, ignore_list); break; +// case FILEVIEW_LIST: ret = vflist_maint_removed(vf, fd, ignore_list); break; case FILEVIEW_ICON: ret = vficon_maint_removed(vf, fd, ignore_list); break; } @@ -780,7 +780,7 @@ switch(vf->type) { - case FILEVIEW_LIST: ret = vflist_maint_moved(vf, fd, ignore_list); break; +// case FILEVIEW_LIST: ret = vflist_maint_moved(vf, fd, ignore_list); break; case FILEVIEW_ICON: ret = vficon_maint_moved(vf, fd, ignore_list); break; }
--- a/src/view_file_list.c Tue Jun 03 19:44:19 2008 +0000 +++ b/src/view_file_list.c Wed Jun 04 21:12:47 2008 +0000 @@ -50,6 +50,7 @@ static gint vflist_row_is_selected(ViewFile *vf, FileData *fd); static gint vflist_row_rename_cb(TreeEditData *td, const gchar *old, const gchar *new, gpointer data); static void vflist_populate_view(ViewFile *vf); +static void vflist_notify_cb(FileData *fd, gpointer data); /* @@ -1460,7 +1461,9 @@ break; } + file_data_unregister_notify_func(vflist_notify_cb, vf); /* we don't need the notification */ file_data_increment_version(fd); + file_data_register_notify_func(vflist_notify_cb, vf); gtk_tree_store_set(GTK_TREE_STORE(store), &iter, FILE_COLUMN_MARKS + n, fd->marks[n], -1); @@ -1563,8 +1566,12 @@ DEBUG_1("%s vflist_refresh: read dir", get_exec_time()); if (vf->dir_fd) { + file_data_unregister_notify_func(vflist_notify_cb, vf); /* we don't need the notification of changes detected by filelist_read */ + ret = filelist_read(vf->dir_fd, &vf->list, NULL); + file_data_register_notify_func(vflist_notify_cb, vf); + DEBUG_1("%s vflist_refresh: sort", get_exec_time()); vf->list = filelist_sort(vf->list, vf->sort_method, vf->sort_ascend); } @@ -1681,14 +1688,17 @@ gtk_tree_view_append_column(GTK_TREE_VIEW(vf->listview), column); } -static void vflist_listview_mark_toggled(GtkCellRendererToggle *cell, gchar *path_str, GtkTreeStore *store) +static void vflist_listview_mark_toggled_cb(GtkCellRendererToggle *cell, gchar *path_str, gpointer data) { + ViewFile *vf = data; + GtkTreeStore *store; GtkTreePath *path = gtk_tree_path_new_from_string(path_str); GtkTreeIter iter; FileData *fd; gboolean mark; guint col_idx; + store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview))); if (!path || !gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path)) return; @@ -1699,7 +1709,9 @@ gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, FILE_COLUMN_POINTER, &fd, col_idx, &mark, -1); mark = !mark; fd->marks[col_idx - FILE_COLUMN_MARKS] = mark; + file_data_unregister_notify_func(vflist_notify_cb, vf); /* we don't need the notification */ file_data_increment_version(fd); + file_data_register_notify_func(vflist_notify_cb, vf); gtk_tree_store_set(store, &iter, col_idx, mark, -1); gtk_tree_path_free(path); @@ -1726,7 +1738,7 @@ gtk_tree_view_column_set_visible(column, vf->marks_enabled); - g_signal_connect(G_OBJECT(renderer), "toggled", G_CALLBACK(vflist_listview_mark_toggled), store); + g_signal_connect(G_OBJECT(renderer), "toggled", G_CALLBACK(vflist_listview_mark_toggled_cb), vf); } /* @@ -1759,6 +1771,8 @@ { ViewFile *vf = data; + file_data_unregister_notify_func(vflist_notify_cb, vf); + vflist_select_idle_cancel(vf); vflist_refresh_idle_cancel(vf); vflist_thumb_stop(vf); @@ -1818,6 +1832,7 @@ vflist_listview_add_column(vf, FILE_COLUMN_SIZE, _("Size"), FALSE, TRUE, FALSE); vflist_listview_add_column(vf, FILE_COLUMN_DATE, _("Date"), FALSE, TRUE, FALSE); + file_data_register_notify_func(vflist_notify_cb, vf); return vf; } @@ -1860,29 +1875,30 @@ *----------------------------------------------------------------------------- */ -void vflist_maint(ViewFile *vf, FileData *fd) +static void vflist_notify_cb(FileData *fd, gpointer data) { + ViewFile *vf = data; gboolean refresh; if (vf->refresh_idle_id != -1) return; refresh = (fd == vf->dir_fd); - if (!refresh && fd->change->dest) + if (!refresh) { gchar *base = remove_level_from_path(fd->path); refresh = (strcmp(base, vf->dir_fd->path) == 0); g_free(base); } - if (!refresh && fd->change->dest) + if (!refresh && fd->change && fd->change->dest) { gchar *dest_base = remove_level_from_path(fd->change->dest); refresh = (strcmp(dest_base, vf->dir_fd->path) == 0); g_free(dest_base); } - if (!refresh && fd->change->source) + if (!refresh && fd->change && fd->change->source) { gchar *source_base = remove_level_from_path(fd->change->source); refresh = (strcmp(source_base, vf->dir_fd->path) == 0); @@ -1895,7 +1911,7 @@ } } -/* the plan is to drop these functions and use vflist_maint directly */ +#if 0 gint vflist_maint_renamed(ViewFile *vf, FileData *fd) { @@ -1914,7 +1930,6 @@ } -#if 0 static gint vflist_maint_find_closest(ViewFile *vf, gint row, gint count, GList *ignore_list) { GList *list = NULL;
--- a/src/view_file_list.h Tue Jun 03 19:44:19 2008 +0000 +++ b/src/view_file_list.h Wed Jun 04 21:12:47 2008 +0000 @@ -60,9 +60,11 @@ void vflist_select_marked(ViewFile *vf, gint mark); void vflist_mark_selected(ViewFile *vf, gint mark, gint value); +/* gint vflist_maint_renamed(ViewFile *vf, FileData *fd); gint vflist_maint_removed(ViewFile *vf, FileData *fd, GList *ignore_list); gint vflist_maint_moved(ViewFile *vf, FileData *fd, GList *ignore_list); +*/ void vflist_color_set(ViewFile *vf, FileData *fd, gint color_set);