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