Mercurial > gftp.yaz
annotate src/gtk/menu-items.c @ 337:5f9d5aee0c1c
2003-12-10 Brian Masney <masneyb@gftp.org>
* src/gtk/gftp-gtk.c src/gtk/menu-items.c src/gtk/misc-gtk.c - check
for a timeout from the remote server when refreshing the directory
listing and changing directores. If it did, reconnect to the server.
author | masneyb |
---|---|
date | Sat, 13 Dec 2003 20:36:39 +0000 |
parents | cdabbe5c9a95 |
children | eedc2c5727fa |
rev | line source |
---|---|
1 | 1 /*****************************************************************************/ |
2 /* menu-items.c - menu callbacks */ | |
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 void | |
24 change_setting (gftp_window_data * wdata, int menuitem, GtkWidget * checkmenu) | |
25 { | |
26 switch (menuitem) | |
27 { | |
28 case 1: | |
254 | 29 gftp_set_global_option ("ascii_transfers", GINT_TO_POINTER(1)); |
1 | 30 break; |
31 case 2: | |
254 | 32 gftp_set_global_option ("ascii_transfers", GINT_TO_POINTER(0)); |
1 | 33 break; |
34 case 3: | |
35 current_wdata = &window1; | |
36 other_wdata = &window2; | |
37 if (wdata->request) | |
38 update_window_info (); | |
39 break; | |
40 case 4: | |
41 current_wdata = &window2; | |
42 other_wdata = &window1; | |
43 if (wdata->request) | |
44 update_window_info (); | |
45 break; | |
46 } | |
47 } | |
48 | |
49 | |
50 void | |
51 tb_openurl_dialog (gpointer data) | |
52 { | |
53 const char *edttxt; | |
54 | |
55 if (current_wdata->request->stopable) | |
56 { | |
57 ftp_log (gftp_logging_misc, NULL, | |
58 _("%s: Please hit the stop button first to do anything else\n"), | |
59 _("OpenURL")); | |
60 return; | |
61 } | |
62 | |
63 edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (hostedit)->entry)); | |
64 if (*edttxt == '\0') | |
65 { | |
66 ftp_log (gftp_logging_misc, NULL, | |
67 _("OpenURL: Operation canceled...you must enter a string\n")); | |
68 return; | |
69 } | |
70 | |
71 if (GFTP_IS_CONNECTED (current_wdata->request)) | |
72 disconnect (current_wdata); | |
73 else if (edttxt != NULL && *edttxt != '\0') | |
74 toolbar_hostedit (NULL, NULL); | |
75 else | |
76 openurl_dialog (current_wdata); | |
77 } | |
78 | |
79 | |
19 | 80 static void |
81 do_openurl (gftp_window_data * wdata, gftp_dialog_data * ddata) | |
1 | 82 { |
83 const char *tempstr; | |
84 | |
85 if (current_wdata->request->stopable) | |
86 { | |
87 ftp_log (gftp_logging_misc, NULL, | |
88 _("%s: Please hit the stop button first to do anything else\n"), | |
89 _("OpenURL")); | |
90 return; | |
91 } | |
92 | |
19 | 93 tempstr = gtk_entry_get_text (GTK_ENTRY (ddata->edit)); |
1 | 94 if (*tempstr == '\0') |
95 { | |
96 ftp_log (gftp_logging_misc, NULL, | |
97 _("OpenURL: Operation canceled...you must enter a string\n")); | |
98 return; | |
99 } | |
100 | |
101 if (GFTP_IS_CONNECTED (wdata->request)) | |
102 disconnect (wdata); | |
103 | |
104 if (gftp_parse_url (wdata->request, tempstr) == 0) | |
105 { | |
19 | 106 gtk_widget_destroy (ddata->dialog); |
1 | 107 ftp_connect (wdata, wdata->request, 1); |
108 } | |
109 else | |
173 | 110 gtk_widget_destroy (ddata->dialog); |
111 | |
19 | 112 ddata->dialog = NULL; |
113 } | |
114 | |
115 | |
116 void | |
117 openurl_dialog (gpointer data) | |
118 { | |
119 MakeEditDialog (_("Connect via URL"), _("Enter ftp url to connect to"), | |
120 NULL, 1, NULL, gftp_dialog_button_connect, do_openurl, data, | |
121 NULL, NULL); | |
1 | 122 } |
123 | |
124 | |
125 void | |
126 disconnect (gpointer data) | |
127 { | |
128 gftp_window_data * wdata; | |
129 | |
130 wdata = data; | |
182 | 131 gftp_delete_cache_entry (wdata->request, NULL, 1); |
1 | 132 gftp_disconnect (wdata->request); |
133 remove_files_window (wdata); | |
134 update_window (wdata); | |
135 } | |
136 | |
137 | |
138 static void | |
19 | 139 dochange_filespec (gftp_window_data * wdata, gftp_dialog_data * ddata) |
1 | 140 { |
141 GList * templist, * filelist; | |
142 gftp_file * tempfle; | |
143 const char *edttext; | |
144 int num; | |
145 | |
146 wdata->show_selected = 0; | |
147 | |
19 | 148 edttext = gtk_entry_get_text (GTK_ENTRY (ddata->edit)); |
1 | 149 if (*edttext == '\0') |
150 { | |
151 ftp_log (gftp_logging_misc, NULL, | |
152 _("Change Filespec: Operation canceled...you must enter a string\n")); | |
153 return; | |
154 } | |
155 if (wdata->filespec) | |
156 g_free (wdata->filespec); | |
129 | 157 wdata->filespec = g_strdup (edttext); |
1 | 158 |
159 filelist = wdata->files; | |
160 templist = GTK_CLIST (wdata->listbox)->selection; | |
161 num = 0; | |
162 while (templist != NULL) | |
163 { | |
164 templist = get_next_selection (templist, &filelist, &num); | |
165 tempfle = filelist->data; | |
166 tempfle->was_sel = 1; | |
167 } | |
168 | |
169 gtk_clist_freeze (GTK_CLIST (wdata->listbox)); | |
170 gtk_clist_clear (GTK_CLIST (wdata->listbox)); | |
171 templist = wdata->files; | |
172 while (templist != NULL) | |
173 { | |
174 tempfle = templist->data; | |
175 add_file_listbox (wdata, tempfle); | |
176 templist = templist->next; | |
177 } | |
178 gtk_clist_thaw (GTK_CLIST (wdata->listbox)); | |
179 update_window (wdata); | |
180 } | |
181 | |
182 | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
183 void |
19 | 184 change_filespec (gpointer data) |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
185 { |
19 | 186 gftp_window_data * wdata; |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
187 |
19 | 188 wdata = data; |
189 if (!check_status (_("Change Filespec"), wdata, 0, 0, 0, 1)) | |
190 return; | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
191 |
19 | 192 MakeEditDialog (_("Change Filespec"), _("Enter the new file specification"), |
193 wdata->filespec, 1, NULL, gftp_dialog_button_change, | |
194 dochange_filespec, wdata, NULL, NULL); | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
195 } |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
196 |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
197 |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
198 static void |
21 | 199 destroy_save_directory_listing (GtkWidget * widget, gftp_save_dir_struct * str) |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
200 { |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
201 gtk_widget_destroy (str->filew); |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
202 g_free (str); |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
203 } |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
204 |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
205 |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
206 static void |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
207 dosave_directory_listing (GtkWidget * widget, gftp_save_dir_struct * str) |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
208 { |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
209 const char *filename; |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
210 gftp_file * tempfle; |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
211 GList * templist; |
131 | 212 char *tempstr; |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
213 FILE * fd; |
131 | 214 |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
215 |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
216 filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (str->filew)); |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
217 if ((fd = fopen (filename, "w")) == NULL) |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
218 { |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
219 ftp_log (gftp_logging_misc, NULL, |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
220 _("Error: Cannot open %s for writing: %s\n"), filename, |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
221 g_strerror (errno)); |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
222 return; |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
223 } |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
224 |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
225 for (templist = str->wdata->files; |
276 | 226 templist != NULL; |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
227 templist = templist->next) |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
228 { |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
229 tempfle = templist->data; |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
230 |
295 | 231 if (!tempfle->shown) |
232 continue; | |
233 | |
131 | 234 tempstr = gftp_gen_ls_string (tempfle, NULL, NULL); |
235 fprintf (fd, "%s\n", tempstr); | |
236 g_free (tempstr); | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
237 } |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
238 |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
239 fclose (fd); |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
240 } |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
241 |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
242 |
19 | 243 void |
244 save_directory_listing (gpointer data) | |
245 { | |
246 gftp_save_dir_struct * str; | |
247 GtkWidget *filew; | |
248 | |
249 filew = gtk_file_selection_new (_("Save Directory Listing")); | |
250 | |
251 str = g_malloc (sizeof (*str)); | |
252 str->filew = filew; | |
253 str->wdata = data; | |
254 | |
255 gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button), | |
256 "clicked", GTK_SIGNAL_FUNC (dosave_directory_listing), | |
257 str); | |
21 | 258 gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button), |
259 "clicked", | |
260 GTK_SIGNAL_FUNC (destroy_save_directory_listing), str); | |
261 gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->cancel_button), | |
262 "clicked", | |
263 GTK_SIGNAL_FUNC (destroy_save_directory_listing), str); | |
19 | 264 |
265 gtk_window_set_wmclass (GTK_WINDOW(filew), "Save Directory Listing", "gFTP"); | |
266 gtk_widget_show (filew); | |
267 } | |
268 | |
269 | |
1 | 270 void |
271 show_selected (gpointer data) | |
272 { | |
273 GList * templist, * filelist; | |
274 gftp_window_data * wdata; | |
275 gftp_file * tempfle; | |
276 int num; | |
277 | |
278 wdata = data; | |
279 wdata->show_selected = 1; | |
280 | |
281 filelist = wdata->files; | |
282 templist = GTK_CLIST (wdata->listbox)->selection; | |
283 num = 0; | |
284 while (templist != NULL) | |
285 { | |
286 templist = get_next_selection (templist, &filelist, &num); | |
287 tempfle = filelist->data; | |
288 tempfle->was_sel = 1; | |
289 } | |
290 | |
291 gtk_clist_freeze (GTK_CLIST (wdata->listbox)); | |
292 gtk_clist_clear (GTK_CLIST (wdata->listbox)); | |
293 templist = wdata->files; | |
294 while (templist != NULL) | |
295 { | |
296 tempfle = templist->data; | |
297 add_file_listbox (wdata, tempfle); | |
298 templist = templist->next; | |
299 } | |
300 gtk_clist_thaw (GTK_CLIST (wdata->listbox)); | |
301 update_window (wdata); | |
302 } | |
303 | |
304 | |
305 void | |
306 selectall (gpointer data) | |
307 { | |
308 gftp_window_data * wdata; | |
309 | |
310 wdata = data; | |
311 wdata->show_selected = 0; | |
312 gtk_clist_select_all (GTK_CLIST (wdata->listbox)); | |
313 } | |
314 | |
315 | |
316 void | |
317 selectallfiles (gpointer data) | |
318 { | |
319 gftp_window_data * wdata; | |
320 gftp_file * tempfle; | |
321 GList *templist; | |
322 int i; | |
323 | |
324 wdata = data; | |
325 wdata->show_selected = 0; | |
326 gtk_clist_freeze (GTK_CLIST (wdata->listbox)); | |
327 i = 0; | |
39 | 328 templist = wdata->files; |
1 | 329 while (templist != NULL) |
330 { | |
331 tempfle = (gftp_file *) templist->data; | |
332 if (tempfle->shown) | |
333 { | |
334 if (tempfle->isdir) | |
335 gtk_clist_unselect_row (GTK_CLIST (wdata->listbox), i, 0); | |
336 else | |
337 gtk_clist_select_row (GTK_CLIST (wdata->listbox), i, 0); | |
338 i++; | |
339 } | |
340 templist = templist->next; | |
341 } | |
342 gtk_clist_thaw (GTK_CLIST (wdata->listbox)); | |
343 } | |
344 | |
345 | |
346 void | |
347 deselectall (gpointer data) | |
348 { | |
349 gftp_window_data * wdata; | |
350 | |
351 wdata = data; | |
352 wdata->show_selected = 0; | |
353 gtk_clist_unselect_all (GTK_CLIST (wdata->listbox)); | |
354 } | |
355 | |
356 | |
19 | 357 static void |
358 dosite (gftp_window_data * wdata, gftp_dialog_data * ddata) | |
1 | 359 { |
360 const char *edttext; | |
361 | |
19 | 362 edttext = gtk_entry_get_text (GTK_ENTRY (ddata->edit)); |
1 | 363 if (*edttext == '\0') |
364 { | |
365 ftp_log (gftp_logging_misc, NULL, | |
366 _("SITE: Operation canceled...you must enter a string\n")); | |
367 return; | |
368 } | |
369 | |
370 if (check_reconnect (wdata) < 0) | |
371 return; | |
372 gftp_site_cmd (wdata->request, edttext); | |
373 | |
374 if (!GFTP_IS_CONNECTED (wdata->request)) | |
375 disconnect (wdata); | |
376 } | |
377 | |
378 | |
19 | 379 void |
380 site_dialog (gpointer data) | |
381 { | |
382 gftp_window_data * wdata; | |
383 | |
384 wdata = data; | |
385 if (!check_status (_("Site"), wdata, 0, 0, 0, wdata->request->site != NULL)) | |
386 return; | |
387 | |
388 MakeEditDialog (_("Site"), _("Enter site-specific command"), NULL, 1, | |
389 NULL, gftp_dialog_button_ok, dosite, wdata, NULL, NULL); | |
390 } | |
391 | |
392 | |
48 | 393 static void * |
394 do_change_dir_thread (void * data) | |
395 { | |
326 | 396 int success, sj; |
397 intptr_t network_timeout; | |
48 | 398 gftp_window_data * wdata; |
399 | |
400 wdata = data; | |
401 | |
402 if (wdata->request->use_threads) | |
403 { | |
404 sj = sigsetjmp (jmp_environment, 1); | |
405 use_jmp_environment = 1; | |
406 } | |
407 else | |
408 sj = 0; | |
409 | |
129 | 410 gftp_lookup_request_option (wdata->request, "network_timeout", |
411 &network_timeout); | |
412 | |
48 | 413 success = 0; |
414 if (sj == 0) | |
415 { | |
129 | 416 if (network_timeout > 0) |
417 alarm (network_timeout); | |
48 | 418 success = gftp_set_directory (wdata->request, wdata->request->directory); |
419 alarm (0); | |
420 } | |
421 else | |
422 { | |
423 gftp_disconnect (wdata->request); | |
424 wdata->request->logging_function (gftp_logging_error, | |
186 | 425 wdata->request, |
48 | 426 _("Operation canceled\n")); |
427 } | |
428 | |
429 if (wdata->request->use_threads) | |
430 use_jmp_environment = 0; | |
431 | |
432 wdata->request->stopable = 0; | |
195 | 433 return (GINT_TO_POINTER (success)); |
48 | 434 } |
435 | |
436 | |
437 static int | |
438 do_change_dir (gftp_window_data * wdata, char *directory) | |
439 { | |
440 char *olddir; | |
441 int ret; | |
442 | |
443 if (directory != wdata->request->directory) | |
444 { | |
445 olddir = wdata->request->directory; | |
129 | 446 wdata->request->directory = g_strdup (directory); |
48 | 447 } |
448 else | |
449 olddir = NULL; | |
450 | |
195 | 451 ret = GPOINTER_TO_INT (generic_thread (do_change_dir_thread, wdata)); |
48 | 452 |
453 if (!GFTP_IS_CONNECTED (wdata->request)) | |
454 { | |
455 disconnect (wdata); | |
456 if (olddir != NULL) | |
457 g_free (olddir); | |
458 return (-2); | |
459 } | |
460 | |
461 if (ret != 0) | |
462 { | |
463 g_free (wdata->request->directory); | |
464 wdata->request->directory = olddir; | |
465 } | |
466 else | |
467 g_free (olddir); | |
468 | |
469 return (ret); | |
470 } | |
471 | |
472 | |
1 | 473 int |
474 chdir_edit (GtkWidget * widget, gpointer data) | |
475 { | |
476 gftp_window_data * wdata; | |
477 const char *edttxt; | |
478 char *tempstr; | |
479 | |
480 wdata = data; | |
481 edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (wdata->combo)->entry)); | |
337 | 482 |
483 if (check_reconnect (wdata) < 0) | |
484 return (0); | |
485 | |
1 | 486 if (!GFTP_IS_CONNECTED (wdata->request) && *edttxt != '\0') |
487 { | |
488 toolbar_hostedit (NULL, NULL); | |
489 return (0); | |
490 } | |
491 | |
492 if (!check_status (_("Chdir"), wdata, wdata->request->use_threads, 0, 0, | |
493 wdata->request->chdir != NULL)) | |
494 return (FALSE); | |
495 | |
496 if ((tempstr = expand_path (edttxt)) == NULL) | |
497 return (FALSE); | |
498 | |
499 if (check_reconnect (wdata) < 0) | |
500 return (FALSE); | |
501 | |
502 if (do_change_dir (wdata, tempstr) == 0) | |
503 { | |
504 gtk_clist_freeze (GTK_CLIST (wdata->listbox)); | |
505 remove_files_window (wdata); | |
506 ftp_list_files (wdata, 1); | |
507 gtk_clist_thaw (GTK_CLIST (wdata->listbox)); | |
508 add_history (wdata->combo, wdata->history, wdata->histlen, tempstr); | |
509 } | |
510 | |
511 g_free (tempstr); | |
512 return (FALSE); | |
513 } | |
514 | |
515 | |
516 int | |
517 chdir_dialog (gpointer data) | |
518 { | |
519 GList * templist, * filelist; | |
520 gftp_window_data * wdata; | |
521 char *newdir, *tempstr; | |
522 gftp_file *tempfle; | |
523 int num, ret; | |
524 | |
525 wdata = data; | |
526 if (!check_status (_("Chdir"), wdata, wdata->request->use_threads, 1, 0, | |
527 wdata->request->chdir != NULL)) | |
528 return (0); | |
529 | |
39 | 530 filelist = wdata->files; |
1 | 531 templist = GTK_CLIST (wdata->listbox)->selection; |
532 num = 0; | |
533 templist = get_next_selection (templist, &filelist, &num); | |
534 tempfle = filelist->data; | |
535 | |
245 | 536 newdir = gftp_build_path (wdata->request->directory, tempfle->file, NULL); |
211 | 537 |
1 | 538 if ((tempstr = expand_path (newdir)) == NULL) |
211 | 539 { |
540 g_free (newdir); | |
541 return (0); | |
542 } | |
543 | |
1 | 544 g_free (newdir); |
545 | |
546 if (check_reconnect (wdata) < 0) | |
547 return (0); | |
548 | |
549 ret = 0; | |
550 if (do_change_dir (wdata, tempstr) == 0) | |
551 { | |
552 gtk_clist_freeze (GTK_CLIST (wdata->listbox)); | |
553 remove_files_window (wdata); | |
554 ftp_list_files (wdata, 1); | |
555 gtk_clist_thaw (GTK_CLIST (wdata->listbox)); | |
556 ret = 1; | |
557 } | |
558 g_free (tempstr); | |
559 return (ret); | |
560 } | |
561 | |
562 | |
563 void | |
564 clearlog (gpointer data) | |
565 { | |
566 guint len; | |
45 | 567 #if GTK_MAJOR_VERSION == 1 |
1 | 568 len = gtk_text_get_length (GTK_TEXT (logwdw)); |
569 gtk_text_set_point (GTK_TEXT (logwdw), len); | |
570 gtk_text_backward_delete (GTK_TEXT (logwdw), len); | |
571 #else | |
572 GtkTextBuffer * textbuf; | |
573 GtkTextIter iter, iter2; | |
574 | |
575 textbuf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (logwdw)); | |
576 len = gtk_text_buffer_get_char_count (textbuf); | |
577 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, 0); | |
578 gtk_text_buffer_get_iter_at_offset (textbuf, &iter2, len - 1); | |
579 gtk_text_buffer_delete (textbuf, &iter, &iter2); | |
580 #endif | |
581 } | |
582 | |
583 | |
584 void | |
585 viewlog (gpointer data) | |
586 { | |
587 char *tempstr, *txt, *pos; | |
588 guint textlen; | |
589 ssize_t len; | |
590 int fd; | |
45 | 591 #if GTK_MAJOR_VERSION > 1 |
1 | 592 GtkTextBuffer * textbuf; |
593 GtkTextIter iter, iter2; | |
594 #endif | |
595 | |
41 | 596 tempstr = g_strconcat (g_get_tmp_dir (), "/gftp-view.XXXXXXXXXX", NULL); |
1 | 597 if ((fd = mkstemp (tempstr)) < 0) |
598 { | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
599 ftp_log (gftp_logging_misc, NULL, |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
600 _("Error: Cannot open %s for writing: %s\n"), tempstr, |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
601 g_strerror (errno)); |
1 | 602 g_free (tempstr); |
603 return; | |
604 } | |
605 chmod (tempstr, S_IRUSR | S_IWUSR); | |
606 unlink (tempstr); | |
607 | |
45 | 608 #if GTK_MAJOR_VERSION == 1 |
1 | 609 textlen = gtk_text_get_length (GTK_TEXT (logwdw)); |
610 txt = gtk_editable_get_chars (GTK_EDITABLE (logwdw), 0, -1); | |
611 #else | |
612 textbuf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (logwdw)); | |
613 textlen = gtk_text_buffer_get_char_count (textbuf); | |
614 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, 0); | |
615 gtk_text_buffer_get_iter_at_offset (textbuf, &iter2, textlen - 1); | |
616 txt = gtk_text_buffer_get_text (textbuf, &iter, &iter2, 0); | |
617 #endif | |
618 pos = txt; | |
619 do | |
620 { | |
621 if ((len = write (fd, pos, textlen)) == -1) | |
622 { | |
186 | 623 ftp_log (gftp_logging_misc, NULL, |
624 _("Error: Error writing to %s: %s\n"), | |
625 tempstr, g_strerror (errno)); | |
1 | 626 break; |
627 } | |
628 textlen -= len; | |
629 pos += len; | |
630 } while (textlen > 0); | |
631 | |
632 lseek (fd, 0, SEEK_SET); | |
633 view_file (tempstr, fd, 1, 0, 0, 1, NULL, NULL); | |
634 close (fd); | |
635 g_free (tempstr); | |
636 g_free (txt); | |
637 } | |
638 | |
639 | |
640 static void | |
641 dosavelog (GtkWidget * widget, GtkFileSelection * fs) | |
642 { | |
643 const char *filename; | |
644 char *txt, *pos; | |
645 guint textlen; | |
646 ssize_t len; | |
647 FILE *fd; | |
648 int ok; | |
45 | 649 #if GTK_MAJOR_VERSION > 1 |
1 | 650 GtkTextBuffer * textbuf; |
651 GtkTextIter iter, iter2; | |
652 #endif | |
653 | |
654 filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs)); | |
655 if ((fd = fopen (filename, "w")) == NULL) | |
656 { | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
657 ftp_log (gftp_logging_misc, NULL, |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
658 _("Error: Cannot open %s for writing: %s\n"), filename, |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
659 g_strerror (errno)); |
1 | 660 return; |
661 } | |
662 | |
45 | 663 #if GTK_MAJOR_VERSION == 1 |
1 | 664 textlen = gtk_text_get_length (GTK_TEXT (logwdw)); |
665 txt = gtk_editable_get_chars (GTK_EDITABLE (logwdw), 0, -1); | |
666 #else | |
667 textbuf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (logwdw)); | |
668 textlen = gtk_text_buffer_get_char_count (textbuf); | |
669 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, 0); | |
670 gtk_text_buffer_get_iter_at_offset (textbuf, &iter2, textlen - 1); | |
671 txt = gtk_text_buffer_get_text (textbuf, &iter, &iter2, 0); | |
672 #endif | |
673 | |
674 ok = 1; | |
675 pos = txt; | |
676 do | |
677 { | |
678 if ((len = write (fileno (fd), pos, textlen)) == -1) | |
679 { | |
680 ok = 0; | |
186 | 681 ftp_log (gftp_logging_misc, NULL, |
682 _("Error: Error writing to %s: %s\n"), | |
683 filename, g_strerror (errno)); | |
1 | 684 break; |
685 } | |
686 | |
687 textlen -= len; | |
688 pos += len; | |
689 } while (textlen > 0); | |
690 | |
691 if (ok) | |
692 ftp_log (gftp_logging_misc, NULL, | |
693 _("Successfully wrote the log file to %s\n"), filename); | |
694 | |
695 fclose (fd); | |
696 g_free (txt); | |
697 } | |
698 | |
699 | |
700 void | |
19 | 701 savelog (gpointer data) |
702 { | |
703 GtkWidget *filew; | |
704 | |
705 filew = gtk_file_selection_new (_("Save Log")); | |
706 | |
707 gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button), | |
708 "clicked", GTK_SIGNAL_FUNC (dosavelog), filew); | |
709 gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button), | |
710 "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy), | |
711 GTK_OBJECT (filew)); | |
712 gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (filew)->cancel_button), "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_OBJECT (filew)); | |
713 | |
714 gtk_file_selection_set_filename (GTK_FILE_SELECTION (filew), "gftp.log"); | |
715 gtk_window_set_wmclass (GTK_WINDOW(filew), "Save Log", "gFTP"); | |
716 gtk_widget_show (filew); | |
717 } | |
718 | |
719 | |
720 void | |
1 | 721 clear_cache (gpointer data) |
722 { | |
723 gftp_clear_cache_files (); | |
724 } | |
725 | |
726 | |
727 void | |
728 about_dialog (gpointer data) | |
729 { | |
730 GtkWidget * tempwid, * notebook, * box, * label, * view, * vscroll, | |
731 * dialog; | |
732 char *tempstr, *no_license_agreement, *str, buf[255]; | |
733 size_t len; | |
734 FILE * fd; | |
45 | 735 #if GTK_MAJOR_VERSION > 1 |
1 | 736 GtkTextBuffer * textbuf; |
737 GtkTextIter iter; | |
738 guint textlen; | |
739 #endif | |
740 | |
741 no_license_agreement = g_strdup_printf (_("Cannot find the license agreement file COPYING. Please make sure it is in either %s or in %s"), BASE_CONF_DIR, SHARE_DIR); | |
742 | |
45 | 743 #if GTK_MAJOR_VERSION == 1 |
1 | 744 dialog = gtk_dialog_new (); |
745 gtk_window_set_title (GTK_WINDOW (dialog), _("About gFTP")); | |
746 gtk_container_border_width (GTK_CONTAINER | |
747 (GTK_DIALOG (dialog)->action_area), 5); | |
748 gtk_box_set_homogeneous (GTK_BOX (GTK_DIALOG (dialog)->action_area), TRUE); | |
19 | 749 #else |
750 dialog = gtk_dialog_new_with_buttons (_("About gFTP"), NULL, 0, | |
751 GTK_STOCK_CLOSE, | |
752 GTK_RESPONSE_CLOSE, | |
753 NULL); | |
754 #endif | |
755 gtk_window_set_wmclass (GTK_WINDOW(dialog), "about", "gFTP"); | |
1 | 756 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE); |
19 | 757 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), 10); |
758 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 5); | |
1 | 759 gtk_widget_realize (dialog); |
760 | |
19 | 761 if (gftp_icon != NULL) |
762 { | |
763 gdk_window_set_icon (dialog->window, NULL, gftp_icon->pixmap, | |
764 gftp_icon->bitmap); | |
168 | 765 gdk_window_set_icon_name (dialog->window, gftp_version); |
19 | 766 } |
767 | |
1 | 768 notebook = gtk_notebook_new (); |
769 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), notebook, TRUE, | |
770 TRUE, 0); | |
771 gtk_widget_show (notebook); | |
772 | |
773 box = gtk_vbox_new (TRUE, 5); | |
774 gtk_container_border_width (GTK_CONTAINER (box), 10); | |
775 gtk_widget_show (box); | |
776 | |
777 tempwid = toolbar_pixmap (dialog, "gftp-logo.xpm"); | |
778 gtk_box_pack_start (GTK_BOX (box), tempwid, FALSE, FALSE, 0); | |
779 gtk_widget_show (tempwid); | |
780 | |
255 | 781 tempstr = g_strdup_printf (_("%s\nCopyright (C) 1998-2003 Brian Masney <masneyb@gftp.org>\nOfficial Homepage: http://www.gftp.org/\nLogo by: Aaron Worley <planet_hoth@yahoo.com>\n"), gftp_version); |
1 | 782 str = _("Translated by"); |
783 if (strcmp (str, "Translated by") != 0) | |
784 { | |
785 tempstr = g_realloc (tempstr, strlen (tempstr) + strlen (str) + 1); | |
786 strcat (tempstr, str); | |
787 } | |
788 tempwid = gtk_label_new (tempstr); | |
789 g_free (tempstr); | |
790 gtk_box_pack_start (GTK_BOX (box), tempwid, FALSE, FALSE, 0); | |
791 gtk_widget_show (tempwid); | |
792 | |
793 label = gtk_label_new (_("About")); | |
794 gtk_widget_show (label); | |
795 | |
796 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), box, label); | |
797 | |
798 box = gtk_vbox_new (FALSE, 5); | |
799 gtk_container_border_width (GTK_CONTAINER (box), 10); | |
800 gtk_widget_show (box); | |
801 | |
802 tempwid = gtk_table_new (1, 2, FALSE); | |
803 gtk_box_pack_start (GTK_BOX (box), tempwid, TRUE, TRUE, 0); | |
804 gtk_widget_show (tempwid); | |
805 | |
45 | 806 #if GTK_MAJOR_VERSION == 1 |
1 | 807 view = gtk_text_new (NULL, NULL); |
808 gtk_text_set_editable (GTK_TEXT (view), FALSE); | |
809 gtk_text_set_word_wrap (GTK_TEXT (view), TRUE); | |
810 | |
811 gtk_table_attach (GTK_TABLE (tempwid), view, 0, 1, 0, 1, | |
812 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
813 0, 0); | |
814 gtk_widget_show (view); | |
815 | |
816 vscroll = gtk_vscrollbar_new (GTK_TEXT (view)->vadj); | |
817 gtk_table_attach (GTK_TABLE (tempwid), vscroll, 1, 2, 0, 1, | |
818 GTK_FILL, GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0); | |
819 gtk_widget_show (vscroll); | |
820 #else | |
821 view = gtk_text_view_new (); | |
822 gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE); | |
823 gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE); | |
824 gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD); | |
825 | |
826 vscroll = gtk_scrolled_window_new (NULL, NULL); | |
827 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (vscroll), | |
828 GTK_POLICY_AUTOMATIC, | |
829 GTK_POLICY_AUTOMATIC); | |
830 | |
831 gtk_container_add (GTK_CONTAINER (vscroll), view); | |
832 gtk_widget_show (view); | |
833 | |
834 gtk_table_attach (GTK_TABLE (tempwid), vscroll, 0, 1, 0, 1, | |
835 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
836 0, 0); | |
837 gtk_widget_show (vscroll); | |
838 | |
839 textbuf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); | |
840 #endif | |
841 | |
842 label = gtk_label_new (_("License Agreement")); | |
843 gtk_widget_show (label); | |
844 | |
845 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), box, label); | |
846 | |
45 | 847 #if GTK_MAJOR_VERSION == 1 |
1 | 848 tempwid = gtk_button_new_with_label (_(" Close ")); |
849 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); | |
850 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid, | |
851 FALSE, FALSE, 0); | |
852 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked", | |
853 GTK_SIGNAL_FUNC (gtk_widget_destroy), | |
854 GTK_OBJECT (dialog)); | |
855 gtk_widget_grab_default (tempwid); | |
856 gtk_widget_show (tempwid); | |
19 | 857 #else |
858 g_signal_connect_swapped (GTK_OBJECT (dialog), "response", | |
859 G_CALLBACK (gtk_widget_destroy), | |
860 GTK_OBJECT (dialog)); | |
861 #endif | |
1 | 862 |
863 tempstr = g_strconcat ("/usr/share/common-licenses/GPL", NULL); | |
864 if (access (tempstr, F_OK) != 0) | |
865 { | |
866 g_free (tempstr); | |
867 tempstr = expand_path (SHARE_DIR "/COPYING"); | |
868 if (access (tempstr, F_OK) != 0) | |
869 { | |
870 g_free (tempstr); | |
871 tempstr = expand_path (BASE_CONF_DIR "/COPYING"); | |
872 if (access (tempstr, F_OK) != 0) | |
873 { | |
45 | 874 #if GTK_MAJOR_VERSION == 1 |
1 | 875 gtk_text_insert (GTK_TEXT (view), NULL, NULL, NULL, |
876 no_license_agreement, -1); | |
877 #else | |
878 textlen = gtk_text_buffer_get_char_count (textbuf); | |
879 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, textlen - 1); | |
880 gtk_text_buffer_insert (textbuf, &iter, no_license_agreement, -1); | |
881 #endif | |
882 gtk_widget_show (dialog); | |
883 return; | |
884 } | |
885 } | |
886 } | |
887 | |
888 if ((fd = fopen (tempstr, "r")) == NULL) | |
889 { | |
45 | 890 #if GTK_MAJOR_VERSION == 1 |
1 | 891 gtk_text_insert (GTK_TEXT (view), NULL, NULL, NULL, |
892 no_license_agreement, -1); | |
893 #else | |
894 textlen = gtk_text_buffer_get_char_count (textbuf); | |
895 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, textlen - 1); | |
896 gtk_text_buffer_insert (textbuf, &iter, no_license_agreement, -1); | |
897 #endif | |
898 gtk_widget_show (dialog); | |
899 g_free (tempstr); | |
900 return; | |
901 } | |
902 g_free (tempstr); | |
903 | |
904 memset (buf, 0, sizeof (buf)); | |
905 while ((len = fread (buf, 1, sizeof (buf) - 1, fd))) | |
906 { | |
907 buf[len] = '\0'; | |
45 | 908 #if GTK_MAJOR_VERSION == 1 |
1 | 909 gtk_text_insert (GTK_TEXT (view), NULL, NULL, NULL, buf, -1); |
910 #else | |
911 textlen = gtk_text_buffer_get_char_count (textbuf); | |
912 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, textlen - 1); | |
913 gtk_text_buffer_insert (textbuf, &iter, buf, -1); | |
914 #endif | |
915 } | |
916 fclose (fd); | |
917 gtk_widget_show (dialog); | |
918 g_free (no_license_agreement); | |
919 gftp_free_pixmap ("gftp-logo.xpm"); | |
920 } | |
921 | |
922 | |
923 void | |
924 compare_windows (gpointer data) | |
925 { | |
926 gftp_file * curfle, * otherfle; | |
927 GList * curlist, * otherlist; | |
928 int row; | |
929 | |
930 if (!check_status (_("Compare Windows"), &window2, 1, 0, 0, 1)) | |
931 return; | |
932 | |
933 deselectall (&window1); | |
934 deselectall (&window2); | |
935 | |
936 row = 0; | |
937 curlist = window1.files; | |
938 while (curlist != NULL) | |
939 { | |
940 curfle = curlist->data; | |
941 if (!curfle->shown) | |
942 { | |
943 curlist = curlist->next; | |
944 continue; | |
945 } | |
946 | |
947 otherlist = window2.files; | |
948 while (otherlist != NULL) | |
949 { | |
950 otherfle = otherlist->data; | |
951 if (!otherfle->shown) | |
952 { | |
953 otherlist = otherlist->next; | |
954 continue; | |
955 } | |
956 | |
957 if (strcmp (otherfle->file, curfle->file) == 0 && | |
958 otherfle->isdir == curfle->isdir && | |
959 (curfle->isdir || otherfle->size == curfle->size)) | |
960 break; | |
961 | |
962 otherlist = otherlist->next; | |
963 } | |
964 | |
965 if (otherlist == NULL) | |
966 gtk_clist_select_row (GTK_CLIST (window1.listbox), row, 0); | |
967 row++; | |
968 curlist = curlist->next; | |
969 } | |
970 | |
971 row = 0; | |
972 curlist = window2.files; | |
973 while (curlist != NULL) | |
974 { | |
975 curfle = curlist->data; | |
976 if (!curfle->shown) | |
977 { | |
978 curlist = curlist->next; | |
979 continue; | |
980 } | |
981 | |
982 otherlist = window1.files; | |
983 while (otherlist != NULL) | |
984 { | |
985 otherfle = otherlist->data; | |
986 if (!otherfle->shown) | |
987 { | |
988 otherlist = otherlist->next; | |
989 continue; | |
990 } | |
991 | |
992 if (strcmp (otherfle->file, curfle->file) == 0 && | |
993 otherfle->isdir == curfle->isdir && | |
994 (curfle->isdir || otherfle->size == curfle->size)) | |
995 break; | |
996 | |
997 otherlist = otherlist->next; | |
998 } | |
999 | |
1000 if (otherlist == NULL) | |
1001 gtk_clist_select_row (GTK_CLIST (window2.listbox), row, 0); | |
1002 row++; | |
1003 curlist = curlist->next; | |
1004 } | |
1005 } |