Commit 833b2fc65ec910de08341786c311e128e236d2b0

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

Implementando novos diálogos de transferência de arquivo

pw3270.cbp
... ... @@ -325,6 +325,13 @@
325 325 <Unit filename="src/pw3270/fonts.c">
326 326 <Option compilerVar="CC" />
327 327 </Unit>
  328 + <Unit filename="src/pw3270/ft/ftdialog.c">
  329 + <Option compilerVar="CC" />
  330 + </Unit>
  331 + <Unit filename="src/pw3270/ft/ftprogress.c">
  332 + <Option compilerVar="CC" />
  333 + </Unit>
  334 + <Unit filename="src/pw3270/ft/v3270ft.h" />
328 335 <Unit filename="src/pw3270/globals.h" />
329 336 <Unit filename="src/pw3270/hostdialog.c">
330 337 <Option compilerVar="CC" />
... ...
src/include/lib3270/filetransfer.h
... ... @@ -143,7 +143,7 @@
143 143 struct lib3270_charset charset;
144 144  
145 145 // Callbacks
146   - void (*complete)(struct _h3270ft *ft,unsigned long length,double kbytes_sec,const char *mode);
  146 + void (*complete)(struct _h3270ft *ft,unsigned long length,double kbytes_sec);
147 147 void (*message)(struct _h3270ft *ft, const char *msg);
148 148 void (*update)(struct _h3270ft *ft, unsigned long current, unsigned long length, double kbytes_sec);
149 149 void (*running)(struct _h3270ft *ft, int is_cut);
... ... @@ -164,12 +164,11 @@
164 164 * @param primspace
165 165 * @param secspace
166 166 * @param dft
167   - * @param msg Pointer to error message.
168 167 *
169 168 * @return Filetransfer handle if ok, NULL if failed
170 169 *
171 170 */
172   - LIB3270_EXPORT H3270FT * lib3270_ft_new(H3270 *hSession, LIB3270_FT_OPTION flags, const char *local, const char *remote, int lrecl, int blksize, int primspace, int secspace, int dft, const char **msg);
  171 + LIB3270_EXPORT H3270FT * lib3270_ft_new(H3270 *hSession, LIB3270_FT_OPTION flags, const char *local, const char *remote, int lrecl, int blksize, int primspace, int secspace, int dft);
173 172  
174 173 LIB3270_EXPORT int lib3270_ft_start(H3270 *hSession);
175 174 LIB3270_EXPORT int lib3270_ft_destroy(H3270 *hSession);
... ...
src/lib3270/ft.c
... ... @@ -126,9 +126,8 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state);
126 126 return 0;
127 127 }
128 128  
129   - static void def_complete(H3270FT *ft,unsigned long length,double kbytes_sec,const char *mode)
  129 + static void def_complete(H3270FT *ft,unsigned long length,double kbytes_sec)
130 130 {
131   -
132 131 }
133 132  
134 133 static void def_message(H3270FT *ft, const char *errmsg)
... ... @@ -157,7 +156,7 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state);
157 156 }
158 157  
159 158  
160   - LIB3270_EXPORT H3270FT * lib3270_ft_new(H3270 *session, LIB3270_FT_OPTION flags, const char *local, const char *remote, int lrecl, int blksize, int primspace, int secspace, int dft, const char **msg)
  159 + LIB3270_EXPORT H3270FT * lib3270_ft_new(H3270 *session, LIB3270_FT_OPTION flags, const char *local, const char *remote, int lrecl, int blksize, int primspace, int secspace, int dft)
161 160 {
162 161 H3270FT * ftHandle = (H3270FT *) session->ft;
163 162 FILE * ft_local_file = NULL;
... ... @@ -166,14 +165,25 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state);
166 165 // trace("%s(%s)",__FUNCTION__,local);
167 166 if(!lib3270_connected(session))
168 167 {
169   - *msg = N_( "Disconnected from host" );
170   - errno = EINVAL;
  168 + lib3270_popup_dialog( session,
  169 + LIB3270_NOTIFY_ERROR,
  170 + _( "Request failed" ),
  171 + _( "Can't start file transfer." ),
  172 + "%s",
  173 + _( "Disconnected from host." ));
  174 + errno = ENOTCONN;
171 175 return NULL;
172 176 }
173 177  
174 178 if(ftHandle)
175 179 {
176   - *msg = N_( "File transfer is already active in this session" );
  180 + lib3270_popup_dialog( session,
  181 + LIB3270_NOTIFY_ERROR,
  182 + _( "Request failed" ),
  183 + _( "Can't start file transfer." ),
  184 + "%s",
  185 + _( "File transfer is already active in this session." ));
  186 +
177 187 errno = EBUSY;
178 188 return NULL;
179 189 }
... ... @@ -181,7 +191,12 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state);
181 191 // Check remote file
182 192 if(!*remote)
183 193 {
184   - *msg = N_( "The remote file name is invalid" );
  194 + lib3270_popup_dialog( session,
  195 + LIB3270_NOTIFY_ERROR,
  196 + _( "Request failed" ),
  197 + _( "Can't start file transfer." ),
  198 + "%s",
  199 + _( "The remote file name is invalid." ));
185 200 errno = EINVAL;
186 201 return NULL;
187 202 }
... ... @@ -195,7 +210,12 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state);
195 210  
196 211 if(!ft_local_file)
197 212 {
198   - *msg = N_( "Can't open local file" );
  213 + lib3270_popup_dialog( session,
  214 + LIB3270_NOTIFY_ERROR,
  215 + _( "Request failed" ),
  216 + _( "Can't open local file." ),
  217 + "%s",
  218 + strerror(errno));
199 219 return NULL;
200 220 }
201 221  
... ... @@ -241,8 +261,6 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state);
241 261  
242 262 session->ft = ftHandle;
243 263  
244   -
245   -
246 264 return ftHandle;
247 265 }
248 266  
... ... @@ -426,8 +444,10 @@ void ft_complete(H3270FT *ft, const char *errmsg)
426 444  
427 445 ft_update_length(ft);
428 446  
429   - ft->message(ft,errmsg);
430   - ft->complete(ft,ft->ft_length,kbytes_sec,ft->ft_is_cut ? "CUT" : "DFT");
  447 + if(errmsg)
  448 + ft->message(ft,errmsg);
  449 +
  450 + ft->complete(ft,ft->ft_length,kbytes_sec);
431 451  
432 452 }
433 453  
... ... @@ -500,10 +520,11 @@ void ft_running(H3270FT *ft, Boolean is_cut)
500 520 void ft_aborting(H3270FT *h)
501 521 {
502 522 if (h->state == FT_RUNNING || h->state == FT_ABORT_WAIT)
  523 + {
503 524 set_ft_state(h,FT_ABORT_SENT);
504   -
505   - h->aborting(h);
506   -
  525 + h->message(h,N_("Aborting..."));
  526 + h->aborting(h);
  527 + }
507 528 }
508 529  
509 530 /* Process a disconnect abort. */
... ...
src/lib3270/ft_cut.c
... ... @@ -331,7 +331,7 @@ static void cut_control_code(H3270 *hSession)
331 331 trace_ds(hSession,"XFER_COMPLETE\n");
332 332 cut_ack(hSession);
333 333 hSession->cut_xfer_in_progress = 0;
334   - ft_complete(ft,N_( "Complete" ) );
  334 + ft_complete(ft,N_( "Transfer complete" ) );
335 335 break;
336 336  
337 337 case SC_ABORT_FILE:
... ...
src/pw3270/Makefile.in
... ... @@ -61,10 +61,11 @@ include uiparser/sources.mak
61 61 APP_SOURCES= main.c @APP_GUI_SRC@
62 62  
63 63 LIB_SOURCES= window.c actions.c fonts.c dialog.c hostdialog.c print.c colors.c \
64   - filetransfer.c tools.c plugin.c trace.c \
  64 + tools.c plugin.c trace.c \
65 65 $(foreach SRC, $(UI_PARSER_SRC), uiparser/$(SRC)) \
66 66 $(foreach SRC, $(V3270_SRC), v3270/$(SRC)) \
67   - $(foreach SRC, $(COMMON_SRC), common/$(SRC))
  67 + $(foreach SRC, $(COMMON_SRC), common/$(SRC)) \
  68 + filetransfer.c ft/ftdialog.c ft/ftprogress.c
68 69  
69 70 DEPENDS=*.h common/*.h uiparser/*.h v3270/*.h $(GLOBAL_DEPS)
70 71  
... ...
src/pw3270/filetransfer.c
... ... @@ -33,863 +33,321 @@
33 33  
34 34 #include <stdlib.h>
35 35 #include "globals.h"
36   -#include "uiparser/parser.h"
37   -#include "filetransfer.h"
38   -
39   -/*--[ FT dialog ]------------------------------------------------------------------------------------*/
40   -
41   - struct ftdialog
42   - {
43   - LIB3270_FT_OPTION option;
44   - const gchar * name;
45   - GtkWidget * dialog;
46   - GtkEntry * file[2];
47   - GtkEntry * parm[5];
48   - GtkWidget * ready;
49   - };
50   -
51   - struct ftoption
52   - {
53   - unsigned int flag;
54   - const gchar * name;
55   - const gchar * label;
56   - };
57   -
58   - struct ftmask
59   - {
60   - unsigned int flag;
61   - unsigned int mask;
62   - const gchar * name;
63   - const gchar * label;
64   - };
  36 +#include "ft/v3270ft.h"
65 37  
66   -/*--[ Implement ]------------------------------------------------------------------------------------*/
67   -
68   -
69   -static void error_dialog(GtkWidget *widget, const gchar *title, const gchar *msg, const gchar *text)
70   -{
71   - GtkWidget *popup = gtk_message_dialog_new_with_markup(
72   - GTK_WINDOW(gtk_widget_get_toplevel(widget)),
73   - GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
74   - GTK_MESSAGE_ERROR,GTK_BUTTONS_CLOSE,
75   - "%s",msg);
76 38  
77   - gtk_window_set_title(GTK_WINDOW(popup),title);
  39 +/*--[ Constants ]------------------------------------------------------------------------------------*/
78 40  
79   - if(text)
80   - gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(popup),"%s",text);
81   -
82   - gtk_dialog_run(GTK_DIALOG(popup));
83   - gtk_widget_destroy(popup);
84   -}
85   -
86   -static gchar * get_attribute(GObject *action, struct ftdialog *dlg, const gchar *name)
87   -{
88   - gchar *val = g_object_get_data(action,name);
89   -
90   - if(val)
91   - return g_strdup(val);
92   -
93   - return get_string_from_config(dlg->name,name,"");
94   -}
  41 + static const struct _ftoptions
  42 + {
  43 + LIB3270_FT_OPTION val;
  44 + const gchar * name;
  45 + }
  46 + ftoptions[] =
  47 + { { LIB3270_FT_OPTION_ASCII, "text" },
  48 + { LIB3270_FT_OPTION_CRLF, "cr" },
  49 + { LIB3270_FT_OPTION_APPEND, "append" },
  50 + { LIB3270_FT_OPTION_REMAP, "remap" }
  51 + };
95 52  
96   -static void browse_file(GtkButton *button,struct ftdialog *dlg)
97   -{
98   - int recv = dlg->option&LIB3270_FT_OPTION_RECEIVE;
99   - gchar * ptr;
100   - GtkWidget * dialog = gtk_file_chooser_dialog_new( recv ? _( "Select file to receive" ) : _( "Select file to send" ),
101   - GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))),
102   - GTK_FILE_CHOOSER_ACTION_OPEN,
103   - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
104   - recv ? GTK_STOCK_SAVE : GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
105   - NULL );
106   -
107   - ptr = get_string_from_config(dlg->name,"uri","");
108   - if(*ptr)
109   - gtk_file_chooser_set_uri(GTK_FILE_CHOOSER(dialog),ptr);
110   - g_free(ptr);
  53 + static const struct _recfm
  54 + {
  55 + LIB3270_FT_OPTION val;
  56 + const gchar * name;
  57 + } recfm[] =
  58 + {
  59 + { LIB3270_FT_RECORD_FORMAT_DEFAULT, "default" },
  60 + { LIB3270_FT_RECORD_FORMAT_FIXED, "fixed" },
  61 + { LIB3270_FT_RECORD_FORMAT_VARIABLE, "variable" },
  62 + { LIB3270_FT_RECORD_FORMAT_UNDEFINED, "undefined" }
  63 + };
111 64  
112   - if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
  65 + static const struct _ftunits
113 66 {
114   - gchar *uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog));
115   - gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
116   - set_string_to_config(dlg->name,"uri",uri);
117   - gtk_entry_set_text(GTK_ENTRY(dlg->file[0]),filename);
118   - g_free(uri);
119   - g_free(filename);
120   - }
  67 + LIB3270_FT_OPTION val;
  68 + const gchar * name;
  69 + } units[] =
  70 + {
  71 + { LIB3270_FT_ALLOCATION_UNITS_DEFAULT, "default" },
  72 + { LIB3270_FT_ALLOCATION_UNITS_TRACKS, "tracks" },
  73 + { LIB3270_FT_ALLOCATION_UNITS_CYLINDERS, "cylinders" },
  74 + { LIB3270_FT_ALLOCATION_UNITS_AVBLOCK, "avblock" }
  75 + };
121 76  
122   - gtk_widget_destroy(dialog);
123 77  
124   -}
  78 +/*--[ Implement ]------------------------------------------------------------------------------------*/
125 79  
126   -static gboolean is_dialog_ok(GtkEditable *editable, struct ftdialog *dlg)
  80 +static LIB3270_FT_OPTION get_options_from_config(const gchar *group)
127 81 {
128   - const gchar *local = gtk_entry_get_text(GTK_ENTRY(dlg->file[0]));
129   - const gchar *remote = gtk_entry_get_text(GTK_ENTRY(dlg->file[1]));
130   - int f;
  82 + int f;
  83 + LIB3270_FT_OPTION rc = 0;
  84 + gchar * ptr;
131 85  
132   - if(!*remote)
133   - return FALSE;
134   -
135   - if(!(dlg->option&LIB3270_FT_OPTION_RECEIVE))
  86 + // Get base FT options
  87 + for(f=0;f<G_N_ELEMENTS(ftoptions);f++)
136 88 {
137   - // Sending file, should have local and remote filenames
138   - if(!( *local && g_file_test(local,G_FILE_TEST_EXISTS)))
139   - return FALSE;
  89 + if(get_boolean_from_config(group,ftoptions[f].name,FALSE))
  90 + rc |= ftoptions[f].val;
140 91 }
141 92  
142   - for(f=0;f<5;f++)
  93 + // Get Record format
  94 + ptr = get_string_from_config(group, "units", "default");
  95 + for(f=0;f<G_N_ELEMENTS(units);f++)
143 96 {
144   - if(dlg->parm[f])
145   - {
146   - const gchar *val = gtk_entry_get_text(GTK_ENTRY(dlg->parm[f]));
147   -
148   - while(*val)
149   - {
150   - if(*val < '0' || *val > '9')
151   - return FALSE;
152   - val++;
153   - }
154   - }
  97 + if(!g_ascii_strcasecmp(ptr,units[f].name))
  98 + rc |= units[f].val;
155 99 }
  100 + g_free(ptr);
156 101  
157   - return TRUE;
158   -}
159   -
160   -static void check_remote_filename(GtkEditable *editable, struct ftdialog *dlg)
161   -{
162   -#if GTK_CHECK_VERSION(3,2,0)
163   - if(!gtk_entry_get_text_length(dlg->file[0]))
  102 + // Get allocation units
  103 + ptr = get_string_from_config(group, "recfm", "default");
  104 + for(f=0;f<G_N_ELEMENTS(recfm);f++)
164 105 {
165   - gchar *basename = g_path_get_basename(gtk_entry_get_text(GTK_ENTRY(editable)));
166   - gchar *filename = g_build_filename(g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS),basename,NULL);
167   - gtk_entry_set_placeholder_text(dlg->file[0],filename);
168   - g_free(filename);
169   - g_free(basename);
  106 + if(!g_ascii_strcasecmp(ptr,recfm[f].name))
  107 + rc |= recfm[f].val;
170 108 }
171   -#endif // GTK(3,2)
172   - gtk_widget_set_sensitive(dlg->ready,is_dialog_ok(editable,dlg));
173   -}
174   -
175   -static void check_entry(GtkEditable *editable, struct ftdialog *dlg)
176   -{
177   - gtk_widget_set_sensitive(dlg->ready,is_dialog_ok(editable,dlg));
178   -}
179   -
180   -static GtkEntry * add_filename_entry(GObject *action, int ix, int row, struct ftdialog *dlg, GtkTable *table)
181   -{
182   - static const gchar * label_text[] = { N_( "_Local file name:" ), N_( "_Host file name:" ) };
183   - static const gchar * attr[] = { "local", "remote" };
184   -
185   - GtkWidget * entry = gtk_entry_new();
186   - GtkWidget * label = gtk_label_new_with_mnemonic(gettext(label_text[ix]));
187   - gchar * val;
188   -
189   - gtk_misc_set_alignment(GTK_MISC(label),0,.5);
190   - gtk_table_attach(GTK_TABLE(table),label,0,1,row,row+1,GTK_FILL,GTK_FILL,2,2);
191   -
192   - gtk_widget_set_name(entry,attr[ix]);
193   -
194   - val = get_attribute(action,dlg,attr[ix]);
195   - gtk_entry_set_text(dlg->file[ix],val);
196   - g_free(val);
197   -
198   - gtk_entry_set_width_chars(GTK_ENTRY(entry),40);
199   -
200   - gtk_label_set_mnemonic_widget(GTK_LABEL(label),entry);
  109 + g_free(ptr);
201 110  
202   - gtk_table_attach(GTK_TABLE(table),entry,1,3,row,row+1,GTK_EXPAND|GTK_SHRINK|GTK_FILL,GTK_EXPAND|GTK_SHRINK|GTK_FILL,2,2);
203 111  
204   - return GTK_ENTRY(entry);
  112 + return rc;
205 113 }
206 114  
207   -static void add_file_fields(GObject *action, struct ftdialog *dlg)
  115 +static void ft_dialog_load(GtkWidget *widget, const gchar *name)
208 116 {
209   - GtkTable * table = GTK_TABLE(gtk_table_new(2,3,FALSE));
210   - GtkWidget * widget;
211   -
212   - gtk_container_set_border_width(GTK_CONTAINER(table),2);
213   -
214   - if(dlg->option&LIB3270_FT_OPTION_RECEIVE)
215   - {
216   - // Receiving file, first the remote filename
217   - dlg->file[1] = add_filename_entry(action,1,0,dlg,table);
  117 + gchar *ptr;
218 118  
219   - dlg->file[0] = add_filename_entry(action,0,1,dlg,table);
220   - widget = gtk_button_new_with_mnemonic( _( "_Browse" ) );
221   - g_signal_connect(G_OBJECT(widget),"clicked",G_CALLBACK(browse_file),dlg);
222   - gtk_table_attach(GTK_TABLE(table),widget,3,4,1,2,0,0,2,2);
223   - }
224   - else
225   - {
226   - // Sending file, first the local filename
227   - dlg->file[0] = add_filename_entry(action,0,0,dlg,table);
228   - widget = gtk_button_new_with_mnemonic( _( "_Browse" ) );
229   - g_signal_connect(G_OBJECT(widget),"clicked",G_CALLBACK(browse_file),dlg);
230   - gtk_table_attach(GTK_TABLE(table),widget,3,4,0,1,0,0,2,2);
  119 + ptr = get_string_from_config(name, "remote", "");
  120 + v3270_ft_dialog_set_host_filename(widget,ptr);
  121 + g_free(ptr);
231 122  
232   - dlg->file[1] = add_filename_entry(action,1,1,dlg,table);
233   - }
  123 + ptr = get_string_from_config(name, "local", "");
  124 + v3270_ft_dialog_set_local_filename(widget,ptr);
  125 + g_free(ptr);
234 126  
235   - gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dlg->dialog))),GTK_WIDGET(table),FALSE,FALSE,2);
  127 + v3270_ft_dialog_set_dft_buffer_size(widget,get_integer_from_config(name,"dft",4096));
  128 + v3270_ft_dialog_set_record_length(widget,get_integer_from_config(name,"reclen",0));
  129 + v3270_ft_dialog_set_block_size(widget,get_integer_from_config(name,"blksize",0));
  130 + v3270_ft_dialog_set_primary_space(widget,get_integer_from_config(name,"primspace",0));
  131 + v3270_ft_dialog_set_secondary_space(widget,get_integer_from_config(name,"secspace",0));
236 132  
237 133 }
238 134  
239   -static void toggle_option(GtkToggleButton *button, const struct ftoption *option)
  135 +static void ft_dialog_save(GtkWidget *widget, const gchar *name)
240 136 {
241   - gboolean active = gtk_toggle_button_get_active(button);
242   - struct ftdialog * dlg = (struct ftdialog *) g_object_get_data(G_OBJECT(button),"dlg");
  137 + const gchar * filename = v3270_ft_dialog_get_local_filename(widget);
243 138  
244   - if(active)
245   - dlg->option |= option->flag;
246   - else
247   - dlg->option &= ~option->flag;
  139 + set_integer_to_config(name,"dft",v3270_ft_dialog_get_dft_buffer_size(widget));
  140 + set_integer_to_config(name,"reclen",v3270_ft_dialog_get_record_length(widget));
  141 + set_integer_to_config(name,"blksize",v3270_ft_dialog_get_block_size(widget));
  142 + set_integer_to_config(name,"primspace",v3270_ft_dialog_get_primary_space(widget));
  143 + set_integer_to_config(name,"secspace",v3270_ft_dialog_get_secondary_space(widget));
248 144  
249   - set_boolean_to_config(dlg->name,option->name,active);
250   -
251   - trace("option \"%s\" is %s (flags=%04x)",option->label,active ? "Active" : "Inactive" ,dlg->option);
252   -}
253   -
254   -static void add_transfer_options(GObject *action, struct ftdialog *dlg)
255   -{
256   - static const struct ftoption option[] =
257   - { { LIB3270_FT_OPTION_ASCII, "text", N_( "_Text file" ) },
258   - { LIB3270_FT_OPTION_CRLF, "cr", N_( "Add/Remove _CR at end of line" ) },
259   - { LIB3270_FT_OPTION_APPEND, "append", N_( "_Append" ) },
260   - { LIB3270_FT_OPTION_REMAP, "remap", N_( "_Remap ASCII Characters" ) }
261   - };
  145 + set_string_to_config(name,"local","%s",filename);
  146 + set_string_to_config(name,"remote","%s",v3270_ft_dialog_get_host_filename(widget));
262 147  
263   - GtkTable * table = GTK_TABLE(gtk_table_new(3,2,TRUE));
264   - GtkWidget * frame = gtk_frame_new( _( "Transfer options" ) );
265   - int row, col, f;
  148 +#ifdef HAVE_WIN_REGISTRY
  149 + gchar *ext = strrchr(filename,'.');
266 150  
267   - row=0;
268   - col=0;
269   - for(f=0;f < G_N_ELEMENTS(option);f++)
  151 + if(ext)
270 152 {
271   - const gchar * val = g_object_get_data(action,option[f].name);
272   - GtkWidget * widget = gtk_check_button_new_with_mnemonic( gettext(option[f].label) );
273   - gboolean active = FALSE;
  153 + // Save extension based file settings
  154 + HKEY hKey;
  155 + DWORD disp;
  156 + gchar * path = g_strdup_printf("%s\\%s\\%s\\%s",registry_path,g_get_application_name(),name,ext+1);
274 157  
275   -
276   - gtk_widget_set_name(widget,option[f].name);
277   -
278   - if(val)
279   - active = g_ascii_strcasecmp(val,"yes") == 0 ? TRUE : FALSE;
280   - else
281   - active = get_boolean_from_config(dlg->name,option[f].name,FALSE);
282   -
283   - if(active)
284   - dlg->option |= option[f].flag;
285   -
286   - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),active);
287   -
288   - g_object_set_data(G_OBJECT(widget),"dlg",(gpointer) dlg);
289   - g_signal_connect(G_OBJECT(widget),"toggled", G_CALLBACK(toggle_option),(gpointer) &option[f]);
290   -
291   - 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);
292   - if(col++ > 0)
  158 + if(RegCreateKeyEx(HKEY_CURRENT_USER,path,0,NULL,REG_OPTION_NON_VOLATILE,KEY_SET_VALUE,NULL,&hKey,&disp) == ERROR_SUCCESS)
293 159 {
294   - row++;
295   - col=0;
296   - }
297   - }
  160 + DWORD value;
298 161  
299   - gtk_container_add(GTK_CONTAINER(frame),GTK_WIDGET(table));
300   - gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dlg->dialog))),GTK_WIDGET(frame),FALSE,FALSE,2);
  162 + value = (DWORD) v3270_ft_dialog_get_options(widget));
  163 + RegSetValueEx(hKey, "options", 0, REG_DWORD,(const BYTE *) &value,sizeof(value));
301 164  
302   -}
303   -
304   -static void setup_dft(GObject *action, struct ftdialog *dlg, GtkWidget **label)
305   -{
306   - gchar *val = g_object_get_data(action,"dft");
307   -
308   - *label = gtk_label_new_with_mnemonic( _( "DFT B_uffer size:" ) );
  165 + value = (DWORD) v3270_ft_dialog_get_dft_buffer_size(widget));
  166 + RegSetValueEx(hKey, "dft", 0, REG_DWORD,(const BYTE *) &value,sizeof(value));
309 167  
310   - gtk_misc_set_alignment(GTK_MISC(*label),0,.5);
  168 + value = (DWORD) v3270_ft_dialog_get_record_length(widget));
  169 + RegSetValueEx(hKey, "reclen", 0, REG_DWORD,(const BYTE *) &value,sizeof(value));
311 170  
312   - dlg->parm[4] = GTK_ENTRY(gtk_entry_new());
313   - gtk_widget_set_name(GTK_WIDGET(dlg->parm[4]),"dftsize");
314   - gtk_entry_set_max_length(dlg->parm[4],10);
315   - gtk_entry_set_width_chars(dlg->parm[4],10);
  171 + value = (DWORD) v3270_ft_dialog_get_block_size(widget));
  172 + RegSetValueEx(hKey, "blksize", 0, REG_DWORD,(const BYTE *) &value,sizeof(value));
316 173  
317   - gtk_entry_set_text(GTK_ENTRY(dlg->parm[4]),val ? val : "4096");
  174 + value = (DWORD) v3270_ft_dialog_get_primary_space(widget));
  175 + RegSetValueEx(hKey, "primspace", 0, REG_DWORD,(const BYTE *) &value,sizeof(value));
318 176  
319   - gtk_label_set_mnemonic_widget(GTK_LABEL(*label),GTK_WIDGET(dlg->parm[4]));
  177 + value = (DWORD) v3270_ft_dialog_get_secondary_space(widget));
  178 + RegSetValueEx(hKey, "secspace", 0, REG_DWORD,(const BYTE *) &value,sizeof(value));
320 179  
321   -}
322   -
323   -static void update(H3270FT *ft, unsigned long length, double kbytes_sec)
324   -{
325   - GtkLabel **info = (GtkLabel **) g_object_get_data(G_OBJECT(ft->widget),"info");
  180 + RegCloseKey(hKey);
  181 + }
326 182  
327   - if(length && info[0])
328   - {
329   - gchar *str = g_strdup_printf("%ld",length);
330   - gtk_label_set_text(info[0],str);
331   - g_free(str);
  183 + g_free(path);
332 184 }
333 185  
334   - if(kbytes_sec && info[2])
335   - {
336   - gchar *str = g_strdup_printf("%ld KB/s",(unsigned long) kbytes_sec);
337   - gtk_label_set_text(info[2],str);
338   - g_free(str);
339   - }
  186 +#endif // HAVE_WIN_REGISTRY
340 187  
341 188 }
342 189  
343   -static void ft_complete(H3270FT *ft, unsigned long length,double kbytes_sec,const char *mode)
  190 +static void ft_complete(H3270FT *ft, unsigned long length,double kbytes_sec)
344 191 {
345   - update(ft,length,kbytes_sec);
  192 + v3270_ft_progress_update(GTK_WIDGET(ft->widget),length,length,kbytes_sec);
346 193 }
347 194  
348 195 static void ft_message(struct _h3270ft *ft, const char *text)
349 196 {
350   - GtkLabel **msg = (GtkLabel **) g_object_get_data(G_OBJECT(ft->widget),"msg");
351   - gtk_label_set_text(msg[2],gettext(text));
  197 + v3270_ft_progress_set_message(GTK_WIDGET(ft->widget),gettext(text));
352 198 }
353 199  
354 200 static void ft_update(H3270FT *ft, unsigned long current, unsigned long length, double kbytes_sec)
355 201 {
356   - GtkLabel **info = (GtkLabel **) g_object_get_data(G_OBJECT(ft->widget),"info");
357   - GtkProgressBar * pbar = g_object_get_data(G_OBJECT(ft->widget),"progress");
358   - gchar * str;
359   -
360   - update(ft, length, kbytes_sec);
361   -
362   - if(current && info[1])
363   - {
364   - str = g_strdup_printf("%ld",current);
365   - gtk_label_set_text(info[1],str);
366   - g_free(str);
367   - }
368   -
369   - if(length)
370   - gtk_progress_bar_set_fraction(pbar,((gdouble) current) / ((gdouble) length));
371   - else
372   - gtk_progress_bar_pulse(pbar);
373   -
  202 + v3270_ft_progress_update(GTK_WIDGET(ft->widget), current, length, kbytes_sec);
374 203 }
375 204  
376 205 static void ft_running(H3270FT *ft, int is_cut)
377 206 {
378   -
379 207 }
380 208  
381 209 static void ft_aborting(H3270FT *ft)
382 210 {
383   - GtkLabel **msg = (GtkLabel **) g_object_get_data(G_OBJECT(ft->widget),"msg");
384   - gtk_label_set_text(msg[2],_("Aborting"));
385 211 }
386 212  
387 213 static void ft_state_changed(H3270FT *ft, LIB3270_FT_STATE state)
388 214 {
389   -
390 215 }
391 216  
392   -static void run_ft_dialog(GObject *action, GtkWidget *widget, struct ftdialog *dlg)
  217 +static GtkWidget * start_file_transfer(GtkAction *action, GtkWidget *widget, GtkWidget *info)
393 218 {
394   - H3270FT * ft = NULL;
395   - const char * msg = NULL;
396   - int f;
397   - int parm[G_N_ELEMENTS(dlg->parm)];
398   - const gchar * remote_filename;
399   -
400   - g_signal_connect(G_OBJECT(dlg->file[0]),"changed",G_CALLBACK(check_entry),dlg);
401   - g_signal_connect(G_OBJECT(dlg->file[1]),"changed",G_CALLBACK(check_remote_filename),dlg);
402   -
403   - for(f=0;f<2;f++)
404   - gtk_widget_set_sensitive(dlg->ready,is_dialog_ok(GTK_EDITABLE(dlg->file[f]),dlg));
405   -
406   - gtk_widget_show_all(dlg->dialog);
407   -
408   - for(f=0;f<G_N_ELEMENTS(dlg->parm);f++)
409   - {
410   - if(dlg->parm[f])
411   - {
412   - gchar *val = get_attribute(action,dlg,gtk_widget_get_name(GTK_WIDGET(dlg->parm[f])));
413   -
414   - gtk_entry_set_alignment(GTK_ENTRY(dlg->parm[f]),1);
415   -
416   - if(val && *val)
417   - gtk_entry_set_text(dlg->parm[f],val);
418   -
419   - g_free(val);
420   - g_signal_connect(G_OBJECT(dlg->parm[f]),"changed",G_CALLBACK(check_entry),dlg);
421   - }
422   - }
423   -
424   - if(gtk_dialog_run(GTK_DIALOG(dlg->dialog)) != GTK_RESPONSE_ACCEPT)
425   - {
426   - gtk_widget_destroy(dlg->dialog);
427   - dlg->dialog = NULL;
428   - return;
429   - }
430   -
431   - for(f=0;f<G_N_ELEMENTS(dlg->parm);f++)
432   - {
433   - if(dlg->parm[f])
434   - {
435   - parm[f] = atoi(gtk_entry_get_text(dlg->parm[f]));
436   - set_string_to_config(dlg->name,gtk_widget_get_name(GTK_WIDGET(dlg->parm[f])),"%d",parm[f]);
437   - }
438   - else
439   - {
440   - parm[f] = 0;
441   - }
442   - }
443   -
444   - remote_filename = gtk_entry_get_text(dlg->file[1]);
445   -
446   - set_string_to_config(dlg->name,"local","%s",gtk_entry_get_text(dlg->file[0]));
447   - set_string_to_config(dlg->name,"remote","%s",remote_filename);
448   -
449   - if(!gtk_entry_get_text_length(dlg->file[0]))
450   - {
451   - // Local filename wasn´t set, create a new one
452   - gchar *basename = g_path_get_basename(remote_filename);
453   - gchar *filename = g_build_filename(g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS),basename,NULL);
454   - gtk_entry_set_text(dlg->file[0],filename);
455   - g_free(filename);
456   - g_free(basename);
457   - }
458   -
459   - ft = lib3270_ft_new( v3270_get_session(widget),
460   - dlg->option,
461   - gtk_entry_get_text(dlg->file[0]),
462   - remote_filename,
463   - parm[0], // lrecl
464   - parm[2], // blksize
465   - parm[1], // primspace
466   - parm[3], // secspace
467   - parm[4], // dft
468   - &msg );
469   -
470   -
471   -#if GTK_CHECK_VERSION(2,18,0)
472   - gtk_widget_set_visible(dlg->dialog,FALSE);
473   -#else
474   - gtk_widget_hide(dlg->dialog);
475   -#endif // GTK(2,18,0)
476   -
477   - if(msg)
478   - {
479   - GtkWidget *popup = gtk_message_dialog_new_with_markup(
480   - GTK_WINDOW(gtk_widget_get_toplevel(widget)),
481   - GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
482   - GTK_MESSAGE_ERROR,GTK_BUTTONS_CLOSE,
483   - "%s", _( "Can't start file transfer" ));
484   -
485   - trace("msg=%s",msg);
486   - gtk_window_set_title(GTK_WINDOW(popup),_("File transfer error"));
487   -
488   - gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(popup),"%s",gettext(msg));
489   -
490   - gtk_widget_show_all(popup);
491   - gtk_dialog_run(GTK_DIALOG(popup));
492   - gtk_widget_destroy(popup);
493   -
494   - }
495   -
496   - if(ft)
497   - {
498   - // Setup FT callbacks, create popup window
499   - /*
500   - http://www.suggestsoft.com/images/medieval-software/medieval-bluetooth-obex-file-transfer.gif
501   -
502   - --Informations----------------------------------------
503   - |
504   - | From: xxx.xxx.xxx.xxx.xxx.xxx.xxx.xxx.xxx.xxx.xxx.xxx.xxx
505   - |
506   - | To: xxx.xxx.xxx.xxx.xxx.xxx.xxx.xxx.xxx.xxx.xxx.xxx.xxx
507   - |
508   - | Status: xxx.xxx.xxx.xxx.xxx.xxx.xxx.xxx.xxx.xxx.xxx.xxx.xxx
509   - ------------------------------------------------------
510   -
511   - --Progress----------------------------------------------
512   - |
513   - | Total: xxx.xxx.xxx Current: xxx.xxx.xxx
514   - |
515   - | Started: xx:xx:xx ETA: xx:xx:xx
516   - |
517   - | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
518   - --------------------------------------------------------
519   -
520   - [Cancel]
521   - */
522   - GtkWidget *container;
523   - GtkWidget *ftdialog;
524   -
525   - ftdialog = gtk_dialog_new_with_buttons( _( "File transfer" ),
  219 + GtkWidget * dialog = gtk_dialog_new_with_buttons( _( "File transfer" ),
526 220 GTK_WINDOW(gtk_widget_get_toplevel(widget)),
527 221 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
528   - GTK_STOCK_CLOSE,GTK_RESPONSE_CLOSE,NULL );
529   -
530   -
531   -#if GTK_CHECK_VERSION(3,0,0)
532   - container = gtk_box_new(GTK_ORIENTATION_VERTICAL,2);
533   -#else
534   - container = gtk_vbox_new(FALSE,2);
535   -#endif // GTK(3,0,0)
536   -
537   - gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(ftdialog))),container,TRUE,TRUE,2);
538   -
539   - // Information frame
540   - {
541   - static const gchar *text[] = { N_( "_From" ), N_( "_To" ), N_( "_Status" ) };
542   -
543   - GtkWidget * frame = gtk_frame_new( _( "Informations" ) );
544   - GtkWidget * table = gtk_table_new(G_N_ELEMENTS(text),2,FALSE);
545   - int f;
546   - GtkWidget **entry = g_new0(GtkWidget *, G_N_ELEMENTS(text));
547   -
548   - g_object_set_data_full(G_OBJECT(ftdialog),"msg",entry,g_free);
549   - gtk_container_set_border_width(GTK_CONTAINER(frame),3);
550   -
551   - for(f=0;f<G_N_ELEMENTS(text);f++)
552   - {
553   - GtkWidget * label = gtk_label_new_with_mnemonic("");
554   - gchar * str = g_strdup_printf("<b>%s:</b>",gettext(text[f]));
555   -
556   - gtk_label_set_markup_with_mnemonic(GTK_LABEL(label),str);
557   - g_free(str);
558   -
559   - gtk_misc_set_alignment(GTK_MISC(label),0,0);
560   - gtk_table_attach(GTK_TABLE(table),label,0,1,f,f+1,GTK_FILL,GTK_FILL,2,2);
561   -
562   - entry[f] = gtk_label_new("");
563   - gtk_label_set_width_chars(GTK_LABEL(entry[f]),70);
564   - gtk_misc_set_alignment(GTK_MISC(entry[f]),0,0);
565   -
566   -// gtk_entry_set_width_chars(GTK_ENTRY(entry[f]),70);
567   -// gtk_editable_set_editable(GTK_EDITABLE(entry[f]),FALSE);
568   -
569   - gtk_table_attach(GTK_TABLE(table),entry[f],1,2,f,f+1,GTK_FILL|GTK_EXPAND,GTK_FILL|GTK_EXPAND,2,2);
570   -
571   - gtk_label_set_mnemonic_widget(GTK_LABEL(label),entry[f]);
572   - }
573   -
574   - for(f=0;f<2;f++)
575   - gtk_label_set_text(GTK_LABEL(entry[f]),gtk_entry_get_text(dlg->file[f]));
576   -
577   - gtk_container_add(GTK_CONTAINER(frame),table);
578   - gtk_box_pack_start(GTK_BOX(container),frame,TRUE,TRUE,2);
579   -
580   - }
581   -
582   - // Progress frame
583   - {
584   - static const gchar *text[] = { N_( "T_otal" ), N_( "C_urrent" ), N_( "Spee_d" ), N_( "ET_A" ) };
585   -
586   - GtkWidget * frame = gtk_frame_new( _( "Progress" ) );
587   - GtkWidget * table = gtk_table_new(3,4,TRUE);
588   - GtkWidget **entry = g_new0(GtkWidget *, G_N_ELEMENTS(text));
589   - GtkWidget * progress = gtk_progress_bar_new();
590   - int pos = 0;
591   -
592   - g_object_set_data_full(G_OBJECT(ftdialog),"info",entry,g_free);
593   - g_object_set_data(G_OBJECT(ftdialog),"progress",progress);
594   -
595   - gtk_container_set_border_width(GTK_CONTAINER(frame),3);
596   -// gtk_container_set_border_width(GTK_CONTAINER(table),6);
597   -
598   - for(f=0;f<2;f++)
599   - {
600   - // Left box
601   - GtkWidget * label;
602   - gchar * str;
603   -
604   - str = g_strdup_printf("<b>%s:</b>",gettext(text[pos]));
605   - label = gtk_label_new("");
606   - gtk_label_set_markup_with_mnemonic(GTK_LABEL(label),str);
607   - g_free(str);
608   -
609   - gtk_misc_set_alignment(GTK_MISC(label),0,0);
610   - gtk_table_attach(GTK_TABLE(table),label,0,1,f,f+1,GTK_FILL,GTK_FILL,2,2);
611   -
612   - entry[pos] = gtk_label_new(_( "N/A" ) );
613   - gtk_misc_set_alignment(GTK_MISC(entry[f]),0,0);
614   -
615   - gtk_table_attach(GTK_TABLE(table),entry[pos],1,2,f,f+1,GTK_EXPAND,GTK_FILL,2,2);
616   -
617   - gtk_label_set_mnemonic_widget(GTK_LABEL(label),entry[pos++]);
618   -
619   - // Right box
620   - str = g_strdup_printf("<b>%s:</b>",gettext(text[pos]));
621   - label = gtk_label_new("");
622   - gtk_label_set_markup_with_mnemonic(GTK_LABEL(label),str);
623   - g_free(str);
624   -
625   - gtk_misc_set_alignment(GTK_MISC(label),0,0);
626   - gtk_table_attach(GTK_TABLE(table),label,2,3,f,f+1,GTK_FILL,GTK_FILL,2,2);
627   -
628   - entry[pos] = gtk_label_new(_("N/A" ));
629   - gtk_misc_set_alignment(GTK_MISC(entry[f]),0,0);
630   - gtk_table_attach(GTK_TABLE(table),entry[pos],3,4,f,f+1,GTK_EXPAND,GTK_FILL,2,2);
631   -
632   - gtk_label_set_mnemonic_widget(GTK_LABEL(label),entry[pos++]);
633   -
634   - }
635   -
636   - gtk_table_attach(GTK_TABLE(table),progress,0,4,f,f+1,GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,2,2);
637   -
638   - gtk_container_add(GTK_CONTAINER(frame),table);
639   - gtk_box_pack_start(GTK_BOX(container),frame,TRUE,TRUE,2);
640   -
641   -
642   - }
643   -
644   - ft->widget = ftdialog;
645   - ft->complete = ft_complete;
646   - ft->update = ft_update;
647   - ft->running = ft_running;
648   - ft->aborting = ft_aborting;
649   - ft->state_changed = ft_state_changed;
650   - ft->message = ft_message;
651   -
652   - gtk_widget_show_all(ftdialog);
653   - lib3270_ft_start(v3270_get_session(widget));
654   -
655   - trace("%s: Running dialog %p",__FUNCTION__,ftdialog);
656   - gtk_dialog_run(GTK_DIALOG(ftdialog));
657   - trace("%s: Dialog %p ends",__FUNCTION__,ftdialog);
658   -
659   - lib3270_ft_destroy(v3270_get_session(widget));
660   -
661   - gtk_widget_destroy(ftdialog);
662   - }
663   -
664   - gtk_widget_destroy(dlg->dialog);
665   - dlg->dialog = NULL;
666   -
667   -}
668   -
669   -static void add_buttons(struct ftdialog *dlg)
670   -{
671   - dlg->ready = gtk_dialog_add_button(GTK_DIALOG(dlg->dialog),
672   - (dlg->option & LIB3270_FT_OPTION_RECEIVE) != 0 ? GTK_STOCK_SAVE : GTK_STOCK_OPEN,
673   - GTK_RESPONSE_ACCEPT);
674   -
675   - gtk_widget_set_sensitive(dlg->ready,FALSE);
676   -
677   - gtk_dialog_add_button(GTK_DIALOG(dlg->dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
  222 + GTK_STOCK_CANCEL,GTK_RESPONSE_CLOSE,NULL );
  223 + const gchar * local = v3270_ft_dialog_get_local_filename(info);
  224 + const gchar * remote = v3270_ft_dialog_get_host_filename(info);
  225 +
  226 + gtk_widget_set_visible(info,FALSE);
  227 +
  228 + H3270FT * ft = lib3270_ft_new(
  229 + v3270_get_session(widget),
  230 + v3270_ft_dialog_get_options(info),
  231 + local,
  232 + remote,
  233 + v3270_ft_dialog_get_record_length(info),
  234 + v3270_ft_dialog_get_block_size(info),
  235 + v3270_ft_dialog_get_primary_space(info),
  236 + v3270_ft_dialog_get_secondary_space(info),
  237 + v3270_ft_dialog_get_dft_buffer_size(info)
  238 + );
  239 +
  240 + if(!ft)
  241 + return NULL;
  242 +
  243 + // Create FT progress dialog
  244 + GtkWidget * progress = v3270_ft_progress_new();
  245 +
  246 + ft->widget = progress;
  247 + ft->complete = ft_complete;
  248 + ft->update = ft_update;
  249 + ft->running = ft_running;
  250 + ft->aborting = ft_aborting;
  251 + ft->state_changed = ft_state_changed;
  252 + ft->message = ft_message;
  253 +
  254 + v3270_ft_progress_set_host_filename(progress,remote);
  255 + v3270_ft_progress_set_local_filename(progress,local);
  256 + v3270_ft_progress_set_message(progress,_("Starting transfer"));
  257 +
  258 + gtk_widget_show_all(progress);
  259 + gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),GTK_WIDGET(progress),FALSE,TRUE,2);
  260 +
  261 + return dialog;
678 262 }
679 263  
680   -
681 264 void download_action(GtkAction *action, GtkWidget *widget)
682 265 {
683   - struct ftdialog dlg;
  266 + const gchar *name = g_object_get_data(G_OBJECT(action),"configuration");
  267 +
  268 + if(!name)
  269 + name = "download";
684 270  
685 271 if(lib3270_get_ft_state(v3270_get_session(widget)) != LIB3270_FT_STATE_NONE)
686 272 {
687   - error_dialog(widget,_( "Can't start download" ), _( "File transfer is already active" ), NULL);
  273 + lib3270_popup_dialog( v3270_get_session(widget),
  274 + LIB3270_NOTIFY_ERROR,
  275 + _( "Request failed" ),
  276 + _( "Can't start download." ),
  277 + "%s",
  278 + _( "File transfer is already active." ));
  279 +
688 280 return;
689 281 }
690 282  
691   - memset(&dlg,0,sizeof(dlg));
  283 + GtkWidget *dialog = v3270_ft_dialog_new(widget,LIB3270_FT_OPTION_RECEIVE|get_options_from_config(name));
  284 + GtkWidget *progress = NULL;
692 285  
693   - dlg.dialog = gtk_dialog_new();
694   - gtk_window_set_title(GTK_WINDOW(dlg.dialog),_( "Receive file from host" ));
695   - gtk_window_set_transient_for(GTK_WINDOW(dlg.dialog),GTK_WINDOW(gtk_widget_get_toplevel(widget)));
  286 + ft_dialog_load(dialog,name);
696 287  
697   - dlg.name = gtk_action_get_name(action);
698   - dlg.option = LIB3270_FT_OPTION_RECEIVE;
  288 + if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
  289 + {
  290 + ft_dialog_save(dialog,name);
  291 + progress = start_file_transfer(action, widget, dialog);
  292 + }
699 293  
700   - add_buttons(&dlg);
701   - add_file_fields(G_OBJECT(action),&dlg);
702   - add_transfer_options(G_OBJECT(action),&dlg);
  294 + gtk_widget_destroy(dialog);
703 295  
  296 + if(progress)
704 297 {
705   - /* Add dft option */
706   -#if GTK_CHECK_VERSION(3,0,0)
707   - GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,2);
708   -#else
709   - GtkWidget *hbox = gtk_hbox_new(FALSE,2);
710   -#endif // GTK(3,0,0)
711   - GtkWidget *label = NULL;
712   -
713   - gtk_container_set_border_width(GTK_CONTAINER(hbox),4);
714   -
715   - setup_dft(G_OBJECT(action),&dlg,&label);
  298 + gtk_widget_show(progress);
  299 + lib3270_ft_start(v3270_get_session(widget));
  300 + gtk_dialog_run(GTK_DIALOG(progress));
  301 + lib3270_ft_destroy(v3270_get_session(widget));
716 302  
717   - gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,FALSE,0);
718   - gtk_box_pack_start(GTK_BOX(hbox),GTK_WIDGET(dlg.parm[4]),FALSE,FALSE,0);
719   - gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dlg.dialog))),hbox,FALSE,FALSE,2);
  303 + gtk_widget_destroy(progress);
720 304 }
721 305  
722   - run_ft_dialog(G_OBJECT(action),widget,&dlg);
723   -
724   -}
725   -
726   -static void toggle_format(GtkToggleButton *button, const struct ftmask *option)
727   -{
728   - gboolean active = gtk_toggle_button_get_active(button);
729   - struct ftdialog * dlg = (struct ftdialog *) g_object_get_data(G_OBJECT(button),"dlg");
730   - const gchar * name = (const gchar *) g_object_get_data(G_OBJECT(button),"setupname");
731   -
732   - dlg->option &= ~option->mask;
733   - dlg->option |= option->flag;
734   -
735   - if(active)
736   - {
737   - set_string_to_config(dlg->name,name,"%s",option->name);
738   - trace("%s=%s (flags=%04x)",name,option->name,dlg->option);
739   - }
740 306 }
741 307  
742 308 void upload_action(GtkAction *action, GtkWidget *widget)
743 309 {
744   - struct ftdialog dlg;
  310 + const gchar *name = g_object_get_data(G_OBJECT(action),"configuration");
  311 +
  312 + if(!name)
  313 + name = "upload";
745 314  
746 315 if(lib3270_get_ft_state(v3270_get_session(widget)) != LIB3270_FT_STATE_NONE)
747 316 {
748   - error_dialog(widget,_( "Can't start upload" ), _( "File transfer is already active" ), NULL);
  317 + lib3270_popup_dialog( v3270_get_session(widget),
  318 + LIB3270_NOTIFY_ERROR,
  319 + _( "Request failed" ),
  320 + _( "Can't start upload." ),
  321 + "%s",
  322 + _( "File transfer is already active." ));
  323 +
749 324 return;
750 325 }
751 326  
752   - memset(&dlg,0,sizeof(dlg));
  327 + GtkWidget *dialog = v3270_ft_dialog_new(widget,LIB3270_FT_OPTION_SEND|get_options_from_config(name));
  328 + GtkWidget *progress = NULL;
753 329  
754   - dlg.dialog = gtk_dialog_new();
755   - gtk_window_set_title(GTK_WINDOW(dlg.dialog),_( "Send file to host" ));
756   - gtk_window_set_transient_for(GTK_WINDOW(dlg.dialog),GTK_WINDOW(gtk_widget_get_toplevel(widget)));
  330 + ft_dialog_load(dialog,name);
757 331  
758   - dlg.name = gtk_action_get_name(action);
759   - dlg.option = LIB3270_FT_OPTION_SEND;
  332 + if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
  333 + {
  334 + ft_dialog_save(dialog,name);
  335 + progress = start_file_transfer(action, widget, dialog);
  336 + }
760 337  
761   - add_buttons(&dlg);
762   - add_file_fields(G_OBJECT(action),&dlg);
763   - add_transfer_options(G_OBJECT(action),&dlg);
  338 + gtk_widget_destroy(dialog);
764 339  
  340 + if(progress)
765 341 {
  342 + gtk_widget_show(progress);
766 343  
767   - static const struct ftmask recfm[] =
768   - {
769   - { LIB3270_FT_RECORD_FORMAT_DEFAULT, LIB3270_FT_RECORD_FORMAT_MASK, "default", N_( "Default" ) },
770   - { LIB3270_FT_RECORD_FORMAT_FIXED, LIB3270_FT_RECORD_FORMAT_MASK, "fixed", N_( "Fixed" ) },
771   - { LIB3270_FT_RECORD_FORMAT_VARIABLE, LIB3270_FT_RECORD_FORMAT_MASK, "variable", N_( "Variable" ) },
772   - { LIB3270_FT_RECORD_FORMAT_UNDEFINED, LIB3270_FT_RECORD_FORMAT_MASK, "undefined", N_( "Undefined" ) },
773   - };
774   -
775   - static const struct ftmask units[] =
776   - {
777   - { LIB3270_FT_ALLOCATION_UNITS_DEFAULT, LIB3270_FT_ALLOCATION_UNITS_MASK, "default", N_( "Default" ) },
778   - { LIB3270_FT_ALLOCATION_UNITS_TRACKS, LIB3270_FT_ALLOCATION_UNITS_MASK, "tracks", N_( "Tracks" ) },
779   - { LIB3270_FT_ALLOCATION_UNITS_CYLINDERS, LIB3270_FT_ALLOCATION_UNITS_MASK, "cilinders", N_( "Cylinders" ) },
780   - { LIB3270_FT_ALLOCATION_UNITS_AVBLOCK, LIB3270_FT_ALLOCATION_UNITS_MASK, "avblock", N_( "Avblock" ) },
781   - };
782   -
783   - static const struct _fdesc
784   - {
785   - const gchar * title;
786   - const gchar * name;
787   - const struct ftmask * option;
788   - } fdesk[] =
789   - {
790   - { N_( "Record format" ), "recordformat", recfm },
791   - { N_( "Space allocation units" ), "allocationunits", units }
792   - };
793   -
794   -
795   - int f;
796   -
797   -#if GTK_CHECK_VERSION(3,0,0)
798   - GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,2);
799   -#else
800   - GtkWidget *box = gtk_hbox_new(TRUE,2);
801   -#endif // GTK(3,0,0)
802   -
803   - for(f=0;f<2;f++)
804   - {
805   - GtkWidget * frame = gtk_frame_new(gettext(fdesk[f].title));
806   - GSList * group = NULL;
807   - gchar * setup = get_attribute(G_OBJECT(action),&dlg,fdesk[f].name);
808   - int p;
809   -#if GTK_CHECK_VERSION(3,0,0)
810   - GtkWidget * vbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,2);
811   - gtk_box_set_homogeneous(GTK_BOX(vbox),TRUE);
812   -#else
813   - GtkWidget * vbox = gtk_vbox_new(TRUE,2);
814   -#endif // GTK(3,0,0)
815   -
816   - for(p=0;p<4;p++)
817   - {
818   - GtkWidget *widget = gtk_radio_button_new_with_label(group,gettext(fdesk[f].option[p].label));
819   - g_object_set_data(G_OBJECT(widget),"dlg",(gpointer) &dlg);
820   - g_object_set_data(G_OBJECT(widget),"setupname",(gpointer) fdesk[f].name);
821   -
822   - g_signal_connect(G_OBJECT(widget),"toggled", G_CALLBACK(toggle_format),(gpointer) &fdesk[f].option[p]);
823   -
824   - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),!g_ascii_strcasecmp(fdesk[f].option[p].name,setup));
825   - group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(widget));
826   - gtk_box_pack_start(GTK_BOX(vbox),widget,TRUE,TRUE,0);
827   - }
828   -
829   - g_free(setup);
830   -
831   - gtk_container_add(GTK_CONTAINER(frame),GTK_WIDGET(vbox));
832   - gtk_box_pack_start(GTK_BOX(box),frame,TRUE,TRUE,2);
833   - }
834   -
835   - gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dlg.dialog))),box,TRUE,TRUE,2);
836   - }
837   -
838   - {
839   - // Add options
840   - static const struct _fld
841   - {
842   - const gchar *name;
843   - const gchar *label;
844   - }
845   - fld[] = { { "lrecl", N_( "LRECL:" ) },
846   - { "primary", N_( "Primary space:" ) },
847   - { "blksize", N_( "BLKSIZE:" ) },
848   - { "secondary", N_( "Secondary space:" ) },
849   - { "dftsize", N_( "DFT B_uffer size:" ) }
850   - };
851   -
852   - GtkTable * table = GTK_TABLE(gtk_table_new(2,2,FALSE));
853   -
854   - int row, col, f;
855   -
856   - gtk_container_set_border_width(GTK_CONTAINER(table),2);
857   -
858   - row=0;
859   - col=0;
860   - for(f=0;f < 5;f++)
861   - {
862   - GtkWidget *label = gtk_label_new_with_mnemonic(gettext(fld[f].label));
863   -
864   - gtk_misc_set_alignment(GTK_MISC(label),0,.5);
865   - dlg.parm[f] = GTK_ENTRY(gtk_entry_new());
866   -
867   - gtk_widget_set_name(GTK_WIDGET(dlg.parm[f]),fld[f].name);
868   -
869   - gtk_label_set_mnemonic_widget(GTK_LABEL(label),GTK_WIDGET(dlg.parm[f]));
870   -
871   - gtk_table_attach(table,label,col,col+1,row,row+1,GTK_EXPAND|GTK_SHRINK|GTK_FILL,GTK_EXPAND|GTK_SHRINK|GTK_FILL,2,2);
872   - gtk_table_attach(table,GTK_WIDGET(dlg.parm[f]),col+1,col+2,row,row+1,GTK_EXPAND|GTK_SHRINK|GTK_FILL,GTK_EXPAND|GTK_SHRINK|GTK_FILL,2,2);
873   -
874   - col += 2;
875   - if(col++ > 3)
876   - {
877   - row++;
878   - col=0;
879   - }
880   -
881   - }
882   -
883   - gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dlg.dialog))),GTK_WIDGET(table),TRUE,TRUE,2);
884   -
  344 + lib3270_ft_start(v3270_get_session(widget));
  345 + gtk_dialog_run(GTK_DIALOG(progress));
  346 + lib3270_ft_destroy(v3270_get_session(widget));
885 347  
  348 + gtk_widget_destroy(progress);
886 349 }
887 350  
888   - trace("Running ft fialog %p",&dlg);
889   -
890   - run_ft_dialog(G_OBJECT(action),widget,&dlg);
891   -
892   -
893 351 }
894 352  
895 353  
... ...
src/pw3270/ft/ftdialog.c
... ... @@ -181,11 +181,15 @@ static GtkWidget * ftvalue_new(v3270FTD *dialog, GtkGrid *grid, int r, const str
181 181 dialog->value[id] = GTK_SPIN_BUTTON(gtk_spin_button_new_with_range(0,99999,1));
182 182  
183 183 gtk_widget_set_hexpand(GTK_WIDGET(label),TRUE);
184   - gtk_widget_set_tooltip_text(GTK_WIDGET(label),gettext(val[f].tooltip));
185 184 gtk_misc_set_alignment(GTK_MISC(label),0,0.5);
186 185  
187 186 gtk_label_set_mnemonic_widget(GTK_LABEL(label),GTK_WIDGET(dialog->value[id]));
188   - gtk_widget_set_tooltip_text(GTK_WIDGET(dialog->value[id]),gettext(val[f].tooltip));
  187 +
  188 + if(val[f].tooltip && *val[f].tooltip)
  189 + {
  190 + gtk_widget_set_tooltip_text(GTK_WIDGET(label),gettext(val[f].tooltip));
  191 + gtk_widget_set_tooltip_text(GTK_WIDGET(dialog->value[id]),gettext(val[f].tooltip));
  192 + }
189 193  
190 194 g_object_set_data(G_OBJECT(dialog->value[id]),"cfg",(gpointer) &val[f]);
191 195  
... ... @@ -224,10 +228,13 @@ static GtkWidget * ftradio_new(v3270FTD *dialog, const gchar *title, const gchar
224 228 return GTK_WIDGET(frame);
225 229 }
226 230  
227   -GtkWidget * v3270_ft_dialog_new(LIB3270_FT_OPTION options)
  231 +GtkWidget * v3270_ft_dialog_new(GtkWidget *parent, LIB3270_FT_OPTION options)
228 232 {
229 233 v3270FTD *dialog = g_object_new(GTK_TYPE_V3270FTD, NULL);
230 234  
  235 + if(parent)
  236 + gtk_window_set_transient_for(GTK_WINDOW(dialog),GTK_WINDOW(gtk_widget_get_toplevel(parent)));
  237 +
231 238 // Set defaults
232 239 dialog->options = options;
233 240  
... ... @@ -313,8 +320,8 @@ GtkWidget * v3270_ft_dialog_new(LIB3270_FT_OPTION options)
313 320 gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),ftoption_new(dialog,opt),FALSE,TRUE,2);
314 321  
315 322 // Create DFT
316   - GtkBox * box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_HORIZONTAL,2));
317   - GtkWidget * label = gtk_label_new_with_mnemonic(_("DFT B_uffer size:"));
  323 + GtkBox * box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_HORIZONTAL,2));
  324 + GtkWidget * label = gtk_label_new_with_mnemonic(_("DFT B_uffer size:"));
318 325 dialog->value[VALUE_DFT] = GTK_SPIN_BUTTON(gtk_spin_button_new_with_range(256,32768,1));
319 326 gtk_misc_set_alignment(GTK_MISC(label),0,0.5);
320 327  
... ... @@ -577,3 +584,77 @@ void v3270_ft_dialog_set_tso(GtkWidget *widget,gboolean flag)
577 584 }
578 585  
579 586 }
  587 +
  588 +LIB3270_EXPORT void v3270_ft_dialog_set_dft_buffer_size(GtkWidget *widget, gint value)
  589 +{
  590 + g_return_if_fail(GTK_IS_V3270FTD(widget));
  591 + gtk_spin_button_set_value(GTK_V3270FTD(widget)->value[VALUE_DFT],value);
  592 +}
  593 +
  594 +LIB3270_EXPORT void v3270_ft_dialog_set_record_length(GtkWidget *widget, gint value)
  595 +{
  596 + g_return_if_fail(GTK_IS_V3270FTD(widget));
  597 + if(GTK_V3270FTD(widget)->value[VALUE_LRECL])
  598 + gtk_spin_button_set_value(GTK_V3270FTD(widget)->value[VALUE_LRECL],value);
  599 +}
  600 +
  601 +LIB3270_EXPORT void v3270_ft_dialog_set_block_size(GtkWidget *widget, gint value)
  602 +{
  603 + g_return_if_fail(GTK_IS_V3270FTD(widget));
  604 + if(GTK_V3270FTD(widget)->value[VALUE_BLKSIZE])
  605 + gtk_spin_button_set_value(GTK_V3270FTD(widget)->value[VALUE_BLKSIZE],value);
  606 +}
  607 +
  608 +LIB3270_EXPORT void v3270_ft_dialog_set_primary_space(GtkWidget *widget, gint value)
  609 +{
  610 + g_return_if_fail(GTK_IS_V3270FTD(widget));
  611 + if(GTK_V3270FTD(widget)->value[VALUE_PRIMSPACE])
  612 + gtk_spin_button_set_value(GTK_V3270FTD(widget)->value[VALUE_PRIMSPACE],value);
  613 +}
  614 +
  615 +LIB3270_EXPORT void v3270_ft_dialog_set_secondary_space(GtkWidget *widget, gint value)
  616 +{
  617 + g_return_if_fail(GTK_IS_V3270FTD(widget));
  618 + if(GTK_V3270FTD(widget)->value[VALUE_SECSPACE])
  619 + gtk_spin_button_set_value(GTK_V3270FTD(widget)->value[VALUE_SECSPACE],value);
  620 +}
  621 +
  622 +LIB3270_EXPORT gint v3270_ft_dialog_get_dft_buffer_size(GtkWidget *widget)
  623 +{
  624 + g_return_val_if_fail(GTK_IS_V3270FTD(widget),0);
  625 + return gtk_spin_button_get_value_as_int(GTK_V3270FTD(widget)->value[VALUE_DFT]);
  626 +}
  627 +
  628 +LIB3270_EXPORT gint v3270_ft_dialog_get_record_length(GtkWidget *widget)
  629 +{
  630 + g_return_val_if_fail(GTK_IS_V3270FTD(widget),0);
  631 + if(GTK_V3270FTD(widget)->value[VALUE_LRECL])
  632 + return gtk_spin_button_get_value_as_int(GTK_V3270FTD(widget)->value[VALUE_LRECL]);
  633 + return 0;
  634 +}
  635 +
  636 +LIB3270_EXPORT gint v3270_ft_dialog_get_block_size(GtkWidget *widget)
  637 +{
  638 + g_return_val_if_fail(GTK_IS_V3270FTD(widget),0);
  639 +
  640 + if(GTK_V3270FTD(widget)->value[VALUE_BLKSIZE])
  641 + return gtk_spin_button_get_value_as_int(GTK_V3270FTD(widget)->value[VALUE_BLKSIZE]);
  642 + return 0;
  643 +}
  644 +
  645 +LIB3270_EXPORT gint v3270_ft_dialog_get_primary_space(GtkWidget *widget)
  646 +{
  647 + g_return_val_if_fail(GTK_IS_V3270FTD(widget),0);
  648 +
  649 + if(GTK_V3270FTD(widget)->value[VALUE_PRIMSPACE])
  650 + return gtk_spin_button_get_value_as_int(GTK_V3270FTD(widget)->value[VALUE_PRIMSPACE]);
  651 + return 0;
  652 +}
  653 +
  654 +LIB3270_EXPORT gint v3270_ft_dialog_get_secondary_space(GtkWidget *widget)
  655 +{
  656 + g_return_val_if_fail(GTK_IS_V3270FTD(widget),0);
  657 + if(GTK_V3270FTD(widget)->value[VALUE_SECSPACE])
  658 + return gtk_spin_button_get_value_as_int(GTK_V3270FTD(widget)->value[VALUE_SECSPACE]);
  659 + return 0;
  660 +}
... ...
src/pw3270/ft/v3270ft.h
... ... @@ -71,7 +71,7 @@
71 71 typedef struct _v3270FTProgressClass v3270FTProgressClass;
72 72  
73 73 /*--[ Prototipes ]-----------------------------------------------------------------------------------*/
74   - LIB3270_EXPORT GtkWidget * v3270_ft_dialog_new(LIB3270_FT_OPTION options);
  74 + LIB3270_EXPORT GtkWidget * v3270_ft_dialog_new(GtkWidget *parent, LIB3270_FT_OPTION options);
75 75 LIB3270_EXPORT void v3270_ft_dialog_set_host_filename(GtkWidget *widget, const gchar *name);
76 76 LIB3270_EXPORT void v3270_ft_dialog_set_local_filename(GtkWidget *widget, const gchar *name);
77 77 LIB3270_EXPORT const gchar * v3270_ft_dialog_get_host_filename(GtkWidget *widget);
... ... @@ -79,6 +79,17 @@
79 79 LIB3270_EXPORT void v3270_ft_dialog_set_options(GtkWidget *widget,LIB3270_FT_OPTION options);
80 80 LIB3270_EXPORT LIB3270_FT_OPTION v3270_ft_dialog_get_options(GtkWidget *widget);
81 81 LIB3270_EXPORT void v3270_ft_dialog_set_tso(GtkWidget *widget,gboolean flag);
  82 + LIB3270_EXPORT void v3270_ft_dialog_set_dft_buffer_size(GtkWidget *widget, gint value);
  83 + LIB3270_EXPORT void v3270_ft_dialog_set_record_length(GtkWidget *widget, gint value);
  84 + LIB3270_EXPORT void v3270_ft_dialog_set_block_size(GtkWidget *widget, gint value);
  85 + LIB3270_EXPORT void v3270_ft_dialog_set_primary_space(GtkWidget *widget, gint value);
  86 + LIB3270_EXPORT void v3270_ft_dialog_set_secondary_space(GtkWidget *widget, gint value);
  87 +
  88 + LIB3270_EXPORT gint v3270_ft_dialog_get_dft_buffer_size(GtkWidget *widget);
  89 + LIB3270_EXPORT gint v3270_ft_dialog_get_record_length(GtkWidget *widget);
  90 + LIB3270_EXPORT gint v3270_ft_dialog_get_block_size(GtkWidget *widget);
  91 + LIB3270_EXPORT gint v3270_ft_dialog_get_primary_space(GtkWidget *widget);
  92 + LIB3270_EXPORT gint v3270_ft_dialog_get_secondary_space(GtkWidget *widget);
82 93  
83 94 LIB3270_EXPORT GtkWidget * v3270_ft_progress_new(void);
84 95 LIB3270_EXPORT void v3270_ft_progress_update(GtkWidget *widget, unsigned long current, unsigned long total, double kbytes_sec);
... ...