From 4fc113f7e687c1433f8155bff74d7835877d29eb Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Fri, 29 May 2020 12:40:04 -0300 Subject: [PATCH] Loading keypad models on application startup. --- pw3270.cbp | 21 ++++++++++++++++++--- src/objects/application/application.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/pw3270.cbp b/pw3270.cbp index ab69997..8d8f25f 100644 --- a/pw3270.cbp +++ b/pw3270.cbp @@ -46,6 +46,7 @@ + @@ -109,6 +110,22 @@ + + + + + + + + + + + @@ -168,9 +185,6 @@ - - - @@ -180,6 +194,7 @@ + diff --git a/src/objects/application/application.c b/src/objects/application/application.c index 4a0161b..07fcb8c 100644 --- a/src/objects/application/application.c +++ b/src/objects/application/application.c @@ -35,6 +35,7 @@ #include #include #include + #include #include enum { @@ -54,6 +55,7 @@ GtkApplication parent; GSettings * settings; + GList * keypads; GSList * plugins; ///< @brief Handlers of the loaded plugins. @@ -331,6 +333,7 @@ application->settings = NULL; } + g_list_free_full(application->keypads,g_object_unref); G_OBJECT_CLASS(pw3270Application_parent_class)->finalize(object); @@ -350,6 +353,8 @@ size_t ix; + pw3270Application * app = PW3270_APPLICATION(application); + G_APPLICATION_CLASS(pw3270Application_parent_class)->startup(application); GAction * actions[] = { @@ -379,6 +384,32 @@ } #endif // DEBUG + + // + // Load keypad models + // + { +#ifdef DEBUG + const gchar * keypad_path = "keypad"; +#else + lib3270_autoptr(char) keypad_path = lib3270_build_data_filename("keypad",NULL); +#endif // DEBUG + + g_autoptr(GError) error = NULL; + g_autoptr(GDir) dir = g_dir_open(keypad_path,0,&error); + + const gchar *name = g_dir_read_name(dir); + while(!error && name) { + g_autofree gchar * path = g_build_filename(keypad_path,name,NULL); + app->keypads = pw3270_keypad_model_new_from_xml(app->keypads,path); + name = g_dir_read_name(dir); + } + + if(error) { + g_message("Can't read %s: %s",keypad_path,error->message); + } + } + if(gtk_application_prefers_app_menu(GTK_APPLICATION(application))) gtk_application_set_app_menu(GTK_APPLICATION (application), G_MENU_MODEL(gtk_builder_get_object (builder, "app-menu"))); -- libgit2 0.21.2