Commit 9db919eec90ef7b120cb04bb8231bc290255cb54
1 parent
1bc88320
Exists in
master
and in
4 other branches
Fixing file transfer action state.
Showing
3 changed files
with
69 additions
and
5 deletions
Show diff stats
src/include/pw3270/actions.h
| @@ -132,6 +132,12 @@ | @@ -132,6 +132,12 @@ | ||
| 132 | const gchar * label; | 132 | const gchar * label; |
| 133 | const gchar * tooltip; | 133 | const gchar * tooltip; |
| 134 | 134 | ||
| 135 | + // Lib3270 Action group | ||
| 136 | + struct { | ||
| 137 | + LIB3270_ACTION_GROUP id; | ||
| 138 | + const void * listener; | ||
| 139 | + } group; | ||
| 140 | + | ||
| 135 | /// @brief Activation method. | 141 | /// @brief Activation method. |
| 136 | void (*activate)(GAction *action, GVariant *parameter, GtkWidget *terminal); | 142 | void (*activate)(GAction *action, GVariant *parameter, GtkWidget *terminal); |
| 137 | 143 |
src/objects/actions/simple.c
| @@ -33,20 +33,25 @@ | @@ -33,20 +33,25 @@ | ||
| 33 | */ | 33 | */ |
| 34 | 34 | ||
| 35 | #include "private.h" | 35 | #include "private.h" |
| 36 | + #include <v3270.h> | ||
| 36 | 37 | ||
| 37 | static void pw3270SimpleAction_class_init(pw3270SimpleActionClass *klass); | 38 | static void pw3270SimpleAction_class_init(pw3270SimpleActionClass *klass); |
| 38 | static void pw3270SimpleAction_init(pw3270SimpleAction *action); | 39 | static void pw3270SimpleAction_init(pw3270SimpleAction *action); |
| 40 | + static void change_widget(GAction *object, GtkWidget *from, GtkWidget *to); | ||
| 39 | 41 | ||
| 40 | G_DEFINE_TYPE(pw3270SimpleAction, pw3270SimpleAction, PW3270_TYPE_ACTION); | 42 | G_DEFINE_TYPE(pw3270SimpleAction, pw3270SimpleAction, PW3270_TYPE_ACTION); |
| 41 | 43 | ||
| 42 | - static void activate(GAction G_GNUC_UNUSED(*action), GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal) { | ||
| 43 | - | 44 | + static void activate(GAction G_GNUC_UNUSED(*action), GVariant G_GNUC_UNUSED(*parameter), GtkWidget G_GNUC_UNUSED(*terminal)) { |
| 44 | debug("%s",__FUNCTION__); | 45 | debug("%s",__FUNCTION__); |
| 45 | - | ||
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | static gboolean get_enabled(GAction *action, GtkWidget *terminal) { | 48 | static gboolean get_enabled(GAction *action, GtkWidget *terminal) { |
| 49 | - return TRUE; | 49 | + |
| 50 | + if(terminal) { | ||
| 51 | + return lib3270_action_group_get_activatable(v3270_get_session(terminal),PW3270_SIMPLE_ACTION(action)->group.id); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + return FALSE; | ||
| 50 | } | 55 | } |
| 51 | 56 | ||
| 52 | static const gchar * get_icon_name(GAction *action) { | 57 | static const gchar * get_icon_name(GAction *action) { |
| @@ -61,14 +66,27 @@ | @@ -61,14 +66,27 @@ | ||
| 61 | return PW3270_SIMPLE_ACTION(action)->tooltip; | 66 | return PW3270_SIMPLE_ACTION(action)->tooltip; |
| 62 | } | 67 | } |
| 63 | 68 | ||
| 69 | + static void dispose(GObject *object) { | ||
| 70 | + | ||
| 71 | + pw3270SimpleAction *action = PW3270_SIMPLE_ACTION(object); | ||
| 72 | + | ||
| 73 | + if(action->group.listener) { | ||
| 74 | + lib3270_unregister_action_group_listener(pw3270_action_get_session(G_ACTION(object)),action->group.id,action->group.listener); | ||
| 75 | + action->group.listener = NULL; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + G_OBJECT_CLASS(pw3270SimpleAction_parent_class)->dispose(object); | ||
| 79 | + } | ||
| 80 | + | ||
| 64 | static void pw3270SimpleAction_class_init(pw3270SimpleActionClass *klass) { | 81 | static void pw3270SimpleAction_class_init(pw3270SimpleActionClass *klass) { |
| 65 | 82 | ||
| 66 | klass->parent_class.get_icon_name = get_icon_name; | 83 | klass->parent_class.get_icon_name = get_icon_name; |
| 67 | klass->parent_class.get_label = get_label; | 84 | klass->parent_class.get_label = get_label; |
| 68 | klass->parent_class.get_tooltip = get_tooltip; | 85 | klass->parent_class.get_tooltip = get_tooltip; |
| 69 | klass->parent_class.get_enabled = get_enabled; | 86 | klass->parent_class.get_enabled = get_enabled; |
| 87 | + klass->parent_class.change_widget = change_widget; | ||
| 70 | 88 | ||
| 71 | - debug("%s:%p",__FUNCTION__,klass->parent_class.get_icon_name); | 89 | + G_OBJECT_CLASS(klass)->dispose = dispose; |
| 72 | 90 | ||
| 73 | } | 91 | } |
| 74 | 92 | ||
| @@ -78,6 +96,9 @@ | @@ -78,6 +96,9 @@ | ||
| 78 | action->label = N_( "No label" ); | 96 | action->label = N_( "No label" ); |
| 79 | action->tooltip = NULL; | 97 | action->tooltip = NULL; |
| 80 | 98 | ||
| 99 | + action->group.id = LIB3270_ACTION_GROUP_NONE; | ||
| 100 | + action->group.listener = NULL; | ||
| 101 | + | ||
| 81 | } | 102 | } |
| 82 | 103 | ||
| 83 | pw3270SimpleAction * pw3270_simple_action_new_from_lib3270(const LIB3270_ACTION * definition, const gchar *name) { | 104 | pw3270SimpleAction * pw3270_simple_action_new_from_lib3270(const LIB3270_ACTION * definition, const gchar *name) { |
| @@ -107,3 +128,39 @@ | @@ -107,3 +128,39 @@ | ||
| 107 | return (pw3270SimpleAction *) g_object_new(PW3270_TYPE_SIMPLE_ACTION, NULL); | 128 | return (pw3270SimpleAction *) g_object_new(PW3270_TYPE_SIMPLE_ACTION, NULL); |
| 108 | } | 129 | } |
| 109 | 130 | ||
| 131 | + static gboolean bg_notify_enabled(GAction *action) { | ||
| 132 | + pw3270_action_notify_enabled(action); | ||
| 133 | + return FALSE; | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + static void event_listener(H3270 G_GNUC_UNUSED(*hSession), void *object) { | ||
| 137 | + g_idle_add((GSourceFunc) bg_notify_enabled, G_ACTION(object)); | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + void change_widget(GAction *object, GtkWidget *from, GtkWidget *to) { | ||
| 141 | + | ||
| 142 | + // Remove old listener | ||
| 143 | + pw3270SimpleAction * action = PW3270_SIMPLE_ACTION(object); | ||
| 144 | + | ||
| 145 | + if(action->group.listener) { | ||
| 146 | + lib3270_unregister_action_group_listener(pw3270_action_get_session(object),action->group.id,action->group.listener); | ||
| 147 | + action->group.listener = NULL; | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + // Get the current "enabled" state | ||
| 151 | + gboolean enabled = g_action_get_enabled(object); | ||
| 152 | + | ||
| 153 | + // Change widget | ||
| 154 | + PW3270_ACTION_CLASS(pw3270SimpleAction_parent_class)->change_widget(object,from,to); | ||
| 155 | + | ||
| 156 | + // Setup new listener | ||
| 157 | + if(action->group.id != LIB3270_ACTION_GROUP_NONE && to) { | ||
| 158 | + action->group.listener = lib3270_register_action_group_listener(pw3270_action_get_session(object),action->group.id,event_listener,object); | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + // Does the "enabled" state has changed? If yes notify customers. | ||
| 162 | + if(g_action_get_enabled(object) != enabled) | ||
| 163 | + pw3270_action_notify_enabled(object); | ||
| 164 | + | ||
| 165 | + } | ||
| 166 | + |
src/objects/window/actions/filetransfer.c
| @@ -39,6 +39,7 @@ | @@ -39,6 +39,7 @@ | ||
| 39 | pw3270SimpleAction * action = pw3270_simple_action_new(); | 39 | pw3270SimpleAction * action = pw3270_simple_action_new(); |
| 40 | 40 | ||
| 41 | action->parent.activate = activate; | 41 | action->parent.activate = activate; |
| 42 | + action->group.id = LIB3270_ACTION_GROUP_ONLINE; | ||
| 42 | action->parent.name = "file.transfer"; | 43 | action->parent.name = "file.transfer"; |
| 43 | action->icon_name = "drive-harddisk"; | 44 | action->icon_name = "drive-harddisk"; |
| 44 | action->label = N_("Send/Receive"); | 45 | action->label = N_("Send/Receive"); |