Mercurial > gftp.yaz
annotate src/gtk/menu-items.c @ 830:afbe37351940
2006-10-19 Brian Masney <masneyb@gftp.org>
WARNING: The CVS version of gFTP is currently broken, especially for
international users. This will be fixed in a few days.
* src/gtk/gtkui.c src/gtk/gtkui_transfer.c src/gtk/misc-gtk.c lib/gftp.h
lib/misc.c lib/protocols.c - removed code that converts the filename to
UTF8. This will be handled by the library. Removed utf8_file member from
the gftp_file structure.
* lib/rfc959.c - convert the file or directory from UTF8 to the proper
locale when sending a command to the server.
* src/uicommon/gftpui.c src/gtk/menu-items.c lib/misc.c lib/gftp.h
(gftp_gen_ls_string) - convert the filename from UTF8 to the proper
locale before it is displayed to the user.
author | masneyb |
---|---|
date | Thu, 19 Oct 2006 11:41:04 +0000 |
parents | 49cfbe02926b |
children | 19dacfb69433 |
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 | |
518 | 20 #include "gftp-gtk.h" |
33 | 21 static const char cvsid[] = "$Id$"; |
1 | 22 |
23 static void | |
19 | 24 dochange_filespec (gftp_window_data * wdata, gftp_dialog_data * ddata) |
1 | 25 { |
26 GList * templist, * filelist; | |
27 gftp_file * tempfle; | |
28 const char *edttext; | |
29 int num; | |
30 | |
31 wdata->show_selected = 0; | |
32 | |
19 | 33 edttext = gtk_entry_get_text (GTK_ENTRY (ddata->edit)); |
1 | 34 if (*edttext == '\0') |
35 { | |
677 | 36 ftp_log (gftp_logging_error, NULL, |
1 | 37 _("Change Filespec: Operation canceled...you must enter a string\n")); |
38 return; | |
39 } | |
40 if (wdata->filespec) | |
41 g_free (wdata->filespec); | |
129 | 42 wdata->filespec = g_strdup (edttext); |
1 | 43 |
44 filelist = wdata->files; | |
525 | 45 templist = gftp_gtk_get_list_selection (wdata); |
1 | 46 num = 0; |
47 while (templist != NULL) | |
48 { | |
49 templist = get_next_selection (templist, &filelist, &num); | |
50 tempfle = filelist->data; | |
51 tempfle->was_sel = 1; | |
52 } | |
53 | |
54 gtk_clist_freeze (GTK_CLIST (wdata->listbox)); | |
55 gtk_clist_clear (GTK_CLIST (wdata->listbox)); | |
56 templist = wdata->files; | |
57 while (templist != NULL) | |
58 { | |
59 tempfle = templist->data; | |
60 add_file_listbox (wdata, tempfle); | |
61 templist = templist->next; | |
62 } | |
63 gtk_clist_thaw (GTK_CLIST (wdata->listbox)); | |
64 update_window (wdata); | |
65 } | |
66 | |
67 | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
68 void |
19 | 69 change_filespec (gpointer data) |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
70 { |
19 | 71 gftp_window_data * wdata; |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
72 |
19 | 73 wdata = data; |
74 if (!check_status (_("Change Filespec"), wdata, 0, 0, 0, 1)) | |
75 return; | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
76 |
19 | 77 MakeEditDialog (_("Change Filespec"), _("Enter the new file specification"), |
78 wdata->filespec, 1, NULL, gftp_dialog_button_change, | |
79 dochange_filespec, wdata, NULL, NULL); | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
80 } |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
81 |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
82 |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
83 static void |
21 | 84 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
|
85 { |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
86 gtk_widget_destroy (str->filew); |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
87 g_free (str); |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
88 } |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
89 |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
90 |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
91 static void |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
92 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
|
93 { |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
94 const char *filename; |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
95 gftp_file * tempfle; |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
96 GList * templist; |
131 | 97 char *tempstr; |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
98 FILE * fd; |
131 | 99 |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
100 |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
101 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
|
102 if ((fd = fopen (filename, "w")) == NULL) |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
103 { |
677 | 104 ftp_log (gftp_logging_error, NULL, |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
105 _("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
|
106 g_strerror (errno)); |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
107 return; |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
108 } |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
109 |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
110 for (templist = str->wdata->files; |
276 | 111 templist != NULL; |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
112 templist = templist->next) |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
113 { |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
114 tempfle = templist->data; |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
115 |
295 | 116 if (!tempfle->shown) |
117 continue; | |
118 | |
830 | 119 tempstr = gftp_gen_ls_string (NULL, tempfle, NULL, NULL); |
131 | 120 fprintf (fd, "%s\n", tempstr); |
121 g_free (tempstr); | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
122 } |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
123 |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
124 fclose (fd); |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
125 } |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
126 |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
127 |
19 | 128 void |
129 save_directory_listing (gpointer data) | |
130 { | |
131 gftp_save_dir_struct * str; | |
132 GtkWidget *filew; | |
133 | |
134 filew = gtk_file_selection_new (_("Save Directory Listing")); | |
135 | |
136 str = g_malloc (sizeof (*str)); | |
137 str->filew = filew; | |
138 str->wdata = data; | |
139 | |
140 gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button), | |
141 "clicked", GTK_SIGNAL_FUNC (dosave_directory_listing), | |
142 str); | |
21 | 143 gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button), |
144 "clicked", | |
145 GTK_SIGNAL_FUNC (destroy_save_directory_listing), str); | |
146 gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->cancel_button), | |
147 "clicked", | |
148 GTK_SIGNAL_FUNC (destroy_save_directory_listing), str); | |
19 | 149 |
150 gtk_window_set_wmclass (GTK_WINDOW(filew), "Save Directory Listing", "gFTP"); | |
151 gtk_widget_show (filew); | |
152 } | |
153 | |
154 | |
1 | 155 void |
156 show_selected (gpointer data) | |
157 { | |
158 GList * templist, * filelist; | |
159 gftp_window_data * wdata; | |
160 gftp_file * tempfle; | |
161 int num; | |
162 | |
163 wdata = data; | |
164 wdata->show_selected = 1; | |
165 | |
166 filelist = wdata->files; | |
525 | 167 templist = gftp_gtk_get_list_selection (wdata); |
1 | 168 num = 0; |
169 while (templist != NULL) | |
170 { | |
171 templist = get_next_selection (templist, &filelist, &num); | |
172 tempfle = filelist->data; | |
173 tempfle->was_sel = 1; | |
174 } | |
175 | |
176 gtk_clist_freeze (GTK_CLIST (wdata->listbox)); | |
177 gtk_clist_clear (GTK_CLIST (wdata->listbox)); | |
178 templist = wdata->files; | |
179 while (templist != NULL) | |
180 { | |
181 tempfle = templist->data; | |
182 add_file_listbox (wdata, tempfle); | |
183 templist = templist->next; | |
184 } | |
185 gtk_clist_thaw (GTK_CLIST (wdata->listbox)); | |
186 update_window (wdata); | |
187 } | |
188 | |
189 | |
190 void | |
191 selectall (gpointer data) | |
192 { | |
193 gftp_window_data * wdata; | |
194 | |
195 wdata = data; | |
196 wdata->show_selected = 0; | |
197 gtk_clist_select_all (GTK_CLIST (wdata->listbox)); | |
198 } | |
199 | |
200 | |
201 void | |
202 selectallfiles (gpointer data) | |
203 { | |
204 gftp_window_data * wdata; | |
205 gftp_file * tempfle; | |
206 GList *templist; | |
207 int i; | |
208 | |
209 wdata = data; | |
210 wdata->show_selected = 0; | |
211 gtk_clist_freeze (GTK_CLIST (wdata->listbox)); | |
212 i = 0; | |
39 | 213 templist = wdata->files; |
1 | 214 while (templist != NULL) |
215 { | |
216 tempfle = (gftp_file *) templist->data; | |
217 if (tempfle->shown) | |
218 { | |
499 | 219 if (S_ISDIR (tempfle->st_mode)) |
1 | 220 gtk_clist_unselect_row (GTK_CLIST (wdata->listbox), i, 0); |
221 else | |
222 gtk_clist_select_row (GTK_CLIST (wdata->listbox), i, 0); | |
223 i++; | |
224 } | |
225 templist = templist->next; | |
226 } | |
227 gtk_clist_thaw (GTK_CLIST (wdata->listbox)); | |
228 } | |
229 | |
230 | |
231 void | |
232 deselectall (gpointer data) | |
233 { | |
234 gftp_window_data * wdata; | |
235 | |
236 wdata = data; | |
237 wdata->show_selected = 0; | |
238 gtk_clist_unselect_all (GTK_CLIST (wdata->listbox)); | |
239 } | |
240 | |
241 | |
242 int | |
243 chdir_edit (GtkWidget * widget, gpointer data) | |
244 { | |
245 gftp_window_data * wdata; | |
246 const char *edttxt; | |
247 char *tempstr; | |
248 | |
249 wdata = data; | |
445 | 250 if (!check_status (_("Chdir"), wdata, gftpui_common_use_threads (wdata->request), 0, 0, |
341 | 251 wdata->request->chdir != NULL)) |
252 return (0); | |
337 | 253 |
254 if (check_reconnect (wdata) < 0) | |
255 return (0); | |
256 | |
341 | 257 edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (wdata->combo)->entry)); |
258 | |
1 | 259 if (!GFTP_IS_CONNECTED (wdata->request) && *edttxt != '\0') |
260 { | |
261 toolbar_hostedit (NULL, NULL); | |
262 return (0); | |
263 } | |
264 | |
555 | 265 if ((tempstr = gftp_expand_path (wdata->request, edttxt)) == NULL) |
1 | 266 return (FALSE); |
267 | |
341 | 268 if (gftpui_run_chdir (wdata, tempstr)) |
269 add_history (wdata->combo, wdata->history, wdata->histlen, edttxt); | |
1 | 270 |
271 g_free (tempstr); | |
341 | 272 return (0); |
1 | 273 } |
274 | |
275 | |
276 void | |
277 clearlog (gpointer data) | |
278 { | |
767 | 279 gint len; |
280 | |
45 | 281 #if GTK_MAJOR_VERSION == 1 |
1 | 282 len = gtk_text_get_length (GTK_TEXT (logwdw)); |
283 gtk_text_set_point (GTK_TEXT (logwdw), len); | |
284 gtk_text_backward_delete (GTK_TEXT (logwdw), len); | |
285 #else | |
286 GtkTextBuffer * textbuf; | |
287 GtkTextIter iter, iter2; | |
288 | |
289 textbuf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (logwdw)); | |
290 len = gtk_text_buffer_get_char_count (textbuf); | |
291 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, 0); | |
444 | 292 gtk_text_buffer_get_iter_at_offset (textbuf, &iter2, len); |
1 | 293 gtk_text_buffer_delete (textbuf, &iter, &iter2); |
294 #endif | |
295 } | |
296 | |
297 | |
298 void | |
299 viewlog (gpointer data) | |
300 { | |
301 char *tempstr, *txt, *pos; | |
767 | 302 gint textlen; |
1 | 303 ssize_t len; |
304 int fd; | |
45 | 305 #if GTK_MAJOR_VERSION > 1 |
1 | 306 GtkTextBuffer * textbuf; |
307 GtkTextIter iter, iter2; | |
308 #endif | |
309 | |
41 | 310 tempstr = g_strconcat (g_get_tmp_dir (), "/gftp-view.XXXXXXXXXX", NULL); |
1 | 311 if ((fd = mkstemp (tempstr)) < 0) |
312 { | |
677 | 313 ftp_log (gftp_logging_error, NULL, |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
314 _("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
|
315 g_strerror (errno)); |
1 | 316 g_free (tempstr); |
317 return; | |
318 } | |
319 chmod (tempstr, S_IRUSR | S_IWUSR); | |
320 | |
45 | 321 #if GTK_MAJOR_VERSION == 1 |
1 | 322 textlen = gtk_text_get_length (GTK_TEXT (logwdw)); |
323 txt = gtk_editable_get_chars (GTK_EDITABLE (logwdw), 0, -1); | |
324 #else | |
325 textbuf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (logwdw)); | |
326 textlen = gtk_text_buffer_get_char_count (textbuf); | |
327 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, 0); | |
444 | 328 gtk_text_buffer_get_iter_at_offset (textbuf, &iter2, textlen); |
1 | 329 txt = gtk_text_buffer_get_text (textbuf, &iter, &iter2, 0); |
588 | 330 |
331 /* gtk_text_buffer_get_char_count() returns the number of characters, | |
332 not bytes. So get the number of bytes that need to be written out */ | |
333 textlen = strlen (txt); | |
1 | 334 #endif |
335 pos = txt; | |
444 | 336 |
337 while (textlen > 0) | |
1 | 338 { |
339 if ((len = write (fd, pos, textlen)) == -1) | |
340 { | |
677 | 341 ftp_log (gftp_logging_error, NULL, |
186 | 342 _("Error: Error writing to %s: %s\n"), |
343 tempstr, g_strerror (errno)); | |
1 | 344 break; |
345 } | |
346 textlen -= len; | |
347 pos += len; | |
444 | 348 } |
1 | 349 |
444 | 350 fsync (fd); |
1 | 351 lseek (fd, 0, SEEK_SET); |
444 | 352 view_file (tempstr, fd, 1, 1, 0, 1, NULL, NULL); |
1 | 353 close (fd); |
444 | 354 |
1 | 355 g_free (tempstr); |
356 g_free (txt); | |
357 } | |
358 | |
359 | |
360 static void | |
361 dosavelog (GtkWidget * widget, GtkFileSelection * fs) | |
362 { | |
363 const char *filename; | |
364 char *txt, *pos; | |
767 | 365 gint textlen; |
1 | 366 ssize_t len; |
367 FILE *fd; | |
368 int ok; | |
45 | 369 #if GTK_MAJOR_VERSION > 1 |
1 | 370 GtkTextBuffer * textbuf; |
371 GtkTextIter iter, iter2; | |
372 #endif | |
373 | |
374 filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs)); | |
375 if ((fd = fopen (filename, "w")) == NULL) | |
376 { | |
677 | 377 ftp_log (gftp_logging_error, NULL, |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
378 _("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
|
379 g_strerror (errno)); |
1 | 380 return; |
381 } | |
382 | |
45 | 383 #if GTK_MAJOR_VERSION == 1 |
1 | 384 textlen = gtk_text_get_length (GTK_TEXT (logwdw)); |
385 txt = gtk_editable_get_chars (GTK_EDITABLE (logwdw), 0, -1); | |
386 #else | |
387 textbuf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (logwdw)); | |
388 textlen = gtk_text_buffer_get_char_count (textbuf); | |
389 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, 0); | |
444 | 390 gtk_text_buffer_get_iter_at_offset (textbuf, &iter2, textlen); |
1 | 391 txt = gtk_text_buffer_get_text (textbuf, &iter, &iter2, 0); |
588 | 392 |
393 /* gtk_text_buffer_get_char_count() returns the number of characters, | |
394 not bytes. So get the number of bytes that need to be written out */ | |
395 textlen = strlen (txt); | |
1 | 396 #endif |
397 | |
398 ok = 1; | |
399 pos = txt; | |
400 do | |
401 { | |
402 if ((len = write (fileno (fd), pos, textlen)) == -1) | |
403 { | |
404 ok = 0; | |
677 | 405 ftp_log (gftp_logging_error, NULL, |
186 | 406 _("Error: Error writing to %s: %s\n"), |
407 filename, g_strerror (errno)); | |
1 | 408 break; |
409 } | |
410 | |
411 textlen -= len; | |
412 pos += len; | |
413 } while (textlen > 0); | |
414 | |
415 if (ok) | |
416 ftp_log (gftp_logging_misc, NULL, | |
417 _("Successfully wrote the log file to %s\n"), filename); | |
418 | |
419 fclose (fd); | |
420 g_free (txt); | |
421 } | |
422 | |
423 | |
424 void | |
19 | 425 savelog (gpointer data) |
426 { | |
427 GtkWidget *filew; | |
428 | |
429 filew = gtk_file_selection_new (_("Save Log")); | |
430 | |
431 gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button), | |
432 "clicked", GTK_SIGNAL_FUNC (dosavelog), filew); | |
433 gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button), | |
434 "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy), | |
435 GTK_OBJECT (filew)); | |
436 gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (filew)->cancel_button), "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_OBJECT (filew)); | |
437 | |
438 gtk_file_selection_set_filename (GTK_FILE_SELECTION (filew), "gftp.log"); | |
439 gtk_window_set_wmclass (GTK_WINDOW(filew), "Save Log", "gFTP"); | |
440 gtk_widget_show (filew); | |
441 } | |
442 | |
443 | |
444 void | |
1 | 445 clear_cache (gpointer data) |
446 { | |
447 gftp_clear_cache_files (); | |
448 } | |
449 | |
450 | |
451 void | |
452 about_dialog (gpointer data) | |
453 { | |
483 | 454 GtkWidget * tempwid, * notebook, * box, * label, * view, * vscroll, * dialog; |
455 char *tempstr, *temp1str, *no_license_agreement, *str, buf[255], *share_dir; | |
1 | 456 size_t len; |
457 FILE * fd; | |
45 | 458 #if GTK_MAJOR_VERSION > 1 |
1 | 459 GtkTextBuffer * textbuf; |
460 GtkTextIter iter; | |
767 | 461 gint textlen; |
1 | 462 #endif |
463 | |
483 | 464 share_dir = gftp_get_share_dir (); |
465 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); | |
1 | 466 |
45 | 467 #if GTK_MAJOR_VERSION == 1 |
1 | 468 dialog = gtk_dialog_new (); |
469 gtk_window_set_title (GTK_WINDOW (dialog), _("About gFTP")); | |
470 gtk_container_border_width (GTK_CONTAINER | |
471 (GTK_DIALOG (dialog)->action_area), 5); | |
472 gtk_box_set_homogeneous (GTK_BOX (GTK_DIALOG (dialog)->action_area), TRUE); | |
19 | 473 #else |
474 dialog = gtk_dialog_new_with_buttons (_("About gFTP"), NULL, 0, | |
475 GTK_STOCK_CLOSE, | |
476 GTK_RESPONSE_CLOSE, | |
477 NULL); | |
478 #endif | |
479 gtk_window_set_wmclass (GTK_WINDOW(dialog), "about", "gFTP"); | |
1 | 480 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE); |
19 | 481 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), 10); |
482 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 5); | |
1 | 483 gtk_widget_realize (dialog); |
484 | |
19 | 485 if (gftp_icon != NULL) |
486 { | |
487 gdk_window_set_icon (dialog->window, NULL, gftp_icon->pixmap, | |
488 gftp_icon->bitmap); | |
168 | 489 gdk_window_set_icon_name (dialog->window, gftp_version); |
19 | 490 } |
491 | |
1 | 492 notebook = gtk_notebook_new (); |
493 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), notebook, TRUE, | |
494 TRUE, 0); | |
495 gtk_widget_show (notebook); | |
496 | |
497 box = gtk_vbox_new (TRUE, 5); | |
498 gtk_container_border_width (GTK_CONTAINER (box), 10); | |
499 gtk_widget_show (box); | |
500 | |
501 tempwid = toolbar_pixmap (dialog, "gftp-logo.xpm"); | |
502 gtk_box_pack_start (GTK_BOX (box), tempwid, FALSE, FALSE, 0); | |
503 gtk_widget_show (tempwid); | |
504 | |
255 | 505 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 | 506 str = _("Translated by"); |
507 if (strcmp (str, "Translated by") != 0) | |
508 { | |
767 | 509 tempstr = g_realloc (tempstr, |
510 (gulong) (strlen (tempstr) + strlen (str) + 1)); | |
1 | 511 strcat (tempstr, str); |
512 } | |
513 tempwid = gtk_label_new (tempstr); | |
514 g_free (tempstr); | |
515 gtk_box_pack_start (GTK_BOX (box), tempwid, FALSE, FALSE, 0); | |
516 gtk_widget_show (tempwid); | |
517 | |
518 label = gtk_label_new (_("About")); | |
519 gtk_widget_show (label); | |
520 | |
521 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), box, label); | |
522 | |
523 box = gtk_vbox_new (FALSE, 5); | |
524 gtk_container_border_width (GTK_CONTAINER (box), 10); | |
525 gtk_widget_show (box); | |
526 | |
527 tempwid = gtk_table_new (1, 2, FALSE); | |
528 gtk_box_pack_start (GTK_BOX (box), tempwid, TRUE, TRUE, 0); | |
529 gtk_widget_show (tempwid); | |
530 | |
45 | 531 #if GTK_MAJOR_VERSION == 1 |
1 | 532 view = gtk_text_new (NULL, NULL); |
533 gtk_text_set_editable (GTK_TEXT (view), FALSE); | |
534 gtk_text_set_word_wrap (GTK_TEXT (view), TRUE); | |
535 | |
536 gtk_table_attach (GTK_TABLE (tempwid), view, 0, 1, 0, 1, | |
537 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
538 0, 0); | |
539 gtk_widget_show (view); | |
540 | |
541 vscroll = gtk_vscrollbar_new (GTK_TEXT (view)->vadj); | |
542 gtk_table_attach (GTK_TABLE (tempwid), vscroll, 1, 2, 0, 1, | |
543 GTK_FILL, GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0); | |
544 gtk_widget_show (vscroll); | |
545 #else | |
546 view = gtk_text_view_new (); | |
547 gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE); | |
548 gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE); | |
549 gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD); | |
550 | |
551 vscroll = gtk_scrolled_window_new (NULL, NULL); | |
552 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (vscroll), | |
553 GTK_POLICY_AUTOMATIC, | |
554 GTK_POLICY_AUTOMATIC); | |
555 | |
556 gtk_container_add (GTK_CONTAINER (vscroll), view); | |
557 gtk_widget_show (view); | |
558 | |
559 gtk_table_attach (GTK_TABLE (tempwid), vscroll, 0, 1, 0, 1, | |
560 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
561 0, 0); | |
562 gtk_widget_show (vscroll); | |
563 | |
564 textbuf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); | |
565 #endif | |
566 | |
567 label = gtk_label_new (_("License Agreement")); | |
568 gtk_widget_show (label); | |
569 | |
570 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), box, label); | |
571 | |
45 | 572 #if GTK_MAJOR_VERSION == 1 |
1 | 573 tempwid = gtk_button_new_with_label (_(" Close ")); |
574 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); | |
575 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid, | |
576 FALSE, FALSE, 0); | |
577 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked", | |
578 GTK_SIGNAL_FUNC (gtk_widget_destroy), | |
579 GTK_OBJECT (dialog)); | |
580 gtk_widget_grab_default (tempwid); | |
581 gtk_widget_show (tempwid); | |
19 | 582 #else |
583 g_signal_connect_swapped (GTK_OBJECT (dialog), "response", | |
584 G_CALLBACK (gtk_widget_destroy), | |
585 GTK_OBJECT (dialog)); | |
586 #endif | |
1 | 587 |
588 tempstr = g_strconcat ("/usr/share/common-licenses/GPL", NULL); | |
589 if (access (tempstr, F_OK) != 0) | |
590 { | |
591 g_free (tempstr); | |
483 | 592 temp1str = g_strconcat (share_dir, "/COPYING", NULL); |
555 | 593 tempstr = gftp_expand_path (NULL, temp1str); |
483 | 594 g_free (temp1str); |
1 | 595 if (access (tempstr, F_OK) != 0) |
596 { | |
597 g_free (tempstr); | |
555 | 598 tempstr = gftp_expand_path (NULL, BASE_CONF_DIR "/COPYING"); |
1 | 599 if (access (tempstr, F_OK) != 0) |
600 { | |
45 | 601 #if GTK_MAJOR_VERSION == 1 |
1 | 602 gtk_text_insert (GTK_TEXT (view), NULL, NULL, NULL, |
603 no_license_agreement, -1); | |
604 #else | |
605 textlen = gtk_text_buffer_get_char_count (textbuf); | |
444 | 606 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, textlen); |
1 | 607 gtk_text_buffer_insert (textbuf, &iter, no_license_agreement, -1); |
608 #endif | |
609 gtk_widget_show (dialog); | |
610 return; | |
611 } | |
612 } | |
613 } | |
614 | |
615 if ((fd = fopen (tempstr, "r")) == NULL) | |
616 { | |
45 | 617 #if GTK_MAJOR_VERSION == 1 |
1 | 618 gtk_text_insert (GTK_TEXT (view), NULL, NULL, NULL, |
619 no_license_agreement, -1); | |
620 #else | |
621 textlen = gtk_text_buffer_get_char_count (textbuf); | |
444 | 622 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, textlen); |
1 | 623 gtk_text_buffer_insert (textbuf, &iter, no_license_agreement, -1); |
624 #endif | |
625 gtk_widget_show (dialog); | |
626 g_free (tempstr); | |
627 return; | |
628 } | |
629 g_free (tempstr); | |
630 | |
631 memset (buf, 0, sizeof (buf)); | |
632 while ((len = fread (buf, 1, sizeof (buf) - 1, fd))) | |
633 { | |
634 buf[len] = '\0'; | |
45 | 635 #if GTK_MAJOR_VERSION == 1 |
1 | 636 gtk_text_insert (GTK_TEXT (view), NULL, NULL, NULL, buf, -1); |
637 #else | |
638 textlen = gtk_text_buffer_get_char_count (textbuf); | |
444 | 639 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, textlen); |
1 | 640 gtk_text_buffer_insert (textbuf, &iter, buf, -1); |
641 #endif | |
642 } | |
643 fclose (fd); | |
644 gtk_widget_show (dialog); | |
645 g_free (no_license_agreement); | |
646 gftp_free_pixmap ("gftp-logo.xpm"); | |
647 } | |
648 | |
649 | |
650 void | |
651 compare_windows (gpointer data) | |
652 { | |
653 gftp_file * curfle, * otherfle; | |
654 GList * curlist, * otherlist; | |
499 | 655 int row, curdir, othdir; |
1 | 656 |
657 if (!check_status (_("Compare Windows"), &window2, 1, 0, 0, 1)) | |
658 return; | |
659 | |
660 deselectall (&window1); | |
661 deselectall (&window2); | |
662 | |
663 row = 0; | |
664 curlist = window1.files; | |
665 while (curlist != NULL) | |
666 { | |
667 curfle = curlist->data; | |
668 if (!curfle->shown) | |
669 { | |
670 curlist = curlist->next; | |
671 continue; | |
672 } | |
673 | |
674 otherlist = window2.files; | |
675 while (otherlist != NULL) | |
676 { | |
677 otherfle = otherlist->data; | |
678 if (!otherfle->shown) | |
679 { | |
680 otherlist = otherlist->next; | |
681 continue; | |
682 } | |
683 | |
499 | 684 curdir = S_ISDIR (curfle->st_mode); |
685 othdir = S_ISDIR (otherfle->st_mode); | |
686 | |
1 | 687 if (strcmp (otherfle->file, curfle->file) == 0 && |
499 | 688 curdir == othdir && |
689 (curdir || otherfle->size == curfle->size)) | |
1 | 690 break; |
691 | |
692 otherlist = otherlist->next; | |
693 } | |
694 | |
695 if (otherlist == NULL) | |
696 gtk_clist_select_row (GTK_CLIST (window1.listbox), row, 0); | |
697 row++; | |
698 curlist = curlist->next; | |
699 } | |
700 | |
701 row = 0; | |
702 curlist = window2.files; | |
703 while (curlist != NULL) | |
704 { | |
705 curfle = curlist->data; | |
706 if (!curfle->shown) | |
707 { | |
708 curlist = curlist->next; | |
709 continue; | |
710 } | |
711 | |
712 otherlist = window1.files; | |
713 while (otherlist != NULL) | |
714 { | |
715 otherfle = otherlist->data; | |
716 if (!otherfle->shown) | |
717 { | |
718 otherlist = otherlist->next; | |
719 continue; | |
720 } | |
721 | |
499 | 722 curdir = S_ISDIR (curfle->st_mode); |
723 othdir = S_ISDIR (otherfle->st_mode); | |
724 | |
1 | 725 if (strcmp (otherfle->file, curfle->file) == 0 && |
499 | 726 curdir == othdir && |
727 (curdir || otherfle->size == curfle->size)) | |
1 | 728 break; |
729 | |
730 otherlist = otherlist->next; | |
731 } | |
732 | |
733 if (otherlist == NULL) | |
734 gtk_clist_select_row (GTK_CLIST (window2.listbox), row, 0); | |
735 row++; | |
736 curlist = curlist->next; | |
737 } | |
738 } |