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