Mercurial > gftp.yaz
annotate src/gtk/transfer.c @ 433:77fffba5e170
2004-3-17 Brian Masney <masneyb@gftp.org>
* lib/options.h src/gtk/transfer.c - added start file transfers option
author | masneyb |
---|---|
date | Wed, 17 Mar 2004 20:42:53 +0000 |
parents | 14ef37b62c20 |
children | 39d9cf1bf0df |
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]; |
649 int hours, mins, secs, pcent, st, show_trans_in_title; | |
246 | 650 unsigned long remaining_secs, lkbs; |
1 | 651 gftp_file * tempfle; |
652 struct timeval tv; | |
320 | 653 |
129 | 654 g_static_mutex_lock (&tdata->statmutex); |
1 | 655 tempfle = tdata->curfle->data; |
656 | |
657 gettimeofday (&tv, NULL); | |
220 | 658 |
659 remaining_secs = (tdata->total_bytes - tdata->trans_bytes - tdata->resumed_bytes) / 1024; | |
246 | 660 |
661 lkbs = (unsigned long) tdata->kbs; | |
662 if (lkbs > 0) | |
663 remaining_secs /= lkbs; | |
1 | 664 |
220 | 665 hours = remaining_secs / 3600; |
666 remaining_secs -= hours * 3600; | |
667 mins = remaining_secs / 60; | |
668 remaining_secs -= mins * 60; | |
669 secs = remaining_secs; | |
1 | 670 |
671 if (hours < 0 || mins < 0 || secs < 0) | |
672 { | |
129 | 673 g_static_mutex_unlock (&tdata->statmutex); |
1 | 674 return; |
675 } | |
676 | |
246 | 677 if ((double) tdata->total_bytes > 0) |
678 pcent = (int) ((double) (tdata->trans_bytes + tdata->resumed_bytes) / (double) tdata->total_bytes * 100.0); | |
679 else | |
1 | 680 pcent = 0; |
681 | |
682 g_snprintf (totstr, sizeof (totstr), | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
683 _("%d%% complete, %02d:%02d:%02d est. time remaining. (File %ld of %ld)"), |
1 | 684 pcent, hours, mins, secs, tdata->current_file_number, |
685 tdata->numdirs + tdata->numfiles); | |
686 | |
687 *dlstr = '\0'; | |
688 if (!tdata->stalled) | |
689 { | |
690 insert_commas (tdata->curtrans + tdata->curresumed, gotstr, sizeof (gotstr)); | |
691 insert_commas (tempfle->size, ofstr, sizeof (ofstr)); | |
692 st = 1; | |
693 if (tv.tv_sec - tdata->lasttime.tv_sec <= 5) | |
694 { | |
695 if (tdata->curfle->next != NULL) | |
696 { | |
220 | 697 remaining_secs = (tempfle->size - tdata->curtrans - tdata->curresumed) / 1024; |
246 | 698 |
699 lkbs = (unsigned long) tdata->kbs; | |
700 if (lkbs > 0) | |
701 remaining_secs /= lkbs; | |
220 | 702 |
703 hours = remaining_secs / 3600; | |
704 remaining_secs -= hours * 3600; | |
705 mins = remaining_secs / 60; | |
706 remaining_secs -= mins * 60; | |
707 secs = remaining_secs; | |
1 | 708 } |
709 | |
710 if (!(hours < 0 || mins < 0 || secs < 0)) | |
711 { | |
712 g_snprintf (dlstr, sizeof (dlstr), | |
713 _("Recv %s of %s at %.2fKB/s, %02d:%02d:%02d est. time remaining"), gotstr, ofstr, tdata->kbs, hours, mins, secs); | |
714 st = 0; | |
715 } | |
716 } | |
717 | |
718 if (st) | |
719 { | |
720 tdata->stalled = 1; | |
721 g_snprintf (dlstr, sizeof (dlstr), | |
722 _("Recv %s of %s, transfer stalled, unknown time remaining"), | |
723 gotstr, ofstr); | |
724 } | |
725 } | |
726 | |
129 | 727 g_static_mutex_unlock (&tdata->statmutex); |
1 | 728 |
129 | 729 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->user_data, 1, totstr); |
320 | 730 |
731 gftp_lookup_global_option ("show_trans_in_title", &show_trans_in_title); | |
732 if (gftp_file_transfers->data == tdata && show_trans_in_title) | |
733 { | |
734 g_snprintf (winstr, sizeof(winstr), "%s: %s", gftp_version, totstr); | |
735 gdk_window_set_title (gtk_widget_get_parent_window (GTK_WIDGET(dlwdw)), | |
736 winstr); | |
737 } | |
1 | 738 |
739 if (*dlstr != '\0') | |
129 | 740 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->user_data, 1, dlstr); |
1 | 741 } |
742 | |
377 | 743 |
56 | 744 static void |
745 update_window_transfer_bytes (gftp_window_data * wdata) | |
746 { | |
747 char *tempstr, *temp1str; | |
748 | |
749 if (wdata->request->gotbytes == -1) | |
750 { | |
751 update_window_info (); | |
752 wdata->request->gotbytes = 0; | |
753 } | |
754 else | |
755 { | |
756 tempstr = insert_commas (wdata->request->gotbytes, NULL, 0); | |
757 temp1str = g_strdup_printf (_("Retrieving file names...%s bytes"), | |
758 tempstr); | |
759 gtk_label_set (GTK_LABEL (wdata->hoststxt), temp1str); | |
760 g_free (tempstr); | |
761 g_free (temp1str); | |
762 } | |
763 } | |
764 | |
1 | 765 |
48 | 766 gint |
767 update_downloads (gpointer data) | |
768 { | |
433 | 769 intptr_t do_one_transfer_at_a_time, start_transfers; |
48 | 770 GList * templist, * next; |
771 gftp_transfer * tdata; | |
772 | |
129 | 773 if (gftp_file_transfer_logs != NULL) |
48 | 774 display_cached_logs (); |
775 | |
56 | 776 if (window1.request->gotbytes != 0) |
777 update_window_transfer_bytes (&window1); | |
48 | 778 if (window2.request->gotbytes != 0) |
56 | 779 update_window_transfer_bytes (&window2); |
48 | 780 |
781 if (viewedit_process_done) | |
782 check_done_process (); | |
783 | |
129 | 784 for (templist = gftp_file_transfers; templist != NULL;) |
48 | 785 { |
786 tdata = templist->data; | |
787 if (tdata->ready) | |
788 { | |
129 | 789 g_static_mutex_lock (&tdata->structmutex); |
48 | 790 |
791 if (tdata->next_file) | |
792 on_next_transfer (tdata); | |
793 else if (tdata->show) | |
794 show_transfer (tdata); | |
795 else if (tdata->done) | |
796 { | |
797 next = templist->next; | |
129 | 798 g_static_mutex_unlock (&tdata->structmutex); |
48 | 799 transfer_done (templist); |
800 templist = next; | |
801 continue; | |
802 } | |
803 | |
804 if (tdata->curfle != NULL) | |
805 { | |
151 | 806 gftp_lookup_global_option ("one_transfer", |
129 | 807 &do_one_transfer_at_a_time); |
433 | 808 gftp_lookup_global_option ("start_transfers", &start_transfers); |
129 | 809 |
433 | 810 if (!tdata->started && start_transfers && |
129 | 811 (num_transfers_in_progress == 0 || !do_one_transfer_at_a_time)) |
48 | 812 create_transfer (tdata); |
813 | |
814 if (tdata->started) | |
815 update_file_status (tdata); | |
816 } | |
129 | 817 g_static_mutex_unlock (&tdata->structmutex); |
48 | 818 } |
819 templist = templist->next; | |
820 } | |
821 | |
822 gtk_timeout_add (500, update_downloads, NULL); | |
823 return (0); | |
824 } | |
825 | |
826 | |
1 | 827 void |
828 start_transfer (gpointer data) | |
829 { | |
367 | 830 gftpui_common_curtrans_data * transdata; |
1 | 831 GtkCTreeNode * node; |
832 | |
833 if (GTK_CLIST (dlwdw)->selection == NULL) | |
834 { | |
835 ftp_log (gftp_logging_misc, NULL, | |
836 _("There are no file transfers selected\n")); | |
837 return; | |
838 } | |
839 node = GTK_CLIST (dlwdw)->selection->data; | |
840 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
841 | |
129 | 842 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 843 if (!transdata->transfer->started) |
844 create_transfer (transdata->transfer); | |
129 | 845 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 846 } |
847 | |
848 | |
849 void | |
850 stop_transfer (gpointer data) | |
851 { | |
367 | 852 gftpui_common_curtrans_data * transdata; |
1 | 853 GtkCTreeNode * node; |
854 | |
855 if (GTK_CLIST (dlwdw)->selection == NULL) | |
856 { | |
857 ftp_log (gftp_logging_misc, NULL, | |
858 _("There are no file transfers selected\n")); | |
859 return; | |
860 } | |
861 node = GTK_CLIST (dlwdw)->selection->data; | |
862 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
863 | |
129 | 864 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 865 if (transdata->transfer->started) |
866 { | |
867 transdata->transfer->cancel = 1; | |
42 | 868 transdata->transfer->fromreq->cancel = 1; |
869 transdata->transfer->toreq->cancel = 1; | |
1 | 870 transdata->transfer->skip_file = 0; |
871 } | |
872 else | |
873 transdata->transfer->done = 1; | |
129 | 874 g_static_mutex_unlock (&transdata->transfer->structmutex); |
40 | 875 |
1 | 876 ftp_log (gftp_logging_misc, NULL, _("Stopping the transfer on host %s\n"), |
877 transdata->transfer->fromreq->hostname); | |
878 } | |
879 | |
880 | |
881 void | |
882 skip_transfer (gpointer data) | |
883 { | |
367 | 884 gftpui_common_curtrans_data * transdata; |
1 | 885 GtkCTreeNode * node; |
886 gftp_file * curfle; | |
40 | 887 char *file; |
1 | 888 |
889 if (GTK_CLIST (dlwdw)->selection == NULL) | |
890 { | |
891 ftp_log (gftp_logging_misc, NULL, | |
892 _("There are no file transfers selected\n")); | |
893 return; | |
894 } | |
895 node = GTK_CLIST (dlwdw)->selection->data; | |
896 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
897 | |
129 | 898 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 899 if (transdata->transfer->curfle != NULL) |
900 { | |
901 curfle = transdata->transfer->curfle->data; | |
902 if (transdata->transfer->started) | |
903 { | |
904 transdata->transfer->cancel = 1; | |
42 | 905 transdata->transfer->fromreq->cancel = 1; |
906 transdata->transfer->toreq->cancel = 1; | |
1 | 907 transdata->transfer->skip_file = 1; |
908 } | |
909 | |
910 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
40 | 911 file = curfle->file; |
1 | 912 } |
40 | 913 else |
914 file = NULL; | |
129 | 915 g_static_mutex_unlock (&transdata->transfer->structmutex); |
40 | 916 |
917 ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"), | |
918 file, transdata->transfer->fromreq->hostname); | |
1 | 919 } |
920 | |
921 | |
922 void | |
923 remove_file_transfer (gpointer data) | |
924 { | |
367 | 925 gftpui_common_curtrans_data * transdata; |
1 | 926 GtkCTreeNode * node; |
927 gftp_file * curfle; | |
928 | |
929 if (GTK_CLIST (dlwdw)->selection == NULL) | |
930 { | |
931 ftp_log (gftp_logging_misc, NULL, | |
932 _("There are no file transfers selected\n")); | |
933 return; | |
934 } | |
935 | |
936 node = GTK_CLIST (dlwdw)->selection->data; | |
937 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
938 | |
939 | |
940 if (transdata->curfle == NULL || transdata->curfle->data == NULL) | |
941 return; | |
942 | |
943 curfle = transdata->curfle->data; | |
944 | |
945 if (curfle->transfer_action & GFTP_TRANS_ACTION_SKIP) | |
946 return; | |
947 | |
129 | 948 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 949 |
950 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
951 | |
952 if (transdata->transfer->started && | |
953 transdata->curfle == transdata->transfer->curfle) | |
954 { | |
955 transdata->transfer->cancel = 1; | |
42 | 956 transdata->transfer->fromreq->cancel = 1; |
957 transdata->transfer->toreq->cancel = 1; | |
1 | 958 transdata->transfer->skip_file = 1; |
959 } | |
960 else if (transdata->curfle != transdata->transfer->curfle && | |
961 !curfle->transfer_done) | |
962 { | |
129 | 963 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), curfle->user_data, 1, |
1 | 964 _("Skipped")); |
965 transdata->transfer->total_bytes -= curfle->size; | |
966 } | |
967 | |
129 | 968 g_static_mutex_unlock (&transdata->transfer->structmutex); |
40 | 969 |
1 | 970 ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"), |
971 curfle->file, transdata->transfer->fromreq->hostname); | |
972 } | |
973 | |
974 | |
975 void | |
976 move_transfer_up (gpointer data) | |
977 { | |
978 GList * firstentry, * secentry, * lastentry; | |
367 | 979 gftpui_common_curtrans_data * transdata; |
1 | 980 GtkCTreeNode * node; |
981 | |
982 if (GTK_CLIST (dlwdw)->selection == NULL) | |
983 { | |
984 ftp_log (gftp_logging_misc, NULL, | |
985 _("There are no file transfers selected\n")); | |
986 return; | |
987 } | |
988 node = GTK_CLIST (dlwdw)->selection->data; | |
989 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
990 | |
991 if (transdata->curfle == NULL) | |
992 return; | |
993 | |
129 | 994 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 995 if (transdata->curfle->prev != NULL && (!transdata->transfer->started || |
996 (transdata->transfer->curfle != transdata->curfle && | |
997 transdata->transfer->curfle != transdata->curfle->prev))) | |
998 { | |
999 if (transdata->curfle->prev->prev == NULL) | |
1000 { | |
1001 firstentry = transdata->curfle->prev; | |
1002 lastentry = transdata->curfle->next; | |
1003 transdata->transfer->files = transdata->curfle; | |
1004 transdata->curfle->next = firstentry; | |
1005 transdata->transfer->files->prev = NULL; | |
1006 firstentry->prev = transdata->curfle; | |
1007 firstentry->next = lastentry; | |
1008 if (lastentry != NULL) | |
1009 lastentry->prev = firstentry; | |
1010 } | |
1011 else | |
1012 { | |
1013 firstentry = transdata->curfle->prev->prev; | |
1014 secentry = transdata->curfle->prev; | |
1015 lastentry = transdata->curfle->next; | |
1016 firstentry->next = transdata->curfle; | |
1017 transdata->curfle->prev = firstentry; | |
1018 transdata->curfle->next = secentry; | |
1019 secentry->prev = transdata->curfle; | |
1020 secentry->next = lastentry; | |
1021 if (lastentry != NULL) | |
1022 lastentry->prev = secentry; | |
1023 } | |
1024 | |
1025 gtk_ctree_move (GTK_CTREE (dlwdw), | |
129 | 1026 ((gftp_file *) transdata->curfle->data)->user_data, |
1027 transdata->transfer->user_data, | |
1 | 1028 transdata->curfle->next != NULL ? |
129 | 1029 ((gftp_file *) transdata->curfle->next->data)->user_data: NULL); |
1 | 1030 } |
129 | 1031 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 1032 } |
1033 | |
367 | 1034 |
1 | 1035 void |
1036 move_transfer_down (gpointer data) | |
1037 { | |
1038 GList * firstentry, * secentry, * lastentry; | |
367 | 1039 gftpui_common_curtrans_data * transdata; |
1 | 1040 GtkCTreeNode * node; |
1041 | |
1042 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1043 { | |
1044 ftp_log (gftp_logging_misc, NULL, | |
1045 _("There are no file transfers selected\n")); | |
1046 return; | |
1047 } | |
1048 node = GTK_CLIST (dlwdw)->selection->data; | |
1049 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1050 | |
1051 if (transdata->curfle == NULL) | |
1052 return; | |
1053 | |
129 | 1054 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 1055 if (transdata->curfle->next != NULL && (!transdata->transfer->started || |
1056 (transdata->transfer->curfle != transdata->curfle && | |
1057 transdata->transfer->curfle != transdata->curfle->next))) | |
1058 { | |
1059 if (transdata->curfle->prev == NULL) | |
1060 { | |
1061 firstentry = transdata->curfle->next; | |
1062 lastentry = transdata->curfle->next->next; | |
1063 transdata->transfer->files = firstentry; | |
1064 transdata->transfer->files->prev = NULL; | |
1065 transdata->transfer->files->next = transdata->curfle; | |
1066 transdata->curfle->prev = transdata->transfer->files; | |
1067 transdata->curfle->next = lastentry; | |
1068 if (lastentry != NULL) | |
1069 lastentry->prev = transdata->curfle; | |
1070 } | |
1071 else | |
1072 { | |
1073 firstentry = transdata->curfle->prev; | |
1074 secentry = transdata->curfle->next; | |
1075 lastentry = transdata->curfle->next->next; | |
1076 firstentry->next = secentry; | |
1077 secentry->prev = firstentry; | |
1078 secentry->next = transdata->curfle; | |
1079 transdata->curfle->prev = secentry; | |
1080 transdata->curfle->next = lastentry; | |
1081 if (lastentry != NULL) | |
1082 lastentry->prev = transdata->curfle; | |
1083 } | |
1084 | |
1085 gtk_ctree_move (GTK_CTREE (dlwdw), | |
129 | 1086 ((gftp_file *) transdata->curfle->data)->user_data, |
1087 transdata->transfer->user_data, | |
1 | 1088 transdata->curfle->next != NULL ? |
129 | 1089 ((gftp_file *) transdata->curfle->next->data)->user_data: NULL); |
1 | 1090 } |
129 | 1091 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 1092 } |
1093 |