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