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