Mercurial > gftp.yaz
annotate src/gtk/transfer.c @ 553:b2b4f5fa8fc7
2004-9-14 Brian Masney <masneyb@gftp.org>
* lib/gftp.h lib/bookmark.c lib/local.c lib/rfc2068.c lib/rfc959.c
lib/sshv2.c src/gtk/transfer.c src/uicommon/gftpui.c - removed
need_userpass from the gftp_request structure. Added need_username and
need_password in it's place
* autogen.sh - updated CFLAGS variable that is passed to configure
author | masneyb |
---|---|
date | Tue, 14 Sep 2004 10:16:52 +0000 |
parents | 7262851e3ae8 |
children | 7f54d0c0edbc |
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 | |
553 | 535 if (!tdata->toreq->stopable && gftp_need_password (tdata->toreq)) |
1 | 536 { |
537 tdata->toreq->stopable = 1; | |
538 MakeEditDialog (_("Enter Password"), | |
539 _("Please enter your password for this site"), NULL, 0, | |
19 | 540 NULL, gftp_dialog_button_connect, |
541 get_trans_password, tdata->toreq, | |
542 cancel_get_trans_password, tdata); | |
1 | 543 } |
544 | |
553 | 545 if (!tdata->fromreq->stopable && gftp_need_password (tdata->fromreq)) |
1 | 546 { |
547 tdata->fromreq->stopable = 1; | |
548 MakeEditDialog (_("Enter Password"), | |
549 _("Please enter your password for this site"), NULL, 0, | |
19 | 550 NULL, gftp_dialog_button_connect, |
551 get_trans_password, tdata->fromreq, | |
552 cancel_get_trans_password, tdata); | |
1 | 553 } |
554 } | |
555 | |
556 | |
557 static void | |
558 transfer_done (GList * node) | |
559 { | |
367 | 560 gftpui_common_curtrans_data * transdata; |
1 | 561 gftp_transfer * tdata; |
562 gftp_file * tempfle; | |
563 GList * templist; | |
564 | |
565 tdata = node->data; | |
566 if (tdata->started) | |
567 { | |
297 | 568 if (GFTP_IS_SAME_HOST_STOP_TRANS ((gftp_window_data *) tdata->fromwdata, |
569 tdata->fromreq)) | |
309 | 570 { |
571 gftp_copy_param_options (((gftp_window_data *) tdata->fromwdata)->request, tdata->fromreq); | |
572 | |
573 gftp_swap_socks (((gftp_window_data *) tdata->fromwdata)->request, | |
574 tdata->fromreq); | |
575 } | |
1 | 576 else |
297 | 577 gftp_disconnect (tdata->fromreq); |
578 | |
579 if (GFTP_IS_SAME_HOST_STOP_TRANS ((gftp_window_data *) tdata->towdata, | |
580 tdata->toreq)) | |
309 | 581 { |
582 gftp_copy_param_options (((gftp_window_data *) tdata->towdata)->request, tdata->toreq); | |
583 | |
584 gftp_swap_socks (((gftp_window_data *) tdata->towdata)->request, | |
585 tdata->toreq); | |
586 } | |
297 | 587 else |
588 gftp_disconnect (tdata->toreq); | |
1 | 589 |
305 | 590 if (tdata->towdata != NULL && compare_request (tdata->toreq, |
591 ((gftp_window_data *) tdata->towdata)->request, 1)) | |
514 | 592 gftpui_refresh (tdata->towdata, 1); |
305 | 593 |
129 | 594 num_transfers_in_progress--; |
1 | 595 } |
596 | |
2
a171df6764a7
* Fixed crash if you was already transfering a file, and you started another
masneyb
parents:
1
diff
changeset
|
597 if (!tdata->show && tdata->started) |
1 | 598 { |
129 | 599 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), |
600 tdata->user_data); | |
1 | 601 if (transdata != NULL) |
602 g_free (transdata); | |
603 | |
604 for (templist = tdata->files; templist != NULL; templist = templist->next) | |
605 { | |
606 tempfle = templist->data; | |
129 | 607 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), |
608 tempfle->user_data); | |
1 | 609 if (transdata != NULL) |
610 g_free (transdata); | |
611 } | |
612 | |
129 | 613 gtk_ctree_remove_node (GTK_CTREE (dlwdw), tdata->user_data); |
1 | 614 } |
129 | 615 |
367 | 616 g_static_mutex_lock (&gftpui_common_transfer_mutex); |
129 | 617 gftp_file_transfers = g_list_remove_link (gftp_file_transfers, node); |
367 | 618 g_static_mutex_unlock (&gftpui_common_transfer_mutex); |
619 | |
320 | 620 gdk_window_set_title (gtk_widget_get_parent_window (GTK_WIDGET(dlwdw)), |
621 gftp_version); | |
129 | 622 |
1 | 623 free_tdata (tdata); |
624 } | |
625 | |
626 | |
367 | 627 static void * |
628 _gftpui_transfer_files (void *data) | |
629 { | |
630 int ret; | |
631 | |
632 pthread_detach (pthread_self ()); | |
633 ret = gftpui_common_transfer_files (data); | |
634 return (GINT_TO_POINTER(ret)); | |
635 } | |
636 | |
637 | |
1 | 638 static void |
639 create_transfer (gftp_transfer * tdata) | |
640 { | |
641 pthread_t tid; | |
642 | |
643 if (!tdata->fromreq->stopable) | |
644 { | |
297 | 645 if (GFTP_IS_SAME_HOST_START_TRANS ((gftp_window_data *) tdata->fromwdata, |
646 tdata->fromreq)) | |
647 { | |
648 gftp_swap_socks (tdata->fromreq, | |
649 ((gftp_window_data *) tdata->fromwdata)->request); | |
650 update_window (tdata->fromwdata); | |
651 } | |
652 | |
653 if (GFTP_IS_SAME_HOST_START_TRANS ((gftp_window_data *) tdata->towdata, | |
654 tdata->toreq)) | |
655 { | |
63 | 656 gftp_swap_socks (tdata->toreq, |
657 ((gftp_window_data *) tdata->towdata)->request); | |
297 | 658 update_window (tdata->towdata); |
1 | 659 } |
297 | 660 |
129 | 661 num_transfers_in_progress++; |
1 | 662 tdata->started = 1; |
663 tdata->stalled = 1; | |
129 | 664 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->user_data, 1, |
1 | 665 _("Connecting...")); |
367 | 666 pthread_create (&tid, NULL, _gftpui_transfer_files, tdata); |
1 | 667 } |
668 } | |
669 | |
670 | |
671 static void | |
672 update_file_status (gftp_transfer * tdata) | |
673 { | |
320 | 674 char totstr[100], dlstr[100], winstr[150], gotstr[50], ofstr[50]; |
246 | 675 unsigned long remaining_secs, lkbs; |
463 | 676 int hours, mins, secs, pcent, st; |
677 intptr_t show_trans_in_title; | |
1 | 678 gftp_file * tempfle; |
679 struct timeval tv; | |
320 | 680 |
129 | 681 g_static_mutex_lock (&tdata->statmutex); |
1 | 682 tempfle = tdata->curfle->data; |
683 | |
684 gettimeofday (&tv, NULL); | |
220 | 685 |
686 remaining_secs = (tdata->total_bytes - tdata->trans_bytes - tdata->resumed_bytes) / 1024; | |
246 | 687 |
688 lkbs = (unsigned long) tdata->kbs; | |
689 if (lkbs > 0) | |
690 remaining_secs /= lkbs; | |
1 | 691 |
220 | 692 hours = remaining_secs / 3600; |
693 remaining_secs -= hours * 3600; | |
694 mins = remaining_secs / 60; | |
695 remaining_secs -= mins * 60; | |
696 secs = remaining_secs; | |
1 | 697 |
698 if (hours < 0 || mins < 0 || secs < 0) | |
699 { | |
129 | 700 g_static_mutex_unlock (&tdata->statmutex); |
1 | 701 return; |
702 } | |
703 | |
246 | 704 if ((double) tdata->total_bytes > 0) |
705 pcent = (int) ((double) (tdata->trans_bytes + tdata->resumed_bytes) / (double) tdata->total_bytes * 100.0); | |
706 else | |
1 | 707 pcent = 0; |
708 | |
709 g_snprintf (totstr, sizeof (totstr), | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
710 _("%d%% complete, %02d:%02d:%02d est. time remaining. (File %ld of %ld)"), |
1 | 711 pcent, hours, mins, secs, tdata->current_file_number, |
712 tdata->numdirs + tdata->numfiles); | |
713 | |
714 *dlstr = '\0'; | |
715 if (!tdata->stalled) | |
716 { | |
717 insert_commas (tdata->curtrans + tdata->curresumed, gotstr, sizeof (gotstr)); | |
718 insert_commas (tempfle->size, ofstr, sizeof (ofstr)); | |
719 st = 1; | |
720 if (tv.tv_sec - tdata->lasttime.tv_sec <= 5) | |
721 { | |
722 if (tdata->curfle->next != NULL) | |
723 { | |
220 | 724 remaining_secs = (tempfle->size - tdata->curtrans - tdata->curresumed) / 1024; |
246 | 725 |
726 lkbs = (unsigned long) tdata->kbs; | |
727 if (lkbs > 0) | |
728 remaining_secs /= lkbs; | |
220 | 729 |
730 hours = remaining_secs / 3600; | |
731 remaining_secs -= hours * 3600; | |
732 mins = remaining_secs / 60; | |
733 remaining_secs -= mins * 60; | |
734 secs = remaining_secs; | |
1 | 735 } |
736 | |
737 if (!(hours < 0 || mins < 0 || secs < 0)) | |
738 { | |
739 g_snprintf (dlstr, sizeof (dlstr), | |
740 _("Recv %s of %s at %.2fKB/s, %02d:%02d:%02d est. time remaining"), gotstr, ofstr, tdata->kbs, hours, mins, secs); | |
741 st = 0; | |
742 } | |
743 } | |
744 | |
745 if (st) | |
746 { | |
747 tdata->stalled = 1; | |
748 g_snprintf (dlstr, sizeof (dlstr), | |
749 _("Recv %s of %s, transfer stalled, unknown time remaining"), | |
750 gotstr, ofstr); | |
751 } | |
752 } | |
753 | |
129 | 754 g_static_mutex_unlock (&tdata->statmutex); |
1 | 755 |
129 | 756 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->user_data, 1, totstr); |
320 | 757 |
758 gftp_lookup_global_option ("show_trans_in_title", &show_trans_in_title); | |
759 if (gftp_file_transfers->data == tdata && show_trans_in_title) | |
760 { | |
761 g_snprintf (winstr, sizeof(winstr), "%s: %s", gftp_version, totstr); | |
762 gdk_window_set_title (gtk_widget_get_parent_window (GTK_WIDGET(dlwdw)), | |
763 winstr); | |
764 } | |
1 | 765 |
766 if (*dlstr != '\0') | |
129 | 767 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->user_data, 1, dlstr); |
1 | 768 } |
769 | |
377 | 770 |
56 | 771 static void |
772 update_window_transfer_bytes (gftp_window_data * wdata) | |
773 { | |
774 char *tempstr, *temp1str; | |
775 | |
776 if (wdata->request->gotbytes == -1) | |
777 { | |
778 update_window_info (); | |
779 wdata->request->gotbytes = 0; | |
780 } | |
781 else | |
782 { | |
783 tempstr = insert_commas (wdata->request->gotbytes, NULL, 0); | |
784 temp1str = g_strdup_printf (_("Retrieving file names...%s bytes"), | |
785 tempstr); | |
786 gtk_label_set (GTK_LABEL (wdata->hoststxt), temp1str); | |
787 g_free (tempstr); | |
788 g_free (temp1str); | |
789 } | |
790 } | |
791 | |
1 | 792 |
48 | 793 gint |
794 update_downloads (gpointer data) | |
795 { | |
433 | 796 intptr_t do_one_transfer_at_a_time, start_transfers; |
48 | 797 GList * templist, * next; |
798 gftp_transfer * tdata; | |
799 | |
129 | 800 if (gftp_file_transfer_logs != NULL) |
48 | 801 display_cached_logs (); |
802 | |
56 | 803 if (window1.request->gotbytes != 0) |
804 update_window_transfer_bytes (&window1); | |
48 | 805 if (window2.request->gotbytes != 0) |
56 | 806 update_window_transfer_bytes (&window2); |
48 | 807 |
470 | 808 if (gftpui_common_child_process_done) |
48 | 809 check_done_process (); |
810 | |
129 | 811 for (templist = gftp_file_transfers; templist != NULL;) |
48 | 812 { |
813 tdata = templist->data; | |
814 if (tdata->ready) | |
815 { | |
129 | 816 g_static_mutex_lock (&tdata->structmutex); |
48 | 817 |
818 if (tdata->next_file) | |
819 on_next_transfer (tdata); | |
820 else if (tdata->show) | |
821 show_transfer (tdata); | |
822 else if (tdata->done) | |
823 { | |
824 next = templist->next; | |
129 | 825 g_static_mutex_unlock (&tdata->structmutex); |
48 | 826 transfer_done (templist); |
827 templist = next; | |
828 continue; | |
829 } | |
830 | |
831 if (tdata->curfle != NULL) | |
832 { | |
151 | 833 gftp_lookup_global_option ("one_transfer", |
129 | 834 &do_one_transfer_at_a_time); |
433 | 835 gftp_lookup_global_option ("start_transfers", &start_transfers); |
129 | 836 |
433 | 837 if (!tdata->started && start_transfers && |
129 | 838 (num_transfers_in_progress == 0 || !do_one_transfer_at_a_time)) |
48 | 839 create_transfer (tdata); |
840 | |
841 if (tdata->started) | |
842 update_file_status (tdata); | |
843 } | |
129 | 844 g_static_mutex_unlock (&tdata->structmutex); |
48 | 845 } |
846 templist = templist->next; | |
847 } | |
848 | |
849 gtk_timeout_add (500, update_downloads, NULL); | |
850 return (0); | |
851 } | |
852 | |
853 | |
1 | 854 void |
855 start_transfer (gpointer data) | |
856 { | |
367 | 857 gftpui_common_curtrans_data * transdata; |
1 | 858 GtkCTreeNode * node; |
859 | |
860 if (GTK_CLIST (dlwdw)->selection == NULL) | |
861 { | |
862 ftp_log (gftp_logging_misc, NULL, | |
863 _("There are no file transfers selected\n")); | |
864 return; | |
865 } | |
866 node = GTK_CLIST (dlwdw)->selection->data; | |
867 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
868 | |
129 | 869 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 870 if (!transdata->transfer->started) |
871 create_transfer (transdata->transfer); | |
129 | 872 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 873 } |
874 | |
875 | |
876 void | |
877 stop_transfer (gpointer data) | |
878 { | |
367 | 879 gftpui_common_curtrans_data * transdata; |
1 | 880 GtkCTreeNode * node; |
881 | |
882 if (GTK_CLIST (dlwdw)->selection == NULL) | |
883 { | |
884 ftp_log (gftp_logging_misc, NULL, | |
885 _("There are no file transfers selected\n")); | |
886 return; | |
887 } | |
888 node = GTK_CLIST (dlwdw)->selection->data; | |
889 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
890 | |
129 | 891 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 892 if (transdata->transfer->started) |
893 { | |
894 transdata->transfer->cancel = 1; | |
42 | 895 transdata->transfer->fromreq->cancel = 1; |
896 transdata->transfer->toreq->cancel = 1; | |
1 | 897 transdata->transfer->skip_file = 0; |
898 } | |
899 else | |
900 transdata->transfer->done = 1; | |
129 | 901 g_static_mutex_unlock (&transdata->transfer->structmutex); |
40 | 902 |
1 | 903 ftp_log (gftp_logging_misc, NULL, _("Stopping the transfer on host %s\n"), |
904 transdata->transfer->fromreq->hostname); | |
905 } | |
906 | |
907 | |
908 void | |
909 skip_transfer (gpointer data) | |
910 { | |
367 | 911 gftpui_common_curtrans_data * transdata; |
1 | 912 GtkCTreeNode * node; |
913 gftp_file * curfle; | |
40 | 914 char *file; |
1 | 915 |
916 if (GTK_CLIST (dlwdw)->selection == NULL) | |
917 { | |
918 ftp_log (gftp_logging_misc, NULL, | |
919 _("There are no file transfers selected\n")); | |
920 return; | |
921 } | |
922 node = GTK_CLIST (dlwdw)->selection->data; | |
923 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
924 | |
129 | 925 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 926 if (transdata->transfer->curfle != NULL) |
927 { | |
928 curfle = transdata->transfer->curfle->data; | |
929 if (transdata->transfer->started) | |
930 { | |
931 transdata->transfer->cancel = 1; | |
42 | 932 transdata->transfer->fromreq->cancel = 1; |
933 transdata->transfer->toreq->cancel = 1; | |
1 | 934 transdata->transfer->skip_file = 1; |
935 } | |
936 | |
937 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
40 | 938 file = curfle->file; |
1 | 939 } |
40 | 940 else |
941 file = NULL; | |
129 | 942 g_static_mutex_unlock (&transdata->transfer->structmutex); |
40 | 943 |
944 ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"), | |
945 file, transdata->transfer->fromreq->hostname); | |
1 | 946 } |
947 | |
948 | |
949 void | |
950 remove_file_transfer (gpointer data) | |
951 { | |
367 | 952 gftpui_common_curtrans_data * transdata; |
1 | 953 GtkCTreeNode * node; |
954 gftp_file * curfle; | |
955 | |
956 if (GTK_CLIST (dlwdw)->selection == NULL) | |
957 { | |
958 ftp_log (gftp_logging_misc, NULL, | |
959 _("There are no file transfers selected\n")); | |
960 return; | |
961 } | |
962 | |
963 node = GTK_CLIST (dlwdw)->selection->data; | |
964 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
965 | |
966 | |
967 if (transdata->curfle == NULL || transdata->curfle->data == NULL) | |
968 return; | |
969 | |
970 curfle = transdata->curfle->data; | |
971 | |
972 if (curfle->transfer_action & GFTP_TRANS_ACTION_SKIP) | |
973 return; | |
974 | |
129 | 975 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 976 |
977 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
978 | |
979 if (transdata->transfer->started && | |
980 transdata->curfle == transdata->transfer->curfle) | |
981 { | |
982 transdata->transfer->cancel = 1; | |
42 | 983 transdata->transfer->fromreq->cancel = 1; |
984 transdata->transfer->toreq->cancel = 1; | |
1 | 985 transdata->transfer->skip_file = 1; |
986 } | |
987 else if (transdata->curfle != transdata->transfer->curfle && | |
988 !curfle->transfer_done) | |
989 { | |
129 | 990 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), curfle->user_data, 1, |
1 | 991 _("Skipped")); |
992 transdata->transfer->total_bytes -= curfle->size; | |
993 } | |
994 | |
129 | 995 g_static_mutex_unlock (&transdata->transfer->structmutex); |
40 | 996 |
1 | 997 ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"), |
998 curfle->file, transdata->transfer->fromreq->hostname); | |
999 } | |
1000 | |
1001 | |
1002 void | |
1003 move_transfer_up (gpointer data) | |
1004 { | |
1005 GList * firstentry, * secentry, * lastentry; | |
367 | 1006 gftpui_common_curtrans_data * transdata; |
1 | 1007 GtkCTreeNode * node; |
1008 | |
1009 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1010 { | |
1011 ftp_log (gftp_logging_misc, NULL, | |
1012 _("There are no file transfers selected\n")); | |
1013 return; | |
1014 } | |
1015 node = GTK_CLIST (dlwdw)->selection->data; | |
1016 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1017 | |
1018 if (transdata->curfle == NULL) | |
1019 return; | |
1020 | |
129 | 1021 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 1022 if (transdata->curfle->prev != NULL && (!transdata->transfer->started || |
1023 (transdata->transfer->curfle != transdata->curfle && | |
1024 transdata->transfer->curfle != transdata->curfle->prev))) | |
1025 { | |
1026 if (transdata->curfle->prev->prev == NULL) | |
1027 { | |
1028 firstentry = transdata->curfle->prev; | |
1029 lastentry = transdata->curfle->next; | |
1030 transdata->transfer->files = transdata->curfle; | |
1031 transdata->curfle->next = firstentry; | |
1032 transdata->transfer->files->prev = NULL; | |
1033 firstentry->prev = transdata->curfle; | |
1034 firstentry->next = lastentry; | |
1035 if (lastentry != NULL) | |
1036 lastentry->prev = firstentry; | |
1037 } | |
1038 else | |
1039 { | |
1040 firstentry = transdata->curfle->prev->prev; | |
1041 secentry = transdata->curfle->prev; | |
1042 lastentry = transdata->curfle->next; | |
1043 firstentry->next = transdata->curfle; | |
1044 transdata->curfle->prev = firstentry; | |
1045 transdata->curfle->next = secentry; | |
1046 secentry->prev = transdata->curfle; | |
1047 secentry->next = lastentry; | |
1048 if (lastentry != NULL) | |
1049 lastentry->prev = secentry; | |
1050 } | |
1051 | |
1052 gtk_ctree_move (GTK_CTREE (dlwdw), | |
129 | 1053 ((gftp_file *) transdata->curfle->data)->user_data, |
1054 transdata->transfer->user_data, | |
1 | 1055 transdata->curfle->next != NULL ? |
129 | 1056 ((gftp_file *) transdata->curfle->next->data)->user_data: NULL); |
1 | 1057 } |
129 | 1058 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 1059 } |
1060 | |
367 | 1061 |
1 | 1062 void |
1063 move_transfer_down (gpointer data) | |
1064 { | |
1065 GList * firstentry, * secentry, * lastentry; | |
367 | 1066 gftpui_common_curtrans_data * transdata; |
1 | 1067 GtkCTreeNode * node; |
1068 | |
1069 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1070 { | |
1071 ftp_log (gftp_logging_misc, NULL, | |
1072 _("There are no file transfers selected\n")); | |
1073 return; | |
1074 } | |
1075 node = GTK_CLIST (dlwdw)->selection->data; | |
1076 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1077 | |
1078 if (transdata->curfle == NULL) | |
1079 return; | |
1080 | |
129 | 1081 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 1082 if (transdata->curfle->next != NULL && (!transdata->transfer->started || |
1083 (transdata->transfer->curfle != transdata->curfle && | |
1084 transdata->transfer->curfle != transdata->curfle->next))) | |
1085 { | |
1086 if (transdata->curfle->prev == NULL) | |
1087 { | |
1088 firstentry = transdata->curfle->next; | |
1089 lastentry = transdata->curfle->next->next; | |
1090 transdata->transfer->files = firstentry; | |
1091 transdata->transfer->files->prev = NULL; | |
1092 transdata->transfer->files->next = transdata->curfle; | |
1093 transdata->curfle->prev = transdata->transfer->files; | |
1094 transdata->curfle->next = lastentry; | |
1095 if (lastentry != NULL) | |
1096 lastentry->prev = transdata->curfle; | |
1097 } | |
1098 else | |
1099 { | |
1100 firstentry = transdata->curfle->prev; | |
1101 secentry = transdata->curfle->next; | |
1102 lastentry = transdata->curfle->next->next; | |
1103 firstentry->next = secentry; | |
1104 secentry->prev = firstentry; | |
1105 secentry->next = transdata->curfle; | |
1106 transdata->curfle->prev = secentry; | |
1107 transdata->curfle->next = lastentry; | |
1108 if (lastentry != NULL) | |
1109 lastentry->prev = transdata->curfle; | |
1110 } | |
1111 | |
1112 gtk_ctree_move (GTK_CTREE (dlwdw), | |
129 | 1113 ((gftp_file *) transdata->curfle->data)->user_data, |
1114 transdata->transfer->user_data, | |
1 | 1115 transdata->curfle->next != NULL ? |
129 | 1116 ((gftp_file *) transdata->curfle->next->data)->user_data: NULL); |
1 | 1117 } |
129 | 1118 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 1119 } |
1120 |