Mercurial > gftp.yaz
annotate src/gtk/transfer.c @ 422:38bfc112ab46
2004-3-14 Brian Masney <masneyb@gftp.org>
* lib/misc.c (expand_path) - skip over paths that are empty
* lib/misc.c (gftp_sort_filelist) - fixed NULL pointer dereference
that would occur when attempting to sort an empty filelist
(from Hans-J?rgen Sch?ler <hjschaeler@t-online.de>)
* src/uicommon/gftpui.c (_gftpui_common_thread_callback) - fix so that
retries would occur properly after a timeout
(from Nam SungHyun <namsh@kldp.org>)
* src/gtk/Makefile.am - removed unneeded localedir defination
(from Nam SungHyun <namsh@kldp.org>)
* lib/gftp.h lib/protocols.c src/gtk/gftp-gtk.c src/text/gftp-text.c -
added gftp_setup_startup_directory(). This function will expand the
startup directory so that ~ directories will work properly
* lib/rfc959.c - removed invalid response error message if the user
enters an invalid password
* src/gtk/bookmarks.c - only allow one bookmark entry to be edited at a
time. This is a design flaw in my code and I'll remove this restriction
until I have time to recode this. Also, fixed segfault that would occur
when renaming a bookmark
* src/gtk/view_dialog.c - when editing a file, make sure the file has
the right suffix so that syntax highlighting works
author | masneyb |
---|---|
date | Mon, 15 Mar 2004 18:07:15 +0000 |
parents | 14ef37b62c20 |
children | 77fffba5e170 |
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 GList * templist; | |
397 | 459 char *text[2]; |
1 | 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; | |
397 | 483 |
484 text[0] = gftpui_gtk_get_utf8_file_pos (tempfle); | |
1 | 485 if (tempfle->transfer_action == GFTP_TRANS_ACTION_SKIP) |
486 text[1] = _("Skipped"); | |
487 else | |
488 { | |
489 tdata->total_bytes += tempfle->size; | |
490 text[1] = _("Waiting..."); | |
491 } | |
492 | |
129 | 493 tempfle->user_data = gtk_ctree_insert_node (GTK_CTREE (dlwdw), |
494 tdata->user_data, | |
1 | 495 NULL, text, 5, NULL, NULL, NULL, |
496 NULL, FALSE, FALSE); | |
497 transdata = g_malloc (sizeof (*transdata)); | |
498 transdata->transfer = tdata; | |
499 transdata->curfle = templist; | |
129 | 500 gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), tempfle->user_data, |
501 transdata); | |
1 | 502 } |
503 | |
504 if (!tdata->toreq->stopable && tdata->toreq->need_userpass && | |
505 (tdata->toreq->password == NULL || *tdata->toreq->password == '\0')) | |
506 { | |
507 tdata->toreq->stopable = 1; | |
508 MakeEditDialog (_("Enter Password"), | |
509 _("Please enter your password for this site"), NULL, 0, | |
19 | 510 NULL, gftp_dialog_button_connect, |
511 get_trans_password, tdata->toreq, | |
512 cancel_get_trans_password, tdata); | |
1 | 513 } |
514 | |
515 if (!tdata->fromreq->stopable && tdata->fromreq->need_userpass && | |
516 (tdata->fromreq->password == NULL || *tdata->fromreq->password == '\0')) | |
517 { | |
518 tdata->fromreq->stopable = 1; | |
519 MakeEditDialog (_("Enter Password"), | |
520 _("Please enter your password for this site"), NULL, 0, | |
19 | 521 NULL, gftp_dialog_button_connect, |
522 get_trans_password, tdata->fromreq, | |
523 cancel_get_trans_password, tdata); | |
1 | 524 } |
525 } | |
526 | |
527 | |
528 static void | |
529 transfer_done (GList * node) | |
530 { | |
367 | 531 gftpui_common_curtrans_data * transdata; |
1 | 532 gftp_request * fromreq; |
533 gftp_transfer * tdata; | |
534 gftp_file * tempfle; | |
535 GList * templist; | |
536 | |
537 tdata = node->data; | |
538 if (tdata->started) | |
539 { | |
56 | 540 fromreq = tdata->fromwdata != NULL ? ((gftp_window_data *) tdata->fromwdata)->request : NULL; |
297 | 541 |
542 if (GFTP_IS_SAME_HOST_STOP_TRANS ((gftp_window_data *) tdata->fromwdata, | |
543 tdata->fromreq)) | |
309 | 544 { |
545 gftp_copy_param_options (((gftp_window_data *) tdata->fromwdata)->request, tdata->fromreq); | |
546 | |
547 gftp_swap_socks (((gftp_window_data *) tdata->fromwdata)->request, | |
548 tdata->fromreq); | |
549 } | |
1 | 550 else |
297 | 551 gftp_disconnect (tdata->fromreq); |
552 | |
553 if (GFTP_IS_SAME_HOST_STOP_TRANS ((gftp_window_data *) tdata->towdata, | |
554 tdata->toreq)) | |
309 | 555 { |
556 gftp_copy_param_options (((gftp_window_data *) tdata->towdata)->request, tdata->toreq); | |
557 | |
558 gftp_swap_socks (((gftp_window_data *) tdata->towdata)->request, | |
559 tdata->toreq); | |
560 } | |
297 | 561 else |
562 gftp_disconnect (tdata->toreq); | |
1 | 563 |
305 | 564 if (tdata->towdata != NULL && compare_request (tdata->toreq, |
565 ((gftp_window_data *) tdata->towdata)->request, 1)) | |
341 | 566 gftpui_refresh (tdata->towdata); |
305 | 567 |
129 | 568 num_transfers_in_progress--; |
1 | 569 } |
570 | |
2
a171df6764a7
* Fixed crash if you was already transfering a file, and you started another
masneyb
parents:
1
diff
changeset
|
571 if (!tdata->show && tdata->started) |
1 | 572 { |
129 | 573 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), |
574 tdata->user_data); | |
1 | 575 if (transdata != NULL) |
576 g_free (transdata); | |
577 | |
578 for (templist = tdata->files; templist != NULL; templist = templist->next) | |
579 { | |
580 tempfle = templist->data; | |
129 | 581 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), |
582 tempfle->user_data); | |
1 | 583 if (transdata != NULL) |
584 g_free (transdata); | |
585 } | |
586 | |
129 | 587 gtk_ctree_remove_node (GTK_CTREE (dlwdw), tdata->user_data); |
1 | 588 } |
129 | 589 |
367 | 590 g_static_mutex_lock (&gftpui_common_transfer_mutex); |
129 | 591 gftp_file_transfers = g_list_remove_link (gftp_file_transfers, node); |
367 | 592 g_static_mutex_unlock (&gftpui_common_transfer_mutex); |
593 | |
320 | 594 gdk_window_set_title (gtk_widget_get_parent_window (GTK_WIDGET(dlwdw)), |
595 gftp_version); | |
129 | 596 |
1 | 597 free_tdata (tdata); |
598 } | |
599 | |
600 | |
367 | 601 static void * |
602 _gftpui_transfer_files (void *data) | |
603 { | |
604 int ret; | |
605 | |
606 pthread_detach (pthread_self ()); | |
607 ret = gftpui_common_transfer_files (data); | |
608 return (GINT_TO_POINTER(ret)); | |
609 } | |
610 | |
611 | |
1 | 612 static void |
613 create_transfer (gftp_transfer * tdata) | |
614 { | |
615 pthread_t tid; | |
616 | |
617 if (!tdata->fromreq->stopable) | |
618 { | |
297 | 619 if (GFTP_IS_SAME_HOST_START_TRANS ((gftp_window_data *) tdata->fromwdata, |
620 tdata->fromreq)) | |
621 { | |
622 gftp_swap_socks (tdata->fromreq, | |
623 ((gftp_window_data *) tdata->fromwdata)->request); | |
624 update_window (tdata->fromwdata); | |
625 } | |
626 | |
627 if (GFTP_IS_SAME_HOST_START_TRANS ((gftp_window_data *) tdata->towdata, | |
628 tdata->toreq)) | |
629 { | |
63 | 630 gftp_swap_socks (tdata->toreq, |
631 ((gftp_window_data *) tdata->towdata)->request); | |
297 | 632 update_window (tdata->towdata); |
1 | 633 } |
297 | 634 |
129 | 635 num_transfers_in_progress++; |
1 | 636 tdata->started = 1; |
637 tdata->stalled = 1; | |
129 | 638 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->user_data, 1, |
1 | 639 _("Connecting...")); |
367 | 640 pthread_create (&tid, NULL, _gftpui_transfer_files, tdata); |
1 | 641 } |
642 } | |
643 | |
644 | |
645 static void | |
646 update_file_status (gftp_transfer * tdata) | |
647 { | |
320 | 648 char totstr[100], dlstr[100], winstr[150], gotstr[50], ofstr[50]; |
649 int hours, mins, secs, pcent, st, show_trans_in_title; | |
246 | 650 unsigned long remaining_secs, lkbs; |
1 | 651 gftp_file * tempfle; |
652 struct timeval tv; | |
320 | 653 |
129 | 654 g_static_mutex_lock (&tdata->statmutex); |
1 | 655 tempfle = tdata->curfle->data; |
656 | |
657 gettimeofday (&tv, NULL); | |
220 | 658 |
659 remaining_secs = (tdata->total_bytes - tdata->trans_bytes - tdata->resumed_bytes) / 1024; | |
246 | 660 |
661 lkbs = (unsigned long) tdata->kbs; | |
662 if (lkbs > 0) | |
663 remaining_secs /= lkbs; | |
1 | 664 |
220 | 665 hours = remaining_secs / 3600; |
666 remaining_secs -= hours * 3600; | |
667 mins = remaining_secs / 60; | |
668 remaining_secs -= mins * 60; | |
669 secs = remaining_secs; | |
1 | 670 |
671 if (hours < 0 || mins < 0 || secs < 0) | |
672 { | |
129 | 673 g_static_mutex_unlock (&tdata->statmutex); |
1 | 674 return; |
675 } | |
676 | |
246 | 677 if ((double) tdata->total_bytes > 0) |
678 pcent = (int) ((double) (tdata->trans_bytes + tdata->resumed_bytes) / (double) tdata->total_bytes * 100.0); | |
679 else | |
1 | 680 pcent = 0; |
681 | |
682 g_snprintf (totstr, sizeof (totstr), | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
683 _("%d%% complete, %02d:%02d:%02d est. time remaining. (File %ld of %ld)"), |
1 | 684 pcent, hours, mins, secs, tdata->current_file_number, |
685 tdata->numdirs + tdata->numfiles); | |
686 | |
687 *dlstr = '\0'; | |
688 if (!tdata->stalled) | |
689 { | |
690 insert_commas (tdata->curtrans + tdata->curresumed, gotstr, sizeof (gotstr)); | |
691 insert_commas (tempfle->size, ofstr, sizeof (ofstr)); | |
692 st = 1; | |
693 if (tv.tv_sec - tdata->lasttime.tv_sec <= 5) | |
694 { | |
695 if (tdata->curfle->next != NULL) | |
696 { | |
220 | 697 remaining_secs = (tempfle->size - tdata->curtrans - tdata->curresumed) / 1024; |
246 | 698 |
699 lkbs = (unsigned long) tdata->kbs; | |
700 if (lkbs > 0) | |
701 remaining_secs /= lkbs; | |
220 | 702 |
703 hours = remaining_secs / 3600; | |
704 remaining_secs -= hours * 3600; | |
705 mins = remaining_secs / 60; | |
706 remaining_secs -= mins * 60; | |
707 secs = remaining_secs; | |
1 | 708 } |
709 | |
710 if (!(hours < 0 || mins < 0 || secs < 0)) | |
711 { | |
712 g_snprintf (dlstr, sizeof (dlstr), | |
713 _("Recv %s of %s at %.2fKB/s, %02d:%02d:%02d est. time remaining"), gotstr, ofstr, tdata->kbs, hours, mins, secs); | |
714 st = 0; | |
715 } | |
716 } | |
717 | |
718 if (st) | |
719 { | |
720 tdata->stalled = 1; | |
721 g_snprintf (dlstr, sizeof (dlstr), | |
722 _("Recv %s of %s, transfer stalled, unknown time remaining"), | |
723 gotstr, ofstr); | |
724 } | |
725 } | |
726 | |
129 | 727 g_static_mutex_unlock (&tdata->statmutex); |
1 | 728 |
129 | 729 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->user_data, 1, totstr); |
320 | 730 |
731 gftp_lookup_global_option ("show_trans_in_title", &show_trans_in_title); | |
732 if (gftp_file_transfers->data == tdata && show_trans_in_title) | |
733 { | |
734 g_snprintf (winstr, sizeof(winstr), "%s: %s", gftp_version, totstr); | |
735 gdk_window_set_title (gtk_widget_get_parent_window (GTK_WIDGET(dlwdw)), | |
736 winstr); | |
737 } | |
1 | 738 |
739 if (*dlstr != '\0') | |
129 | 740 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->user_data, 1, dlstr); |
1 | 741 } |
742 | |
377 | 743 |
56 | 744 static void |
745 update_window_transfer_bytes (gftp_window_data * wdata) | |
746 { | |
747 char *tempstr, *temp1str; | |
748 | |
749 if (wdata->request->gotbytes == -1) | |
750 { | |
751 update_window_info (); | |
752 wdata->request->gotbytes = 0; | |
753 } | |
754 else | |
755 { | |
756 tempstr = insert_commas (wdata->request->gotbytes, NULL, 0); | |
757 temp1str = g_strdup_printf (_("Retrieving file names...%s bytes"), | |
758 tempstr); | |
759 gtk_label_set (GTK_LABEL (wdata->hoststxt), temp1str); | |
760 g_free (tempstr); | |
761 g_free (temp1str); | |
762 } | |
763 } | |
764 | |
1 | 765 |
48 | 766 gint |
767 update_downloads (gpointer data) | |
768 { | |
326 | 769 intptr_t do_one_transfer_at_a_time; |
48 | 770 GList * templist, * next; |
771 gftp_transfer * tdata; | |
772 | |
129 | 773 if (gftp_file_transfer_logs != NULL) |
48 | 774 display_cached_logs (); |
775 | |
56 | 776 if (window1.request->gotbytes != 0) |
777 update_window_transfer_bytes (&window1); | |
48 | 778 if (window2.request->gotbytes != 0) |
56 | 779 update_window_transfer_bytes (&window2); |
48 | 780 |
781 if (viewedit_process_done) | |
782 check_done_process (); | |
783 | |
129 | 784 for (templist = gftp_file_transfers; templist != NULL;) |
48 | 785 { |
786 tdata = templist->data; | |
787 if (tdata->ready) | |
788 { | |
129 | 789 g_static_mutex_lock (&tdata->structmutex); |
48 | 790 |
791 if (tdata->next_file) | |
792 on_next_transfer (tdata); | |
793 else if (tdata->show) | |
794 show_transfer (tdata); | |
795 else if (tdata->done) | |
796 { | |
797 next = templist->next; | |
129 | 798 g_static_mutex_unlock (&tdata->structmutex); |
48 | 799 transfer_done (templist); |
800 templist = next; | |
801 continue; | |
802 } | |
803 | |
804 if (tdata->curfle != NULL) | |
805 { | |
151 | 806 gftp_lookup_global_option ("one_transfer", |
129 | 807 &do_one_transfer_at_a_time); |
808 | |
207 | 809 if (!tdata->started && |
129 | 810 (num_transfers_in_progress == 0 || !do_one_transfer_at_a_time)) |
48 | 811 create_transfer (tdata); |
812 | |
813 if (tdata->started) | |
814 update_file_status (tdata); | |
815 } | |
129 | 816 g_static_mutex_unlock (&tdata->structmutex); |
48 | 817 } |
818 templist = templist->next; | |
819 } | |
820 | |
821 gtk_timeout_add (500, update_downloads, NULL); | |
822 return (0); | |
823 } | |
824 | |
825 | |
1 | 826 void |
827 start_transfer (gpointer data) | |
828 { | |
367 | 829 gftpui_common_curtrans_data * transdata; |
1 | 830 GtkCTreeNode * node; |
831 | |
832 if (GTK_CLIST (dlwdw)->selection == NULL) | |
833 { | |
834 ftp_log (gftp_logging_misc, NULL, | |
835 _("There are no file transfers selected\n")); | |
836 return; | |
837 } | |
838 node = GTK_CLIST (dlwdw)->selection->data; | |
839 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
840 | |
129 | 841 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 842 if (!transdata->transfer->started) |
843 create_transfer (transdata->transfer); | |
129 | 844 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 845 } |
846 | |
847 | |
848 void | |
849 stop_transfer (gpointer data) | |
850 { | |
367 | 851 gftpui_common_curtrans_data * transdata; |
1 | 852 GtkCTreeNode * node; |
853 | |
854 if (GTK_CLIST (dlwdw)->selection == NULL) | |
855 { | |
856 ftp_log (gftp_logging_misc, NULL, | |
857 _("There are no file transfers selected\n")); | |
858 return; | |
859 } | |
860 node = GTK_CLIST (dlwdw)->selection->data; | |
861 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
862 | |
129 | 863 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 864 if (transdata->transfer->started) |
865 { | |
866 transdata->transfer->cancel = 1; | |
42 | 867 transdata->transfer->fromreq->cancel = 1; |
868 transdata->transfer->toreq->cancel = 1; | |
1 | 869 transdata->transfer->skip_file = 0; |
870 } | |
871 else | |
872 transdata->transfer->done = 1; | |
129 | 873 g_static_mutex_unlock (&transdata->transfer->structmutex); |
40 | 874 |
1 | 875 ftp_log (gftp_logging_misc, NULL, _("Stopping the transfer on host %s\n"), |
876 transdata->transfer->fromreq->hostname); | |
877 } | |
878 | |
879 | |
880 void | |
881 skip_transfer (gpointer data) | |
882 { | |
367 | 883 gftpui_common_curtrans_data * transdata; |
1 | 884 GtkCTreeNode * node; |
885 gftp_file * curfle; | |
40 | 886 char *file; |
1 | 887 |
888 if (GTK_CLIST (dlwdw)->selection == NULL) | |
889 { | |
890 ftp_log (gftp_logging_misc, NULL, | |
891 _("There are no file transfers selected\n")); | |
892 return; | |
893 } | |
894 node = GTK_CLIST (dlwdw)->selection->data; | |
895 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
896 | |
129 | 897 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 898 if (transdata->transfer->curfle != NULL) |
899 { | |
900 curfle = transdata->transfer->curfle->data; | |
901 if (transdata->transfer->started) | |
902 { | |
903 transdata->transfer->cancel = 1; | |
42 | 904 transdata->transfer->fromreq->cancel = 1; |
905 transdata->transfer->toreq->cancel = 1; | |
1 | 906 transdata->transfer->skip_file = 1; |
907 } | |
908 | |
909 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
40 | 910 file = curfle->file; |
1 | 911 } |
40 | 912 else |
913 file = NULL; | |
129 | 914 g_static_mutex_unlock (&transdata->transfer->structmutex); |
40 | 915 |
916 ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"), | |
917 file, transdata->transfer->fromreq->hostname); | |
1 | 918 } |
919 | |
920 | |
921 void | |
922 remove_file_transfer (gpointer data) | |
923 { | |
367 | 924 gftpui_common_curtrans_data * transdata; |
1 | 925 GtkCTreeNode * node; |
926 gftp_file * curfle; | |
927 | |
928 if (GTK_CLIST (dlwdw)->selection == NULL) | |
929 { | |
930 ftp_log (gftp_logging_misc, NULL, | |
931 _("There are no file transfers selected\n")); | |
932 return; | |
933 } | |
934 | |
935 node = GTK_CLIST (dlwdw)->selection->data; | |
936 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
937 | |
938 | |
939 if (transdata->curfle == NULL || transdata->curfle->data == NULL) | |
940 return; | |
941 | |
942 curfle = transdata->curfle->data; | |
943 | |
944 if (curfle->transfer_action & GFTP_TRANS_ACTION_SKIP) | |
945 return; | |
946 | |
129 | 947 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 948 |
949 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
950 | |
951 if (transdata->transfer->started && | |
952 transdata->curfle == transdata->transfer->curfle) | |
953 { | |
954 transdata->transfer->cancel = 1; | |
42 | 955 transdata->transfer->fromreq->cancel = 1; |
956 transdata->transfer->toreq->cancel = 1; | |
1 | 957 transdata->transfer->skip_file = 1; |
958 } | |
959 else if (transdata->curfle != transdata->transfer->curfle && | |
960 !curfle->transfer_done) | |
961 { | |
129 | 962 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), curfle->user_data, 1, |
1 | 963 _("Skipped")); |
964 transdata->transfer->total_bytes -= curfle->size; | |
965 } | |
966 | |
129 | 967 g_static_mutex_unlock (&transdata->transfer->structmutex); |
40 | 968 |
1 | 969 ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"), |
970 curfle->file, transdata->transfer->fromreq->hostname); | |
971 } | |
972 | |
973 | |
974 void | |
975 move_transfer_up (gpointer data) | |
976 { | |
977 GList * firstentry, * secentry, * lastentry; | |
367 | 978 gftpui_common_curtrans_data * transdata; |
1 | 979 GtkCTreeNode * node; |
980 | |
981 if (GTK_CLIST (dlwdw)->selection == NULL) | |
982 { | |
983 ftp_log (gftp_logging_misc, NULL, | |
984 _("There are no file transfers selected\n")); | |
985 return; | |
986 } | |
987 node = GTK_CLIST (dlwdw)->selection->data; | |
988 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
989 | |
990 if (transdata->curfle == NULL) | |
991 return; | |
992 | |
129 | 993 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 994 if (transdata->curfle->prev != NULL && (!transdata->transfer->started || |
995 (transdata->transfer->curfle != transdata->curfle && | |
996 transdata->transfer->curfle != transdata->curfle->prev))) | |
997 { | |
998 if (transdata->curfle->prev->prev == NULL) | |
999 { | |
1000 firstentry = transdata->curfle->prev; | |
1001 lastentry = transdata->curfle->next; | |
1002 transdata->transfer->files = transdata->curfle; | |
1003 transdata->curfle->next = firstentry; | |
1004 transdata->transfer->files->prev = NULL; | |
1005 firstentry->prev = transdata->curfle; | |
1006 firstentry->next = lastentry; | |
1007 if (lastentry != NULL) | |
1008 lastentry->prev = firstentry; | |
1009 } | |
1010 else | |
1011 { | |
1012 firstentry = transdata->curfle->prev->prev; | |
1013 secentry = transdata->curfle->prev; | |
1014 lastentry = transdata->curfle->next; | |
1015 firstentry->next = transdata->curfle; | |
1016 transdata->curfle->prev = firstentry; | |
1017 transdata->curfle->next = secentry; | |
1018 secentry->prev = transdata->curfle; | |
1019 secentry->next = lastentry; | |
1020 if (lastentry != NULL) | |
1021 lastentry->prev = secentry; | |
1022 } | |
1023 | |
1024 gtk_ctree_move (GTK_CTREE (dlwdw), | |
129 | 1025 ((gftp_file *) transdata->curfle->data)->user_data, |
1026 transdata->transfer->user_data, | |
1 | 1027 transdata->curfle->next != NULL ? |
129 | 1028 ((gftp_file *) transdata->curfle->next->data)->user_data: NULL); |
1 | 1029 } |
129 | 1030 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 1031 } |
1032 | |
367 | 1033 |
1 | 1034 void |
1035 move_transfer_down (gpointer data) | |
1036 { | |
1037 GList * firstentry, * secentry, * lastentry; | |
367 | 1038 gftpui_common_curtrans_data * transdata; |
1 | 1039 GtkCTreeNode * node; |
1040 | |
1041 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1042 { | |
1043 ftp_log (gftp_logging_misc, NULL, | |
1044 _("There are no file transfers selected\n")); | |
1045 return; | |
1046 } | |
1047 node = GTK_CLIST (dlwdw)->selection->data; | |
1048 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1049 | |
1050 if (transdata->curfle == NULL) | |
1051 return; | |
1052 | |
129 | 1053 g_static_mutex_lock (&transdata->transfer->structmutex); |
1 | 1054 if (transdata->curfle->next != NULL && (!transdata->transfer->started || |
1055 (transdata->transfer->curfle != transdata->curfle && | |
1056 transdata->transfer->curfle != transdata->curfle->next))) | |
1057 { | |
1058 if (transdata->curfle->prev == NULL) | |
1059 { | |
1060 firstentry = transdata->curfle->next; | |
1061 lastentry = transdata->curfle->next->next; | |
1062 transdata->transfer->files = firstentry; | |
1063 transdata->transfer->files->prev = NULL; | |
1064 transdata->transfer->files->next = transdata->curfle; | |
1065 transdata->curfle->prev = transdata->transfer->files; | |
1066 transdata->curfle->next = lastentry; | |
1067 if (lastentry != NULL) | |
1068 lastentry->prev = transdata->curfle; | |
1069 } | |
1070 else | |
1071 { | |
1072 firstentry = transdata->curfle->prev; | |
1073 secentry = transdata->curfle->next; | |
1074 lastentry = transdata->curfle->next->next; | |
1075 firstentry->next = secentry; | |
1076 secentry->prev = firstentry; | |
1077 secentry->next = transdata->curfle; | |
1078 transdata->curfle->prev = secentry; | |
1079 transdata->curfle->next = lastentry; | |
1080 if (lastentry != NULL) | |
1081 lastentry->prev = transdata->curfle; | |
1082 } | |
1083 | |
1084 gtk_ctree_move (GTK_CTREE (dlwdw), | |
129 | 1085 ((gftp_file *) transdata->curfle->data)->user_data, |
1086 transdata->transfer->user_data, | |
1 | 1087 transdata->curfle->next != NULL ? |
129 | 1088 ((gftp_file *) transdata->curfle->next->data)->user_data: NULL); |
1 | 1089 } |
129 | 1090 g_static_mutex_unlock (&transdata->transfer->structmutex); |
1 | 1091 } |
1092 |