Mercurial > gftp.yaz
annotate src/gtk/transfer.c @ 555:7f54d0c0edbc
2004-9-17 Brian Masney <masneyb@gftp.org>
* lib/misc.c lib/cache.c lib/config_file.c lib/gftp.h lib/protocols.c
lib/rfc2068.c lib/sshv2.c src/gtk/bookmarks.c src/gtk/dnd.c
src/gtk/gftp-gtk.c src/gtk/gtkui.c src/gtk/menu-items.c
src/gtk/misc-gtk.c src/gtk/transfer.c src/uicommon/gftpui.c - added
gftp_request argument to gftp_build_path() and expand_path(). Renamed
expand_path() to gftp_expand_path()
* lib/gftp.h - fixed compile error in gftp_need_username macro
author | masneyb |
---|---|
date | Fri, 17 Sep 2004 23:37:47 +0000 |
parents | b2b4f5fa8fc7 |
children | 017b1108305b |
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)); |
555 | 303 tempfle->destfile = gftp_build_path (ve_proc->torequest, |
304 ve_proc->torequest->directory, | |
294 | 305 ve_proc->remote_filename, NULL); |
48 | 306 ve_proc->remote_filename = NULL; |
307 tempfle->file = ve_proc->filename; | |
308 ve_proc->filename = NULL; | |
309 tempfle->done_rm = 1; | |
310 newfile = g_list_append (NULL, tempfle); | |
367 | 311 tdata = gftpui_common_add_file_transfer (ve_proc->fromwdata->request, |
312 ve_proc->torequest, | |
313 ve_proc->fromwdata, | |
314 ve_proc->towdata, newfile); | |
48 | 315 free_edit_data (ve_proc); |
303 | 316 |
317 if (tdata != NULL) | |
318 tdata->conn_error_no_timeout = 1; | |
48 | 319 } |
320 | |
1 | 321 |
48 | 322 static void |
323 check_done_process (void) | |
324 { | |
325 gftp_viewedit_data * ve_proc; | |
326 GList * curdata, *deldata; | |
327 struct stat st; | |
328 int ret; | |
329 char *str; | |
330 pid_t pid; | |
331 | |
470 | 332 gftpui_common_child_process_done = 0; |
48 | 333 while ((pid = waitpid (-1, &ret, WNOHANG)) > 0) |
1 | 334 { |
48 | 335 curdata = viewedit_processes; |
336 while (curdata != NULL) | |
337 { | |
338 ve_proc = curdata->data; | |
339 deldata = curdata; | |
340 curdata = curdata->next; | |
341 if (ve_proc->pid == pid) | |
342 { | |
343 viewedit_processes = g_list_remove_link (viewedit_processes, | |
344 deldata); | |
345 if (ret != 0) | |
346 ftp_log (gftp_logging_error, NULL, | |
347 _("Error: Child %d returned %d\n"), pid, ret); | |
348 else | |
349 ftp_log (gftp_logging_misc, NULL, | |
350 _("Child %d returned successfully\n"), pid); | |
351 | |
352 if (!ve_proc->view && !ve_proc->dontupload) | |
353 { | |
354 /* We was editing the file. Upload it */ | |
355 if (stat (ve_proc->filename, &st) == -1) | |
356 ftp_log (gftp_logging_error, NULL, | |
357 _("Error: Cannot get information about file %s: %s\n"), | |
358 ve_proc->filename, g_strerror (errno)); | |
359 else if (st.st_mtime == ve_proc->st.st_mtime) | |
360 { | |
361 ftp_log (gftp_logging_misc, NULL, | |
362 _("File %s was not changed\n"), | |
363 ve_proc->filename); | |
364 remove_file (ve_proc->filename); | |
365 } | |
366 else | |
367 { | |
368 memcpy (&ve_proc->st, &st, sizeof (ve_proc->st)); | |
369 str = g_strdup_printf ( | |
370 _("File %s has changed.\nWould you like to upload it?"), | |
371 ve_proc->remote_filename); | |
372 | |
373 MakeYesNoDialog (_("Edit File"), str, | |
374 do_upload, ve_proc, | |
375 dont_upload, ve_proc); | |
376 g_free (str); | |
377 continue; | |
378 } | |
379 } | |
380 | |
381 free_edit_data (ve_proc); | |
382 continue; | |
383 } | |
1 | 384 } |
385 } | |
386 } | |
387 | |
388 | |
389 static void | |
390 on_next_transfer (gftp_transfer * tdata) | |
391 { | |
326 | 392 int fd; |
393 intptr_t refresh_files; | |
1 | 394 gftp_file * tempfle; |
395 | |
396 tdata->next_file = 0; | |
397 for (; tdata->updfle != tdata->curfle; tdata->updfle = tdata->updfle->next) | |
398 { | |
399 tempfle = tdata->updfle->data; | |
400 | |
401 if (tempfle->is_fd) | |
58 | 402 fd = tempfle->fd; |
1 | 403 else |
404 fd = 0; | |
405 | |
406 if (tempfle->done_view) | |
407 { | |
408 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) | |
409 view_file (tempfle->destfile, fd, 1, tempfle->done_rm, 1, 0, | |
410 tempfle->file, NULL); | |
411 | |
412 if (tempfle->is_fd) | |
413 { | |
58 | 414 close (tempfle->fd); |
415 tempfle->fd = -1; | |
1 | 416 } |
417 } | |
418 else if (tempfle->done_edit) | |
419 { | |
420 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) | |
421 view_file (tempfle->destfile, fd, 0, tempfle->done_rm, 1, 0, | |
422 tempfle->file, NULL); | |
423 | |
424 if (tempfle->is_fd) | |
425 { | |
58 | 426 close (tempfle->fd); |
427 tempfle->fd = -1; | |
1 | 428 } |
429 } | |
430 else if (tempfle->done_rm) | |
431 tdata->fromreq->rmfile (tdata->fromreq, tempfle->file); | |
432 | |
433 if (tempfle->transfer_action == GFTP_TRANS_ACTION_SKIP) | |
129 | 434 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->user_data, 1, |
1 | 435 _("Skipped")); |
436 else | |
129 | 437 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->user_data, 1, |
1 | 438 _("Finished")); |
439 } | |
440 | |
129 | 441 gftp_lookup_request_option (tdata->fromreq, "refresh_files", &refresh_files); |
442 | |
1 | 443 if (refresh_files && tdata->curfle && tdata->curfle->next && |
444 compare_request (tdata->toreq, | |
445 ((gftp_window_data *) tdata->towdata)->request, 1)) | |
514 | 446 gftpui_refresh (tdata->towdata, 1); |
1 | 447 } |
448 | |
449 | |
450 static void | |
19 | 451 get_trans_password (gftp_request * request, gftp_dialog_data * ddata) |
452 { | |
453 gftp_set_password (request, gtk_entry_get_text (GTK_ENTRY (ddata->edit))); | |
454 request->stopable = 0; | |
455 } | |
456 | |
457 | |
458 static void | |
459 cancel_get_trans_password (gftp_transfer * tdata, gftp_dialog_data * ddata) | |
460 { | |
461 if (tdata->fromreq->stopable == 0) | |
462 return; | |
463 | |
129 | 464 g_static_mutex_lock (&tdata->structmutex); |
19 | 465 if (tdata->started) |
42 | 466 { |
467 tdata->cancel = 1; | |
468 tdata->fromreq->cancel = 1; | |
469 tdata->toreq->cancel = 1; | |
470 } | |
19 | 471 else |
472 tdata->done = 1; | |
473 | |
474 tdata->fromreq->stopable = 0; | |
475 tdata->toreq->stopable = 0; | |
129 | 476 g_static_mutex_unlock (&tdata->structmutex); |
40 | 477 |
19 | 478 ftp_log (gftp_logging_misc, NULL, _("Stopping the transfer of %s\n"), |
479 ((gftp_file *) tdata->curfle->data)->file); | |
480 } | |
481 | |
482 | |
483 static void | |
1 | 484 show_transfer (gftp_transfer * tdata) |
485 { | |
486 GdkPixmap * closedir_pixmap, * opendir_pixmap; | |
487 GdkBitmap * closedir_bitmap, * opendir_bitmap; | |
367 | 488 gftpui_common_curtrans_data * transdata; |
1 | 489 gftp_file * tempfle; |
490 GList * templist; | |
397 | 491 char *text[2]; |
1 | 492 |
493 gftp_get_pixmap (dlwdw, "open_dir.xpm", &opendir_pixmap, &opendir_bitmap); | |
494 gftp_get_pixmap (dlwdw, "dir.xpm", &closedir_pixmap, &closedir_bitmap); | |
495 | |
129 | 496 text[0] = tdata->fromreq->hostname; |
1 | 497 text[1] = _("Waiting..."); |
129 | 498 tdata->user_data = gtk_ctree_insert_node (GTK_CTREE (dlwdw), NULL, NULL, |
499 text, 5, | |
1 | 500 closedir_pixmap, closedir_bitmap, |
501 opendir_pixmap, opendir_bitmap, | |
502 FALSE, | |
503 tdata->numdirs + tdata->numfiles < 50); | |
504 transdata = g_malloc (sizeof (*transdata)); | |
505 transdata->transfer = tdata; | |
506 transdata->curfle = NULL; | |
129 | 507 gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), tdata->user_data, transdata); |
1 | 508 tdata->show = 0; |
509 tdata->curfle = tdata->updfle = tdata->files; | |
510 | |
511 tdata->total_bytes = 0; | |
512 for (templist = tdata->files; templist != NULL; templist = templist->next) | |
513 { | |
514 tempfle = templist->data; | |
397 | 515 |
516 text[0] = gftpui_gtk_get_utf8_file_pos (tempfle); | |
1 | 517 if (tempfle->transfer_action == GFTP_TRANS_ACTION_SKIP) |
518 text[1] = _("Skipped"); | |
519 else | |
520 { | |
521 tdata->total_bytes += tempfle->size; | |
522 text[1] = _("Waiting..."); | |
523 } | |
524 | |
129 | 525 tempfle->user_data = gtk_ctree_insert_node (GTK_CTREE (dlwdw), |
526 tdata->user_data, | |
1 | 527 NULL, text, 5, NULL, NULL, NULL, |
528 NULL, FALSE, FALSE); | |
529 transdata = g_malloc (sizeof (*transdata)); | |
530 transdata->transfer = tdata; | |
531 transdata->curfle = templist; | |
129 | 532 gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), tempfle->user_data, |
533 transdata); | |
1 | 534 } |
535 | |
553 | 536 if (!tdata->toreq->stopable && gftp_need_password (tdata->toreq)) |
1 | 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 | |
553 | 546 if (!tdata->fromreq->stopable && gftp_need_password (tdata->fromreq)) |
1 | 547 { |
548 tdata->fromreq->stopable = 1; | |
549 MakeEditDialog (_("Enter Password"), | |
550 _("Please enter your password for this site"), NULL, 0, | |
19 | 551 NULL, gftp_dialog_button_connect, |
552 get_trans_password, tdata->fromreq, | |
553 cancel_get_trans_password, tdata); | |
1 | 554 } |
555 } | |
556 | |
557 | |
558 static void | |
559 transfer_done (GList * node) | |
560 { | |
367 | 561 gftpui_common_curtrans_data * transdata; |
1 | 562 gftp_transfer * tdata; |
563 gftp_file * tempfle; | |
564 GList * templist; | |
565 | |
566 tdata = node->data; | |
567 if (tdata->started) | |
568 { | |
297 | 569 if (GFTP_IS_SAME_HOST_STOP_TRANS ((gftp_window_data *) tdata->fromwdata, |
570 tdata->fromreq)) | |
309 | 571 { |
572 gftp_copy_param_options (((gftp_window_data *) tdata->fromwdata)->request, tdata->fromreq); | |
573 | |
574 gftp_swap_socks (((gftp_window_data *) tdata->fromwdata)->request, | |
575 tdata->fromreq); | |
576 } | |
1 | 577 else |
297 | 578 gftp_disconnect (tdata->fromreq); |
579 | |
580 if (GFTP_IS_SAME_HOST_STOP_TRANS ((gftp_window_data *) tdata->towdata, | |
581 tdata->toreq)) | |
309 | 582 { |
583 gftp_copy_param_options (((gftp_window_data *) tdata->towdata)->request, tdata->toreq); | |
584 | |
585 gftp_swap_socks (((gftp_window_data *) tdata->towdata)->request, | |
586 tdata->toreq); | |
587 } | |
297 | 588 else |
589 gftp_disconnect (tdata->toreq); | |
1 | 590 |
305 | 591 if (tdata->towdata != NULL && compare_request (tdata->toreq, |
592 ((gftp_window_data *) tdata->towdata)->request, 1)) | |
514 | 593 gftpui_refresh (tdata->towdata, 1); |
305 | 594 |
129 | 595 num_transfers_in_progress--; |
1 | 596 } |
597 | |
2
a171df6764a7
* Fixed crash if you was already transfering a file, and you started another
masneyb
parents:
1
diff
changeset
|
598 if (!tdata->show && tdata->started) |
1 | 599 { |
129 | 600 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), |
601 tdata->user_data); | |
1 | 602 if (transdata != NULL) |
603 g_free (transdata); | |
604 | |
605 for (templist = tdata->files; templist != NULL; templist = templist->next) | |
606 { | |
607 tempfle = templist->data; | |
129 | 608 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), |
609 tempfle->user_data); | |
1 | 610 if (transdata != NULL) |
611 g_free (transdata); | |
612 } | |
613 | |
129 | 614 gtk_ctree_remove_node (GTK_CTREE (dlwdw), tdata->user_data); |
1 | 615 } |
129 | 616 |
367 | 617 g_static_mutex_lock (&gftpui_common_transfer_mutex); |
129 | 618 gftp_file_transfers = g_list_remove_link (gftp_file_transfers, node); |
367 | 619 g_static_mutex_unlock (&gftpui_common_transfer_mutex); |
620 | |
320 | 621 gdk_window_set_title (gtk_widget_get_parent_window (GTK_WIDGET(dlwdw)), |
622 gftp_version); | |
129 | 623 |
1 | 624 free_tdata (tdata); |
625 } | |
626 | |
627 | |
367 | 628 static void * |
629 _gftpui_transfer_files (void *data) | |
630 { | |
631 int ret; | |
632 | |
633 pthread_detach (pthread_self ()); | |
634 ret = gftpui_common_transfer_files (data); | |
635 return (GINT_TO_POINTER(ret)); | |
636 } | |
637 | |
638 | |
1 | 639 static void |
640 create_transfer (gftp_transfer * tdata) | |
641 { | |
642 pthread_t tid; | |
643 | |
644 if (!tdata->fromreq->stopable) | |
645 { | |
297 | 646 if (GFTP_IS_SAME_HOST_START_TRANS ((gftp_window_data *) tdata->fromwdata, |
647 tdata->fromreq)) | |
648 { | |
649 gftp_swap_socks (tdata->fromreq, | |
650 ((gftp_window_data *) tdata->fromwdata)->request); | |
651 update_window (tdata->fromwdata); | |
652 } | |
653 | |
654 if (GFTP_IS_SAME_HOST_START_TRANS ((gftp_window_data *) tdata->towdata, | |
655 tdata->toreq)) | |
656 { | |
63 | 657 gftp_swap_socks (tdata->toreq, |
658 ((gftp_window_data *) tdata->towdata)->request); | |
297 | 659 update_window (tdata->towdata); |
1 | 660 } |
297 | 661 |
129 | 662 num_transfers_in_progress++; |
1 | 663 tdata->started = 1; |
664 tdata->stalled = 1; | |
129 | 665 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->user_data, 1, |
1 | 666 _("Connecting...")); |
367 | 667 pthread_create (&tid, NULL, _gftpui_transfer_files, tdata); |
1 | 668 } |
669 } | |
670 | |
671 | |
672 static void | |
673 update_file_status (gftp_transfer * tdata) | |
674 { | |
320 | 675 char totstr[100], dlstr[100], winstr[150], gotstr[50], ofstr[50]; |
246 | 676 unsigned long remaining_secs, lkbs; |
463 | 677 int hours, mins, secs, pcent, st; |
678 intptr_t show_trans_in_title; | |
1 | 679 gftp_file * tempfle; |
680 struct timeval tv; | |
320 | 681 |
129 | 682 g_static_mutex_lock (&tdata->statmutex); |
1 | 683 tempfle = tdata->curfle->data; |
684 | |
685 gettimeofday (&tv, NULL); | |
220 | 686 |
687 remaining_secs = (tdata->total_bytes - tdata->trans_bytes - tdata->resumed_bytes) / 1024; | |
246 | 688 |
689 lkbs = (unsigned long) tdata->kbs; | |
690 if (lkbs > 0) | |
691 remaining_secs /= lkbs; | |
1 | 692 |
220 | 693 hours = remaining_secs / 3600; |
694 remaining_secs -= hours * 3600; | |
695 mins = remaining_secs / 60; | |
696 remaining_secs -= mins * 60; | |
697 secs = remaining_secs; | |
1 | 698 |
699 if (hours < 0 || mins < 0 || secs < 0) | |
700 { | |
129 | 701 g_static_mutex_unlock (&tdata->statmutex); |
1 | 702 return; |
703 } | |
704 | |
246 | 705 if ((double) tdata->total_bytes > 0) |
706 pcent = (int) ((double) (tdata->trans_bytes + tdata->resumed_bytes) / (double) tdata->total_bytes * 100.0); | |
707 else | |
1 | 708 pcent = 0; |
709 | |
710 g_snprintf (totstr, sizeof (totstr), | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
711 _("%d%% complete, %02d:%02d:%02d est. time remaining. (File %ld of %ld)"), |
1 | 712 pcent, hours, mins, secs, tdata->current_file_number, |
713 tdata->numdirs + tdata->numfiles); | |
714 | |
715 *dlstr = '\0'; | |
716 if (!tdata->stalled) | |
717 { | |
718 insert_commas (tdata->curtrans + tdata->curresumed, gotstr, sizeof (gotstr)); | |
719 insert_commas (tempfle->size, ofstr, sizeof (ofstr)); | |
720 st = 1; | |
721 if (tv.tv_sec - tdata->lasttime.tv_sec <= 5) | |
722 { | |
723 if (tdata->curfle->next != NULL) | |
724 { | |
220 | 725 remaining_secs = (tempfle->size - tdata->curtrans - tdata->curresumed) / 1024; |
246 | 726 |
727 lkbs = (unsigned long) tdata->kbs; | |
728 if (lkbs > 0) | |
729 remaining_secs /= lkbs; | |
220 | 730 |
731 hours = remaining_secs / 3600; | |
732 remaining_secs -= hours * 3600; | |
733 mins = remaining_secs / 60; | |
734 remaining_secs -= mins * 60; | |
735 secs = remaining_secs; | |
1 | 736 } |
737 | |
738 if (!(hours < 0 || mins < 0 || secs < 0)) | |
739 { | |
740 g_snprintf (dlstr, sizeof (dlstr), | |
741 _("Recv %s of %s at %.2fKB/s, %02d:%02d:%02d est. time remaining"), gotstr, ofstr, tdata->kbs, hours, mins, secs); | |
742 st = 0; | |
743 } | |
744 } | |
745 | |
746 if (st) | |
747 { | |
748 tdata->stalled = 1; | |
749 g_snprintf (dlstr, sizeof (dlstr), | |
750 _("Recv %s of %s, transfer stalled, unknown time remaining"), | |
751 gotstr, ofstr); | |
752 } | |
753 } | |
754 | |
129 | 755 g_static_mutex_unlock (&tdata->statmutex); |
1 | 756 |
129 | 757 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->user_data, 1, totstr); |
320 | 758 |
759 gftp_lookup_global_option ("show_trans_in_title", &show_trans_in_title); | |
760 if (gftp_file_transfers->data == tdata && show_trans_in_title) | |
761 { | |
762 g_snprintf (winstr, sizeof(winstr), "%s: %s", gftp_version, totstr); | |
763 gdk_window_set_title (gtk_widget_get_parent_window (GTK_WIDGET(dlwdw)), | |
764 winstr); | |
765 } | |
1 | 766 |
767 if (*dlstr != '\0') | |
129 | 768 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->user_data, 1, dlstr); |
1 | 769 } |
770 | |
377 | 771 |
56 | 772 static void |
773 update_window_transfer_bytes (gftp_window_data * wdata) | |
774 { | |
775 char *tempstr, *temp1str; | |
776 | |
777 if (wdata->request->gotbytes == -1) | |
778 { | |
779 update_window_info (); | |
780 wdata->request->gotbytes = 0; | |
781 } | |
782 else | |
783 { | |
784 tempstr = insert_commas (wdata->request->gotbytes, NULL, 0); | |
785 temp1str = g_strdup_printf (_("Retrieving file names...%s bytes"), | |
786 tempstr); | |
787 gtk_label_set (GTK_LABEL (wdata->hoststxt), temp1str); | |
788 g_free (tempstr); | |
789 g_free (temp1str); | |
790 } | |
791 } | |
792 | |
1 | 793 |
48 | 794 gint |
795 update_downloads (gpointer data) | |
796 { | |
433 | 797 intptr_t do_one_transfer_at_a_time, start_transfers; |
48 | 798 GList * templist, * next; |
799 gftp_transfer * tdata; | |
800 | |
129 | 801 if (gftp_file_transfer_logs != NULL) |
48 | 802 display_cached_logs (); |
803 | |
56 | 804 if (window1.request->gotbytes != 0) |
805 update_window_transfer_bytes (&window1); | |
48 | 806 if (window2.request->gotbytes != 0) |
56 | 807 update_window_transfer_bytes (&window2); |
48 | 808 |
470 | 809 if (gftpui_common_child_process_done) |
48 | 810 check_done_process (); |
811 | |
129 | 812 for (templist = gftp_file_transfers; templist != NULL;) |
48 | 813 { |
814 tdata = templist->data; | |
815 if (tdata->ready) | |
816 { | |
129 | 817 g_static_mutex_lock (&tdata->structmutex); |
48 | 818 |
819 if (tdata->next_file) | |
820 on_next_transfer (tdata); | |
821 else if (tdata->show) | |
822 show_transfer (tdata); | |
823 else if (tdata->done) | |
824 { | |
825 next = templist->next; | |
129 | 826 g_static_mutex_unlock (&tdata->structmutex); |
48 | 827 transfer_done (templist); |
828 templist = next; | |
829 continue; | |
830 } | |
831 | |
832 if (tdata->curfle != NULL) | |
833 { | |
151 | 834 gftp_lookup_global_option ("one_transfer", |
129 | 835 &do_one_transfer_at_a_time); |
433 | 836 gftp_lookup_global_option ("start_transfers", &start_transfers); |
129 | 837 |
433 | 838 if (!tdata->started && start_transfers && |
129 | 839 (num_transfers_in_progress == 0 || !do_one_transfer_at_a_time)) |
48 | 840 create_transfer (tdata); |
841 | |
842 if (tdata->started) | |
843 update_file_status (tdata); | |
844 } | |
129 | 845 g_static_mutex_unlock (&tdata->structmutex); |
48 | 846 } |
847 templist = templist->next; | |
848 } | |
849 | |
850 gtk_timeout_add (500, update_downloads, NULL); | |
851 return (0); | |
852 } | |
853 | |
854 | |
1 | 855 void |
856 start_transfer (gpointer data) | |
857 { | |
367 | 858 gftpui_common_curtrans_data * transdata; |
1 | 859 GtkCTreeNode * node; |
860 | |
861 if (GTK_CLIST (dlwdw)->selection == NULL) | |
862 { | |
863 ftp_log (gftp_logging_misc, NULL, | |
864 _("There are no file transfers selected\n")); | |
865 return; | |
866 } | |
867 node = GTK_CLIST (dlwdw)->selection->data; | |
868 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
869 | |
129 | 870 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 871 if (!transdata->transfer->started) |
872 create_transfer (transdata->transfer); | |
129 | 873 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 874 } |
875 | |
876 | |
877 void | |
878 stop_transfer (gpointer data) | |
879 { | |
367 | 880 gftpui_common_curtrans_data * transdata; |
1 | 881 GtkCTreeNode * node; |
882 | |
883 if (GTK_CLIST (dlwdw)->selection == NULL) | |
884 { | |
885 ftp_log (gftp_logging_misc, NULL, | |
886 _("There are no file transfers selected\n")); | |
887 return; | |
888 } | |
889 node = GTK_CLIST (dlwdw)->selection->data; | |
890 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
891 | |
129 | 892 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 893 if (transdata->transfer->started) |
894 { | |
895 transdata->transfer->cancel = 1; | |
42 | 896 transdata->transfer->fromreq->cancel = 1; |
897 transdata->transfer->toreq->cancel = 1; | |
1 | 898 transdata->transfer->skip_file = 0; |
899 } | |
900 else | |
901 transdata->transfer->done = 1; | |
129 | 902 g_static_mutex_unlock (&transdata->transfer->structmutex); |
40 | 903 |
1 | 904 ftp_log (gftp_logging_misc, NULL, _("Stopping the transfer on host %s\n"), |
905 transdata->transfer->fromreq->hostname); | |
906 } | |
907 | |
908 | |
909 void | |
910 skip_transfer (gpointer data) | |
911 { | |
367 | 912 gftpui_common_curtrans_data * transdata; |
1 | 913 GtkCTreeNode * node; |
914 gftp_file * curfle; | |
40 | 915 char *file; |
1 | 916 |
917 if (GTK_CLIST (dlwdw)->selection == NULL) | |
918 { | |
919 ftp_log (gftp_logging_misc, NULL, | |
920 _("There are no file transfers selected\n")); | |
921 return; | |
922 } | |
923 node = GTK_CLIST (dlwdw)->selection->data; | |
924 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
925 | |
129 | 926 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 927 if (transdata->transfer->curfle != NULL) |
928 { | |
929 curfle = transdata->transfer->curfle->data; | |
930 if (transdata->transfer->started) | |
931 { | |
932 transdata->transfer->cancel = 1; | |
42 | 933 transdata->transfer->fromreq->cancel = 1; |
934 transdata->transfer->toreq->cancel = 1; | |
1 | 935 transdata->transfer->skip_file = 1; |
936 } | |
937 | |
938 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
40 | 939 file = curfle->file; |
1 | 940 } |
40 | 941 else |
942 file = NULL; | |
129 | 943 g_static_mutex_unlock (&transdata->transfer->structmutex); |
40 | 944 |
945 ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"), | |
946 file, transdata->transfer->fromreq->hostname); | |
1 | 947 } |
948 | |
949 | |
950 void | |
951 remove_file_transfer (gpointer data) | |
952 { | |
367 | 953 gftpui_common_curtrans_data * transdata; |
1 | 954 GtkCTreeNode * node; |
955 gftp_file * curfle; | |
956 | |
957 if (GTK_CLIST (dlwdw)->selection == NULL) | |
958 { | |
959 ftp_log (gftp_logging_misc, NULL, | |
960 _("There are no file transfers selected\n")); | |
961 return; | |
962 } | |
963 | |
964 node = GTK_CLIST (dlwdw)->selection->data; | |
965 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
966 | |
967 | |
968 if (transdata->curfle == NULL || transdata->curfle->data == NULL) | |
969 return; | |
970 | |
971 curfle = transdata->curfle->data; | |
972 | |
973 if (curfle->transfer_action & GFTP_TRANS_ACTION_SKIP) | |
974 return; | |
975 | |
129 | 976 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 977 |
978 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
979 | |
980 if (transdata->transfer->started && | |
981 transdata->curfle == transdata->transfer->curfle) | |
982 { | |
983 transdata->transfer->cancel = 1; | |
42 | 984 transdata->transfer->fromreq->cancel = 1; |
985 transdata->transfer->toreq->cancel = 1; | |
1 | 986 transdata->transfer->skip_file = 1; |
987 } | |
988 else if (transdata->curfle != transdata->transfer->curfle && | |
989 !curfle->transfer_done) | |
990 { | |
129 | 991 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), curfle->user_data, 1, |
1 | 992 _("Skipped")); |
993 transdata->transfer->total_bytes -= curfle->size; | |
994 } | |
995 | |
129 | 996 g_static_mutex_unlock (&transdata->transfer->structmutex); |
40 | 997 |
1 | 998 ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"), |
999 curfle->file, transdata->transfer->fromreq->hostname); | |
1000 } | |
1001 | |
1002 | |
1003 void | |
1004 move_transfer_up (gpointer data) | |
1005 { | |
1006 GList * firstentry, * secentry, * lastentry; | |
367 | 1007 gftpui_common_curtrans_data * transdata; |
1 | 1008 GtkCTreeNode * node; |
1009 | |
1010 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1011 { | |
1012 ftp_log (gftp_logging_misc, NULL, | |
1013 _("There are no file transfers selected\n")); | |
1014 return; | |
1015 } | |
1016 node = GTK_CLIST (dlwdw)->selection->data; | |
1017 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1018 | |
1019 if (transdata->curfle == NULL) | |
1020 return; | |
1021 | |
129 | 1022 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 1023 if (transdata->curfle->prev != NULL && (!transdata->transfer->started || |
1024 (transdata->transfer->curfle != transdata->curfle && | |
1025 transdata->transfer->curfle != transdata->curfle->prev))) | |
1026 { | |
1027 if (transdata->curfle->prev->prev == NULL) | |
1028 { | |
1029 firstentry = transdata->curfle->prev; | |
1030 lastentry = transdata->curfle->next; | |
1031 transdata->transfer->files = transdata->curfle; | |
1032 transdata->curfle->next = firstentry; | |
1033 transdata->transfer->files->prev = NULL; | |
1034 firstentry->prev = transdata->curfle; | |
1035 firstentry->next = lastentry; | |
1036 if (lastentry != NULL) | |
1037 lastentry->prev = firstentry; | |
1038 } | |
1039 else | |
1040 { | |
1041 firstentry = transdata->curfle->prev->prev; | |
1042 secentry = transdata->curfle->prev; | |
1043 lastentry = transdata->curfle->next; | |
1044 firstentry->next = transdata->curfle; | |
1045 transdata->curfle->prev = firstentry; | |
1046 transdata->curfle->next = secentry; | |
1047 secentry->prev = transdata->curfle; | |
1048 secentry->next = lastentry; | |
1049 if (lastentry != NULL) | |
1050 lastentry->prev = secentry; | |
1051 } | |
1052 | |
1053 gtk_ctree_move (GTK_CTREE (dlwdw), | |
129 | 1054 ((gftp_file *) transdata->curfle->data)->user_data, |
1055 transdata->transfer->user_data, | |
1 | 1056 transdata->curfle->next != NULL ? |
129 | 1057 ((gftp_file *) transdata->curfle->next->data)->user_data: NULL); |
1 | 1058 } |
129 | 1059 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 1060 } |
1061 | |
367 | 1062 |
1 | 1063 void |
1064 move_transfer_down (gpointer data) | |
1065 { | |
1066 GList * firstentry, * secentry, * lastentry; | |
367 | 1067 gftpui_common_curtrans_data * transdata; |
1 | 1068 GtkCTreeNode * node; |
1069 | |
1070 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1071 { | |
1072 ftp_log (gftp_logging_misc, NULL, | |
1073 _("There are no file transfers selected\n")); | |
1074 return; | |
1075 } | |
1076 node = GTK_CLIST (dlwdw)->selection->data; | |
1077 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1078 | |
1079 if (transdata->curfle == NULL) | |
1080 return; | |
1081 | |
129 | 1082 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 1083 if (transdata->curfle->next != NULL && (!transdata->transfer->started || |
1084 (transdata->transfer->curfle != transdata->curfle && | |
1085 transdata->transfer->curfle != transdata->curfle->next))) | |
1086 { | |
1087 if (transdata->curfle->prev == NULL) | |
1088 { | |
1089 firstentry = transdata->curfle->next; | |
1090 lastentry = transdata->curfle->next->next; | |
1091 transdata->transfer->files = firstentry; | |
1092 transdata->transfer->files->prev = NULL; | |
1093 transdata->transfer->files->next = transdata->curfle; | |
1094 transdata->curfle->prev = transdata->transfer->files; | |
1095 transdata->curfle->next = lastentry; | |
1096 if (lastentry != NULL) | |
1097 lastentry->prev = transdata->curfle; | |
1098 } | |
1099 else | |
1100 { | |
1101 firstentry = transdata->curfle->prev; | |
1102 secentry = transdata->curfle->next; | |
1103 lastentry = transdata->curfle->next->next; | |
1104 firstentry->next = secentry; | |
1105 secentry->prev = firstentry; | |
1106 secentry->next = transdata->curfle; | |
1107 transdata->curfle->prev = secentry; | |
1108 transdata->curfle->next = lastentry; | |
1109 if (lastentry != NULL) | |
1110 lastentry->prev = transdata->curfle; | |
1111 } | |
1112 | |
1113 gtk_ctree_move (GTK_CTREE (dlwdw), | |
129 | 1114 ((gftp_file *) transdata->curfle->data)->user_data, |
1115 transdata->transfer->user_data, | |
1 | 1116 transdata->curfle->next != NULL ? |
129 | 1117 ((gftp_file *) transdata->curfle->next->data)->user_data: NULL); |
1 | 1118 } |
129 | 1119 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 1120 } |
1121 |