Commit a73ec3ca04c81076c1c63e58e641e449a9efebca
1 parent
925b3ce9
Exists in
master
and in
5 other branches
Iniciando implementação de alteração pedida no forum do projeto.
Em: 2014-07-03 11:22:17.300246-03 De: rogermachine@gmail.com É possível adicionar um sub-menu em Configurações/Opções/SessionCloseTime na versão do PW3270 (para linux e windows)? Na versão 2.6 do PW3270 para windows existe esta opção. Gostaria de colocar esta opção nas novas versões. Esta opção expira a seção ociosa, por exemplo se em 10 minutos o usuário não utilizar o terminal ele fecha a sessão, liberando a porta para outro usuário. Se alguém puder ajudar agradeço! Rodrigo
Showing
6 changed files
with
95 additions
and
5 deletions
Show diff stats
src/include/pw3270/v3270.h
| ... | ... | @@ -163,6 +163,10 @@ |
| 163 | 163 | |
| 164 | 164 | LIB3270_EXPORT int v3270_set_host_charset(GtkWidget *widget, const gchar *name); |
| 165 | 165 | |
| 166 | + LIB3270_EXPORT void v3270_set_auto_disconnect(GtkWidget *widget, guint minutes); | |
| 167 | + LIB3270_EXPORT guint v3270_get_auto_disconnect(GtkWidget *widget); | |
| 168 | + | |
| 169 | + | |
| 166 | 170 | // Clipboard |
| 167 | 171 | typedef enum _v3270_select_format |
| 168 | 172 | { | ... | ... |
src/pw3270/main.c
| ... | ... | @@ -55,6 +55,7 @@ |
| 55 | 55 | static GtkWidget * toplevel = NULL; |
| 56 | 56 | static GtkWidget * trace_window = NULL; |
| 57 | 57 | static unsigned int syscolors = 16; |
| 58 | + static unsigned int timer = 0; | |
| 58 | 59 | static const gchar * systype = NULL; |
| 59 | 60 | static const gchar * toggleset = NULL; |
| 60 | 61 | static const gchar * togglereset = NULL; |
| ... | ... | @@ -408,6 +409,7 @@ int main(int argc, char *argv[]) |
| 408 | 409 | { "togglereset", 'R', 0, G_OPTION_ARG_STRING, &togglereset, N_( "Set toggles OFF" ), NULL }, |
| 409 | 410 | { "charset", 'C', 0, G_OPTION_ARG_STRING, &charset, N_( "Set host charset" ), NULL }, |
| 410 | 411 | { "model", 'M', 0, G_OPTION_ARG_STRING, &model, N_( "The model of 3270 display to be emulated" ), NULL }, |
| 412 | + { "autodisconnect", 'D', 0, G_OPTION_ARG_INT, &timer, N_( "Minutes for auto-disconnect" ), 0 }, | |
| 411 | 413 | |
| 412 | 414 | #if defined( HAVE_SYSLOG ) |
| 413 | 415 | { "syslog", 'l', 0, G_OPTION_ARG_NONE, &log_to_syslog, N_( "Send messages to syslog" ), NULL }, |
| ... | ... | @@ -562,6 +564,8 @@ int main(int argc, char *argv[]) |
| 562 | 564 | if(model) |
| 563 | 565 | lib3270_set_model(pw3270_get_session(toplevel),model); |
| 564 | 566 | |
| 567 | + v3270_set_auto_disconnect(pw3270_get_terminal_widget(toplevel),timer); | |
| 568 | + | |
| 565 | 569 | pw3270_start_plugins(toplevel); |
| 566 | 570 | gtk_window_present(GTK_WINDOW(toplevel)); |
| 567 | 571 | ... | ... |
src/pw3270/v3270/keyboard.c
| ... | ... | @@ -198,6 +198,7 @@ |
| 198 | 198 | { |
| 199 | 199 | v3270 * terminal = GTK_V3270(widget); |
| 200 | 200 | |
| 201 | + terminal->activity.timestamp = time(0); | |
| 201 | 202 | update_keyboard_state(terminal,event,TRUE); |
| 202 | 203 | |
| 203 | 204 | if(gtk_im_context_filter_keypress(terminal->input_method,event)) |
| ... | ... | @@ -229,12 +230,14 @@ |
| 229 | 230 | void v3270_tab(GtkWidget *widget) |
| 230 | 231 | { |
| 231 | 232 | g_return_if_fail(GTK_IS_V3270(widget)); |
| 233 | + GTK_V3270(widget)->activity.timestamp = time(0); | |
| 232 | 234 | lib3270_nextfield(GTK_V3270(widget)->host); |
| 233 | 235 | } |
| 234 | 236 | |
| 235 | 237 | void v3270_backtab(GtkWidget *widget) |
| 236 | 238 | { |
| 237 | 239 | g_return_if_fail(GTK_IS_V3270(widget)); |
| 240 | + GTK_V3270(widget)->activity.timestamp = time(0); | |
| 238 | 241 | lib3270_previousfield(GTK_V3270(widget)->host); |
| 239 | 242 | } |
| 240 | 243 | |
| ... | ... | @@ -246,6 +249,7 @@ |
| 246 | 249 | g_return_if_fail(GTK_IS_V3270(widget)); |
| 247 | 250 | |
| 248 | 251 | host = GTK_V3270(widget)->host; |
| 252 | + GTK_V3270(widget)->activity.timestamp = time(0); | |
| 249 | 253 | |
| 250 | 254 | utf = g_convert((char *) str, -1, lib3270_get_display_charset(host), "UTF-8", NULL, NULL, NULL); |
| 251 | 255 | |
| ... | ... | @@ -264,7 +268,6 @@ |
| 264 | 268 | if(utf) |
| 265 | 269 | { |
| 266 | 270 | lib3270_input_string(GTK_V3270(widget)->host, (const unsigned char *) utf); |
| 267 | -// lib3270_set_string(GTK_V3270(widget)->host, (const unsigned char *) utf); | |
| 268 | 271 | g_free(utf); |
| 269 | 272 | } |
| 270 | 273 | else | ... | ... |
src/pw3270/v3270/private.h
| ... | ... | @@ -199,6 +199,14 @@ G_BEGIN_DECLS |
| 199 | 199 | H3270 * host; /**< Related 3270 session */ |
| 200 | 200 | gchar * session_name; /**< Session name (for window title) */ |
| 201 | 201 | |
| 202 | + // Auto disconnect | |
| 203 | + struct | |
| 204 | + { | |
| 205 | + time_t timestamp; /**< Last action in this widget */ | |
| 206 | + guint disconnect; /**< Time (in minutes) for auto disconnect */ | |
| 207 | + GSource * timer; /**< Auto disconnect timer */ | |
| 208 | + } activity; | |
| 209 | + | |
| 202 | 210 | // Scripting |
| 203 | 211 | struct |
| 204 | 212 | { |
| ... | ... | @@ -224,6 +232,7 @@ G_BEGIN_DECLS |
| 224 | 232 | PROP_SELECTION, |
| 225 | 233 | PROP_MODEL, |
| 226 | 234 | PROP_LUNAME, |
| 235 | + PROP_AUTO_DISCONNECT, | |
| 227 | 236 | |
| 228 | 237 | /* Toggles - always the last one, the real values are PROP_TOGGLE+LIB3270_TOGGLE */ |
| 229 | 238 | PROP_TOGGLE | ... | ... |
src/pw3270/v3270/properties.c
| ... | ... | @@ -53,6 +53,10 @@ |
| 53 | 53 | lib3270_set_model(window->host,g_value_get_string(value)); |
| 54 | 54 | break; |
| 55 | 55 | |
| 56 | + case PROP_AUTO_DISCONNECT: | |
| 57 | + v3270_set_auto_disconnect(GTK_WIDGET(object),g_value_get_int(value)); | |
| 58 | + break; | |
| 59 | + | |
| 56 | 60 | default: |
| 57 | 61 | if(prop_id < (PROP_TOGGLE + LIB3270_TOGGLE_COUNT)) |
| 58 | 62 | { |
| ... | ... | @@ -74,6 +78,10 @@ |
| 74 | 78 | g_value_set_string(value,lib3270_get_model(window->host)); |
| 75 | 79 | break; |
| 76 | 80 | |
| 81 | + case PROP_AUTO_DISCONNECT: | |
| 82 | + g_value_set_int(value,v3270_get_auto_disconnect(GTK_WIDGET(object))); | |
| 83 | + break; | |
| 84 | + | |
| 77 | 85 | case PROP_LUNAME: |
| 78 | 86 | g_value_set_string(value,lib3270_get_luname(window->host)); |
| 79 | 87 | break; |
| ... | ... | @@ -129,6 +137,14 @@ |
| 129 | 137 | FALSE,G_PARAM_READABLE|G_PARAM_WRITABLE); |
| 130 | 138 | g_object_class_install_property(gobject_class,PROP_LUNAME,v3270_properties[PROP_LUNAME]); |
| 131 | 139 | |
| 140 | + | |
| 141 | + v3270_properties[PROP_AUTO_DISCONNECT] = g_param_spec_string( | |
| 142 | + "auto_disconnect", | |
| 143 | + "auto_disconnect", | |
| 144 | + "Minutes to disconnect when idle", | |
| 145 | + FALSE,G_PARAM_READABLE|G_PARAM_WRITABLE); | |
| 146 | + g_object_class_install_property(gobject_class,PROP_LUNAME,v3270_properties[PROP_LUNAME]); | |
| 147 | + | |
| 132 | 148 | // Toggle properties |
| 133 | 149 | int f; |
| 134 | 150 | |
| ... | ... | @@ -138,3 +154,15 @@ |
| 138 | 154 | g_object_class_install_property(gobject_class,PROP_TOGGLE+f,v3270_properties[PROP_TOGGLE+f]); |
| 139 | 155 | } |
| 140 | 156 | } |
| 157 | + | |
| 158 | + LIB3270_EXPORT void v3270_set_auto_disconnect(GtkWidget *widget, guint minutes) | |
| 159 | + { | |
| 160 | + g_return_if_fail(GTK_IS_V3270(widget)); | |
| 161 | + GTK_V3270(widget)->activity.disconnect = minutes; | |
| 162 | + } | |
| 163 | + | |
| 164 | + LIB3270_EXPORT guint v3270_get_auto_disconnect(GtkWidget *widget) | |
| 165 | + { | |
| 166 | + g_return_val_if_fail(GTK_IS_V3270(widget),0); | |
| 167 | + return GTK_V3270(widget)->activity.disconnect; | |
| 168 | + } | ... | ... |
src/pw3270/v3270/widget.c
| ... | ... | @@ -675,8 +675,8 @@ static void update_toggle(H3270 *session, LIB3270_TOGGLE ix, unsigned char value |
| 675 | 675 | break; |
| 676 | 676 | |
| 677 | 677 | case LIB3270_TOGGLE_INSERT: |
| 678 | - v3270_draw_ins_status(GTK_WIDGET(session->widget)); | |
| 679 | - v3270_cursor_draw(GTK_WIDGET(session->widget)); | |
| 678 | + v3270_draw_ins_status(GTK_V3270(session->widget)); | |
| 679 | + v3270_cursor_draw(GTK_V3270(session->widget)); | |
| 680 | 680 | break; |
| 681 | 681 | |
| 682 | 682 | case LIB3270_TOGGLE_BOLD: |
| ... | ... | @@ -762,6 +762,8 @@ static void update_connect(H3270 *session, unsigned char connected) |
| 762 | 762 | g_object_notify(G_OBJECT(widget),"online"); |
| 763 | 763 | #endif // GTK_CHECK_VERSION |
| 764 | 764 | |
| 765 | + widget->activity.timestamp = time(0); | |
| 766 | + | |
| 765 | 767 | gtk_widget_queue_draw(GTK_WIDGET(widget)); |
| 766 | 768 | } |
| 767 | 769 | |
| ... | ... | @@ -881,6 +883,21 @@ static int emit_print_signal(H3270 *session) |
| 881 | 883 | return 0; |
| 882 | 884 | } |
| 883 | 885 | |
| 886 | +static gboolean activity_tick(v3270 *widget) | |
| 887 | +{ | |
| 888 | + trace("idle=%d (%d) timeout=%d",time(0) - widget->activity.timestamp,((time(0) - widget->activity.timestamp)/60),widget->activity.disconnect); | |
| 889 | + | |
| 890 | + if(widget->activity.disconnect && lib3270_is_connected(widget->host) && ((time(0) - widget->activity.timestamp)/60) >= widget->activity.disconnect) | |
| 891 | + lib3270_disconnect(widget->host); | |
| 892 | + | |
| 893 | + return TRUE; | |
| 894 | +} | |
| 895 | + | |
| 896 | +static void release_activity_timer(v3270 *widget) | |
| 897 | +{ | |
| 898 | + widget->activity.timer = NULL; | |
| 899 | +} | |
| 900 | + | |
| 884 | 901 | static void v3270_init(v3270 *widget) |
| 885 | 902 | { |
| 886 | 903 | widget->host = lib3270_session_new(""); |
| ... | ... | @@ -917,6 +934,10 @@ static void v3270_init(v3270 *widget) |
| 917 | 934 | widget->host->update_ssl = v3270_update_ssl; |
| 918 | 935 | widget->host->print = emit_print_signal; |
| 919 | 936 | |
| 937 | + // Reset timer | |
| 938 | + widget->activity.timestamp = time(0); | |
| 939 | + widget->activity.disconnect = 0; | |
| 940 | + | |
| 920 | 941 | // Setup input method |
| 921 | 942 | widget->input_method = gtk_im_multicontext_new(); |
| 922 | 943 | g_signal_connect(G_OBJECT(widget->input_method),"commit",G_CALLBACK(v3270_key_commit),widget); |
| ... | ... | @@ -932,6 +953,9 @@ static void v3270_init(v3270 *widget) |
| 932 | 953 | gtk_widget_add_events(GTK_WIDGET(widget),GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK|GDK_BUTTON_PRESS_MASK|GDK_BUTTON_MOTION_MASK|GDK_BUTTON_RELEASE_MASK|GDK_POINTER_MOTION_MASK|GDK_ENTER_NOTIFY_MASK|GDK_SCROLL_MASK); |
| 933 | 954 | gtk_widget_set_has_tooltip(GTK_WIDGET(widget),TRUE); |
| 934 | 955 | |
| 956 | + // Setup auto disconnect timer | |
| 957 | + widget->cursor.timer = NULL; | |
| 958 | + | |
| 935 | 959 | trace("%s",__FUNCTION__); |
| 936 | 960 | } |
| 937 | 961 | |
| ... | ... | @@ -1013,6 +1037,13 @@ static void v3270_destroy(GtkObject *widget) |
| 1013 | 1037 | g_source_unref(terminal->cursor.timer); |
| 1014 | 1038 | } |
| 1015 | 1039 | |
| 1040 | + if(terminal->activity.timer) | |
| 1041 | + { | |
| 1042 | + g_source_destroy(terminal->activity.timer); | |
| 1043 | + while(terminal->activity.timer) | |
| 1044 | + g_source_unref(terminal->activity.timer); | |
| 1045 | + } | |
| 1046 | + | |
| 1016 | 1047 | if(terminal->input_method) |
| 1017 | 1048 | { |
| 1018 | 1049 | g_object_unref(terminal->input_method); |
| ... | ... | @@ -1049,7 +1080,7 @@ static gboolean timer_tick(v3270 *widget) |
| 1049 | 1080 | return TRUE; |
| 1050 | 1081 | } |
| 1051 | 1082 | |
| 1052 | -static void release_timer(v3270 *widget) | |
| 1083 | +static void release_cursor_timer(v3270 *widget) | |
| 1053 | 1084 | { |
| 1054 | 1085 | widget->cursor.timer = NULL; |
| 1055 | 1086 | } |
| ... | ... | @@ -1144,12 +1175,22 @@ static void v3270_realize(GtkWidget * widget) |
| 1144 | 1175 | v3270 *terminal = GTK_V3270(widget); |
| 1145 | 1176 | |
| 1146 | 1177 | terminal->cursor.timer = g_timeout_source_new(500); |
| 1147 | - g_source_set_callback(terminal->cursor.timer,(GSourceFunc) timer_tick, widget, (GDestroyNotify) release_timer); | |
| 1178 | + g_source_set_callback(terminal->cursor.timer,(GSourceFunc) timer_tick, widget, (GDestroyNotify) release_cursor_timer); | |
| 1148 | 1179 | |
| 1149 | 1180 | g_source_attach(terminal->cursor.timer, NULL); |
| 1150 | 1181 | g_source_unref(terminal->cursor.timer); |
| 1151 | 1182 | } |
| 1152 | 1183 | |
| 1184 | + if(!GTK_V3270(widget)->activity.timer) | |
| 1185 | + { | |
| 1186 | + v3270 *terminal = GTK_V3270(widget); | |
| 1187 | + | |
| 1188 | + terminal->activity.timer = g_timeout_source_new(10000); | |
| 1189 | + g_source_set_callback(terminal->activity.timer,(GSourceFunc) activity_tick, widget, (GDestroyNotify) release_activity_timer); | |
| 1190 | + g_source_attach(terminal->activity.timer, NULL); | |
| 1191 | + g_source_unref(terminal->activity.timer); | |
| 1192 | + } | |
| 1193 | + | |
| 1153 | 1194 | } |
| 1154 | 1195 | |
| 1155 | 1196 | static void v3270_size_allocate(GtkWidget * widget, GtkAllocation * allocation) |
| ... | ... | @@ -1464,6 +1505,7 @@ static void v3270_activate(GtkWidget *widget) |
| 1464 | 1505 | v3270 * terminal = GTK_V3270(widget); |
| 1465 | 1506 | |
| 1466 | 1507 | trace("%s: %p",__FUNCTION__,terminal); |
| 1508 | + terminal->activity.timestamp = time(0); | |
| 1467 | 1509 | |
| 1468 | 1510 | if(lib3270_connected(terminal->host)) |
| 1469 | 1511 | lib3270_enter(terminal->host); | ... | ... |