Commit 4fc113f7e687c1433f8155bff74d7835877d29eb

Authored by Perry Werneck
1 parent 14bc5874

Loading keypad models on application startup.

pw3270.cbp
... ... @@ -46,6 +46,7 @@
46 46 <Unit filename="src/include/pw3270.h" />
47 47 <Unit filename="src/include/pw3270/actions.h" />
48 48 <Unit filename="src/include/pw3270/application.h" />
  49 + <Unit filename="src/include/pw3270/keypad.h" />
49 50 <Unit filename="src/include/pw3270/settings.h" />
50 51 <Unit filename="src/include/pw3270/toolbar.h" />
51 52 <Unit filename="src/include/pw3270/window.h" />
... ... @@ -109,6 +110,22 @@
109 110 <Option compilerVar="CC" />
110 111 </Unit>
111 112 <Unit filename="src/objects/application/private.h" />
  113 + <Unit filename="src/objects/keypad/attribute.c">
  114 + <Option compilerVar="CC" />
  115 + </Unit>
  116 + <Unit filename="src/objects/keypad/element.c">
  117 + <Option compilerVar="CC" />
  118 + </Unit>
  119 + <Unit filename="src/objects/keypad/keypad.c">
  120 + <Option compilerVar="CC" />
  121 + </Unit>
  122 + <Unit filename="src/objects/keypad/load.c">
  123 + <Option compilerVar="CC" />
  124 + </Unit>
  125 + <Unit filename="src/objects/keypad/private.h" />
  126 + <Unit filename="src/objects/keypad/widget.c">
  127 + <Option compilerVar="CC" />
  128 + </Unit>
112 129 <Unit filename="src/objects/linux/savedesktopicon.c">
113 130 <Option compilerVar="CC" />
114 131 </Unit>
... ... @@ -168,9 +185,6 @@
168 185 <Unit filename="ui/application.xml" />
169 186 <Unit filename="ui/window.xml" />
170 187 <Extensions>
171   - <code_completion />
172   - <debugger />
173   - <envvars set="default" />
174 188 <DoxyBlocks>
175 189 <comment_style block="0" line="0" />
176 190 <doxyfile_project />
... ... @@ -180,6 +194,7 @@
180 194 <doxyfile_dot />
181 195 <general />
182 196 </DoxyBlocks>
  197 + <envvars set="default" />
183 198 </Extensions>
184 199 </Project>
185 200 </CodeBlocks_project_file>
... ...
src/objects/application/application.c
... ... @@ -35,6 +35,7 @@
35 35 #include <pw3270.h>
36 36 #include <pw3270/application.h>
37 37 #include <pw3270/actions.h>
  38 + #include <pw3270/keypad.h>
38 39 #include <stdlib.h>
39 40  
40 41 enum {
... ... @@ -54,6 +55,7 @@
54 55 GtkApplication parent;
55 56  
56 57 GSettings * settings;
  58 + GList * keypads;
57 59  
58 60 GSList * plugins; ///< @brief Handlers of the loaded plugins.
59 61  
... ... @@ -331,6 +333,7 @@
331 333 application->settings = NULL;
332 334 }
333 335  
  336 + g_list_free_full(application->keypads,g_object_unref);
334 337  
335 338 G_OBJECT_CLASS(pw3270Application_parent_class)->finalize(object);
336 339  
... ... @@ -350,6 +353,8 @@
350 353  
351 354 size_t ix;
352 355  
  356 + pw3270Application * app = PW3270_APPLICATION(application);
  357 +
353 358 G_APPLICATION_CLASS(pw3270Application_parent_class)->startup(application);
354 359  
355 360 GAction * actions[] = {
... ... @@ -379,6 +384,32 @@
379 384 }
380 385 #endif // DEBUG
381 386  
  387 +
  388 + //
  389 + // Load keypad models
  390 + //
  391 + {
  392 +#ifdef DEBUG
  393 + const gchar * keypad_path = "keypad";
  394 +#else
  395 + lib3270_autoptr(char) keypad_path = lib3270_build_data_filename("keypad",NULL);
  396 +#endif // DEBUG
  397 +
  398 + g_autoptr(GError) error = NULL;
  399 + g_autoptr(GDir) dir = g_dir_open(keypad_path,0,&error);
  400 +
  401 + const gchar *name = g_dir_read_name(dir);
  402 + while(!error && name) {
  403 + g_autofree gchar * path = g_build_filename(keypad_path,name,NULL);
  404 + app->keypads = pw3270_keypad_model_new_from_xml(app->keypads,path);
  405 + name = g_dir_read_name(dir);
  406 + }
  407 +
  408 + if(error) {
  409 + g_message("Can't read %s: %s",keypad_path,error->message);
  410 + }
  411 + }
  412 +
382 413 if(gtk_application_prefers_app_menu(GTK_APPLICATION(application)))
383 414 gtk_application_set_app_menu(GTK_APPLICATION (application), G_MENU_MODEL(gtk_builder_get_object (builder, "app-menu")));
384 415  
... ...