Mercurial > gftp.yaz
annotate src/gtk/transfer.c @ 368:af541d789f4c
2003-1-18 Brian Masney <masneyb@gftp.org>
* lib/gftp.h lib/misc.c src/gtk/delete_dialog.c src/gtk/transfer.c
src/gtk/view_dialog.c src/uicommon/gftpui.c - renamed all instances of
copy_request() to gftp_copy_request(). Removed second argument
(copy_local_options), the options are always copied now.
author | masneyb |
---|---|
date | Sun, 18 Jan 2004 20:18:19 +0000 |
parents | d5409bf03ff1 |
children | 14da115b149b |
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 { | |
44 disconnect (wdata); | |
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 |
367 | 64 return (gftpui_common_cmd_open (wdata, request, 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 { | |
161 disconnect (fromwdata); | |
162 return; | |
163 } | |
164 | |
165 if (!GFTP_IS_CONNECTED (transfer->toreq)) | |
166 { | |
167 disconnect (towdata); | |
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 char *pos, *text[2]; | |
459 GList * templist; | |
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; | |
483 if ((pos = strrchr (tempfle->file, '/')) == NULL) | |
484 pos = tempfle->file; | |
485 else | |
486 pos++; | |
487 text[0] = pos; | |
488 if (tempfle->transfer_action == GFTP_TRANS_ACTION_SKIP) | |
489 text[1] = _("Skipped"); | |
490 else | |
491 { | |
492 tdata->total_bytes += tempfle->size; | |
493 text[1] = _("Waiting..."); | |
494 } | |
495 | |
129 | 496 tempfle->user_data = gtk_ctree_insert_node (GTK_CTREE (dlwdw), |
497 tdata->user_data, | |
1 | 498 NULL, text, 5, NULL, NULL, NULL, |
499 NULL, FALSE, FALSE); | |
500 transdata = g_malloc (sizeof (*transdata)); | |
501 transdata->transfer = tdata; | |
502 transdata->curfle = templist; | |
129 | 503 gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), tempfle->user_data, |
504 transdata); | |
1 | 505 } |
506 | |
507 if (!tdata->toreq->stopable && tdata->toreq->need_userpass && | |
508 (tdata->toreq->password == NULL || *tdata->toreq->password == '\0')) | |
509 { | |
510 tdata->toreq->stopable = 1; | |
511 MakeEditDialog (_("Enter Password"), | |
512 _("Please enter your password for this site"), NULL, 0, | |
19 | 513 NULL, gftp_dialog_button_connect, |
514 get_trans_password, tdata->toreq, | |
515 cancel_get_trans_password, tdata); | |
1 | 516 } |
517 | |
518 if (!tdata->fromreq->stopable && tdata->fromreq->need_userpass && | |
519 (tdata->fromreq->password == NULL || *tdata->fromreq->password == '\0')) | |
520 { | |
521 tdata->fromreq->stopable = 1; | |
522 MakeEditDialog (_("Enter Password"), | |
523 _("Please enter your password for this site"), NULL, 0, | |
19 | 524 NULL, gftp_dialog_button_connect, |
525 get_trans_password, tdata->fromreq, | |
526 cancel_get_trans_password, tdata); | |
1 | 527 } |
528 } | |
529 | |
530 | |
531 static void | |
532 transfer_done (GList * node) | |
533 { | |
367 | 534 gftpui_common_curtrans_data * transdata; |
1 | 535 gftp_request * fromreq; |
536 gftp_transfer * tdata; | |
537 gftp_file * tempfle; | |
538 GList * templist; | |
539 | |
540 tdata = node->data; | |
541 if (tdata->started) | |
542 { | |
56 | 543 fromreq = tdata->fromwdata != NULL ? ((gftp_window_data *) tdata->fromwdata)->request : NULL; |
297 | 544 |
545 if (GFTP_IS_SAME_HOST_STOP_TRANS ((gftp_window_data *) tdata->fromwdata, | |
546 tdata->fromreq)) | |
309 | 547 { |
548 gftp_copy_param_options (((gftp_window_data *) tdata->fromwdata)->request, tdata->fromreq); | |
549 | |
550 gftp_swap_socks (((gftp_window_data *) tdata->fromwdata)->request, | |
551 tdata->fromreq); | |
552 } | |
1 | 553 else |
297 | 554 gftp_disconnect (tdata->fromreq); |
555 | |
556 if (GFTP_IS_SAME_HOST_STOP_TRANS ((gftp_window_data *) tdata->towdata, | |
557 tdata->toreq)) | |
309 | 558 { |
559 gftp_copy_param_options (((gftp_window_data *) tdata->towdata)->request, tdata->toreq); | |
560 | |
561 gftp_swap_socks (((gftp_window_data *) tdata->towdata)->request, | |
562 tdata->toreq); | |
563 } | |
297 | 564 else |
565 gftp_disconnect (tdata->toreq); | |
1 | 566 |
305 | 567 if (tdata->towdata != NULL && compare_request (tdata->toreq, |
568 ((gftp_window_data *) tdata->towdata)->request, 1)) | |
341 | 569 gftpui_refresh (tdata->towdata); |
305 | 570 |
129 | 571 num_transfers_in_progress--; |
1 | 572 } |
573 | |
2
a171df6764a7
* Fixed crash if you was already transfering a file, and you started another
masneyb
parents:
1
diff
changeset
|
574 if (!tdata->show && tdata->started) |
1 | 575 { |
129 | 576 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), |
577 tdata->user_data); | |
1 | 578 if (transdata != NULL) |
579 g_free (transdata); | |
580 | |
581 for (templist = tdata->files; templist != NULL; templist = templist->next) | |
582 { | |
583 tempfle = templist->data; | |
129 | 584 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), |
585 tempfle->user_data); | |
1 | 586 if (transdata != NULL) |
587 g_free (transdata); | |
588 } | |
589 | |
129 | 590 gtk_ctree_remove_node (GTK_CTREE (dlwdw), tdata->user_data); |
1 | 591 } |
129 | 592 |
367 | 593 g_static_mutex_lock (&gftpui_common_transfer_mutex); |
129 | 594 gftp_file_transfers = g_list_remove_link (gftp_file_transfers, node); |
367 | 595 g_static_mutex_unlock (&gftpui_common_transfer_mutex); |
596 | |
320 | 597 gdk_window_set_title (gtk_widget_get_parent_window (GTK_WIDGET(dlwdw)), |
598 gftp_version); | |
129 | 599 |
1 | 600 free_tdata (tdata); |
601 } | |
602 | |
603 | |
367 | 604 static void * |
605 _gftpui_transfer_files (void *data) | |
606 { | |
607 int ret; | |
608 | |
609 pthread_detach (pthread_self ()); | |
610 ret = gftpui_common_transfer_files (data); | |
611 return (GINT_TO_POINTER(ret)); | |
612 } | |
613 | |
614 | |
1 | 615 static void |
616 create_transfer (gftp_transfer * tdata) | |
617 { | |
618 pthread_t tid; | |
619 | |
620 if (!tdata->fromreq->stopable) | |
621 { | |
297 | 622 if (GFTP_IS_SAME_HOST_START_TRANS ((gftp_window_data *) tdata->fromwdata, |
623 tdata->fromreq)) | |
624 { | |
625 gftp_swap_socks (tdata->fromreq, | |
626 ((gftp_window_data *) tdata->fromwdata)->request); | |
627 update_window (tdata->fromwdata); | |
628 } | |
629 | |
630 if (GFTP_IS_SAME_HOST_START_TRANS ((gftp_window_data *) tdata->towdata, | |
631 tdata->toreq)) | |
632 { | |
63 | 633 gftp_swap_socks (tdata->toreq, |
634 ((gftp_window_data *) tdata->towdata)->request); | |
297 | 635 update_window (tdata->towdata); |
1 | 636 } |
297 | 637 |
129 | 638 num_transfers_in_progress++; |
1 | 639 tdata->started = 1; |
640 tdata->stalled = 1; | |
129 | 641 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->user_data, 1, |
1 | 642 _("Connecting...")); |
367 | 643 pthread_create (&tid, NULL, _gftpui_transfer_files, tdata); |
1 | 644 } |
645 } | |
646 | |
647 | |
648 static void | |
649 update_file_status (gftp_transfer * tdata) | |
650 { | |
320 | 651 char totstr[100], dlstr[100], winstr[150], gotstr[50], ofstr[50]; |
652 int hours, mins, secs, pcent, st, show_trans_in_title; | |
246 | 653 unsigned long remaining_secs, lkbs; |
1 | 654 gftp_file * tempfle; |
655 struct timeval tv; | |
320 | 656 |
129 | 657 g_static_mutex_lock (&tdata->statmutex); |
1 | 658 tempfle = tdata->curfle->data; |
659 | |
660 gettimeofday (&tv, NULL); | |
220 | 661 |
662 remaining_secs = (tdata->total_bytes - tdata->trans_bytes - tdata->resumed_bytes) / 1024; | |
246 | 663 |
664 lkbs = (unsigned long) tdata->kbs; | |
665 if (lkbs > 0) | |
666 remaining_secs /= lkbs; | |
1 | 667 |
220 | 668 hours = remaining_secs / 3600; |
669 remaining_secs -= hours * 3600; | |
670 mins = remaining_secs / 60; | |
671 remaining_secs -= mins * 60; | |
672 secs = remaining_secs; | |
1 | 673 |
674 if (hours < 0 || mins < 0 || secs < 0) | |
675 { | |
129 | 676 g_static_mutex_unlock (&tdata->statmutex); |
1 | 677 return; |
678 } | |
679 | |
246 | 680 if ((double) tdata->total_bytes > 0) |
681 pcent = (int) ((double) (tdata->trans_bytes + tdata->resumed_bytes) / (double) tdata->total_bytes * 100.0); | |
682 else | |
1 | 683 pcent = 0; |
684 | |
685 g_snprintf (totstr, sizeof (totstr), | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
686 _("%d%% complete, %02d:%02d:%02d est. time remaining. (File %ld of %ld)"), |
1 | 687 pcent, hours, mins, secs, tdata->current_file_number, |
688 tdata->numdirs + tdata->numfiles); | |
689 | |
690 *dlstr = '\0'; | |
691 if (!tdata->stalled) | |
692 { | |
693 insert_commas (tdata->curtrans + tdata->curresumed, gotstr, sizeof (gotstr)); | |
694 insert_commas (tempfle->size, ofstr, sizeof (ofstr)); | |
695 st = 1; | |
696 if (tv.tv_sec - tdata->lasttime.tv_sec <= 5) | |
697 { | |
698 if (tdata->curfle->next != NULL) | |
699 { | |
220 | 700 remaining_secs = (tempfle->size - tdata->curtrans - tdata->curresumed) / 1024; |
246 | 701 |
702 lkbs = (unsigned long) tdata->kbs; | |
703 if (lkbs > 0) | |
704 remaining_secs /= lkbs; | |
220 | 705 |
706 hours = remaining_secs / 3600; | |
707 remaining_secs -= hours * 3600; | |
708 mins = remaining_secs / 60; | |
709 remaining_secs -= mins * 60; | |
710 secs = remaining_secs; | |
1 | 711 } |
712 | |
713 if (!(hours < 0 || mins < 0 || secs < 0)) | |
714 { | |
715 g_snprintf (dlstr, sizeof (dlstr), | |
716 _("Recv %s of %s at %.2fKB/s, %02d:%02d:%02d est. time remaining"), gotstr, ofstr, tdata->kbs, hours, mins, secs); | |
717 st = 0; | |
718 } | |
719 } | |
720 | |
721 if (st) | |
722 { | |
723 tdata->stalled = 1; | |
724 g_snprintf (dlstr, sizeof (dlstr), | |
725 _("Recv %s of %s, transfer stalled, unknown time remaining"), | |
726 gotstr, ofstr); | |
727 } | |
728 } | |
729 | |
129 | 730 g_static_mutex_unlock (&tdata->statmutex); |
1 | 731 |
129 | 732 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->user_data, 1, totstr); |
320 | 733 |
734 gftp_lookup_global_option ("show_trans_in_title", &show_trans_in_title); | |
735 if (gftp_file_transfers->data == tdata && show_trans_in_title) | |
736 { | |
737 g_snprintf (winstr, sizeof(winstr), "%s: %s", gftp_version, totstr); | |
738 gdk_window_set_title (gtk_widget_get_parent_window (GTK_WIDGET(dlwdw)), | |
739 winstr); | |
740 } | |
1 | 741 |
742 if (*dlstr != '\0') | |
129 | 743 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->user_data, 1, dlstr); |
1 | 744 } |
745 | |
56 | 746 static void |
747 update_window_transfer_bytes (gftp_window_data * wdata) | |
748 { | |
749 char *tempstr, *temp1str; | |
750 | |
751 if (wdata->request->gotbytes == -1) | |
752 { | |
753 update_window_info (); | |
754 wdata->request->gotbytes = 0; | |
755 } | |
756 else | |
757 { | |
758 tempstr = insert_commas (wdata->request->gotbytes, NULL, 0); | |
759 temp1str = g_strdup_printf (_("Retrieving file names...%s bytes"), | |
760 tempstr); | |
761 gtk_label_set (GTK_LABEL (wdata->hoststxt), temp1str); | |
762 g_free (tempstr); | |
763 g_free (temp1str); | |
764 } | |
765 } | |
766 | |
1 | 767 |
48 | 768 gint |
769 update_downloads (gpointer data) | |
770 { | |
326 | 771 intptr_t do_one_transfer_at_a_time; |
48 | 772 GList * templist, * next; |
773 gftp_transfer * tdata; | |
774 | |
129 | 775 if (gftp_file_transfer_logs != NULL) |
48 | 776 display_cached_logs (); |
777 | |
56 | 778 if (window1.request->gotbytes != 0) |
779 update_window_transfer_bytes (&window1); | |
48 | 780 if (window2.request->gotbytes != 0) |
56 | 781 update_window_transfer_bytes (&window2); |
48 | 782 |
783 if (viewedit_process_done) | |
784 check_done_process (); | |
785 | |
129 | 786 for (templist = gftp_file_transfers; templist != NULL;) |
48 | 787 { |
788 tdata = templist->data; | |
789 if (tdata->ready) | |
790 { | |
129 | 791 g_static_mutex_lock (&tdata->structmutex); |
48 | 792 |
793 if (tdata->next_file) | |
794 on_next_transfer (tdata); | |
795 else if (tdata->show) | |
796 show_transfer (tdata); | |
797 else if (tdata->done) | |
798 { | |
799 next = templist->next; | |
129 | 800 g_static_mutex_unlock (&tdata->structmutex); |
48 | 801 transfer_done (templist); |
802 templist = next; | |
803 continue; | |
804 } | |
805 | |
806 if (tdata->curfle != NULL) | |
807 { | |
151 | 808 gftp_lookup_global_option ("one_transfer", |
129 | 809 &do_one_transfer_at_a_time); |
810 | |
207 | 811 if (!tdata->started && |
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 |