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