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