Commit 12521a322ff18eb3403e64ac5894dadbda8612bc

Authored by perry.werneck@gmail.com
1 parent eedb58c8

Implementando opcao para ativar opcao de 8 cores via linha de comando

src/include/lib3270.h
... ... @@ -246,7 +246,8 @@
246 246  
247 247 } LIB3270_OPTION;
248 248  
249   - #define LIB3270_OPTION_COUNT 2
  249 + #define LIB3270_OPTION_DEFAULT 0
  250 + #define LIB3270_OPTION_COUNT 2
250 251  
251 252 typedef struct _lib3270_option_entry
252 253 {
... ...
src/include/pw3270.h
... ... @@ -65,6 +65,7 @@
65 65  
66 66 LIB3270_EXPORT const gchar * pw3270_get_session_name(GtkWidget *widget);
67 67 LIB3270_EXPORT void pw3270_set_session_name(GtkWidget *widget, const gchar *name);
  68 + LIB3270_EXPORT void pw3270_set_session_options(GtkWidget *widget, LIB3270_OPTION options);
68 69  
69 70 LIB3270_EXPORT gint pw3270_get_integer(GtkWidget *widget, const gchar *group, const gchar *key, gint def);
70 71 LIB3270_EXPORT void pw3270_set_integer(GtkWidget *widget, const gchar *group, const gchar *key, gint val);
... ...
src/include/pw3270/v3270.h
... ... @@ -188,7 +188,7 @@
188 188 LIB3270_EXPORT void v3270_set_session_name(GtkWidget *widget, const gchar *name);
189 189 LIB3270_EXPORT int v3270_set_script(GtkWidget *widget, const gchar id, gboolean on);
190 190 LIB3270_EXPORT void v3270_set_scaled_fonts(GtkWidget *widget, gboolean on);
191   -
  191 + LIB3270_EXPORT void v3270_set_session_options(GtkWidget *widget, LIB3270_OPTION options);
192 192 LIB3270_EXPORT void v3270_set_host(GtkWidget *widget, const gchar *uri);
193 193  
194 194 // Keyboard & Mouse special actions
... ...
src/pw3270/actions.c
... ... @@ -73,7 +73,7 @@ static void connect_action(GtkAction *action, GtkWidget *widget)
73 73  
74 74 if(host)
75 75 {
76   - lib3270_set_options(v3270_get_session(widget),0);
  76 + v3270_set_session_options(widget,0);
77 77 v3270_connect(widget,host);
78 78 return;
79 79 }
... ...
src/pw3270/dialog.c
... ... @@ -45,7 +45,7 @@
45 45 if(get_boolean_from_config("host",options[f].key,FALSE))
46 46 opt |= options[f].value;
47 47 }
48   - lib3270_set_options(v3270_get_session(widget),opt);
  48 + v3270_set_session_options(widget,opt);
49 49 }
50 50  
51 51  
... ... @@ -432,7 +432,7 @@
432 432 set_boolean_to_config("host", options[f].key, val);
433 433 }
434 434  
435   - lib3270_set_options(v3270_get_session(widget),opt);
  435 + v3270_set_session_options(widget,opt);
436 436  
437 437 }
438 438  
... ...
src/pw3270/main.c
... ... @@ -38,15 +38,24 @@
38 38 #endif // HAVE_GTKMAC
39 39  
40 40 #include <pw3270/v3270.h>
  41 +#include <pw3270/plugin.h>
41 42 #include "v3270/accessible.h"
42 43 #include <stdlib.h>
43 44  
  45 + struct option
  46 + {
  47 + LIB3270_OPTION host;
  48 + };
  49 +
  50 + #define ERROR_DOMAIN g_quark_from_static_string(PACKAGE_NAME)
  51 +
44 52 /*--[ Statics ]--------------------------------------------------------------------------------------*/
45 53  
46   - static GtkWidget *toplevel = NULL;
  54 + static struct option cmdline_opt = { LIB3270_OPTION_DEFAULT };
  55 + static GtkWidget * toplevel = NULL;
47 56  
48 57 #ifdef HAVE_GTKMAC
49   - GtkOSXApplication * osxapp = NULL;
  58 + GtkOSXApplication * osxapp = NULL;
50 59 #endif // HAVE_GTKMAC
51 60  
52 61 /*--[ Implement ]------------------------------------------------------------------------------------*/
... ... @@ -112,13 +121,32 @@ static void toplevel_setup(GtkWindow *window)
112 121 }
113 122  
114 123 #if ! defined( WIN32 )
115   -static gboolean appname(const gchar *option_name, const gchar *value, gpointer data,GError **error)
  124 +static gboolean appname(const gchar *option_name, const gchar *value, gpointer data, GError **error)
116 125 {
117 126 g_set_application_name(value);
118 127 return TRUE;
119 128 }
120 129 #endif // !win32
121 130  
  131 +static gboolean optcolors(const gchar *option_name, const gchar *value, gpointer data, GError **error)
  132 +{
  133 + switch(atoi(value))
  134 + {
  135 + case 8:
  136 + ((struct option *) data)->host |= LIB3270_OPTION_COLOR8;
  137 + break;
  138 +
  139 + case 16:
  140 + break;
  141 +
  142 + default:
  143 + *error = g_error_new(ERROR_DOMAIN,EINVAL, _("Unexpected or invalid color value \"%s\""), value );
  144 + return FALSE;
  145 + }
  146 +
  147 + return TRUE;
  148 +}
  149 +
122 150 int main(int argc, char *argv[])
123 151 {
124 152 #if defined( WIN32 )
... ... @@ -190,15 +218,20 @@ int main(int argc, char *argv[])
190 218 #endif // WIN32
191 219 { "session", 's', 0, G_OPTION_ARG_STRING, &session_name, N_( "Session name" ), PACKAGE_NAME },
192 220 { "host", 'h', 0, G_OPTION_ARG_STRING, &host, N_( "Host to connect"), NULL },
  221 + { "colors", 'c', 0, G_OPTION_ARG_CALLBACK, optcolors, N_( "Set reported colors (8/16)" ), "16" },
  222 +
193 223 { NULL }
194 224 };
195 225  
196   - GOptionContext * options = g_option_context_new (_("- 3270 Emulator for Gtk"));
197   - GError * error = NULL;
  226 + GOptionContext * context = g_option_context_new (_("- 3270 Emulator for Gtk"));
  227 + GError * error = NULL;
  228 + GOptionGroup * group = g_option_group_new( PACKAGE_NAME, NULL, NULL, &cmdline_opt, NULL);
  229 +
  230 + g_option_context_set_main_group(context, group);
198 231  
199   - g_option_context_add_main_entries(options, app_options, NULL);
  232 + g_option_context_add_main_entries(context, app_options, NULL);
200 233  
201   - if(!g_option_context_parse( options, &argc, &argv, &error ))
  234 + if(!g_option_context_parse( context, &argc, &argv, &error ))
202 235 {
203 236 int f;
204 237 GString * str;
... ... @@ -225,6 +258,7 @@ int main(int argc, char *argv[])
225 258  
226 259 return -1;
227 260 }
  261 +
228 262 }
229 263  
230 264 {
... ... @@ -274,6 +308,7 @@ int main(int argc, char *argv[])
274 308  
275 309 toplevel = pw3270_new(host);
276 310 pw3270_set_session_name(toplevel,session_name);
  311 + pw3270_set_session_options(toplevel,cmdline_opt.host);
277 312  
278 313 toplevel_setup(GTK_WINDOW(toplevel));
279 314  
... ...
src/pw3270/v3270/widget.c
... ... @@ -1438,6 +1438,12 @@ void v3270_set_session_name(GtkWidget *widget, const gchar *name)
1438 1438 GTK_V3270(widget)->session_name = g_strdup(name);
1439 1439 }
1440 1440  
  1441 +void v3270_set_session_options(GtkWidget *widget, LIB3270_OPTION options)
  1442 +{
  1443 + g_return_if_fail(GTK_IS_V3270(widget));
  1444 + lib3270_set_options(GTK_V3270(widget)->host,options);
  1445 +}
  1446 +
1441 1447 gboolean v3270_is_connected(GtkWidget *widget)
1442 1448 {
1443 1449 g_return_val_if_fail(GTK_IS_V3270(widget),FALSE);
... ...
src/pw3270/window.c
... ... @@ -233,6 +233,12 @@
233 233 gtk_window_set_title(GTK_WINDOW(widget),name);
234 234 }
235 235  
  236 + LIB3270_EXPORT void pw3270_set_session_options(GtkWidget *widget, LIB3270_OPTION options)
  237 + {
  238 + g_return_if_fail(GTK_IS_PW3270(widget));
  239 + v3270_set_session_options(GTK_PW3270(widget)->terminal,options);
  240 + }
  241 +
236 242 static void chktoplevel(GtkWidget *window, GtkWidget **widget)
237 243 {
238 244 if(*widget)
... ...