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