Commit 0c1da4a6b3a4e54675304f989d03421a39c4c63b

Authored by perry.werneck@gmail.com
1 parent f7cac77f

Implementando dialogosde download

pw3270.cbp
... ... @@ -46,7 +46,6 @@
46 46 <Unit filename="configure.ac" />
47 47 <Unit filename="pw3270.spec.in" />
48 48 <Unit filename="src/gtk/Makefile.in" />
49   - <Unit filename="src/gtk/common/common.h" />
50 49 <Unit filename="src/gtk/common/common.h.in" />
51 50 <Unit filename="src/gtk/globals.h" />
52 51 <Unit filename="src/gtk/uiparser/Makefile.in" />
... ... @@ -248,6 +247,10 @@
248 247 <Unit filename="src/pw3270/dialog.c">
249 248 <Option compilerVar="CC" />
250 249 </Unit>
  250 + <Unit filename="src/pw3270/filetransfer.c">
  251 + <Option compilerVar="CC" />
  252 + </Unit>
  253 + <Unit filename="src/pw3270/filetransfer.h" />
251 254 <Unit filename="src/pw3270/fonts.c">
252 255 <Option compilerVar="CC" />
253 256 </Unit>
... ...
pw3270.spec.in
... ... @@ -62,7 +62,7 @@ Source: %{name}-%{version}.tar.gz
62 62 BuildRoot: %{_tmppath}/%{name}-%{version}-build
63 63 Requires: openssl shared-mime-info
64 64 Distribution: %_distro
65   -BuildRequires: autoconf automake gcc-c++ sed pkgconfig gtk@GTK_VERSION@-devel gettext-devel libopenssl-devel findutils coreutils rsvg-view
  65 +BuildRequires: autoconf automake gcc-c++ sed pkgconfig gtk@GTK_VERSION@-devel gettext-devel libopenssl-devel findutils coreutils rsvg-view desktop-file-utils
66 66  
67 67 %description
68 68 IBM 3270 terminal emulator gtk. It can be used to communicate with
... ...
src/include/lib3270/filetransfer.h
... ... @@ -35,6 +35,8 @@
35 35 #define LIB3270_FILETRANSFER_INCLUDED 1
36 36 #include <stdio.h>
37 37  
  38 + #define LIB3270_FT_OPTION_SEND 0x0000
  39 +
38 40 typedef enum _lib3270_FT_FLAG
39 41 {
40 42 LIB3270_FT_OPTION_RECEIVE = 0x0001,
... ...
src/pw3270/Makefile.in
... ... @@ -53,7 +53,7 @@ include uiparser/sources.mak
53 53  
54 54 #---[ Targets ]----------------------------------------------------------------
55 55  
56   -SOURCES=main.c window.c actions.c fonts.c dialog.c print.c colors.c \
  56 +SOURCES=main.c window.c actions.c fonts.c dialog.c print.c colors.c filetransfer.c \
57 57 $(foreach SRC, $(V3270_SRC), v3270/$(SRC)) \
58 58 $(foreach SRC, $(COMMON_SRC), common/$(SRC)) \
59 59 $(foreach SRC, $(UI_PARSER_SRC), uiparser/$(SRC))
... ...
src/pw3270/actions.c
... ... @@ -32,6 +32,7 @@
32 32 #include "globals.h"
33 33 #include "uiparser/parser.h"
34 34 #include "v3270/v3270.h"
  35 + #include "filetransfer.h"
35 36 #include <lib3270/actions.h>
36 37 #include <lib3270/selection.h>
37 38 #include <lib3270/trace.h>
... ... @@ -217,6 +218,8 @@ static void connect_standard_action(GtkAction *action, GtkWidget *widget, const
217 218 { "about", about_dialog_action },
218 219 { "kpsubtract", kp_subtract_action },
219 220 { "kpadd", kp_add_action },
  221 + { "download", download_action },
  222 + { "upload", upload_action },
220 223 };
221 224  
222 225 int f;
... ...
src/pw3270/filetransfer.c 0 → 100644
... ... @@ -0,0 +1,317 @@
  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., 59 Temple
  19 + * Place, Suite 330, Boston, MA, 02111-1307, USA
  20 + *
  21 + * Este programa está nomeado como filetransfer.c 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 + * Agradecimento:
  29 + *
  30 + * Roberto Soares (a_r_soares@hotmail.com)
  31 + *
  32 + */
  33 +
  34 +#include "globals.h"
  35 +#include "uiparser/parser.h"
  36 +#include "filetransfer.h"
  37 +
  38 +/*--[ FT dialog ]------------------------------------------------------------------------------------*/
  39 +
  40 + struct ftdialog
  41 + {
  42 + LIB3270_FT_OPTION option;
  43 + const gchar * name;
  44 + GtkWidget * dialog;
  45 + GtkEntry * file[2];
  46 + GtkEntry * dft;
  47 + };
  48 +
  49 + struct ftoption
  50 + {
  51 + unsigned int flag;
  52 + const gchar * name;
  53 + const gchar * label;
  54 + };
  55 +
  56 +/*--[ Implement ]------------------------------------------------------------------------------------*/
  57 +
  58 +
  59 +static void error_dialog(GtkWidget *widget, const gchar *title, const gchar *msg, const gchar *text)
  60 +{
  61 + GtkWidget *popup = gtk_message_dialog_new_with_markup(
  62 + GTK_WINDOW(gtk_widget_get_toplevel(widget)),
  63 + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
  64 + GTK_MESSAGE_ERROR,GTK_BUTTONS_CLOSE,
  65 + "%s",msg);
  66 +
  67 + gtk_window_set_title(GTK_WINDOW(popup),title);
  68 +
  69 + if(text)
  70 + gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(popup),"%s",text);
  71 +
  72 + gtk_dialog_run(GTK_DIALOG(popup));
  73 + gtk_widget_destroy(popup);
  74 +}
  75 +
  76 +static void begin_ft_session(GtkAction *action, GtkWidget *widget, LIB3270_FT_OPTION opt)
  77 +{
  78 + // Create file-transfer options dialog
  79 +
  80 +}
  81 +
  82 +static void browse_file(GtkButton *button,struct ftdialog *dlg)
  83 +{
  84 + int recv = dlg->option&LIB3270_FT_OPTION_RECEIVE;
  85 + gchar * ptr;
  86 + GtkWidget * dialog = gtk_file_chooser_dialog_new( recv ? _( "Select file to receive" ) : _( "Select file to send" ),
  87 + GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))),
  88 + GTK_FILE_CHOOSER_ACTION_OPEN,
  89 + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
  90 + recv ? GTK_STOCK_SAVE : GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
  91 + NULL );
  92 +
  93 + ptr = get_string_from_config(dlg->name,"uri","");
  94 + if(*ptr)
  95 + gtk_file_chooser_set_uri(GTK_FILE_CHOOSER(dialog),ptr);
  96 + g_free(ptr);
  97 +
  98 + if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
  99 + {
  100 + gchar *uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog));
  101 + gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
  102 + set_string_to_config(dlg->name,"uri",uri);
  103 + gtk_entry_set_text(GTK_ENTRY(dlg->file[0]),filename);
  104 + g_free(uri);
  105 + g_free(filename);
  106 + }
  107 +
  108 + gtk_widget_destroy(dialog);
  109 +
  110 +}
  111 +
  112 +static void add_file_fields(GObject *action, struct ftdialog *dlg)
  113 +{
  114 + static const gchar * label[] = { N_( "_Local file name:" ), N_( "_Host file name:" ) };
  115 + static const gchar * attr[] = { "local", "remote" };
  116 + GtkTable * table = GTK_TABLE(gtk_table_new(2,3,FALSE));
  117 + GtkWidget * widget;
  118 + int f;
  119 +
  120 + for(f=0;f<2;f++)
  121 + {
  122 + const gchar *val;
  123 +
  124 + widget = gtk_label_new_with_mnemonic(gettext(label[f]));
  125 +
  126 + gtk_misc_set_alignment(GTK_MISC(widget),0,.5);
  127 + gtk_table_attach(GTK_TABLE(table),widget,0,1,f,f+1,GTK_FILL,GTK_FILL,2,2);
  128 +
  129 + dlg->file[f] = GTK_ENTRY(gtk_entry_new());
  130 +
  131 + gtk_widget_set_name(GTK_WIDGET(dlg->file[f]),attr[f]);
  132 +
  133 + val = g_object_get_data(action,attr[f]);
  134 +
  135 + if(val)
  136 + {
  137 + gtk_entry_set_text(dlg->file[f],val);
  138 + }
  139 + else
  140 + {
  141 + gchar *name = get_string_from_config(dlg->name,attr[f],"");
  142 + gtk_entry_set_text(dlg->file[f],name);
  143 + g_free(name);
  144 + }
  145 +
  146 + gtk_entry_set_width_chars(dlg->file[f],40);
  147 +
  148 + gtk_label_set_mnemonic_widget(GTK_LABEL(widget),GTK_WIDGET(dlg->file[f]));
  149 +
  150 + gtk_table_attach(GTK_TABLE(table),GTK_WIDGET(dlg->file[f]),1,3,f,f+1,GTK_EXPAND|GTK_SHRINK|GTK_FILL,GTK_EXPAND|GTK_SHRINK|GTK_FILL,2,2);
  151 +
  152 + }
  153 +
  154 + widget = gtk_button_new_with_mnemonic( _( "_Browse" ) );
  155 + g_signal_connect(G_OBJECT(widget),"clicked",G_CALLBACK(browse_file),dlg);
  156 + gtk_table_attach(GTK_TABLE(table),widget,3,4,0,1,0,0,2,2);
  157 +
  158 + gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dlg->dialog))),GTK_WIDGET(table),FALSE,FALSE,2);
  159 +
  160 +}
  161 +
  162 +static void toggle_option(GtkToggleButton *button, const struct ftoption *option)
  163 +{
  164 + gboolean active = gtk_toggle_button_get_active(button);
  165 + struct ftdialog * dlg = (struct ftdialog *) g_object_get_data(G_OBJECT(button),"dlg");
  166 +
  167 + if(active)
  168 + dlg->option |= option->flag;
  169 + else
  170 + dlg->option &= ~option->flag;
  171 +
  172 + set_boolean_to_config(dlg->name,option->name,active);
  173 +
  174 + trace("option \"%s\" is %s (flags=%04x)",option->label,active ? "Active" : "Inactive" ,dlg->option);
  175 +}
  176 +
  177 +static void add_transfer_options(GObject *action, struct ftdialog *dlg)
  178 +{
  179 + static const struct ftoption option[] =
  180 + { { LIB3270_FT_OPTION_ASCII, "text", N_( "_Text file" ) },
  181 + { LIB3270_FT_OPTION_TSO, "tso", N_( "Host is T_SO" ) },
  182 + { LIB3270_FT_OPTION_CRLF, "cr", N_( "Add/Remove _CR at end of line" ) },
  183 + { LIB3270_FT_OPTION_APPEND, "append", N_( "_Append" ) },
  184 + { LIB3270_FT_OPTION_REMAP_ASCII, "remap", N_( "_Remap ASCII Characters" ) }
  185 + };
  186 +
  187 + GtkTable * table = GTK_TABLE(gtk_table_new(3,2,TRUE));
  188 + GtkWidget * frame = gtk_frame_new( _( "Transfer options" ) );
  189 + int row, col, f;
  190 +
  191 + row=0;
  192 + col=0;
  193 + for(f=0;f < G_N_ELEMENTS(option);f++)
  194 + {
  195 + const gchar * val = g_object_get_data(action,option[f].name);
  196 + GtkWidget * widget = gtk_check_button_new_with_mnemonic( gettext(option[f].label) );
  197 + gboolean active = FALSE;
  198 +
  199 + gtk_widget_set_name(widget,option[f].name);
  200 +
  201 + if(val)
  202 + active = g_strcasecmp(val,"yes") == 0 ? TRUE : FALSE;
  203 + else
  204 + active = get_boolean_from_config(dlg->name,option[f].name,FALSE);
  205 +
  206 + if(active)
  207 + dlg->option |= option[f].flag;
  208 +
  209 + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),active);
  210 +
  211 + g_object_set_data(G_OBJECT(widget),"dlg",(gpointer) dlg);
  212 + g_signal_connect(G_OBJECT(widget),"toggled", G_CALLBACK(toggle_option),(gpointer) &option[f]);
  213 +
  214 + gtk_table_attach(table,widget,col,col+1,row,row+1,GTK_EXPAND|GTK_SHRINK|GTK_FILL,GTK_EXPAND|GTK_SHRINK|GTK_FILL,2,2);
  215 + if(col++ > 0)
  216 + {
  217 + row++;
  218 + col=0;
  219 + }
  220 + }
  221 +
  222 + gtk_container_add(GTK_CONTAINER(frame),GTK_WIDGET(table));
  223 + gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dlg->dialog))),GTK_WIDGET(frame),FALSE,FALSE,2);
  224 +
  225 +}
  226 +
  227 +static void setup_dft(GObject *action, struct ftdialog *dlg, GtkWidget **label)
  228 +{
  229 + gchar *val = g_object_get_data(action,"dft");
  230 +
  231 + *label = gtk_label_new_with_mnemonic( _( "DFT Buffer _size:" ) );
  232 +
  233 + gtk_misc_set_alignment(GTK_MISC(*label),0,.5);
  234 +
  235 + dlg->dft = GTK_ENTRY(gtk_entry_new());
  236 + gtk_entry_set_max_length(dlg->dft,10);
  237 + gtk_entry_set_width_chars(dlg->dft,10);
  238 +
  239 + gtk_label_set_mnemonic_widget(GTK_LABEL(*label),GTK_WIDGET(dlg->dft));
  240 +
  241 + if(val)
  242 + {
  243 + gtk_entry_set_text(dlg->dft,val);
  244 + }
  245 + else
  246 + {
  247 + val = get_string_from_config(dlg->name,"dft","");
  248 + gtk_entry_set_text(dlg->dft,val);
  249 + g_free(val);
  250 + }
  251 +
  252 +
  253 +}
  254 +
  255 +void download_action(GtkAction *action, GtkWidget *widget)
  256 +{
  257 + struct ftdialog dlg;
  258 +
  259 +
  260 + if(lib3270_get_ft_state(v3270_get_session(widget)) != LIB3270_FT_STATE_NONE)
  261 + {
  262 + error_dialog(widget,_( "Can't start download" ), _( "File transfer is already active" ), NULL);
  263 + return;
  264 + }
  265 +
  266 + memset(&dlg,0,sizeof(dlg));
  267 +
  268 + dlg.dialog = gtk_dialog_new_with_buttons( _( "Receive file from host" ), \
  269 + GTK_WINDOW(gtk_widget_get_toplevel(widget)),
  270 + GTK_DIALOG_DESTROY_WITH_PARENT, \
  271 + GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, \
  272 + GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, \
  273 + NULL );
  274 +
  275 + dlg.name = "download";
  276 + dlg.option = LIB3270_FT_OPTION_RECEIVE;
  277 + add_file_fields(G_OBJECT(action),&dlg);
  278 + add_transfer_options(G_OBJECT(action),&dlg);
  279 +
  280 + {
  281 + /* Add dft option */
  282 + GtkWidget *hbox = gtk_hbox_new(FALSE,2);
  283 + GtkWidget *label = NULL;
  284 +
  285 + setup_dft(G_OBJECT(action),&dlg,&label);
  286 +
  287 + gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,FALSE,0);
  288 + gtk_box_pack_start(GTK_BOX(hbox),GTK_WIDGET(dlg.dft),FALSE,FALSE,0);
  289 + gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dlg.dialog))),hbox,FALSE,FALSE,2);
  290 + }
  291 +
  292 + gtk_widget_show_all(dlg.dialog);
  293 +
  294 + if(gtk_dialog_run(GTK_DIALOG(dlg.dialog)) == GTK_RESPONSE_ACCEPT)
  295 + {
  296 + // Begin file transfer
  297 + }
  298 +
  299 +
  300 +// begin_ft_session(action,widget,LIB3270_FT_OPTION_RECEIVE);
  301 +
  302 + gtk_widget_destroy(dlg.dialog);
  303 +
  304 +}
  305 +
  306 +void upload_action(GtkAction *action, GtkWidget *widget)
  307 +{
  308 + if(lib3270_get_ft_state(v3270_get_session(widget)) != LIB3270_FT_STATE_NONE)
  309 + {
  310 + error_dialog(widget,_( "Can't start upload" ), _( "File transfer is already active" ), NULL);
  311 + return;
  312 + }
  313 +
  314 +// begin_ft_session(action,widget,LIB3270_FT_OPTION_SEND);
  315 +}
  316 +
  317 +
... ...
src/pw3270/filetransfer.h 0 → 100644
... ... @@ -0,0 +1,41 @@
  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., 59 Temple
  19 + * Place, Suite 330, Boston, MA, 02111-1307, USA
  20 + *
  21 + * Este programa está nomeado como globals.c 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 PW3270_FT_H_INCLUDED
  31 +
  32 + #define PW3270_FT_H_INCLUDED 1
  33 + #include <pw3270.h>
  34 + #include <lib3270/config.h>
  35 + #include <lib3270/filetransfer.h>
  36 +
  37 +
  38 +
  39 +
  40 +#endif // PW3270_FT_H_INCLUDED
  41 +
... ...
src/pw3270/globals.h
... ... @@ -74,4 +74,9 @@
74 74 G_GNUC_INTERNAL void print_copy_action(GtkAction *action, GtkWidget *widget);
75 75 G_GNUC_INTERNAL void editcolors_action(GtkAction *action, GtkWidget *widget);
76 76 G_GNUC_INTERNAL void about_dialog_action(GtkAction *action, GtkWidget *widget);
  77 + G_GNUC_INTERNAL void download_action(GtkAction *action, GtkWidget *widget);
  78 + G_GNUC_INTERNAL void upload_action(GtkAction *action, GtkWidget *widget);
  79 +
  80 +
  81 +
77 82  
... ...
ui/00default.xml
... ... @@ -49,9 +49,9 @@
49 49 <menuitem action='print' src='selected' group='selection' label='Print selected' />
50 50 <menuitem action='print' src='copy' group='clipboard' label='Print copy' />
51 51 <separator/>
52   - <menu name='FTMenu' group='filetransfer' label='Send/Receive' >
53   - <menuitem action='Download' key='<alt>d' group='filetransfer' label='Receive file' />
54   - <menuitem action='Upload' key='<alt>u' group='filetransfer' label='Send file' />
  52 + <menu name='FTMenu' label='Send/Receive' >
  53 + <menuitem action='download' key='<alt>d' label='Receive file' />
  54 + <menuitem action='upload' key='<alt>u' label='Send file' />
55 55 </menu>
56 56 <menuitem action='Quit' key='<ctrl>q' icon="quit" />
57 57 </menu>
... ...