Mercurial > gftp.yaz
annotate src/gtk/transfer.c @ 31:d930e06af9ae
2002-10-03 Brian Masney <masneyb@gftp.org>
* src/gtk/gftp-gtk.c - call g_thread_init (NULL)
* src/gtk/delete_dialog.c, src/gtk/misc-gtk.c, src/gtk/transfer.c -
call gdk_threads_enter() and gdk_threads_leave()
author | masneyb |
---|---|
date | Thu, 03 Oct 2002 12:05:54 +0000 |
parents | 3b2dcdefc7e9 |
children | c8ec7877432e |
rev | line source |
---|---|
1 | 1 /*****************************************************************************/ |
2 /* transfer.c - functions to handle transfering files */ | |
3 /* Copyright (C) 1998-2002 Brian Masney <masneyb@gftp.org> */ | |
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> | |
21 | |
22 static void *getdir_thread ( void *data ); | |
23 static void *connect_thread ( void *data ); | |
24 static void on_next_transfer ( gftp_transfer * tdata ); | |
25 static void show_transfer ( gftp_transfer * tdata ); | |
26 static void transfer_done ( GList * node ); | |
27 static void create_transfer ( gftp_transfer * tdata ); | |
28 static void update_file_status ( gftp_transfer * tdata ); | |
29 static void trans_selectall ( GtkWidget * widget, | |
30 gpointer data ); | |
31 static void trans_unselectall ( GtkWidget * widget, | |
32 gpointer data ); | |
33 static void overwrite ( GtkWidget * widget, | |
34 gpointer data ); | |
35 static void resume ( GtkWidget * widget, | |
36 gpointer data ); | |
37 static void skip ( GtkWidget * widget, | |
38 gpointer data ); | |
39 static void ok ( GtkWidget * widget, | |
40 gpointer data ); | |
41 static void cancel ( GtkWidget * widget, | |
42 gpointer data ); | |
43 static void gftp_gtk_calc_kbs ( gftp_transfer * tdata, | |
44 ssize_t num_read ); | |
45 static void check_done_process ( void ); | |
19 | 46 static void do_upload ( gftp_viewedit_data * ve_proc, |
47 gftp_dialog_data * ddata ); | |
48 static void dont_upload ( gftp_viewedit_data * ve_proc, | |
49 gftp_dialog_data * ddata ); | |
50 static void free_edit_data ( gftp_viewedit_data *ve_proc ); | |
1 | 51 static int get_status ( gftp_transfer * tdata, |
52 ssize_t num_read ); | |
53 static void wakeup_main_thread ( gpointer data, | |
54 gint source, | |
55 GdkInputCondition condition ); | |
56 static gint setup_wakeup_main_thread ( gftp_request * request ); | |
57 static void teardown_wakeup_main_thread ( gftp_request * request, | |
58 gint handler ); | |
59 static mode_t parse_attribs ( char *attribs ); | |
60 static void remove_file ( char *filename ); | |
61 static RETSIGTYPE sig_connquit ( int signo ); | |
62 | |
63 static sigjmp_buf connenvir; | |
64 static GtkWidget * dialog; | |
65 | |
66 int | |
67 ftp_list_files (gftp_window_data * wdata, int usecache) | |
68 { | |
69 guint handler; | |
70 void *success; | |
71 | |
72 gtk_label_set (GTK_LABEL (wdata->hoststxt), _("Receiving file names...")); | |
73 fix_display (); | |
74 wdata->show_selected = 0; | |
75 if (wdata->files == NULL) | |
76 { | |
77 if (check_reconnect (wdata) < 0) | |
78 return (0); | |
79 | |
80 gtk_clist_freeze (GTK_CLIST (wdata->listbox)); | |
81 wdata->request->stopable = 1; | |
82 if (wdata->request->use_threads) | |
83 { | |
84 gtk_widget_set_sensitive (stop_btn, 1); | |
85 | |
86 handler = setup_wakeup_main_thread (wdata->request); | |
87 pthread_create (&wdata->tid, NULL, getdir_thread, wdata->request); | |
88 while (wdata->request->stopable) | |
31 | 89 { |
90 gdk_threads_leave (); | |
91 g_main_iteration (TRUE); | |
92 gdk_threads_enter (); | |
93 } | |
1 | 94 teardown_wakeup_main_thread (wdata->request, handler); |
95 | |
96 pthread_join (wdata->tid, &success); | |
97 gtk_widget_set_sensitive (stop_btn, 0); | |
98 } | |
99 else | |
100 success = getdir_thread (wdata->request); | |
101 wdata->files = success; | |
102 gtk_clist_thaw (GTK_CLIST (wdata->listbox)); | |
103 memset (&wdata->tid, 0, sizeof (wdata->tid)); | |
104 } | |
105 | |
106 if (wdata->files == NULL || !GFTP_IS_CONNECTED (wdata->request)) | |
107 { | |
108 disconnect (wdata); | |
109 return (0); | |
110 } | |
111 | |
112 wdata->sorted = 0; | |
113 sortrows (GTK_CLIST (wdata->listbox), wdata->sortcol, (gpointer) wdata); | |
114 if (IS_NONE_SELECTED (wdata)) | |
115 gtk_clist_select_row (GTK_CLIST (wdata->listbox), 0, 0); | |
116 return (1); | |
117 } | |
118 | |
119 | |
120 static void * | |
121 getdir_thread (void * data) | |
122 { | |
123 int sj, havedotdot, got; | |
124 gftp_request * request; | |
125 gftp_file * fle; | |
126 GList * files; | |
127 | |
128 request = data; | |
129 request->user_data = (void *) 0x1; | |
130 | |
131 if (request->use_threads) | |
132 { | |
133 sj = sigsetjmp (connenvir, 1); | |
134 signal (SIGINT, sig_connquit); | |
135 signal (SIGALRM, sig_connquit); | |
136 } | |
137 else | |
138 sj = 0; | |
139 | |
140 files = NULL; | |
141 if (sj == 0 || sj == 2) | |
142 { | |
143 if (gftp_list_files (request) != 0 || !GFTP_IS_CONNECTED (request)) | |
144 { | |
145 if (request->use_threads) | |
146 { | |
147 signal (SIGINT, SIG_DFL); | |
148 signal (SIGALRM, SIG_IGN); | |
149 } | |
150 request->user_data = NULL; | |
151 request->stopable = 0; | |
152 if (request->wakeup_main_thread[1] > 0) | |
153 write (request->wakeup_main_thread[1], " ", 1); | |
154 return (NULL); | |
155 } | |
156 | |
157 request->gotbytes = 0; | |
158 havedotdot = 0; | |
159 fle = g_malloc0 (sizeof (*fle)); | |
160 while ((got = gftp_get_next_file (request, NULL, fle)) > 0) | |
161 { | |
162 request->gotbytes += got; | |
163 if (strcmp (fle->file, ".") == 0) | |
164 { | |
165 gftp_file_destroy (fle); | |
166 continue; | |
167 } | |
168 else if (strcmp (fle->file, "..") == 0) | |
169 havedotdot = 1; | |
170 | |
171 files = g_list_append (files, fle); | |
172 fle = g_malloc0 (sizeof (*fle)); | |
173 } | |
174 g_free (fle); | |
175 | |
176 if (!GFTP_IS_CONNECTED (request)) | |
177 { | |
178 if (request->use_threads) | |
179 { | |
180 signal (SIGINT, SIG_DFL); | |
181 signal (SIGALRM, SIG_IGN); | |
182 } | |
183 request->user_data = NULL; | |
184 request->stopable = 0; | |
185 if (request->wakeup_main_thread[1] > 0) | |
186 write (request->wakeup_main_thread[1], " ", 1); | |
187 return (NULL); | |
188 } | |
189 | |
190 gftp_end_transfer (request); | |
191 request->gotbytes = -1; | |
192 | |
193 if (!havedotdot) | |
194 { | |
195 fle = g_malloc0 (sizeof (*fle)); | |
196 fle->file = g_malloc (3); | |
197 strcpy (fle->file, ".."); | |
198 fle->user = g_malloc0 (1); | |
199 fle->group = g_malloc0 (1); | |
200 fle->attribs = g_malloc0 (1); | |
201 *fle->attribs = '\0'; | |
202 fle->isdir = 1; | |
203 files = g_list_prepend (files, fle); | |
204 } | |
205 } | |
206 | |
207 request->user_data = NULL; | |
208 if (request->use_threads) | |
209 { | |
210 signal (SIGINT, SIG_DFL); | |
211 signal (SIGALRM, SIG_IGN); | |
212 } | |
213 request->stopable = 0; | |
214 if (request->wakeup_main_thread[1] > 0) | |
215 write (request->wakeup_main_thread[1], " ", 1); | |
216 return (files); | |
217 } | |
218 | |
219 | |
19 | 220 static void |
221 try_connect_again (gftp_request * request, gftp_dialog_data * ddata) | |
222 { | |
223 gftp_set_password (request, gtk_entry_get_text (GTK_ENTRY (ddata->edit))); | |
224 request->stopable = 0; | |
225 } | |
226 | |
227 | |
228 static void | |
229 dont_connect_again (gftp_request * request, gftp_dialog_data * ddata) | |
230 { | |
231 request->stopable = 0; | |
232 } | |
233 | |
234 | |
1 | 235 int |
236 ftp_connect (gftp_window_data * wdata, gftp_request * request, int getdir) | |
237 { | |
238 int success; | |
239 guint handler; | |
240 void *ret; | |
241 | |
242 ret = 0; | |
243 if (wdata->request == request) | |
244 { | |
245 gtk_label_set (GTK_LABEL (wdata->hoststxt), _("Connecting...")); | |
246 } | |
247 | |
7 | 248 if (request->need_userpass && request->username != NULL && |
249 *request->username != '\0' && | |
250 (request->password == NULL || *request->password == '\0')) | |
1 | 251 { |
252 if (wdata && wdata->request == request) | |
253 { | |
254 request->stopable = 1; | |
255 MakeEditDialog (_("Enter Password"), | |
256 _("Please enter your password for this site"), NULL, | |
19 | 257 0, NULL, gftp_dialog_button_connect, |
258 try_connect_again, request, | |
259 dont_connect_again, request); | |
31 | 260 |
1 | 261 while (request->stopable) |
31 | 262 { |
263 gdk_threads_leave (); | |
264 g_main_iteration (TRUE); | |
265 gdk_threads_enter (); | |
266 } | |
1 | 267 |
268 if (GFTP_GET_PASSWORD (request) == NULL || | |
269 *GFTP_GET_PASSWORD (request) == '\0') | |
270 return (0); | |
271 } | |
272 else | |
273 gftp_set_password (request, ""); | |
274 } | |
275 | |
276 if (wdata && wdata->request == request && request->use_threads) | |
277 { | |
278 request->stopable = 1; | |
279 if (wdata) | |
280 gtk_clist_freeze (GTK_CLIST (wdata->listbox)); | |
281 gtk_widget_set_sensitive (stop_btn, 1); | |
282 pthread_create (&wdata->tid, NULL, connect_thread, request); | |
283 | |
284 handler = setup_wakeup_main_thread (wdata->request); | |
285 while (request->stopable) | |
31 | 286 { |
287 gdk_threads_leave (); | |
288 g_main_iteration (TRUE); | |
289 gdk_threads_enter (); | |
290 } | |
1 | 291 pthread_join (wdata->tid, &ret); |
292 teardown_wakeup_main_thread (wdata->request, handler); | |
293 | |
294 gtk_widget_set_sensitive (stop_btn, 0); | |
295 if (wdata) | |
296 gtk_clist_thaw (GTK_CLIST (wdata->listbox)); | |
297 } | |
298 else | |
299 ret = connect_thread (request); | |
300 success = (int) ret; | |
301 memset (&wdata->tid, 0, sizeof (wdata->tid)); | |
302 | |
303 if (!GFTP_IS_CONNECTED (wdata->request)) | |
304 disconnect (wdata); | |
305 else if (success) | |
306 { | |
307 ftp_list_files (wdata, 1); | |
308 if (!GFTP_IS_CONNECTED (wdata->request)) | |
309 disconnect (wdata); | |
310 } | |
311 | |
312 return (success); | |
313 } | |
314 | |
315 | |
316 static void * | |
317 connect_thread (void *data) | |
318 { | |
319 static int conn_num; | |
320 gftp_request * request; | |
321 int ret, sj; | |
322 | |
323 request = data; | |
324 request->user_data = (void *) 0x1; | |
325 | |
326 conn_num = 0; | |
327 if (request->use_threads) | |
328 { | |
329 sj = sigsetjmp (connenvir, 1); | |
330 signal (SIGINT, sig_connquit); | |
331 signal (SIGALRM, sig_connquit); | |
332 } | |
333 else | |
334 sj = 0; | |
335 | |
336 ret = 0; | |
337 if (sj != 0) | |
338 { | |
339 ret = 0; | |
340 gftp_disconnect (request); | |
341 } | |
342 | |
343 while (sj != 1 && (request->retries == 0 || conn_num < request->retries)) | |
344 { | |
345 conn_num++; | |
346 if (request->network_timeout > 0) | |
347 alarm (request->network_timeout); | |
348 ret = gftp_connect (request) == 0; | |
349 alarm (0); | |
350 | |
351 if (ret) | |
352 break; | |
353 else if (request->retries == 0 || conn_num < request->retries) | |
354 { | |
355 request->logging_function (gftp_logging_misc, request->user_data, | |
356 _("Waiting %d seconds until trying to connect again\n"), | |
357 request->sleep_time); | |
358 alarm (request->sleep_time); | |
359 pause (); | |
360 } | |
361 } | |
362 | |
363 if (request->use_threads) | |
364 { | |
365 signal (SIGINT, SIG_DFL); | |
366 signal (SIGALRM, SIG_IGN); | |
367 } | |
368 | |
369 request->user_data = NULL; | |
370 request->stopable = 0; | |
371 if (request->wakeup_main_thread[1] > 0) | |
372 write (request->wakeup_main_thread[1], " ", 1); | |
373 return ((void *) ret); | |
374 } | |
375 | |
376 | |
377 void | |
378 get_files (gpointer data) | |
379 { | |
380 transfer_window_files (&window2, &window1); | |
381 } | |
382 | |
383 | |
384 void | |
385 put_files (gpointer data) | |
386 { | |
387 transfer_window_files (&window1, &window2); | |
388 } | |
389 | |
390 | |
391 void | |
392 transfer_window_files (gftp_window_data * fromwdata, gftp_window_data * towdata) | |
393 { | |
394 gftp_file * tempfle, * newfle; | |
395 GList * templist, * filelist; | |
396 gftp_transfer * transfer; | |
397 guint timeout_num; | |
398 void *ret; | |
399 int num; | |
400 | |
401 if (!check_status (_("Transfer Files"), fromwdata, 1, 0, 1, | |
402 towdata->request->put_file != NULL && fromwdata->request->get_file != NULL)) | |
403 return; | |
404 | |
405 if (!GFTP_IS_CONNECTED (fromwdata->request) || | |
406 !GFTP_IS_CONNECTED (towdata->request)) | |
407 { | |
408 ftp_log (gftp_logging_misc, NULL, | |
409 _("Retrieve Files: Not connected to a remote site\n")); | |
410 return; | |
411 } | |
412 | |
413 if (check_reconnect (fromwdata) < 0 || check_reconnect (towdata) < 0) | |
414 return; | |
415 | |
416 transfer = g_malloc0 (sizeof (*transfer)); | |
417 transfer->fromreq = copy_request (fromwdata->request); | |
418 transfer->toreq = copy_request (towdata->request); | |
419 transfer->transfer_direction = fromwdata == &window2 ? | |
420 GFTP_DIRECTION_DOWNLOAD : GFTP_DIRECTION_UPLOAD; | |
421 transfer->fromwdata = fromwdata; | |
422 transfer->towdata = towdata; | |
423 | |
424 num = 0; | |
425 templist = GTK_CLIST (fromwdata->listbox)->selection; | |
426 filelist = fromwdata->files; | |
427 while (templist != NULL) | |
428 { | |
429 templist = get_next_selection (templist, &filelist, &num); | |
430 tempfle = filelist->data; | |
431 if (strcmp (tempfle->file, "..") != 0) | |
432 { | |
433 newfle = copy_fdata (tempfle); | |
434 transfer->files = g_list_append (transfer->files, newfle); | |
435 } | |
436 } | |
437 | |
438 if (transfer->files != NULL) | |
439 { | |
440 swap_socks (transfer->fromreq, fromwdata->request); | |
441 swap_socks (transfer->toreq, towdata->request); | |
442 | |
443 if (transfer->fromreq->use_threads || | |
444 (transfer->toreq && transfer->toreq->use_threads)) | |
445 { | |
446 transfer->fromreq->stopable = 1; | |
447 pthread_create (&fromwdata->tid, NULL, do_getdir_thread, transfer); | |
448 | |
449 timeout_num = gtk_timeout_add (100, progress_timeout, transfer); | |
450 | |
451 while (transfer->fromreq->stopable) | |
31 | 452 { |
453 gdk_threads_leave (); | |
454 g_main_iteration (TRUE); | |
455 gdk_threads_enter (); | |
456 } | |
1 | 457 |
458 gtk_timeout_remove (timeout_num); | |
459 transfer->numfiles = transfer->numdirs = -1; | |
460 update_directory_download_progress (transfer); | |
461 | |
462 pthread_join (fromwdata->tid, &ret); | |
463 } | |
464 else | |
465 ret = do_getdir_thread (transfer); | |
466 | |
467 if (!GFTP_IS_CONNECTED (transfer->fromreq)) | |
468 { | |
469 disconnect (fromwdata); | |
470 return; | |
471 } | |
472 | |
473 if (!GFTP_IS_CONNECTED (transfer->toreq)) | |
474 { | |
475 disconnect (towdata); | |
476 return; | |
477 } | |
478 | |
479 swap_socks (fromwdata->request, transfer->fromreq); | |
480 swap_socks (towdata->request, transfer->toreq); | |
481 } | |
482 | |
483 if (transfer->files != NULL) | |
484 { | |
485 add_file_transfer (transfer->fromreq, transfer->toreq, | |
486 transfer->fromwdata, transfer->towdata, | |
487 transfer->files, 0); | |
488 g_free (transfer); | |
489 } | |
490 else | |
491 { | |
492 if (transfer->statmutex) | |
493 pthread_mutex_destroy (transfer->statmutex); | |
494 if (transfer->structmutex) | |
495 pthread_mutex_destroy (transfer->structmutex); | |
496 free_tdata (transfer); | |
497 } | |
498 } | |
499 | |
500 void * | |
501 do_getdir_thread (void * data) | |
502 { | |
503 gftp_transfer * transfer; | |
504 int success, sj; | |
505 | |
506 transfer = data; | |
507 transfer->fromreq->user_data = (void *) 0x01; | |
508 if (transfer->toreq) | |
509 transfer->toreq->user_data = (void *) 0x01; | |
510 | |
511 if (transfer->fromreq->use_threads || | |
512 (transfer->toreq && transfer->toreq->use_threads)) | |
513 { | |
514 sj = sigsetjmp (connenvir, 1); | |
515 signal (SIGINT, sig_connquit); | |
516 signal (SIGALRM, sig_connquit); | |
517 } | |
518 else | |
519 sj = 0; | |
520 | |
521 success = 0; | |
522 if (sj == 0) | |
523 success = gftp_get_all_subdirs (transfer, NULL) == 0; | |
524 else | |
525 { | |
526 gftp_disconnect (transfer->fromreq); | |
527 if (transfer->toreq) | |
528 gftp_disconnect (transfer->toreq); | |
529 transfer->fromreq->logging_function (gftp_logging_error, | |
530 transfer->fromreq->user_data, | |
531 _("Operation canceled\n")); | |
532 } | |
533 | |
534 if (transfer->fromreq->use_threads || | |
535 (transfer->toreq && transfer->toreq->use_threads)) | |
536 { | |
537 signal (SIGINT, SIG_DFL); | |
538 signal (SIGALRM, SIG_IGN); | |
539 } | |
540 | |
541 transfer->fromreq->user_data = NULL; | |
542 if (transfer->toreq) | |
543 transfer->toreq->user_data = NULL; | |
544 transfer->fromreq->stopable = 0; | |
545 return ((void *) success); | |
546 } | |
547 | |
548 | |
549 | |
550 void * | |
551 gftp_gtk_transfer_files (void *data) | |
552 { | |
553 gftp_transfer * transfer; | |
554 char *tempstr, buf[8192]; | |
555 FILE * tofd, * fromfd; | |
556 off_t fromsize, total; | |
557 gftp_file * curfle; | |
558 ssize_t num_read; | |
559 int i, mode; | |
560 | |
561 pthread_detach (pthread_self ()); | |
562 transfer = data; | |
563 transfer->fromreq->user_data = (void *) 0x1; | |
564 transfer->toreq->user_data = (void *) 0x1; | |
565 transfer->curfle = transfer->files; | |
566 gettimeofday (&transfer->starttime, NULL); | |
567 memcpy (&transfer->lasttime, &transfer->starttime, | |
568 sizeof (transfer->lasttime)); | |
569 while (transfer->curfle != NULL) | |
570 { | |
571 pthread_mutex_lock (transfer->structmutex); | |
572 curfle = transfer->curfle->data; | |
573 transfer->current_file_number++; | |
574 pthread_mutex_unlock (transfer->structmutex); | |
575 | |
576 if (curfle->transfer_action == GFTP_TRANS_ACTION_SKIP) | |
577 { | |
578 pthread_mutex_lock (transfer->structmutex); | |
579 transfer->next_file = 1; | |
580 transfer->curfle = transfer->curfle->next; | |
581 pthread_mutex_unlock (transfer->structmutex); | |
582 continue; | |
583 } | |
584 | |
585 fromsize = -1; | |
586 if (gftp_connect (transfer->fromreq) == 0 && | |
587 gftp_connect (transfer->toreq) == 0) | |
588 { | |
589 if (curfle->isdir) | |
590 { | |
591 if (transfer->toreq->mkdir != NULL) | |
592 { | |
593 transfer->toreq->mkdir (transfer->toreq, curfle->destfile); | |
594 if (!GFTP_IS_CONNECTED (transfer->toreq)) | |
595 break; | |
596 } | |
597 | |
598 pthread_mutex_lock (transfer->structmutex); | |
599 transfer->next_file = 1; | |
600 transfer->curfle = transfer->curfle->next; | |
601 pthread_mutex_unlock (transfer->structmutex); | |
602 continue; | |
603 } | |
604 | |
605 if (transfer->fromreq->maxkbs > 0) | |
606 { | |
607 transfer->fromreq->logging_function (gftp_logging_misc, | |
608 transfer->fromreq->user_data, | |
609 _("File transfer will be throttled to %.2f KB/s\n"), | |
610 transfer->fromreq->maxkbs); | |
611 } | |
612 | |
613 if (curfle->is_fd) | |
614 { | |
615 if (transfer->transfer_direction == GFTP_DIRECTION_DOWNLOAD) | |
616 { | |
617 tofd = curfle->fd; | |
618 fromfd = NULL; | |
619 } | |
620 else | |
621 { | |
622 tofd = NULL; | |
623 fromfd = curfle->fd; | |
624 } | |
625 } | |
626 else | |
627 { | |
628 tofd = NULL; | |
629 fromfd = NULL; | |
630 } | |
631 | |
632 if (curfle->size == 0) | |
633 { | |
634 curfle->size = gftp_get_file_size (transfer->fromreq, curfle->file); | |
635 transfer->total_bytes += curfle->size; | |
636 } | |
637 | |
638 if (GFTP_IS_CONNECTED (transfer->fromreq) && | |
639 GFTP_IS_CONNECTED (transfer->toreq)) | |
640 { | |
641 fromsize = gftp_transfer_file (transfer->fromreq, curfle->file, | |
642 fromfd, | |
643 curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ? | |
644 curfle->startsize : 0, | |
645 transfer->toreq, curfle->destfile, tofd, | |
646 curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ? | |
647 curfle->startsize : 0); | |
648 } | |
649 } | |
650 | |
651 if (!GFTP_IS_CONNECTED (transfer->fromreq) || | |
652 !GFTP_IS_CONNECTED (transfer->toreq)) | |
653 { | |
654 transfer->fromreq->logging_function (gftp_logging_misc, | |
655 transfer->fromreq->user_data, | |
656 _("Error: Remote site disconnected after trying to transfer file\n")); | |
657 num_read = -1; | |
658 } | |
659 else if (fromsize < 0) | |
660 { | |
661 if (curfle->is_fd) | |
662 { | |
663 if (transfer->transfer_direction == GFTP_DIRECTION_DOWNLOAD) | |
664 transfer->toreq->datafd = NULL; | |
665 else | |
666 transfer->fromreq->datafd = NULL; | |
667 } | |
668 | |
669 pthread_mutex_lock (transfer->structmutex); | |
670 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
671 transfer->next_file = 1; | |
672 transfer->curfle = transfer->curfle->next; | |
673 pthread_mutex_unlock (transfer->structmutex); | |
674 continue; | |
675 } | |
676 else | |
677 { | |
678 pthread_mutex_lock (transfer->structmutex); | |
679 transfer->curtrans = 0; | |
680 transfer->curresumed = curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ? curfle->startsize : 0; | |
681 transfer->resumed_bytes += transfer->curresumed; | |
682 pthread_mutex_unlock (transfer->structmutex); | |
683 | |
684 total = 0; | |
685 i = 0; | |
686 while (!transfer->cancel && | |
687 (num_read = gftp_get_next_file_chunk (transfer->fromreq, | |
688 buf, sizeof (buf))) > 0) | |
689 { | |
690 total += num_read; | |
691 gftp_gtk_calc_kbs (transfer, num_read); | |
692 | |
693 if (GFTP_GET_DATA_TYPE (transfer->fromreq) == GFTP_TYPE_ASCII) | |
694 tempstr = gftp_convert_ascii (buf, &num_read, 1); | |
695 else | |
696 tempstr = buf; | |
697 | |
698 if (gftp_put_next_file_chunk (transfer->toreq, tempstr, | |
699 num_read) < 0) | |
700 { | |
701 num_read = -1; | |
702 break; | |
703 } | |
704 | |
705 /* We don't have to free tempstr for a download because new | |
706 memory is not allocated for it in that case */ | |
707 if (GFTP_GET_DATA_TYPE (transfer->fromreq) == GFTP_TYPE_ASCII && | |
708 transfer->transfer_direction == GFTP_DIRECTION_UPLOAD) | |
709 g_free (tempstr); | |
710 } | |
711 } | |
712 | |
713 if (num_read < 0 || transfer->cancel) | |
714 { | |
715 transfer->fromreq->logging_function (gftp_logging_misc, | |
716 transfer->fromreq->user_data, | |
717 _("Could not download %s from %s\n"), | |
718 curfle->file, | |
719 transfer->fromreq->hostname); | |
720 | |
721 if (get_status (transfer, num_read) == 1) | |
722 { | |
723 transfer->cancel = 0; | |
724 continue; | |
725 } | |
726 break; | |
727 } | |
728 else | |
729 { | |
730 /* FIXME - this needs cleaned up. NOTE: view/edit file will be broken if the file hsa to be resumed */ | |
731 if (curfle->is_fd) | |
732 { | |
733 if (transfer->transfer_direction == GFTP_DIRECTION_DOWNLOAD) | |
734 transfer->toreq->datafd = NULL; | |
735 else | |
736 transfer->fromreq->datafd = NULL; | |
737 } | |
738 | |
739 if (gftp_end_transfer (transfer->fromreq) != 0) | |
740 { | |
741 if (get_status (transfer, -1) == 1) | |
742 { | |
743 transfer->cancel = 0; | |
744 continue; | |
745 } | |
746 break; | |
747 } | |
748 gftp_end_transfer (transfer->toreq); | |
749 | |
750 transfer->fromreq->logging_function (gftp_logging_misc, | |
751 transfer->fromreq->user_data, | |
752 _("Successfully transferred %s at %.2f KB/s\n"), | |
753 curfle->file, transfer->kbs); | |
754 } | |
755 | |
756 if (!curfle->is_fd) | |
757 { | |
758 if (curfle->attribs) | |
759 { | |
760 mode = parse_attribs (curfle->attribs); | |
761 if (mode != 0) | |
762 gftp_chmod (transfer->toreq, curfle->destfile, | |
763 parse_attribs (curfle->attribs)); | |
764 } | |
765 | |
766 if (curfle->datetime != 0) | |
767 gftp_set_file_time (transfer->toreq, curfle->destfile, | |
768 curfle->datetime); | |
769 } | |
770 | |
771 pthread_mutex_lock (transfer->structmutex); | |
772 transfer->next_file = 1; | |
773 curfle->transfer_done = 1; | |
774 transfer->curfle = transfer->curfle->next; | |
775 pthread_mutex_unlock (transfer->structmutex); | |
776 | |
777 if (transfer->cancel && !transfer->skip_file) | |
778 break; | |
779 transfer->cancel = 0; | |
780 } | |
781 transfer->done = 1; | |
782 transfer->fromreq->user_data = NULL; | |
783 transfer->toreq->user_data = NULL; | |
784 return (NULL); | |
785 } | |
786 | |
787 | |
788 void | |
789 add_file_transfer (gftp_request * fromreq, gftp_request * toreq, | |
790 gftp_window_data * fromwdata, gftp_window_data * towdata, | |
791 GList * files, int copy_req) | |
792 { | |
793 gftp_curtrans_data * transdata; | |
794 GList * templist, *curfle; | |
795 gftp_transfer * tdata; | |
796 gftp_file * tempfle; | |
797 char *pos, *text[2]; | |
798 int dialog; | |
799 | |
800 for (templist = files; templist != NULL; templist = templist->next) | |
801 { | |
802 tempfle = templist->data; | |
803 if (tempfle->startsize > 0) | |
804 break; | |
805 } | |
806 dialog = templist != NULL; | |
807 | |
808 if (append_file_transfers) | |
809 { | |
810 pthread_mutex_lock (&transfer_mutex); | |
811 for (templist = file_transfers; templist != NULL; templist = templist->next) | |
812 { | |
813 tdata = templist->data; | |
814 pthread_mutex_lock (tdata->structmutex); | |
815 if (compare_request (tdata->fromreq, fromreq, 0) && | |
816 compare_request (tdata->toreq, toreq, 0) && | |
817 tdata->curfle != NULL) | |
818 { | |
819 if (!copy_req) | |
820 { | |
821 gftp_request_destroy (fromreq); | |
822 gftp_request_destroy (toreq); | |
823 } | |
824 fromreq = NULL; | |
825 toreq = NULL; | |
826 | |
827 for (curfle = tdata->curfle; | |
828 curfle != NULL && curfle->next != NULL; | |
829 curfle = curfle->next); | |
830 if (curfle == NULL) | |
831 { | |
832 curfle = files; | |
833 files->prev = NULL; | |
834 } | |
835 else | |
836 { | |
837 curfle->next = files; | |
838 files->prev = curfle; | |
839 } | |
840 | |
841 for (curfle = files; curfle != NULL; curfle = curfle->next) | |
842 { | |
843 tempfle = curfle->data; | |
844 if (tempfle->isdir) | |
845 tdata->numdirs++; | |
846 else | |
847 tdata->numfiles++; | |
848 if ((pos = strrchr (tempfle->file, '/')) == NULL) | |
849 pos = tempfle->file; | |
850 else | |
851 pos++; | |
852 | |
853 text[0] = pos; | |
854 if (tempfle->transfer_action == GFTP_TRANS_ACTION_SKIP) | |
855 text[1] = _("Skipped"); | |
856 else | |
857 { | |
858 tdata->total_bytes += tempfle->size; | |
859 text[1] = _("Waiting..."); | |
860 } | |
861 | |
862 tempfle->node = gtk_ctree_insert_node (GTK_CTREE (dlwdw), | |
863 tdata->node, NULL, text, 5, | |
864 NULL, NULL, NULL, NULL, | |
865 FALSE, FALSE); | |
866 transdata = g_malloc (sizeof (*transdata)); | |
867 transdata->transfer = tdata; | |
868 transdata->curfle = curfle; | |
869 gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), tempfle->node, | |
870 transdata); | |
871 } | |
872 pthread_mutex_unlock (tdata->structmutex); | |
873 break; | |
874 } | |
875 pthread_mutex_unlock (tdata->structmutex); | |
876 } | |
877 pthread_mutex_unlock (&transfer_mutex); | |
878 } | |
879 else | |
880 templist = NULL; | |
881 | |
882 if (templist == NULL) | |
883 { | |
884 tdata = g_malloc0 (sizeof (*tdata)); | |
885 if (copy_req) | |
886 { | |
887 tdata->fromreq = copy_request (fromreq); | |
888 tdata->toreq = copy_request (toreq); | |
889 } | |
890 else | |
891 { | |
892 tdata->fromreq = fromreq; | |
893 tdata->toreq = toreq; | |
894 } | |
895 tdata->transfer_direction = fromwdata && fromwdata == &window1 ? | |
896 GFTP_DIRECTION_UPLOAD : GFTP_DIRECTION_DOWNLOAD; | |
897 tdata->fromwdata = fromwdata; | |
898 tdata->towdata = towdata; | |
899 if (!dialog) | |
900 tdata->show = tdata->ready = 1; | |
901 tdata->files = files; | |
902 for (curfle = files; curfle != NULL; curfle = curfle->next) | |
903 { | |
904 tempfle = curfle->data; | |
905 if (tempfle->isdir) | |
906 tdata->numdirs++; | |
907 else | |
908 tdata->numfiles++; | |
909 } | |
910 tdata->structmutex = g_malloc (sizeof (pthread_mutex_t)); | |
911 pthread_mutex_init (tdata->structmutex, NULL); | |
912 tdata->statmutex = g_malloc (sizeof (pthread_mutex_t)); | |
913 pthread_mutex_init (tdata->statmutex, NULL); | |
914 pthread_mutex_lock (&transfer_mutex); | |
915 file_transfers = g_list_append (file_transfers, tdata); | |
916 pthread_mutex_unlock (&transfer_mutex); | |
917 if (dialog) | |
918 gftp_gtk_ask_transfer (tdata); | |
919 } | |
920 } | |
921 | |
922 | |
923 gint | |
924 update_downloads (gpointer data) | |
925 { | |
926 char tempstr[50], temp1str[127]; | |
927 GList * templist, * next; | |
928 gftp_transfer * tdata; | |
929 | |
930 if (file_transfer_logs != NULL) | |
931 display_cached_logs (); | |
932 | |
933 if (window2.request->gotbytes != 0) | |
934 { | |
935 if (window2.request->gotbytes == -1) | |
936 { | |
937 update_window_info (); | |
938 window2.request->gotbytes = 0; | |
939 } | |
940 else | |
941 { | |
942 insert_commas (window2.request->gotbytes, tempstr, sizeof (tempstr)); | |
943 g_snprintf (temp1str, sizeof (temp1str), | |
944 _("Retrieving file names...%s bytes"), tempstr); | |
945 gtk_label_set (GTK_LABEL (window2.hoststxt), temp1str); | |
946 } | |
947 } | |
948 | |
949 if (viewedit_process_done) | |
950 check_done_process (); | |
951 | |
952 for (templist = file_transfers; templist != NULL;) | |
953 { | |
954 tdata = templist->data; | |
955 if (tdata->ready) | |
956 { | |
957 pthread_mutex_lock (tdata->structmutex); | |
958 | |
959 if (tdata->next_file) | |
960 on_next_transfer (tdata); | |
961 else if (tdata->show) | |
962 show_transfer (tdata); | |
963 else if (tdata->done) | |
964 { | |
965 next = templist->next; | |
966 transfer_done (templist); | |
967 templist = next; | |
968 continue; | |
969 } | |
970 | |
971 if (tdata->curfle != NULL) | |
972 { | |
973 if (!tdata->started && start_file_transfers && | |
974 (transfer_in_progress == 0 || !do_one_transfer_at_a_time)) | |
975 create_transfer (tdata); | |
976 | |
977 if (tdata->started) | |
978 update_file_status (tdata); | |
979 } | |
980 pthread_mutex_unlock (tdata->structmutex); | |
981 } | |
982 templist = templist->next; | |
983 } | |
984 | |
985 gtk_timeout_add (500, update_downloads, NULL); | |
986 return (0); | |
987 } | |
988 | |
989 | |
990 static void | |
991 on_next_transfer (gftp_transfer * tdata) | |
992 { | |
993 gftp_file * tempfle; | |
994 int fd; | |
995 | |
996 tdata->next_file = 0; | |
997 for (; tdata->updfle != tdata->curfle; tdata->updfle = tdata->updfle->next) | |
998 { | |
999 tempfle = tdata->updfle->data; | |
1000 | |
1001 if (tempfle->is_fd) | |
1002 fd = fileno (tempfle->fd); | |
1003 else | |
1004 fd = 0; | |
1005 | |
1006 if (tempfle->done_view) | |
1007 { | |
1008 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) | |
1009 view_file (tempfle->destfile, fd, 1, tempfle->done_rm, 1, 0, | |
1010 tempfle->file, NULL); | |
1011 | |
1012 if (tempfle->is_fd) | |
1013 { | |
1014 fclose (tempfle->fd); | |
1015 tempfle->fd = NULL; | |
1016 } | |
1017 } | |
1018 else if (tempfle->done_edit) | |
1019 { | |
1020 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) | |
1021 view_file (tempfle->destfile, fd, 0, tempfle->done_rm, 1, 0, | |
1022 tempfle->file, NULL); | |
1023 | |
1024 if (tempfle->is_fd) | |
1025 { | |
1026 fclose (tempfle->fd); | |
1027 tempfle->fd = NULL; | |
1028 } | |
1029 } | |
1030 else if (tempfle->done_rm) | |
1031 tdata->fromreq->rmfile (tdata->fromreq, tempfle->file); | |
1032 | |
1033 if (tempfle->transfer_action == GFTP_TRANS_ACTION_SKIP) | |
1034 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->node, 1, | |
1035 _("Skipped")); | |
1036 else | |
1037 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->node, 1, | |
1038 _("Finished")); | |
1039 } | |
1040 | |
1041 if (refresh_files && tdata->curfle && tdata->curfle->next && | |
1042 compare_request (tdata->toreq, | |
1043 ((gftp_window_data *) tdata->towdata)->request, 1)) | |
1044 refresh (tdata->towdata); | |
1045 } | |
1046 | |
1047 | |
1048 static void | |
19 | 1049 get_trans_password (gftp_request * request, gftp_dialog_data * ddata) |
1050 { | |
1051 gftp_set_password (request, gtk_entry_get_text (GTK_ENTRY (ddata->edit))); | |
1052 request->stopable = 0; | |
1053 } | |
1054 | |
1055 | |
1056 static void | |
1057 cancel_get_trans_password (gftp_transfer * tdata, gftp_dialog_data * ddata) | |
1058 { | |
1059 if (tdata->fromreq->stopable == 0) | |
1060 return; | |
1061 | |
1062 pthread_mutex_lock (tdata->structmutex); | |
1063 if (tdata->started) | |
1064 tdata->cancel = 1; | |
1065 else | |
1066 tdata->done = 1; | |
1067 | |
1068 tdata->fromreq->stopable = 0; | |
1069 tdata->toreq->stopable = 0; | |
1070 ftp_log (gftp_logging_misc, NULL, _("Stopping the transfer of %s\n"), | |
1071 ((gftp_file *) tdata->curfle->data)->file); | |
1072 pthread_mutex_unlock (tdata->structmutex); | |
1073 } | |
1074 | |
1075 | |
1076 static void | |
1 | 1077 show_transfer (gftp_transfer * tdata) |
1078 { | |
1079 GdkPixmap * closedir_pixmap, * opendir_pixmap; | |
1080 GdkBitmap * closedir_bitmap, * opendir_bitmap; | |
1081 gftp_curtrans_data * transdata; | |
1082 gftp_file * tempfle; | |
1083 char *pos, *text[2]; | |
1084 GList * templist; | |
1085 | |
1086 gftp_get_pixmap (dlwdw, "open_dir.xpm", &opendir_pixmap, &opendir_bitmap); | |
1087 gftp_get_pixmap (dlwdw, "dir.xpm", &closedir_pixmap, &closedir_bitmap); | |
1088 | |
1089 text[0] = GFTP_GET_HOSTNAME (tdata->fromreq); | |
1090 text[1] = _("Waiting..."); | |
1091 tdata->node = gtk_ctree_insert_node (GTK_CTREE (dlwdw), NULL, NULL, text, 5, | |
1092 closedir_pixmap, closedir_bitmap, | |
1093 opendir_pixmap, opendir_bitmap, | |
1094 FALSE, | |
1095 tdata->numdirs + tdata->numfiles < 50); | |
1096 transdata = g_malloc (sizeof (*transdata)); | |
1097 transdata->transfer = tdata; | |
1098 transdata->curfle = NULL; | |
1099 gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), tdata->node, transdata); | |
1100 tdata->show = 0; | |
1101 tdata->curfle = tdata->updfle = tdata->files; | |
1102 | |
1103 tdata->total_bytes = 0; | |
1104 for (templist = tdata->files; templist != NULL; templist = templist->next) | |
1105 { | |
1106 tempfle = templist->data; | |
1107 if ((pos = strrchr (tempfle->file, '/')) == NULL) | |
1108 pos = tempfle->file; | |
1109 else | |
1110 pos++; | |
1111 text[0] = pos; | |
1112 if (tempfle->transfer_action == GFTP_TRANS_ACTION_SKIP) | |
1113 text[1] = _("Skipped"); | |
1114 else | |
1115 { | |
1116 tdata->total_bytes += tempfle->size; | |
1117 text[1] = _("Waiting..."); | |
1118 } | |
1119 | |
1120 tempfle->node = gtk_ctree_insert_node (GTK_CTREE (dlwdw), tdata->node, | |
1121 NULL, text, 5, NULL, NULL, NULL, | |
1122 NULL, FALSE, FALSE); | |
1123 transdata = g_malloc (sizeof (*transdata)); | |
1124 transdata->transfer = tdata; | |
1125 transdata->curfle = templist; | |
1126 gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), tempfle->node, transdata); | |
1127 } | |
1128 | |
1129 if (!tdata->toreq->stopable && tdata->toreq->need_userpass && | |
1130 (tdata->toreq->password == NULL || *tdata->toreq->password == '\0')) | |
1131 { | |
1132 tdata->toreq->stopable = 1; | |
1133 MakeEditDialog (_("Enter Password"), | |
1134 _("Please enter your password for this site"), NULL, 0, | |
19 | 1135 NULL, gftp_dialog_button_connect, |
1136 get_trans_password, tdata->toreq, | |
1137 cancel_get_trans_password, tdata); | |
1 | 1138 } |
1139 | |
1140 if (!tdata->fromreq->stopable && tdata->fromreq->need_userpass && | |
1141 (tdata->fromreq->password == NULL || *tdata->fromreq->password == '\0')) | |
1142 { | |
1143 tdata->fromreq->stopable = 1; | |
1144 MakeEditDialog (_("Enter Password"), | |
1145 _("Please enter your password for this site"), NULL, 0, | |
19 | 1146 NULL, gftp_dialog_button_connect, |
1147 get_trans_password, tdata->fromreq, | |
1148 cancel_get_trans_password, tdata); | |
1 | 1149 } |
1150 } | |
1151 | |
1152 | |
1153 static void | |
1154 transfer_done (GList * node) | |
1155 { | |
1156 gftp_curtrans_data * transdata; | |
1157 gftp_request * fromreq; | |
1158 gftp_transfer * tdata; | |
1159 gftp_file * tempfle; | |
1160 GList * templist; | |
1161 | |
1162 tdata = node->data; | |
1163 if (tdata->started) | |
1164 { | |
1165 fromreq = ((gftp_window_data *) tdata->fromwdata)->request; | |
1166 if (!tdata->fromreq->stopable && tdata->fromwdata && | |
1167 ((fromreq->sockfd == NULL && fromreq->cached) || | |
1168 fromreq->always_connected) && tdata->fromreq->sockfd != NULL && | |
1169 compare_request (tdata->fromreq, fromreq, 0)) | |
1170 { | |
1171 swap_socks (((gftp_window_data *) tdata->towdata)->request, | |
1172 tdata->toreq); | |
1173 swap_socks (((gftp_window_data *) tdata->fromwdata)->request, | |
1174 tdata->fromreq); | |
1175 } | |
1176 else | |
1177 { | |
1178 gftp_disconnect (tdata->fromreq); | |
1179 gftp_disconnect (tdata->toreq); | |
1180 } | |
1181 | |
1182 if (tdata->towdata != NULL && compare_request (tdata->toreq, | |
1183 ((gftp_window_data *) tdata->towdata)->request, 1)) | |
1184 refresh (tdata->towdata); | |
1185 | |
1186 transfer_in_progress--; | |
1187 } | |
1188 | |
2
a171df6764a7
* Fixed crash if you was already transfering a file, and you started another
masneyb
parents:
1
diff
changeset
|
1189 if (!tdata->show && tdata->started) |
1 | 1190 { |
1191 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), tdata->node); | |
1192 if (transdata != NULL) | |
1193 g_free (transdata); | |
1194 | |
1195 for (templist = tdata->files; templist != NULL; templist = templist->next) | |
1196 { | |
1197 tempfle = templist->data; | |
1198 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), tempfle->node); | |
1199 if (transdata != NULL) | |
1200 g_free (transdata); | |
1201 } | |
1202 | |
1203 gtk_ctree_remove_node (GTK_CTREE (dlwdw), tdata->node); | |
1204 } | |
1205 pthread_mutex_lock (&transfer_mutex); | |
1206 file_transfers = g_list_remove_link (file_transfers, node); | |
1207 pthread_mutex_unlock (&transfer_mutex); | |
1208 pthread_mutex_destroy (tdata->structmutex); | |
1209 pthread_mutex_destroy (tdata->statmutex); | |
1210 free_tdata (tdata); | |
1211 fix_display (); | |
1212 } | |
1213 | |
1214 | |
1215 static void | |
1216 create_transfer (gftp_transfer * tdata) | |
1217 { | |
1218 pthread_t tid; | |
1219 | |
1220 if (!tdata->fromreq->stopable) | |
1221 { | |
1222 if (tdata->fromwdata && | |
1223 ((gftp_window_data *) tdata->fromwdata)->request->sockfd != NULL && | |
1224 !((gftp_window_data *) tdata->fromwdata)->request->stopable && | |
1225 compare_request (tdata->fromreq, ((gftp_window_data *) tdata->fromwdata)->request, 0)) | |
1226 { | |
1227 swap_socks (tdata->toreq, | |
1228 ((gftp_window_data *) tdata->towdata)->request); | |
1229 swap_socks (tdata->fromreq, | |
1230 ((gftp_window_data *) tdata->fromwdata)->request); | |
1231 update_window_info (); | |
1232 } | |
1233 transfer_in_progress++; | |
1234 tdata->started = 1; | |
1235 tdata->stalled = 1; | |
1236 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->node, 1, | |
1237 _("Connecting...")); | |
1238 pthread_create (&tid, NULL, gftp_gtk_transfer_files, tdata); | |
1239 } | |
1240 } | |
1241 | |
1242 | |
1243 static void | |
1244 update_file_status (gftp_transfer * tdata) | |
1245 { | |
1246 char totstr[100], dlstr[100], gotstr[50], ofstr[50]; | |
1247 int hours, mins, secs, pcent, st; | |
1248 double remaining; | |
1249 gftp_file * tempfle; | |
1250 struct timeval tv; | |
1251 | |
1252 pthread_mutex_lock (tdata->statmutex); | |
1253 tempfle = tdata->curfle->data; | |
1254 | |
1255 gettimeofday (&tv, NULL); | |
1256 if ((remaining = (double) (tv.tv_sec - tdata->starttime.tv_sec) + ((double) (tv.tv_usec - tdata->starttime.tv_usec) / 1000000.0)) == 0) | |
1257 remaining = 1.0; | |
1258 | |
1259 remaining = ((double) (tdata->total_bytes - tdata->trans_bytes - tdata->resumed_bytes)) / 1024.0 / tdata->kbs; | |
1260 hours = (off_t) remaining / 3600; | |
1261 remaining -= hours * 3600; | |
1262 mins = (off_t) remaining / 60; | |
1263 remaining -= mins * 60; | |
1264 secs = (off_t) remaining; | |
1265 | |
1266 if (hours < 0 || mins < 0 || secs < 0) | |
1267 { | |
1268 pthread_mutex_unlock (tdata->statmutex); | |
1269 return; | |
1270 } | |
1271 | |
1272 pcent = (int) ((double) (tdata->trans_bytes + tdata->resumed_bytes) / (double) tdata->total_bytes * 100.0); | |
1273 if (pcent < 0 || pcent > 100) | |
1274 pcent = 0; | |
1275 | |
1276 g_snprintf (totstr, sizeof (totstr), | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
1277 _("%d%% complete, %02d:%02d:%02d est. time remaining. (File %ld of %ld)"), |
1 | 1278 pcent, hours, mins, secs, tdata->current_file_number, |
1279 tdata->numdirs + tdata->numfiles); | |
1280 | |
1281 *dlstr = '\0'; | |
1282 if (!tdata->stalled) | |
1283 { | |
1284 insert_commas (tdata->curtrans + tdata->curresumed, gotstr, sizeof (gotstr)); | |
1285 insert_commas (tempfle->size, ofstr, sizeof (ofstr)); | |
1286 st = 1; | |
1287 if (tv.tv_sec - tdata->lasttime.tv_sec <= 5) | |
1288 { | |
1289 if (tdata->curfle->next != NULL) | |
1290 { | |
1291 remaining = ((double) (tempfle->size - tdata->curtrans - tdata->curresumed)) / 1024.0 / tdata->kbs; | |
1292 hours = (off_t) remaining / 3600; | |
1293 remaining -= hours * 3600; | |
1294 mins = (off_t) remaining / 60; | |
1295 remaining -= mins * 60; | |
1296 secs = (off_t) remaining; | |
1297 } | |
1298 | |
1299 if (!(hours < 0 || mins < 0 || secs < 0)) | |
1300 { | |
1301 g_snprintf (dlstr, sizeof (dlstr), | |
1302 _("Recv %s of %s at %.2fKB/s, %02d:%02d:%02d est. time remaining"), gotstr, ofstr, tdata->kbs, hours, mins, secs); | |
1303 st = 0; | |
1304 } | |
1305 } | |
1306 | |
1307 if (st) | |
1308 { | |
1309 tdata->stalled = 1; | |
1310 g_snprintf (dlstr, sizeof (dlstr), | |
1311 _("Recv %s of %s, transfer stalled, unknown time remaining"), | |
1312 gotstr, ofstr); | |
1313 } | |
1314 } | |
1315 | |
1316 pthread_mutex_unlock (tdata->statmutex); | |
1317 | |
1318 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->node, 1, totstr); | |
1319 | |
1320 if (*dlstr != '\0') | |
1321 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->node, 1, dlstr); | |
1322 } | |
1323 | |
1324 | |
1325 void | |
1326 start_transfer (gpointer data) | |
1327 { | |
1328 gftp_curtrans_data * transdata; | |
1329 GtkCTreeNode * node; | |
1330 | |
1331 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1332 { | |
1333 ftp_log (gftp_logging_misc, NULL, | |
1334 _("There are no file transfers selected\n")); | |
1335 return; | |
1336 } | |
1337 node = GTK_CLIST (dlwdw)->selection->data; | |
1338 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1339 | |
1340 pthread_mutex_lock (transdata->transfer->structmutex); | |
1341 if (!transdata->transfer->started) | |
1342 create_transfer (transdata->transfer); | |
1343 pthread_mutex_unlock (transdata->transfer->structmutex); | |
1344 } | |
1345 | |
1346 | |
1347 void | |
1348 stop_transfer (gpointer data) | |
1349 { | |
1350 gftp_curtrans_data * transdata; | |
1351 GtkCTreeNode * node; | |
1352 | |
1353 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1354 { | |
1355 ftp_log (gftp_logging_misc, NULL, | |
1356 _("There are no file transfers selected\n")); | |
1357 return; | |
1358 } | |
1359 node = GTK_CLIST (dlwdw)->selection->data; | |
1360 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1361 | |
1362 pthread_mutex_lock (transdata->transfer->structmutex); | |
1363 if (transdata->transfer->started) | |
1364 { | |
1365 transdata->transfer->cancel = 1; | |
1366 transdata->transfer->skip_file = 0; | |
1367 } | |
1368 else | |
1369 transdata->transfer->done = 1; | |
1370 ftp_log (gftp_logging_misc, NULL, _("Stopping the transfer on host %s\n"), | |
1371 transdata->transfer->fromreq->hostname); | |
1372 pthread_mutex_unlock (transdata->transfer->structmutex); | |
1373 } | |
1374 | |
1375 | |
1376 void | |
1377 skip_transfer (gpointer data) | |
1378 { | |
1379 gftp_curtrans_data * transdata; | |
1380 GtkCTreeNode * node; | |
1381 gftp_file * curfle; | |
1382 | |
1383 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1384 { | |
1385 ftp_log (gftp_logging_misc, NULL, | |
1386 _("There are no file transfers selected\n")); | |
1387 return; | |
1388 } | |
1389 node = GTK_CLIST (dlwdw)->selection->data; | |
1390 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1391 | |
1392 pthread_mutex_lock (transdata->transfer->structmutex); | |
1393 if (transdata->transfer->curfle != NULL) | |
1394 { | |
1395 curfle = transdata->transfer->curfle->data; | |
1396 if (transdata->transfer->started) | |
1397 { | |
1398 transdata->transfer->cancel = 1; | |
1399 transdata->transfer->skip_file = 1; | |
1400 } | |
1401 | |
1402 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
1403 ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"), | |
1404 curfle->file, transdata->transfer->fromreq->hostname); | |
1405 } | |
1406 pthread_mutex_unlock (transdata->transfer->structmutex); | |
1407 } | |
1408 | |
1409 | |
1410 void | |
1411 remove_file_transfer (gpointer data) | |
1412 { | |
1413 gftp_curtrans_data * transdata; | |
1414 GtkCTreeNode * node; | |
1415 gftp_file * curfle; | |
1416 | |
1417 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1418 { | |
1419 ftp_log (gftp_logging_misc, NULL, | |
1420 _("There are no file transfers selected\n")); | |
1421 return; | |
1422 } | |
1423 | |
1424 node = GTK_CLIST (dlwdw)->selection->data; | |
1425 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1426 | |
1427 | |
1428 if (transdata->curfle == NULL || transdata->curfle->data == NULL) | |
1429 return; | |
1430 | |
1431 curfle = transdata->curfle->data; | |
1432 | |
1433 if (curfle->transfer_action & GFTP_TRANS_ACTION_SKIP) | |
1434 return; | |
1435 | |
1436 pthread_mutex_lock (transdata->transfer->structmutex); | |
1437 | |
1438 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
1439 | |
1440 if (transdata->transfer->started && | |
1441 transdata->curfle == transdata->transfer->curfle) | |
1442 { | |
1443 transdata->transfer->cancel = 1; | |
1444 transdata->transfer->skip_file = 1; | |
1445 } | |
1446 else if (transdata->curfle != transdata->transfer->curfle && | |
1447 !curfle->transfer_done) | |
1448 { | |
1449 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), curfle->node, 1, | |
1450 _("Skipped")); | |
1451 transdata->transfer->total_bytes -= curfle->size; | |
1452 } | |
1453 | |
1454 ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"), | |
1455 curfle->file, transdata->transfer->fromreq->hostname); | |
1456 | |
1457 pthread_mutex_unlock (transdata->transfer->structmutex); | |
1458 } | |
1459 | |
1460 | |
1461 void | |
1462 move_transfer_up (gpointer data) | |
1463 { | |
1464 GList * firstentry, * secentry, * lastentry; | |
1465 gftp_curtrans_data * transdata; | |
1466 GtkCTreeNode * node; | |
1467 | |
1468 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1469 { | |
1470 ftp_log (gftp_logging_misc, NULL, | |
1471 _("There are no file transfers selected\n")); | |
1472 return; | |
1473 } | |
1474 node = GTK_CLIST (dlwdw)->selection->data; | |
1475 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1476 | |
1477 if (transdata->curfle == NULL) | |
1478 return; | |
1479 | |
1480 pthread_mutex_lock (transdata->transfer->structmutex); | |
1481 if (transdata->curfle->prev != NULL && (!transdata->transfer->started || | |
1482 (transdata->transfer->curfle != transdata->curfle && | |
1483 transdata->transfer->curfle != transdata->curfle->prev))) | |
1484 { | |
1485 if (transdata->curfle->prev->prev == NULL) | |
1486 { | |
1487 firstentry = transdata->curfle->prev; | |
1488 lastentry = transdata->curfle->next; | |
1489 transdata->transfer->files = transdata->curfle; | |
1490 transdata->curfle->next = firstentry; | |
1491 transdata->transfer->files->prev = NULL; | |
1492 firstentry->prev = transdata->curfle; | |
1493 firstentry->next = lastentry; | |
1494 if (lastentry != NULL) | |
1495 lastentry->prev = firstentry; | |
1496 } | |
1497 else | |
1498 { | |
1499 firstentry = transdata->curfle->prev->prev; | |
1500 secentry = transdata->curfle->prev; | |
1501 lastentry = transdata->curfle->next; | |
1502 firstentry->next = transdata->curfle; | |
1503 transdata->curfle->prev = firstentry; | |
1504 transdata->curfle->next = secentry; | |
1505 secentry->prev = transdata->curfle; | |
1506 secentry->next = lastentry; | |
1507 if (lastentry != NULL) | |
1508 lastentry->prev = secentry; | |
1509 } | |
1510 | |
1511 gtk_ctree_move (GTK_CTREE (dlwdw), | |
1512 ((gftp_file *) transdata->curfle->data)->node, | |
1513 transdata->transfer->node, | |
1514 transdata->curfle->next != NULL ? | |
1515 ((gftp_file *) transdata->curfle->next->data)->node : | |
1516 NULL); | |
1517 } | |
1518 pthread_mutex_unlock (transdata->transfer->structmutex); | |
1519 } | |
1520 | |
1521 void | |
1522 move_transfer_down (gpointer data) | |
1523 { | |
1524 GList * firstentry, * secentry, * lastentry; | |
1525 gftp_curtrans_data * transdata; | |
1526 GtkCTreeNode * node; | |
1527 | |
1528 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1529 { | |
1530 ftp_log (gftp_logging_misc, NULL, | |
1531 _("There are no file transfers selected\n")); | |
1532 return; | |
1533 } | |
1534 node = GTK_CLIST (dlwdw)->selection->data; | |
1535 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1536 | |
1537 if (transdata->curfle == NULL) | |
1538 return; | |
1539 | |
1540 pthread_mutex_lock (transdata->transfer->structmutex); | |
1541 if (transdata->curfle->next != NULL && (!transdata->transfer->started || | |
1542 (transdata->transfer->curfle != transdata->curfle && | |
1543 transdata->transfer->curfle != transdata->curfle->next))) | |
1544 { | |
1545 if (transdata->curfle->prev == NULL) | |
1546 { | |
1547 firstentry = transdata->curfle->next; | |
1548 lastentry = transdata->curfle->next->next; | |
1549 transdata->transfer->files = firstentry; | |
1550 transdata->transfer->files->prev = NULL; | |
1551 transdata->transfer->files->next = transdata->curfle; | |
1552 transdata->curfle->prev = transdata->transfer->files; | |
1553 transdata->curfle->next = lastentry; | |
1554 if (lastentry != NULL) | |
1555 lastentry->prev = transdata->curfle; | |
1556 } | |
1557 else | |
1558 { | |
1559 firstentry = transdata->curfle->prev; | |
1560 secentry = transdata->curfle->next; | |
1561 lastentry = transdata->curfle->next->next; | |
1562 firstentry->next = secentry; | |
1563 secentry->prev = firstentry; | |
1564 secentry->next = transdata->curfle; | |
1565 transdata->curfle->prev = secentry; | |
1566 transdata->curfle->next = lastentry; | |
1567 if (lastentry != NULL) | |
1568 lastentry->prev = transdata->curfle; | |
1569 } | |
1570 | |
1571 gtk_ctree_move (GTK_CTREE (dlwdw), | |
1572 ((gftp_file *) transdata->curfle->data)->node, | |
1573 transdata->transfer->node, | |
1574 transdata->curfle->next != NULL ? | |
1575 ((gftp_file *) transdata->curfle->next->data)->node : | |
1576 NULL); | |
1577 } | |
1578 pthread_mutex_unlock (transdata->transfer->structmutex); | |
1579 } | |
1580 | |
1581 | |
1582 void | |
1583 gftp_gtk_ask_transfer (gftp_transfer * tdata) | |
1584 { | |
1585 char *dltitles[4], *add_data[4] = { NULL, NULL, NULL, NULL }, | |
1586 tempstr[50], temp1str[50]; | |
1587 GtkWidget * tempwid, * scroll, * hbox; | |
1588 gftp_file * tempfle; | |
1589 GList * templist; | |
1590 size_t len; | |
1591 char *pos; | |
1592 int i; | |
1593 | |
1594 dltitles[0] = _("Filename"); | |
1595 dltitles[1] = _("Local Size"); | |
1596 dltitles[2] = _("Remote Size"); | |
1597 dltitles[3] = _("Action"); | |
19 | 1598 dialog = gtk_dialog_new (); /* FIXME - gtk+ 2.0 stock icons */ |
1 | 1599 gtk_grab_add (dialog); |
1600 gtk_window_set_title (GTK_WINDOW (dialog), | |
1601 tdata->transfer_direction == GFTP_DIRECTION_DOWNLOAD ? | |
1602 _("Download Files") : _("Upload Files")); | |
1603 gtk_window_set_wmclass (GTK_WINDOW(dialog), "transfer", "gFTP"); | |
1604 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), 10); | |
1605 gtk_container_border_width (GTK_CONTAINER | |
1606 (GTK_DIALOG (dialog)->action_area), 5); | |
1607 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 5); | |
1608 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 35); | |
1609 gtk_box_set_homogeneous (GTK_BOX (GTK_DIALOG (dialog)->action_area), TRUE); | |
1610 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE); | |
1611 gtk_signal_connect_object (GTK_OBJECT (dialog), "delete_event", | |
1612 GTK_SIGNAL_FUNC (gtk_widget_destroy), | |
1613 GTK_OBJECT (dialog)); | |
1614 | |
1615 tempwid = gtk_label_new (_("The following file(s) exist on both the local and remote computer\nPlease select what you would like to do")); | |
1616 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), tempwid, FALSE, | |
1617 FALSE, 0); | |
1618 gtk_widget_show (tempwid); | |
1619 | |
1620 scroll = gtk_scrolled_window_new (NULL, NULL); | |
1621 gtk_widget_set_size_request (scroll, 450, 200); | |
1622 | |
1623 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), | |
1624 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
1625 tdata->clist = gtk_clist_new_with_titles (4, dltitles); | |
1626 gtk_container_add (GTK_CONTAINER (scroll), tdata->clist); | |
1627 | |
1628 #if GTK_MAJOR_VERSION == 1 && GTK_MINOR_VERSION == 2 | |
1629 gtk_clist_set_selection_mode (GTK_CLIST (tdata->clist), | |
1630 GTK_SELECTION_EXTENDED); | |
1631 #else | |
1632 gtk_clist_set_selection_mode (GTK_CLIST (tdata->clist), | |
1633 GTK_SELECTION_MULTIPLE); | |
1634 #endif | |
1635 gtk_clist_set_column_width (GTK_CLIST (tdata->clist), 0, 100); | |
1636 gtk_clist_set_column_justification (GTK_CLIST (tdata->clist), 1, | |
1637 GTK_JUSTIFY_RIGHT); | |
1638 gtk_clist_set_column_width (GTK_CLIST (tdata->clist), 1, 85); | |
1639 gtk_clist_set_column_justification (GTK_CLIST (tdata->clist), 2, | |
1640 GTK_JUSTIFY_RIGHT); | |
1641 gtk_clist_set_column_width (GTK_CLIST (tdata->clist), 2, 85); | |
1642 gtk_clist_set_column_width (GTK_CLIST (tdata->clist), 3, 85); | |
1643 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), scroll, TRUE, TRUE, | |
1644 0); | |
1645 gtk_widget_show (tdata->clist); | |
1646 gtk_widget_show (scroll); | |
1647 | |
1648 for (templist = tdata->files; templist != NULL; | |
1649 templist = templist->next) | |
1650 { | |
1651 tempfle = templist->data; | |
1652 if (tempfle->startsize == 0 || tempfle->isdir) | |
1653 { | |
1654 tempfle->shown = 0; | |
1655 continue; | |
1656 } | |
1657 tempfle->shown = 1; | |
1658 | |
1659 pos = tempfle->destfile; | |
1660 len = strlen (GFTP_GET_DIRECTORY (tdata->toreq)); | |
1661 if (strncmp (pos, GFTP_GET_DIRECTORY (tdata->toreq), len) == 0) | |
1662 pos = tempfle->destfile + len + 1; | |
1663 add_data[0] = pos; | |
1664 | |
1665 if (overwrite_by_default) | |
1666 add_data[3] = _("Overwrite"); | |
1667 else | |
1668 { | |
1669 if (tempfle->startsize >= tempfle->size) | |
1670 { | |
1671 add_data[3] = _("Skip"); | |
1672 tempfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
1673 } | |
1674 else | |
1675 { | |
1676 add_data[3] = _("Resume"); | |
1677 tempfle->transfer_action = GFTP_TRANS_ACTION_RESUME; | |
1678 } | |
1679 } | |
1680 | |
1681 if (tdata->transfer_direction == GFTP_DIRECTION_DOWNLOAD) | |
1682 { | |
1683 add_data[2] = insert_commas (tempfle->size, tempstr, | |
1684 sizeof (tempstr)); | |
1685 add_data[1] = insert_commas (tempfle->startsize, temp1str, | |
1686 sizeof (temp1str)); | |
1687 } | |
1688 else | |
1689 { | |
1690 add_data[1] = insert_commas (tempfle->size, tempstr, | |
1691 sizeof (tempstr)); | |
1692 add_data[2] = insert_commas (tempfle->startsize, temp1str, | |
1693 sizeof (temp1str)); | |
1694 } | |
1695 i = gtk_clist_append (GTK_CLIST (tdata->clist), add_data); | |
1696 gtk_clist_set_row_data (GTK_CLIST (tdata->clist), i, tempfle); | |
1697 } | |
1698 | |
1699 gtk_clist_select_all (GTK_CLIST (tdata->clist)); | |
1700 | |
1701 hbox = gtk_hbox_new (TRUE, 20); | |
1702 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, TRUE, TRUE, 0); | |
1703 gtk_widget_show (hbox); | |
1704 | |
1705 tempwid = gtk_button_new_with_label (_("Overwrite")); | |
1706 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
1707 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
1708 GTK_SIGNAL_FUNC (overwrite), (gpointer) tdata); | |
1709 gtk_widget_show (tempwid); | |
1710 | |
1711 tempwid = gtk_button_new_with_label (_("Resume")); | |
1712 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
1713 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
1714 GTK_SIGNAL_FUNC (resume), (gpointer) tdata); | |
1715 gtk_widget_show (tempwid); | |
1716 | |
1717 tempwid = gtk_button_new_with_label (_("Skip File")); | |
1718 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
1719 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", GTK_SIGNAL_FUNC (skip), | |
1720 (gpointer) tdata); | |
1721 gtk_widget_show (tempwid); | |
1722 | |
1723 hbox = gtk_hbox_new (TRUE, 20); | |
1724 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, TRUE, TRUE, 0); | |
1725 gtk_widget_show (hbox); | |
1726 | |
1727 tempwid = gtk_button_new_with_label (_("Select All")); | |
1728 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
1729 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
1730 GTK_SIGNAL_FUNC (trans_selectall), (gpointer) tdata); | |
1731 gtk_widget_show (tempwid); | |
1732 | |
1733 tempwid = gtk_button_new_with_label (_("Deselect All")); | |
1734 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
1735 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
1736 GTK_SIGNAL_FUNC (trans_unselectall), (gpointer) tdata); | |
1737 gtk_widget_show (tempwid); | |
1738 | |
1739 tempwid = gtk_button_new_with_label (_("OK")); | |
1740 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); | |
1741 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid, | |
1742 TRUE, TRUE, 0); | |
1743 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", GTK_SIGNAL_FUNC (ok), | |
1744 (gpointer) tdata); | |
1745 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked", | |
1746 GTK_SIGNAL_FUNC (gtk_widget_destroy), | |
1747 GTK_OBJECT (dialog)); | |
1748 gtk_widget_grab_default (tempwid); | |
1749 gtk_widget_show (tempwid); | |
1750 | |
1751 tempwid = gtk_button_new_with_label (_(" Cancel ")); | |
1752 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); | |
1753 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid, | |
1754 TRUE, TRUE, 0); | |
1755 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
1756 GTK_SIGNAL_FUNC (cancel), (gpointer) tdata); | |
1757 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked", | |
1758 GTK_SIGNAL_FUNC (gtk_widget_destroy), | |
1759 GTK_OBJECT (dialog)); | |
1760 gtk_widget_show (tempwid); | |
1761 | |
1762 gtk_widget_show (dialog); | |
1763 dialog = NULL; | |
1764 } | |
1765 | |
1766 | |
1767 static void | |
1768 trans_selectall (GtkWidget * widget, gpointer data) | |
1769 { | |
1770 gftp_transfer * tdata; | |
1771 tdata = data; | |
1772 | |
1773 gtk_clist_select_all (GTK_CLIST (tdata->clist)); | |
1774 } | |
1775 | |
1776 | |
1777 static void | |
1778 trans_unselectall (GtkWidget * widget, gpointer data) | |
1779 { | |
1780 gftp_transfer * tdata; | |
1781 tdata = data; | |
1782 | |
1783 gtk_clist_unselect_all (GTK_CLIST (tdata->clist)); | |
1784 } | |
1785 | |
1786 | |
1787 static void | |
1788 overwrite (GtkWidget * widget, gpointer data) | |
1789 { | |
1790 GList * templist, * filelist; | |
1791 gftp_transfer * tdata; | |
1792 gftp_file * tempfle; | |
1793 int curpos; | |
1794 | |
1795 tdata = data; | |
1796 curpos = 0; | |
1797 filelist = tdata->files; | |
1798 templist = GTK_CLIST (tdata->clist)->selection; | |
1799 while (templist != NULL) | |
1800 { | |
1801 templist = get_next_selection (templist, &filelist, &curpos); | |
1802 tempfle = filelist->data; | |
1803 tempfle->transfer_action = GFTP_TRANS_ACTION_OVERWRITE; | |
1804 gtk_clist_set_text (GTK_CLIST (tdata->clist), curpos, 3, _("Overwrite")); | |
1805 } | |
1806 } | |
1807 | |
1808 | |
1809 static void | |
1810 resume (GtkWidget * widget, gpointer data) | |
1811 { | |
1812 GList * templist, * filelist; | |
1813 gftp_transfer * tdata; | |
1814 gftp_file * tempfle; | |
1815 int curpos; | |
1816 | |
1817 tdata = data; | |
1818 curpos = 0; | |
1819 filelist = tdata->files; | |
1820 templist = GTK_CLIST (tdata->clist)->selection; | |
1821 while (templist != NULL) | |
1822 { | |
1823 templist = get_next_selection (templist, &filelist, &curpos); | |
1824 tempfle = filelist->data; | |
1825 tempfle->transfer_action = GFTP_TRANS_ACTION_RESUME; | |
1826 gtk_clist_set_text (GTK_CLIST (tdata->clist), curpos, 3, _("Resume")); | |
1827 } | |
1828 } | |
1829 | |
1830 | |
1831 static void | |
1832 skip (GtkWidget * widget, gpointer data) | |
1833 { | |
1834 GList * templist, * filelist; | |
1835 gftp_transfer * tdata; | |
1836 gftp_file * tempfle; | |
1837 int curpos; | |
1838 | |
1839 tdata = data; | |
1840 curpos = 0; | |
1841 filelist = tdata->files; | |
1842 templist = GTK_CLIST (tdata->clist)->selection; | |
1843 while (templist != NULL) | |
1844 { | |
1845 templist = get_next_selection (templist, &filelist, &curpos); | |
1846 tempfle = filelist->data; | |
1847 tempfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
1848 gtk_clist_set_text (GTK_CLIST (tdata->clist), curpos, 3, _("Skip")); | |
1849 } | |
1850 } | |
1851 | |
1852 | |
1853 static void | |
1854 ok (GtkWidget * widget, gpointer data) | |
1855 { | |
1856 gftp_transfer * tdata; | |
1857 gftp_file * tempfle; | |
1858 GList * templist; | |
1859 | |
1860 tdata = data; | |
1861 pthread_mutex_lock ((pthread_mutex_t *) tdata->structmutex); | |
1862 for (templist = tdata->files; templist != NULL; templist = templist->next) | |
1863 { | |
1864 tempfle = templist->data; | |
1865 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) | |
1866 break; | |
1867 } | |
1868 | |
1869 if (templist == NULL) | |
1870 { | |
1871 tdata->show = 0; | |
1872 tdata->ready = tdata->done = 1; | |
1873 } | |
1874 else | |
1875 tdata->show = tdata->ready = 1; | |
1876 pthread_mutex_unlock ((pthread_mutex_t *) tdata->structmutex); | |
1877 } | |
1878 | |
1879 | |
1880 static void | |
1881 cancel (GtkWidget * widget, gpointer data) | |
1882 { | |
1883 gftp_transfer * tdata; | |
1884 | |
1885 tdata = data; | |
1886 pthread_mutex_lock ((pthread_mutex_t *) tdata->structmutex); | |
1887 tdata->show = 0; | |
1888 tdata->done = tdata->ready = 1; | |
1889 pthread_mutex_unlock ((pthread_mutex_t *) tdata->structmutex); | |
1890 } | |
1891 | |
1892 | |
1893 static void | |
1894 gftp_gtk_calc_kbs (gftp_transfer * tdata, ssize_t num_read) | |
1895 { | |
1896 unsigned long waitusecs; | |
1897 double difftime, curkbs; | |
1898 gftp_file * tempfle; | |
1899 struct timeval tv; | |
1900 unsigned long toadd; | |
1901 | |
1902 gettimeofday (&tv, NULL); | |
1903 pthread_mutex_lock (tdata->statmutex); | |
1904 | |
1905 tempfle = tdata->curfle->data; | |
1906 tdata->trans_bytes += num_read; | |
1907 tdata->curtrans += num_read; | |
1908 tdata->stalled = 0; | |
1909 | |
1910 difftime = (tv.tv_sec - tdata->starttime.tv_sec) + ((double) (tv.tv_usec - tdata->starttime.tv_usec) / 1000000.0); | |
19 | 1911 if (difftime <= 0) |
1 | 1912 tdata->kbs = (double) tdata->trans_bytes / 1024.0; |
1913 else | |
1914 tdata->kbs = (double) tdata->trans_bytes / 1024.0 / difftime; | |
1915 | |
1916 difftime = (tv.tv_sec - tdata->lasttime.tv_sec) + ((double) (tv.tv_usec - tdata->lasttime.tv_usec) / 1000000.0); | |
1917 | |
1918 if (difftime <= 0) | |
1919 curkbs = (double) (num_read / 1024.0); | |
1920 else | |
1921 curkbs = (double) (num_read / 1024.0 / difftime); | |
1922 | |
1923 if (tdata->fromreq->maxkbs > 0 && | |
1924 curkbs > tdata->fromreq->maxkbs) | |
1925 { | |
1926 waitusecs = (double) num_read / 1024.0 / tdata->fromreq->maxkbs * 1000000.0 - difftime; | |
1927 | |
1928 if (waitusecs > 0) | |
1929 { | |
1930 pthread_mutex_unlock (tdata->statmutex); | |
1931 difftime += ((double) waitusecs / 1000000.0); | |
1932 usleep (waitusecs); | |
1933 pthread_mutex_lock (tdata->statmutex); | |
1934 } | |
1935 } | |
1936 | |
1937 /* I don't call gettimeofday (&tdata->lasttime) here because this will use | |
1938 less system resources. This will be close enough for what we need */ | |
1939 difftime += tdata->lasttime.tv_usec / 1000000.0; | |
1940 toadd = (long) difftime; | |
1941 difftime -= toadd; | |
1942 tdata->lasttime.tv_sec += toadd; | |
1943 tdata->lasttime.tv_usec = difftime * 1000000.0; | |
1944 | |
1945 pthread_mutex_unlock (tdata->statmutex); | |
1946 } | |
1947 | |
1948 | |
1949 static void | |
1950 check_done_process (void) | |
1951 { | |
1952 gftp_viewedit_data * ve_proc; | |
1953 GList * curdata, *deldata; | |
1954 struct stat st; | |
1955 int ret; | |
1956 char *str; | |
1957 pid_t pid; | |
1958 | |
1959 viewedit_process_done = 0; | |
1960 while ((pid = waitpid (-1, &ret, WNOHANG)) > 0) | |
1961 { | |
1962 curdata = viewedit_processes; | |
1963 while (curdata != NULL) | |
1964 { | |
1965 ve_proc = curdata->data; | |
1966 deldata = curdata; | |
1967 curdata = curdata->next; | |
1968 if (ve_proc->pid == pid) | |
1969 { | |
1970 viewedit_processes = g_list_remove_link (viewedit_processes, | |
1971 deldata); | |
1972 if (ret != 0) | |
1973 ftp_log (gftp_logging_error, NULL, | |
1974 _("Error: Child %d returned %d\n"), pid, ret); | |
1975 else | |
1976 ftp_log (gftp_logging_misc, NULL, | |
1977 _("Child %d returned successfully\n"), pid); | |
1978 | |
1979 if (!ve_proc->view && !ve_proc->dontupload) | |
1980 { | |
1981 /* We was editing the file. Upload it */ | |
1982 if (stat (ve_proc->filename, &st) == -1) | |
1983 ftp_log (gftp_logging_error, NULL, | |
1984 _("Error: Cannot get information about file %s: %s\n"), | |
1985 ve_proc->filename, g_strerror (errno)); | |
1986 else if (st.st_mtime == ve_proc->st.st_mtime) | |
1987 { | |
1988 ftp_log (gftp_logging_misc, NULL, | |
1989 _("File %s was not changed\n"), | |
1990 ve_proc->filename); | |
1991 remove_file (ve_proc->filename); | |
1992 } | |
1993 else | |
1994 { | |
1995 memcpy (&ve_proc->st, &st, sizeof (ve_proc->st)); | |
1996 str = g_strdup_printf ( | |
19 | 1997 _("File %s has changed.\nWould you like to upload it?"), |
1 | 1998 ve_proc->remote_filename); |
1999 | |
19 | 2000 MakeYesNoDialog (_("Edit File"), str, |
2001 do_upload, ve_proc, | |
2002 dont_upload, ve_proc); | |
1 | 2003 g_free (str); |
2004 continue; | |
2005 } | |
2006 } | |
2007 | |
19 | 2008 free_edit_data (ve_proc); |
1 | 2009 continue; |
2010 } | |
2011 } | |
2012 } | |
2013 } | |
2014 | |
2015 | |
2016 static void | |
19 | 2017 do_upload (gftp_viewedit_data * ve_proc, gftp_dialog_data * ddata) |
1 | 2018 { |
2019 gftp_file * tempfle; | |
2020 GList * newfile; | |
2021 | |
2022 tempfle = g_malloc0 (sizeof (*tempfle)); | |
2023 tempfle->destfile = ve_proc->remote_filename; | |
2024 ve_proc->remote_filename = NULL; | |
2025 tempfle->file = ve_proc->filename; | |
2026 ve_proc->filename = NULL; | |
2027 tempfle->done_rm = 1; | |
2028 newfile = g_list_append (NULL, tempfle); | |
2029 add_file_transfer (ve_proc->fromwdata->request, ve_proc->towdata->request, | |
2030 ve_proc->fromwdata, ve_proc->towdata, newfile, 1); | |
19 | 2031 free_edit_data (ve_proc); |
1 | 2032 } |
2033 | |
2034 | |
2035 static void | |
19 | 2036 dont_upload (gftp_viewedit_data * ve_proc, gftp_dialog_data * ddata) |
1 | 2037 { |
2038 remove_file (ve_proc->filename); | |
19 | 2039 free_edit_data (ve_proc); |
1 | 2040 } |
2041 | |
2042 | |
2043 static void | |
19 | 2044 free_edit_data (gftp_viewedit_data * ve_proc) |
1 | 2045 { |
2046 int i; | |
2047 | |
2048 if (ve_proc->filename) | |
2049 g_free (ve_proc->filename); | |
2050 if (ve_proc->remote_filename) | |
2051 g_free (ve_proc->remote_filename); | |
2052 for (i = 0; ve_proc->argv[i] != NULL; i++) | |
2053 g_free (ve_proc->argv[i]); | |
2054 g_free (ve_proc->argv); | |
2055 g_free (ve_proc); | |
2056 } | |
2057 | |
2058 | |
2059 static int | |
2060 get_status (gftp_transfer * tdata, ssize_t num_read) | |
2061 { | |
2062 gftp_file * tempfle; | |
2063 struct timeval tv; | |
2064 | |
2065 pthread_mutex_lock (tdata->structmutex); | |
2066 if (tdata->curfle == NULL) | |
2067 { | |
2068 pthread_mutex_unlock (tdata->structmutex); | |
2069 return (-1); | |
2070 } | |
2071 tempfle = tdata->curfle->data; | |
2072 pthread_mutex_unlock (tdata->structmutex); | |
2073 | |
2074 gftp_disconnect (tdata->fromreq); | |
2075 gftp_disconnect (tdata->toreq); | |
2076 if (num_read < 0 || tdata->skip_file) | |
2077 { | |
2078 if (tdata->fromreq->retries != 0 && tdata->current_file_retries >= tdata->fromreq->retries) | |
2079 { | |
2080 tdata->fromreq->logging_function (gftp_logging_error, | |
2081 tdata->fromreq->user_data, | |
2082 _("Error: Remote site %s disconnected. Max retries reached...giving up\n"), | |
2083 GFTP_GET_HOSTNAME (tdata->fromreq)); | |
2084 return (-1); | |
2085 } | |
2086 else | |
2087 { | |
2088 tdata->fromreq->logging_function (gftp_logging_error, | |
2089 tdata->fromreq->user_data, | |
2090 _("Error: Remote site %s disconnected. Will reconnect in %d seconds\n"), | |
2091 GFTP_GET_HOSTNAME (tdata->fromreq), tdata->fromreq->sleep_time); | |
2092 } | |
2093 | |
2094 while (tdata->fromreq->retries == 0 || | |
2095 tdata->current_file_retries <= tdata->fromreq->retries) | |
2096 { | |
2097 if (!tdata->skip_file) | |
2098 { | |
2099 tv.tv_sec = tdata->fromreq->sleep_time; | |
2100 tv.tv_usec = 0; | |
2101 select (0, NULL, NULL, NULL, &tv); | |
2102 } | |
2103 | |
2104 if (gftp_connect (tdata->fromreq) == 0 && | |
2105 gftp_connect (tdata->toreq) == 0) | |
2106 { | |
2107 pthread_mutex_lock (tdata->structmutex); | |
2108 tdata->resumed_bytes = tdata->resumed_bytes + tdata->trans_bytes - tdata->curresumed - tdata->curtrans; | |
2109 tdata->trans_bytes = 0; | |
2110 if (tdata->skip_file) | |
2111 { | |
2112 tdata->total_bytes -= tempfle->size; | |
2113 tdata->curtrans = 0; | |
2114 | |
2115 tdata->curfle = tdata->curfle->next; | |
2116 tdata->next_file = 1; | |
2117 tdata->skip_file = 0; | |
2118 tdata->cancel = 0; | |
2119 } | |
2120 else | |
2121 { | |
2122 tempfle->transfer_action = GFTP_TRANS_ACTION_RESUME; | |
2123 tempfle->startsize = tdata->curtrans + tdata->curresumed; | |
2124 /* We decrement this here because it will be incremented in | |
2125 the loop again */ | |
2126 tdata->curresumed = 0; | |
2127 tdata->current_file_number--; /* Decrement this because it | |
2128 will be incremented when we | |
2129 continue in the loop */ | |
2130 } | |
2131 gettimeofday (&tdata->starttime, NULL); | |
2132 pthread_mutex_unlock (tdata->structmutex); | |
2133 return (1); | |
2134 } | |
2135 else | |
2136 tdata->current_file_retries++; | |
2137 } | |
2138 } | |
2139 else if (tdata->cancel) | |
2140 return (-1); | |
2141 | |
2142 return (0); | |
2143 } | |
2144 | |
2145 | |
2146 static void | |
2147 wakeup_main_thread (gpointer data, gint source, GdkInputCondition condition) | |
2148 { | |
2149 gftp_request * request; | |
2150 char c; | |
2151 | |
2152 request = data; | |
2153 if (request->wakeup_main_thread[0] > 0) | |
2154 read (request->wakeup_main_thread[0], &c, 1); | |
2155 } | |
2156 | |
2157 | |
2158 static gint | |
2159 setup_wakeup_main_thread (gftp_request * request) | |
2160 { | |
2161 gint handler; | |
2162 | |
2163 if (socketpair (AF_UNIX, SOCK_STREAM, 0, request->wakeup_main_thread) == 0) | |
2164 { | |
2165 handler = gdk_input_add (request->wakeup_main_thread[0], | |
2166 GDK_INPUT_READ, wakeup_main_thread, request); | |
2167 } | |
2168 else | |
2169 { | |
2170 request->wakeup_main_thread[0] = 0; | |
2171 request->wakeup_main_thread[1] = 0; | |
2172 handler = 0; | |
2173 } | |
2174 return (handler); | |
2175 } | |
2176 | |
2177 | |
2178 static void | |
2179 teardown_wakeup_main_thread (gftp_request * request, gint handler) | |
2180 { | |
2181 if (request->wakeup_main_thread[0] > 0 && request->wakeup_main_thread[1] > 0) | |
2182 { | |
2183 gdk_input_remove (handler); | |
2184 close (request->wakeup_main_thread[0]); | |
2185 close (request->wakeup_main_thread[1]); | |
2186 request->wakeup_main_thread[0] = 0; | |
2187 request->wakeup_main_thread[1] = 0; | |
2188 } | |
2189 } | |
2190 | |
2191 | |
2192 static mode_t | |
2193 parse_attribs (char *attribs) | |
2194 { | |
2195 mode_t mode; | |
2196 int cur; | |
2197 | |
2198 cur = 0; | |
2199 if (attribs[1] == 'r') | |
2200 cur += 4; | |
2201 if (attribs[2] == 'w') | |
2202 cur += 2; | |
2203 if (attribs[3] == 'x' || | |
2204 attribs[3] == 's') | |
2205 cur += 1; | |
2206 mode = cur; | |
2207 | |
2208 cur = 0; | |
2209 if (attribs[4] == 'r') | |
2210 cur += 4; | |
2211 if (attribs[5] == 'w') | |
2212 cur += 2; | |
2213 if (attribs[6] == 'x' || | |
2214 attribs[6] == 's') | |
2215 cur += 1; | |
2216 mode = (mode * 10) + cur; | |
2217 | |
2218 cur = 0; | |
2219 if (attribs[7] == 'r') | |
2220 cur += 4; | |
2221 if (attribs[8] == 'w') | |
2222 cur += 2; | |
2223 if (attribs[9] == 'x' || | |
2224 attribs[9] == 's') | |
2225 cur += 1; | |
2226 mode = (mode * 10) + cur; | |
2227 | |
2228 return (mode); | |
2229 } | |
2230 | |
2231 | |
2232 static void | |
2233 remove_file (char *filename) | |
2234 { | |
2235 if (unlink (filename) == 0) | |
2236 ftp_log (gftp_logging_misc, NULL, _("Successfully removed %s\n"), | |
2237 filename); | |
2238 else | |
2239 ftp_log (gftp_logging_error, NULL, | |
2240 _("Error: Could not remove file %s: %s\n"), filename, | |
2241 g_strerror (errno)); | |
2242 } | |
2243 | |
2244 | |
2245 static RETSIGTYPE | |
2246 sig_connquit (int signo) | |
2247 { | |
2248 signal (signo, sig_connquit); | |
2249 siglongjmp (connenvir, signo == SIGINT ? 1 : 2); | |
2250 } | |
2251 |