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