Commit 1b59e4072fda1bdba58ec6ad48b4174fe9b36e8e

Authored by Perry Werneck
1 parent 4984a67f

Using the V3270 terminal actions.

pw3270.cbp
... ... @@ -49,6 +49,7 @@
49 49 <Unit filename="src/include/pw3270/settings.h" />
50 50 <Unit filename="src/include/pw3270/toolbar.h" />
51 51 <Unit filename="src/include/pw3270/window.h" />
  52 + <Unit filename="src/include/v3270_actions.h" />
52 53 <Unit filename="src/main/main.c">
53 54 <Option compilerVar="CC" />
54 55 </Unit>
... ... @@ -96,6 +97,9 @@
96 97 <Unit filename="src/objects/actions/simple.c">
97 98 <Option compilerVar="CC" />
98 99 </Unit>
  100 + <Unit filename="src/objects/actions/v3270/action.c">
  101 + <Option compilerVar="CC" />
  102 + </Unit>
99 103 <Unit filename="src/objects/actions/v3270/conditional.c">
100 104 <Option compilerVar="CC" />
101 105 </Unit>
... ...
src/include/pw3270/actions.h
... ... @@ -40,6 +40,7 @@
40 40 #include <gtk/gtk.h>
41 41 #include <lib3270.h>
42 42 #include <lib3270/actions.h>
  43 + #include <v3270/actions.h>
43 44  
44 45 G_BEGIN_DECLS
45 46  
... ... @@ -121,7 +122,7 @@
121 122 const gchar * pw3270_action_get_tooltip(GAction *action);
122 123  
123 124 /// @brief Create a button associated with the action.
124   - GtkWidget * pw3270_action_button_new(GAction *action, const gchar *action_name);
  125 + //GtkWidget * pw3270_action_button_new(GAction *action, const gchar *action_name);
125 126  
126 127 /// @brief Associate action with the terminal widget.
127 128 void pw3270_action_set_terminal_widget(GAction *action, GtkWidget *terminal);
... ... @@ -252,6 +253,7 @@
252 253 GType v3270ConditionalAction_get_type(void) G_GNUC_CONST;
253 254  
254 255 GAction * v3270_conditional_action_new(GtkWidget *widget, const gchar *property_name);
  256 + GAction * v3270_action_new(const V3270_ACTION *action_data);
255 257  
256 258 //
257 259 // Action view
... ... @@ -271,7 +273,14 @@
271 273 //
272 274 // Tools
273 275 //
274   - GdkPixbuf * g_action_get_pixbuf(GAction *action, GtkIconSize icon_size);
  276 + gchar * g_action_get_icon_name(GAction *action);
  277 + gchar * g_action_get_tooltip(GAction *action);
  278 + gchar * g_action_get_label(GAction *action);
  279 +
  280 + GdkPixbuf * g_action_get_pixbuf(GAction *action, GtkIconSize icon_size, GtkIconLookupFlags flags);
  281 +
  282 + GtkWidget * gtk_button_new_from_action(GAction *action, GtkIconSize icon_size);
  283 + GtkToolItem * gtk_tool_button_new_from_action(GAction *action, GtkIconSize icon_size);
275 284  
276 285 G_END_DECLS
277 286  
... ...
src/include/pw3270/toolbar.h
... ... @@ -56,7 +56,7 @@
56 56  
57 57 GtkWidget * pw3270_toolbar_new(void);
58 58  
59   - GtkWidget * pw3270_toolbar_insert_lib3270_action(GtkWidget *toolbar, const LIB3270_ACTION *action, gint pos);
  59 +// GtkWidget * pw3270_toolbar_insert_lib3270_action(GtkWidget *toolbar, const LIB3270_ACTION *action, gint pos);
60 60 GtkWidget * pw3270_toolbar_insert_action(GtkWidget *toolbar, const gchar *name, gint pos);
61 61  
62 62 void pw3270_toolbar_set_actions(GtkWidget *toolbar, const gchar *action_names);
... ...
src/objects/actions/abstract.c
... ... @@ -362,6 +362,7 @@
362 362 }
363 363  
364 364 static gboolean bg_notify_enabled(GObject *action) {
  365 + // debug("%s(%s,%s)",__FUNCTION__,g_action_get_name(G_ACTION(action)),(g_action_get_enabled(G_ACTION(action)) ? "enabled" : "disabled"));
365 366 g_object_notify(action, "enabled");
366 367 return FALSE;
367 368 }
... ... @@ -493,7 +494,7 @@
493 494 return G_ACTION(g_object_new(PW3270_TYPE_ACTION, NULL));
494 495 }
495 496  
496   - static GdkPixbuf * pixbuf_from_icon_name(GValue *value, GtkIconSize icon_size) {
  497 + static GdkPixbuf * pixbuf_from_icon_name(GValue *value, gint width, gint G_GNUC_UNUSED(height), GtkIconLookupFlags flags) {
497 498  
498 499 const gchar * icon_name = g_value_get_string(value);
499 500  
... ... @@ -503,19 +504,48 @@
503 504 return gtk_icon_theme_load_icon(
504 505 gtk_icon_theme_get_default(),
505 506 icon_name,
506   - icon_size,
507   - GTK_ICON_LOOKUP_GENERIC_FALLBACK,
  507 + width,
  508 + flags, // GTK_ICON_LOOKUP_GENERIC_FALLBACK,
508 509 NULL
509 510 );
510 511  
511 512 }
512 513  
513   - GdkPixbuf * g_action_get_pixbuf(GAction *action, GtkIconSize icon_size) {
  514 + gchar * g_action_get_text(GAction *action, const gchar * property_name) {
  515 + gchar *rc = NULL;
  516 +
  517 + GValue value = G_VALUE_INIT;
  518 + g_value_init(&value, G_TYPE_STRING);
  519 + g_object_get_property(G_OBJECT(action),property_name,&value);
  520 +
  521 + const gchar * text = g_value_get_string(&value);
  522 + if(text)
  523 + rc = g_strdup(text);
  524 +
  525 + g_value_unset(&value);
  526 +
  527 + return rc;
  528 +
  529 + }
  530 +
  531 + gchar * g_action_get_tooltip(GAction *action) {
  532 + return g_action_get_text(action, "tooltip");
  533 + }
  534 +
  535 + gchar * g_action_get_label(GAction *action) {
  536 + return g_action_get_text(action, "label");
  537 + }
  538 +
  539 + gchar * g_action_get_icon_name(GAction *action) {
  540 + return g_action_get_text(action, "icon-name");
  541 + }
  542 +
  543 + GdkPixbuf * g_action_get_pixbuf(GAction *action, GtkIconSize icon_size, GtkIconLookupFlags flags) {
514 544  
515 545 struct Properties {
516 546 const gchar * name;
517 547 GType value_type;
518   - GdkPixbuf * (*translate)(GValue *value, GtkIconSize icon_size);
  548 + GdkPixbuf * (*translate)(GValue *value, gint width, gint height, GtkIconLookupFlags flags);
519 549 } properties[] = {
520 550 {
521 551 .name = "icon-name",
... ... @@ -526,6 +556,9 @@
526 556  
527 557 size_t ix;
528 558 GdkPixbuf * pixbuf = NULL;
  559 + gint width, height;
  560 +
  561 + gtk_icon_size_lookup(icon_size,&width,&height);
529 562  
530 563 for(ix = 0; ix < G_N_ELEMENTS(properties) && !pixbuf; ix++) {
531 564  
... ... @@ -537,7 +570,7 @@
537 570  
538 571 g_object_get_property(G_OBJECT(action),properties[ix].name,&value);
539 572  
540   - pixbuf = properties[ix].translate(&value,icon_size);
  573 + pixbuf = properties[ix].translate(&value,width,height,flags);
541 574  
542 575 g_value_unset(&value);
543 576  
... ...
src/objects/actions/button.c
... ... @@ -35,6 +35,85 @@
35 35 #include "private.h"
36 36 #include <pw3270/actions.h>
37 37  
  38 + GtkWidget * gtk_button_new_from_action(GAction *action, GtkIconSize icon_size) {
  39 +
  40 + if(!action)
  41 + return NULL;
  42 +
  43 + g_autofree gchar * icon_name = g_action_get_icon_name(action);
  44 + if(icon_name)
  45 + return gtk_button_new_from_icon_name(icon_name,icon_size);
  46 +
  47 + GdkPixbuf * pixbuf = g_action_get_pixbuf(action, GTK_ICON_SIZE_BUTTON, GTK_ICON_LOOKUP_GENERIC_FALLBACK);
  48 +
  49 + if(pixbuf) {
  50 +
  51 + GtkWidget * button = gtk_button_new();
  52 +
  53 + GtkWidget * image = gtk_image_new_from_pixbuf(pixbuf);
  54 + gtk_widget_show_all(image);
  55 +
  56 + gtk_button_set_image(GTK_BUTTON(button),image);
  57 +
  58 + return button;
  59 + }
  60 +
  61 +
  62 + return NULL;
  63 + }
  64 +
  65 + GtkToolItem * gtk_tool_button_new_from_action(GAction *action, GtkIconSize icon_size) {
  66 +
  67 + if(!action)
  68 + return NULL;
  69 +
  70 + g_autofree gchar * tooltip = g_action_get_tooltip(action);
  71 + g_autofree gchar * label = g_action_get_label(action);
  72 + debug("%s(%s).label=%s",__FUNCTION__,g_action_get_name(action),label);
  73 + if(!label)
  74 + return NULL;
  75 +
  76 + g_autofree gchar * icon_name = g_action_get_icon_name(action);
  77 + debug("%s(%s).icon_name=%s",__FUNCTION__,g_action_get_name(action),icon_name);
  78 + if(icon_name) {
  79 +
  80 + // Has icon name
  81 + GtkToolItem * item = gtk_tool_button_new(NULL,label);
  82 +
  83 + gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(item),icon_name);
  84 +
  85 + if(tooltip)
  86 + gtk_widget_set_tooltip_markup(GTK_WIDGET(item),tooltip);
  87 +
  88 + return item;
  89 + }
  90 +
  91 +
  92 + /// FIXME: Get size from icon_size
  93 + GdkPixbuf * pixbuf = g_action_get_pixbuf(action, icon_size, GTK_ICON_LOOKUP_GENERIC_FALLBACK);
  94 +
  95 + if(pixbuf) {
  96 +
  97 + GtkToolItem * item = gtk_tool_button_new(NULL,label);
  98 +
  99 + GtkWidget * image = gtk_image_new_from_pixbuf(pixbuf);
  100 + gtk_widget_show_all(image);
  101 +
  102 + gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(item),image);
  103 +
  104 + if(tooltip)
  105 + gtk_widget_set_tooltip_markup(GTK_WIDGET(item),tooltip);
  106 +
  107 + return item;
  108 + }
  109 +
  110 +
  111 + return NULL;
  112 +
  113 + }
  114 +
  115 +
  116 + /*
38 117 /// @brief Create a button associated with the action.
39 118 GtkWidget * pw3270_action_button_new(GAction *action, const gchar *action_name) {
40 119  
... ... @@ -72,4 +151,5 @@
72 151 return button;
73 152  
74 153 }
  154 + */
75 155  
... ...
src/objects/actions/print.c
... ... @@ -36,6 +36,7 @@
36 36 #include <v3270.h>
37 37 #include <pw3270/application.h>
38 38  
  39 + /*
39 40 static void activate_print_all(GAction G_GNUC_UNUSED(*action), GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal) {
40 41 debug("%s",__FUNCTION__);
41 42 v3270_print_all(terminal,NULL);
... ... @@ -105,4 +106,5 @@
105 106 return G_ACTION(action);
106 107  
107 108 }
  109 + */
108 110  
... ...
src/objects/actions/private.h
... ... @@ -66,6 +66,7 @@
66 66 G_GNUC_INTERNAL GAction * pw3270_action_cut_new(void);
67 67 G_GNUC_INTERNAL GAction * pw3270_action_paste_new(void);
68 68  
  69 + /*
69 70 G_GNUC_INTERNAL GAction * pw3270_action_save_new(void);
70 71 G_GNUC_INTERNAL GAction * pw3270_action_save_screen_new(void);
71 72 G_GNUC_INTERNAL GAction * pw3270_action_save_selected_new(void);
... ... @@ -73,5 +74,6 @@
73 74 G_GNUC_INTERNAL GAction * pw3270_action_print_new(void);
74 75 G_GNUC_INTERNAL GAction * pw3270_action_print_all_new(void);
75 76 G_GNUC_INTERNAL GAction * pw3270_action_print_selected_new(void);
  77 + */
76 78  
77 79 #endif // PRIVATE_H_INCLUDED
... ...
src/objects/actions/save.c
... ... @@ -36,6 +36,7 @@
36 36 #include <v3270.h>
37 37 #include <pw3270/application.h>
38 38  
  39 + /*
39 40 static void activate_save_screen(GAction G_GNUC_UNUSED(*action), GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal) {
40 41 debug("%s",__FUNCTION__);
41 42 v3270_save_all(terminal,NULL,NULL);
... ... @@ -103,4 +104,4 @@
103 104 return G_ACTION(action);
104 105  
105 106 }
106   -
  107 +*/
... ...
src/objects/actions/view.c
... ... @@ -229,7 +229,7 @@
229 229 return list;
230 230 }
231 231  
232   - GdkPixbuf * pixbuf = g_action_get_pixbuf(action, GTK_ICON_SIZE_MENU);
  232 + GdkPixbuf * pixbuf = g_action_get_pixbuf(action, GTK_ICON_SIZE_MENU, GTK_ICON_LOOKUP_GENERIC_FALLBACK);
233 233 if(!pixbuf) {
234 234 debug("Action \"%s\": Doesn't have a pixbuf",g_action_get_name(action));
235 235 return list;
... ...
src/objects/actions/window.c
... ... @@ -34,6 +34,7 @@
34 34  
35 35 #include "private.h"
36 36 #include <lib3270/actions.h>
  37 + #include <v3270/actions.h>
37 38 #include <pw3270/window.h>
38 39  
39 40 void pw3270_window_add_actions(GtkWidget * appwindow) {
... ... @@ -63,23 +64,34 @@
63 64 }
64 65 }
65 66  
  67 + // Map V3270 actions
  68 + {
  69 + const V3270_ACTION * actions = v3270_get_actions();
  70 +
  71 + for(ix = 0; actions[ix].name; ix++) {
  72 + GAction * action = v3270_action_new(&actions[ix]);
  73 + g_action_map_add_action(map,action);
  74 + }
  75 +
  76 + }
  77 +
66 78 // Map special actions
67 79 {
68 80 GAction * actions[] = {
69 81 pw3270_action_new_pfkey(),
70 82 pw3270_action_new_pakey(),
71   - pw3270_action_connect_new(),
72   - pw3270_action_copy_new(),
73   - pw3270_action_cut_new(),
74   - pw3270_action_paste_new(),
  83 +// pw3270_action_connect_new(),
  84 +// pw3270_action_copy_new(),
  85 +// pw3270_action_cut_new(),
  86 +// pw3270_action_paste_new(),
75 87  
76 88 // pw3270_action_save_new(),
77 89 // pw3270_action_save_screen_new(),
78 90 // pw3270_action_save_selected_new(),
79 91  
80   - pw3270_action_print_new(),
81   - pw3270_action_print_all_new(),
82   - pw3270_action_print_selected_new(),
  92 +// pw3270_action_print_new(),
  93 +// pw3270_action_print_all_new(),
  94 +// pw3270_action_print_selected_new(),
83 95  
84 96 };
85 97  
... ...
src/objects/application/application.c
... ... @@ -310,6 +310,7 @@
310 310  
311 311 }
312 312  
  313 + /*
313 314 // Create conditional actions.
314 315 static const struct {
315 316 const gchar * label;
... ... @@ -350,6 +351,7 @@
350 351 );
351 352  
352 353 }
  354 + */
353 355  
354 356 // Present the new window
355 357 pw3270_window_set_current_page(window,0);
... ...
src/objects/toolbar/actions.c
... ... @@ -70,16 +70,23 @@
70 70 action = g_action_map_lookup_action(G_ACTION_MAP(window), ptr+1);
71 71 }
72 72  
  73 + debug("%s(%s)=%p",__FUNCTION__,name,action);
  74 +
73 75 if(action) {
74 76 debug("Creating button \"%s\" from action \"%s\"",name,g_action_get_name(G_ACTION(action)));
75   - item = GTK_TOOL_ITEM(pw3270_tool_button_new(action));
76   - } else {
  77 + item = gtk_tool_button_new_from_action(action,GTK_ICON_SIZE_LARGE_TOOLBAR);
  78 + }
  79 + /*
  80 + else {
77 81 debug("Creating button \"%s\" from action name",name);
78 82 item = GTK_TOOL_ITEM(pw3270_tool_button_new_from_action_name(name));
79 83 }
  84 + */
80 85  
81 86 if(item) {
82 87  
  88 + gtk_widget_show_all(GTK_WIDGET(item));
  89 +
83 90 if(action && g_action_get_parameter_type(action) == G_VARIANT_TYPE_STRING) {
84 91 g_autofree gchar * detailed = g_strconcat(name,"::",NULL);
85 92 gtk_actionable_set_detailed_action_name(GTK_ACTIONABLE(item),detailed);
... ... @@ -89,6 +96,11 @@
89 96  
90 97 gtk_toolbar_insert(GTK_TOOLBAR(toolbar),item,pos);
91 98 return GTK_WIDGET(item);
  99 +
  100 + } else {
  101 +
  102 + g_warning("Can't create toolbar item for action \"%s\"",name);
  103 +
92 104 }
93 105  
94 106 }
... ...
src/objects/toolbar/toolbar.c
... ... @@ -270,6 +270,7 @@
270 270 return g_object_new(PW3270_TYPE_TOOLBAR, NULL);
271 271 }
272 272  
  273 + /*
273 274 GtkWidget * pw3270_toolbar_insert_lib3270_action(GtkWidget *toolbar, const LIB3270_ACTION *action, gint pos) {
274 275  
275 276 g_return_val_if_fail(GTK_IS_TOOLBAR(toolbar),NULL);
... ... @@ -303,6 +304,7 @@
303 304  
304 305 return GTK_WIDGET(item);
305 306 }
  307 + */
306 308  
307 309 gboolean popup_context_menu(GtkToolbar *widget, gint G_GNUC_UNUSED(x), gint G_GNUC_UNUSED(y), gint button_number) {
308 310  
... ...
src/objects/toolbar/toolbutton.c
... ... @@ -30,6 +30,7 @@
30 30 #include "private.h"
31 31 #include <pw3270/actions.h>
32 32  
  33 + /*
33 34 static const struct Button {
34 35 const gchar * name;
35 36 const gchar * icon_name;
... ... @@ -162,4 +163,5 @@
162 163 return pw3270_tool_button_new_from_action_name(action_name);
163 164  
164 165 }
  166 + */
165 167  
... ...
src/objects/window/actions/hostproperties.c
... ... @@ -50,7 +50,7 @@
50 50 GtkWidget * factory(GtkWidget *terminal) {
51 51  
52 52 GtkWidget * dialog = v3270_settings_dialog_new();
53   - V3270Settings * settings = GTK_V3270_SETTINGS(v3270_host_select_new());
  53 + V3270Settings * settings = GTK_V3270_SETTINGS(v3270_host_settings_new());
54 54  
55 55 if(settings->title)
56 56 gtk_window_set_title(GTK_WINDOW(dialog), settings->title);
... ...
src/objects/window/header.c
... ... @@ -84,7 +84,7 @@
84 84  
85 85 }
86 86  
87   - static void on_sensitive(GtkWidget *button, GParamSpec *spec, GtkWidget *widget) {
  87 + static void on_sensitive(GtkWidget G_GNUC_UNUSED(*button), GParamSpec G_GNUC_UNUSED(*spec), GtkWidget *widget) {
88 88  
89 89 gboolean sensitive;
90 90 g_object_get(button, "sensitive", &sensitive, NULL);
... ... @@ -100,7 +100,10 @@
100 100  
101 101 // It's a menu
102 102 g_autofree gchar * icon_name = g_strconcat(action_name+5,"-symbolic",NULL);
103   - button = pw3270_setup_image_button(gtk_menu_button_new(),icon_name);
  103 +
  104 + button = gtk_menu_button_new();
  105 + gtk_button_set_image(GTK_BUTTON(button),gtk_image_new_from_icon_name(icon_name,GTK_ICON_SIZE_MENU));
  106 +
104 107 gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(button), G_MENU_MODEL(gtk_builder_get_object(builder, action_name+5)));
105 108 gtk_widget_set_visible(button,TRUE);
106 109  
... ... @@ -113,8 +116,19 @@
113 116 // It's a window action.
114 117 GAction * action = g_action_map_lookup_action(G_ACTION_MAP(widget),action_name+4);
115 118  
116   - if(action)
117   - button = pw3270_action_button_new(action,action_name);
  119 + if(action) {
  120 +
  121 + button = gtk_button_new_from_action(action,GTK_ICON_SIZE_BUTTON);
  122 +
  123 + gtk_actionable_set_action_name(GTK_ACTIONABLE(button),action_name);
  124 + gtk_widget_set_visible(button,g_action_get_enabled(action));
  125 +
  126 +
  127 + } else {
  128 +
  129 + g_warning("Can't find action \"%s\"",action_name+4);
  130 +
  131 + }
118 132  
119 133 }
120 134  
... ...
src/objects/window/private.h
... ... @@ -73,9 +73,6 @@
73 73  
74 74 };
75 75  
76   - // Internal methods
77   - G_GNUC_INTERNAL GtkWidget * pw3270_setup_image_button(GtkWidget *button, const gchar *image_name);
78   -
79 76 // Actions
80 77 G_GNUC_INTERNAL GAction * pw3270_action_host_properties_new(void);
81 78 G_GNUC_INTERNAL GAction * pw3270_set_color_action_new(void);
... ...
src/objects/window/terminal.c
... ... @@ -86,8 +86,14 @@
86 86  
87 87 GAction * action = g_action_map_lookup_action(G_ACTION_MAP(window), actions[ix]);
88 88  
89   - if(action && PW3270_IS_ACTION(action)) {
90   - pw3270_action_set_terminal_widget(action,terminal);
  89 + if(action) {
  90 +
  91 + if(V3270_IS_ACTION(action)) {
  92 + v3270_action_set_terminal_widget(action,terminal);
  93 + } else if(PW3270_IS_ACTION(action)) {
  94 + pw3270_action_set_terminal_widget(action,terminal);
  95 + }
  96 +
91 97 }
92 98  
93 99 }
... ...
src/objects/window/tools.c
... ... @@ -30,6 +30,7 @@
30 30 #include "private.h"
31 31 #include <pw3270/application.h>
32 32  
  33 + /*
33 34 GtkWidget * pw3270_setup_image_button(GtkWidget *button, const gchar *image_name) {
34 35  
35 36 gtk_button_set_image(GTK_BUTTON(button),gtk_image_new_from_icon_name(image_name,GTK_ICON_SIZE_MENU));
... ... @@ -41,6 +42,7 @@
41 42 return button;
42 43  
43 44 }
  45 +*/
44 46  
45 47 gboolean pw3270_settings_set_int(const gchar *key, gint value) {
46 48  
... ...
src/objects/window/window.c
... ... @@ -142,6 +142,8 @@
142 142 //
143 143 pw3270_window_add_actions(GTK_WIDGET(widget));
144 144  
  145 + g_action_map_add_v3270_actions(G_ACTION_MAP(widget));
  146 +
145 147 // Map special actions
146 148 {
147 149 size_t ix;
... ...