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