Mercurial > gftp.yaz
annotate src/gtk/transfer.c @ 355:60d3da6ab336
2003-1-5 Brian Masney <masneyb@gftp.org>
* src/gtk/gftp-gtk.h src/gtk/gtkui.c - when spawning a thread,
make sure that the GUI will be updated properly as soon as the thread
is finished.
* src/uicommon/gftpuicallbacks.c src/uicommon/gftpui.h - added
gftpui_common_run_ls()
* src/uicommon/gftpui.c (gftpui_common_cmd_ls)
src/gtk/transfer.c (ftp_list_files) - converted these functions
over to use gftpui_common_run_ls()
author | masneyb |
---|---|
date | Tue, 06 Jan 2004 01:44:09 +0000 |
parents | eedc2c5727fa |
children | 7cb3327f96f7 |
rev | line source |
---|---|
1 | 1 /*****************************************************************************/ |
2 /* transfer.c - functions to handle transfering files */ | |
255 | 3 /* Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org> */ |
1 | 4 /* */ |
5 /* This program is free software; you can redistribute it and/or modify */ | |
6 /* it under the terms of the GNU General Public License as published by */ | |
7 /* the Free Software Foundation; either version 2 of the License, or */ | |
8 /* (at your option) any later version. */ | |
9 /* */ | |
10 /* This program is distributed in the hope that it will be useful, */ | |
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ | |
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ | |
13 /* GNU General Public License for more details. */ | |
14 /* */ | |
15 /* You should have received a copy of the GNU General Public License */ | |
16 /* along with this program; if not, write to the Free Software */ | |
17 /* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
18 /*****************************************************************************/ | |
19 | |
20 #include <gftp-gtk.h> | |
33 | 21 static const char cvsid[] = "$Id$"; |
1 | 22 |
23 static GtkWidget * dialog; | |
129 | 24 static int num_transfers_in_progress = 0; |
1 | 25 |
48 | 26 int |
27 ftp_list_files (gftp_window_data * wdata, int usecache) | |
28 { | |
355 | 29 gftpui_callback_data * cdata; |
48 | 30 |
31 gtk_label_set (GTK_LABEL (wdata->hoststxt), _("Receiving file names...")); | |
32 | |
355 | 33 cdata = g_malloc0 (sizeof (*cdata)); |
34 cdata->request = wdata->request; | |
35 cdata->uidata = wdata; | |
36 cdata->run_function = gftpui_common_run_ls; | |
48 | 37 |
355 | 38 gftpui_common_run_callback_function (cdata); |
48 | 39 |
355 | 40 wdata->files = cdata->files; |
41 cdata->files = NULL; | |
42 g_free (cdata); | |
48 | 43 |
44 if (wdata->files == NULL || !GFTP_IS_CONNECTED (wdata->request)) | |
45 { | |
46 disconnect (wdata); | |
47 return (0); | |
48 } | |
49 | |
50 wdata->sorted = 0; | |
129 | 51 sortrows (GTK_CLIST (wdata->listbox), -1, (gpointer) wdata); |
355 | 52 |
48 | 53 if (IS_NONE_SELECTED (wdata)) |
54 gtk_clist_select_row (GTK_CLIST (wdata->listbox), 0, 0); | |
355 | 55 |
48 | 56 return (1); |
57 } | |
58 | |
59 | |
19 | 60 static void |
61 try_connect_again (gftp_request * request, gftp_dialog_data * ddata) | |
62 { | |
63 gftp_set_password (request, gtk_entry_get_text (GTK_ENTRY (ddata->edit))); | |
64 request->stopable = 0; | |
65 } | |
66 | |
67 | |
68 static void | |
69 dont_connect_again (gftp_request * request, gftp_dialog_data * ddata) | |
70 { | |
71 request->stopable = 0; | |
72 } | |
73 | |
74 | |
48 | 75 static void * |
76 connect_thread (void *data) | |
77 { | |
326 | 78 int ret, sj; |
79 intptr_t retries, sleep_time, network_timeout; | |
48 | 80 static int conn_num; |
81 gftp_request * request; | |
82 | |
83 request = data; | |
84 | |
129 | 85 gftp_lookup_request_option (request, "retries", &retries); |
86 gftp_lookup_request_option (request, "sleep_time", &sleep_time); | |
87 gftp_lookup_request_option (request, "network_timeout", &network_timeout); | |
88 | |
48 | 89 conn_num = 0; |
341 | 90 if (gftpui_common_use_threads (request)) |
48 | 91 { |
341 | 92 sj = sigsetjmp (gftpui_common_jmp_environment, 1); |
93 gftpui_common_use_jmp_environment = 1; | |
48 | 94 } |
95 else | |
96 sj = 0; | |
97 | |
98 ret = 0; | |
99 if (sj != 0) | |
100 { | |
101 ret = 0; | |
102 gftp_disconnect (request); | |
103 } | |
104 | |
129 | 105 while (sj != 1 && (retries == 0 || conn_num < retries)) |
48 | 106 { |
107 conn_num++; | |
129 | 108 if (network_timeout > 0) |
109 alarm (network_timeout); | |
84 | 110 ret = gftp_connect (request); |
48 | 111 alarm (0); |
112 | |
84 | 113 if (ret == GFTP_EFATAL) |
114 { | |
115 ret = 0; | |
116 break; | |
117 } | |
118 else if (ret == 0) | |
119 { | |
120 ret = 1; | |
121 break; | |
122 } | |
129 | 123 else if (retries == 0 || conn_num < retries) |
48 | 124 { |
186 | 125 request->logging_function (gftp_logging_misc, request, |
48 | 126 _("Waiting %d seconds until trying to connect again\n"), |
129 | 127 sleep_time); |
128 alarm (sleep_time); | |
48 | 129 pause (); |
130 } | |
131 } | |
132 | |
341 | 133 if (gftpui_common_use_threads (request)) |
134 gftpui_common_use_jmp_environment = 0; | |
48 | 135 |
136 request->stopable = 0; | |
137 if (request->wakeup_main_thread[1] > 0) | |
138 write (request->wakeup_main_thread[1], " ", 1); | |
195 | 139 return (GINT_TO_POINTER (ret)); |
48 | 140 } |
141 | |
142 | |
1 | 143 int |
144 ftp_connect (gftp_window_data * wdata, gftp_request * request, int getdir) | |
145 { | |
146 int success; | |
147 void *ret; | |
148 | |
149 ret = 0; | |
150 if (wdata->request == request) | |
151 { | |
152 gtk_label_set (GTK_LABEL (wdata->hoststxt), _("Connecting...")); | |
153 } | |
154 | |
7 | 155 if (request->need_userpass && request->username != NULL && |
156 *request->username != '\0' && | |
157 (request->password == NULL || *request->password == '\0')) | |
1 | 158 { |
159 if (wdata && wdata->request == request) | |
160 { | |
161 request->stopable = 1; | |
162 MakeEditDialog (_("Enter Password"), | |
163 _("Please enter your password for this site"), NULL, | |
19 | 164 0, NULL, gftp_dialog_button_connect, |
165 try_connect_again, request, | |
166 dont_connect_again, request); | |
31 | 167 |
1 | 168 while (request->stopable) |
31 | 169 { |
33 | 170 GDK_THREADS_LEAVE (); |
45 | 171 #if GTK_MAJOR_VERSION == 1 |
31 | 172 g_main_iteration (TRUE); |
41 | 173 #else |
174 g_main_context_iteration (NULL, TRUE); | |
175 #endif | |
31 | 176 } |
1 | 177 |
129 | 178 if (request->password == NULL || *request->password == '\0') |
1 | 179 return (0); |
180 } | |
181 else | |
182 gftp_set_password (request, ""); | |
183 } | |
184 | |
341 | 185 if (wdata && wdata->request == request && gftpui_common_use_threads (request)) |
1 | 186 { |
187 request->stopable = 1; | |
188 if (wdata) | |
189 gtk_clist_freeze (GTK_CLIST (wdata->listbox)); | |
190 gtk_widget_set_sensitive (stop_btn, 1); | |
191 pthread_create (&wdata->tid, NULL, connect_thread, request); | |
192 | |
193 while (request->stopable) | |
31 | 194 { |
33 | 195 GDK_THREADS_LEAVE (); |
45 | 196 #if GTK_MAJOR_VERSION == 1 |
31 | 197 g_main_iteration (TRUE); |
41 | 198 #else |
199 g_main_context_iteration (NULL, TRUE); | |
200 #endif | |
31 | 201 } |
1 | 202 pthread_join (wdata->tid, &ret); |
203 | |
204 gtk_widget_set_sensitive (stop_btn, 0); | |
205 if (wdata) | |
206 gtk_clist_thaw (GTK_CLIST (wdata->listbox)); | |
207 } | |
208 else | |
209 ret = connect_thread (request); | |
195 | 210 |
211 success = GPOINTER_TO_INT (ret); | |
1 | 212 memset (&wdata->tid, 0, sizeof (wdata->tid)); |
213 | |
214 if (!GFTP_IS_CONNECTED (wdata->request)) | |
215 disconnect (wdata); | |
216 else if (success) | |
217 { | |
218 ftp_list_files (wdata, 1); | |
219 if (!GFTP_IS_CONNECTED (wdata->request)) | |
220 disconnect (wdata); | |
221 } | |
222 | |
223 return (success); | |
224 } | |
225 | |
226 | |
227 void | |
228 get_files (gpointer data) | |
229 { | |
230 transfer_window_files (&window2, &window1); | |
231 } | |
232 | |
233 | |
234 void | |
235 put_files (gpointer data) | |
236 { | |
237 transfer_window_files (&window1, &window2); | |
238 } | |
239 | |
240 | |
241 void | |
242 transfer_window_files (gftp_window_data * fromwdata, gftp_window_data * towdata) | |
243 { | |
244 gftp_file * tempfle, * newfle; | |
245 GList * templist, * filelist; | |
246 gftp_transfer * transfer; | |
247 guint timeout_num; | |
248 void *ret; | |
249 int num; | |
250 | |
251 if (!check_status (_("Transfer Files"), fromwdata, 1, 0, 1, | |
252 towdata->request->put_file != NULL && fromwdata->request->get_file != NULL)) | |
253 return; | |
254 | |
255 if (!GFTP_IS_CONNECTED (fromwdata->request) || | |
256 !GFTP_IS_CONNECTED (towdata->request)) | |
257 { | |
258 ftp_log (gftp_logging_misc, NULL, | |
259 _("Retrieve Files: Not connected to a remote site\n")); | |
260 return; | |
261 } | |
262 | |
263 if (check_reconnect (fromwdata) < 0 || check_reconnect (towdata) < 0) | |
264 return; | |
265 | |
266 transfer = g_malloc0 (sizeof (*transfer)); | |
151 | 267 transfer->fromreq = copy_request (fromwdata->request, 0); |
268 transfer->toreq = copy_request (towdata->request, 0); | |
1 | 269 transfer->fromwdata = fromwdata; |
270 transfer->towdata = towdata; | |
271 | |
272 num = 0; | |
273 templist = GTK_CLIST (fromwdata->listbox)->selection; | |
274 filelist = fromwdata->files; | |
275 while (templist != NULL) | |
276 { | |
277 templist = get_next_selection (templist, &filelist, &num); | |
278 tempfle = filelist->data; | |
279 if (strcmp (tempfle->file, "..") != 0) | |
280 { | |
281 newfle = copy_fdata (tempfle); | |
282 transfer->files = g_list_append (transfer->files, newfle); | |
283 } | |
284 } | |
285 | |
286 if (transfer->files != NULL) | |
287 { | |
63 | 288 gftp_swap_socks (transfer->fromreq, fromwdata->request); |
289 gftp_swap_socks (transfer->toreq, towdata->request); | |
1 | 290 |
341 | 291 if (gftpui_common_use_threads (transfer->fromreq) || |
292 (transfer->toreq && gftpui_common_use_threads (transfer->toreq))) | |
1 | 293 { |
294 transfer->fromreq->stopable = 1; | |
295 pthread_create (&fromwdata->tid, NULL, do_getdir_thread, transfer); | |
296 | |
297 timeout_num = gtk_timeout_add (100, progress_timeout, transfer); | |
298 | |
299 while (transfer->fromreq->stopable) | |
31 | 300 { |
33 | 301 GDK_THREADS_LEAVE (); |
45 | 302 #if GTK_MAJOR_VERSION == 1 |
31 | 303 g_main_iteration (TRUE); |
41 | 304 #else |
305 g_main_context_iteration (NULL, TRUE); | |
306 #endif | |
31 | 307 } |
1 | 308 |
309 gtk_timeout_remove (timeout_num); | |
310 transfer->numfiles = transfer->numdirs = -1; | |
311 update_directory_download_progress (transfer); | |
312 | |
313 pthread_join (fromwdata->tid, &ret); | |
314 } | |
315 else | |
316 ret = do_getdir_thread (transfer); | |
317 | |
318 if (!GFTP_IS_CONNECTED (transfer->fromreq)) | |
319 { | |
320 disconnect (fromwdata); | |
321 return; | |
322 } | |
323 | |
324 if (!GFTP_IS_CONNECTED (transfer->toreq)) | |
325 { | |
326 disconnect (towdata); | |
327 return; | |
328 } | |
329 | |
63 | 330 gftp_swap_socks (fromwdata->request, transfer->fromreq); |
331 gftp_swap_socks (towdata->request, transfer->toreq); | |
1 | 332 } |
333 | |
334 if (transfer->files != NULL) | |
335 { | |
336 add_file_transfer (transfer->fromreq, transfer->toreq, | |
337 transfer->fromwdata, transfer->towdata, | |
338 transfer->files, 0); | |
339 g_free (transfer); | |
340 } | |
341 else | |
129 | 342 free_tdata (transfer); |
1 | 343 } |
344 | |
345 void * | |
346 do_getdir_thread (void * data) | |
347 { | |
348 gftp_transfer * transfer; | |
349 int success, sj; | |
350 | |
351 transfer = data; | |
352 | |
341 | 353 if (gftpui_common_use_threads (transfer->fromreq) || |
354 (transfer->toreq && gftpui_common_use_threads (transfer->toreq))) | |
1 | 355 { |
341 | 356 sj = sigsetjmp (gftpui_common_jmp_environment, 1); |
357 gftpui_common_use_jmp_environment = 1; | |
1 | 358 } |
359 else | |
360 sj = 0; | |
361 | |
362 success = 0; | |
363 if (sj == 0) | |
364 success = gftp_get_all_subdirs (transfer, NULL) == 0; | |
365 else | |
366 { | |
367 gftp_disconnect (transfer->fromreq); | |
368 if (transfer->toreq) | |
369 gftp_disconnect (transfer->toreq); | |
370 transfer->fromreq->logging_function (gftp_logging_error, | |
186 | 371 transfer->fromreq, |
1 | 372 _("Operation canceled\n")); |
373 } | |
374 | |
341 | 375 if (gftpui_common_use_threads (transfer->fromreq) || |
376 (transfer->toreq && gftpui_common_use_threads (transfer->toreq))) | |
377 gftpui_common_use_jmp_environment = 0; | |
1 | 378 |
379 transfer->fromreq->stopable = 0; | |
195 | 380 return (GINT_TO_POINTER (success)); |
1 | 381 } |
382 | |
383 | |
305 | 384 static void |
385 _gftp_setup_fds (gftp_transfer * tdata, gftp_file * curfle, | |
386 int *fromfd, int *tofd) | |
387 { | |
388 *tofd = -1; | |
389 *fromfd = -1; | |
390 | |
391 if (curfle->is_fd) | |
392 { | |
393 if (tdata->toreq->protonum == GFTP_LOCAL_NUM) | |
394 *tofd = curfle->fd; | |
395 else if (tdata->fromreq->protonum == GFTP_LOCAL_NUM) | |
396 *fromfd = curfle->fd; | |
397 } | |
398 } | |
399 | |
400 | |
401 static void | |
402 _gftp_done_with_fds (gftp_transfer * tdata, gftp_file * curfle) | |
403 { | |
404 if (curfle->is_fd) | |
405 { | |
406 if (tdata->toreq->protonum == GFTP_LOCAL_NUM) | |
407 tdata->toreq->datafd = -1; | |
408 else | |
409 tdata->fromreq->datafd = -1; | |
410 } | |
411 } | |
412 | |
413 | |
1 | 414 void * |
415 gftp_gtk_transfer_files (void *data) | |
416 { | |
326 | 417 int i, mode, tofd, fromfd; |
418 intptr_t preserve_permissions; | |
1 | 419 gftp_transfer * transfer; |
129 | 420 char buf[8192]; |
1 | 421 off_t fromsize, total; |
422 gftp_file * curfle; | |
86 | 423 ssize_t num_read, ret; |
1 | 424 |
425 pthread_detach (pthread_self ()); | |
426 transfer = data; | |
427 transfer->curfle = transfer->files; | |
428 gettimeofday (&transfer->starttime, NULL); | |
429 memcpy (&transfer->lasttime, &transfer->starttime, | |
430 sizeof (transfer->lasttime)); | |
76 | 431 |
182 | 432 gftp_lookup_request_option (transfer->fromreq, "preserve_permissions", |
433 &preserve_permissions); | |
434 | |
1 | 435 while (transfer->curfle != NULL) |
436 { | |
129 | 437 num_read = -1; |
438 g_static_mutex_lock (&transfer->structmutex); | |
1 | 439 curfle = transfer->curfle->data; |
76 | 440 transfer->current_file_number++; |
129 | 441 g_static_mutex_unlock (&transfer->structmutex); |
1 | 442 |
443 if (curfle->transfer_action == GFTP_TRANS_ACTION_SKIP) | |
444 { | |
129 | 445 g_static_mutex_lock (&transfer->structmutex); |
1 | 446 transfer->next_file = 1; |
447 transfer->curfle = transfer->curfle->next; | |
129 | 448 g_static_mutex_unlock (&transfer->structmutex); |
1 | 449 continue; |
450 } | |
451 | |
452 fromsize = -1; | |
453 if (gftp_connect (transfer->fromreq) == 0 && | |
454 gftp_connect (transfer->toreq) == 0) | |
455 { | |
456 if (curfle->isdir) | |
457 { | |
458 if (transfer->toreq->mkdir != NULL) | |
459 { | |
460 transfer->toreq->mkdir (transfer->toreq, curfle->destfile); | |
461 if (!GFTP_IS_CONNECTED (transfer->toreq)) | |
462 break; | |
463 } | |
464 | |
129 | 465 g_static_mutex_lock (&transfer->structmutex); |
1 | 466 transfer->next_file = 1; |
467 transfer->curfle = transfer->curfle->next; | |
129 | 468 g_static_mutex_unlock (&transfer->structmutex); |
1 | 469 continue; |
470 } | |
471 | |
305 | 472 _gftp_setup_fds (transfer, curfle, &fromfd, &tofd); |
1 | 473 |
474 if (curfle->size == 0) | |
475 { | |
476 curfle->size = gftp_get_file_size (transfer->fromreq, curfle->file); | |
477 transfer->total_bytes += curfle->size; | |
478 } | |
479 | |
480 if (GFTP_IS_CONNECTED (transfer->fromreq) && | |
481 GFTP_IS_CONNECTED (transfer->toreq)) | |
482 { | |
483 fromsize = gftp_transfer_file (transfer->fromreq, curfle->file, | |
484 fromfd, | |
485 curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ? | |
486 curfle->startsize : 0, | |
487 transfer->toreq, curfle->destfile, tofd, | |
488 curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ? | |
489 curfle->startsize : 0); | |
490 } | |
491 } | |
492 | |
493 if (!GFTP_IS_CONNECTED (transfer->fromreq) || | |
494 !GFTP_IS_CONNECTED (transfer->toreq)) | |
495 { | |
496 transfer->fromreq->logging_function (gftp_logging_misc, | |
186 | 497 transfer->fromreq, |
1 | 498 _("Error: Remote site disconnected after trying to transfer file\n")); |
499 } | |
500 else if (fromsize < 0) | |
501 { | |
129 | 502 g_static_mutex_lock (&transfer->structmutex); |
1 | 503 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; |
504 transfer->next_file = 1; | |
505 transfer->curfle = transfer->curfle->next; | |
129 | 506 g_static_mutex_unlock (&transfer->structmutex); |
1 | 507 continue; |
508 } | |
509 else | |
510 { | |
129 | 511 g_static_mutex_lock (&transfer->structmutex); |
1 | 512 transfer->curtrans = 0; |
513 transfer->curresumed = curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ? curfle->startsize : 0; | |
514 transfer->resumed_bytes += transfer->curresumed; | |
129 | 515 g_static_mutex_unlock (&transfer->structmutex); |
1 | 516 |
517 total = 0; | |
518 i = 0; | |
519 while (!transfer->cancel && | |
520 (num_read = gftp_get_next_file_chunk (transfer->fromreq, | |
521 buf, sizeof (buf))) > 0) | |
522 { | |
523 total += num_read; | |
129 | 524 gftp_calc_kbs (transfer, num_read); |
1 | 525 |
129 | 526 if ((ret = gftp_put_next_file_chunk (transfer->toreq, buf, |
86 | 527 num_read)) < 0) |
1 | 528 { |
86 | 529 num_read = (int) ret; |
1 | 530 break; |
531 } | |
532 } | |
533 } | |
534 | |
40 | 535 if (transfer->cancel) |
536 { | |
537 if (gftp_abort_transfer (transfer->fromreq) != 0) | |
538 gftp_disconnect (transfer->fromreq); | |
539 | |
540 if (gftp_abort_transfer (transfer->toreq) != 0) | |
541 gftp_disconnect (transfer->toreq); | |
542 } | |
543 else if (num_read < 0) | |
1 | 544 { |
545 transfer->fromreq->logging_function (gftp_logging_misc, | |
186 | 546 transfer->fromreq, |
1 | 547 _("Could not download %s from %s\n"), |
548 curfle->file, | |
549 transfer->fromreq->hostname); | |
550 | |
129 | 551 if (gftp_get_transfer_status (transfer, num_read) == GFTP_ERETRYABLE) |
40 | 552 continue; |
553 | |
1 | 554 break; |
555 } | |
556 else | |
557 { | |
305 | 558 _gftp_done_with_fds (transfer, curfle); |
1 | 559 if (gftp_end_transfer (transfer->fromreq) != 0) |
560 { | |
129 | 561 if (gftp_get_transfer_status (transfer, -1) == GFTP_ERETRYABLE) |
40 | 562 continue; |
563 | |
1 | 564 break; |
565 } | |
566 gftp_end_transfer (transfer->toreq); | |
567 | |
568 transfer->fromreq->logging_function (gftp_logging_misc, | |
186 | 569 transfer->fromreq, |
1 | 570 _("Successfully transferred %s at %.2f KB/s\n"), |
571 curfle->file, transfer->kbs); | |
572 } | |
573 | |
182 | 574 if (!curfle->is_fd && preserve_permissions) |
1 | 575 { |
576 if (curfle->attribs) | |
577 { | |
129 | 578 mode = gftp_parse_attribs (curfle->attribs); |
1 | 579 if (mode != 0) |
129 | 580 gftp_chmod (transfer->toreq, curfle->destfile, mode); |
1 | 581 } |
582 | |
583 if (curfle->datetime != 0) | |
584 gftp_set_file_time (transfer->toreq, curfle->destfile, | |
585 curfle->datetime); | |
586 } | |
587 | |
129 | 588 g_static_mutex_lock (&transfer->structmutex); |
278 | 589 transfer->curtrans = 0; |
1 | 590 transfer->next_file = 1; |
591 curfle->transfer_done = 1; | |
592 transfer->curfle = transfer->curfle->next; | |
129 | 593 g_static_mutex_unlock (&transfer->structmutex); |
1 | 594 |
595 if (transfer->cancel && !transfer->skip_file) | |
596 break; | |
597 transfer->cancel = 0; | |
42 | 598 transfer->fromreq->cancel = 0; |
599 transfer->toreq->cancel = 0; | |
1 | 600 } |
601 transfer->done = 1; | |
602 return (NULL); | |
603 } | |
604 | |
605 | |
303 | 606 gftp_transfer * |
1 | 607 add_file_transfer (gftp_request * fromreq, gftp_request * toreq, |
608 gftp_window_data * fromwdata, gftp_window_data * towdata, | |
609 GList * files, int copy_req) | |
610 { | |
326 | 611 int dialog; |
612 intptr_t append_transfers, one_transfer; | |
1 | 613 gftp_curtrans_data * transdata; |
614 GList * templist, *curfle; | |
615 gftp_transfer * tdata; | |
616 gftp_file * tempfle; | |
617 char *pos, *text[2]; | |
618 | |
619 for (templist = files; templist != NULL; templist = templist->next) | |
620 { | |
621 tempfle = templist->data; | |
622 if (tempfle->startsize > 0) | |
623 break; | |
624 } | |
625 dialog = templist != NULL; | |
626 | |
143 | 627 gftp_lookup_request_option (fromreq, "append_transfers", |
628 &append_transfers); | |
305 | 629 gftp_lookup_request_option (fromreq, "one_transfer", |
630 &one_transfer); | |
129 | 631 |
303 | 632 tdata = NULL; |
305 | 633 if (append_transfers && one_transfer) |
1 | 634 { |
635 pthread_mutex_lock (&transfer_mutex); | |
129 | 636 for (templist = gftp_file_transfers; templist != NULL; templist = templist->next) |
1 | 637 { |
638 tdata = templist->data; | |
129 | 639 g_static_mutex_lock (&tdata->structmutex); |
1 | 640 if (compare_request (tdata->fromreq, fromreq, 0) && |
641 compare_request (tdata->toreq, toreq, 0) && | |
642 tdata->curfle != NULL) | |
643 { | |
644 if (!copy_req) | |
645 { | |
67 | 646 gftp_request_destroy (fromreq, 1); |
647 gftp_request_destroy (toreq, 1); | |
1 | 648 } |
649 fromreq = NULL; | |
650 toreq = NULL; | |
651 | |
652 for (curfle = tdata->curfle; | |
653 curfle != NULL && curfle->next != NULL; | |
654 curfle = curfle->next); | |
655 if (curfle == NULL) | |
656 { | |
657 curfle = files; | |
658 files->prev = NULL; | |
659 } | |
660 else | |
661 { | |
662 curfle->next = files; | |
663 files->prev = curfle; | |
664 } | |
665 | |
666 for (curfle = files; curfle != NULL; curfle = curfle->next) | |
667 { | |
668 tempfle = curfle->data; | |
669 if (tempfle->isdir) | |
670 tdata->numdirs++; | |
671 else | |
672 tdata->numfiles++; | |
673 if ((pos = strrchr (tempfle->file, '/')) == NULL) | |
674 pos = tempfle->file; | |
675 else | |
676 pos++; | |
677 | |
678 text[0] = pos; | |
679 if (tempfle->transfer_action == GFTP_TRANS_ACTION_SKIP) | |
680 text[1] = _("Skipped"); | |
681 else | |
682 { | |
683 tdata->total_bytes += tempfle->size; | |
684 text[1] = _("Waiting..."); | |
685 } | |
686 | |
129 | 687 tempfle->user_data = gtk_ctree_insert_node (GTK_CTREE (dlwdw), |
688 tdata->user_data, NULL, text, 5, | |
689 NULL, NULL, NULL, NULL, | |
690 FALSE, FALSE); | |
1 | 691 transdata = g_malloc (sizeof (*transdata)); |
692 transdata->transfer = tdata; | |
693 transdata->curfle = curfle; | |
129 | 694 gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), tempfle->user_data, |
1 | 695 transdata); |
696 } | |
129 | 697 g_static_mutex_unlock (&tdata->structmutex); |
1 | 698 break; |
699 } | |
129 | 700 g_static_mutex_unlock (&tdata->structmutex); |
1 | 701 } |
702 pthread_mutex_unlock (&transfer_mutex); | |
703 } | |
704 else | |
705 templist = NULL; | |
706 | |
707 if (templist == NULL) | |
708 { | |
129 | 709 tdata = gftp_tdata_new (); |
1 | 710 if (copy_req) |
711 { | |
151 | 712 tdata->fromreq = copy_request (fromreq, 0); |
713 tdata->toreq = copy_request (toreq, 0); | |
1 | 714 } |
715 else | |
716 { | |
717 tdata->fromreq = fromreq; | |
718 tdata->toreq = toreq; | |
719 } | |
305 | 720 |
1 | 721 tdata->fromwdata = fromwdata; |
722 tdata->towdata = towdata; | |
723 if (!dialog) | |
724 tdata->show = tdata->ready = 1; | |
725 tdata->files = files; | |
726 for (curfle = files; curfle != NULL; curfle = curfle->next) | |
727 { | |
728 tempfle = curfle->data; | |
729 if (tempfle->isdir) | |
730 tdata->numdirs++; | |
731 else | |
732 tdata->numfiles++; | |
733 } | |
129 | 734 |
1 | 735 pthread_mutex_lock (&transfer_mutex); |
129 | 736 gftp_file_transfers = g_list_append (gftp_file_transfers, tdata); |
1 | 737 pthread_mutex_unlock (&transfer_mutex); |
129 | 738 |
1 | 739 if (dialog) |
740 gftp_gtk_ask_transfer (tdata); | |
741 } | |
303 | 742 |
743 return (tdata); | |
1 | 744 } |
745 | |
746 | |
48 | 747 static void |
748 remove_file (char *filename) | |
749 { | |
750 if (unlink (filename) == 0) | |
751 ftp_log (gftp_logging_misc, NULL, _("Successfully removed %s\n"), | |
752 filename); | |
753 else | |
754 ftp_log (gftp_logging_error, NULL, | |
755 _("Error: Could not remove file %s: %s\n"), filename, | |
756 g_strerror (errno)); | |
757 } | |
758 | |
759 | |
760 static void | |
761 free_edit_data (gftp_viewedit_data * ve_proc) | |
762 { | |
763 int i; | |
764 | |
294 | 765 if (ve_proc->torequest) |
766 gftp_request_destroy (ve_proc->torequest, 1); | |
48 | 767 if (ve_proc->filename) |
768 g_free (ve_proc->filename); | |
769 if (ve_proc->remote_filename) | |
770 g_free (ve_proc->remote_filename); | |
771 for (i = 0; ve_proc->argv[i] != NULL; i++) | |
772 g_free (ve_proc->argv[i]); | |
773 g_free (ve_proc->argv); | |
774 g_free (ve_proc); | |
775 } | |
776 | |
777 | |
778 static void | |
779 dont_upload (gftp_viewedit_data * ve_proc, gftp_dialog_data * ddata) | |
1 | 780 { |
48 | 781 remove_file (ve_proc->filename); |
782 free_edit_data (ve_proc); | |
783 } | |
784 | |
785 | |
786 static void | |
787 do_upload (gftp_viewedit_data * ve_proc, gftp_dialog_data * ddata) | |
788 { | |
303 | 789 gftp_transfer * tdata; |
48 | 790 gftp_file * tempfle; |
791 GList * newfile; | |
1 | 792 |
48 | 793 tempfle = g_malloc0 (sizeof (*tempfle)); |
294 | 794 tempfle->destfile = gftp_build_path (ve_proc->torequest->directory, |
795 ve_proc->remote_filename, NULL); | |
48 | 796 ve_proc->remote_filename = NULL; |
797 tempfle->file = ve_proc->filename; | |
798 ve_proc->filename = NULL; | |
799 tempfle->done_rm = 1; | |
800 newfile = g_list_append (NULL, tempfle); | |
303 | 801 tdata = add_file_transfer (ve_proc->fromwdata->request, ve_proc->torequest, |
802 ve_proc->fromwdata, ve_proc->towdata, newfile, 1); | |
48 | 803 free_edit_data (ve_proc); |
303 | 804 |
805 if (tdata != NULL) | |
806 tdata->conn_error_no_timeout = 1; | |
48 | 807 } |
808 | |
1 | 809 |
48 | 810 static void |
811 check_done_process (void) | |
812 { | |
813 gftp_viewedit_data * ve_proc; | |
814 GList * curdata, *deldata; | |
815 struct stat st; | |
816 int ret; | |
817 char *str; | |
818 pid_t pid; | |
819 | |
820 viewedit_process_done = 0; | |
821 while ((pid = waitpid (-1, &ret, WNOHANG)) > 0) | |
1 | 822 { |
48 | 823 curdata = viewedit_processes; |
824 while (curdata != NULL) | |
825 { | |
826 ve_proc = curdata->data; | |
827 deldata = curdata; | |
828 curdata = curdata->next; | |
829 if (ve_proc->pid == pid) | |
830 { | |
831 viewedit_processes = g_list_remove_link (viewedit_processes, | |
832 deldata); | |
833 if (ret != 0) | |
834 ftp_log (gftp_logging_error, NULL, | |
835 _("Error: Child %d returned %d\n"), pid, ret); | |
836 else | |
837 ftp_log (gftp_logging_misc, NULL, | |
838 _("Child %d returned successfully\n"), pid); | |
839 | |
840 if (!ve_proc->view && !ve_proc->dontupload) | |
841 { | |
842 /* We was editing the file. Upload it */ | |
843 if (stat (ve_proc->filename, &st) == -1) | |
844 ftp_log (gftp_logging_error, NULL, | |
845 _("Error: Cannot get information about file %s: %s\n"), | |
846 ve_proc->filename, g_strerror (errno)); | |
847 else if (st.st_mtime == ve_proc->st.st_mtime) | |
848 { | |
849 ftp_log (gftp_logging_misc, NULL, | |
850 _("File %s was not changed\n"), | |
851 ve_proc->filename); | |
852 remove_file (ve_proc->filename); | |
853 } | |
854 else | |
855 { | |
856 memcpy (&ve_proc->st, &st, sizeof (ve_proc->st)); | |
857 str = g_strdup_printf ( | |
858 _("File %s has changed.\nWould you like to upload it?"), | |
859 ve_proc->remote_filename); | |
860 | |
861 MakeYesNoDialog (_("Edit File"), str, | |
862 do_upload, ve_proc, | |
863 dont_upload, ve_proc); | |
864 g_free (str); | |
865 continue; | |
866 } | |
867 } | |
868 | |
869 free_edit_data (ve_proc); | |
870 continue; | |
871 } | |
1 | 872 } |
873 } | |
874 } | |
875 | |
876 | |
877 static void | |
878 on_next_transfer (gftp_transfer * tdata) | |
879 { | |
326 | 880 int fd; |
881 intptr_t refresh_files; | |
1 | 882 gftp_file * tempfle; |
883 | |
884 tdata->next_file = 0; | |
885 for (; tdata->updfle != tdata->curfle; tdata->updfle = tdata->updfle->next) | |
886 { | |
887 tempfle = tdata->updfle->data; | |
888 | |
889 if (tempfle->is_fd) | |
58 | 890 fd = tempfle->fd; |
1 | 891 else |
892 fd = 0; | |
893 | |
894 if (tempfle->done_view) | |
895 { | |
896 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) | |
897 view_file (tempfle->destfile, fd, 1, tempfle->done_rm, 1, 0, | |
898 tempfle->file, NULL); | |
899 | |
900 if (tempfle->is_fd) | |
901 { | |
58 | 902 close (tempfle->fd); |
903 tempfle->fd = -1; | |
1 | 904 } |
905 } | |
906 else if (tempfle->done_edit) | |
907 { | |
908 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) | |
909 view_file (tempfle->destfile, fd, 0, tempfle->done_rm, 1, 0, | |
910 tempfle->file, NULL); | |
911 | |
912 if (tempfle->is_fd) | |
913 { | |
58 | 914 close (tempfle->fd); |
915 tempfle->fd = -1; | |
1 | 916 } |
917 } | |
918 else if (tempfle->done_rm) | |
919 tdata->fromreq->rmfile (tdata->fromreq, tempfle->file); | |
920 | |
921 if (tempfle->transfer_action == GFTP_TRANS_ACTION_SKIP) | |
129 | 922 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->user_data, 1, |
1 | 923 _("Skipped")); |
924 else | |
129 | 925 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->user_data, 1, |
1 | 926 _("Finished")); |
927 } | |
928 | |
129 | 929 gftp_lookup_request_option (tdata->fromreq, "refresh_files", &refresh_files); |
930 | |
1 | 931 if (refresh_files && tdata->curfle && tdata->curfle->next && |
932 compare_request (tdata->toreq, | |
933 ((gftp_window_data *) tdata->towdata)->request, 1)) | |
341 | 934 gftpui_refresh (tdata->towdata); |
1 | 935 } |
936 | |
937 | |
938 static void | |
19 | 939 get_trans_password (gftp_request * request, gftp_dialog_data * ddata) |
940 { | |
941 gftp_set_password (request, gtk_entry_get_text (GTK_ENTRY (ddata->edit))); | |
942 request->stopable = 0; | |
943 } | |
944 | |
945 | |
946 static void | |
947 cancel_get_trans_password (gftp_transfer * tdata, gftp_dialog_data * ddata) | |
948 { | |
949 if (tdata->fromreq->stopable == 0) | |
950 return; | |
951 | |
129 | 952 g_static_mutex_lock (&tdata->structmutex); |
19 | 953 if (tdata->started) |
42 | 954 { |
955 tdata->cancel = 1; | |
956 tdata->fromreq->cancel = 1; | |
957 tdata->toreq->cancel = 1; | |
958 } | |
19 | 959 else |
960 tdata->done = 1; | |
961 | |
962 tdata->fromreq->stopable = 0; | |
963 tdata->toreq->stopable = 0; | |
129 | 964 g_static_mutex_unlock (&tdata->structmutex); |
40 | 965 |
19 | 966 ftp_log (gftp_logging_misc, NULL, _("Stopping the transfer of %s\n"), |
967 ((gftp_file *) tdata->curfle->data)->file); | |
968 } | |
969 | |
970 | |
971 static void | |
1 | 972 show_transfer (gftp_transfer * tdata) |
973 { | |
974 GdkPixmap * closedir_pixmap, * opendir_pixmap; | |
975 GdkBitmap * closedir_bitmap, * opendir_bitmap; | |
976 gftp_curtrans_data * transdata; | |
977 gftp_file * tempfle; | |
978 char *pos, *text[2]; | |
979 GList * templist; | |
980 | |
981 gftp_get_pixmap (dlwdw, "open_dir.xpm", &opendir_pixmap, &opendir_bitmap); | |
982 gftp_get_pixmap (dlwdw, "dir.xpm", &closedir_pixmap, &closedir_bitmap); | |
983 | |
129 | 984 text[0] = tdata->fromreq->hostname; |
1 | 985 text[1] = _("Waiting..."); |
129 | 986 tdata->user_data = gtk_ctree_insert_node (GTK_CTREE (dlwdw), NULL, NULL, |
987 text, 5, | |
1 | 988 closedir_pixmap, closedir_bitmap, |
989 opendir_pixmap, opendir_bitmap, | |
990 FALSE, | |
991 tdata->numdirs + tdata->numfiles < 50); | |
992 transdata = g_malloc (sizeof (*transdata)); | |
993 transdata->transfer = tdata; | |
994 transdata->curfle = NULL; | |
129 | 995 gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), tdata->user_data, transdata); |
1 | 996 tdata->show = 0; |
997 tdata->curfle = tdata->updfle = tdata->files; | |
998 | |
999 tdata->total_bytes = 0; | |
1000 for (templist = tdata->files; templist != NULL; templist = templist->next) | |
1001 { | |
1002 tempfle = templist->data; | |
1003 if ((pos = strrchr (tempfle->file, '/')) == NULL) | |
1004 pos = tempfle->file; | |
1005 else | |
1006 pos++; | |
1007 text[0] = pos; | |
1008 if (tempfle->transfer_action == GFTP_TRANS_ACTION_SKIP) | |
1009 text[1] = _("Skipped"); | |
1010 else | |
1011 { | |
1012 tdata->total_bytes += tempfle->size; | |
1013 text[1] = _("Waiting..."); | |
1014 } | |
1015 | |
129 | 1016 tempfle->user_data = gtk_ctree_insert_node (GTK_CTREE (dlwdw), |
1017 tdata->user_data, | |
1 | 1018 NULL, text, 5, NULL, NULL, NULL, |
1019 NULL, FALSE, FALSE); | |
1020 transdata = g_malloc (sizeof (*transdata)); | |
1021 transdata->transfer = tdata; | |
1022 transdata->curfle = templist; | |
129 | 1023 gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), tempfle->user_data, |
1024 transdata); | |
1 | 1025 } |
1026 | |
1027 if (!tdata->toreq->stopable && tdata->toreq->need_userpass && | |
1028 (tdata->toreq->password == NULL || *tdata->toreq->password == '\0')) | |
1029 { | |
1030 tdata->toreq->stopable = 1; | |
1031 MakeEditDialog (_("Enter Password"), | |
1032 _("Please enter your password for this site"), NULL, 0, | |
19 | 1033 NULL, gftp_dialog_button_connect, |
1034 get_trans_password, tdata->toreq, | |
1035 cancel_get_trans_password, tdata); | |
1 | 1036 } |
1037 | |
1038 if (!tdata->fromreq->stopable && tdata->fromreq->need_userpass && | |
1039 (tdata->fromreq->password == NULL || *tdata->fromreq->password == '\0')) | |
1040 { | |
1041 tdata->fromreq->stopable = 1; | |
1042 MakeEditDialog (_("Enter Password"), | |
1043 _("Please enter your password for this site"), NULL, 0, | |
19 | 1044 NULL, gftp_dialog_button_connect, |
1045 get_trans_password, tdata->fromreq, | |
1046 cancel_get_trans_password, tdata); | |
1 | 1047 } |
1048 } | |
1049 | |
1050 | |
1051 static void | |
1052 transfer_done (GList * node) | |
1053 { | |
1054 gftp_curtrans_data * transdata; | |
1055 gftp_request * fromreq; | |
1056 gftp_transfer * tdata; | |
1057 gftp_file * tempfle; | |
1058 GList * templist; | |
1059 | |
1060 tdata = node->data; | |
1061 if (tdata->started) | |
1062 { | |
56 | 1063 fromreq = tdata->fromwdata != NULL ? ((gftp_window_data *) tdata->fromwdata)->request : NULL; |
297 | 1064 |
1065 if (GFTP_IS_SAME_HOST_STOP_TRANS ((gftp_window_data *) tdata->fromwdata, | |
1066 tdata->fromreq)) | |
309 | 1067 { |
1068 gftp_copy_param_options (((gftp_window_data *) tdata->fromwdata)->request, tdata->fromreq); | |
1069 | |
1070 gftp_swap_socks (((gftp_window_data *) tdata->fromwdata)->request, | |
1071 tdata->fromreq); | |
1072 } | |
1 | 1073 else |
297 | 1074 gftp_disconnect (tdata->fromreq); |
1075 | |
1076 if (GFTP_IS_SAME_HOST_STOP_TRANS ((gftp_window_data *) tdata->towdata, | |
1077 tdata->toreq)) | |
309 | 1078 { |
1079 gftp_copy_param_options (((gftp_window_data *) tdata->towdata)->request, tdata->toreq); | |
1080 | |
1081 gftp_swap_socks (((gftp_window_data *) tdata->towdata)->request, | |
1082 tdata->toreq); | |
1083 } | |
297 | 1084 else |
1085 gftp_disconnect (tdata->toreq); | |
1 | 1086 |
305 | 1087 if (tdata->towdata != NULL && compare_request (tdata->toreq, |
1088 ((gftp_window_data *) tdata->towdata)->request, 1)) | |
341 | 1089 gftpui_refresh (tdata->towdata); |
305 | 1090 |
129 | 1091 num_transfers_in_progress--; |
1 | 1092 } |
1093 | |
2
a171df6764a7
* Fixed crash if you was already transfering a file, and you started another
masneyb
parents:
1
diff
changeset
|
1094 if (!tdata->show && tdata->started) |
1 | 1095 { |
129 | 1096 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), |
1097 tdata->user_data); | |
1 | 1098 if (transdata != NULL) |
1099 g_free (transdata); | |
1100 | |
1101 for (templist = tdata->files; templist != NULL; templist = templist->next) | |
1102 { | |
1103 tempfle = templist->data; | |
129 | 1104 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), |
1105 tempfle->user_data); | |
1 | 1106 if (transdata != NULL) |
1107 g_free (transdata); | |
1108 } | |
1109 | |
129 | 1110 gtk_ctree_remove_node (GTK_CTREE (dlwdw), tdata->user_data); |
1 | 1111 } |
129 | 1112 |
1 | 1113 pthread_mutex_lock (&transfer_mutex); |
129 | 1114 gftp_file_transfers = g_list_remove_link (gftp_file_transfers, node); |
320 | 1115 gdk_window_set_title (gtk_widget_get_parent_window (GTK_WIDGET(dlwdw)), |
1116 gftp_version); | |
1 | 1117 pthread_mutex_unlock (&transfer_mutex); |
129 | 1118 |
1 | 1119 free_tdata (tdata); |
1120 } | |
1121 | |
1122 | |
1123 static void | |
1124 create_transfer (gftp_transfer * tdata) | |
1125 { | |
1126 pthread_t tid; | |
1127 | |
1128 if (!tdata->fromreq->stopable) | |
1129 { | |
297 | 1130 if (GFTP_IS_SAME_HOST_START_TRANS ((gftp_window_data *) tdata->fromwdata, |
1131 tdata->fromreq)) | |
1132 { | |
1133 gftp_swap_socks (tdata->fromreq, | |
1134 ((gftp_window_data *) tdata->fromwdata)->request); | |
1135 update_window (tdata->fromwdata); | |
1136 } | |
1137 | |
1138 if (GFTP_IS_SAME_HOST_START_TRANS ((gftp_window_data *) tdata->towdata, | |
1139 tdata->toreq)) | |
1140 { | |
63 | 1141 gftp_swap_socks (tdata->toreq, |
1142 ((gftp_window_data *) tdata->towdata)->request); | |
297 | 1143 update_window (tdata->towdata); |
1 | 1144 } |
297 | 1145 |
129 | 1146 num_transfers_in_progress++; |
1 | 1147 tdata->started = 1; |
1148 tdata->stalled = 1; | |
129 | 1149 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->user_data, 1, |
1 | 1150 _("Connecting...")); |
1151 pthread_create (&tid, NULL, gftp_gtk_transfer_files, tdata); | |
1152 } | |
1153 } | |
1154 | |
1155 | |
1156 static void | |
1157 update_file_status (gftp_transfer * tdata) | |
1158 { | |
320 | 1159 char totstr[100], dlstr[100], winstr[150], gotstr[50], ofstr[50]; |
1160 int hours, mins, secs, pcent, st, show_trans_in_title; | |
246 | 1161 unsigned long remaining_secs, lkbs; |
1 | 1162 gftp_file * tempfle; |
1163 struct timeval tv; | |
320 | 1164 |
129 | 1165 g_static_mutex_lock (&tdata->statmutex); |
1 | 1166 tempfle = tdata->curfle->data; |
1167 | |
1168 gettimeofday (&tv, NULL); | |
220 | 1169 |
1170 remaining_secs = (tdata->total_bytes - tdata->trans_bytes - tdata->resumed_bytes) / 1024; | |
246 | 1171 |
1172 lkbs = (unsigned long) tdata->kbs; | |
1173 if (lkbs > 0) | |
1174 remaining_secs /= lkbs; | |
1 | 1175 |
220 | 1176 hours = remaining_secs / 3600; |
1177 remaining_secs -= hours * 3600; | |
1178 mins = remaining_secs / 60; | |
1179 remaining_secs -= mins * 60; | |
1180 secs = remaining_secs; | |
1 | 1181 |
1182 if (hours < 0 || mins < 0 || secs < 0) | |
1183 { | |
129 | 1184 g_static_mutex_unlock (&tdata->statmutex); |
1 | 1185 return; |
1186 } | |
1187 | |
246 | 1188 if ((double) tdata->total_bytes > 0) |
1189 pcent = (int) ((double) (tdata->trans_bytes + tdata->resumed_bytes) / (double) tdata->total_bytes * 100.0); | |
1190 else | |
1 | 1191 pcent = 0; |
1192 | |
1193 g_snprintf (totstr, sizeof (totstr), | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
1194 _("%d%% complete, %02d:%02d:%02d est. time remaining. (File %ld of %ld)"), |
1 | 1195 pcent, hours, mins, secs, tdata->current_file_number, |
1196 tdata->numdirs + tdata->numfiles); | |
1197 | |
1198 *dlstr = '\0'; | |
1199 if (!tdata->stalled) | |
1200 { | |
1201 insert_commas (tdata->curtrans + tdata->curresumed, gotstr, sizeof (gotstr)); | |
1202 insert_commas (tempfle->size, ofstr, sizeof (ofstr)); | |
1203 st = 1; | |
1204 if (tv.tv_sec - tdata->lasttime.tv_sec <= 5) | |
1205 { | |
1206 if (tdata->curfle->next != NULL) | |
1207 { | |
220 | 1208 remaining_secs = (tempfle->size - tdata->curtrans - tdata->curresumed) / 1024; |
246 | 1209 |
1210 lkbs = (unsigned long) tdata->kbs; | |
1211 if (lkbs > 0) | |
1212 remaining_secs /= lkbs; | |
220 | 1213 |
1214 hours = remaining_secs / 3600; | |
1215 remaining_secs -= hours * 3600; | |
1216 mins = remaining_secs / 60; | |
1217 remaining_secs -= mins * 60; | |
1218 secs = remaining_secs; | |
1 | 1219 } |
1220 | |
1221 if (!(hours < 0 || mins < 0 || secs < 0)) | |
1222 { | |
1223 g_snprintf (dlstr, sizeof (dlstr), | |
1224 _("Recv %s of %s at %.2fKB/s, %02d:%02d:%02d est. time remaining"), gotstr, ofstr, tdata->kbs, hours, mins, secs); | |
1225 st = 0; | |
1226 } | |
1227 } | |
1228 | |
1229 if (st) | |
1230 { | |
1231 tdata->stalled = 1; | |
1232 g_snprintf (dlstr, sizeof (dlstr), | |
1233 _("Recv %s of %s, transfer stalled, unknown time remaining"), | |
1234 gotstr, ofstr); | |
1235 } | |
1236 } | |
1237 | |
129 | 1238 g_static_mutex_unlock (&tdata->statmutex); |
1 | 1239 |
129 | 1240 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->user_data, 1, totstr); |
320 | 1241 |
1242 gftp_lookup_global_option ("show_trans_in_title", &show_trans_in_title); | |
1243 if (gftp_file_transfers->data == tdata && show_trans_in_title) | |
1244 { | |
1245 g_snprintf (winstr, sizeof(winstr), "%s: %s", gftp_version, totstr); | |
1246 gdk_window_set_title (gtk_widget_get_parent_window (GTK_WIDGET(dlwdw)), | |
1247 winstr); | |
1248 } | |
1 | 1249 |
1250 if (*dlstr != '\0') | |
129 | 1251 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->user_data, 1, dlstr); |
1 | 1252 } |
1253 | |
56 | 1254 static void |
1255 update_window_transfer_bytes (gftp_window_data * wdata) | |
1256 { | |
1257 char *tempstr, *temp1str; | |
1258 | |
1259 if (wdata->request->gotbytes == -1) | |
1260 { | |
1261 update_window_info (); | |
1262 wdata->request->gotbytes = 0; | |
1263 } | |
1264 else | |
1265 { | |
1266 tempstr = insert_commas (wdata->request->gotbytes, NULL, 0); | |
1267 temp1str = g_strdup_printf (_("Retrieving file names...%s bytes"), | |
1268 tempstr); | |
1269 gtk_label_set (GTK_LABEL (wdata->hoststxt), temp1str); | |
1270 g_free (tempstr); | |
1271 g_free (temp1str); | |
1272 } | |
1273 } | |
1274 | |
1 | 1275 |
48 | 1276 gint |
1277 update_downloads (gpointer data) | |
1278 { | |
326 | 1279 intptr_t do_one_transfer_at_a_time; |
48 | 1280 GList * templist, * next; |
1281 gftp_transfer * tdata; | |
1282 | |
129 | 1283 if (gftp_file_transfer_logs != NULL) |
48 | 1284 display_cached_logs (); |
1285 | |
56 | 1286 if (window1.request->gotbytes != 0) |
1287 update_window_transfer_bytes (&window1); | |
48 | 1288 if (window2.request->gotbytes != 0) |
56 | 1289 update_window_transfer_bytes (&window2); |
48 | 1290 |
1291 if (viewedit_process_done) | |
1292 check_done_process (); | |
1293 | |
129 | 1294 for (templist = gftp_file_transfers; templist != NULL;) |
48 | 1295 { |
1296 tdata = templist->data; | |
1297 if (tdata->ready) | |
1298 { | |
129 | 1299 g_static_mutex_lock (&tdata->structmutex); |
48 | 1300 |
1301 if (tdata->next_file) | |
1302 on_next_transfer (tdata); | |
1303 else if (tdata->show) | |
1304 show_transfer (tdata); | |
1305 else if (tdata->done) | |
1306 { | |
1307 next = templist->next; | |
129 | 1308 g_static_mutex_unlock (&tdata->structmutex); |
48 | 1309 transfer_done (templist); |
1310 templist = next; | |
1311 continue; | |
1312 } | |
1313 | |
1314 if (tdata->curfle != NULL) | |
1315 { | |
151 | 1316 gftp_lookup_global_option ("one_transfer", |
129 | 1317 &do_one_transfer_at_a_time); |
1318 | |
207 | 1319 if (!tdata->started && |
129 | 1320 (num_transfers_in_progress == 0 || !do_one_transfer_at_a_time)) |
48 | 1321 create_transfer (tdata); |
1322 | |
1323 if (tdata->started) | |
1324 update_file_status (tdata); | |
1325 } | |
129 | 1326 g_static_mutex_unlock (&tdata->structmutex); |
48 | 1327 } |
1328 templist = templist->next; | |
1329 } | |
1330 | |
1331 gtk_timeout_add (500, update_downloads, NULL); | |
1332 return (0); | |
1333 } | |
1334 | |
1335 | |
1 | 1336 void |
1337 start_transfer (gpointer data) | |
1338 { | |
1339 gftp_curtrans_data * transdata; | |
1340 GtkCTreeNode * node; | |
1341 | |
1342 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1343 { | |
1344 ftp_log (gftp_logging_misc, NULL, | |
1345 _("There are no file transfers selected\n")); | |
1346 return; | |
1347 } | |
1348 node = GTK_CLIST (dlwdw)->selection->data; | |
1349 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1350 | |
129 | 1351 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 1352 if (!transdata->transfer->started) |
1353 create_transfer (transdata->transfer); | |
129 | 1354 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 1355 } |
1356 | |
1357 | |
1358 void | |
1359 stop_transfer (gpointer data) | |
1360 { | |
1361 gftp_curtrans_data * transdata; | |
1362 GtkCTreeNode * node; | |
1363 | |
1364 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1365 { | |
1366 ftp_log (gftp_logging_misc, NULL, | |
1367 _("There are no file transfers selected\n")); | |
1368 return; | |
1369 } | |
1370 node = GTK_CLIST (dlwdw)->selection->data; | |
1371 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1372 | |
129 | 1373 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 1374 if (transdata->transfer->started) |
1375 { | |
1376 transdata->transfer->cancel = 1; | |
42 | 1377 transdata->transfer->fromreq->cancel = 1; |
1378 transdata->transfer->toreq->cancel = 1; | |
1 | 1379 transdata->transfer->skip_file = 0; |
1380 } | |
1381 else | |
1382 transdata->transfer->done = 1; | |
129 | 1383 g_static_mutex_unlock (&transdata->transfer->structmutex); |
40 | 1384 |
1 | 1385 ftp_log (gftp_logging_misc, NULL, _("Stopping the transfer on host %s\n"), |
1386 transdata->transfer->fromreq->hostname); | |
1387 } | |
1388 | |
1389 | |
1390 void | |
1391 skip_transfer (gpointer data) | |
1392 { | |
1393 gftp_curtrans_data * transdata; | |
1394 GtkCTreeNode * node; | |
1395 gftp_file * curfle; | |
40 | 1396 char *file; |
1 | 1397 |
1398 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1399 { | |
1400 ftp_log (gftp_logging_misc, NULL, | |
1401 _("There are no file transfers selected\n")); | |
1402 return; | |
1403 } | |
1404 node = GTK_CLIST (dlwdw)->selection->data; | |
1405 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1406 | |
129 | 1407 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 1408 if (transdata->transfer->curfle != NULL) |
1409 { | |
1410 curfle = transdata->transfer->curfle->data; | |
1411 if (transdata->transfer->started) | |
1412 { | |
1413 transdata->transfer->cancel = 1; | |
42 | 1414 transdata->transfer->fromreq->cancel = 1; |
1415 transdata->transfer->toreq->cancel = 1; | |
1 | 1416 transdata->transfer->skip_file = 1; |
1417 } | |
1418 | |
1419 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
40 | 1420 file = curfle->file; |
1 | 1421 } |
40 | 1422 else |
1423 file = NULL; | |
129 | 1424 g_static_mutex_unlock (&transdata->transfer->structmutex); |
40 | 1425 |
1426 ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"), | |
1427 file, transdata->transfer->fromreq->hostname); | |
1 | 1428 } |
1429 | |
1430 | |
1431 void | |
1432 remove_file_transfer (gpointer data) | |
1433 { | |
1434 gftp_curtrans_data * transdata; | |
1435 GtkCTreeNode * node; | |
1436 gftp_file * curfle; | |
1437 | |
1438 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1439 { | |
1440 ftp_log (gftp_logging_misc, NULL, | |
1441 _("There are no file transfers selected\n")); | |
1442 return; | |
1443 } | |
1444 | |
1445 node = GTK_CLIST (dlwdw)->selection->data; | |
1446 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1447 | |
1448 | |
1449 if (transdata->curfle == NULL || transdata->curfle->data == NULL) | |
1450 return; | |
1451 | |
1452 curfle = transdata->curfle->data; | |
1453 | |
1454 if (curfle->transfer_action & GFTP_TRANS_ACTION_SKIP) | |
1455 return; | |
1456 | |
129 | 1457 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 1458 |
1459 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
1460 | |
1461 if (transdata->transfer->started && | |
1462 transdata->curfle == transdata->transfer->curfle) | |
1463 { | |
1464 transdata->transfer->cancel = 1; | |
42 | 1465 transdata->transfer->fromreq->cancel = 1; |
1466 transdata->transfer->toreq->cancel = 1; | |
1 | 1467 transdata->transfer->skip_file = 1; |
1468 } | |
1469 else if (transdata->curfle != transdata->transfer->curfle && | |
1470 !curfle->transfer_done) | |
1471 { | |
129 | 1472 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), curfle->user_data, 1, |
1 | 1473 _("Skipped")); |
1474 transdata->transfer->total_bytes -= curfle->size; | |
1475 } | |
1476 | |
129 | 1477 g_static_mutex_unlock (&transdata->transfer->structmutex); |
40 | 1478 |
1 | 1479 ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"), |
1480 curfle->file, transdata->transfer->fromreq->hostname); | |
1481 } | |
1482 | |
1483 | |
1484 void | |
1485 move_transfer_up (gpointer data) | |
1486 { | |
1487 GList * firstentry, * secentry, * lastentry; | |
1488 gftp_curtrans_data * transdata; | |
1489 GtkCTreeNode * node; | |
1490 | |
1491 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1492 { | |
1493 ftp_log (gftp_logging_misc, NULL, | |
1494 _("There are no file transfers selected\n")); | |
1495 return; | |
1496 } | |
1497 node = GTK_CLIST (dlwdw)->selection->data; | |
1498 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1499 | |
1500 if (transdata->curfle == NULL) | |
1501 return; | |
1502 | |
129 | 1503 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 1504 if (transdata->curfle->prev != NULL && (!transdata->transfer->started || |
1505 (transdata->transfer->curfle != transdata->curfle && | |
1506 transdata->transfer->curfle != transdata->curfle->prev))) | |
1507 { | |
1508 if (transdata->curfle->prev->prev == NULL) | |
1509 { | |
1510 firstentry = transdata->curfle->prev; | |
1511 lastentry = transdata->curfle->next; | |
1512 transdata->transfer->files = transdata->curfle; | |
1513 transdata->curfle->next = firstentry; | |
1514 transdata->transfer->files->prev = NULL; | |
1515 firstentry->prev = transdata->curfle; | |
1516 firstentry->next = lastentry; | |
1517 if (lastentry != NULL) | |
1518 lastentry->prev = firstentry; | |
1519 } | |
1520 else | |
1521 { | |
1522 firstentry = transdata->curfle->prev->prev; | |
1523 secentry = transdata->curfle->prev; | |
1524 lastentry = transdata->curfle->next; | |
1525 firstentry->next = transdata->curfle; | |
1526 transdata->curfle->prev = firstentry; | |
1527 transdata->curfle->next = secentry; | |
1528 secentry->prev = transdata->curfle; | |
1529 secentry->next = lastentry; | |
1530 if (lastentry != NULL) | |
1531 lastentry->prev = secentry; | |
1532 } | |
1533 | |
1534 gtk_ctree_move (GTK_CTREE (dlwdw), | |
129 | 1535 ((gftp_file *) transdata->curfle->data)->user_data, |
1536 transdata->transfer->user_data, | |
1 | 1537 transdata->curfle->next != NULL ? |
129 | 1538 ((gftp_file *) transdata->curfle->next->data)->user_data: NULL); |
1 | 1539 } |
129 | 1540 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 1541 } |
1542 | |
1543 void | |
1544 move_transfer_down (gpointer data) | |
1545 { | |
1546 GList * firstentry, * secentry, * lastentry; | |
1547 gftp_curtrans_data * transdata; | |
1548 GtkCTreeNode * node; | |
1549 | |
1550 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1551 { | |
1552 ftp_log (gftp_logging_misc, NULL, | |
1553 _("There are no file transfers selected\n")); | |
1554 return; | |
1555 } | |
1556 node = GTK_CLIST (dlwdw)->selection->data; | |
1557 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1558 | |
1559 if (transdata->curfle == NULL) | |
1560 return; | |
1561 | |
129 | 1562 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 1563 if (transdata->curfle->next != NULL && (!transdata->transfer->started || |
1564 (transdata->transfer->curfle != transdata->curfle && | |
1565 transdata->transfer->curfle != transdata->curfle->next))) | |
1566 { | |
1567 if (transdata->curfle->prev == NULL) | |
1568 { | |
1569 firstentry = transdata->curfle->next; | |
1570 lastentry = transdata->curfle->next->next; | |
1571 transdata->transfer->files = firstentry; | |
1572 transdata->transfer->files->prev = NULL; | |
1573 transdata->transfer->files->next = transdata->curfle; | |
1574 transdata->curfle->prev = transdata->transfer->files; | |
1575 transdata->curfle->next = lastentry; | |
1576 if (lastentry != NULL) | |
1577 lastentry->prev = transdata->curfle; | |
1578 } | |
1579 else | |
1580 { | |
1581 firstentry = transdata->curfle->prev; | |
1582 secentry = transdata->curfle->next; | |
1583 lastentry = transdata->curfle->next->next; | |
1584 firstentry->next = secentry; | |
1585 secentry->prev = firstentry; | |
1586 secentry->next = transdata->curfle; | |
1587 transdata->curfle->prev = secentry; | |
1588 transdata->curfle->next = lastentry; | |
1589 if (lastentry != NULL) | |
1590 lastentry->prev = transdata->curfle; | |
1591 } | |
1592 | |
1593 gtk_ctree_move (GTK_CTREE (dlwdw), | |
129 | 1594 ((gftp_file *) transdata->curfle->data)->user_data, |
1595 transdata->transfer->user_data, | |
1 | 1596 transdata->curfle->next != NULL ? |
129 | 1597 ((gftp_file *) transdata->curfle->next->data)->user_data: NULL); |
1 | 1598 } |
129 | 1599 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 1600 } |
1601 | |
1602 | |
48 | 1603 static void |
1604 trans_selectall (GtkWidget * widget, gpointer data) | |
1605 { | |
1606 gftp_transfer * tdata; | |
1607 tdata = data; | |
1608 | |
1609 gtk_clist_select_all (GTK_CLIST (tdata->clist)); | |
1610 } | |
1611 | |
1612 | |
1613 static void | |
1614 trans_unselectall (GtkWidget * widget, gpointer data) | |
1615 { | |
1616 gftp_transfer * tdata; | |
1617 tdata = data; | |
1618 | |
1619 gtk_clist_unselect_all (GTK_CLIST (tdata->clist)); | |
1620 } | |
1621 | |
1622 | |
1623 static void | |
1624 overwrite (GtkWidget * widget, gpointer data) | |
1625 { | |
1626 GList * templist, * filelist; | |
1627 gftp_transfer * tdata; | |
1628 gftp_file * tempfle; | |
1629 int curpos; | |
1630 | |
1631 tdata = data; | |
1632 curpos = 0; | |
1633 filelist = tdata->files; | |
1634 templist = GTK_CLIST (tdata->clist)->selection; | |
1635 while (templist != NULL) | |
1636 { | |
1637 templist = get_next_selection (templist, &filelist, &curpos); | |
1638 tempfle = filelist->data; | |
1639 tempfle->transfer_action = GFTP_TRANS_ACTION_OVERWRITE; | |
1640 gtk_clist_set_text (GTK_CLIST (tdata->clist), curpos, 3, _("Overwrite")); | |
1641 } | |
1642 } | |
1643 | |
1644 | |
1645 static void | |
1646 resume (GtkWidget * widget, gpointer data) | |
1647 { | |
1648 GList * templist, * filelist; | |
1649 gftp_transfer * tdata; | |
1650 gftp_file * tempfle; | |
1651 int curpos; | |
1652 | |
1653 tdata = data; | |
1654 curpos = 0; | |
1655 filelist = tdata->files; | |
1656 templist = GTK_CLIST (tdata->clist)->selection; | |
1657 while (templist != NULL) | |
1658 { | |
1659 templist = get_next_selection (templist, &filelist, &curpos); | |
1660 tempfle = filelist->data; | |
1661 tempfle->transfer_action = GFTP_TRANS_ACTION_RESUME; | |
1662 gtk_clist_set_text (GTK_CLIST (tdata->clist), curpos, 3, _("Resume")); | |
1663 } | |
1664 } | |
1665 | |
1666 | |
1667 static void | |
1668 skip (GtkWidget * widget, gpointer data) | |
1669 { | |
1670 GList * templist, * filelist; | |
1671 gftp_transfer * tdata; | |
1672 gftp_file * tempfle; | |
1673 int curpos; | |
1674 | |
1675 tdata = data; | |
1676 curpos = 0; | |
1677 filelist = tdata->files; | |
1678 templist = GTK_CLIST (tdata->clist)->selection; | |
1679 while (templist != NULL) | |
1680 { | |
1681 templist = get_next_selection (templist, &filelist, &curpos); | |
1682 tempfle = filelist->data; | |
1683 tempfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
1684 gtk_clist_set_text (GTK_CLIST (tdata->clist), curpos, 3, _("Skip")); | |
1685 } | |
1686 } | |
1687 | |
1688 | |
1689 static void | |
1690 ok (GtkWidget * widget, gpointer data) | |
1691 { | |
1692 gftp_transfer * tdata; | |
1693 gftp_file * tempfle; | |
1694 GList * templist; | |
1695 | |
1696 tdata = data; | |
129 | 1697 g_static_mutex_lock (&tdata->structmutex); |
48 | 1698 for (templist = tdata->files; templist != NULL; templist = templist->next) |
1699 { | |
1700 tempfle = templist->data; | |
1701 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) | |
1702 break; | |
1703 } | |
1704 | |
1705 if (templist == NULL) | |
1706 { | |
1707 tdata->show = 0; | |
1708 tdata->ready = tdata->done = 1; | |
1709 } | |
1710 else | |
1711 tdata->show = tdata->ready = 1; | |
129 | 1712 g_static_mutex_unlock (&tdata->structmutex); |
48 | 1713 } |
1714 | |
1715 | |
1716 static void | |
1717 cancel (GtkWidget * widget, gpointer data) | |
1718 { | |
1719 gftp_transfer * tdata; | |
1720 | |
1721 tdata = data; | |
129 | 1722 g_static_mutex_lock (&tdata->structmutex); |
48 | 1723 tdata->show = 0; |
1724 tdata->done = tdata->ready = 1; | |
129 | 1725 g_static_mutex_unlock (&tdata->structmutex); |
48 | 1726 } |
1727 | |
1728 | |
49 | 1729 #if GTK_MAJOR_VERSION > 1 |
1730 static void | |
1731 transfer_action (GtkWidget * widget, gint response, gpointer user_data) | |
1732 { | |
1733 switch (response) | |
1734 { | |
1735 case GTK_RESPONSE_OK: | |
1736 ok (widget, user_data); | |
1737 gtk_widget_destroy (widget); | |
1738 break; | |
1739 case GTK_RESPONSE_CANCEL: | |
1740 cancel (widget, user_data); | |
1741 /* no break */ | |
1742 default: | |
1743 gtk_widget_destroy (widget); | |
1744 } | |
1745 } | |
1746 #endif | |
1747 | |
1748 | |
1 | 1749 void |
1750 gftp_gtk_ask_transfer (gftp_transfer * tdata) | |
1751 { | |
1752 char *dltitles[4], *add_data[4] = { NULL, NULL, NULL, NULL }, | |
305 | 1753 tempstr[50], temp1str[50], *pos; |
1 | 1754 GtkWidget * tempwid, * scroll, * hbox; |
326 | 1755 int i; |
1756 intptr_t overwrite_default; | |
1 | 1757 gftp_file * tempfle; |
1758 GList * templist; | |
1759 size_t len; | |
1760 | |
1761 dltitles[0] = _("Filename"); | |
305 | 1762 dltitles[1] = tdata->fromreq->hostname; |
1763 dltitles[2] = tdata->toreq->hostname; | |
1 | 1764 dltitles[3] = _("Action"); |
49 | 1765 |
1766 #if GTK_MAJOR_VERSION == 1 | |
1767 dialog = gtk_dialog_new (); | |
1 | 1768 gtk_grab_add (dialog); |
305 | 1769 gtk_window_set_title (GTK_WINDOW (dialog), _("Transfer Files")); |
49 | 1770 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), 5); |
1 | 1771 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 35); |
1772 gtk_box_set_homogeneous (GTK_BOX (GTK_DIALOG (dialog)->action_area), TRUE); | |
49 | 1773 |
1 | 1774 gtk_signal_connect_object (GTK_OBJECT (dialog), "delete_event", |
1775 GTK_SIGNAL_FUNC (gtk_widget_destroy), | |
1776 GTK_OBJECT (dialog)); | |
49 | 1777 #else |
305 | 1778 dialog = gtk_dialog_new_with_buttons (_("Transfer Files"), NULL, 0, |
49 | 1779 GTK_STOCK_OK, |
1780 GTK_RESPONSE_OK, | |
1781 GTK_STOCK_CANCEL, | |
1782 GTK_RESPONSE_CANCEL, | |
1783 NULL); | |
1784 #endif | |
1785 gtk_window_set_wmclass (GTK_WINDOW(dialog), "transfer", "gFTP"); | |
1786 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE); | |
1787 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), 10); | |
1788 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 5); | |
1 | 1789 |
1790 tempwid = gtk_label_new (_("The following file(s) exist on both the local and remote computer\nPlease select what you would like to do")); | |
1791 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), tempwid, FALSE, | |
1792 FALSE, 0); | |
1793 gtk_widget_show (tempwid); | |
1794 | |
1795 scroll = gtk_scrolled_window_new (NULL, NULL); | |
1796 gtk_widget_set_size_request (scroll, 450, 200); | |
1797 | |
1798 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), | |
1799 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
1800 tdata->clist = gtk_clist_new_with_titles (4, dltitles); | |
1801 gtk_container_add (GTK_CONTAINER (scroll), tdata->clist); | |
1802 | |
45 | 1803 #if GTK_MAJOR_VERSION == 1 |
1 | 1804 gtk_clist_set_selection_mode (GTK_CLIST (tdata->clist), |
1805 GTK_SELECTION_EXTENDED); | |
1806 #else | |
1807 gtk_clist_set_selection_mode (GTK_CLIST (tdata->clist), | |
1808 GTK_SELECTION_MULTIPLE); | |
1809 #endif | |
1810 gtk_clist_set_column_width (GTK_CLIST (tdata->clist), 0, 100); | |
1811 gtk_clist_set_column_justification (GTK_CLIST (tdata->clist), 1, | |
1812 GTK_JUSTIFY_RIGHT); | |
1813 gtk_clist_set_column_width (GTK_CLIST (tdata->clist), 1, 85); | |
1814 gtk_clist_set_column_justification (GTK_CLIST (tdata->clist), 2, | |
1815 GTK_JUSTIFY_RIGHT); | |
1816 gtk_clist_set_column_width (GTK_CLIST (tdata->clist), 2, 85); | |
1817 gtk_clist_set_column_width (GTK_CLIST (tdata->clist), 3, 85); | |
1818 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), scroll, TRUE, TRUE, | |
1819 0); | |
1820 gtk_widget_show (tdata->clist); | |
1821 gtk_widget_show (scroll); | |
1822 | |
234 | 1823 gftp_lookup_request_option (tdata->fromreq, "overwrite_default", |
1824 &overwrite_default); | |
129 | 1825 |
1 | 1826 for (templist = tdata->files; templist != NULL; |
1827 templist = templist->next) | |
1828 { | |
1829 tempfle = templist->data; | |
1830 if (tempfle->startsize == 0 || tempfle->isdir) | |
1831 { | |
1832 tempfle->shown = 0; | |
1833 continue; | |
1834 } | |
1835 tempfle->shown = 1; | |
1836 | |
1837 pos = tempfle->destfile; | |
129 | 1838 len = strlen (tdata->toreq->directory); |
1839 if (strncmp (pos, tdata->toreq->directory, len) == 0) | |
1 | 1840 pos = tempfle->destfile + len + 1; |
1841 add_data[0] = pos; | |
1842 | |
234 | 1843 if (overwrite_default) |
319 | 1844 { |
1845 add_data[3] = _("Overwrite"); | |
1846 tempfle->transfer_action = GFTP_TRANS_ACTION_OVERWRITE; | |
1847 } | |
1848 else if (tempfle->startsize == tempfle->size) | |
1849 { | |
1850 add_data[3] = _("Skip"); | |
1851 tempfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
1852 } | |
1853 else if (tempfle->startsize > tempfle->size) | |
1854 { | |
1855 add_data[3] = _("Overwrite"); | |
1856 tempfle->transfer_action = GFTP_TRANS_ACTION_OVERWRITE; | |
1857 } | |
1 | 1858 else |
1859 { | |
319 | 1860 add_data[3] = _("Resume"); |
1861 tempfle->transfer_action = GFTP_TRANS_ACTION_RESUME; | |
1 | 1862 } |
1863 | |
305 | 1864 add_data[1] = insert_commas (tempfle->size, tempstr, sizeof (tempstr)); |
1865 add_data[2] = insert_commas (tempfle->startsize, temp1str, | |
1866 sizeof (temp1str)); | |
1867 | |
1 | 1868 i = gtk_clist_append (GTK_CLIST (tdata->clist), add_data); |
1869 gtk_clist_set_row_data (GTK_CLIST (tdata->clist), i, tempfle); | |
1870 } | |
1871 | |
1872 gtk_clist_select_all (GTK_CLIST (tdata->clist)); | |
1873 | |
1874 hbox = gtk_hbox_new (TRUE, 20); | |
1875 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, TRUE, TRUE, 0); | |
1876 gtk_widget_show (hbox); | |
1877 | |
1878 tempwid = gtk_button_new_with_label (_("Overwrite")); | |
1879 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
1880 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
1881 GTK_SIGNAL_FUNC (overwrite), (gpointer) tdata); | |
1882 gtk_widget_show (tempwid); | |
1883 | |
1884 tempwid = gtk_button_new_with_label (_("Resume")); | |
1885 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
1886 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
1887 GTK_SIGNAL_FUNC (resume), (gpointer) tdata); | |
1888 gtk_widget_show (tempwid); | |
1889 | |
1890 tempwid = gtk_button_new_with_label (_("Skip File")); | |
1891 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
1892 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", GTK_SIGNAL_FUNC (skip), | |
1893 (gpointer) tdata); | |
1894 gtk_widget_show (tempwid); | |
1895 | |
1896 hbox = gtk_hbox_new (TRUE, 20); | |
1897 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, TRUE, TRUE, 0); | |
1898 gtk_widget_show (hbox); | |
1899 | |
1900 tempwid = gtk_button_new_with_label (_("Select All")); | |
1901 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
1902 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
1903 GTK_SIGNAL_FUNC (trans_selectall), (gpointer) tdata); | |
1904 gtk_widget_show (tempwid); | |
1905 | |
1906 tempwid = gtk_button_new_with_label (_("Deselect All")); | |
1907 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
1908 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
1909 GTK_SIGNAL_FUNC (trans_unselectall), (gpointer) tdata); | |
1910 gtk_widget_show (tempwid); | |
1911 | |
49 | 1912 #if GTK_MAJOR_VERSION == 1 |
1 | 1913 tempwid = gtk_button_new_with_label (_("OK")); |
1914 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); | |
1915 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid, | |
1916 TRUE, TRUE, 0); | |
1917 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", GTK_SIGNAL_FUNC (ok), | |
1918 (gpointer) tdata); | |
1919 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked", | |
1920 GTK_SIGNAL_FUNC (gtk_widget_destroy), | |
1921 GTK_OBJECT (dialog)); | |
1922 gtk_widget_grab_default (tempwid); | |
1923 gtk_widget_show (tempwid); | |
1924 | |
1925 tempwid = gtk_button_new_with_label (_(" Cancel ")); | |
1926 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); | |
1927 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid, | |
1928 TRUE, TRUE, 0); | |
1929 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
1930 GTK_SIGNAL_FUNC (cancel), (gpointer) tdata); | |
1931 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked", | |
1932 GTK_SIGNAL_FUNC (gtk_widget_destroy), | |
1933 GTK_OBJECT (dialog)); | |
1934 gtk_widget_show (tempwid); | |
49 | 1935 #else |
1936 g_signal_connect (GTK_OBJECT (dialog), "response", | |
1937 G_CALLBACK (transfer_action), (gpointer) tdata); | |
1938 #endif | |
1 | 1939 |
1940 gtk_widget_show (dialog); | |
1941 dialog = NULL; | |
1942 } | |
1943 |