Commit 3f0a2779ace926ff3b37760c8b1a33dd706abc18
1 parent
34dc0b37
Exists in
master
and in
4 other branches
Fixing gtk/glib warnings
Fixing performance issues in session file.
Showing
7 changed files
with
95 additions
and
66 deletions
Show diff stats
Makefile.in
@@ -265,7 +265,7 @@ run: \ | @@ -265,7 +265,7 @@ run: \ | ||
265 | $(BINDBG)/$(PACKAGE_NAME)@EXEEXT@ \ | 265 | $(BINDBG)/$(PACKAGE_NAME)@EXEEXT@ \ |
266 | gschemas.compiled | 266 | gschemas.compiled |
267 | 267 | ||
268 | - @LD_LIBRARY_PATH=$(BINDBG) \ | 268 | + @G_DEBUG=fatal-warnings \ |
269 | $(BINDBG)/$(PACKAGE_NAME)@EXEEXT@ | 269 | $(BINDBG)/$(PACKAGE_NAME)@EXEEXT@ |
270 | 270 | ||
271 | mem-check: \ | 271 | mem-check: \ |
src/objects/actions/lib3270/pakey.c
@@ -100,14 +100,15 @@ | @@ -100,14 +100,15 @@ | ||
100 | } | 100 | } |
101 | 101 | ||
102 | void Lib3270PaAction_init(Lib3270PaAction *object) { | 102 | void Lib3270PaAction_init(Lib3270PaAction *object) { |
103 | - pw3270Action * action = PW3270_ACTION(object); | ||
104 | - | ||
105 | - action->activate = activate; | ||
106 | - action->name = "pakey"; | ||
107 | } | 103 | } |
108 | 104 | ||
109 | 105 | ||
110 | GAction * pw3270_action_new_pakey(void) { | 106 | GAction * pw3270_action_new_pakey(void) { |
111 | - return G_ACTION(g_object_new(PW3270_TYPE_PAKEY_ACTION, NULL)); | 107 | + pw3270Action * action = PW3270_ACTION(g_object_new(PW3270_TYPE_PAKEY_ACTION, NULL)); |
108 | + | ||
109 | + action->activate = activate; | ||
110 | + action->name = "pakey"; | ||
111 | + | ||
112 | + return G_ACTION(action); | ||
112 | } | 113 | } |
113 | 114 |
src/objects/actions/lib3270/pfkey.c
@@ -100,14 +100,16 @@ | @@ -100,14 +100,16 @@ | ||
100 | } | 100 | } |
101 | 101 | ||
102 | void Lib3270PfAction_init(Lib3270PfAction *action) { | 102 | void Lib3270PfAction_init(Lib3270PfAction *action) { |
103 | - | ||
104 | - action->parent.activate = activate; | ||
105 | - action->parent.name = "pfkey"; | ||
106 | - | ||
107 | } | 103 | } |
108 | 104 | ||
109 | GAction * pw3270_action_new_pfkey(void) { | 105 | GAction * pw3270_action_new_pfkey(void) { |
110 | - return G_ACTION(g_object_new(PW3270_TYPE_PFKEY_ACTION, NULL)); | 106 | + |
107 | + pw3270Action * action = PW3270_ACTION(g_object_new(PW3270_TYPE_PFKEY_ACTION, NULL)); | ||
108 | + | ||
109 | + action->activate = activate; | ||
110 | + action->name = "pfkey"; | ||
111 | + | ||
112 | + return G_ACTION(action); | ||
111 | } | 113 | } |
112 | 114 | ||
113 | 115 |
src/objects/actions/window.c
@@ -83,6 +83,7 @@ | @@ -83,6 +83,7 @@ | ||
83 | }; | 83 | }; |
84 | 84 | ||
85 | for(ix = 0; ix < G_N_ELEMENTS(actions); ix++) { | 85 | for(ix = 0; ix < G_N_ELEMENTS(actions); ix++) { |
86 | + debug("Creating action %u (%s)", (unsigned int) ix, g_action_get_name(actions[ix])); | ||
86 | g_action_map_add_action(map,actions[ix]); | 87 | g_action_map_add_action(map,actions[ix]); |
87 | } | 88 | } |
88 | } | 89 | } |
src/objects/application/actions/window.c
@@ -56,7 +56,7 @@ | @@ -56,7 +56,7 @@ | ||
56 | 56 | ||
57 | } | 57 | } |
58 | 58 | ||
59 | - void pw3270_application_new_tab_activated(GSimpleAction G_GNUC_UNUSED(* action), GVariant G_GNUC_UNUSED(*parameter), gpointer application) { | 59 | + void pw3270_application_new_tab_activated(GSimpleAction G_GNUC_UNUSED(*action), GVariant G_GNUC_UNUSED(*parameter), gpointer application) { |
60 | 60 | ||
61 | debug("%s",__FUNCTION__); | 61 | debug("%s",__FUNCTION__); |
62 | pw3270_terminal_new(GTK_WIDGET(gtk_application_get_active_window(GTK_APPLICATION(application))), NULL); | 62 | pw3270_terminal_new(GTK_WIDGET(gtk_application_get_active_window(GTK_APPLICATION(application))), NULL); |
src/objects/window/terminal.c
@@ -33,6 +33,13 @@ | @@ -33,6 +33,13 @@ | ||
33 | #include <v3270/settings.h> | 33 | #include <v3270/settings.h> |
34 | #include <v3270/actions.h> | 34 | #include <v3270/actions.h> |
35 | 35 | ||
36 | + struct SessionDescriptor | ||
37 | + { | ||
38 | + gboolean changed; ///< @brief Save file? | ||
39 | + GKeyFile * key_file; | ||
40 | + gchar filename[1]; | ||
41 | + }; | ||
42 | + | ||
36 | static void session_changed(GtkWidget *terminal, GtkWidget *label) { | 43 | static void session_changed(GtkWidget *terminal, GtkWidget *label) { |
37 | 44 | ||
38 | gtk_label_set_text(GTK_LABEL(label),v3270_get_session_name(terminal)); | 45 | gtk_label_set_text(GTK_LABEL(label),v3270_get_session_name(terminal)); |
@@ -89,8 +96,37 @@ | @@ -89,8 +96,37 @@ | ||
89 | return FALSE; | 96 | return FALSE; |
90 | } | 97 | } |
91 | 98 | ||
99 | + static void check_for_session_changed(GtkWidget *terminal) { | ||
100 | + | ||
101 | + struct SessionDescriptor * session = (struct SessionDescriptor *) g_object_get_data(G_OBJECT(terminal),"session-descriptor"); | ||
102 | + | ||
103 | + if(session->changed) { | ||
104 | + | ||
105 | + session->changed = FALSE; | ||
106 | + | ||
107 | + GError * error = NULL; | ||
108 | + g_key_file_save_to_file(session->key_file,session->filename,&error); | ||
109 | + | ||
110 | + if(error) { | ||
111 | + | ||
112 | + g_warning("Can't save \"%s\": %s",session->filename,error->message); | ||
113 | + g_error_free(error); | ||
114 | + | ||
115 | + } else { | ||
116 | + | ||
117 | + g_message("Session was saved to %s",session->filename); | ||
118 | + | ||
119 | + } | ||
120 | + | ||
121 | + } | ||
122 | + | ||
123 | + } | ||
124 | + | ||
125 | + | ||
92 | static void on_terminal_destroy(GtkWidget *terminal, GtkWindow * window) { | 126 | static void on_terminal_destroy(GtkWidget *terminal, GtkWindow * window) { |
93 | 127 | ||
128 | + check_for_session_changed(terminal); | ||
129 | + | ||
94 | if(gtk_window_get_default_widget(window) != terminal) { | 130 | if(gtk_window_get_default_widget(window) != terminal) { |
95 | return; | 131 | return; |
96 | } | 132 | } |
@@ -116,12 +152,6 @@ | @@ -116,12 +152,6 @@ | ||
116 | 152 | ||
117 | } | 153 | } |
118 | 154 | ||
119 | - | ||
120 | - static gboolean bg_auto_connect(GtkWidget *terminal) { | ||
121 | - v3270_reconnect(terminal); | ||
122 | - return FALSE; | ||
123 | - } | ||
124 | - | ||
125 | static void disconnected(GtkWidget *terminal, GtkWindow * window) { | 155 | static void disconnected(GtkWidget *terminal, GtkWindow * window) { |
126 | 156 | ||
127 | debug("%s",__FUNCTION__); | 157 | debug("%s",__FUNCTION__); |
@@ -205,85 +235,84 @@ | @@ -205,85 +235,84 @@ | ||
205 | 235 | ||
206 | // Setup session. | 236 | // Setup session. |
207 | 237 | ||
208 | - H3270 * hSession = v3270_get_session(terminal); | ||
209 | - | ||
210 | - if(lib3270_get_toggle(hSession,LIB3270_TOGGLE_CONNECT_ON_STARTUP)) | ||
211 | - g_idle_add((GSourceFunc) bg_auto_connect, terminal); | 238 | +// H3270 * hSession = v3270_get_session(terminal); |
212 | 239 | ||
213 | return page; | 240 | return page; |
214 | 241 | ||
215 | } | 242 | } |
216 | 243 | ||
217 | - static void save_settings(GtkWidget *terminal, const gchar *filename) { | ||
218 | - | ||
219 | - GError *error = NULL; | ||
220 | - GKeyFile * key_file = g_key_file_new(); | ||
221 | - | ||
222 | - g_key_file_load_from_file(key_file,filename,G_KEY_FILE_NONE,&error); | ||
223 | - | ||
224 | - if(error) { | ||
225 | - | ||
226 | - g_warning("Can't load \"%s\": %s",filename,error->message); | ||
227 | - g_error_free(error); | ||
228 | - return; | ||
229 | - | ||
230 | - } | 244 | + static void save_settings(GtkWidget *terminal, struct SessionDescriptor * session) { |
231 | 245 | ||
232 | - v3270_to_key_file(terminal,key_file,"terminal"); | ||
233 | - v3270_accelerator_map_to_key_file(terminal, key_file, "accelerators"); | 246 | + debug("************************************* %s",__FUNCTION__); |
247 | + v3270_to_key_file(terminal,session->key_file,"terminal"); | ||
248 | + v3270_accelerator_map_to_key_file(terminal, session->key_file, "accelerators"); | ||
234 | 249 | ||
235 | - g_key_file_save_to_file(key_file,filename,&error); | 250 | + session->changed = TRUE; |
236 | 251 | ||
237 | - if(error) { | 252 | + } |
238 | 253 | ||
239 | - g_warning("Can't save \"%s\": %s",filename,error->message); | ||
240 | - g_error_free(error); | 254 | + static void toggle_changed(G_GNUC_UNUSED v3270 *widget, G_GNUC_UNUSED LIB3270_TOGGLE_ID toggle_id, gboolean toggle_state, const gchar *toggle_name, struct SessionDescriptor * session) { |
255 | + debug("%s(%s)=%s",__FUNCTION__,toggle_name,toggle_state ? "ON" : "OFF"); | ||
256 | + g_key_file_set_boolean(session->key_file,"terminal",toggle_name,toggle_state); | ||
257 | + session->changed = TRUE; | ||
258 | + } | ||
241 | 259 | ||
242 | - } else { | 260 | + static void close_settings(struct SessionDescriptor * session) { |
243 | 261 | ||
244 | - g_message("Session properties save to %s",filename); | ||
245 | - } | 262 | + if(session->key_file) { |
246 | 263 | ||
247 | - g_key_file_free(key_file); | 264 | + if(session->changed) { |
265 | + g_message("Saving file %s",session->filename); | ||
266 | + g_key_file_save_to_file(session->key_file,session->filename,NULL); | ||
267 | + } else { | ||
268 | + g_message("Closing file %s",session->filename); | ||
269 | + } | ||
248 | 270 | ||
271 | + g_key_file_free(session->key_file); | ||
272 | + session->key_file = NULL; | ||
273 | + } | ||
249 | 274 | ||
275 | + g_free(session); | ||
250 | } | 276 | } |
251 | 277 | ||
252 | - | ||
253 | GtkWidget * pw3270_terminal_new(GtkWidget *widget, const gchar *session_file) { | 278 | GtkWidget * pw3270_terminal_new(GtkWidget *widget, const gchar *session_file) { |
254 | 279 | ||
280 | + struct SessionDescriptor * descriptor; | ||
281 | + | ||
255 | g_return_val_if_fail(PW3270_IS_APPLICATION_WINDOW(widget),NULL); | 282 | g_return_val_if_fail(PW3270_IS_APPLICATION_WINDOW(widget),NULL); |
256 | 283 | ||
257 | pw3270ApplicationWindow * window = PW3270_APPLICATION_WINDOW(widget); | 284 | pw3270ApplicationWindow * window = PW3270_APPLICATION_WINDOW(widget); |
258 | GtkWidget * terminal = v3270_new(); | 285 | GtkWidget * terminal = v3270_new(); |
259 | 286 | ||
260 | - gchar * filename; | ||
261 | - | ||
262 | if(session_file) { | 287 | if(session_file) { |
263 | 288 | ||
264 | // Use the supplied session file | 289 | // Use the supplied session file |
265 | - filename = g_strdup(session_file); | 290 | + descriptor = g_malloc0(sizeof(struct SessionDescriptor) + strlen(session_file)); |
291 | + strcpy(descriptor->filename,session_file); | ||
266 | 292 | ||
267 | } else { | 293 | } else { |
268 | 294 | ||
269 | // No session file, use the default one. | 295 | // No session file, use the default one. |
270 | - filename = g_build_filename(g_get_user_config_dir(),G_STRINGIFY(PRODUCT_NAME) ".conf",NULL); | 296 | + g_autofree gchar * filename = g_build_filename(g_get_user_config_dir(),G_STRINGIFY(PRODUCT_NAME) ".conf",NULL); |
297 | + | ||
298 | + descriptor = g_malloc0(sizeof(struct SessionDescriptor) + strlen(filename)); | ||
299 | + strcpy(descriptor->filename,filename); | ||
271 | 300 | ||
272 | } | 301 | } |
273 | 302 | ||
274 | // Setup session file; | 303 | // Setup session file; |
275 | GError *error = NULL; | 304 | GError *error = NULL; |
276 | - g_object_set_data_full(G_OBJECT(terminal),"session-file-name",filename,g_free); | 305 | + g_object_set_data_full(G_OBJECT(terminal),"session-descriptor",descriptor,(GDestroyNotify) close_settings); |
277 | 306 | ||
278 | - GKeyFile * key_file = g_key_file_new(); | 307 | + descriptor->key_file = g_key_file_new(); |
279 | 308 | ||
280 | - if(g_file_test(filename,G_FILE_TEST_IS_REGULAR)) { | 309 | + if(g_file_test(descriptor->filename,G_FILE_TEST_IS_REGULAR)) { |
281 | 310 | ||
282 | // Found session file, open it. | 311 | // Found session file, open it. |
283 | - if(!g_key_file_load_from_file(key_file,filename,G_KEY_FILE_NONE,&error)) { | ||
284 | - g_warning("Can't load \"%s\"",filename); | 312 | + if(!g_key_file_load_from_file(descriptor->key_file,descriptor->filename,G_KEY_FILE_NONE,&error)) { |
313 | + g_warning("Can't load \"%s\"",descriptor->filename); | ||
285 | } else { | 314 | } else { |
286 | - g_message("Loading session properties from %s",filename); | 315 | + g_message("Loading session properties from %s",descriptor->filename); |
287 | } | 316 | } |
288 | 317 | ||
289 | } else { | 318 | } else { |
@@ -291,7 +320,7 @@ | @@ -291,7 +320,7 @@ | ||
291 | // No session file, load the defaults (if available). | 320 | // No session file, load the defaults (if available). |
292 | lib3270_autoptr(char) default_settings = lib3270_build_data_filename("defaults.conf",NULL); | 321 | lib3270_autoptr(char) default_settings = lib3270_build_data_filename("defaults.conf",NULL); |
293 | if(g_file_test(default_settings,G_FILE_TEST_IS_REGULAR)) { | 322 | if(g_file_test(default_settings,G_FILE_TEST_IS_REGULAR)) { |
294 | - if(!g_key_file_load_from_file(key_file,default_settings,G_KEY_FILE_NONE,&error)) { | 323 | + if(!g_key_file_load_from_file(descriptor->key_file,default_settings,G_KEY_FILE_NONE,&error)) { |
295 | g_warning("Can't load \"%s\"",default_settings); | 324 | g_warning("Can't load \"%s\"",default_settings); |
296 | } else { | 325 | } else { |
297 | g_message("Loading session properties from %s",default_settings); | 326 | g_message("Loading session properties from %s",default_settings); |
@@ -310,17 +339,16 @@ | @@ -310,17 +339,16 @@ | ||
310 | 339 | ||
311 | } else { | 340 | } else { |
312 | 341 | ||
313 | - v3270_load_key_file(terminal,key_file,NULL); | ||
314 | - v3270_accelerator_map_load_key_file(terminal,key_file,NULL); | 342 | + v3270_load_key_file(terminal,descriptor->key_file,NULL); |
343 | + v3270_accelerator_map_load_key_file(terminal,descriptor->key_file,NULL); | ||
315 | 344 | ||
316 | } | 345 | } |
317 | 346 | ||
318 | - g_key_file_free(key_file); | ||
319 | - | ||
320 | append_terminal_page(window,terminal); | 347 | append_terminal_page(window,terminal); |
321 | 348 | ||
322 | // Setup signals. | 349 | // Setup signals. |
323 | - g_signal_connect(G_OBJECT(terminal),"save-settings",G_CALLBACK(save_settings),filename); | 350 | + g_signal_connect(G_OBJECT(terminal),"save-settings",G_CALLBACK(save_settings),descriptor); |
351 | + g_signal_connect(G_OBJECT(terminal),"toggle_changed",G_CALLBACK(toggle_changed),descriptor); | ||
324 | 352 | ||
325 | return terminal; | 353 | return terminal; |
326 | 354 |
src/pw3270/window.c
@@ -306,9 +306,6 @@ static GtkWidget * trace_window = NULL; | @@ -306,9 +306,6 @@ static GtkWidget * trace_window = NULL; | ||
306 | 306 | ||
307 | v3270_set_scaled_fonts(GTK_PW3270(widget)->terminal,get_boolean_from_config("terminal","sfonts",FALSE)); | 307 | v3270_set_scaled_fonts(GTK_PW3270(widget)->terminal,get_boolean_from_config("terminal","sfonts",FALSE)); |
308 | 308 | ||
309 | - if(pw3270_get_toggle(widget,LIB3270_TOGGLE_CONNECT_ON_STARTUP)) | ||
310 | - g_idle_add((GSourceFunc) bg_auto_connect, widget); | ||
311 | - | ||
312 | return widget; | 309 | return widget; |
313 | } | 310 | } |
314 | 311 |