Mercurial > gftp.yaz
annotate src/gtk/transfer.c @ 67:aa971a4bb16f
2002-11-27 Brian Masney <masneyb@gftp.org>
* Officially release 2.0.14rc1
* lib/cache.c - take out a warning message
* lib/misc.c lib/protocols.c lib/gftp.h lib/gtk/dnd.c lib/transfer.c -
add second argument (free_request) to gftp_request_destroy
* lib/protocols.c (gftp_parse_url) - make sure the request structure
is cleared before we start to modify it
* src/gtk/gftp-text.c - fixed crash if you didn't enter a username
author | masneyb |
---|---|
date | Wed, 27 Nov 2002 14:29:57 +0000 |
parents | cd3e457cbc85 |
children | e2b30d0c97a4 |
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 { | |
67 | 1001 gftp_request_destroy (fromreq, 1); |
1002 gftp_request_destroy (toreq, 1); | |
1 | 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 && |
67 | 1408 ((fromreq->sockfd < 0 && fromreq->cached) || fromreq->always_connected) && |
66 | 1409 (tdata->fromreq->sockfd > 0 || tdata->fromreq->always_connected) && |
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 && | |
66 | 1463 (((gftp_window_data *) tdata->fromwdata)->request->sockfd > 0 || |
1464 ((gftp_window_data *) tdata->fromwdata)->request->always_connected) && | |
1 | 1465 !((gftp_window_data *) tdata->fromwdata)->request->stopable && |
1466 compare_request (tdata->fromreq, ((gftp_window_data *) tdata->fromwdata)->request, 0)) | |
1467 { | |
63 | 1468 gftp_swap_socks (tdata->toreq, |
1469 ((gftp_window_data *) tdata->towdata)->request); | |
1470 gftp_swap_socks (tdata->fromreq, | |
1471 ((gftp_window_data *) tdata->fromwdata)->request); | |
1 | 1472 update_window_info (); |
1473 } | |
1474 transfer_in_progress++; | |
1475 tdata->started = 1; | |
1476 tdata->stalled = 1; | |
1477 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->node, 1, | |
1478 _("Connecting...")); | |
1479 pthread_create (&tid, NULL, gftp_gtk_transfer_files, tdata); | |
1480 } | |
1481 } | |
1482 | |
1483 | |
1484 static void | |
1485 update_file_status (gftp_transfer * tdata) | |
1486 { | |
1487 char totstr[100], dlstr[100], gotstr[50], ofstr[50]; | |
1488 int hours, mins, secs, pcent, st; | |
1489 double remaining; | |
1490 gftp_file * tempfle; | |
1491 struct timeval tv; | |
1492 | |
1493 pthread_mutex_lock (tdata->statmutex); | |
1494 tempfle = tdata->curfle->data; | |
1495 | |
1496 gettimeofday (&tv, NULL); | |
1497 if ((remaining = (double) (tv.tv_sec - tdata->starttime.tv_sec) + ((double) (tv.tv_usec - tdata->starttime.tv_usec) / 1000000.0)) == 0) | |
1498 remaining = 1.0; | |
1499 | |
1500 remaining = ((double) (tdata->total_bytes - tdata->trans_bytes - tdata->resumed_bytes)) / 1024.0 / tdata->kbs; | |
1501 hours = (off_t) remaining / 3600; | |
1502 remaining -= hours * 3600; | |
1503 mins = (off_t) remaining / 60; | |
1504 remaining -= mins * 60; | |
1505 secs = (off_t) remaining; | |
1506 | |
1507 if (hours < 0 || mins < 0 || secs < 0) | |
1508 { | |
1509 pthread_mutex_unlock (tdata->statmutex); | |
1510 return; | |
1511 } | |
1512 | |
1513 pcent = (int) ((double) (tdata->trans_bytes + tdata->resumed_bytes) / (double) tdata->total_bytes * 100.0); | |
1514 if (pcent < 0 || pcent > 100) | |
1515 pcent = 0; | |
1516 | |
1517 g_snprintf (totstr, sizeof (totstr), | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
1518 _("%d%% complete, %02d:%02d:%02d est. time remaining. (File %ld of %ld)"), |
1 | 1519 pcent, hours, mins, secs, tdata->current_file_number, |
1520 tdata->numdirs + tdata->numfiles); | |
1521 | |
1522 *dlstr = '\0'; | |
1523 if (!tdata->stalled) | |
1524 { | |
1525 insert_commas (tdata->curtrans + tdata->curresumed, gotstr, sizeof (gotstr)); | |
1526 insert_commas (tempfle->size, ofstr, sizeof (ofstr)); | |
1527 st = 1; | |
1528 if (tv.tv_sec - tdata->lasttime.tv_sec <= 5) | |
1529 { | |
1530 if (tdata->curfle->next != NULL) | |
1531 { | |
1532 remaining = ((double) (tempfle->size - tdata->curtrans - tdata->curresumed)) / 1024.0 / tdata->kbs; | |
1533 hours = (off_t) remaining / 3600; | |
1534 remaining -= hours * 3600; | |
1535 mins = (off_t) remaining / 60; | |
1536 remaining -= mins * 60; | |
1537 secs = (off_t) remaining; | |
1538 } | |
1539 | |
1540 if (!(hours < 0 || mins < 0 || secs < 0)) | |
1541 { | |
1542 g_snprintf (dlstr, sizeof (dlstr), | |
1543 _("Recv %s of %s at %.2fKB/s, %02d:%02d:%02d est. time remaining"), gotstr, ofstr, tdata->kbs, hours, mins, secs); | |
1544 st = 0; | |
1545 } | |
1546 } | |
1547 | |
1548 if (st) | |
1549 { | |
1550 tdata->stalled = 1; | |
1551 g_snprintf (dlstr, sizeof (dlstr), | |
1552 _("Recv %s of %s, transfer stalled, unknown time remaining"), | |
1553 gotstr, ofstr); | |
1554 } | |
1555 } | |
1556 | |
1557 pthread_mutex_unlock (tdata->statmutex); | |
1558 | |
1559 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tdata->node, 1, totstr); | |
1560 | |
1561 if (*dlstr != '\0') | |
1562 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->node, 1, dlstr); | |
1563 } | |
1564 | |
56 | 1565 static void |
1566 update_window_transfer_bytes (gftp_window_data * wdata) | |
1567 { | |
1568 char *tempstr, *temp1str; | |
1569 | |
1570 if (wdata->request->gotbytes == -1) | |
1571 { | |
1572 update_window_info (); | |
1573 wdata->request->gotbytes = 0; | |
1574 } | |
1575 else | |
1576 { | |
1577 tempstr = insert_commas (wdata->request->gotbytes, NULL, 0); | |
1578 temp1str = g_strdup_printf (_("Retrieving file names...%s bytes"), | |
1579 tempstr); | |
1580 gtk_label_set (GTK_LABEL (wdata->hoststxt), temp1str); | |
1581 g_free (tempstr); | |
1582 g_free (temp1str); | |
1583 } | |
1584 } | |
1585 | |
1 | 1586 |
48 | 1587 gint |
1588 update_downloads (gpointer data) | |
1589 { | |
1590 GList * templist, * next; | |
1591 gftp_transfer * tdata; | |
1592 | |
1593 if (file_transfer_logs != NULL) | |
1594 display_cached_logs (); | |
1595 | |
56 | 1596 if (window1.request->gotbytes != 0) |
1597 update_window_transfer_bytes (&window1); | |
48 | 1598 if (window2.request->gotbytes != 0) |
56 | 1599 update_window_transfer_bytes (&window2); |
48 | 1600 |
1601 if (viewedit_process_done) | |
1602 check_done_process (); | |
1603 | |
1604 for (templist = file_transfers; templist != NULL;) | |
1605 { | |
1606 tdata = templist->data; | |
1607 if (tdata->ready) | |
1608 { | |
1609 pthread_mutex_lock (tdata->structmutex); | |
1610 | |
1611 if (tdata->next_file) | |
1612 on_next_transfer (tdata); | |
1613 else if (tdata->show) | |
1614 show_transfer (tdata); | |
1615 else if (tdata->done) | |
1616 { | |
1617 next = templist->next; | |
59 | 1618 pthread_mutex_unlock (tdata->structmutex); |
48 | 1619 transfer_done (templist); |
1620 templist = next; | |
1621 continue; | |
1622 } | |
1623 | |
1624 if (tdata->curfle != NULL) | |
1625 { | |
1626 if (!tdata->started && start_file_transfers && | |
1627 (transfer_in_progress == 0 || !do_one_transfer_at_a_time)) | |
1628 create_transfer (tdata); | |
1629 | |
1630 if (tdata->started) | |
1631 update_file_status (tdata); | |
1632 } | |
1633 pthread_mutex_unlock (tdata->structmutex); | |
1634 } | |
1635 templist = templist->next; | |
1636 } | |
1637 | |
1638 gtk_timeout_add (500, update_downloads, NULL); | |
1639 return (0); | |
1640 } | |
1641 | |
1642 | |
1 | 1643 void |
1644 start_transfer (gpointer data) | |
1645 { | |
1646 gftp_curtrans_data * transdata; | |
1647 GtkCTreeNode * node; | |
1648 | |
1649 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1650 { | |
1651 ftp_log (gftp_logging_misc, NULL, | |
1652 _("There are no file transfers selected\n")); | |
1653 return; | |
1654 } | |
1655 node = GTK_CLIST (dlwdw)->selection->data; | |
1656 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1657 | |
1658 pthread_mutex_lock (transdata->transfer->structmutex); | |
1659 if (!transdata->transfer->started) | |
1660 create_transfer (transdata->transfer); | |
1661 pthread_mutex_unlock (transdata->transfer->structmutex); | |
1662 } | |
1663 | |
1664 | |
1665 void | |
1666 stop_transfer (gpointer data) | |
1667 { | |
1668 gftp_curtrans_data * transdata; | |
1669 GtkCTreeNode * node; | |
1670 | |
1671 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1672 { | |
1673 ftp_log (gftp_logging_misc, NULL, | |
1674 _("There are no file transfers selected\n")); | |
1675 return; | |
1676 } | |
1677 node = GTK_CLIST (dlwdw)->selection->data; | |
1678 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1679 | |
1680 pthread_mutex_lock (transdata->transfer->structmutex); | |
1681 if (transdata->transfer->started) | |
1682 { | |
1683 transdata->transfer->cancel = 1; | |
42 | 1684 transdata->transfer->fromreq->cancel = 1; |
1685 transdata->transfer->toreq->cancel = 1; | |
1 | 1686 transdata->transfer->skip_file = 0; |
1687 } | |
1688 else | |
1689 transdata->transfer->done = 1; | |
40 | 1690 pthread_mutex_unlock (transdata->transfer->structmutex); |
1691 | |
1 | 1692 ftp_log (gftp_logging_misc, NULL, _("Stopping the transfer on host %s\n"), |
1693 transdata->transfer->fromreq->hostname); | |
1694 } | |
1695 | |
1696 | |
1697 void | |
1698 skip_transfer (gpointer data) | |
1699 { | |
1700 gftp_curtrans_data * transdata; | |
1701 GtkCTreeNode * node; | |
1702 gftp_file * curfle; | |
40 | 1703 char *file; |
1 | 1704 |
1705 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1706 { | |
1707 ftp_log (gftp_logging_misc, NULL, | |
1708 _("There are no file transfers selected\n")); | |
1709 return; | |
1710 } | |
1711 node = GTK_CLIST (dlwdw)->selection->data; | |
1712 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1713 | |
1714 pthread_mutex_lock (transdata->transfer->structmutex); | |
1715 if (transdata->transfer->curfle != NULL) | |
1716 { | |
1717 curfle = transdata->transfer->curfle->data; | |
1718 if (transdata->transfer->started) | |
1719 { | |
1720 transdata->transfer->cancel = 1; | |
42 | 1721 transdata->transfer->fromreq->cancel = 1; |
1722 transdata->transfer->toreq->cancel = 1; | |
1 | 1723 transdata->transfer->skip_file = 1; |
1724 } | |
1725 | |
1726 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
40 | 1727 file = curfle->file; |
1 | 1728 } |
40 | 1729 else |
1730 file = NULL; | |
1 | 1731 pthread_mutex_unlock (transdata->transfer->structmutex); |
40 | 1732 |
1733 ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"), | |
1734 file, transdata->transfer->fromreq->hostname); | |
1 | 1735 } |
1736 | |
1737 | |
1738 void | |
1739 remove_file_transfer (gpointer data) | |
1740 { | |
1741 gftp_curtrans_data * transdata; | |
1742 GtkCTreeNode * node; | |
1743 gftp_file * curfle; | |
1744 | |
1745 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1746 { | |
1747 ftp_log (gftp_logging_misc, NULL, | |
1748 _("There are no file transfers selected\n")); | |
1749 return; | |
1750 } | |
1751 | |
1752 node = GTK_CLIST (dlwdw)->selection->data; | |
1753 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1754 | |
1755 | |
1756 if (transdata->curfle == NULL || transdata->curfle->data == NULL) | |
1757 return; | |
1758 | |
1759 curfle = transdata->curfle->data; | |
1760 | |
1761 if (curfle->transfer_action & GFTP_TRANS_ACTION_SKIP) | |
1762 return; | |
1763 | |
1764 pthread_mutex_lock (transdata->transfer->structmutex); | |
1765 | |
1766 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
1767 | |
1768 if (transdata->transfer->started && | |
1769 transdata->curfle == transdata->transfer->curfle) | |
1770 { | |
1771 transdata->transfer->cancel = 1; | |
42 | 1772 transdata->transfer->fromreq->cancel = 1; |
1773 transdata->transfer->toreq->cancel = 1; | |
1 | 1774 transdata->transfer->skip_file = 1; |
1775 } | |
1776 else if (transdata->curfle != transdata->transfer->curfle && | |
1777 !curfle->transfer_done) | |
1778 { | |
1779 gtk_ctree_node_set_text (GTK_CTREE (dlwdw), curfle->node, 1, | |
1780 _("Skipped")); | |
1781 transdata->transfer->total_bytes -= curfle->size; | |
1782 } | |
1783 | |
40 | 1784 pthread_mutex_unlock (transdata->transfer->structmutex); |
1785 | |
1 | 1786 ftp_log (gftp_logging_misc, NULL, _("Skipping file %s on host %s\n"), |
1787 curfle->file, transdata->transfer->fromreq->hostname); | |
1788 } | |
1789 | |
1790 | |
1791 void | |
1792 move_transfer_up (gpointer data) | |
1793 { | |
1794 GList * firstentry, * secentry, * lastentry; | |
1795 gftp_curtrans_data * transdata; | |
1796 GtkCTreeNode * node; | |
1797 | |
1798 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1799 { | |
1800 ftp_log (gftp_logging_misc, NULL, | |
1801 _("There are no file transfers selected\n")); | |
1802 return; | |
1803 } | |
1804 node = GTK_CLIST (dlwdw)->selection->data; | |
1805 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1806 | |
1807 if (transdata->curfle == NULL) | |
1808 return; | |
1809 | |
1810 pthread_mutex_lock (transdata->transfer->structmutex); | |
1811 if (transdata->curfle->prev != NULL && (!transdata->transfer->started || | |
1812 (transdata->transfer->curfle != transdata->curfle && | |
1813 transdata->transfer->curfle != transdata->curfle->prev))) | |
1814 { | |
1815 if (transdata->curfle->prev->prev == NULL) | |
1816 { | |
1817 firstentry = transdata->curfle->prev; | |
1818 lastentry = transdata->curfle->next; | |
1819 transdata->transfer->files = transdata->curfle; | |
1820 transdata->curfle->next = firstentry; | |
1821 transdata->transfer->files->prev = NULL; | |
1822 firstentry->prev = transdata->curfle; | |
1823 firstentry->next = lastentry; | |
1824 if (lastentry != NULL) | |
1825 lastentry->prev = firstentry; | |
1826 } | |
1827 else | |
1828 { | |
1829 firstentry = transdata->curfle->prev->prev; | |
1830 secentry = transdata->curfle->prev; | |
1831 lastentry = transdata->curfle->next; | |
1832 firstentry->next = transdata->curfle; | |
1833 transdata->curfle->prev = firstentry; | |
1834 transdata->curfle->next = secentry; | |
1835 secentry->prev = transdata->curfle; | |
1836 secentry->next = lastentry; | |
1837 if (lastentry != NULL) | |
1838 lastentry->prev = secentry; | |
1839 } | |
1840 | |
1841 gtk_ctree_move (GTK_CTREE (dlwdw), | |
1842 ((gftp_file *) transdata->curfle->data)->node, | |
1843 transdata->transfer->node, | |
1844 transdata->curfle->next != NULL ? | |
1845 ((gftp_file *) transdata->curfle->next->data)->node : | |
1846 NULL); | |
1847 } | |
1848 pthread_mutex_unlock (transdata->transfer->structmutex); | |
1849 } | |
1850 | |
1851 void | |
1852 move_transfer_down (gpointer data) | |
1853 { | |
1854 GList * firstentry, * secentry, * lastentry; | |
1855 gftp_curtrans_data * transdata; | |
1856 GtkCTreeNode * node; | |
1857 | |
1858 if (GTK_CLIST (dlwdw)->selection == NULL) | |
1859 { | |
1860 ftp_log (gftp_logging_misc, NULL, | |
1861 _("There are no file transfers selected\n")); | |
1862 return; | |
1863 } | |
1864 node = GTK_CLIST (dlwdw)->selection->data; | |
1865 transdata = gtk_ctree_node_get_row_data (GTK_CTREE (dlwdw), node); | |
1866 | |
1867 if (transdata->curfle == NULL) | |
1868 return; | |
1869 | |
1870 pthread_mutex_lock (transdata->transfer->structmutex); | |
1871 if (transdata->curfle->next != NULL && (!transdata->transfer->started || | |
1872 (transdata->transfer->curfle != transdata->curfle && | |
1873 transdata->transfer->curfle != transdata->curfle->next))) | |
1874 { | |
1875 if (transdata->curfle->prev == NULL) | |
1876 { | |
1877 firstentry = transdata->curfle->next; | |
1878 lastentry = transdata->curfle->next->next; | |
1879 transdata->transfer->files = firstentry; | |
1880 transdata->transfer->files->prev = NULL; | |
1881 transdata->transfer->files->next = transdata->curfle; | |
1882 transdata->curfle->prev = transdata->transfer->files; | |
1883 transdata->curfle->next = lastentry; | |
1884 if (lastentry != NULL) | |
1885 lastentry->prev = transdata->curfle; | |
1886 } | |
1887 else | |
1888 { | |
1889 firstentry = transdata->curfle->prev; | |
1890 secentry = transdata->curfle->next; | |
1891 lastentry = transdata->curfle->next->next; | |
1892 firstentry->next = secentry; | |
1893 secentry->prev = firstentry; | |
1894 secentry->next = transdata->curfle; | |
1895 transdata->curfle->prev = secentry; | |
1896 transdata->curfle->next = lastentry; | |
1897 if (lastentry != NULL) | |
1898 lastentry->prev = transdata->curfle; | |
1899 } | |
1900 | |
1901 gtk_ctree_move (GTK_CTREE (dlwdw), | |
1902 ((gftp_file *) transdata->curfle->data)->node, | |
1903 transdata->transfer->node, | |
1904 transdata->curfle->next != NULL ? | |
1905 ((gftp_file *) transdata->curfle->next->data)->node : | |
1906 NULL); | |
1907 } | |
1908 pthread_mutex_unlock (transdata->transfer->structmutex); | |
1909 } | |
1910 | |
1911 | |
48 | 1912 static void |
1913 trans_selectall (GtkWidget * widget, gpointer data) | |
1914 { | |
1915 gftp_transfer * tdata; | |
1916 tdata = data; | |
1917 | |
1918 gtk_clist_select_all (GTK_CLIST (tdata->clist)); | |
1919 } | |
1920 | |
1921 | |
1922 static void | |
1923 trans_unselectall (GtkWidget * widget, gpointer data) | |
1924 { | |
1925 gftp_transfer * tdata; | |
1926 tdata = data; | |
1927 | |
1928 gtk_clist_unselect_all (GTK_CLIST (tdata->clist)); | |
1929 } | |
1930 | |
1931 | |
1932 static void | |
1933 overwrite (GtkWidget * widget, gpointer data) | |
1934 { | |
1935 GList * templist, * filelist; | |
1936 gftp_transfer * tdata; | |
1937 gftp_file * tempfle; | |
1938 int curpos; | |
1939 | |
1940 tdata = data; | |
1941 curpos = 0; | |
1942 filelist = tdata->files; | |
1943 templist = GTK_CLIST (tdata->clist)->selection; | |
1944 while (templist != NULL) | |
1945 { | |
1946 templist = get_next_selection (templist, &filelist, &curpos); | |
1947 tempfle = filelist->data; | |
1948 tempfle->transfer_action = GFTP_TRANS_ACTION_OVERWRITE; | |
1949 gtk_clist_set_text (GTK_CLIST (tdata->clist), curpos, 3, _("Overwrite")); | |
1950 } | |
1951 } | |
1952 | |
1953 | |
1954 static void | |
1955 resume (GtkWidget * widget, gpointer data) | |
1956 { | |
1957 GList * templist, * filelist; | |
1958 gftp_transfer * tdata; | |
1959 gftp_file * tempfle; | |
1960 int curpos; | |
1961 | |
1962 tdata = data; | |
1963 curpos = 0; | |
1964 filelist = tdata->files; | |
1965 templist = GTK_CLIST (tdata->clist)->selection; | |
1966 while (templist != NULL) | |
1967 { | |
1968 templist = get_next_selection (templist, &filelist, &curpos); | |
1969 tempfle = filelist->data; | |
1970 tempfle->transfer_action = GFTP_TRANS_ACTION_RESUME; | |
1971 gtk_clist_set_text (GTK_CLIST (tdata->clist), curpos, 3, _("Resume")); | |
1972 } | |
1973 } | |
1974 | |
1975 | |
1976 static void | |
1977 skip (GtkWidget * widget, gpointer data) | |
1978 { | |
1979 GList * templist, * filelist; | |
1980 gftp_transfer * tdata; | |
1981 gftp_file * tempfle; | |
1982 int curpos; | |
1983 | |
1984 tdata = data; | |
1985 curpos = 0; | |
1986 filelist = tdata->files; | |
1987 templist = GTK_CLIST (tdata->clist)->selection; | |
1988 while (templist != NULL) | |
1989 { | |
1990 templist = get_next_selection (templist, &filelist, &curpos); | |
1991 tempfle = filelist->data; | |
1992 tempfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
1993 gtk_clist_set_text (GTK_CLIST (tdata->clist), curpos, 3, _("Skip")); | |
1994 } | |
1995 } | |
1996 | |
1997 | |
1998 static void | |
1999 ok (GtkWidget * widget, gpointer data) | |
2000 { | |
2001 gftp_transfer * tdata; | |
2002 gftp_file * tempfle; | |
2003 GList * templist; | |
2004 | |
2005 tdata = data; | |
2006 pthread_mutex_lock ((pthread_mutex_t *) tdata->structmutex); | |
2007 for (templist = tdata->files; templist != NULL; templist = templist->next) | |
2008 { | |
2009 tempfle = templist->data; | |
2010 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) | |
2011 break; | |
2012 } | |
2013 | |
2014 if (templist == NULL) | |
2015 { | |
2016 tdata->show = 0; | |
2017 tdata->ready = tdata->done = 1; | |
2018 } | |
2019 else | |
2020 tdata->show = tdata->ready = 1; | |
2021 pthread_mutex_unlock ((pthread_mutex_t *) tdata->structmutex); | |
2022 } | |
2023 | |
2024 | |
2025 static void | |
2026 cancel (GtkWidget * widget, gpointer data) | |
2027 { | |
2028 gftp_transfer * tdata; | |
2029 | |
2030 tdata = data; | |
2031 pthread_mutex_lock ((pthread_mutex_t *) tdata->structmutex); | |
2032 tdata->show = 0; | |
2033 tdata->done = tdata->ready = 1; | |
2034 pthread_mutex_unlock ((pthread_mutex_t *) tdata->structmutex); | |
2035 } | |
2036 | |
2037 | |
49 | 2038 #if GTK_MAJOR_VERSION > 1 |
2039 static void | |
2040 transfer_action (GtkWidget * widget, gint response, gpointer user_data) | |
2041 { | |
2042 switch (response) | |
2043 { | |
2044 case GTK_RESPONSE_OK: | |
2045 ok (widget, user_data); | |
2046 gtk_widget_destroy (widget); | |
2047 break; | |
2048 case GTK_RESPONSE_CANCEL: | |
2049 cancel (widget, user_data); | |
2050 /* no break */ | |
2051 default: | |
2052 gtk_widget_destroy (widget); | |
2053 } | |
2054 } | |
2055 #endif | |
2056 | |
2057 | |
1 | 2058 void |
2059 gftp_gtk_ask_transfer (gftp_transfer * tdata) | |
2060 { | |
2061 char *dltitles[4], *add_data[4] = { NULL, NULL, NULL, NULL }, | |
49 | 2062 tempstr[50], temp1str[50], *pos, *title; |
1 | 2063 GtkWidget * tempwid, * scroll, * hbox; |
2064 gftp_file * tempfle; | |
2065 GList * templist; | |
2066 size_t len; | |
2067 int i; | |
2068 | |
2069 dltitles[0] = _("Filename"); | |
2070 dltitles[1] = _("Local Size"); | |
2071 dltitles[2] = _("Remote Size"); | |
2072 dltitles[3] = _("Action"); | |
49 | 2073 title = tdata->transfer_direction == GFTP_DIRECTION_DOWNLOAD ? |
2074 _("Download Files") : _("Upload Files"); | |
2075 | |
2076 #if GTK_MAJOR_VERSION == 1 | |
2077 dialog = gtk_dialog_new (); | |
1 | 2078 gtk_grab_add (dialog); |
49 | 2079 gtk_window_set_title (GTK_WINDOW (dialog), title); |
2080 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), 5); | |
1 | 2081 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 35); |
2082 gtk_box_set_homogeneous (GTK_BOX (GTK_DIALOG (dialog)->action_area), TRUE); | |
49 | 2083 |
1 | 2084 gtk_signal_connect_object (GTK_OBJECT (dialog), "delete_event", |
2085 GTK_SIGNAL_FUNC (gtk_widget_destroy), | |
2086 GTK_OBJECT (dialog)); | |
49 | 2087 #else |
2088 dialog = gtk_dialog_new_with_buttons (title, NULL, 0, | |
2089 GTK_STOCK_OK, | |
2090 GTK_RESPONSE_OK, | |
2091 GTK_STOCK_CANCEL, | |
2092 GTK_RESPONSE_CANCEL, | |
2093 NULL); | |
2094 #endif | |
2095 gtk_window_set_wmclass (GTK_WINDOW(dialog), "transfer", "gFTP"); | |
2096 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE); | |
2097 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), 10); | |
2098 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 5); | |
1 | 2099 |
2100 tempwid = gtk_label_new (_("The following file(s) exist on both the local and remote computer\nPlease select what you would like to do")); | |
2101 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), tempwid, FALSE, | |
2102 FALSE, 0); | |
2103 gtk_widget_show (tempwid); | |
2104 | |
2105 scroll = gtk_scrolled_window_new (NULL, NULL); | |
2106 gtk_widget_set_size_request (scroll, 450, 200); | |
2107 | |
2108 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), | |
2109 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
2110 tdata->clist = gtk_clist_new_with_titles (4, dltitles); | |
2111 gtk_container_add (GTK_CONTAINER (scroll), tdata->clist); | |
2112 | |
45 | 2113 #if GTK_MAJOR_VERSION == 1 |
1 | 2114 gtk_clist_set_selection_mode (GTK_CLIST (tdata->clist), |
2115 GTK_SELECTION_EXTENDED); | |
2116 #else | |
2117 gtk_clist_set_selection_mode (GTK_CLIST (tdata->clist), | |
2118 GTK_SELECTION_MULTIPLE); | |
2119 #endif | |
2120 gtk_clist_set_column_width (GTK_CLIST (tdata->clist), 0, 100); | |
2121 gtk_clist_set_column_justification (GTK_CLIST (tdata->clist), 1, | |
2122 GTK_JUSTIFY_RIGHT); | |
2123 gtk_clist_set_column_width (GTK_CLIST (tdata->clist), 1, 85); | |
2124 gtk_clist_set_column_justification (GTK_CLIST (tdata->clist), 2, | |
2125 GTK_JUSTIFY_RIGHT); | |
2126 gtk_clist_set_column_width (GTK_CLIST (tdata->clist), 2, 85); | |
2127 gtk_clist_set_column_width (GTK_CLIST (tdata->clist), 3, 85); | |
2128 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), scroll, TRUE, TRUE, | |
2129 0); | |
2130 gtk_widget_show (tdata->clist); | |
2131 gtk_widget_show (scroll); | |
2132 | |
2133 for (templist = tdata->files; templist != NULL; | |
2134 templist = templist->next) | |
2135 { | |
2136 tempfle = templist->data; | |
2137 if (tempfle->startsize == 0 || tempfle->isdir) | |
2138 { | |
2139 tempfle->shown = 0; | |
2140 continue; | |
2141 } | |
2142 tempfle->shown = 1; | |
2143 | |
2144 pos = tempfle->destfile; | |
2145 len = strlen (GFTP_GET_DIRECTORY (tdata->toreq)); | |
2146 if (strncmp (pos, GFTP_GET_DIRECTORY (tdata->toreq), len) == 0) | |
2147 pos = tempfle->destfile + len + 1; | |
2148 add_data[0] = pos; | |
2149 | |
2150 if (overwrite_by_default) | |
2151 add_data[3] = _("Overwrite"); | |
2152 else | |
2153 { | |
2154 if (tempfle->startsize >= tempfle->size) | |
2155 { | |
2156 add_data[3] = _("Skip"); | |
2157 tempfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
2158 } | |
2159 else | |
2160 { | |
2161 add_data[3] = _("Resume"); | |
2162 tempfle->transfer_action = GFTP_TRANS_ACTION_RESUME; | |
2163 } | |
2164 } | |
2165 | |
2166 if (tdata->transfer_direction == GFTP_DIRECTION_DOWNLOAD) | |
2167 { | |
2168 add_data[2] = insert_commas (tempfle->size, tempstr, | |
2169 sizeof (tempstr)); | |
2170 add_data[1] = insert_commas (tempfle->startsize, temp1str, | |
2171 sizeof (temp1str)); | |
2172 } | |
2173 else | |
2174 { | |
2175 add_data[1] = insert_commas (tempfle->size, tempstr, | |
2176 sizeof (tempstr)); | |
2177 add_data[2] = insert_commas (tempfle->startsize, temp1str, | |
2178 sizeof (temp1str)); | |
2179 } | |
2180 i = gtk_clist_append (GTK_CLIST (tdata->clist), add_data); | |
2181 gtk_clist_set_row_data (GTK_CLIST (tdata->clist), i, tempfle); | |
2182 } | |
2183 | |
2184 gtk_clist_select_all (GTK_CLIST (tdata->clist)); | |
2185 | |
2186 hbox = gtk_hbox_new (TRUE, 20); | |
2187 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, TRUE, TRUE, 0); | |
2188 gtk_widget_show (hbox); | |
2189 | |
2190 tempwid = gtk_button_new_with_label (_("Overwrite")); | |
2191 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
2192 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
2193 GTK_SIGNAL_FUNC (overwrite), (gpointer) tdata); | |
2194 gtk_widget_show (tempwid); | |
2195 | |
2196 tempwid = gtk_button_new_with_label (_("Resume")); | |
2197 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
2198 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
2199 GTK_SIGNAL_FUNC (resume), (gpointer) tdata); | |
2200 gtk_widget_show (tempwid); | |
2201 | |
2202 tempwid = gtk_button_new_with_label (_("Skip File")); | |
2203 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
2204 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", GTK_SIGNAL_FUNC (skip), | |
2205 (gpointer) tdata); | |
2206 gtk_widget_show (tempwid); | |
2207 | |
2208 hbox = gtk_hbox_new (TRUE, 20); | |
2209 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, TRUE, TRUE, 0); | |
2210 gtk_widget_show (hbox); | |
2211 | |
2212 tempwid = gtk_button_new_with_label (_("Select All")); | |
2213 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
2214 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
2215 GTK_SIGNAL_FUNC (trans_selectall), (gpointer) tdata); | |
2216 gtk_widget_show (tempwid); | |
2217 | |
2218 tempwid = gtk_button_new_with_label (_("Deselect All")); | |
2219 gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); | |
2220 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
2221 GTK_SIGNAL_FUNC (trans_unselectall), (gpointer) tdata); | |
2222 gtk_widget_show (tempwid); | |
2223 | |
49 | 2224 #if GTK_MAJOR_VERSION == 1 |
1 | 2225 tempwid = gtk_button_new_with_label (_("OK")); |
2226 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); | |
2227 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid, | |
2228 TRUE, TRUE, 0); | |
2229 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", GTK_SIGNAL_FUNC (ok), | |
2230 (gpointer) tdata); | |
2231 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked", | |
2232 GTK_SIGNAL_FUNC (gtk_widget_destroy), | |
2233 GTK_OBJECT (dialog)); | |
2234 gtk_widget_grab_default (tempwid); | |
2235 gtk_widget_show (tempwid); | |
2236 | |
2237 tempwid = gtk_button_new_with_label (_(" Cancel ")); | |
2238 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); | |
2239 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid, | |
2240 TRUE, TRUE, 0); | |
2241 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
2242 GTK_SIGNAL_FUNC (cancel), (gpointer) tdata); | |
2243 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked", | |
2244 GTK_SIGNAL_FUNC (gtk_widget_destroy), | |
2245 GTK_OBJECT (dialog)); | |
2246 gtk_widget_show (tempwid); | |
49 | 2247 #else |
2248 g_signal_connect (GTK_OBJECT (dialog), "response", | |
2249 G_CALLBACK (transfer_action), (gpointer) tdata); | |
2250 #endif | |
1 | 2251 |
2252 gtk_widget_show (dialog); | |
2253 dialog = NULL; | |
2254 } | |
2255 |