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