Commit b9edbfb281272c0f66d77082fbfe2aeac04c2942
1 parent
f8811726
Exists in
master
and in
2 other branches
Adding to to bind a GtkEntry to GtkFileChooser.
Showing
5 changed files
with
218 additions
and
78 deletions
Show diff stats
Makefile.in
| ... | ... | @@ -40,6 +40,7 @@ SOURCES= \ |
| 40 | 40 | $(wildcard src/objects/settings/*.c) \ |
| 41 | 41 | $(wildcard src/objects/os/@OSNAME@/*.c) \ |
| 42 | 42 | $(wildcard src/main/*.c) \ |
| 43 | + $(wildcard src/tools/*.c) \ | |
| 43 | 44 | $(wildcard src/main/@OSNAME@/*.c) \ |
| 44 | 45 | $(wildcard src/main/@OSNAME@/*.rc) \ |
| 45 | 46 | $(wildcard src/objects/keypad/*.c) | ... | ... |
pw3270.cbp
| ... | ... | @@ -52,6 +52,7 @@ |
| 52 | 52 | <Unit filename="src/include/pw3270/keypad.h" /> |
| 53 | 53 | <Unit filename="src/include/pw3270/settings.h" /> |
| 54 | 54 | <Unit filename="src/include/pw3270/toolbar.h" /> |
| 55 | + <Unit filename="src/include/pw3270/tools.h" /> | |
| 55 | 56 | <Unit filename="src/include/pw3270/window.h" /> |
| 56 | 57 | <Unit filename="src/include/v3270/keyfile.h" /> |
| 57 | 58 | <Unit filename="src/main/main.c"> |
| ... | ... | @@ -195,6 +196,9 @@ |
| 195 | 196 | <Unit filename="src/objects/window/window.c"> |
| 196 | 197 | <Option compilerVar="CC" /> |
| 197 | 198 | </Unit> |
| 199 | + <Unit filename="src/tools/entry.c"> | |
| 200 | + <Option compilerVar="CC" /> | |
| 201 | + </Unit> | |
| 198 | 202 | <Unit filename="ui/application.xml" /> |
| 199 | 203 | <Unit filename="ui/window.xml" /> |
| 200 | 204 | <Extensions> | ... | ... |
| ... | ... | @@ -0,0 +1,53 @@ |
| 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 | +/** | |
| 31 | + * @brief Tool methods. | |
| 32 | + * | |
| 33 | + */ | |
| 34 | + | |
| 35 | +#ifndef PW3270_TOOLS_H_INCLUDED | |
| 36 | + | |
| 37 | + #define PW3270_TOOLS_H_INCLUDED | |
| 38 | + | |
| 39 | + #include <gtk/gtk.h> | |
| 40 | + | |
| 41 | + G_BEGIN_DECLS | |
| 42 | + | |
| 43 | + /// @brief Release ptr on 'destroy' signal. | |
| 44 | + void gtk_widget_bind_ptr(GtkWidget *widget, gpointer ptr); | |
| 45 | + | |
| 46 | + /// @brief Bind a GtkEntry to a file chooser dialog. | |
| 47 | + void gtk_entry_bind_to_filechooser(GtkWidget *entry, GtkFileChooserAction action, const gchar *title, const gchar *icon_name, const gchar *pattern, const gchar *name); | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + G_END_DECLS | |
| 52 | + | |
| 53 | +#endif // PW3270_TOOLS_H_INCLUDED | ... | ... |
src/objects/os/linux/savedesktopicon.c
| ... | ... | @@ -41,16 +41,11 @@ |
| 41 | 41 | #include <lib3270.h> |
| 42 | 42 | #include <lib3270/log.h> |
| 43 | 43 | #include <lib3270/properties.h> |
| 44 | + #include <pw3270/tools.h> | |
| 44 | 45 | |
| 45 | 46 | static GtkWidget * factory(V3270SimpleAction *action, GtkWidget *terminal); |
| 46 | 47 | static void response(GtkWidget *dialog, gint response_id, GtkWidget *terminal); |
| 47 | 48 | |
| 48 | - struct FileEntry { | |
| 49 | - const gchar * title; | |
| 50 | - const gchar * pattern; | |
| 51 | - const gchar * name; | |
| 52 | - }; | |
| 53 | - | |
| 54 | 49 | static const struct _entry { |
| 55 | 50 | |
| 56 | 51 | const gchar * key; |
| ... | ... | @@ -154,62 +149,6 @@ |
| 154 | 149 | |
| 155 | 150 | } |
| 156 | 151 | |
| 157 | - static void icon_response(GtkDialog *dialog, int response_id, GtkEntry *entry) { | |
| 158 | - | |
| 159 | - if(response_id == GTK_RESPONSE_ACCEPT) { | |
| 160 | - g_autofree gchar * filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); | |
| 161 | - gtk_entry_set_text(entry,filename ? filename : ""); | |
| 162 | - } | |
| 163 | - | |
| 164 | - gtk_widget_destroy(GTK_WIDGET(dialog)); | |
| 165 | - | |
| 166 | - } | |
| 167 | - | |
| 168 | - static void icon_press(GtkWidget *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_pos, G_GNUC_UNUSED GdkEvent *event, const struct FileEntry *descr) { | |
| 169 | - | |
| 170 | - GtkWidget * dialog = | |
| 171 | - gtk_file_chooser_dialog_new( | |
| 172 | - gettext(descr->title), | |
| 173 | - GTK_WINDOW(gtk_widget_get_toplevel(entry)), | |
| 174 | - GTK_FILE_CHOOSER_ACTION_SAVE, | |
| 175 | - _("Cancel"), GTK_RESPONSE_CANCEL, | |
| 176 | - _("Select"), GTK_RESPONSE_ACCEPT, | |
| 177 | - NULL | |
| 178 | - ); | |
| 179 | - | |
| 180 | - { | |
| 181 | - GtkFileFilter *filter; | |
| 182 | - | |
| 183 | - // Standard filter | |
| 184 | - filter = gtk_file_filter_new(); | |
| 185 | - gtk_file_filter_add_pattern (filter, descr->pattern); | |
| 186 | - gtk_file_filter_set_name(filter, gettext(descr->name)); | |
| 187 | - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog),filter); | |
| 188 | - | |
| 189 | - // All files | |
| 190 | - filter = gtk_file_filter_new(); | |
| 191 | - gtk_file_filter_add_pattern (filter, "*.*"); | |
| 192 | - gtk_file_filter_set_name(filter, _("All files")); | |
| 193 | - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog),filter); | |
| 194 | - | |
| 195 | - } | |
| 196 | - | |
| 197 | - gtk_window_set_modal(GTK_WINDOW(dialog),TRUE); | |
| 198 | - gtk_window_set_deletable(GTK_WINDOW(dialog),FALSE); | |
| 199 | - | |
| 200 | - const gchar *filename = gtk_entry_get_text(GTK_ENTRY(entry)); | |
| 201 | - | |
| 202 | - if(filename && *filename) | |
| 203 | - gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),filename); | |
| 204 | - | |
| 205 | - g_signal_connect(dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL); | |
| 206 | - g_signal_connect(dialog,"response",G_CALLBACK(icon_response),entry); | |
| 207 | - | |
| 208 | - gtk_widget_show_all(dialog); | |
| 209 | - | |
| 210 | - | |
| 211 | - } | |
| 212 | - | |
| 213 | 152 | GtkWidget * factory(V3270SimpleAction *action, GtkWidget *terminal) { |
| 214 | 153 | |
| 215 | 154 | size_t ix; |
| ... | ... | @@ -288,15 +227,16 @@ |
| 288 | 227 | |
| 289 | 228 | // 1 = Shortcut filename |
| 290 | 229 | { |
| 291 | - static const struct FileEntry entry = { | |
| 292 | - .title = N_("Save to shortcut file"), | |
| 293 | - .name = N_("Standard desktop files"), | |
| 294 | - .pattern = "*.desktop" | |
| 295 | - }; | |
| 296 | - | |
| 297 | 230 | gtk_entry_set_text(GTK_ENTRY(inputs[1]),filename); |
| 298 | - gtk_entry_set_icon_from_icon_name(GTK_ENTRY(inputs[1]),GTK_ENTRY_ICON_SECONDARY,"document-save"); | |
| 299 | - g_signal_connect(inputs[1],"icon_press",G_CALLBACK(icon_press),(gpointer) &entry); | |
| 231 | + gtk_entry_bind_to_filechooser( | |
| 232 | + inputs[1], | |
| 233 | + GTK_FILE_CHOOSER_ACTION_SAVE, | |
| 234 | + _("Save to shortcut file"), | |
| 235 | + "document-save", | |
| 236 | + "*.desktop", | |
| 237 | + _("Standard desktop files") | |
| 238 | + ); | |
| 239 | + | |
| 300 | 240 | } |
| 301 | 241 | |
| 302 | 242 | // 2 = Session name |
| ... | ... | @@ -313,16 +253,18 @@ |
| 313 | 253 | |
| 314 | 254 | // 3 = Session filename |
| 315 | 255 | { |
| 316 | - static const struct FileEntry entry = { | |
| 317 | - .title = N_("Save to session filename"), | |
| 318 | - .name = N_("3270 session files"), | |
| 319 | - .pattern = "*.3270" | |
| 320 | - }; | |
| 321 | - | |
| 322 | 256 | g_autofree gchar * session_filename = get_filename(terminal); |
| 323 | 257 | gtk_entry_set_text(GTK_ENTRY(inputs[3]),session_filename); |
| 324 | - gtk_entry_set_icon_from_icon_name(GTK_ENTRY(inputs[3]),GTK_ENTRY_ICON_SECONDARY,"document-save"); | |
| 325 | - g_signal_connect(inputs[3],"icon_press",G_CALLBACK(icon_press),(gpointer) &entry); | |
| 258 | + | |
| 259 | + gtk_entry_bind_to_filechooser( | |
| 260 | + inputs[3], | |
| 261 | + GTK_FILE_CHOOSER_ACTION_SAVE, | |
| 262 | + _("Save to session filename"), | |
| 263 | + "document-save", | |
| 264 | + "*.3270", | |
| 265 | + _("3270 session files") | |
| 266 | + ); | |
| 267 | + | |
| 326 | 268 | } |
| 327 | 269 | |
| 328 | 270 | // 4 = Generic name | ... | ... |
| ... | ... | @@ -0,0 +1,140 @@ |
| 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 | + /** | |
| 31 | + * @brief Implement Linux version of the save desktop icon action. | |
| 32 | + * | |
| 33 | + */ | |
| 34 | + | |
| 35 | + #include <pw3270/tools.h> | |
| 36 | + #include <pw3270/application.h> | |
| 37 | + #include <v3270/actions.h> | |
| 38 | + #include <v3270/keyfile.h> | |
| 39 | + #include <v3270/settings.h> | |
| 40 | + #include <lib3270.h> | |
| 41 | + #include <lib3270/log.h> | |
| 42 | + #include <lib3270/properties.h> | |
| 43 | + #include <pw3270.h> | |
| 44 | + | |
| 45 | + struct FileEntry { | |
| 46 | + GtkFileChooserAction action; | |
| 47 | + const gchar * title; | |
| 48 | + const gchar * pattern; | |
| 49 | + const gchar * name; | |
| 50 | + const gchar * accept; | |
| 51 | + }; | |
| 52 | + | |
| 53 | + static void icon_response(GtkDialog *dialog, int response_id, GtkEntry *entry) { | |
| 54 | + | |
| 55 | + if(response_id == GTK_RESPONSE_ACCEPT) { | |
| 56 | + g_autofree gchar * filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); | |
| 57 | + gtk_entry_set_text(entry,filename ? filename : ""); | |
| 58 | + } | |
| 59 | + | |
| 60 | + gtk_widget_destroy(GTK_WIDGET(dialog)); | |
| 61 | + | |
| 62 | + } | |
| 63 | + | |
| 64 | + static void icon_press(GtkWidget *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_pos, G_GNUC_UNUSED GdkEvent *event, const struct FileEntry *descr) { | |
| 65 | + | |
| 66 | + GtkWidget * dialog = | |
| 67 | + gtk_file_chooser_dialog_new( | |
| 68 | + gettext(descr->title), | |
| 69 | + GTK_WINDOW(gtk_widget_get_toplevel(entry)), | |
| 70 | + descr->action, | |
| 71 | + _("Cancel"), GTK_RESPONSE_CANCEL, | |
| 72 | + descr->accept, GTK_RESPONSE_ACCEPT, | |
| 73 | + NULL | |
| 74 | + ); | |
| 75 | + | |
| 76 | + { | |
| 77 | + GtkFileFilter *filter; | |
| 78 | + | |
| 79 | + // Standard filter | |
| 80 | + filter = gtk_file_filter_new(); | |
| 81 | + gtk_file_filter_add_pattern (filter, descr->pattern); | |
| 82 | + gtk_file_filter_set_name(filter, gettext(descr->name)); | |
| 83 | + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog),filter); | |
| 84 | + | |
| 85 | + // All files | |
| 86 | + filter = gtk_file_filter_new(); | |
| 87 | + gtk_file_filter_add_pattern (filter, "*.*"); | |
| 88 | + gtk_file_filter_set_name(filter, _("All files")); | |
| 89 | + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog),filter); | |
| 90 | + | |
| 91 | + } | |
| 92 | + | |
| 93 | + gtk_window_set_modal(GTK_WINDOW(dialog),TRUE); | |
| 94 | + gtk_window_set_deletable(GTK_WINDOW(dialog),FALSE); | |
| 95 | + | |
| 96 | + const gchar *filename = gtk_entry_get_text(GTK_ENTRY(entry)); | |
| 97 | + | |
| 98 | + if(filename && *filename) | |
| 99 | + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),filename); | |
| 100 | + | |
| 101 | + g_signal_connect(dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL); | |
| 102 | + g_signal_connect(dialog,"response",G_CALLBACK(icon_response),entry); | |
| 103 | + | |
| 104 | + gtk_widget_show_all(dialog); | |
| 105 | + | |
| 106 | + | |
| 107 | + } | |
| 108 | + | |
| 109 | + static void release_ptr(GtkWidget *object, gpointer ptr) { | |
| 110 | + g_free(ptr); | |
| 111 | + } | |
| 112 | + | |
| 113 | + void gtk_widget_bind_ptr(GtkWidget *widget, gpointer ptr) { | |
| 114 | + g_signal_connect(widget,"destroy",G_CALLBACK(release_ptr),ptr); | |
| 115 | + } | |
| 116 | + | |
| 117 | + void gtk_entry_bind_to_filechooser(GtkWidget *widget, GtkFileChooserAction action, const gchar *title, const gchar *icon_name, const gchar *pattern, const gchar *name) { | |
| 118 | + | |
| 119 | + gtk_entry_set_icon_from_icon_name(GTK_ENTRY(widget),GTK_ENTRY_ICON_SECONDARY,icon_name ? icon_name : "document-save"); | |
| 120 | + | |
| 121 | + // Store data | |
| 122 | + gsize szEntry = sizeof(struct FileEntry) + strlen(title) + strlen(pattern) + strlen(name) + 4; | |
| 123 | + struct FileEntry * entry = (struct FileEntry *) g_malloc0(szEntry); | |
| 124 | + gtk_widget_bind_ptr(widget,entry); | |
| 125 | + | |
| 126 | + entry->action = action; | |
| 127 | + entry->accept = _("Continue"); | |
| 128 | + | |
| 129 | + entry->title = (const char *) (entry+1); | |
| 130 | + strcpy((char *) entry->title,title); | |
| 131 | + | |
| 132 | + entry->pattern = entry->title + strlen(entry->title) +1; | |
| 133 | + strcpy((char *) entry->pattern,pattern); | |
| 134 | + | |
| 135 | + entry->name = entry->pattern + strlen(entry->pattern) + 1; | |
| 136 | + strcpy((char *) entry->name,name); | |
| 137 | + | |
| 138 | + g_signal_connect(widget,"icon_press",G_CALLBACK(icon_press),(gpointer) entry); | |
| 139 | + | |
| 140 | + } | ... | ... |