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