Commit 992ffd3423723c9dcc78db687e47c995b1d0034d
1 parent
78c87dd2
Exists in
master
and in
2 other branches
'gfile' open has failed on windows, building an OS specific version.
Showing
5 changed files
with
168 additions
and
114 deletions
Show diff stats
pw3270.cbp
@@ -130,6 +130,9 @@ | @@ -130,6 +130,9 @@ | ||
130 | <Unit filename="src/objects/keypad/widget.c"> | 130 | <Unit filename="src/objects/keypad/widget.c"> |
131 | <Option compilerVar="CC" /> | 131 | <Option compilerVar="CC" /> |
132 | </Unit> | 132 | </Unit> |
133 | + <Unit filename="src/objects/os/linux/open.c"> | ||
134 | + <Option compilerVar="CC" /> | ||
135 | + </Unit> | ||
133 | <Unit filename="src/objects/os/linux/savedesktopicon.c"> | 136 | <Unit filename="src/objects/os/linux/savedesktopicon.c"> |
134 | <Option compilerVar="CC" /> | 137 | <Option compilerVar="CC" /> |
135 | </Unit> | 138 | </Unit> |
src/include/pw3270/application.h
@@ -65,6 +65,7 @@ typedef struct _pw3270Application pw3270Application; | @@ -65,6 +65,7 @@ typedef struct _pw3270Application pw3270Application; | ||
65 | 65 | ||
66 | GType pw3270Application_get_type(); | 66 | GType pw3270Application_get_type(); |
67 | GtkApplication * pw3270_application_new(const gchar *application_id, GApplicationFlags flags); | 67 | GtkApplication * pw3270_application_new(const gchar *application_id, GApplicationFlags flags); |
68 | +void pw3270_application_open_file(GtkApplication *application, GtkWindow **window, GFile *file); | ||
68 | 69 | ||
69 | /// @brief Get application settings. | 70 | /// @brief Get application settings. |
70 | /// @param app The pw3270 application object. | 71 | /// @param app The pw3270 application object. |
src/objects/application/open.c
@@ -31,120 +31,6 @@ | @@ -31,120 +31,6 @@ | ||
31 | #include <pw3270/application.h> | 31 | #include <pw3270/application.h> |
32 | #include <v3270/keyfile.h> | 32 | #include <v3270/keyfile.h> |
33 | 33 | ||
34 | -gchar * v3270_keyfile_find(const gchar *name) { | ||
35 | - // | ||
36 | - // It can be a session file, scans for it | ||
37 | - // | ||
38 | - const gchar * paths[] = { | ||
39 | - g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS), | ||
40 | - g_get_user_config_dir() | ||
41 | - }; | ||
42 | - | ||
43 | - static const gchar *subdirs[] = { | ||
44 | - "3270", | ||
45 | - G_STRINGIFY(PRODUCT_NAME), | ||
46 | - PACKAGE_NAME | ||
47 | - }; | ||
48 | - | ||
49 | - size_t path, subdir; | ||
50 | - | ||
51 | - g_autofree gchar * filename = g_strconcat(name,".3270",NULL); | ||
52 | - | ||
53 | - for(path = 0; path < G_N_ELEMENTS(paths); path++) { | ||
54 | - | ||
55 | - for(subdir = 0; subdir < G_N_ELEMENTS(subdirs); subdir++) { | ||
56 | - | ||
57 | - gchar * fullpath = g_build_filename(paths[path],subdirs[subdir],filename,NULL); | ||
58 | - | ||
59 | - debug("Searching for \"%s\"",fullpath); | ||
60 | - | ||
61 | - if(g_file_test(fullpath,G_FILE_TEST_IS_REGULAR)) { | ||
62 | - return fullpath; | ||
63 | - } | ||
64 | - g_free(fullpath); | ||
65 | - | ||
66 | - } | ||
67 | - } | ||
68 | - | ||
69 | - return NULL; | ||
70 | - | ||
71 | -} | ||
72 | - | ||
73 | -/// @brief Open session file | ||
74 | -static void open(GtkApplication *application, GtkWindow **window, const gchar *filename) { | ||
75 | - | ||
76 | - g_message("Opening '%s'",filename); | ||
77 | - | ||
78 | - if(*window) { | ||
79 | - | ||
80 | - // Already open a window, open in new tab. | ||
81 | - pw3270_application_window_new_tab(GTK_WIDGET(*window), filename); | ||
82 | - | ||
83 | - } else { | ||
84 | - // It's a new window | ||
85 | - *window = GTK_WINDOW(pw3270_application_window_new(application, filename)); | ||
86 | - | ||
87 | - } | ||
88 | - | ||
89 | -} | ||
90 | - | ||
91 | -void pw3270_application_open_file(GtkApplication *application, GtkWindow **window, GFile *file) { | ||
92 | - | ||
93 | - g_autofree gchar * scheme = g_file_get_uri_scheme(file); | ||
94 | - | ||
95 | - if(g_ascii_strcasecmp(scheme,"file") == 0) { | ||
96 | - | ||
97 | - // It's a file scheme. | ||
98 | - if(g_file_query_exists(file,NULL)) { | ||
99 | - | ||
100 | - // The file exists, load it. | ||
101 | - g_autofree gchar *filename = g_file_get_path(file); | ||
102 | - open(application,window,filename); | ||
103 | - | ||
104 | - } else { | ||
105 | - | ||
106 | - // Search for file. | ||
107 | - g_autofree gchar * basename = g_file_get_basename(file); | ||
108 | - g_autofree gchar * filename = v3270_keyfile_find(basename); | ||
109 | - | ||
110 | - if(filename) { | ||
111 | - open(application,window,filename); | ||
112 | - } else { | ||
113 | - g_warning("Cant find session '%s'",basename); | ||
114 | - } | ||
115 | - | ||
116 | - } | ||
117 | - | ||
118 | - } else if(g_ascii_strcasecmp(scheme,"tn3270") == 0 || g_ascii_strcasecmp(scheme,"tn3270s") == 0) { | ||
119 | - | ||
120 | - g_autofree gchar * uri = g_file_get_uri(file); | ||
121 | - size_t sz = strlen(uri); | ||
122 | - | ||
123 | - if(sz > 0 && uri[sz-1] == '/') | ||
124 | - uri[sz-1] = 0; | ||
125 | - | ||
126 | - g_message("Opening '%s' with default settings",uri); | ||
127 | - | ||
128 | - if(!*window) { | ||
129 | - *window = GTK_WINDOW(pw3270_application_window_new(application, NULL)); | ||
130 | - } else { | ||
131 | - pw3270_application_window_new_tab(GTK_WIDGET(*window), NULL); | ||
132 | - } | ||
133 | - | ||
134 | - GtkWidget * terminal = pw3270_application_window_get_active_terminal(GTK_WIDGET(*window)); | ||
135 | - v3270_set_default_session(terminal); | ||
136 | - v3270_set_url(terminal,uri); | ||
137 | - | ||
138 | - } else { | ||
139 | - | ||
140 | - g_warning("Don't know how to handle '%s' scheme",scheme); | ||
141 | - | ||
142 | - } | ||
143 | - | ||
144 | - | ||
145 | - | ||
146 | -} | ||
147 | - | ||
148 | void pw3270_application_open(GApplication *application, GFile **files, gint n_files, const gchar G_GNUC_UNUSED(*hint)) { | 34 | void pw3270_application_open(GApplication *application, GFile **files, gint n_files, const gchar G_GNUC_UNUSED(*hint)) { |
149 | 35 | ||
150 | gint file; | 36 | gint file; |
src/objects/application/private.h
@@ -47,6 +47,7 @@ | @@ -47,6 +47,7 @@ | ||
47 | #include <lib3270/log.h> | 47 | #include <lib3270/log.h> |
48 | 48 | ||
49 | G_GNUC_INTERNAL void pw3270_application_open(GApplication * application, GFile **files, gint n_files, const gchar *hint); | 49 | G_GNUC_INTERNAL void pw3270_application_open(GApplication * application, GFile **files, gint n_files, const gchar *hint); |
50 | + | ||
50 | G_GNUC_INTERNAL GtkWidget * pw3270_terminal_new(const gchar *session_file); | 51 | G_GNUC_INTERNAL GtkWidget * pw3270_terminal_new(const gchar *session_file); |
51 | 52 | ||
52 | // Actions | 53 | // Actions |
@@ -0,0 +1,163 @@ | @@ -0,0 +1,163 @@ | ||
1 | +/* | ||
2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | ||
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | ||
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | ||
5 | + * | ||
6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | ||
7 | + * | ||
8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | ||
9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | ||
10 | + * Free Software Foundation. | ||
11 | + * | ||
12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | ||
13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | ||
14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | ||
15 | + * obter mais detalhes. | ||
16 | + * | ||
17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | ||
18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | ||
19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | + * | ||
21 | + * Este programa está nomeado como - e possui - linhas de código. | ||
22 | + * | ||
23 | + * Contatos: | ||
24 | + * | ||
25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | ||
26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | ||
27 | + * | ||
28 | + */ | ||
29 | + | ||
30 | +#include <config.h> | ||
31 | + | ||
32 | +#include <lib3270.h> | ||
33 | +#include <lib3270/log.h> | ||
34 | +#include <pw3270/application.h> | ||
35 | +#include <pw3270/window.h> | ||
36 | +#include <v3270.h> | ||
37 | +#include <v3270/keyfile.h> | ||
38 | + | ||
39 | +static gchar * v3270_keyfile_find(const gchar *name) { | ||
40 | + // | ||
41 | + // It can be a session file, scans for it | ||
42 | + // | ||
43 | + const gchar * paths[] = { | ||
44 | + g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS), | ||
45 | + g_get_user_config_dir() | ||
46 | + }; | ||
47 | + | ||
48 | + static const gchar *subdirs[] = { | ||
49 | + "3270", | ||
50 | + G_STRINGIFY(PRODUCT_NAME), | ||
51 | + PACKAGE_NAME | ||
52 | + }; | ||
53 | + | ||
54 | + size_t path, subdir; | ||
55 | + | ||
56 | + g_autofree gchar * filename = g_strconcat(name,".3270",NULL); | ||
57 | + | ||
58 | + for(path = 0; path < G_N_ELEMENTS(paths); path++) { | ||
59 | + | ||
60 | + // Try subdirs. | ||
61 | + for(subdir = 0; subdir < G_N_ELEMENTS(subdirs); subdir++) { | ||
62 | + | ||
63 | + gchar * fullpath = g_build_filename(paths[path],subdirs[subdir],filename,NULL); | ||
64 | + | ||
65 | + debug("Searching for \"%s\"",fullpath); | ||
66 | + | ||
67 | + if(g_file_test(fullpath,G_FILE_TEST_IS_REGULAR)) { | ||
68 | + return fullpath; | ||
69 | + } | ||
70 | + g_free(fullpath); | ||
71 | + | ||
72 | + } | ||
73 | + | ||
74 | + // Try path. | ||
75 | + { | ||
76 | + gchar * fullpath = g_build_filename(paths[path],filename,NULL); | ||
77 | + | ||
78 | + debug("Searching for \"%s\"",fullpath); | ||
79 | + | ||
80 | + if(g_file_test(fullpath,G_FILE_TEST_IS_REGULAR)) { | ||
81 | + return fullpath; | ||
82 | + } | ||
83 | + g_free(fullpath); | ||
84 | + } | ||
85 | + | ||
86 | + } | ||
87 | + | ||
88 | + return NULL; | ||
89 | + | ||
90 | +} | ||
91 | + | ||
92 | +/// @brief Open session file | ||
93 | +static void open(GtkApplication *application, GtkWindow **window, const gchar *filename) { | ||
94 | + | ||
95 | + g_message("Opening '%s'",filename); | ||
96 | + | ||
97 | + if(*window) { | ||
98 | + | ||
99 | + // Already open a window, open in new tab. | ||
100 | + pw3270_application_window_new_tab(GTK_WIDGET(*window), filename); | ||
101 | + | ||
102 | + } else { | ||
103 | + // It's a new window | ||
104 | + *window = GTK_WINDOW(pw3270_application_window_new(application, filename)); | ||
105 | + | ||
106 | + } | ||
107 | + | ||
108 | +} | ||
109 | + | ||
110 | +void pw3270_application_open_file(GtkApplication *application, GtkWindow **window, GFile *file) { | ||
111 | + | ||
112 | + g_autofree gchar * scheme = g_file_get_uri_scheme(file); | ||
113 | + | ||
114 | + if(g_ascii_strcasecmp(scheme,"file") == 0) { | ||
115 | + | ||
116 | + // It's a file scheme. | ||
117 | + if(g_file_query_exists(file,NULL)) { | ||
118 | + | ||
119 | + // The file exists, load it. | ||
120 | + g_autofree gchar *filename = g_file_get_path(file); | ||
121 | + open(application,window,filename); | ||
122 | + | ||
123 | + } else { | ||
124 | + | ||
125 | + // Search for file. | ||
126 | + g_autofree gchar * basename = g_file_get_basename(file); | ||
127 | + g_autofree gchar * filename = v3270_keyfile_find(basename); | ||
128 | + | ||
129 | + if(filename) { | ||
130 | + open(application,window,filename); | ||
131 | + } else { | ||
132 | + g_warning("Cant find session '%s'",basename); | ||
133 | + } | ||
134 | + | ||
135 | + } | ||
136 | + | ||
137 | + } else if(g_ascii_strcasecmp(scheme,"tn3270") == 0 || g_ascii_strcasecmp(scheme,"tn3270s") == 0) { | ||
138 | + | ||
139 | + g_autofree gchar * uri = g_file_get_uri(file); | ||
140 | + size_t sz = strlen(uri); | ||
141 | + | ||
142 | + if(sz > 0 && uri[sz-1] == '/') | ||
143 | + uri[sz-1] = 0; | ||
144 | + | ||
145 | + g_message("Opening '%s' with default settings",uri); | ||
146 | + | ||
147 | + if(!*window) { | ||
148 | + *window = GTK_WINDOW(pw3270_application_window_new(application, NULL)); | ||
149 | + } else { | ||
150 | + pw3270_application_window_new_tab(GTK_WIDGET(*window), NULL); | ||
151 | + } | ||
152 | + | ||
153 | + GtkWidget * terminal = pw3270_application_window_get_active_terminal(GTK_WIDGET(*window)); | ||
154 | + v3270_set_default_session(terminal); | ||
155 | + v3270_set_url(terminal,uri); | ||
156 | + | ||
157 | + } else { | ||
158 | + | ||
159 | + g_warning("Don't know how to handle '%s' scheme",scheme); | ||
160 | + | ||
161 | + } | ||
162 | + | ||
163 | +} |