From 9db919eec90ef7b120cb04bb8231bc290255cb54 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 30 Oct 2019 17:26:04 -0300 Subject: [PATCH] Fixing file transfer action state. --- src/include/pw3270/actions.h | 6 ++++++ src/objects/actions/simple.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- src/objects/window/actions/filetransfer.c | 1 + 3 files changed, 69 insertions(+), 5 deletions(-) diff --git a/src/include/pw3270/actions.h b/src/include/pw3270/actions.h index 6aac43e..1ad06f7 100644 --- a/src/include/pw3270/actions.h +++ b/src/include/pw3270/actions.h @@ -132,6 +132,12 @@ const gchar * label; const gchar * tooltip; + // Lib3270 Action group + struct { + LIB3270_ACTION_GROUP id; + const void * listener; + } group; + /// @brief Activation method. void (*activate)(GAction *action, GVariant *parameter, GtkWidget *terminal); diff --git a/src/objects/actions/simple.c b/src/objects/actions/simple.c index e024de5..0cb6d30 100644 --- a/src/objects/actions/simple.c +++ b/src/objects/actions/simple.c @@ -33,20 +33,25 @@ */ #include "private.h" + #include static void pw3270SimpleAction_class_init(pw3270SimpleActionClass *klass); static void pw3270SimpleAction_init(pw3270SimpleAction *action); + static void change_widget(GAction *object, GtkWidget *from, GtkWidget *to); G_DEFINE_TYPE(pw3270SimpleAction, pw3270SimpleAction, PW3270_TYPE_ACTION); - static void activate(GAction G_GNUC_UNUSED(*action), GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal) { - + static void activate(GAction G_GNUC_UNUSED(*action), GVariant G_GNUC_UNUSED(*parameter), GtkWidget G_GNUC_UNUSED(*terminal)) { debug("%s",__FUNCTION__); - } static gboolean get_enabled(GAction *action, GtkWidget *terminal) { - return TRUE; + + if(terminal) { + return lib3270_action_group_get_activatable(v3270_get_session(terminal),PW3270_SIMPLE_ACTION(action)->group.id); + } + + return FALSE; } static const gchar * get_icon_name(GAction *action) { @@ -61,14 +66,27 @@ return PW3270_SIMPLE_ACTION(action)->tooltip; } + static void dispose(GObject *object) { + + pw3270SimpleAction *action = PW3270_SIMPLE_ACTION(object); + + if(action->group.listener) { + lib3270_unregister_action_group_listener(pw3270_action_get_session(G_ACTION(object)),action->group.id,action->group.listener); + action->group.listener = NULL; + } + + G_OBJECT_CLASS(pw3270SimpleAction_parent_class)->dispose(object); + } + static void pw3270SimpleAction_class_init(pw3270SimpleActionClass *klass) { klass->parent_class.get_icon_name = get_icon_name; klass->parent_class.get_label = get_label; klass->parent_class.get_tooltip = get_tooltip; klass->parent_class.get_enabled = get_enabled; + klass->parent_class.change_widget = change_widget; - debug("%s:%p",__FUNCTION__,klass->parent_class.get_icon_name); + G_OBJECT_CLASS(klass)->dispose = dispose; } @@ -78,6 +96,9 @@ action->label = N_( "No label" ); action->tooltip = NULL; + action->group.id = LIB3270_ACTION_GROUP_NONE; + action->group.listener = NULL; + } pw3270SimpleAction * pw3270_simple_action_new_from_lib3270(const LIB3270_ACTION * definition, const gchar *name) { @@ -107,3 +128,39 @@ return (pw3270SimpleAction *) g_object_new(PW3270_TYPE_SIMPLE_ACTION, NULL); } + static gboolean bg_notify_enabled(GAction *action) { + pw3270_action_notify_enabled(action); + return FALSE; + } + + static void event_listener(H3270 G_GNUC_UNUSED(*hSession), void *object) { + g_idle_add((GSourceFunc) bg_notify_enabled, G_ACTION(object)); + } + + void change_widget(GAction *object, GtkWidget *from, GtkWidget *to) { + + // Remove old listener + pw3270SimpleAction * action = PW3270_SIMPLE_ACTION(object); + + if(action->group.listener) { + lib3270_unregister_action_group_listener(pw3270_action_get_session(object),action->group.id,action->group.listener); + action->group.listener = NULL; + } + + // Get the current "enabled" state + gboolean enabled = g_action_get_enabled(object); + + // Change widget + PW3270_ACTION_CLASS(pw3270SimpleAction_parent_class)->change_widget(object,from,to); + + // Setup new listener + if(action->group.id != LIB3270_ACTION_GROUP_NONE && to) { + action->group.listener = lib3270_register_action_group_listener(pw3270_action_get_session(object),action->group.id,event_listener,object); + } + + // Does the "enabled" state has changed? If yes notify customers. + if(g_action_get_enabled(object) != enabled) + pw3270_action_notify_enabled(object); + + } + diff --git a/src/objects/window/actions/filetransfer.c b/src/objects/window/actions/filetransfer.c index 95183bb..30c24c5 100644 --- a/src/objects/window/actions/filetransfer.c +++ b/src/objects/window/actions/filetransfer.c @@ -39,6 +39,7 @@ pw3270SimpleAction * action = pw3270_simple_action_new(); action->parent.activate = activate; + action->group.id = LIB3270_ACTION_GROUP_ONLINE; action->parent.name = "file.transfer"; action->icon_name = "drive-harddisk"; action->label = N_("Send/Receive"); -- libgit2 0.21.2