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