Commit 7b95d4de2c384f45b925bd18308982bea489f2b9

Authored by perry.werneck@gmail.com
1 parent 833b2fc6

Reimplementando diálogos de transferência de arquivos

src/include/pw3270/v3270.h
@@ -35,6 +35,7 @@ @@ -35,6 +35,7 @@
35 #include <lib3270/config.h> 35 #include <lib3270/config.h>
36 #include <lib3270.h> 36 #include <lib3270.h>
37 #include <lib3270/popup.h> 37 #include <lib3270/popup.h>
  38 + #include <lib3270/filetransfer.h>
38 39
39 #define V3270_H_INCLUDED 1 40 #define V3270_H_INCLUDED 1
40 41
@@ -226,6 +227,7 @@ @@ -226,6 +227,7 @@
226 LIB3270_EXPORT const gchar * v3270_get_ssl_status_message(GtkWidget *widget); 227 LIB3270_EXPORT const gchar * v3270_get_ssl_status_message(GtkWidget *widget);
227 LIB3270_EXPORT void v3270_popup_security_dialog(GtkWidget *widget); 228 LIB3270_EXPORT void v3270_popup_security_dialog(GtkWidget *widget);
228 229
  230 + LIB3270_EXPORT gint v3270_transfer_file(GtkWidget *widget, LIB3270_FT_OPTION options, const gchar *local, const gchar *remote, int lrecl, int blksize, int primspace, int secspace, int dft);
229 231
230 G_END_DECLS 232 G_END_DECLS
231 233
src/pw3270/filetransfer.c
@@ -134,7 +134,27 @@ static void ft_dialog_load(GtkWidget *widget, const gchar *name) @@ -134,7 +134,27 @@ static void ft_dialog_load(GtkWidget *widget, const gchar *name)
134 134
135 static void ft_dialog_save(GtkWidget *widget, const gchar *name) 135 static void ft_dialog_save(GtkWidget *widget, const gchar *name)
136 { 136 {
137 - const gchar * filename = v3270_ft_dialog_get_local_filename(widget); 137 + LIB3270_FT_OPTION opt = v3270_ft_dialog_get_options(widget);
  138 + const gchar * filename = v3270_ft_dialog_get_local_filename(widget);
  139 + int f;
  140 +
  141 + for(f=0;f<G_N_ELEMENTS(ftoptions);f++)
  142 + {
  143 + trace("%s=%s",ftoptions[f].name,((opt & ftoptions[f].val) != 0) ? "ON" : "OFF");
  144 + set_boolean_to_config(name, ftoptions[f].name, ((opt & ftoptions[f].val) != 0));
  145 + }
  146 +
  147 + for(f=0;f<G_N_ELEMENTS(recfm);f++)
  148 + {
  149 + if((opt & LIB3270_FT_RECORD_FORMAT_MASK) == recfm[f].val)
  150 + set_string_to_config(name,"recfm","%s",recfm[f].name);
  151 + }
  152 +
  153 + for(f=0;f<G_N_ELEMENTS(units);f++)
  154 + {
  155 + if( (opt & LIB3270_FT_ALLOCATION_UNITS_MASK) == units[f].val)
  156 + set_string_to_config(name,"units","%s",units[f].name);
  157 + }
138 158
139 set_integer_to_config(name,"dft",v3270_ft_dialog_get_dft_buffer_size(widget)); 159 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)); 160 set_integer_to_config(name,"reclen",v3270_ft_dialog_get_record_length(widget));
@@ -214,31 +234,21 @@ static void ft_state_changed(H3270FT *ft, LIB3270_FT_STATE state) @@ -214,31 +234,21 @@ static void ft_state_changed(H3270FT *ft, LIB3270_FT_STATE state)
214 { 234 {
215 } 235 }
216 236
217 -static GtkWidget * start_file_transfer(GtkAction *action, GtkWidget *widget, GtkWidget *info) 237 +gint v3270_transfer_file(GtkWidget *widget, LIB3270_FT_OPTION options, const gchar *local, const gchar *remote, int lrecl, int blksize, int primspace, int secspace, int dft)
218 { 238 {
219 - GtkWidget * dialog = gtk_dialog_new_with_buttons( _( "File transfer" ),  
220 - GTK_WINDOW(gtk_widget_get_toplevel(widget)),  
221 - GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,  
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 + g_return_val_if_fail(GTK_IS_V3270(widget),NULL);
  240 +
  241 + H3270FT * ft = lib3270_ft_new(v3270_get_session(widget),options,local,remote,lrecl,blksize,primspace,secspace,dft);
239 242
240 if(!ft) 243 if(!ft)
241 - return NULL; 244 + return -1;
  245 +
  246 + GtkWidget * dialog = gtk_dialog_new_with_buttons(
  247 + (options & LIB3270_FT_OPTION_RECEIVE) ? _( "Receiving file" ) : _( "Sending file" ),
  248 + GTK_WINDOW(gtk_widget_get_toplevel(widget)),
  249 + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
  250 + GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL,NULL );
  251 +
242 252
243 // Create FT progress dialog 253 // Create FT progress dialog
244 GtkWidget * progress = v3270_ft_progress_new(); 254 GtkWidget * progress = v3270_ft_progress_new();
@@ -258,7 +268,15 @@ static GtkWidget * start_file_transfer(GtkAction *action, GtkWidget *widget, Gtk @@ -258,7 +268,15 @@ static GtkWidget * start_file_transfer(GtkAction *action, GtkWidget *widget, Gtk
258 gtk_widget_show_all(progress); 268 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); 269 gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),GTK_WIDGET(progress),FALSE,TRUE,2);
260 270
261 - return dialog; 271 + gtk_widget_show_all(dialog);
  272 + lib3270_ft_start(v3270_get_session(widget));
  273 + int rc = gtk_dialog_run(GTK_DIALOG(dialog));
  274 + lib3270_ft_destroy(v3270_get_session(widget));
  275 +
  276 + gtk_widget_destroy(dialog);
  277 +
  278 + return rc;
  279 +
262 } 280 }
263 281
264 void download_action(GtkAction *action, GtkWidget *widget) 282 void download_action(GtkAction *action, GtkWidget *widget)
@@ -281,28 +299,27 @@ void download_action(GtkAction *action, GtkWidget *widget) @@ -281,28 +299,27 @@ void download_action(GtkAction *action, GtkWidget *widget)
281 } 299 }
282 300
283 GtkWidget *dialog = v3270_ft_dialog_new(widget,LIB3270_FT_OPTION_RECEIVE|get_options_from_config(name)); 301 GtkWidget *dialog = v3270_ft_dialog_new(widget,LIB3270_FT_OPTION_RECEIVE|get_options_from_config(name));
284 - GtkWidget *progress = NULL;  
285 302
286 ft_dialog_load(dialog,name); 303 ft_dialog_load(dialog,name);
287 304
288 if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) 305 if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
289 { 306 {
290 ft_dialog_save(dialog,name); 307 ft_dialog_save(dialog,name);
291 - progress = start_file_transfer(action, widget, dialog); 308 + gtk_widget_hide(dialog);
  309 +
  310 + v3270_transfer_file( widget,
  311 + v3270_ft_dialog_get_options(dialog),
  312 + v3270_ft_dialog_get_local_filename(dialog),
  313 + v3270_ft_dialog_get_host_filename(dialog),
  314 + v3270_ft_dialog_get_record_length(dialog),
  315 + v3270_ft_dialog_get_block_size(dialog),
  316 + v3270_ft_dialog_get_primary_space(dialog),
  317 + v3270_ft_dialog_get_secondary_space(dialog),
  318 + v3270_ft_dialog_get_dft_buffer_size(dialog));
292 } 319 }
293 320
294 gtk_widget_destroy(dialog); 321 gtk_widget_destroy(dialog);
295 322
296 - if(progress)  
297 - {  
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));  
302 -  
303 - gtk_widget_destroy(progress);  
304 - }  
305 -  
306 } 323 }
307 324
308 void upload_action(GtkAction *action, GtkWidget *widget) 325 void upload_action(GtkAction *action, GtkWidget *widget)
@@ -325,29 +342,27 @@ void upload_action(GtkAction *action, GtkWidget *widget) @@ -325,29 +342,27 @@ void upload_action(GtkAction *action, GtkWidget *widget)
325 } 342 }
326 343
327 GtkWidget *dialog = v3270_ft_dialog_new(widget,LIB3270_FT_OPTION_SEND|get_options_from_config(name)); 344 GtkWidget *dialog = v3270_ft_dialog_new(widget,LIB3270_FT_OPTION_SEND|get_options_from_config(name));
328 - GtkWidget *progress = NULL;  
329 345
330 ft_dialog_load(dialog,name); 346 ft_dialog_load(dialog,name);
331 347
332 if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) 348 if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
333 { 349 {
334 ft_dialog_save(dialog,name); 350 ft_dialog_save(dialog,name);
335 - progress = start_file_transfer(action, widget, dialog); 351 + gtk_widget_hide(dialog);
  352 +
  353 + v3270_transfer_file( widget,
  354 + v3270_ft_dialog_get_options(dialog),
  355 + v3270_ft_dialog_get_local_filename(dialog),
  356 + v3270_ft_dialog_get_host_filename(dialog),
  357 + v3270_ft_dialog_get_record_length(dialog),
  358 + v3270_ft_dialog_get_block_size(dialog),
  359 + v3270_ft_dialog_get_primary_space(dialog),
  360 + v3270_ft_dialog_get_secondary_space(dialog),
  361 + v3270_ft_dialog_get_dft_buffer_size(dialog));
336 } 362 }
337 363
338 gtk_widget_destroy(dialog); 364 gtk_widget_destroy(dialog);
339 365
340 - if(progress)  
341 - {  
342 - gtk_widget_show(progress);  
343 -  
344 - lib3270_ft_start(v3270_get_session(widget));  
345 - gtk_dialog_run(GTK_DIALOG(progress));  
346 - lib3270_ft_destroy(v3270_get_session(widget));  
347 -  
348 - gtk_widget_destroy(progress);  
349 - }  
350 -  
351 } 366 }
352 367
353 368
src/pw3270/ft/ftdialog.c
@@ -115,6 +115,10 @@ static void browse_file(GtkButton *button,v3270FTD *parent) @@ -115,6 +115,10 @@ static void browse_file(GtkButton *button,v3270FTD *parent)
115 NULL 115 NULL
116 ); 116 );
117 117
  118 + const gchar * current = gtk_entry_get_text(GTK_ENTRY(parent->filename[FILENAME_LOCAL]));
  119 + if(current && *current)
  120 + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),current);
  121 +
118 if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) 122 if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
119 { 123 {
120 gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); 124 gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));