Commit d83b690b1bacb8ffabdea49583e14f749fbaed8d
1 parent
bc758ecb
Exists in
master
and in
3 other branches
Scanning standard directories for session definition files.
Showing
1 changed file
with
74 additions
and
8 deletions
Show diff stats
src/objects/application/open.c
... | ... | @@ -29,22 +29,54 @@ |
29 | 29 | |
30 | 30 | #include "private.h" |
31 | 31 | |
32 | + gchar * v3270_keyfile_find(const gchar *name) { | |
33 | + // | |
34 | + // It can be a session file, scans for it | |
35 | + // | |
36 | + const gchar * paths[] = { | |
37 | + g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS), | |
38 | + g_get_user_config_dir() | |
39 | + }; | |
40 | + | |
41 | + static const gchar *subdirs[] = { | |
42 | + "3270", | |
43 | + G_STRINGIFY(PRODUCT_NAME), | |
44 | + PACKAGE_NAME | |
45 | + }; | |
46 | + | |
47 | + size_t path, subdir; | |
48 | + | |
49 | + g_autofree gchar * filename = g_strconcat(name,".3270",NULL); | |
50 | + | |
51 | + for(path = 0; path < G_N_ELEMENTS(paths); path++) { | |
52 | + | |
53 | + for(subdir = 0; subdir < G_N_ELEMENTS(subdirs); subdir++) { | |
54 | + | |
55 | + gchar * fullpath = g_build_filename(paths[path],subdirs[subdir],filename,NULL); | |
56 | + | |
57 | + debug("Searching for \"%s\"",fullpath); | |
58 | + | |
59 | + if(g_file_test(fullpath,G_FILE_TEST_IS_REGULAR)) { | |
60 | + return fullpath; | |
61 | + } | |
62 | + g_free(fullpath); | |
63 | + | |
64 | + } | |
65 | + } | |
66 | + | |
67 | + return NULL; | |
68 | + | |
69 | + } | |
70 | + | |
32 | 71 | void pw3270_application_open(GApplication *application, GFile **files, gint n_files, const gchar G_GNUC_UNUSED(*hint)) { |
33 | 72 | |
34 | 73 | GtkWidget * window = GTK_WIDGET(gtk_application_get_active_window(GTK_APPLICATION(application))); |
35 | - | |
74 | + size_t path, subdir; | |
36 | 75 | gint file; |
37 | 76 | |
38 | 77 | for(file = 0; file < n_files; file++) { |
39 | 78 | |
40 | 79 | g_autofree gchar *path = g_file_get_path(files[file]); |
41 | - if(!window) { | |
42 | - debug("%s: Open in new window",__FUNCTION__); | |
43 | - window = pw3270_application_window_new(GTK_APPLICATION(application), path); | |
44 | - } else { | |
45 | - debug("%s: Open in new tab",__FUNCTION__); | |
46 | - window = pw3270_application_window_new_tab(window,path); | |
47 | - } | |
48 | 80 | |
49 | 81 | if(!path) { |
50 | 82 | |
... | ... | @@ -63,6 +95,40 @@ |
63 | 95 | |
64 | 96 | } |
65 | 97 | |
98 | + continue; | |
99 | + | |
100 | + } | |
101 | + | |
102 | + if(g_file_test(path,G_FILE_TEST_IS_REGULAR)) { | |
103 | + | |
104 | + // The file exists, use it. | |
105 | + | |
106 | + if(!window) { | |
107 | + window = pw3270_application_window_new(GTK_APPLICATION(application), path); | |
108 | + } else { | |
109 | + window = pw3270_application_window_new_tab(window,path); | |
110 | + } | |
111 | + | |
112 | + continue; | |
113 | + } | |
114 | + | |
115 | + { | |
116 | + g_autofree gchar * basename = g_file_get_basename(files[file]); | |
117 | + g_autofree gchar * filename = v3270_keyfile_find(basename); | |
118 | + | |
119 | + if(filename) { | |
120 | + | |
121 | + g_message("Using \"%s\" for session properties",filename); | |
122 | + | |
123 | + if(!window) { | |
124 | + window = pw3270_application_window_new(GTK_APPLICATION(application), filename); | |
125 | + } else { | |
126 | + window = pw3270_application_window_new_tab(window, filename); | |
127 | + } | |
128 | + | |
129 | + continue; | |
130 | + } | |
131 | + | |
66 | 132 | } |
67 | 133 | |
68 | 134 | } | ... | ... |