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