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