Commit 92db2da1db53b7eca96ac090180466d02c744693
1 parent
2b230fbb
Exists in
master
and in
1 other branch
Adding usefull gtk extension methods from pw3270 application.
Showing
4 changed files
with
245 additions
and
1 deletions
Show diff stats
Makefile.in
| ... | ... | @@ -49,7 +49,8 @@ SOURCES= \ |
| 49 | 49 | $(wildcard src/dialogs/print/*.c) \ |
| 50 | 50 | $(wildcard src/dialogs/save/*.c) \ |
| 51 | 51 | $(wildcard src/dialogs/font/*.c) \ |
| 52 | - $(wildcard src/dialogs/settings/*.c) | |
| 52 | + $(wildcard src/dialogs/settings/*.c) \ | |
| 53 | + $(wildcard src/tools/*.c) | |
| 53 | 54 | |
| 54 | 55 | TEST_SOURCES= \ |
| 55 | 56 | $(wildcard src/testprogram/*.c) |
| ... | ... | @@ -149,6 +150,11 @@ $(OBJDBG)/%.o: \ |
| 149 | 150 | |
| 150 | 151 | @$(CC) \ |
| 151 | 152 | $(CFLAGS) \ |
| 153 | + -DDEBUG=1 \ | |
| 154 | + -MM -MT $@ -MF $(patsubst %.o,%.d,$@) $< | |
| 155 | + | |
| 156 | + @$(CC) \ | |
| 157 | + $(CFLAGS) \ | |
| 152 | 158 | -Wall -Wextra -fstack-check \ |
| 153 | 159 | -DDEBUG=1 \ |
| 154 | 160 | -o $@ -c $< |
| ... | ... | @@ -177,6 +183,13 @@ $(OBJRLS)/%.o: \ |
| 177 | 183 | |
| 178 | 184 | @echo $< ... |
| 179 | 185 | @$(MKDIR) $(dir $@) |
| 186 | + | |
| 187 | + @$(CC) \ | |
| 188 | + $(CFLAGS) \ | |
| 189 | + -DNDEBUG=1 \ | |
| 190 | + -MM -MT $@ -MF $(patsubst %.o,%.d,$@) $< | |
| 191 | + | |
| 192 | + | |
| 180 | 193 | @$(CC) \ |
| 181 | 194 | $(CFLAGS) \ |
| 182 | 195 | -DNDEBUG=1 \ |
| ... | ... | @@ -564,4 +577,8 @@ clean: \ |
| 564 | 577 | cleanDebug \ |
| 565 | 578 | cleanRelease |
| 566 | 579 | |
| 580 | +-include $(foreach SRC, $(basename $(SOURCES)), $(OBJDBG)/$(SRC).d) | |
| 581 | +-include $(foreach SRC, $(basename $(SOURCES)), $(OBJRLS)/$(SRC).d) | |
| 582 | + | |
| 583 | + | |
| 567 | 584 | ... | ... |
| ... | ... | @@ -0,0 +1,46 @@ |
| 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 tools.h 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 | +#ifndef V3270_TOOLS_H_INCLUDED | |
| 31 | + | |
| 32 | + #include <gtk/gtk.h> | |
| 33 | + #include <lib3270.h> | |
| 34 | + | |
| 35 | + G_BEGIN_DECLS | |
| 36 | + | |
| 37 | + /// @brief Bind pointer to widget; release it when widget is destroyed. | |
| 38 | + LIB3270_EXPORT void gtk_widget_bind_ptr(GtkWidget *widget, gpointer ptr); | |
| 39 | + | |
| 40 | + /// @brief Bind file chooser with entry field. | |
| 41 | + LIB3270_EXPORT void gtk_entry_bind_to_filechooser(GtkWidget *widget, GtkFileChooserAction action, const gchar *title, const gchar *icon_name, const gchar *pattern, const gchar *name); | |
| 42 | + | |
| 43 | + G_END_DECLS | |
| 44 | + | |
| 45 | +#endif // V3270_TOOLS_H_INCLUDED | |
| 46 | + | ... | ... |
| ... | ... | @@ -0,0 +1,177 @@ |
| 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 Usefull extensions for GtkEntry. | |
| 32 | + * | |
| 33 | + */ | |
| 34 | + | |
| 35 | + #include <internals.h> | |
| 36 | + #include <v3270/tools.h> | |
| 37 | + #include <string.h> | |
| 38 | + | |
| 39 | + struct FileEntry { | |
| 40 | + GtkFileChooserAction action; | |
| 41 | + const gchar * title; | |
| 42 | + const gchar * pattern; | |
| 43 | + const gchar * name; | |
| 44 | + const gchar * accept; | |
| 45 | + }; | |
| 46 | + | |
| 47 | + static void icon_response(GtkDialog *dialog, int response_id, GtkEntry *entry) { | |
| 48 | + | |
| 49 | + if(response_id == GTK_RESPONSE_ACCEPT) { | |
| 50 | + | |
| 51 | + g_autofree gchar * filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); | |
| 52 | + | |
| 53 | + if(filename) { | |
| 54 | + | |
| 55 | + // https://github.com/PerryWerneck/pw3270/issues/9#issuecomment-708963229 | |
| 56 | + // | |
| 57 | + // Works here (openSUSE Tumbleweed), BUT: the "open session" dialog comes with a filter | |
| 58 | + // set to "TN3270 files" and that's good, but when you save a session pw3270 does NOT add | |
| 59 | + // the extension, so how do you know what file extension those "TN3270 files" are supposed to have? | |
| 60 | + // | |
| 61 | + // I tried .tn3270 but it did not work, so I had to look hard in the internet to find out this page | |
| 62 | + // ... | |
| 63 | + // | |
| 64 | + if(strchr(filename,'.')) { | |
| 65 | + | |
| 66 | + // Filename has extension, use it. | |
| 67 | + gtk_entry_set_text(entry,filename); | |
| 68 | + | |
| 69 | + } else { | |
| 70 | + | |
| 71 | + // No extension, add it from the standard. | |
| 72 | + const gchar *ext = (const gchar *) g_object_get_data(G_OBJECT(dialog),"default-file-extension"); | |
| 73 | + if(ext) { | |
| 74 | + g_autofree gchar * new_name = g_strconcat(filename,ext,NULL); | |
| 75 | + gtk_entry_set_text(entry,new_name); | |
| 76 | + } else { | |
| 77 | + g_warning("No default file extension set"); | |
| 78 | + gtk_entry_set_text(entry,filename); | |
| 79 | + } | |
| 80 | + | |
| 81 | + } | |
| 82 | + | |
| 83 | + } else { | |
| 84 | + gtk_entry_set_text(entry,""); | |
| 85 | + } | |
| 86 | + } | |
| 87 | + | |
| 88 | + gtk_widget_destroy(GTK_WIDGET(dialog)); | |
| 89 | + | |
| 90 | + } | |
| 91 | + | |
| 92 | + static void icon_press(GtkWidget *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_pos, G_GNUC_UNUSED GdkEvent *event, const struct FileEntry *descr) { | |
| 93 | + | |
| 94 | + GtkWidget * dialog = | |
| 95 | + gtk_file_chooser_dialog_new( | |
| 96 | + gettext(descr->title), | |
| 97 | + GTK_WINDOW(gtk_widget_get_toplevel(entry)), | |
| 98 | + descr->action, | |
| 99 | + _("Cancel"), GTK_RESPONSE_CANCEL, | |
| 100 | + descr->accept, GTK_RESPONSE_ACCEPT, | |
| 101 | + NULL | |
| 102 | + ); | |
| 103 | + | |
| 104 | + { | |
| 105 | + GtkFileFilter *filter; | |
| 106 | + | |
| 107 | + // Standard filter | |
| 108 | + filter = gtk_file_filter_new(); | |
| 109 | + gtk_file_filter_add_pattern (filter, descr->pattern); | |
| 110 | + gtk_file_filter_set_name(filter, gettext(descr->name)); | |
| 111 | + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog),filter); | |
| 112 | + | |
| 113 | + const gchar *ext = strchr(descr->pattern,'.'); | |
| 114 | + if(ext) { | |
| 115 | + g_object_set_data_full(G_OBJECT(dialog),"default-file-extension",g_strdup(ext),g_free); | |
| 116 | + } | |
| 117 | + | |
| 118 | + // All files | |
| 119 | + filter = gtk_file_filter_new(); | |
| 120 | + gtk_file_filter_add_pattern (filter, "*.*"); | |
| 121 | + gtk_file_filter_set_name(filter, _("All files")); | |
| 122 | + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog),filter); | |
| 123 | + | |
| 124 | + } | |
| 125 | + | |
| 126 | + gtk_window_set_modal(GTK_WINDOW(dialog),TRUE); | |
| 127 | + gtk_window_set_deletable(GTK_WINDOW(dialog),FALSE); | |
| 128 | + | |
| 129 | + const gchar *filename = gtk_entry_get_text(GTK_ENTRY(entry)); | |
| 130 | + | |
| 131 | + if(filename && *filename) | |
| 132 | + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),filename); | |
| 133 | + | |
| 134 | + g_signal_connect(dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL); | |
| 135 | + g_signal_connect(dialog,"response",G_CALLBACK(icon_response),entry); | |
| 136 | + | |
| 137 | + gtk_widget_show_all(dialog); | |
| 138 | + | |
| 139 | + | |
| 140 | + } | |
| 141 | + | |
| 142 | + static void release_ptr(GtkWidget G_GNUC_UNUSED(*object), gpointer ptr) { | |
| 143 | + g_free(ptr); | |
| 144 | + } | |
| 145 | + | |
| 146 | + LIB3270_EXPORT void gtk_widget_bind_ptr(GtkWidget *widget, gpointer ptr) { | |
| 147 | + g_signal_connect(widget,"destroy",G_CALLBACK(release_ptr),ptr); | |
| 148 | + } | |
| 149 | + | |
| 150 | + LIB3270_EXPORT void gtk_entry_bind_to_filechooser(GtkWidget *widget, GtkFileChooserAction action, const gchar *title, const gchar *icon_name, const gchar *pattern, const gchar *name) { | |
| 151 | + | |
| 152 | + gtk_entry_set_icon_from_icon_name( | |
| 153 | + GTK_ENTRY(widget), | |
| 154 | + GTK_ENTRY_ICON_SECONDARY, | |
| 155 | + icon_name ? icon_name : "document-open" | |
| 156 | + ); | |
| 157 | + | |
| 158 | + // Store data | |
| 159 | + gsize szEntry = sizeof(struct FileEntry) + strlen(title) + strlen(pattern) + strlen(name) + 4; | |
| 160 | + struct FileEntry * entry = (struct FileEntry *) g_malloc0(szEntry); | |
| 161 | + gtk_widget_bind_ptr(widget,entry); | |
| 162 | + | |
| 163 | + entry->action = action; | |
| 164 | + entry->accept = _("Continue"); | |
| 165 | + | |
| 166 | + entry->title = (const char *) (entry+1); | |
| 167 | + strcpy((char *) entry->title,title); | |
| 168 | + | |
| 169 | + entry->pattern = entry->title + strlen(entry->title) +1; | |
| 170 | + strcpy((char *) entry->pattern,pattern); | |
| 171 | + | |
| 172 | + entry->name = entry->pattern + strlen(entry->pattern) + 1; | |
| 173 | + strcpy((char *) entry->name,name); | |
| 174 | + | |
| 175 | + g_signal_connect(widget,"icon_press",G_CALLBACK(icon_press),(gpointer) entry); | |
| 176 | + | |
| 177 | + } | ... | ... |
v3270.cbp
| ... | ... | @@ -198,6 +198,7 @@ |
| 198 | 198 | <Unit filename="src/include/v3270/selection.h" /> |
| 199 | 199 | <Unit filename="src/include/v3270/settings.h" /> |
| 200 | 200 | <Unit filename="src/include/v3270/toggle.h" /> |
| 201 | + <Unit filename="src/include/v3270/tools.h" /> | |
| 201 | 202 | <Unit filename="src/include/v3270/trace.h" /> |
| 202 | 203 | <Unit filename="src/selection/copy.c"> |
| 203 | 204 | <Option compilerVar="CC" /> |
| ... | ... | @@ -404,6 +405,9 @@ |
| 404 | 405 | <Unit filename="src/testprogram/toolbar.c"> |
| 405 | 406 | <Option compilerVar="CC" /> |
| 406 | 407 | </Unit> |
| 408 | + <Unit filename="src/tools/entry.c"> | |
| 409 | + <Option compilerVar="CC" /> | |
| 410 | + </Unit> | |
| 407 | 411 | <Unit filename="src/trace/exec.c"> |
| 408 | 412 | <Option compilerVar="CC" /> |
| 409 | 413 | </Unit> | ... | ... |