Mercurial > gftp.yaz
annotate src/gtk/transfer.c @ 463:39d9cf1bf0df
2004-4-14 Brian Masney <masneyb@gftp.org>
* lib/protocols.c lib/rfc959.c src/gtk/transfer.c - AMD64 fixes
author | masneyb |
---|---|
date | Fri, 16 Apr 2004 02:11:22 +0000 |
parents | 77fffba5e170 |
children | a68273d9725a |
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 |
129 | 23 static int num_transfers_in_progress = 0; |
1 | 24 |
48 | 25 int |
26 ftp_list_files (gftp_window_data * wdata, int usecache) | |
27 { | |
355 | 28 gftpui_callback_data * cdata; |
48 | 29 |
30 gtk_label_set (GTK_LABEL (wdata->hoststxt), _("Receiving file names...")); | |
31 | |
355 | 32 cdata = g_malloc0 (sizeof (*cdata)); |
33 cdata->request = wdata->request; | |
34 cdata->uidata = wdata; | |
35 cdata->run_function = gftpui_common_run_ls; | |
48 | 36 |
355 | 37 gftpui_common_run_callback_function (cdata); |
48 | 38 |
355 | 39 wdata->files = cdata->files; |
40 g_free (cdata); | |
48 | 41 |
42 if (wdata->files == NULL || !GFTP_IS_CONNECTED (wdata->request)) | |
43 { | |
380 | 44 gftpui_disconnect (wdata); |
48 | 45 return (0); |
46 } | |
47 | |
48 wdata->sorted = 0; | |
129 | 49 sortrows (GTK_CLIST (wdata->listbox), -1, (gpointer) wdata); |
355 | 50 |
48 | 51 if (IS_NONE_SELECTED (wdata)) |
52 gtk_clist_select_row (GTK_CLIST (wdata->listbox), 0, 0); | |
355 | 53 |
48 | 54 return (1); |
55 } | |
56 | |
57 | |
1 | 58 int |
59 ftp_connect (gftp_window_data * wdata, gftp_request * request, int getdir) | |
60 { | |
61 if (wdata->request == request) | |
367 | 62 gtk_label_set (GTK_LABEL (wdata->hoststxt), _("Connecting...")); |
1 | 63 |
377 | 64 return (gftpui_common_cmd_open (wdata, request, NULL, NULL, NULL)); |
1 | 65 } |
66 | |
67 | |
68 void | |
69 get_files (gpointer data) | |
70 { | |
71 transfer_window_files (&window2, &window1); | |
72 } | |
73 | |
74 | |
75 void | |
76 put_files (gpointer data) | |
77 { | |
78 transfer_window_files (&window1, &window2); | |
79 } | |
80 | |
81 | |
82 void | |
83 transfer_window_files (gftp_window_data * fromwdata, gftp_window_data * towdata) | |
84 { | |
85 gftp_file * tempfle, * newfle; | |
86 GList * templist, * filelist; | |
87 gftp_transfer * transfer; | |
88 guint timeout_num; | |
89 void *ret; | |
90 int num; | |
91 | |
92 if (!check_status (_("Transfer Files"), fromwdata, 1, 0, 1, | |
93 towdata->request->put_file != NULL && fromwdata->request->get_file != NULL)) | |
94 return; | |
95 | |
96 if (!GFTP_IS_CONNECTED (fromwdata->request) || | |
97 !GFTP_IS_CONNECTED (towdata->request)) | |
98 { | |
99 ftp_log (gftp_logging_misc, NULL, | |
100 _("Retrieve Files: Not connected to a remote site\n")); | |
101 return; | |
102 } | |
103 | |
104 if (check_reconnect (fromwdata) < 0 || check_reconnect (towdata) < 0) | |
105 return; | |
106 | |
107 transfer = g_malloc0 (sizeof (*transfer)); | |
368 | 108 transfer->fromreq = gftp_copy_request (fromwdata->request); |
109 transfer->toreq = gftp_copy_request (towdata->request); | |
1 | 110 transfer->fromwdata = fromwdata; |
111 transfer->towdata = towdata; | |
112 | |
113 num = 0; | |
114 templist = GTK_CLIST (fromwdata->listbox)->selection; | |
115 filelist = fromwdata->files; | |
116 while (templist != NULL) | |
117 { | |
118 templist = get_next_selection (templist, &filelist, &num); | |
119 tempfle = filelist->data; | |
120 if (strcmp (tempfle->file, "..") != 0) | |
121 { | |
122 newfle = copy_fdata (tempfle); | |
123 transfer->files = g_list_append (transfer->files, newfle); | |
124 } | |
125 } | |
126 | |
127 if (transfer->files != NULL) | |
128 { | |
63 | 129 gftp_swap_socks (transfer->fromreq, fromwdata->request); |
130 gftp_swap_socks (transfer->toreq, towdata->request); | |
1 | 131 |
341 | 132 if (gftpui_common_use_threads (transfer->fromreq) || |
133 (transfer->toreq && gftpui_common_use_threads (transfer->toreq))) | |
1 | 134 { |
135 transfer->fromreq->stopable = 1; | |
136 pthread_create (&fromwdata->tid, NULL, do_getdir_thread, transfer); | |
137 | |
138 timeout_num = gtk_timeout_add (100, progress_timeout, transfer); | |
139 | |
140 while (transfer->fromreq->stopable) | |
31 | 141 { |
33 | 142 GDK_THREADS_LEAVE (); |
45 | 143 #if GTK_MAJOR_VERSION == 1 |
31 | 144 g_main_iteration (TRUE); |
41 | 145 #else |
146 g_main_context_iteration (NULL, TRUE); | |
147 #endif | |
31 | 148 } |
1 | 149 |
150 gtk_timeout_remove (timeout_num); | |
151 transfer->numfiles = transfer->numdirs = -1; | |
152 update_directory_download_progress (transfer); | |
153 | |
154 pthread_join (fromwdata->tid, &ret); | |
155 } | |
156 else | |
157 ret = do_getdir_thread (transfer); | |
158 | |
159 if (!GFTP_IS_CONNECTED (transfer->fromreq)) | |
160 { | |
380 | 161 gftpui_disconnect (fromwdata); |
1 | 162 return; |
163 } | |
164 | |
165 if (!GFTP_IS_CONNECTED (transfer->toreq)) | |
166 { | |
380 | 167 gftpui_disconnect (towdata); |
1 | 168 return; |
169 } | |
170 | |
63 | 171 gftp_swap_socks (fromwdata->request, transfer->fromreq); |
172 gftp_swap_socks (towdata->request, transfer->toreq); | |
1 | 173 } |
174 | |
175 if (transfer->files != NULL) | |
176 { | |
367 | 177 gftpui_common_add_file_transfer (transfer->fromreq, transfer->toreq, |
178 transfer->fromwdata, transfer->towdata, | |
179 transfer->files); | |
1 | 180 g_free (transfer); |
181 } | |
182 else | |
129 | 183 free_tdata (transfer); |
1 | 184 } |
185 | |
186 void * | |
187 do_getdir_thread (void * data) | |
188 { | |
189 gftp_transfer * transfer; | |
190 int success, sj; | |
191 | |
192 transfer = data; | |
193 | |
341 | 194 if (gftpui_common_use_threads (transfer->fromreq) || |
195 (transfer->toreq && gftpui_common_use_threads (transfer->toreq))) | |
1 | 196 { |
341 | 197 sj = sigsetjmp (gftpui_common_jmp_environment, 1); |
198 gftpui_common_use_jmp_environment = 1; | |
1 | 199 } |
200 else | |
201 sj = 0; | |
202 | |
203 success = 0; | |
204 if (sj == 0) | |
205 success = gftp_get_all_subdirs (transfer, NULL) == 0; | |
206 else | |
207 { | |
208 gftp_disconnect (transfer->fromreq); | |
209 if (transfer->toreq) | |
210 gftp_disconnect (transfer->toreq); | |
211 transfer->fromreq->logging_function (gftp_logging_error, | |
186 | 212 transfer->fromreq, |
1 | 213 _("Operation canceled\n")); |
214 } | |
215 | |
341 | 216 if (gftpui_common_use_threads (transfer->fromreq) || |
217 (transfer->toreq && gftpui_common_use_threads (transfer->toreq))) | |
218 gftpui_common_use_jmp_environment = 0; | |
1 | 219 |
220 transfer->fromreq->stopable = 0; | |
195 | 221 return (GINT_TO_POINTER (success)); |
1 | 222 } |
223 | |
224 | |
305 | 225 static void |
48 | 226 remove_file (char *filename) |
227 { | |
228 if (unlink (filename) == 0) | |
229 ftp_log (gftp_logging_misc, NULL, _("Successfully removed %s\n"), | |
230 filename); | |
231 else | |
232 ftp_log (gftp_logging_error, NULL, | |
233 _("Error: Could not remove file %s: %s\n"), filename, | |
234 g_strerror (errno)); | |
235 } | |
236 | |
237 | |
238 static void | |
239 free_edit_data (gftp_viewedit_data * ve_proc) | |
240 { | |
241 int i; | |
242 | |
294 | 243 if (ve_proc->torequest) |
244 gftp_request_destroy (ve_proc->torequest, 1); | |
48 | 245 if (ve_proc->filename) |
246 g_free (ve_proc->filename); | |
247 if (ve_proc->remote_filename) | |
248 g_free (ve_proc->remote_filename); | |
249 for (i = 0; ve_proc->argv[i] != NULL; i++) | |
250 g_free (ve_proc->argv[i]); | |
251 g_free (ve_proc->argv); | |
252 g_free (ve_proc); | |
253 } | |
254 | |
255 | |
256 static void | |
257 dont_upload (gftp_viewedit_data * ve_proc, gftp_dialog_data * ddata) | |
1 | 258 { |
48 | 259 remove_file (ve_proc->filename); |
260 free_edit_data (ve_proc); | |
261 } | |
262 | |
263 | |
264 static void | |
265 do_upload (gftp_viewedit_data * ve_proc, gftp_dialog_data * ddata) | |
266 { | |
303 | 267 gftp_transfer * tdata; |
48 | 268 gftp_file * tempfle; |
269 GList * newfile; | |
1 | 270 |
48 | 271 tempfle = g_malloc0 (sizeof (*tempfle)); |
294 | 272 tempfle->destfile = gftp_build_path (ve_proc->torequest->directory, |
273 ve_proc->remote_filename, NULL); | |
48 | 274 ve_proc->remote_filename = NULL; |
275 tempfle->file = ve_proc->filename; | |
276 ve_proc->filename = NULL; | |
277 tempfle->done_rm = 1; | |
278 newfile = g_list_append (NULL, tempfle); | |
367 | 279 tdata = gftpui_common_add_file_transfer (ve_proc->fromwdata->request, |
280 ve_proc->torequest, | |
281 ve_proc->fromwdata, | |
282 ve_proc->towdata, newfile); | |
48 | 283 free_edit_data (ve_proc); |
303 | 284 |
285 if (tdata != NULL) | |
286 tdata->conn_error_no_timeout = 1; | |
48 | 287 } |
288 | |
1 | 289 |
48 | 290 static void |
291 check_done_process (void) | |
292 { | |
293 gftp_viewedit_data * ve_proc; | |
294 GList * curdata, *deldata; | |
295 struct stat st; | |
296 int ret; | |
297 char *str; | |
298 pid_t pid; | |
299 | |
300 viewedit_process_done = 0; | |
301 while ((pid = waitpid (-1, &ret, WNOHANG)) > 0) | |
1 | 302 { |
48 | 303 curdata = viewedit_processes; |
304 while (curdata != NULL) | |
305 { | |
306 ve_proc = curdata->data; | |
307 deldata = curdata; | |
308 curdata = curdata->next; | |
309 if (ve_proc->pid == pid) | |
310 { | |
311 viewedit_processes = g_list_remove_link (viewedit_processes, | |
312 deldata); | |
313 if (ret != 0) | |
314 ftp_log (gftp_logging_error, NULL, | |
315 _("Error: Child %d returned %d\n"), pid, ret); | |
316 else | |
317 ftp_log (gftp_logging_misc, NULL, | |
318 _("Child %d returned successfully\n"), pid); | |
319 | |
320 if (!ve_proc->view && !ve_proc->dontupload) | |
321 { | |
322 /* We was editing the file. Upload it */ | |
323 if (stat (ve_proc->filename, &st) == -1) | |
324 ftp_log (gftp_logging_error, NULL, | |
325 _("Error: Cannot get information about file %s: %s\n"), | |
326 ve_proc->filename, g_strerror (errno)); | |
327 else if (st.st_mtime == ve_proc->st.st_mtime) | |
328 { | |
329 ftp_log (gftp_logging_misc, NULL, | |
330 _("File %s was not changed\n"), | |
331 ve_proc->filename); | |
332 remove_file (ve_proc->filename); | |
333 } | |
334 else | |
335 { | |
336 memcpy (&ve_proc->st, &st, sizeof (ve_proc->st)); | |
337 str = g_strdup_printf ( | |
338 _("File %s has changed.\nWould you like to upload it?"), | |
339 ve_proc->remote_filename); | |
340 | |
341 MakeYesNoDialog (_("Edit File"), str, | |
342 do_upload, ve_proc, | |
343 dont_upload, ve_proc); | |
344 g_free (str); | |
345 continue; | |
346 } | |
347 } | |
348 | |
349 free_edit_data (ve_proc); | |
350 continue; | |
351 } | |
1 | 352 } |
353 } | |
354 } | |
355 | |
356 | |
357 static void | |
358 on_next_transfer (gftp_transfer * tdata) | |
359 { | |
326 | 360 int fd; |
361 intptr_t refresh_files; | |
1 | 362 gftp_file * tempfle; |
363 | |
364 tdata->next_file = 0; | |
365 for (; tdata->updfle != tdata->curfle; tdata->updfle = tdata->updfle->next) | |
366 { | |
367 tempfle = tdata->updfle->data; | |
368 | |
369 if (tempfle->is_fd) | |
58 | 370 fd = tempfle->fd; |
1 | 371 else |
372 fd = 0; | |
373 | |
374 if (tempfle->done_view) | |
375 { | |
376 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) | |
377 view_file (tempfle->destfile, fd, 1, tempfle->done_rm, 1, 0, | |
378 tempfle->file, NULL); | |
379 | |
380 if (tempfle->is_fd) | |
381 { | |
58 | 382 close (tempfle->fd); |
383 tempfle->fd = -1; | |
1 | 384 } |
385 } | |
386 else if (tempfle->done_edit) | |
387 { | |
388 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) | |
389 view_file (tempfle->destfile, fd, 0, tempfle->done_rm, 1, 0, | |
390 tempfle->file, NULL); | |
391 | |
392 if (tempfle->is_fd) | |
393 { | |
58 | 394 close (tempfle->fd); |
395 tempfle->fd = -1; | |
1 | 396 } |
397 } | |
398 else if (tempfle->done_rm) | |
399 tdata->fromreq->rmfile (tdata->fromreq, tempfle->file); | |
400 | |
401 if (tempfle->transfer_action == GFTP_TRANS_ACTION_SKIP) | |
129 | 402 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->user_data, 1, |
1 | 403 _("Skipped")); |
404 else | |
129 | 405 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->user_data, 1, |
1 | 406 _("Finished")); |
407 } | |
408 | |
129 | 409 gftp_lookup_request_option (tdata->fromreq, "refresh_files", &refresh_files); |
410 | |
1 | 411 if (refresh_files && tdata->curfle && tdata->curfle->next && |
412 compare_request (tdata->toreq, | |
413 ((gftp_window_data *) tdata->towdata)->request, 1)) | |
341 | 414 gftpui_refresh (tdata->towdata); |
1 | 415 } |
416 | |
417 | |
418 static void | |
19 | 419 get_trans_password (gftp_request * request, gftp_dialog_data * ddata) |
420 { | |
421 gftp_set_password (request, gtk_entry_get_text (GTK_ENTRY (ddata->edit))); | |
422 request->stopable = 0; | |
423 } | |
424 | |
425 | |
426 static void | |
427 cancel_get_trans_password (gftp_transfer * tdata, gftp_dialog_data * ddata) | |
428 { | |
429 if (tdata->fromreq->stopable == 0) | |
430 return; | |
431 | |
129 | 432 g_static_mutex_lock (&tdata->structmutex); |
19 | 433 if (tdata->started) |
42 | 434 { |
435 tdata->cancel = 1; | |
436 tdata->fromreq->cancel = 1; | |
437 tdata->toreq->cancel = 1; | |
438 } | |
19 | 439 else |
440 tdata->done = 1; | |
441 | |
442 tdata->fromreq->stopable = 0; | |
443 tdata->toreq->stopable = 0; | |
129 | 444 g_static_mutex_unlock (&tdata->structmutex); |
40 | 445 |
19 | 446 ftp_log (gftp_logging_misc, NULL, _("Stopping the transfer of %s\n"), |
447 ((gftp_file *) tdata->curfle->data)->file); | |
448 } | |
449 | |
450 | |
451 static void | |
1 | 452 show_transfer (gftp_transfer * tdata) |
453 { | |
454 GdkPixmap * closedir_pixmap, * opendir_pixmap; | |
455 GdkBitmap * closedir_bitmap, * opendir_bitmap; | |
367 | 456 gftpui_common_curtrans_data * transdata; |
1 | 457 gftp_file * tempfle; |
458 GList * templist; | |
397 | 459 char *text[2]; |
1 | 460 |
461 gftp_get_pixmap (dlwdw, "open_dir.xpm", &opendir_pixmap, &opendir_bitmap); | |
462 gftp_get_pixmap (dlwdw, "dir.xpm", &closedir_pixmap, &closedir_bitmap); | |
463 | |
129 | 464 text[0] = tdata->fromreq->hostname; |
1 | 465 text[1] = _("Waiting..."); |
129 | 466 tdata->user_data = gtk_ctree_insert_node (GTK_CTREE (dlwdw), NULL, NULL, |
467 text, 5, | |
1 | 468 closedir_pixmap, closedir_bitmap, |
469 opendir_pixmap, opendir_bitmap, | |
470 FALSE, | |
471 tdata->numdirs + tdata->numfiles < 50); | |
472 transdata = g_malloc (sizeof (*transdata)); | |
473 transdata->transfer = tdata; | |
474 transdata->curfle = NULL; | |
129 | 475 gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), tdata->user_data, transdata); |
1 | 476 tdata->show = 0; |
477 tdata->curfle = tdata->updfle = tdata->files; | |
478 | |
479 tdata->total_bytes = 0; | |
480 for (templist = tdata->files; templist != NULL; templist = templist->next) | |
481 { | |
482 tempfle = templist->data; | |
397 | 483 |
484 text[0] = gftpui_gtk_get_utf8_file_pos (tempfle); | |
1 | 485 if (tempfle->transfer_action == GFTP_TRANS_ACTION_SKIP) |
486 text[1] = _("Skipped"); | |
487 else | |
488 { | |
489 tdata->total_bytes += tempfle->size; | |
490 text[1] = _("Waiting..."); | |
491 } | |
492 | |
129 | 493 tempfle->user_data = gtk_ctree_insert_node (GTK_CTREE (dlwdw), |
494 tdata->user_data, | |
1 | 495 NULL, text, 5, NULL, NULL, NULL, |
496 NULL, FALSE, FALSE); | |
497 transdata = g_malloc (sizeof (*transdata)); | |
498 transdata->transfer = tdata; | |
499 transdata->curfle = templist; | |
129 | 500 gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), tempfle->user_data, |
501 transdata); | |
1 | 502 } |
503 | |
504 if (!tdata->toreq->stopable && tdata->toreq->need_userpass && | |
505 (tdata->toreq->password == NULL || *tdata->toreq->password == '\0')) | |
506 { | |
507 tdata->toreq->stopable = 1; | |
508 MakeEditDialog (_("Enter Password"), | |
509 _("Please enter your password for this site"), NULL, 0, | |
19 | 510 NULL, gftp_dialog_button_connect, |
511 get_trans_password, tdata->toreq, | |
512 cancel_get_trans_password, tdata); | |
1 | 513 } |
514 | |
515 if (!tdata->fromreq->stopable && tdata->fromreq->need_userpass && | |
516 (tdata->fromreq->password == NULL || *tdata->fromreq->password == '\0')) | |
517 { | |
518 tdata->fromreq->stopable = 1; | |
519 MakeEditDialog (_("Enter Password"), | |
520 _("Please enter your password for this site"), NULL, 0, | |
19 | 521 NULL, gftp_dialog_button_connect, |
522 get_trans_password, tdata->fromreq, | |
523 cancel_get_trans_password, tdata); | |
1 | 524 } |
525 } | |
526 | |
527 | |
528 static void | |
529 transfer_done (GList * node) | |
530 { | |
367 | 531 gftpui_common_curtrans_data * transdata; |
1 | 532 gftp_request * fromreq; |
533 gftp_transfer * tdata; | |
534 gftp_file * tempfle; | |
535 GList * templist; | |
536 | |
537 tdata = node->data; | |
538 if (tdata->started) | |
539 { | |
56 | 540 fromreq = tdata->fromwdata != NULL ? ((gftp_window_data *) tdata->fromwdata)->request : NULL; |
297 | 541 |
542 if (GFTP_IS_SAME_HOST_STOP_TRANS ((gftp_window_data *) tdata->fromwdata, | |
543 tdata->fromreq)) | |
309 | 544 { |
545 gftp_copy_param_options (((gftp_window_data *) tdata->fromwdata)->request, tdata->fromreq); | |
546 | |
547 gftp_swap_socks (((gftp_window_data *) tdata->fromwdata)->request, | |
548 tdata->fromreq); | |
549 } | |
1 | 550 else |
297 | 551 gftp_disconnect (tdata->fromreq); |
552 | |
553 if (GFTP_IS_SAME_HOST_STOP_TRANS ((gftp_window_data *) tdata->towdata, | |
554 tdata->toreq)) | |
309 | 555 { |
556 gftp_copy_param_options (((gftp_window_data *) tdata->towdata)->request, tdata->toreq); | |
557 | |
558 gftp_swap_socks (((gftp_window_data *) tdata->towdata)->request, | |
559 tdata->toreq); | |
560 } | |
297 | 561 else |
562 gftp_disconnect (tdata->toreq); | |
1 | 563 |
305 | 564 if (tdata->towdata != NULL && compare_request (tdata->toreq, |
565 ((gftp_window_data *) tdata->towdata)->request, 1)) | |
341 | 566 gftpui_refresh (tdata->towdata); |
305 | 567 |
129 | 568 num_transfers_in_progress--; |
1 | 569 } |
570 | |
2
a171df6764a7
* Fixed crash if you was already transfering a file, and you started another
masneyb
parents:
1
diff
changeset
|
571 if (!tdata->show && tdata->started) |
1 | 572 { |
129 | 573 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), |
574 tdata->user_data); | |
1 | 575 if (transdata != NULL) |
576 g_free (transdata); | |
577 | |
578 for (templist = tdata->files; templist != NULL; templist = templist->next) | |
579 { | |
580 tempfle = templist->data; | |
129 | 581 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), |
582 tempfle->user_data); | |
1 | 583 if (transdata != NULL) |
584 g_free (transdata); | |
585 } | |
586 | |
129 | 587 gtk_ctree_remove_node (GTK_CTREE (dlwdw), tdata->user_data); |
1 | 588 } |
129 | 589 |
367 | 590 g_static_mutex_lock (&gftpui_common_transfer_mutex); |
129 | 591 gftp_file_transfers = g_list_remove_link (gftp_file_transfers, node); |
367 | 592 g_static_mutex_unlock (&gftpui_common_transfer_mutex); |
593 | |
320 | 594 gdk_window_set_title (gtk_widget_get_parent_window (GTK_WIDGET(dlwdw)), |
595 gftp_version); | |
129 | 596 |
1 | 597 free_tdata (tdata); |
598 } | |
599 | |
600 | |
367 | 601 static void * |
602 _gftpui_transfer_files (void *data) | |
603 { | |
604 int ret; | |
605 | |
606 pthread_detach (pthread_self ()); | |
607 ret = gftpui_common_transfer_files (data); | |
608 return (GINT_TO_POINTER(ret)); | |
609 } | |
610 | |
611 | |
1 | 612 static void |
613 create_transfer (gftp_transfer * tdata) | |
614 { | |
615 pthread_t tid; | |
616 | |
617 if (!tdata->fromreq->stopable) | |
618 { | |
297 | 619 if (GFTP_IS_SAME_HOST_START_TRANS ((gftp_window_data *) tdata->fromwdata, |
620 tdata->fromreq)) | |
621 { | |
622 gftp_swap_socks (tdata->fromreq, | |
623 ((gftp_window_data *) tdata->fromwdata)->request); | |
624 update_window (tdata->fromwdata); | |
625 } | |
626 | |
627 if (GFTP_IS_SAME_HOST_START_TRANS ((gftp_window_data *) tdata->towdata, | |
628 tdata->toreq)) | |
629 { | |
63 | 630 gftp_swap_socks (tdata->toreq, |
631 ((gftp_window_data *) tdata->towdata)->request); | |
297 | 632 update_window (tdata->towdata); |
1 | 633 } |
297 | 634 |
129 | 635 num_transfers_in_progress++; |
1 | 636 tdata->started = 1; |
637 tdata->stalled = 1; | |
129 | 638 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->user_data, 1, |
1 | 639 _("Connecting...")); |
367 | 640 pthread_create (&tid, NULL, _gftpui_transfer_files, tdata); |
1 | 641 } |
642 } | |
643 | |
644 | |
645 static void | |
646 update_file_status (gftp_transfer * tdata) | |
647 { | |
320 | 648 char totstr[100], dlstr[100], winstr[150], gotstr[50], ofstr[50]; |
246 | 649 unsigned long remaining_secs, lkbs; |
463 | 650 int hours, mins, secs, pcent, st; |
651 intptr_t show_trans_in_title; | |
1 | 652 gftp_file * tempfle; |
653 struct timeval tv; | |
320 | 654 |
129 | 655 g_static_mutex_lock (&tdata->statmutex); |
1 | 656 tempfle = tdata->curfle->data; |
657 | |
658 gettimeofday (&tv, NULL); | |
220 | 659 |
660 remaining_secs = (tdata->total_bytes - tdata->trans_bytes - tdata->resumed_bytes) / 1024; | |
246 | 661 |
662 lkbs = (unsigned long) tdata->kbs; | |
663 if (lkbs > 0) | |
664 remaining_secs /= lkbs; | |
1 | 665 |
220 | 666 hours = remaining_secs / 3600; |
667 remaining_secs -= hours * 3600; | |
668 mins = remaining_secs / 60; | |
669 remaining_secs -= mins * 60; | |
670 secs = remaining_secs; | |
1 | 671 |
672 if (hours < 0 || mins < 0 || secs < 0) | |
673 { | |
129 | 674 g_static_mutex_unlock (&tdata->statmutex); |
1 | 675 return; |
676 } | |
677 | |
246 | 678 if ((double) tdata->total_bytes > 0) |
679 pcent = (int) ((double) (tdata->trans_bytes + tdata->resumed_bytes) / (double) tdata->total_bytes * 100.0); | |
680 else | |
1 | 681 pcent = 0; |
682 | |
683 g_snprintf (totstr, sizeof (totstr), | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
684 _("%d%% complete, %02d:%02d:%02d est. time remaining. (File %ld of %ld)"), |
1 | 685 pcent, hours, mins, secs, tdata->current_file_number, |
686 tdata->numdirs + tdata->numfiles); | |
687 | |
688 *dlstr = '\0'; | |
689 if (!tdata->stalled) | |
690 { | |
691 insert_commas (tdata->curtrans + tdata->curresumed, gotstr, sizeof (gotstr)); | |
692 insert_commas (tempfle->size, ofstr, sizeof (ofstr)); | |
693 st = 1; | |
694 if (tv.tv_sec - tdata->lasttime.tv_sec <= 5) | |
695 { | |
696 if (tdata->curfle->next != NULL) | |
697 { | |
220 | 698 remaining_secs = (tempfle->size - tdata->curtrans - tdata->curresumed) / 1024; |
246 | 699 |
700 lkbs = (unsigned long) tdata->kbs; | |
701 if (lkbs > 0) | |
702 remaining_secs /= lkbs; | |
220 | 703 |
704 hours = remaining_secs / 3600; | |
705 remaining_secs -= hours * 3600; | |
706 mins = remaining_secs / 60; | |
707 remaining_secs -= mins * 60; | |
708 secs = remaining_secs; | |
1 | 709 } |
710 | |
711 if (!(hours < 0 || mins < 0 || secs < 0)) | |
712 { | |
713 g_snprintf (dlstr, sizeof (dlstr), | |
714 _("Recv %s of %s at %.2fKB/s, %02d:%02d:%02d est. time remaining"), gotstr, ofstr, tdata->kbs, hours, mins, secs); | |
715 st = 0; | |
716 } | |
717 } | |
718 | |
719 if (st) | |
720 { | |
721 tdata->stalled = 1; | |
722 g_snprintf (dlstr, sizeof (dlstr), | |
723 _("Recv %s of %s, transfer stalled, unknown time remaining"), | |
724 gotstr, ofstr); | |
725 } | |
726 } | |
727 | |
129 | 728 g_static_mutex_unlock (&tdata->statmutex); |
1 | 729 |
129 | 730 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->user_data, 1, totstr); |
320 | 731 |
732 gftp_lookup_global_option ("show_trans_in_title", &show_trans_in_title); | |
733 if (gftp_file_transfers->data == tdata && show_trans_in_title) | |
734 { | |
735 g_snprintf (winstr, sizeof(winstr), "%s: %s", gftp_version, totstr); | |
736 gdk_window_set_title (gtk_widget_get_parent_window (GTK_WIDGET(dlwdw)), | |
737 winstr); | |
738 } | |
1 | 739 |
740 if (*dlstr != '\0') | |
129 | 741 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->user_data, 1, dlstr); |
1 | 742 } |
743 | |
377 | 744 |
56 | 745 static void |
746 update_window_transfer_bytes (gftp_window_data * wdata) | |
747 { | |
748 char *tempstr, *temp1str; | |
749 | |
750 if (wdata->request->gotbytes == -1) | |
751 { | |
752 update_window_info (); | |
753 wdata->request->gotbytes = 0; | |
754 } | |
755 else | |
756 { | |
757 tempstr = insert_commas (wdata->request->gotbytes, NULL, 0); | |
758 temp1str = g_strdup_printf (_("Retrieving file names...%s bytes"), | |
759 tempstr); | |
760 gtk_label_set (GTK_LABEL (wdata->hoststxt), temp1str); | |
761 g_free (tempstr); | |
762 g_free (temp1str); | |
763 } | |
764 } | |
765 | |
1 | 766 |
48 | 767 gint |
768 update_downloads (gpointer data) | |
769 { | |
433 | 770 intptr_t do_one_transfer_at_a_time, start_transfers; |
48 | 771 GList * templist, * next; |
772 gftp_transfer * tdata; | |
773 | |
129 | 774 if (gftp_file_transfer_logs != NULL) |
48 | 775 display_cached_logs (); |
776 | |
56 | 777 if (window1.request->gotbytes != 0) |
778 update_window_transfer_bytes (&window1); | |
48 | 779 if (window2.request->gotbytes != 0) |
56 | 780 update_window_transfer_bytes (&window2); |
48 | 781 |
782 if (viewedit_process_done) | |
783 check_done_process (); | |
784 | |
129 | 785 for (templist = gftp_file_transfers; templist != NULL;) |
48 | 786 { |
787 tdata = templist->data; | |
788 if (tdata->ready) | |
789 { | |
129 | 790 g_static_mutex_lock (&tdata->structmutex); |
48 | 791 |
792 if (tdata->next_file) | |
793 on_next_transfer (tdata); | |
794 else if (tdata->show) | |
795 show_transfer (tdata); | |
796 else if (tdata->done) | |
797 { | |
798 next = templist->next; | |
129 | 799 g_static_mutex_unlock (&tdata->structmutex); |
48 | 800 transfer_done (templist); |
801 templist = next; | |
802 continue; | |
803 } | |
804 | |
805 if (tdata->curfle != NULL) | |
806 { | |
151 | 807 gftp_lookup_global_option ("one_transfer", |
129 | 808 &do_one_transfer_at_a_time); |
433 | 809 gftp_lookup_global_option ("start_transfers", &start_transfers); |
129 | 810 |
433 | 811 if (!tdata->started && start_transfers && |
129 | 812 (num_transfers_in_progress == 0 || !do_one_transfer_at_a_time)) |
48 | 813 create_transfer (tdata); |
814 | |
815 if (tdata->started) | |
816 update_file_status (tdata); | |
817 } | |
129 | 818 g_static_mutex_unlock (&tdata->structmutex); |
48 | 819 } |
820 templist = templist->next; | |
821 } | |
822 | |
823 gtk_timeout_add (500, update_downloads, NULL); | |
824 return (0); | |
825 } | |
826 | |
827 | |
1 | 828 void |
829 start_transfer (gpointer data) | |
830 { | |
367 | 831 gftpui_common_curtrans_data * transdata; |
1 | 832 GtkCTreeNode * node; |
833 | |
834 if (GTK_CLIST (dlwdw)->selection == NULL) | |
835 { | |
836 ftp_log (gftp_logging_misc, NULL, | |
837 _("There are no file transfers selected\n")); | |
838 return; | |
839 } | |
840 node = GTK_CLIST (dlwdw)->selection->data; | |
841 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
842 | |
129 | 843 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 844 if (!transdata->transfer->started) |
845 create_transfer (transdata->transfer); | |
129 | 846 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 847 } |
848 | |
849 | |
850 void | |
851 stop_transfer (gpointer data) | |
852 { | |
367 | 853 gftpui_common_curtrans_data * transdata; |
1 | 854 GtkCTreeNode * node; |
855 | |
856 if (GTK_CLIST (dlwdw)->selection == NULL) | |
857 { | |
858 ftp_log (gftp_logging_misc, NULL, | |
859 _("There are no file transfers selected\n")); | |
860 return; | |
861 } | |
862 node = GTK_CLIST (dlwdw)->selection->data; | |
863 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
864 | |
129 | 865 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 866 if (transdata->transfer->started) |
867 { | |
868 transdata->transfer->cancel = 1; | |
42 | 869 transdata->transfer->fromreq->cancel = 1; |
870 transdata->transfer->toreq->cancel = 1; | |
1 | 871 transdata->transfer->skip_file = 0; |
872 } | |
873 else | |
874 transdata->transfer->done = 1; | |
129 | 875 g_static_mutex_unlock (&transdata->transfer->structmutex); |
40 | 876 |
1 | 877 ftp_log (gftp_logging_misc, NULL, _("Stopping the transfer on host %s\n"), |
878 transdata->transfer->fromreq->hostname); | |
879 } | |
880 | |
881 | |
882 void | |
883 skip_transfer (gpointer data) | |
884 { | |
367 | 885 gftpui_common_curtrans_data * transdata; |
1 | 886 GtkCTreeNode * node; |
887 gftp_file * curfle; | |
40 | 888 char *file; |
1 | 889 |
890 if (GTK_CLIST (dlwdw)->selection == NULL) | |
891 { | |
892 ftp_log (gftp_logging_misc, NULL, | |
893 _("There are no file transfers selected\n")); | |
894 return; | |
895 } | |
896 node = GTK_CLIST (dlwdw)->selection->data; | |
897 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
898 | |
129 | 899 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 900 if (transdata->transfer->curfle != NULL) |
901 { | |
902 curfle = transdata->transfer->curfle->data; | |
903 if (transdata->transfer->started) | |
904 { | |
905 transdata->transfer->cancel = 1; | |
42 | 906 transdata->transfer->fromreq->cancel = 1; |
907 transdata->transfer->toreq->cancel = 1; | |
1 | 908 transdata->transfer->skip_file = 1; |
909 } | |
910 | |
911 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
40 | 912 file = curfle->file; |
1 | 913 } |
40 | 914 else |
915 file = NULL; | |
129 | 916 g_static_mutex_unlock (&transdata->transfer->structmutex); |
40 | 917 |
918 ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"), | |
919 file, transdata->transfer->fromreq->hostname); | |
1 | 920 } |
921 | |
922 | |
923 void | |
924 remove_file_transfer (gpointer data) | |
925 { | |
367 | 926 gftpui_common_curtrans_data * transdata; |
1 | 927 GtkCTreeNode * node; |
928 gftp_file * curfle; | |
929 | |
930 if (GTK_CLIST (dlwdw)->selection == NULL) | |
931 { | |
932 ftp_log (gftp_logging_misc, NULL, | |
933 _("There are no file transfers selected\n")); | |
934 return; | |
935 } | |
936 | |
937 node = GTK_CLIST (dlwdw)->selection->data; | |
938 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
939 | |
940 | |
941 if (transdata->curfle == NULL || transdata->curfle->data == NULL) | |
942 return; | |
943 | |
944 curfle = transdata->curfle->data; | |
945 | |
946 if (curfle->transfer_action & GFTP_TRANS_ACTION_SKIP) | |
947 return; | |
948 | |
129 | 949 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 950 |
951 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
952 | |
953 if (transdata->transfer->started && | |
954 transdata->curfle == transdata->transfer->curfle) | |
955 { | |
956 transdata->transfer->cancel = 1; | |
42 | 957 transdata->transfer->fromreq->cancel = 1; |
958 transdata->transfer->toreq->cancel = 1; | |
1 | 959 transdata->transfer->skip_file = 1; |
960 } | |
961 else if (transdata->curfle != transdata->transfer->curfle && | |
962 !curfle->transfer_done) | |
963 { | |
129 | 964 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), curfle->user_data, 1, |
1 | 965 _("Skipped")); |
966 transdata->transfer->total_bytes -= curfle->size; | |
967 } | |
968 | |
129 | 969 g_static_mutex_unlock (&transdata->transfer->structmutex); |
40 | 970 |
1 | 971 ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"), |
972 curfle->file, transdata->transfer->fromreq->hostname); | |
973 } | |
974 | |
975 | |
976 void | |
977 move_transfer_up (gpointer data) | |
978 { | |
979 GList * firstentry, * secentry, * lastentry; | |
367 | 980 gftpui_common_curtrans_data * transdata; |
1 | 981 GtkCTreeNode * node; |
982 | |
983 if (GTK_CLIST (dlwdw)->selection == NULL) | |
984 { | |
985 ftp_log (gftp_logging_misc, NULL, | |
986 _("There are no file transfers selected\n")); | |
987 return; | |
988 } | |
989 node = GTK_CLIST (dlwdw)->selection->data; | |
990 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
991 | |
992 if (transdata->curfle == NULL) | |
993 return; | |
994 | |
129 | 995 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 996 if (transdata->curfle->prev != NULL && (!transdata->transfer->started || |
997 (transdata->transfer->curfle != transdata->curfle && | |
998 transdata->transfer->curfle != transdata->curfle->prev))) | |
999 { | |
1000 if (transdata->curfle->prev->prev == NULL) | |
1001 { | |
1002 firstentry = transdata->curfle->prev; | |
1003 lastentry = transdata->curfle->next; | |
1004 transdata->transfer->files = transdata->curfle; | |
1005 transdata->curfle->next = firstentry; | |
1006 transdata->transfer->files->prev = NULL; | |
1007 firstentry->prev = transdata->curfle; | |
1008 firstentry->next = lastentry; | |
1009 if (lastentry != NULL) | |
1010 lastentry->prev = firstentry; | |
1011 } | |
1012 else | |
1013 { | |
1014 firstentry = transdata->curfle->prev->prev; | |
1015 secentry = transdata->curfle->prev; | |
1016 lastentry = transdata->curfle->next; | |
1017 firstentry->next = transdata->curfle; | |
1018 transdata->curfle->prev = firstentry; | |
1019 transdata->curfle->next = secentry; | |
1020 secentry->prev = transdata->curfle; | |
1021 secentry->next = lastentry; | |
1022 if (lastentry != NULL) | |
1023 lastentry->prev = secentry; | |
1024 } | |
1025 | |
1026 gtk_ctree_move (GTK_CTREE (dlwdw), | |
129 | 1027 ((gftp_file *) transdata->curfle->data)->user_data, |
1028 transdata->transfer->user_data, | |
1 | 1029 transdata->curfle->next != NULL ? |
129 | 1030 ((gftp_file *) transdata->curfle->next->data)->user_data: NULL); |
1 | 1031 } |
129 | 1032 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 1033 } |
1034 | |
367 | 1035 |
1 | 1036 void |
1037 move_transfer_down (gpointer data) | |
1038 { | |
1039 GList * firstentry, * secentry, * lastentry; | |
367 | 1040 gftpui_common_curtrans_data * transdata; |
1 | 1041 GtkCTreeNode * node; |
1042 | |
1043 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1044 { | |
1045 ftp_log (gftp_logging_misc, NULL, | |
1046 _("There are no file transfers selected\n")); | |
1047 return; | |
1048 } | |
1049 node = GTK_CLIST (dlwdw)->selection->data; | |
1050 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1051 | |
1052 if (transdata->curfle == NULL) | |
1053 return; | |
1054 | |
129 | 1055 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 1056 if (transdata->curfle->next != NULL && (!transdata->transfer->started || |
1057 (transdata->transfer->curfle != transdata->curfle && | |
1058 transdata->transfer->curfle != transdata->curfle->next))) | |
1059 { | |
1060 if (transdata->curfle->prev == NULL) | |
1061 { | |
1062 firstentry = transdata->curfle->next; | |
1063 lastentry = transdata->curfle->next->next; | |
1064 transdata->transfer->files = firstentry; | |
1065 transdata->transfer->files->prev = NULL; | |
1066 transdata->transfer->files->next = transdata->curfle; | |
1067 transdata->curfle->prev = transdata->transfer->files; | |
1068 transdata->curfle->next = lastentry; | |
1069 if (lastentry != NULL) | |
1070 lastentry->prev = transdata->curfle; | |
1071 } | |
1072 else | |
1073 { | |
1074 firstentry = transdata->curfle->prev; | |
1075 secentry = transdata->curfle->next; | |
1076 lastentry = transdata->curfle->next->next; | |
1077 firstentry->next = secentry; | |
1078 secentry->prev = firstentry; | |
1079 secentry->next = transdata->curfle; | |
1080 transdata->curfle->prev = secentry; | |
1081 transdata->curfle->next = lastentry; | |
1082 if (lastentry != NULL) | |
1083 lastentry->prev = transdata->curfle; | |
1084 } | |
1085 | |
1086 gtk_ctree_move (GTK_CTREE (dlwdw), | |
129 | 1087 ((gftp_file *) transdata->curfle->data)->user_data, |
1088 transdata->transfer->user_data, | |
1 | 1089 transdata->curfle->next != NULL ? |
129 | 1090 ((gftp_file *) transdata->curfle->next->data)->user_data: NULL); |
1 | 1091 } |
129 | 1092 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 1093 } |
1094 |