Commit 7205253bf0d42c0cfa41a68d52bfa3066b5f7f91
1 parent
4aaf5c14
Exists in
master
and in
5 other branches
Finalizando diálogo de transferência de arquivos
Showing
5 changed files
with
172 additions
and
127 deletions
Show diff stats
src/include/lib3270/filetransfer.h
... | ... | @@ -73,12 +73,23 @@ |
73 | 73 | unsigned short sz; /**< Size of FT data structure */ |
74 | 74 | H3270 * host; |
75 | 75 | void * widget; /**< File transfer dialog handle */ |
76 | - FILE * ft_local_file; /**< File descriptor for local file */ | |
76 | + FILE * local_file; /**< File descriptor for local file */ | |
77 | 77 | unsigned long length; /**< File length */ |
78 | 78 | |
79 | 79 | LIB3270_FT_STATE state; |
80 | + LIB3270_FT_OPTION flags; | |
80 | 81 | |
81 | - void (*complete)(struct _h3270ft *ft, const char *errmsg,unsigned long length,double kbytes_sec,const char *mode); | |
82 | + int lrecl; | |
83 | + int blksize; | |
84 | + int primspace; | |
85 | + int secspace; | |
86 | + int dft; | |
87 | + | |
88 | + const char * local; /**< Local filename */ | |
89 | + const char * remote; /**< Remote filename */ | |
90 | + | |
91 | + void (*complete)(struct _h3270ft *ft,unsigned long length,double kbytes_sec,const char *mode); | |
92 | + void (*message)(struct _h3270ft *ft, const char *msg); | |
82 | 93 | void (*update)(struct _h3270ft *ft, unsigned long current, unsigned long length, double kbytes_sec); |
83 | 94 | void (*running)(struct _h3270ft *ft, int is_cut); |
84 | 95 | void (*aborting)(struct _h3270ft *ft); |
... | ... | @@ -87,7 +98,7 @@ |
87 | 98 | } H3270FT; |
88 | 99 | |
89 | 100 | /** |
90 | - * Start a new file transfer session. | |
101 | + * Create a new file transfer session. | |
91 | 102 | * |
92 | 103 | * @param session |
93 | 104 | * @param flags |
... | ... | @@ -104,6 +115,8 @@ |
104 | 115 | * |
105 | 116 | */ |
106 | 117 | 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); |
118 | + | |
119 | + LIB3270_EXPORT int lib3270_ft_start(H3270FT *ft); | |
107 | 120 | LIB3270_EXPORT void lib3270_ft_destroy(H3270FT *ft); |
108 | 121 | |
109 | 122 | LIB3270_EXPORT int lib3270_ft_cancel(H3270FT *ft, int force); | ... | ... |
src/lib3270/ft.c
... | ... | @@ -160,11 +160,16 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); |
160 | 160 | return 0; |
161 | 161 | } |
162 | 162 | |
163 | - static void def_complete(H3270FT *ft, const char *errmsg,unsigned long length,double kbytes_sec,const char *mode) | |
163 | + static void def_complete(H3270FT *ft,unsigned long length,double kbytes_sec,const char *mode) | |
164 | 164 | { |
165 | 165 | |
166 | 166 | } |
167 | 167 | |
168 | + static void def_message(H3270FT *ft, const char *errmsg) | |
169 | + { | |
170 | + lib3270_write_log(ft->host,"ft","%s",errmsg); | |
171 | + } | |
172 | + | |
168 | 173 | static void def_update(H3270FT *ft, unsigned long current, unsigned long length, double kbytes_sec) |
169 | 174 | { |
170 | 175 | |
... | ... | @@ -189,20 +194,9 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); |
189 | 194 | 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) |
190 | 195 | { |
191 | 196 | H3270FT * ftHandle = NULL; |
192 | - static const char * rec = "fvu"; | |
193 | - static const char * un[] = { "tracks", "cylinders", "avblock" }; | |
194 | - | |
195 | - unsigned short recfm = (flags & FT_RECORD_FORMAT_MASK) >> 8; | |
196 | - unsigned short units = (flags & FT_ALLOCATION_UNITS_MASK) >> 12; | |
197 | - | |
198 | 197 | FILE * ft_local_file = NULL; |
199 | 198 | unsigned long ft_length = 0L; |
200 | 199 | |
201 | - char op[4096]; | |
202 | - char buffer[4096]; | |
203 | - | |
204 | - unsigned int flen; | |
205 | - | |
206 | 200 | // trace("%s(%s)",__FUNCTION__,local); |
207 | 201 | if(!lib3270_connected(session)) |
208 | 202 | { |
... | ... | @@ -246,62 +240,112 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); |
246 | 240 | dft_buffersize = dft; |
247 | 241 | set_dft_buffersize(); |
248 | 242 | |
249 | - ascii_flag = ((flags & LIB3270_FT_OPTION_ASCII) != 0); | |
250 | - cr_flag = ((flags & LIB3270_FT_OPTION_CRLF) != 0); | |
251 | - remap_flag = ((flags & LIB3270_FT_OPTION_ASCII) != 0); | |
243 | + // Initialize ft control structure. | |
244 | + ft_last_cr = False; | |
245 | + ft_is_cut = False; | |
246 | + | |
247 | + ftHandle = lib3270_malloc(sizeof(H3270FT)+strlen(local)+strlen(remote)+3); | |
248 | + | |
249 | + ftHandle->sz = sizeof(H3270FT); | |
250 | + ftHandle->host = session; | |
251 | + ftHandle->flags = flags; | |
252 | + ftHandle->local_file = ft_local_file; | |
253 | + ftHandle->length = ft_length; | |
254 | + ftHandle->state = LIB3270_FT_STATE_AWAIT_ACK; | |
255 | + ftHandle->complete = def_complete; | |
256 | + ftHandle->message = def_message; | |
257 | + ftHandle->update = def_update; | |
258 | + ftHandle->running = def_running; | |
259 | + ftHandle->aborting = def_aborting; | |
260 | + ftHandle->state_changed = def_state_changed; | |
261 | + ftHandle->lrecl = lrecl; | |
262 | + ftHandle->blksize = blksize; | |
263 | + ftHandle->primspace = primspace; | |
264 | + ftHandle->secspace = secspace; | |
265 | + ftHandle->dft = dft; | |
266 | + | |
267 | + ftHandle->local = (char *) (ftHandle+1); | |
268 | + strcpy((char *) ftHandle->local,local); | |
269 | + | |
270 | + ftHandle->remote = ftHandle->local + strlen(ftHandle->local)+1; | |
271 | + strcpy((char *) ftHandle->remote,remote); | |
272 | + | |
273 | + session->ft = ftHandle; | |
274 | + | |
275 | + return ftsession = ftHandle; | |
276 | + } | |
252 | 277 | |
253 | - if(flags & LIB3270_FT_OPTION_RECEIVE) | |
278 | + LIB3270_EXPORT int lib3270_ft_start(H3270FT *ft) | |
279 | + { | |
280 | + static const char * rec = "fvu"; | |
281 | + static const char * un[] = { "tracks", "cylinders", "avblock" }; | |
282 | + | |
283 | + char op[4096]; | |
284 | + char buffer[4096]; | |
285 | + unsigned int flen; | |
286 | + unsigned short recfm; | |
287 | + unsigned short units; | |
288 | + | |
289 | + CHECK_FT_HANDLE(ft); | |
290 | + | |
291 | + recfm = (ft->flags & FT_RECORD_FORMAT_MASK) >> 8; | |
292 | + units = (ft->flags & FT_ALLOCATION_UNITS_MASK) >> 12; | |
293 | + ascii_flag = ((ft->flags & LIB3270_FT_OPTION_ASCII) != 0); | |
294 | + cr_flag = ((ft->flags & LIB3270_FT_OPTION_CRLF) != 0); | |
295 | + remap_flag = ((ft->flags & LIB3270_FT_OPTION_ASCII) != 0); | |
296 | + | |
297 | + if(ft->flags & LIB3270_FT_OPTION_RECEIVE) | |
254 | 298 | { |
255 | 299 | // Receiving file |
256 | - lib3270_write_log(session,"ft","Receiving file %s",local); | |
300 | + lib3270_write_log(ft->host,"ft","Receiving file %s",ft->local); | |
257 | 301 | } |
258 | 302 | else |
259 | 303 | { |
260 | 304 | // Sending file |
261 | - if(fseek(ft_local_file,0L,SEEK_END) < 0) | |
305 | + if(fseek(ft->local_file,0L,SEEK_END) < 0) | |
262 | 306 | { |
263 | - *msg = N_( "Can't get file size" ); | |
264 | - return NULL; | |
307 | + ft_complete(ft,N_( "Can't get file size" )); | |
308 | + return errno ? errno : -1; | |
265 | 309 | } |
266 | 310 | |
267 | - ft_length = ftell(ft_local_file); | |
311 | + ft_length = ftell(ft->local_file); | |
268 | 312 | |
269 | - lib3270_write_log(session,"ft","Sending file %s (%ld bytes)",local,ft_length); | |
270 | - rewind(ft_local_file); | |
313 | + lib3270_write_log(ft->host,"ft","Sending file %s (%ld bytes)",ft->local,ft_length); | |
314 | + rewind(ft->local_file); | |
271 | 315 | } |
272 | 316 | |
273 | 317 | /* Build the ind$file command */ |
274 | 318 | snprintf(op,4095,"%s%s%s", |
275 | - (flags & LIB3270_FT_OPTION_ASCII) ? " ASCII" : "", | |
276 | - (flags & LIB3270_FT_OPTION_CRLF) ? " CRLF" : "", | |
277 | - (flags & LIB3270_FT_OPTION_APPEND) ? " APPEND" : "" | |
319 | + (ft->flags & LIB3270_FT_OPTION_ASCII) ? " ASCII" : "", | |
320 | + (ft->flags & LIB3270_FT_OPTION_CRLF) ? " CRLF" : "", | |
321 | + (ft->flags & LIB3270_FT_OPTION_APPEND) ? " APPEND" : "" | |
278 | 322 | ); |
279 | 323 | |
280 | - if(!(flags & LIB3270_FT_OPTION_RECEIVE)) | |
324 | + if(!(ft->flags & LIB3270_FT_OPTION_RECEIVE)) | |
281 | 325 | { |
282 | - if(flags & LIB3270_FT_OPTION_TSO) | |
326 | + if(ft->flags & LIB3270_FT_OPTION_TSO) | |
283 | 327 | { |
284 | 328 | // TSO Host |
285 | 329 | if(recfm > 0) |
286 | 330 | { |
287 | 331 | snconcat(op,4096," recfm(%c)",rec[recfm-1]); |
288 | 332 | |
289 | - if(lrecl > 0) | |
290 | - snconcat(op,4096," lrecl(%d)",lrecl); | |
333 | + if(ft->lrecl > 0) | |
334 | + snconcat(op,4096," lrecl(%d)",ft->lrecl); | |
291 | 335 | |
292 | - if(blksize > 0) | |
293 | - snconcat(op,4096," blksize(%d)", blksize); | |
336 | + if(ft->blksize > 0) | |
337 | + snconcat(op,4096," blksize(%d)", ft->blksize); | |
294 | 338 | } |
295 | 339 | |
296 | 340 | if(units > 0) |
297 | 341 | { |
298 | 342 | snconcat(op,4096," %s",un[units-1]); |
299 | 343 | |
300 | - if(primspace > 0) | |
344 | + if(ft->primspace > 0) | |
301 | 345 | { |
302 | - snconcat(op,4096," space(%d",primspace); | |
303 | - if(secspace) | |
304 | - snconcat(op,4096,",%d",secspace); | |
346 | + snconcat(op,4096," space(%d",ft->primspace); | |
347 | + if(ft->secspace) | |
348 | + snconcat(op,4096,",%d",ft->secspace); | |
305 | 349 | snconcat(op,4096,"%s",")"); |
306 | 350 | } |
307 | 351 | } |
... | ... | @@ -313,20 +357,20 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); |
313 | 357 | { |
314 | 358 | snconcat(op,4096," recfm %c",rec[recfm-1]); |
315 | 359 | |
316 | - if(lrecl > 0) | |
317 | - snconcat(op,4096," lrecl %d",lrecl); | |
360 | + if(ft->lrecl > 0) | |
361 | + snconcat(op,4096," lrecl %d",ft->lrecl); | |
318 | 362 | |
319 | 363 | } |
320 | 364 | } |
321 | 365 | } |
322 | 366 | |
323 | 367 | snprintf(buffer,4095,"%s %s %s", "IND$FILE", |
324 | - (flags & LIB3270_FT_OPTION_RECEIVE) ? "GET" : "PUT", | |
325 | - remote ); | |
368 | + (ft->flags & LIB3270_FT_OPTION_RECEIVE) ? "GET" : "PUT", | |
369 | + ft->remote ); | |
326 | 370 | |
327 | 371 | if(*op) |
328 | 372 | { |
329 | - if(flags & LIB3270_FT_OPTION_TSO) | |
373 | + if(ft->flags & LIB3270_FT_OPTION_TSO) | |
330 | 374 | snconcat(buffer,4095," %s",op+1); |
331 | 375 | else |
332 | 376 | snconcat(buffer,4095," (%s)",op+1); |
... | ... | @@ -338,40 +382,25 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); |
338 | 382 | flen = kybd_prime(); |
339 | 383 | if (!flen || flen < strlen(buffer) - 1) |
340 | 384 | { |
341 | - lib3270_write_log(session, "Unable to send command \"%s\" (flen=%d szBuffer=%d)",buffer,flen,strlen(buffer)); | |
342 | - fclose(ft_local_file); | |
343 | - *msg = _( "Unable to send file-transfer request" ); | |
344 | - errno = EINVAL; | |
345 | - return NULL; | |
385 | + lib3270_write_log(ft->host, "Unable to send command \"%s\" (flen=%d szBuffer=%d)",buffer,flen,strlen(buffer)); | |
386 | + ft_complete(ft,N_( "Unable to send file-transfer request" )); | |
387 | + return errno = EINVAL; | |
346 | 388 | } |
347 | 389 | |
348 | 390 | trace_event("Sending FT request:\n%s\n",buffer); |
349 | 391 | |
350 | - (void) lib3270_emulate_input(NULL, buffer, strlen(buffer), False); | |
351 | - | |
352 | - // Get this thing started. | |
353 | - | |
354 | - ft_last_cr = False; | |
355 | - ft_is_cut = False; | |
392 | + lib3270_emulate_input(ft->host, buffer, strlen(buffer), False); | |
356 | 393 | |
357 | - ftHandle = lib3270_malloc(sizeof(H3270FT)); | |
358 | - | |
359 | - ftHandle->sz = sizeof(H3270FT); | |
360 | - ftHandle->host = session; | |
361 | - ftHandle->ft_local_file = ft_local_file; | |
362 | - ftHandle->length = ft_length; | |
363 | - ftHandle->state = LIB3270_FT_STATE_AWAIT_ACK; | |
364 | - ftHandle->complete = def_complete; | |
365 | - ftHandle->update = def_update; | |
366 | - ftHandle->running = def_running; | |
367 | - ftHandle->aborting = def_aborting; | |
368 | - ftHandle->state_changed = def_state_changed; | |
394 | + if(ft->flags & LIB3270_FT_OPTION_RECEIVE) | |
395 | + ft->message(ft,N_( "Waiting for GET response" )); | |
396 | + else | |
397 | + ft->message(ft,N_( "Waiting for PUT response" )); | |
369 | 398 | |
370 | - session->ft = ftHandle; | |
399 | + return 0; | |
371 | 400 | |
372 | - return ftsession = ftHandle; | |
373 | 401 | } |
374 | 402 | |
403 | + | |
375 | 404 | /* External entry points called by ft_dft and ft_cut. */ |
376 | 405 | |
377 | 406 | /** |
... | ... | @@ -391,10 +420,10 @@ void ft_complete(H3270FT *session, const char *errmsg) |
391 | 420 | (double)(t1.tv_usec - starting_time.tv_usec) / 1.0e6); |
392 | 421 | |
393 | 422 | // Close the local file. |
394 | - if(session->ft_local_file) | |
423 | + if(session->local_file) | |
395 | 424 | { |
396 | - fclose(session->ft_local_file); | |
397 | - session->ft_local_file = NULL; | |
425 | + fclose(session->local_file); | |
426 | + session->local_file = NULL; | |
398 | 427 | } |
399 | 428 | |
400 | 429 | // Clean up the state. |
... | ... | @@ -402,7 +431,8 @@ void ft_complete(H3270FT *session, const char *errmsg) |
402 | 431 | |
403 | 432 | ft_update_length(session); |
404 | 433 | |
405 | - session->complete(session,errmsg,ft_length,kbytes_sec,ft_is_cut ? "CUT" : "DFT"); | |
434 | + session->message(session,errmsg); | |
435 | + session->complete(session,ft_length,kbytes_sec,ft_is_cut ? "CUT" : "DFT"); | |
406 | 436 | |
407 | 437 | } |
408 | 438 | |
... | ... | @@ -413,10 +443,10 @@ LIB3270_EXPORT void lib3270_ft_destroy(H3270FT *session) |
413 | 443 | if (session->state != LIB3270_FT_STATE_NONE) |
414 | 444 | lib3270_ft_cancel(session,1); |
415 | 445 | |
416 | - if(session->ft_local_file) | |
446 | + if(session->local_file) | |
417 | 447 | { |
418 | - fclose(session->ft_local_file); | |
419 | - session->ft_local_file = NULL; | |
448 | + fclose(session->local_file); | |
449 | + session->local_file = NULL; | |
420 | 450 | } |
421 | 451 | |
422 | 452 | if(session == ftsession) | ... | ... |
src/lib3270/ft_cut.c
... | ... | @@ -398,7 +398,7 @@ cut_data_request(void) |
398 | 398 | } |
399 | 399 | |
400 | 400 | /* Check for errors. */ |
401 | - if (ferror(((H3270FT *) h3270.ft)->ft_local_file)) { | |
401 | + if (ferror(((H3270FT *) h3270.ft)->local_file)) { | |
402 | 402 | int j; |
403 | 403 | |
404 | 404 | /* Clean out any data we may have written. */ |
... | ... | @@ -411,7 +411,7 @@ cut_data_request(void) |
411 | 411 | } |
412 | 412 | |
413 | 413 | /* Send special data for EOF. */ |
414 | - if (!count && feof(((H3270FT *) h3270.ft)->ft_local_file)) { | |
414 | + if (!count && feof(((H3270FT *) h3270.ft)->local_file)) { | |
415 | 415 | ctlr_add(O_UP_DATA, EOF_DATA1, 0); |
416 | 416 | ctlr_add(O_UP_DATA+1, EOF_DATA2, 0); |
417 | 417 | count = 2; |
... | ... | @@ -502,7 +502,7 @@ cut_data(void) |
502 | 502 | return; |
503 | 503 | |
504 | 504 | /* Write it to the file. */ |
505 | - if (fwrite((char *)cvbuf, conv_length, 1, ((H3270FT *) h3270.ft)->ft_local_file) == 0) { | |
505 | + if (fwrite((char *)cvbuf, conv_length, 1, ((H3270FT *) h3270.ft)->local_file) == 0) { | |
506 | 506 | cut_abort(SC_ABORT_FILE,_( "Error \"%s\" writing to local file (rc=%d)" ),strerror(errno),errno); |
507 | 507 | } else { |
508 | 508 | ft_length += conv_length; |
... | ... | @@ -570,7 +570,7 @@ xlate_getc(void) |
570 | 570 | } |
571 | 571 | |
572 | 572 | /* Get the next byte from the file. */ |
573 | - c = fgetc(((H3270FT *) h3270.ft)->ft_local_file); | |
573 | + c = fgetc(((H3270FT *) h3270.ft)->local_file); | |
574 | 574 | if (c == EOF) |
575 | 575 | return c; |
576 | 576 | ft_length++; | ... | ... |
src/lib3270/ft_dft.c
... | ... | @@ -291,7 +291,7 @@ dft_data_insert(struct data_buffer *data_bufr) |
291 | 291 | |
292 | 292 | if (l) |
293 | 293 | { |
294 | - rv = fwrite(s, l, (size_t)1,((H3270FT *) h3270.ft)->ft_local_file); | |
294 | + rv = fwrite(s, l, (size_t)1,((H3270FT *) h3270.ft)->local_file); | |
295 | 295 | if (rv == 0) |
296 | 296 | break; |
297 | 297 | ft_length += l; |
... | ... | @@ -302,7 +302,7 @@ dft_data_insert(struct data_buffer *data_bufr) |
302 | 302 | len -= l; |
303 | 303 | } |
304 | 304 | } else { |
305 | - rv = fwrite((char *)data_bufr->data, my_length,(size_t)1, ((H3270FT *) h3270.ft)->ft_local_file); | |
305 | + rv = fwrite((char *)data_bufr->data, my_length,(size_t)1, ((H3270FT *) h3270.ft)->local_file); | |
306 | 306 | ft_length += my_length; |
307 | 307 | } |
308 | 308 | |
... | ... | @@ -363,7 +363,7 @@ dft_get_request(void) |
363 | 363 | int c; |
364 | 364 | |
365 | 365 | /* Read one byte and do CR/LF translation. */ |
366 | - c = fgetc(((H3270FT *) h3270.ft)->ft_local_file); | |
366 | + c = fgetc(((H3270FT *) h3270.ft)->local_file); | |
367 | 367 | if (c == EOF) { |
368 | 368 | break; |
369 | 369 | } |
... | ... | @@ -373,7 +373,7 @@ dft_get_request(void) |
373 | 373 | * Not enough room to expand NL to |
374 | 374 | * CR/LF. |
375 | 375 | */ |
376 | - ungetc(c, ((H3270FT *) h3270.ft)->ft_local_file); | |
376 | + ungetc(c, ((H3270FT *) h3270.ft)->local_file); | |
377 | 377 | break; |
378 | 378 | } |
379 | 379 | *bufptr++ = '\r'; |
... | ... | @@ -386,7 +386,7 @@ dft_get_request(void) |
386 | 386 | total_read++; |
387 | 387 | } else { |
388 | 388 | /* Binary read. */ |
389 | - numread = fread(bufptr, 1, numbytes, ((H3270FT *) h3270.ft)->ft_local_file); | |
389 | + numread = fread(bufptr, 1, numbytes, ((H3270FT *) h3270.ft)->local_file); | |
390 | 390 | if (numread <= 0) { |
391 | 391 | break; |
392 | 392 | } |
... | ... | @@ -404,13 +404,13 @@ dft_get_request(void) |
404 | 404 | numbytes -= numread; |
405 | 405 | total_read += numread; |
406 | 406 | } |
407 | - if (feof(((H3270FT *) h3270.ft)->ft_local_file) || ferror(((H3270FT *) h3270.ft)->ft_local_file)) { | |
407 | + if (feof(((H3270FT *) h3270.ft)->local_file) || ferror(((H3270FT *) h3270.ft)->local_file)) { | |
408 | 408 | break; |
409 | 409 | } |
410 | 410 | } |
411 | 411 | |
412 | 412 | /* Check for read error. */ |
413 | - if (ferror(((H3270FT *) h3270.ft)->ft_local_file)) | |
413 | + if (ferror(((H3270FT *) h3270.ft)->local_file)) | |
414 | 414 | { |
415 | 415 | dft_abort(TR_GET_REQ, _( "Error \"%s\" reading from local file (rc=%d)" ), strerror(errno), errno); |
416 | 416 | return; |
... | ... | @@ -436,7 +436,7 @@ dft_get_request(void) |
436 | 436 | |
437 | 437 | ft_length += total_read; |
438 | 438 | |
439 | - if (feof(((H3270FT *) h3270.ft)->ft_local_file)) | |
439 | + if (feof(((H3270FT *) h3270.ft)->local_file)) | |
440 | 440 | { |
441 | 441 | dft_eof = True; |
442 | 442 | } | ... | ... |
src/pw3270/filetransfer.c
... | ... | @@ -283,57 +283,56 @@ static void setup_dft(GObject *action, struct ftdialog *dlg, GtkWidget **label) |
283 | 283 | |
284 | 284 | } |
285 | 285 | |
286 | - | |
287 | -static void ft_complete(H3270FT *ft, const char *errmsg,unsigned long length,double kbytes_sec,const char *mode) | |
286 | +static void update(H3270FT *ft, unsigned long length, double kbytes_sec) | |
288 | 287 | { |
289 | - if(!ft->widget) | |
290 | - return; | |
288 | + GtkLabel **info = (GtkLabel **) g_object_get_data(G_OBJECT(ft->widget),"info"); | |
289 | + | |
290 | + if(length && info[0]) | |
291 | + { | |
292 | + gchar *str = g_strdup_printf("%ld",length); | |
293 | + gtk_label_set_text(info[0],str); | |
294 | + g_free(str); | |
295 | + } | |
296 | + | |
297 | + if(kbytes_sec && info[2]) | |
298 | + { | |
299 | + gchar *str = g_strdup_printf("%ld KB/s",(unsigned long) kbytes_sec); | |
300 | + gtk_label_set_text(info[2],str); | |
301 | + g_free(str); | |
302 | + } | |
291 | 303 | |
304 | +} | |
292 | 305 | |
306 | +static void ft_complete(H3270FT *ft, unsigned long length,double kbytes_sec,const char *mode) | |
307 | +{ | |
308 | + update(ft,length,kbytes_sec); | |
309 | +} | |
293 | 310 | |
294 | - ft->widget = NULL; | |
311 | +static void ft_message(struct _h3270ft *ft, const char *text) | |
312 | +{ | |
313 | + GtkLabel **msg = (GtkLabel **) g_object_get_data(G_OBJECT(ft->widget),"msg"); | |
314 | + gtk_label_set_text(msg[2],gettext(text)); | |
295 | 315 | } |
296 | 316 | |
297 | 317 | static void ft_update(H3270FT *ft, unsigned long current, unsigned long length, double kbytes_sec) |
298 | 318 | { |
299 | 319 | GtkLabel **info = (GtkLabel **) g_object_get_data(G_OBJECT(ft->widget),"info"); |
300 | 320 | GtkProgressBar * pbar = g_object_get_data(G_OBJECT(ft->widget),"progress"); |
321 | + gchar * str; | |
301 | 322 | |
302 | - if(info) | |
303 | - { | |
304 | - gchar *str; | |
323 | + update(ft, length, kbytes_sec); | |
305 | 324 | |
306 | - if(length && info[0]) | |
307 | - { | |
308 | - str = g_strdup_printf("%ld",length); | |
309 | - gtk_label_set_text(info[0],str); | |
310 | - g_free(str); | |
311 | - } | |
312 | - | |
313 | - if(current && info[1]) | |
314 | - { | |
315 | - str = g_strdup_printf("%ld",current); | |
316 | - gtk_label_set_text(info[1],str); | |
317 | - g_free(str); | |
318 | - } | |
319 | - | |
320 | - if(kbytes_sec && info[2]) | |
321 | - { | |
322 | - str = g_strdup_printf("%ld KB/s",(unsigned long) kbytes_sec); | |
323 | - gtk_label_set_text(info[2],str); | |
324 | - g_free(str); | |
325 | - } | |
326 | - | |
327 | - } | |
328 | - | |
329 | - if(pbar) | |
325 | + if(current && info[1]) | |
330 | 326 | { |
331 | - if(length) | |
332 | - gtk_progress_bar_set_fraction(pbar,((gdouble) current) / ((gdouble) length)); | |
333 | - else | |
334 | - gtk_progress_bar_pulse(pbar); | |
327 | + str = g_strdup_printf("%ld",current); | |
328 | + gtk_label_set_text(info[1],str); | |
329 | + g_free(str); | |
335 | 330 | } |
336 | 331 | |
332 | + if(length) | |
333 | + gtk_progress_bar_set_fraction(pbar,((gdouble) current) / ((gdouble) length)); | |
334 | + else | |
335 | + gtk_progress_bar_pulse(pbar); | |
337 | 336 | |
338 | 337 | } |
339 | 338 | |
... | ... | @@ -344,7 +343,8 @@ static void ft_running(H3270FT *ft, int is_cut) |
344 | 343 | |
345 | 344 | static void ft_aborting(H3270FT *ft) |
346 | 345 | { |
347 | - | |
346 | + GtkLabel **msg = (GtkLabel **) g_object_get_data(G_OBJECT(ft->widget),"msg"); | |
347 | + gtk_label_set_text(msg[2],_("Aborting")); | |
348 | 348 | } |
349 | 349 | |
350 | 350 | static void ft_state_changed(H3270FT *ft, LIB3270_FT_STATE state) |
... | ... | @@ -542,7 +542,7 @@ static void run_ft_dialog(GObject *action, GtkWidget *widget, struct ftdialog *d |
542 | 542 | gtk_misc_set_alignment(GTK_MISC(label),0,0); |
543 | 543 | gtk_table_attach(GTK_TABLE(table),label,0,1,f,f+1,GTK_FILL,GTK_FILL,2,2); |
544 | 544 | |
545 | - entry[pos] = gtk_label_new(""); | |
545 | + entry[pos] = gtk_label_new(_( "N/A" ) ); | |
546 | 546 | gtk_misc_set_alignment(GTK_MISC(entry[f]),0,0); |
547 | 547 | |
548 | 548 | gtk_table_attach(GTK_TABLE(table),entry[pos],1,2,f,f+1,GTK_EXPAND,GTK_FILL,2,2); |
... | ... | @@ -558,7 +558,7 @@ static void run_ft_dialog(GObject *action, GtkWidget *widget, struct ftdialog *d |
558 | 558 | gtk_misc_set_alignment(GTK_MISC(label),0,0); |
559 | 559 | gtk_table_attach(GTK_TABLE(table),label,2,3,f,f+1,GTK_FILL,GTK_FILL,2,2); |
560 | 560 | |
561 | - entry[pos] = gtk_label_new(""); | |
561 | + entry[pos] = gtk_label_new(_("N/A" )); | |
562 | 562 | gtk_misc_set_alignment(GTK_MISC(entry[f]),0,0); |
563 | 563 | |
564 | 564 | gtk_label_set_mnemonic_widget(GTK_LABEL(label),entry[pos++]); |
... | ... | @@ -579,8 +579,10 @@ static void run_ft_dialog(GObject *action, GtkWidget *widget, struct ftdialog *d |
579 | 579 | ft->running = ft_running; |
580 | 580 | ft->aborting = ft_aborting; |
581 | 581 | ft->state_changed = ft_state_changed; |
582 | + ft->message = ft_message; | |
582 | 583 | |
583 | 584 | gtk_widget_show_all(ftdialog); |
585 | + lib3270_ft_start(ft); | |
584 | 586 | |
585 | 587 | trace("%s: Running dialog %p",ftdialog); |
586 | 588 | gtk_dialog_run(GTK_DIALOG(ftdialog)); | ... | ... |