Commit b0d210f734029fff6afb40dfe6ae9941a91afcce
1 parent
992ffd34
Exists in
master
and in
2 other branches
Fixing windows startup with session file name.
Showing
2 changed files
with
210 additions
and
0 deletions
Show diff stats
pw3270.cbp
| @@ -136,6 +136,9 @@ | @@ -136,6 +136,9 @@ | ||
| 136 | <Unit filename="src/objects/os/linux/savedesktopicon.c"> | 136 | <Unit filename="src/objects/os/linux/savedesktopicon.c"> |
| 137 | <Option compilerVar="CC" /> | 137 | <Option compilerVar="CC" /> |
| 138 | </Unit> | 138 | </Unit> |
| 139 | + <Unit filename="src/objects/os/windows/open.c"> | ||
| 140 | + <Option compilerVar="CC" /> | ||
| 141 | + </Unit> | ||
| 139 | <Unit filename="src/objects/os/windows/savedesktopicon.c"> | 142 | <Unit filename="src/objects/os/windows/savedesktopicon.c"> |
| 140 | <Option compilerVar="CC" /> | 143 | <Option compilerVar="CC" /> |
| 141 | </Unit> | 144 | </Unit> |
| @@ -0,0 +1,207 @@ | @@ -0,0 +1,207 @@ | ||
| 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 <pw3270.h> | ||
| 33 | +#include <lib3270.h> | ||
| 34 | +#include <lib3270/log.h> | ||
| 35 | +#include <pw3270/application.h> | ||
| 36 | +#include <pw3270/window.h> | ||
| 37 | +#include <v3270.h> | ||
| 38 | +#include <v3270/keyfile.h> | ||
| 39 | +#include <v3270/dialogs.h> | ||
| 40 | + | ||
| 41 | +/* | ||
| 42 | +static gchar * v3270_keyfile_find(const gchar *name) { | ||
| 43 | + // | ||
| 44 | + // It can be a session file, scans for it | ||
| 45 | + // | ||
| 46 | + g_autofree gchar * appdir = g_win32_get_package_installation_directory_of_module(NULL); | ||
| 47 | + | ||
| 48 | + const gchar * paths[] = { | ||
| 49 | + g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS), | ||
| 50 | + g_get_user_config_dir(), | ||
| 51 | + appdir | ||
| 52 | + }; | ||
| 53 | + | ||
| 54 | + static const gchar *subdirs[] = { | ||
| 55 | + "3270", | ||
| 56 | + G_STRINGIFY(PRODUCT_NAME), | ||
| 57 | + PACKAGE_NAME | ||
| 58 | + }; | ||
| 59 | + | ||
| 60 | + size_t path, subdir; | ||
| 61 | + | ||
| 62 | + g_autofree gchar * filename = g_strconcat(name,".3270",NULL); | ||
| 63 | + | ||
| 64 | + for(path = 0; path < G_N_ELEMENTS(paths); path++) { | ||
| 65 | + | ||
| 66 | + // Try subdirs. | ||
| 67 | + for(subdir = 0; subdir < G_N_ELEMENTS(subdirs); subdir++) { | ||
| 68 | + | ||
| 69 | + gchar * fullpath = g_build_filename(paths[path],subdirs[subdir],filename,NULL); | ||
| 70 | + | ||
| 71 | + debug("Searching for \"%s\"",fullpath); | ||
| 72 | + | ||
| 73 | + if(g_file_test(fullpath,G_FILE_TEST_IS_REGULAR)) { | ||
| 74 | + return fullpath; | ||
| 75 | + } | ||
| 76 | + g_free(fullpath); | ||
| 77 | + | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + // Try path. | ||
| 81 | + { | ||
| 82 | + gchar * fullpath = g_build_filename(paths[path],filename,NULL); | ||
| 83 | + | ||
| 84 | + debug("Searching for \"%s\"",fullpath); | ||
| 85 | + | ||
| 86 | + if(g_file_test(fullpath,G_FILE_TEST_IS_REGULAR)) { | ||
| 87 | + return fullpath; | ||
| 88 | + } | ||
| 89 | + g_free(fullpath); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + return NULL; | ||
| 95 | + | ||
| 96 | +} | ||
| 97 | +*/ | ||
| 98 | + | ||
| 99 | +/// @brief Open session file | ||
| 100 | +static void open(GtkApplication *application, GtkWindow **window, const gchar *filename) { | ||
| 101 | + | ||
| 102 | + g_message("Opening '%s'",filename); | ||
| 103 | + | ||
| 104 | + if(*window) { | ||
| 105 | + | ||
| 106 | + // Already open a window, open in new tab. | ||
| 107 | + pw3270_application_window_new_tab(GTK_WIDGET(*window), filename); | ||
| 108 | + | ||
| 109 | + } else { | ||
| 110 | + // It's a new window | ||
| 111 | + *window = GTK_WINDOW(pw3270_application_window_new(application, filename)); | ||
| 112 | + | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | +} | ||
| 116 | + | ||
| 117 | +void pw3270_application_open_file(GtkApplication *application, GtkWindow **window, GFile *file) { | ||
| 118 | + | ||
| 119 | + g_autofree gchar *filename = g_file_get_path(file); | ||
| 120 | + | ||
| 121 | + if(g_file_query_exists(file,NULL) && filename) { | ||
| 122 | + | ||
| 123 | + // The file exists, load it. | ||
| 124 | + open(application,window,filename); | ||
| 125 | + | ||
| 126 | + } else { | ||
| 127 | + | ||
| 128 | + GtkWidget * dialog = gtk_message_dialog_new_with_markup( | ||
| 129 | + NULL, | ||
| 130 | + 0, | ||
| 131 | + GTK_MESSAGE_ERROR, | ||
| 132 | + GTK_BUTTONS_CLOSE, | ||
| 133 | + _("Can't load session preferences") | ||
| 134 | + ); | ||
| 135 | + | ||
| 136 | + if(filename) { | ||
| 137 | + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),_("Unable to load session preferences from '%s'"),filename); | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + gtk_window_set_title(GTK_WINDOW(dialog),_("Error starting session")); | ||
| 141 | + | ||
| 142 | + gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); | ||
| 143 | + gtk_widget_show_all(dialog); | ||
| 144 | + | ||
| 145 | + //g_signal_connect(dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL); | ||
| 146 | + //g_signal_connect(dialog,"response",G_CALLBACK(gtk_widget_destroy),NULL); | ||
| 147 | + gtk_dialog_run(GTK_DIALOG(dialog)); | ||
| 148 | + | ||
| 149 | + g_application_quit(G_APPLICATION(application)); | ||
| 150 | + | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + | ||
| 154 | + /* | ||
| 155 | + g_autofree gchar * scheme = g_file_get_uri_scheme(file); | ||
| 156 | + | ||
| 157 | + if(g_ascii_strcasecmp(scheme,"file") == 0) { | ||
| 158 | + | ||
| 159 | + // It's a file scheme. | ||
| 160 | + if(g_file_query_exists(file,NULL)) { | ||
| 161 | + | ||
| 162 | + // The file exists, load it. | ||
| 163 | + g_autofree gchar *filename = g_file_get_path(file); | ||
| 164 | + open(application,window,filename); | ||
| 165 | + | ||
| 166 | + } else { | ||
| 167 | + | ||
| 168 | + // Search for file. | ||
| 169 | + g_autofree gchar * basename = g_file_get_basename(file); | ||
| 170 | + g_autofree gchar * filename = v3270_keyfile_find(basename); | ||
| 171 | + | ||
| 172 | + if(filename) { | ||
| 173 | + open(application,window,filename); | ||
| 174 | + } else { | ||
| 175 | + g_warning("Cant find session '%s'",basename); | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | + } else if(g_ascii_strcasecmp(scheme,"tn3270") == 0 || g_ascii_strcasecmp(scheme,"tn3270s") == 0) { | ||
| 181 | + | ||
| 182 | + g_autofree gchar * uri = g_file_get_uri(file); | ||
| 183 | + size_t sz = strlen(uri); | ||
| 184 | + | ||
| 185 | + if(sz > 0 && uri[sz-1] == '/') | ||
| 186 | + uri[sz-1] = 0; | ||
| 187 | + | ||
| 188 | + g_message("Opening '%s' with default settings",uri); | ||
| 189 | + | ||
| 190 | + if(!*window) { | ||
| 191 | + *window = GTK_WINDOW(pw3270_application_window_new(application, NULL)); | ||
| 192 | + } else { | ||
| 193 | + pw3270_application_window_new_tab(GTK_WIDGET(*window), NULL); | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + GtkWidget * terminal = pw3270_application_window_get_active_terminal(GTK_WIDGET(*window)); | ||
| 197 | + v3270_set_default_session(terminal); | ||
| 198 | + v3270_set_url(terminal,uri); | ||
| 199 | + | ||
| 200 | + } else { | ||
| 201 | + | ||
| 202 | + g_warning("Don't know how to handle '%s' scheme",scheme); | ||
| 203 | + | ||
| 204 | + } | ||
| 205 | + */ | ||
| 206 | + | ||
| 207 | +} |