Commit 350429563725483de296f813275041e650d4e3a9
1 parent
3001f886
Exists in
master
and in
4 other branches
Adding support for session settings file.
Showing
4 changed files
with
105 additions
and
4 deletions
Show diff stats
src/include/pw3270/window.h
| ... | ... | @@ -60,7 +60,7 @@ |
| 60 | 60 | GtkWidget * pw3270_application_window_new(GtkApplication * app); |
| 61 | 61 | |
| 62 | 62 | /// @brief Create a new terminal tab. |
| 63 | - GtkWidget * pw3270_terminal_new(GtkWidget *window); | |
| 63 | + GtkWidget * pw3270_terminal_new(GtkWidget *window, const gchar *session_file); | |
| 64 | 64 | |
| 65 | 65 | /// @brief Get the active terminal widget. |
| 66 | 66 | GtkWidget * pw3270_window_get_terminal_widget(GtkWidget *window); | ... | ... |
src/objects/application/actions/window.c
| ... | ... | @@ -59,7 +59,7 @@ |
| 59 | 59 | void pw3270_application_new_tab_activated(GSimpleAction G_GNUC_UNUSED(* action), GVariant G_GNUC_UNUSED(*parameter), gpointer application) { |
| 60 | 60 | |
| 61 | 61 | debug("%s",__FUNCTION__); |
| 62 | - pw3270_terminal_new(GTK_WIDGET(gtk_application_get_active_window(GTK_APPLICATION(application)))); | |
| 62 | + pw3270_terminal_new(GTK_WIDGET(gtk_application_get_active_window(GTK_APPLICATION(application))), NULL); | |
| 63 | 63 | |
| 64 | 64 | } |
| 65 | 65 | ... | ... |
src/objects/application/application.c
| ... | ... | @@ -283,7 +283,7 @@ |
| 283 | 283 | GtkWidget * window = pw3270_application_window_new(GTK_APPLICATION(application)); |
| 284 | 284 | |
| 285 | 285 | // Create terminal widget & associated widget |
| 286 | - GtkWidget * terminal = pw3270_terminal_new(window); | |
| 286 | + GtkWidget * terminal = pw3270_terminal_new(window, NULL); | |
| 287 | 287 | |
| 288 | 288 | // Create property actions |
| 289 | 289 | static const gchar * properties[] = { | ... | ... |
src/objects/window/terminal.c
| ... | ... | @@ -30,6 +30,8 @@ |
| 30 | 30 | #include "private.h" |
| 31 | 31 | #include <pw3270/actions.h> |
| 32 | 32 | #include <lib3270/toggle.h> |
| 33 | + #include <v3270/settings.h> | |
| 34 | + #include <v3270/actions.h> | |
| 33 | 35 | |
| 34 | 36 | static void session_changed(GtkWidget *terminal, GtkWidget *label) { |
| 35 | 37 | |
| ... | ... | @@ -212,15 +214,114 @@ |
| 212 | 214 | |
| 213 | 215 | } |
| 214 | 216 | |
| 215 | - GtkWidget * pw3270_terminal_new(GtkWidget *widget) { | |
| 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 | + } | |
| 231 | + | |
| 232 | + v3270_to_key_file(terminal,key_file,"terminal"); | |
| 233 | + v3270_accelerator_map_to_key_file(terminal, key_file, "accelerators"); | |
| 234 | + | |
| 235 | + g_key_file_save_to_file(key_file,"terminal.conf",&error); | |
| 236 | + | |
| 237 | + if(error) { | |
| 238 | + | |
| 239 | + g_warning("Can't save \"%s\": %s",filename,error->message); | |
| 240 | + g_error_free(error); | |
| 241 | + | |
| 242 | + } else { | |
| 243 | + | |
| 244 | + g_message("Session properties save to %s",filename); | |
| 245 | + } | |
| 246 | + | |
| 247 | + g_key_file_free(key_file); | |
| 248 | + | |
| 249 | + | |
| 250 | + } | |
| 251 | + | |
| 252 | + | |
| 253 | + GtkWidget * pw3270_terminal_new(GtkWidget *widget, const gchar *session_file) { | |
| 216 | 254 | |
| 217 | 255 | g_return_val_if_fail(PW3270_IS_APPLICATION_WINDOW(widget),NULL); |
| 218 | 256 | |
| 219 | 257 | pw3270ApplicationWindow * window = PW3270_APPLICATION_WINDOW(widget); |
| 220 | 258 | GtkWidget * terminal = v3270_new(); |
| 221 | 259 | |
| 260 | + gchar * filename; | |
| 261 | + | |
| 262 | + if(session_file) { | |
| 263 | + | |
| 264 | + // Use the supplied session file | |
| 265 | + filename = g_strdup(session_file); | |
| 266 | + | |
| 267 | + } else { | |
| 268 | + | |
| 269 | + // No session file, use the default one. | |
| 270 | + filename = g_build_filename(g_get_user_config_dir(),G_STRINGIFY(PRODUCT_NAME) ".conf",NULL); | |
| 271 | + | |
| 272 | + } | |
| 273 | + | |
| 274 | + // Setup session file; | |
| 275 | + GError *error = NULL; | |
| 276 | + g_object_set_data_full(G_OBJECT(terminal),"session-file-name",filename,g_free); | |
| 277 | + | |
| 278 | + GKeyFile * key_file = g_key_file_new(); | |
| 279 | + | |
| 280 | + if(g_file_test(filename,G_FILE_TEST_IS_REGULAR)) { | |
| 281 | + | |
| 282 | + // 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); | |
| 285 | + } else { | |
| 286 | + g_message("Loading session properties from %s",filename); | |
| 287 | + } | |
| 288 | + | |
| 289 | + } else { | |
| 290 | + | |
| 291 | + // No session file, load the defaults (if available). | |
| 292 | + lib3270_autoptr(char) default_settings = lib3270_build_data_filename("defaults.conf",NULL); | |
| 293 | + 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)) { | |
| 295 | + g_warning("Can't load \"%s\"",default_settings); | |
| 296 | + } else { | |
| 297 | + g_message("Loading session properties from %s",default_settings); | |
| 298 | + } | |
| 299 | + } else { | |
| 300 | + g_warning("Can't find default settings file \"%s\"",default_settings); | |
| 301 | + } | |
| 302 | + | |
| 303 | + } | |
| 304 | + | |
| 305 | + if(error) { | |
| 306 | + | |
| 307 | + g_warning(error->message); | |
| 308 | + g_error_free(error); | |
| 309 | + error = NULL; | |
| 310 | + | |
| 311 | + } else { | |
| 312 | + | |
| 313 | + v3270_load_key_file(terminal,key_file,NULL); | |
| 314 | + v3270_accelerator_map_load_key_file(terminal,key_file,NULL); | |
| 315 | + | |
| 316 | + } | |
| 317 | + | |
| 318 | + g_key_file_free(key_file); | |
| 319 | + | |
| 222 | 320 | append_terminal_page(window,terminal); |
| 223 | 321 | |
| 322 | + // Setup signals. | |
| 323 | + g_signal_connect(G_OBJECT(terminal),"save-settings",G_CALLBACK(save_settings),filename); | |
| 324 | + | |
| 224 | 325 | return terminal; |
| 225 | 326 | |
| 226 | 327 | } | ... | ... |