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