Mercurial > gftp.yaz
annotate src/gtk/menu-items.c @ 276:70d0c9a2e424
2003-9-21 Brian Masney <masneyb@gftp.org>
* src/gtk/menu-items.c (dosave_directory_listing) - fixed a bug that
would occur when saving directory listings to a file, the last filename
in the list was never written to the file
(from Aurelien Jarno <aurel32@debian.org>)
author | masneyb |
---|---|
date | Mon, 22 Sep 2003 10:40:08 +0000 |
parents | 2ad324cf4930 |
children | ab4c90a561fc |
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 |
131 | 231 tempstr = gftp_gen_ls_string (tempfle, NULL, NULL); |
232 fprintf (fd, "%s\n", tempstr); | |
233 g_free (tempstr); | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
234 } |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
235 |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
236 fclose (fd); |
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 |
19 | 240 void |
241 save_directory_listing (gpointer data) | |
242 { | |
243 gftp_save_dir_struct * str; | |
244 GtkWidget *filew; | |
245 | |
246 filew = gtk_file_selection_new (_("Save Directory Listing")); | |
247 | |
248 str = g_malloc (sizeof (*str)); | |
249 str->filew = filew; | |
250 str->wdata = data; | |
251 | |
252 gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button), | |
253 "clicked", GTK_SIGNAL_FUNC (dosave_directory_listing), | |
254 str); | |
21 | 255 gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button), |
256 "clicked", | |
257 GTK_SIGNAL_FUNC (destroy_save_directory_listing), str); | |
258 gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->cancel_button), | |
259 "clicked", | |
260 GTK_SIGNAL_FUNC (destroy_save_directory_listing), str); | |
19 | 261 |
262 gtk_window_set_wmclass (GTK_WINDOW(filew), "Save Directory Listing", "gFTP"); | |
263 gtk_widget_show (filew); | |
264 } | |
265 | |
266 | |
1 | 267 void |
268 show_selected (gpointer data) | |
269 { | |
270 GList * templist, * filelist; | |
271 gftp_window_data * wdata; | |
272 gftp_file * tempfle; | |
273 int num; | |
274 | |
275 wdata = data; | |
276 wdata->show_selected = 1; | |
277 | |
278 filelist = wdata->files; | |
279 templist = GTK_CLIST (wdata->listbox)->selection; | |
280 num = 0; | |
281 while (templist != NULL) | |
282 { | |
283 templist = get_next_selection (templist, &filelist, &num); | |
284 tempfle = filelist->data; | |
285 tempfle->was_sel = 1; | |
286 } | |
287 | |
288 gtk_clist_freeze (GTK_CLIST (wdata->listbox)); | |
289 gtk_clist_clear (GTK_CLIST (wdata->listbox)); | |
290 templist = wdata->files; | |
291 while (templist != NULL) | |
292 { | |
293 tempfle = templist->data; | |
294 add_file_listbox (wdata, tempfle); | |
295 templist = templist->next; | |
296 } | |
297 gtk_clist_thaw (GTK_CLIST (wdata->listbox)); | |
298 update_window (wdata); | |
299 } | |
300 | |
301 | |
302 void | |
303 selectall (gpointer data) | |
304 { | |
305 gftp_window_data * wdata; | |
306 | |
307 wdata = data; | |
308 wdata->show_selected = 0; | |
309 gtk_clist_select_all (GTK_CLIST (wdata->listbox)); | |
310 } | |
311 | |
312 | |
313 void | |
314 selectallfiles (gpointer data) | |
315 { | |
316 gftp_window_data * wdata; | |
317 gftp_file * tempfle; | |
318 GList *templist; | |
319 int i; | |
320 | |
321 wdata = data; | |
322 wdata->show_selected = 0; | |
323 gtk_clist_freeze (GTK_CLIST (wdata->listbox)); | |
324 i = 0; | |
39 | 325 templist = wdata->files; |
1 | 326 while (templist != NULL) |
327 { | |
328 tempfle = (gftp_file *) templist->data; | |
329 if (tempfle->shown) | |
330 { | |
331 if (tempfle->isdir) | |
332 gtk_clist_unselect_row (GTK_CLIST (wdata->listbox), i, 0); | |
333 else | |
334 gtk_clist_select_row (GTK_CLIST (wdata->listbox), i, 0); | |
335 i++; | |
336 } | |
337 templist = templist->next; | |
338 } | |
339 gtk_clist_thaw (GTK_CLIST (wdata->listbox)); | |
340 } | |
341 | |
342 | |
343 void | |
344 deselectall (gpointer data) | |
345 { | |
346 gftp_window_data * wdata; | |
347 | |
348 wdata = data; | |
349 wdata->show_selected = 0; | |
350 gtk_clist_unselect_all (GTK_CLIST (wdata->listbox)); | |
351 } | |
352 | |
353 | |
19 | 354 static void |
355 dosite (gftp_window_data * wdata, gftp_dialog_data * ddata) | |
1 | 356 { |
357 const char *edttext; | |
358 | |
19 | 359 edttext = gtk_entry_get_text (GTK_ENTRY (ddata->edit)); |
1 | 360 if (*edttext == '\0') |
361 { | |
362 ftp_log (gftp_logging_misc, NULL, | |
363 _("SITE: Operation canceled...you must enter a string\n")); | |
364 return; | |
365 } | |
366 | |
367 if (check_reconnect (wdata) < 0) | |
368 return; | |
369 gftp_site_cmd (wdata->request, edttext); | |
370 | |
371 if (!GFTP_IS_CONNECTED (wdata->request)) | |
372 disconnect (wdata); | |
373 } | |
374 | |
375 | |
19 | 376 void |
377 site_dialog (gpointer data) | |
378 { | |
379 gftp_window_data * wdata; | |
380 | |
381 wdata = data; | |
382 if (!check_status (_("Site"), wdata, 0, 0, 0, wdata->request->site != NULL)) | |
383 return; | |
384 | |
385 MakeEditDialog (_("Site"), _("Enter site-specific command"), NULL, 1, | |
386 NULL, gftp_dialog_button_ok, dosite, wdata, NULL, NULL); | |
387 } | |
388 | |
389 | |
48 | 390 static void * |
391 do_change_dir_thread (void * data) | |
392 { | |
129 | 393 int success, sj, network_timeout; |
48 | 394 gftp_window_data * wdata; |
395 | |
396 wdata = data; | |
397 | |
398 if (wdata->request->use_threads) | |
399 { | |
400 sj = sigsetjmp (jmp_environment, 1); | |
401 use_jmp_environment = 1; | |
402 } | |
403 else | |
404 sj = 0; | |
405 | |
129 | 406 gftp_lookup_request_option (wdata->request, "network_timeout", |
407 &network_timeout); | |
408 | |
48 | 409 success = 0; |
410 if (sj == 0) | |
411 { | |
129 | 412 if (network_timeout > 0) |
413 alarm (network_timeout); | |
48 | 414 success = gftp_set_directory (wdata->request, wdata->request->directory); |
415 alarm (0); | |
416 } | |
417 else | |
418 { | |
419 gftp_disconnect (wdata->request); | |
420 wdata->request->logging_function (gftp_logging_error, | |
186 | 421 wdata->request, |
48 | 422 _("Operation canceled\n")); |
423 } | |
424 | |
425 if (wdata->request->use_threads) | |
426 use_jmp_environment = 0; | |
427 | |
428 wdata->request->stopable = 0; | |
195 | 429 return (GINT_TO_POINTER (success)); |
48 | 430 } |
431 | |
432 | |
433 static int | |
434 do_change_dir (gftp_window_data * wdata, char *directory) | |
435 { | |
436 char *olddir; | |
437 int ret; | |
438 | |
439 if (directory != wdata->request->directory) | |
440 { | |
441 olddir = wdata->request->directory; | |
129 | 442 wdata->request->directory = g_strdup (directory); |
48 | 443 } |
444 else | |
445 olddir = NULL; | |
446 | |
195 | 447 ret = GPOINTER_TO_INT (generic_thread (do_change_dir_thread, wdata)); |
48 | 448 |
449 if (!GFTP_IS_CONNECTED (wdata->request)) | |
450 { | |
451 disconnect (wdata); | |
452 if (olddir != NULL) | |
453 g_free (olddir); | |
454 return (-2); | |
455 } | |
456 | |
457 if (ret != 0) | |
458 { | |
459 g_free (wdata->request->directory); | |
460 wdata->request->directory = olddir; | |
461 } | |
462 else | |
463 g_free (olddir); | |
464 | |
465 return (ret); | |
466 } | |
467 | |
468 | |
1 | 469 int |
470 chdir_edit (GtkWidget * widget, gpointer data) | |
471 { | |
472 gftp_window_data * wdata; | |
473 const char *edttxt; | |
474 char *tempstr; | |
475 | |
476 wdata = data; | |
477 edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (wdata->combo)->entry)); | |
478 if (!GFTP_IS_CONNECTED (wdata->request) && *edttxt != '\0') | |
479 { | |
480 toolbar_hostedit (NULL, NULL); | |
481 return (0); | |
482 } | |
483 | |
484 if (!check_status (_("Chdir"), wdata, wdata->request->use_threads, 0, 0, | |
485 wdata->request->chdir != NULL)) | |
486 return (FALSE); | |
487 | |
488 if ((tempstr = expand_path (edttxt)) == NULL) | |
489 return (FALSE); | |
490 | |
491 if (check_reconnect (wdata) < 0) | |
492 return (FALSE); | |
493 | |
494 if (do_change_dir (wdata, tempstr) == 0) | |
495 { | |
496 gtk_clist_freeze (GTK_CLIST (wdata->listbox)); | |
497 remove_files_window (wdata); | |
498 ftp_list_files (wdata, 1); | |
499 gtk_clist_thaw (GTK_CLIST (wdata->listbox)); | |
500 add_history (wdata->combo, wdata->history, wdata->histlen, tempstr); | |
501 } | |
502 | |
503 g_free (tempstr); | |
504 return (FALSE); | |
505 } | |
506 | |
507 | |
508 int | |
509 chdir_dialog (gpointer data) | |
510 { | |
511 GList * templist, * filelist; | |
512 gftp_window_data * wdata; | |
513 char *newdir, *tempstr; | |
514 gftp_file *tempfle; | |
515 int num, ret; | |
516 | |
517 wdata = data; | |
518 if (!check_status (_("Chdir"), wdata, wdata->request->use_threads, 1, 0, | |
519 wdata->request->chdir != NULL)) | |
520 return (0); | |
521 | |
39 | 522 filelist = wdata->files; |
1 | 523 templist = GTK_CLIST (wdata->listbox)->selection; |
524 num = 0; | |
525 templist = get_next_selection (templist, &filelist, &num); | |
526 tempfle = filelist->data; | |
527 | |
245 | 528 newdir = gftp_build_path (wdata->request->directory, tempfle->file, NULL); |
211 | 529 |
1 | 530 if ((tempstr = expand_path (newdir)) == NULL) |
211 | 531 { |
532 g_free (newdir); | |
533 return (0); | |
534 } | |
535 | |
1 | 536 g_free (newdir); |
537 | |
538 if (check_reconnect (wdata) < 0) | |
539 return (0); | |
540 | |
541 ret = 0; | |
542 if (do_change_dir (wdata, tempstr) == 0) | |
543 { | |
544 gtk_clist_freeze (GTK_CLIST (wdata->listbox)); | |
545 remove_files_window (wdata); | |
546 ftp_list_files (wdata, 1); | |
547 gtk_clist_thaw (GTK_CLIST (wdata->listbox)); | |
548 ret = 1; | |
549 } | |
550 g_free (tempstr); | |
551 return (ret); | |
552 } | |
553 | |
554 | |
555 void | |
556 clearlog (gpointer data) | |
557 { | |
558 guint len; | |
45 | 559 #if GTK_MAJOR_VERSION == 1 |
1 | 560 len = gtk_text_get_length (GTK_TEXT (logwdw)); |
561 gtk_text_set_point (GTK_TEXT (logwdw), len); | |
562 gtk_text_backward_delete (GTK_TEXT (logwdw), len); | |
563 #else | |
564 GtkTextBuffer * textbuf; | |
565 GtkTextIter iter, iter2; | |
566 | |
567 textbuf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (logwdw)); | |
568 len = gtk_text_buffer_get_char_count (textbuf); | |
569 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, 0); | |
570 gtk_text_buffer_get_iter_at_offset (textbuf, &iter2, len - 1); | |
571 gtk_text_buffer_delete (textbuf, &iter, &iter2); | |
572 #endif | |
573 } | |
574 | |
575 | |
576 void | |
577 viewlog (gpointer data) | |
578 { | |
579 char *tempstr, *txt, *pos; | |
580 guint textlen; | |
581 ssize_t len; | |
582 int fd; | |
45 | 583 #if GTK_MAJOR_VERSION > 1 |
1 | 584 GtkTextBuffer * textbuf; |
585 GtkTextIter iter, iter2; | |
586 #endif | |
587 | |
41 | 588 tempstr = g_strconcat (g_get_tmp_dir (), "/gftp-view.XXXXXXXXXX", NULL); |
1 | 589 if ((fd = mkstemp (tempstr)) < 0) |
590 { | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
591 ftp_log (gftp_logging_misc, NULL, |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
592 _("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
|
593 g_strerror (errno)); |
1 | 594 g_free (tempstr); |
595 return; | |
596 } | |
597 chmod (tempstr, S_IRUSR | S_IWUSR); | |
598 unlink (tempstr); | |
599 | |
45 | 600 #if GTK_MAJOR_VERSION == 1 |
1 | 601 textlen = gtk_text_get_length (GTK_TEXT (logwdw)); |
602 txt = gtk_editable_get_chars (GTK_EDITABLE (logwdw), 0, -1); | |
603 #else | |
604 textbuf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (logwdw)); | |
605 textlen = gtk_text_buffer_get_char_count (textbuf); | |
606 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, 0); | |
607 gtk_text_buffer_get_iter_at_offset (textbuf, &iter2, textlen - 1); | |
608 txt = gtk_text_buffer_get_text (textbuf, &iter, &iter2, 0); | |
609 #endif | |
610 pos = txt; | |
611 do | |
612 { | |
613 if ((len = write (fd, pos, textlen)) == -1) | |
614 { | |
186 | 615 ftp_log (gftp_logging_misc, NULL, |
616 _("Error: Error writing to %s: %s\n"), | |
617 tempstr, g_strerror (errno)); | |
1 | 618 break; |
619 } | |
620 textlen -= len; | |
621 pos += len; | |
622 } while (textlen > 0); | |
623 | |
624 lseek (fd, 0, SEEK_SET); | |
625 view_file (tempstr, fd, 1, 0, 0, 1, NULL, NULL); | |
626 close (fd); | |
627 g_free (tempstr); | |
628 g_free (txt); | |
629 } | |
630 | |
631 | |
632 static void | |
633 dosavelog (GtkWidget * widget, GtkFileSelection * fs) | |
634 { | |
635 const char *filename; | |
636 char *txt, *pos; | |
637 guint textlen; | |
638 ssize_t len; | |
639 FILE *fd; | |
640 int ok; | |
45 | 641 #if GTK_MAJOR_VERSION > 1 |
1 | 642 GtkTextBuffer * textbuf; |
643 GtkTextIter iter, iter2; | |
644 #endif | |
645 | |
646 filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs)); | |
647 if ((fd = fopen (filename, "w")) == NULL) | |
648 { | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
649 ftp_log (gftp_logging_misc, NULL, |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
650 _("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
|
651 g_strerror (errno)); |
1 | 652 return; |
653 } | |
654 | |
45 | 655 #if GTK_MAJOR_VERSION == 1 |
1 | 656 textlen = gtk_text_get_length (GTK_TEXT (logwdw)); |
657 txt = gtk_editable_get_chars (GTK_EDITABLE (logwdw), 0, -1); | |
658 #else | |
659 textbuf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (logwdw)); | |
660 textlen = gtk_text_buffer_get_char_count (textbuf); | |
661 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, 0); | |
662 gtk_text_buffer_get_iter_at_offset (textbuf, &iter2, textlen - 1); | |
663 txt = gtk_text_buffer_get_text (textbuf, &iter, &iter2, 0); | |
664 #endif | |
665 | |
666 ok = 1; | |
667 pos = txt; | |
668 do | |
669 { | |
670 if ((len = write (fileno (fd), pos, textlen)) == -1) | |
671 { | |
672 ok = 0; | |
186 | 673 ftp_log (gftp_logging_misc, NULL, |
674 _("Error: Error writing to %s: %s\n"), | |
675 filename, g_strerror (errno)); | |
1 | 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 | |
255 | 773 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 | 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 } |