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