Commit b962a055db341bbd21bad07c61ed5833b30e4cf5

Authored by Perry Werneck
1 parent c80d53ee

Working on command line session file parser.

src/include/pw3270/application.h
@@ -90,8 +90,6 @@ GtkBuilder * pw3270_application_get_builder(const gchar *name); @@ -90,8 +90,6 @@ GtkBuilder * pw3270_application_get_builder(const gchar *name);
90 90
91 void gtk_container_remove_all(GtkContainer *container); 91 void gtk_container_remove_all(GtkContainer *container);
92 92
93 -gboolean pw3270_application_allow_tabs(GApplication *application);  
94 -  
95 // Actions 93 // Actions
96 void pw3270_application_print_copy_activated(GAction *action, GVariant *parameter, GtkWidget *terminal); 94 void pw3270_application_print_copy_activated(GAction *action, GVariant *parameter, GtkWidget *terminal);
97 void pw3270_application_save_copy_activated(GAction *action, GVariant *parameter, GtkWidget *terminal); 95 void pw3270_application_save_copy_activated(GAction *action, GVariant *parameter, GtkWidget *terminal);
src/objects/application/application.c
@@ -57,8 +57,6 @@ struct _pw3270Application { @@ -57,8 +57,6 @@ struct _pw3270Application {
57 GSettings * settings; 57 GSettings * settings;
58 GList * keypads; 58 GList * keypads;
59 gchar * logfile; 59 gchar * logfile;
60 - gboolean allow_tabs; ///< @brief Always open window.  
61 -  
62 GSList * plugins; ///< @brief Handlers of the loaded plugins. 60 GSList * plugins; ///< @brief Handlers of the loaded plugins.
63 PW3270_UI_STYLE ui_style; 61 PW3270_UI_STYLE ui_style;
64 62
@@ -230,17 +228,6 @@ static gboolean on_user_interface(const gchar G_GNUC_UNUSED(*option), const gcha @@ -230,17 +228,6 @@ static gboolean on_user_interface(const gchar G_GNUC_UNUSED(*option), const gcha
230 228
231 } 229 }
232 230
233 -static gboolean on_allow_tabs(const gchar G_GNUC_UNUSED(*option), const gchar *value, gpointer G_GNUC_UNUSED(dunno), GError **error) {  
234 - pw3270Application *app = PW3270_APPLICATION(g_application_get_default());  
235 - app->allow_tabs = (g_ascii_strcasecmp(value,"no") != 0);  
236 - if(app->allow_tabs) {  
237 - g_message("Opening new sessions on tabs");  
238 - } else {  
239 - g_message("Opening new sessions on windows");  
240 - }  
241 - return TRUE;  
242 -}  
243 -  
244 static gboolean on_logfile(const gchar G_GNUC_UNUSED(*option), const gchar *value, gpointer G_GNUC_UNUSED(dunno), GError **error) { 231 static gboolean on_logfile(const gchar G_GNUC_UNUSED(*option), const gchar *value, gpointer G_GNUC_UNUSED(dunno), GError **error) {
245 pw3270_application_set_log_filename(g_application_get_default(),value); 232 pw3270_application_set_log_filename(g_application_get_default(),value);
246 return TRUE; 233 return TRUE;
@@ -251,14 +238,11 @@ static void pw3270Application_init(pw3270Application *app) { @@ -251,14 +238,11 @@ static void pw3270Application_init(pw3270Application *app) {
251 static GOptionEntry cmd_options[] = { 238 static GOptionEntry cmd_options[] = {
252 239
253 { "user-interface", 'U', 0, G_OPTION_ARG_CALLBACK, &on_user_interface, N_( "Set the user-interface type" ), NULL }, 240 { "user-interface", 'U', 0, G_OPTION_ARG_CALLBACK, &on_user_interface, N_( "Set the user-interface type" ), NULL },
254 - { "allow-tabs", 'T', 0, G_OPTION_ARG_CALLBACK, &on_allow_tabs, N_( "If 'no' allways open a window" ), NULL },  
255 { "logfile", 'l', 0, G_OPTION_ARG_CALLBACK, &on_logfile, N_( "Set default log file name" ), NULL }, 241 { "logfile", 'l', 0, G_OPTION_ARG_CALLBACK, &on_logfile, N_( "Set default log file name" ), NULL },
256 { NULL } 242 { NULL }
257 243
258 }; 244 };
259 245
260 - app->allow_tabs = TRUE;  
261 -  
262 g_application_add_main_option_entries(G_APPLICATION(app), cmd_options); 246 g_application_add_main_option_entries(G_APPLICATION(app), cmd_options);
263 247
264 #ifdef _WIN32 248 #ifdef _WIN32
@@ -558,11 +542,6 @@ void pw3270_application_plugin_foreach(GApplication *app, GFunc func, gpointer u @@ -558,11 +542,6 @@ void pw3270_application_plugin_foreach(GApplication *app, GFunc func, gpointer u
558 542
559 } 543 }
560 544
561 -gboolean pw3270_application_allow_tabs(GApplication *app) {  
562 - g_return_val_if_fail(PW3270_IS_APPLICATION(app),TRUE);  
563 - return PW3270_APPLICATION(app)->allow_tabs;  
564 -}  
565 -  
566 void pw3270_application_plugin_call(GApplication *app, const gchar *method, gpointer user_data) { 545 void pw3270_application_plugin_call(GApplication *app, const gchar *method, gpointer user_data) {
567 546
568 g_return_if_fail(PW3270_IS_APPLICATION(app)); 547 g_return_if_fail(PW3270_IS_APPLICATION(app));
src/objects/application/open.c
@@ -70,16 +70,70 @@ gchar * v3270_keyfile_find(const gchar *name) { @@ -70,16 +70,70 @@ gchar * v3270_keyfile_find(const gchar *name) {
70 70
71 } 71 }
72 72
73 -void pw3270_application_open(GApplication *application, GFile **files, gint n_files, const gchar G_GNUC_UNUSED(*hint)) { 73 +/// @brief Open session file
  74 +static void open(GtkApplication *application, const gchar *filename) {
  75 +
  76 + g_message("Opening '%s'",filename);
  77 +
  78 + GtkWindow *window = GTK_WINDOW(pw3270_application_window_new(application, filename));
  79 + gtk_window_present(window);
  80 +
  81 +}
  82 +
  83 +void pw3270_application_open_file(GtkApplication *application, GFile *file) {
  84 +
  85 +// GtkWidget * window = gtk_application_get_active_window(application);
  86 + g_autofree gchar * scheme = g_file_get_uri_scheme(file);
  87 +
  88 + if(g_ascii_strcasecmp(scheme,"file") == 0) {
  89 +
  90 + // It's a file scheme.
  91 + if(g_file_query_exists(file,NULL)) {
  92 +
  93 + // The file exists, load it.
  94 + g_autofree gchar *filename = g_file_get_path(file);
  95 + open(application,filename);
  96 +
  97 + } else {
  98 +
  99 + // The file doesn't exist, search for.
  100 + g_autofree gchar * basename = g_file_get_basename(file);
  101 + g_autofree gchar * filename = v3270_keyfile_find(basename);
  102 +
  103 + if(filename) {
  104 + open(application,filename);
  105 + } else {
  106 + g_warning("Cant find session '%s'",basename);
  107 + }
  108 +
  109 + }
  110 +
  111 + } else if(g_ascii_strcasecmp(scheme,"tn3270") == 0 || g_ascii_strcasecmp(scheme,"tn3270s") == 0) {
  112 +
  113 +
  114 + } else {
  115 +
  116 + g_warning("Don't know how to handle '%s' scheme",scheme);
  117 +
  118 + }
  119 +
  120 +
  121 +
  122 +}
74 123
75 - GtkWidget * window = GTK_WIDGET(gtk_application_get_active_window(GTK_APPLICATION(application))); 124 +void pw3270_application_open(GApplication *application, GFile **files, gint n_files, const gchar G_GNUC_UNUSED(*hint)) {
76 125
77 gint file; 126 gint file;
78 127
79 - debug("%s files=%d",__FUNCTION__,n_files); 128 + debug("\n\n%s files=%d",__FUNCTION__,n_files);
80 129
81 for(file = 0; file < n_files; file++) { 130 for(file = 0; file < n_files; file++) {
82 131
  132 + debug("%s(%d,%p)",__FUNCTION__,file,files[file]);
  133 + pw3270_application_open_file(GTK_APPLICATION(application),files[file]);
  134 +
  135 + /*
  136 +
83 g_autofree gchar *path = g_file_get_path(files[file]); 137 g_autofree gchar *path = g_file_get_path(files[file]);
84 138
85 if(!path) { 139 if(!path) {
@@ -152,10 +206,11 @@ void pw3270_application_open(GApplication *application, GFile **files, gint n_fi @@ -152,10 +206,11 @@ void pw3270_application_open(GApplication *application, GFile **files, gint n_fi
152 206
153 } 207 }
154 208
  209 + */
155 } 210 }
156 211
157 - if(window)  
158 - gtk_window_present(GTK_WINDOW(window)); 212 +// if(window)
  213 +// gtk_window_present(GTK_WINDOW(window));
159 214
160 } 215 }
161 216