From 4005b7924e255d60f5fe43ad6c16a083a7b7145f Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Tue, 15 Feb 2011 16:41:22 +0200 Subject: [PATCH] Use events to check timestamp of panel directories ...instead of direct access to panels in VGS GC. Inlcudes clean up. Signed-off-by: Andrew Borodin Signed-off-by: Slava Zanko --- lib/event-types.h | 12 ++++++ lib/vfs/gc.c | 59 +++++++-------------------- src/filemanager/midnight.c | 81 +++++++++++++++++++++++++++++++++----- 3 files changed, 99 insertions(+), 53 deletions(-) diff --git a/lib/event-types.h b/lib/event-types.h index 2eb40113d..1686c11d8 100644 --- a/lib/event-types.h +++ b/lib/event-types.h @@ -1,6 +1,8 @@ #ifndef MC__EVENT_TYPES_H #define MC__EVENT_TYPES_H +#include + /*** typedefs(not structures) and defined constants **********************************************/ /* Event groups for main modules */ @@ -14,6 +16,16 @@ /*** structures declarations (and typedefs of structures)*****************************************/ + +/* MCEVENT_GROUP_CORE:vfs_timestamp */ +struct vfs_class; +typedef struct +{ + struct vfs_class *vclass; + gpointer id; + gboolean ret; +} ev_vfs_stamp_create_t; + /*** global variables defined in .c file *********************************************************/ /*** declarations of public functions ************************************************************/ diff --git a/lib/vfs/gc.c b/lib/vfs/gc.c index c412de820..abb2e4a95 100644 --- a/lib/vfs/gc.c +++ b/lib/vfs/gc.c @@ -33,18 +33,12 @@ #include -#include #include /* For atol() */ -#include -#include -#include #include -#include /* is_digit() */ #include /* gettimeofday() */ #include "lib/global.h" - -#include "src/filemanager/midnight.h" /* current_panel */ +#include "lib/event.h" #include "vfs.h" #include "utilvfs.h" @@ -173,58 +167,35 @@ vfs_stamp_path (const char *path) */ void -vfs_stamp_create (struct vfs_class *oldvfs, vfsid oldvfsid) +vfs_stamp_create (struct vfs_class *vclass, vfsid id) { - struct vfs_class *nvfs, *n2vfs, *n3vfs; - vfsid nvfsid, n2vfsid, n3vfsid; + struct vfs_class *nvfs; + vfsid nvfsid; + + ev_vfs_stamp_create_t event_data = { vclass, id, FALSE }; /* There are three directories we have to take care of: current_dir, current_panel->cwd and other_panel->cwd. Athough most of the time either current_dir and current_panel->cwd or current_dir and other_panel->cwd are the same, it's possible that all three are different -- Norbert */ - if (current_panel == NULL) + if (!mc_event_present (MCEVENT_GROUP_CORE, "vfs_timestamp")) return; nvfs = vfs_get_class (vfs_get_current_dir ()); nvfsid = vfs_getid (nvfs, vfs_get_current_dir ()); vfs_rmstamp (nvfs, nvfsid); - if ((nvfs == oldvfs && nvfsid == oldvfsid) || oldvfsid == NULL) - { - return; - } - - if (get_current_type () == view_listing) - { - n2vfs = vfs_get_class (current_panel->cwd); - n2vfsid = vfs_getid (n2vfs, current_panel->cwd); - if (n2vfs == oldvfs && n2vfsid == oldvfsid) - return; - } - else - { - n2vfs = NULL; - n2vfsid = NULL; - } - - if (get_other_type () == view_listing) - { - n3vfs = vfs_get_class (other_panel->cwd); - n3vfsid = vfs_getid (n3vfs, other_panel->cwd); - if (n3vfs == oldvfs && n3vfsid == oldvfsid) - return; - } - else - { - n3vfs = NULL; - n3vfsid = NULL; - } - - if (!oldvfs || !oldvfs->nothingisopen || !(*oldvfs->nothingisopen) (oldvfsid)) + if (id == NULL || (nvfs == vclass && nvfsid == id)) return; - vfs_addstamp (oldvfs, oldvfsid); + mc_event_raise (MCEVENT_GROUP_CORE, "vfs_timestamp", (gpointer) &event_data); + + if (event_data.ret) + return; + + if (vclass != NULL && vclass->nothingisopen != NULL && vclass->nothingisopen (id) != 0) + vfs_addstamp (vclass, id); } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/filemanager/midnight.c b/src/filemanager/midnight.c index 5c4323f7f..3ae6a9365 100644 --- a/src/filemanager/midnight.c +++ b/src/filemanager/midnight.c @@ -57,6 +57,8 @@ #include "src/learn.h" /* learn_keys() */ #include "src/execute.h" /* suspend_cmd() */ #include "src/keybind-defaults.h" +#include "lib/keybind.h" +#include "lib/event.h" #include "option.h" /* configure_box() */ #include "tree.h" @@ -66,7 +68,6 @@ #include "hotlist.h" #include "panelize.h" #include "command.h" /* cmdline */ -#include "lib/keybind.h" #include "chmod.h" #include "chown.h" @@ -487,6 +488,66 @@ translated_mc_chdir (char *dir) /* --------------------------------------------------------------------------------------------- */ +#if ENABLE_VFS + +/* event helper */ +static gboolean +check_panel_timestamp (WPanel * panel, panel_view_mode_t mode, struct vfs_class *vclass, vfsid id) +{ + if (mode == view_listing) + { + struct vfs_class *nvfs; + vfsid nvfsid; + nvfs = vfs_get_class (panel->cwd); + if (nvfs != vclass) + return FALSE; + nvfsid = vfs_getid (nvfs, panel->cwd); + if (nvfsid == id) + return TRUE; + } + return TRUE; +} + +/* --------------------------------------------------------------------------------------------- */ + +/* event callback */ +static gboolean +check_current_panel_timestamp (const gchar * event_group_name, const gchar * event_name, + gpointer init_data, gpointer data) +{ + ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data; + + (void) event_group_name; + (void) event_name; + (void) init_data; + + event_data->ret = + check_panel_timestamp (current_panel, get_current_type (), event_data->vclass, + event_data->id); + return !event_data->ret; +} + +/* --------------------------------------------------------------------------------------------- */ + +/* event callback */ +static gboolean +check_other_panel_timestamp (const gchar * event_group_name, const gchar * event_name, + gpointer init_data, gpointer data) +{ + ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data; + + (void) event_group_name; + (void) event_name; + (void) init_data; + + event_data->ret = + check_panel_timestamp (other_panel, get_other_type (), event_data->vclass, event_data->id); + return !event_data->ret; +} +#endif /* ENABLE_VFS */ + +/* --------------------------------------------------------------------------------------------- */ + static void create_panels (void) { @@ -534,16 +595,18 @@ create_panels (void) set_display_type (other_index, other_mode); if (startup_left_mode == view_listing) - { current_panel = left_panel; - } + else if (right_panel != NULL) + current_panel = right_panel; else - { - if (right_panel) - current_panel = right_panel; - else - current_panel = left_panel; - } + current_panel = left_panel; + +#if ENABLE_VFS + mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_other_panel_timestamp, NULL, + NULL); + mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_current_panel_timestamp, NULL, + NULL); +#endif /* ENABLE_VFS */ /* Create the nice widgets */ cmdline = command_new (0, 0, 0);