diff --git a/src/include/lib3270.h b/src/include/lib3270.h index c63805e..7b8ac50 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -246,7 +246,8 @@ } LIB3270_OPTION; - #define LIB3270_OPTION_COUNT 2 + #define LIB3270_OPTION_DEFAULT 0 + #define LIB3270_OPTION_COUNT 2 typedef struct _lib3270_option_entry { diff --git a/src/include/pw3270.h b/src/include/pw3270.h index 8d809f5..4bbdbfd 100644 --- a/src/include/pw3270.h +++ b/src/include/pw3270.h @@ -65,6 +65,7 @@ LIB3270_EXPORT const gchar * pw3270_get_session_name(GtkWidget *widget); LIB3270_EXPORT void pw3270_set_session_name(GtkWidget *widget, const gchar *name); + LIB3270_EXPORT void pw3270_set_session_options(GtkWidget *widget, LIB3270_OPTION options); LIB3270_EXPORT gint pw3270_get_integer(GtkWidget *widget, const gchar *group, const gchar *key, gint def); LIB3270_EXPORT void pw3270_set_integer(GtkWidget *widget, const gchar *group, const gchar *key, gint val); diff --git a/src/include/pw3270/v3270.h b/src/include/pw3270/v3270.h index b826d73..b1a5fb5 100644 --- a/src/include/pw3270/v3270.h +++ b/src/include/pw3270/v3270.h @@ -188,7 +188,7 @@ LIB3270_EXPORT void v3270_set_session_name(GtkWidget *widget, const gchar *name); LIB3270_EXPORT int v3270_set_script(GtkWidget *widget, const gchar id, gboolean on); LIB3270_EXPORT void v3270_set_scaled_fonts(GtkWidget *widget, gboolean on); - + LIB3270_EXPORT void v3270_set_session_options(GtkWidget *widget, LIB3270_OPTION options); LIB3270_EXPORT void v3270_set_host(GtkWidget *widget, const gchar *uri); // Keyboard & Mouse special actions diff --git a/src/pw3270/actions.c b/src/pw3270/actions.c index bdea1c9..70f6394 100644 --- a/src/pw3270/actions.c +++ b/src/pw3270/actions.c @@ -73,7 +73,7 @@ static void connect_action(GtkAction *action, GtkWidget *widget) if(host) { - lib3270_set_options(v3270_get_session(widget),0); + v3270_set_session_options(widget,0); v3270_connect(widget,host); return; } diff --git a/src/pw3270/dialog.c b/src/pw3270/dialog.c index ce534c9..94b51a3 100644 --- a/src/pw3270/dialog.c +++ b/src/pw3270/dialog.c @@ -45,7 +45,7 @@ if(get_boolean_from_config("host",options[f].key,FALSE)) opt |= options[f].value; } - lib3270_set_options(v3270_get_session(widget),opt); + v3270_set_session_options(widget,opt); } @@ -432,7 +432,7 @@ set_boolean_to_config("host", options[f].key, val); } - lib3270_set_options(v3270_get_session(widget),opt); + v3270_set_session_options(widget,opt); } diff --git a/src/pw3270/main.c b/src/pw3270/main.c index 97ccb0c..c32736e 100644 --- a/src/pw3270/main.c +++ b/src/pw3270/main.c @@ -38,15 +38,24 @@ #endif // HAVE_GTKMAC #include +#include #include "v3270/accessible.h" #include + struct option + { + LIB3270_OPTION host; + }; + + #define ERROR_DOMAIN g_quark_from_static_string(PACKAGE_NAME) + /*--[ Statics ]--------------------------------------------------------------------------------------*/ - static GtkWidget *toplevel = NULL; + static struct option cmdline_opt = { LIB3270_OPTION_DEFAULT }; + static GtkWidget * toplevel = NULL; #ifdef HAVE_GTKMAC - GtkOSXApplication * osxapp = NULL; + GtkOSXApplication * osxapp = NULL; #endif // HAVE_GTKMAC /*--[ Implement ]------------------------------------------------------------------------------------*/ @@ -112,13 +121,32 @@ static void toplevel_setup(GtkWindow *window) } #if ! defined( WIN32 ) -static gboolean appname(const gchar *option_name, const gchar *value, gpointer data,GError **error) +static gboolean appname(const gchar *option_name, const gchar *value, gpointer data, GError **error) { g_set_application_name(value); return TRUE; } #endif // !win32 +static gboolean optcolors(const gchar *option_name, const gchar *value, gpointer data, GError **error) +{ + switch(atoi(value)) + { + case 8: + ((struct option *) data)->host |= LIB3270_OPTION_COLOR8; + break; + + case 16: + break; + + default: + *error = g_error_new(ERROR_DOMAIN,EINVAL, _("Unexpected or invalid color value \"%s\""), value ); + return FALSE; + } + + return TRUE; +} + int main(int argc, char *argv[]) { #if defined( WIN32 ) @@ -190,15 +218,20 @@ int main(int argc, char *argv[]) #endif // WIN32 { "session", 's', 0, G_OPTION_ARG_STRING, &session_name, N_( "Session name" ), PACKAGE_NAME }, { "host", 'h', 0, G_OPTION_ARG_STRING, &host, N_( "Host to connect"), NULL }, + { "colors", 'c', 0, G_OPTION_ARG_CALLBACK, optcolors, N_( "Set reported colors (8/16)" ), "16" }, + { NULL } }; - GOptionContext * options = g_option_context_new (_("- 3270 Emulator for Gtk")); - GError * error = NULL; + GOptionContext * context = g_option_context_new (_("- 3270 Emulator for Gtk")); + GError * error = NULL; + GOptionGroup * group = g_option_group_new( PACKAGE_NAME, NULL, NULL, &cmdline_opt, NULL); + + g_option_context_set_main_group(context, group); - g_option_context_add_main_entries(options, app_options, NULL); + g_option_context_add_main_entries(context, app_options, NULL); - if(!g_option_context_parse( options, &argc, &argv, &error )) + if(!g_option_context_parse( context, &argc, &argv, &error )) { int f; GString * str; @@ -225,6 +258,7 @@ int main(int argc, char *argv[]) return -1; } + } { @@ -274,6 +308,7 @@ int main(int argc, char *argv[]) toplevel = pw3270_new(host); pw3270_set_session_name(toplevel,session_name); + pw3270_set_session_options(toplevel,cmdline_opt.host); toplevel_setup(GTK_WINDOW(toplevel)); diff --git a/src/pw3270/v3270/widget.c b/src/pw3270/v3270/widget.c index a92cdd3..cab60c0 100644 --- a/src/pw3270/v3270/widget.c +++ b/src/pw3270/v3270/widget.c @@ -1438,6 +1438,12 @@ void v3270_set_session_name(GtkWidget *widget, const gchar *name) GTK_V3270(widget)->session_name = g_strdup(name); } +void v3270_set_session_options(GtkWidget *widget, LIB3270_OPTION options) +{ + g_return_if_fail(GTK_IS_V3270(widget)); + lib3270_set_options(GTK_V3270(widget)->host,options); +} + gboolean v3270_is_connected(GtkWidget *widget) { g_return_val_if_fail(GTK_IS_V3270(widget),FALSE); diff --git a/src/pw3270/window.c b/src/pw3270/window.c index 73e7898..88cd058 100644 --- a/src/pw3270/window.c +++ b/src/pw3270/window.c @@ -233,6 +233,12 @@ gtk_window_set_title(GTK_WINDOW(widget),name); } + LIB3270_EXPORT void pw3270_set_session_options(GtkWidget *widget, LIB3270_OPTION options) + { + g_return_if_fail(GTK_IS_PW3270(widget)); + v3270_set_session_options(GTK_PW3270(widget)->terminal,options); + } + static void chktoplevel(GtkWidget *window, GtkWidget **widget) { if(*widget) -- libgit2 0.21.2