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