Commit 8f7e5643214ce3004b75e6ac2ea8ce89854d7912

Authored by Perry Werneck
1 parent f565ad1e

Terminal actions now lives in libv3270.

@@ -81,10 +81,7 @@ @@ -81,10 +81,7 @@
81 <Unit filename="src/objects/actions/simple.c"> 81 <Unit filename="src/objects/actions/simple.c">
82 <Option compilerVar="CC" /> 82 <Option compilerVar="CC" />
83 </Unit> 83 </Unit>
84 - <Unit filename="src/objects/actions/v3270/conditional.c">  
85 - <Option compilerVar="CC" />  
86 - </Unit>  
87 - <Unit filename="src/objects/actions/v3270/property.c"> 84 + <Unit filename="src/objects/actions/tools.c">
88 <Option compilerVar="CC" /> 85 <Option compilerVar="CC" />
89 </Unit> 86 </Unit>
90 <Unit filename="src/objects/actions/view.c"> 87 <Unit filename="src/objects/actions/view.c">
src/include/pw3270/actions.h
@@ -44,6 +44,7 @@ @@ -44,6 +44,7 @@
44 44
45 G_BEGIN_DECLS 45 G_BEGIN_DECLS
46 46
  47 + /*
47 // 48 //
48 // Abstract action 49 // Abstract action
49 // 50 //
@@ -126,7 +127,9 @@ @@ -126,7 +127,9 @@
126 127
127 /// @brief Get lib3270 session handle. 128 /// @brief Get lib3270 session handle.
128 H3270 * pw3270_action_get_session(GAction *action); 129 H3270 * pw3270_action_get_session(GAction *action);
  130 + */
129 131
  132 + /*
130 // 133 //
131 // "Simple" action 134 // "Simple" action
132 // 135 //
@@ -176,6 +179,7 @@ @@ -176,6 +179,7 @@
176 179
177 /// @brief Update simple action from LIB3270's property description. 180 /// @brief Update simple action from LIB3270's property description.
178 void pw3270_simple_action_set_lib3270_property(pw3270SimpleAction *action, const LIB3270_PROPERTY * property); 181 void pw3270_simple_action_set_lib3270_property(pw3270SimpleAction *action, const LIB3270_PROPERTY * property);
  182 + */
179 183
180 // 184 //
181 // Action view 185 // Action view
src/objects/actions/abstract.c
@@ -30,6 +30,8 @@ @@ -30,6 +30,8 @@
30 #include "private.h" 30 #include "private.h"
31 #include <v3270.h> 31 #include <v3270.h>
32 32
  33 + /*
  34 +
33 static void pw3270_action_iface_init(GActionInterface *iface); 35 static void pw3270_action_iface_init(GActionInterface *iface);
34 static void pw3270Action_class_init(pw3270ActionClass *klass); 36 static void pw3270Action_class_init(pw3270ActionClass *klass);
35 static void pw3270Action_init(pw3270Action *action); 37 static void pw3270Action_init(pw3270Action *action);
@@ -68,17 +70,6 @@ @@ -68,17 +70,6 @@
68 PROP_TOOLTIP 70 PROP_TOOLTIP
69 }; 71 };
70 72
71 - /*  
72 - enum {  
73 - SIGNAL_CHANGE_STATE,  
74 - NR_SIGNALS  
75 - };  
76 -  
77 - static guint action_signals[NR_SIGNALS];  
78 -  
79 - */  
80 -  
81 -  
82 G_DEFINE_TYPE_WITH_CODE(pw3270Action, pw3270Action, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(G_TYPE_ACTION, pw3270_action_iface_init)) 73 G_DEFINE_TYPE_WITH_CODE(pw3270Action, pw3270Action, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(G_TYPE_ACTION, pw3270_action_iface_init))
83 74
84 void pw3270_action_iface_init(GActionInterface *iface) { 75 void pw3270_action_iface_init(GActionInterface *iface) {
@@ -188,19 +179,6 @@ @@ -188,19 +179,6 @@
188 179
189 g_object_class_install_property (object_class, PROP_STATE, klass->properties.state); 180 g_object_class_install_property (object_class, PROP_STATE, klass->properties.state);
190 181
191 - /*  
192 - // Install signals  
193 - action_signals[SIGNAL_CHANGE_STATE] =  
194 - g_signal_new(  
195 - I_("change_state"),  
196 - G_TYPE_ACTION,  
197 - G_SIGNAL_RUN_LAST | G_SIGNAL_MUST_COLLECT,  
198 - 0, NULL, NULL,  
199 - NULL,  
200 - G_TYPE_NONE, 1,  
201 - G_TYPE_VARIANT  
202 - );  
203 - */  
204 } 182 }
205 183
206 void pw3270Action_init(pw3270Action *action) { 184 void pw3270Action_init(pw3270Action *action) {
@@ -580,3 +558,4 @@ @@ -580,3 +558,4 @@
580 558
581 return pixbuf; 559 return pixbuf;
582 } 560 }
  561 +*/
src/objects/actions/simple.c
@@ -35,6 +35,7 @@ @@ -35,6 +35,7 @@
35 #include "private.h" 35 #include "private.h"
36 #include <v3270.h> 36 #include <v3270.h>
37 37
  38 + /*
38 static void pw3270SimpleAction_class_init(pw3270SimpleActionClass *klass); 39 static void pw3270SimpleAction_class_init(pw3270SimpleActionClass *klass);
39 static void pw3270SimpleAction_init(pw3270SimpleAction *action); 40 static void pw3270SimpleAction_init(pw3270SimpleAction *action);
40 static void change_widget(GAction *object, GtkWidget *from, GtkWidget *to); 41 static void change_widget(GAction *object, GtkWidget *from, GtkWidget *to);
@@ -175,4 +176,4 @@ @@ -175,4 +176,4 @@
175 pw3270_action_notify_enabled(object); 176 pw3270_action_notify_enabled(object);
176 177
177 } 178 }
178 - 179 + */
src/objects/actions/tools.c 0 → 100644
@@ -0,0 +1,118 @@ @@ -0,0 +1,118 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como - e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 + #include "private.h"
  31 + #include <v3270.h>
  32 +
  33 + gchar * g_action_get_text(GAction *action, const gchar * property_name) {
  34 + gchar *rc = NULL;
  35 +
  36 + GValue value = G_VALUE_INIT;
  37 + g_value_init(&value, G_TYPE_STRING);
  38 + g_object_get_property(G_OBJECT(action),property_name,&value);
  39 +
  40 + const gchar * text = g_value_get_string(&value);
  41 + if(text)
  42 + rc = g_strdup(text);
  43 +
  44 + g_value_unset(&value);
  45 +
  46 + return rc;
  47 +
  48 + }
  49 +
  50 + gchar * g_action_get_tooltip(GAction *action) {
  51 + return g_action_get_text(action, "tooltip");
  52 + }
  53 +
  54 + gchar * g_action_get_label(GAction *action) {
  55 + return g_action_get_text(action, "label");
  56 + }
  57 +
  58 + gchar * g_action_get_icon_name(GAction *action) {
  59 + return g_action_get_text(action, "icon-name");
  60 + }
  61 +
  62 + static GdkPixbuf * pixbuf_from_icon_name(GValue *value, gint width, gint G_GNUC_UNUSED(height), GtkIconLookupFlags flags) {
  63 +
  64 + const gchar * icon_name = g_value_get_string(value);
  65 +
  66 + if(!icon_name)
  67 + return NULL;
  68 +
  69 + return gtk_icon_theme_load_icon(
  70 + gtk_icon_theme_get_default(),
  71 + icon_name,
  72 + width,
  73 + flags, // GTK_ICON_LOOKUP_GENERIC_FALLBACK,
  74 + NULL
  75 + );
  76 +
  77 + }
  78 +
  79 + GdkPixbuf * g_action_get_pixbuf(GAction *action, GtkIconSize icon_size, GtkIconLookupFlags flags) {
  80 +
  81 + struct Properties {
  82 + const gchar * name;
  83 + GType value_type;
  84 + GdkPixbuf * (*translate)(GValue *value, gint width, gint height, GtkIconLookupFlags flags);
  85 + } properties[] = {
  86 + {
  87 + .name = "icon-name",
  88 + .value_type = G_TYPE_STRING,
  89 + .translate = pixbuf_from_icon_name
  90 + }
  91 + };
  92 +
  93 + size_t ix;
  94 + GdkPixbuf * pixbuf = NULL;
  95 + gint width, height;
  96 +
  97 + gtk_icon_size_lookup(icon_size,&width,&height);
  98 +
  99 + for(ix = 0; ix < G_N_ELEMENTS(properties) && !pixbuf; ix++) {
  100 +
  101 + GParamSpec *spec = g_object_class_find_property(G_OBJECT_GET_CLASS(action),properties[ix].name);
  102 + if(spec && spec->value_type == properties[ix].value_type && (spec->flags & G_PARAM_READABLE) != 0) {
  103 +
  104 + GValue value = G_VALUE_INIT;
  105 + g_value_init(&value, properties[ix].value_type);
  106 +
  107 + g_object_get_property(G_OBJECT(action),properties[ix].name,&value);
  108 +
  109 + pixbuf = properties[ix].translate(&value,width,height,flags);
  110 +
  111 + g_value_unset(&value);
  112 +
  113 + }
  114 +
  115 + }
  116 +
  117 + return pixbuf;
  118 + }
src/objects/window/actions/connect.c
@@ -34,6 +34,7 @@ @@ -34,6 +34,7 @@
34 34
35 #include <pw3270.h> 35 #include <pw3270.h>
36 #include <pw3270/actions.h> 36 #include <pw3270/actions.h>
  37 + #include <lib3270/properties.h>
37 #include "../private.h" 38 #include "../private.h"
38 39
39 static void activate(GAction G_GNUC_UNUSED(*action), GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal) { 40 static void activate(GAction G_GNUC_UNUSED(*action), GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal) {
@@ -43,12 +44,20 @@ @@ -43,12 +44,20 @@
43 44
44 } 45 }
45 46
46 - GAction * pw3270_action_connect_new(void) { 47 + GAction * pw3270_action_connect_new(void) {
47 48
48 - pw3270SimpleAction * action = pw3270_simple_action_new_from_lib3270(lib3270_action_get_by_name("reconnect"),"connect"); 49 + V3270SimpleAction *action = v3270_simple_action_new();
  50 +
  51 + const LIB3270_PROPERTY * property = (const LIB3270_PROPERTY *) lib3270_action_get_by_name("reconnect");
  52 + if(property) {
  53 + action->icon_name = property->icon;
  54 + action->group.id = property->group;
  55 + }
  56 +
  57 + action->name = "connect";
49 action->parent.activate = activate; 58 action->parent.activate = activate;
50 action->label = _("Connect"); 59 action->label = _("Connect");
51 - action->tooltip = N_("Connect to host"); 60 + action->tooltip = _("Connect to host");
52 61
53 return G_ACTION(action); 62 return G_ACTION(action);
54 63
src/objects/window/window.c
@@ -522,14 +522,8 @@ @@ -522,14 +522,8 @@
522 522
523 GAction * action = g_action_map_lookup_action(G_ACTION_MAP(window), actions[ix]); 523 GAction * action = g_action_map_lookup_action(G_ACTION_MAP(window), actions[ix]);
524 524
525 - if(action) {  
526 -  
527 - if(V3270_IS_ACTION(action)) {  
528 - v3270_action_set_terminal_widget(action,terminal);  
529 - } else if(PW3270_IS_ACTION(action)) {  
530 - pw3270_action_set_terminal_widget(action,terminal);  
531 - }  
532 - 525 + if(action && V3270_IS_ACTION(action)) {
  526 + v3270_action_set_terminal_widget(action,terminal);
533 } 527 }
534 528
535 } 529 }