Mercurial > gftp.yaz
annotate src/gtk/misc-gtk.c @ 788:0e7ab0a51ddd
2006-7-28 Brian Masney <masneyb@gftp.org>
* src/gtk/gftp-gtk.c src/gtk/gftp-gtk.h src/gtk/misc-gtk.c - warning
fixes when creating the system menus. Removed some unused global
variables.
author | masneyb |
---|---|
date | Fri, 28 Jul 2006 11:20:05 +0000 |
parents | 6f766002bff2 |
children | 37bc51131e2d |
rev | line source |
---|---|
1 | 1 /*****************************************************************************/ |
2 /* misc-gtk.c - misc stuff for the gtk+ 1.2 port of gftp */ | |
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 GtkWidget * statuswid; | |
24 | |
25 | |
26 void | |
27 remove_files_window (gftp_window_data * wdata) | |
28 { | |
29 wdata->show_selected = 0; | |
30 gtk_clist_freeze (GTK_CLIST (wdata->listbox)); | |
31 gtk_clist_clear (GTK_CLIST (wdata->listbox)); | |
32 free_file_list (wdata->files); | |
33 wdata->files = NULL; | |
34 gtk_clist_thaw (GTK_CLIST (wdata->listbox)); | |
35 } | |
36 | |
37 | |
38 void | |
186 | 39 ftp_log (gftp_logging_level level, gftp_request * request, |
40 const char *string, ...) | |
1 | 41 { |
326 | 42 uintptr_t max_log_window_size; |
45 | 43 int upd, free_logstr; |
1 | 44 gftp_log * newlog; |
519 | 45 gint delsize; |
45 | 46 char *logstr; |
1 | 47 va_list argp; |
519 | 48 size_t len; |
45 | 49 #if GTK_MAJOR_VERSION == 1 |
1 | 50 gftp_color * color; |
51 GdkColor fore; | |
52 #else | |
53 GtkTextBuffer * textbuf; | |
54 GtkTextIter iter, iter2; | |
55 const char *descr; | |
291 | 56 char *utf8_str; |
1 | 57 #endif |
58 | |
59 va_start (argp, string); | |
45 | 60 if (strcmp (string, "%s") == 0) |
61 { | |
62 logstr = va_arg (argp, char *); | |
63 free_logstr = 0; | |
64 } | |
65 else | |
66 { | |
67 logstr = g_strdup_vprintf (string, argp); | |
68 free_logstr = 1; | |
69 } | |
1 | 70 va_end (argp); |
71 | |
186 | 72 #if GTK_MAJOR_VERSION > 1 |
291 | 73 if ((utf8_str = gftp_string_to_utf8 (request, logstr)) != NULL) |
186 | 74 { |
291 | 75 if (free_logstr) |
76 g_free (logstr); | |
77 else | |
78 free_logstr = 1; | |
186 | 79 |
291 | 80 logstr = utf8_str; |
186 | 81 } |
82 #endif | |
83 | |
190 | 84 if (pthread_self () != main_thread_id) |
85 { | |
86 newlog = g_malloc0 (sizeof (*newlog)); | |
87 newlog->type = level; | |
88 if (free_logstr) | |
89 newlog->msg = logstr; | |
90 else | |
91 newlog->msg = g_strdup (logstr); | |
92 | |
93 pthread_mutex_lock (&log_mutex); | |
94 gftp_file_transfer_logs = g_list_append (gftp_file_transfer_logs, newlog); | |
95 pthread_mutex_unlock (&log_mutex); | |
96 return; | |
97 } | |
98 | |
354 | 99 if (gftp_logfd != NULL && level != gftp_logging_misc_nolog) |
1 | 100 { |
129 | 101 if (fwrite (logstr, strlen (logstr), 1, gftp_logfd) != 1) |
1 | 102 { |
129 | 103 fclose (gftp_logfd); |
104 gftp_logfd = NULL; | |
1 | 105 } |
106 else | |
45 | 107 { |
129 | 108 fflush (gftp_logfd); |
109 if (ferror (gftp_logfd)) | |
45 | 110 { |
129 | 111 fclose (gftp_logfd); |
112 gftp_logfd = NULL; | |
45 | 113 } |
114 } | |
1 | 115 } |
116 | |
117 upd = logwdw_vadj->upper - logwdw_vadj->page_size == logwdw_vadj->value; | |
118 | |
129 | 119 gftp_lookup_global_option ("max_log_window_size", &max_log_window_size); |
120 | |
45 | 121 #if GTK_MAJOR_VERSION == 1 |
1 | 122 switch (level) |
123 { | |
124 case gftp_logging_send: | |
151 | 125 gftp_lookup_global_option ("send_color", &color); |
1 | 126 break; |
127 case gftp_logging_recv: | |
151 | 128 gftp_lookup_global_option ("recv_color", &color); |
1 | 129 break; |
130 case gftp_logging_error: | |
151 | 131 gftp_lookup_global_option ("error_color", &color); |
1 | 132 break; |
133 default: | |
151 | 134 gftp_lookup_global_option ("misc_color", &color); |
1 | 135 break; |
136 } | |
137 | |
138 memset (&fore, 0, sizeof (fore)); | |
139 fore.red = color->red; | |
140 fore.green = color->green; | |
141 fore.blue = color->blue; | |
142 | |
143 gtk_text_freeze (GTK_TEXT (logwdw)); | |
45 | 144 gtk_text_insert (GTK_TEXT (logwdw), NULL, &fore, NULL, logstr, -1); |
1 | 145 |
146 len = gtk_text_get_length (GTK_TEXT (logwdw)); | |
147 if (max_log_window_size > 0 && len > max_log_window_size) | |
148 { | |
149 delsize = len - max_log_window_size; | |
150 gtk_text_set_point (GTK_TEXT (logwdw), delsize); | |
151 gtk_text_backward_delete (GTK_TEXT (logwdw), delsize); | |
152 len = max_log_window_size; | |
153 } | |
154 gtk_text_set_point (GTK_TEXT (logwdw), len); | |
155 | |
156 gtk_text_thaw (GTK_TEXT (logwdw)); | |
157 | |
158 if (upd) | |
159 gtk_adjustment_set_value (logwdw_vadj, logwdw_vadj->upper); | |
160 #else | |
161 switch (level) | |
162 { | |
163 case gftp_logging_send: | |
164 descr = "send"; | |
165 break; | |
166 case gftp_logging_recv: | |
167 descr = "recv"; | |
168 break; | |
169 case gftp_logging_error: | |
170 descr = "error"; | |
171 break; | |
172 default: | |
173 descr = "misc"; | |
174 break; | |
175 } | |
176 | |
177 textbuf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (logwdw)); | |
178 len = gtk_text_buffer_get_char_count (textbuf); | |
179 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, len); | |
45 | 180 gtk_text_buffer_insert_with_tags_by_name (textbuf, &iter, logstr, -1, |
1 | 181 descr, NULL); |
182 | |
183 if (upd) | |
184 { | |
185 gtk_text_buffer_move_mark (textbuf, logwdw_textmark, &iter); | |
186 gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (logwdw), logwdw_textmark, | |
187 0, 1, 1, 1); | |
188 } | |
189 | |
45 | 190 if (max_log_window_size > 0) |
1 | 191 { |
45 | 192 delsize = len + g_utf8_strlen (logstr, -1) - max_log_window_size; |
193 | |
194 if (delsize > 0) | |
195 { | |
196 gtk_text_buffer_get_iter_at_offset (textbuf, &iter, 0); | |
197 gtk_text_buffer_get_iter_at_offset (textbuf, &iter2, delsize); | |
198 gtk_text_buffer_delete (textbuf, &iter, &iter2); | |
199 } | |
1 | 200 } |
201 #endif | |
202 | |
45 | 203 if (free_logstr) |
204 g_free (logstr); | |
1 | 205 } |
206 | |
207 | |
208 void | |
209 update_window_info (void) | |
210 { | |
211 char *tempstr, empty[] = ""; | |
783 | 212 unsigned int port, i, j; |
1 | 213 GtkWidget * tempwid; |
214 | |
215 if (current_wdata->request != NULL) | |
216 { | |
616 | 217 if (GFTP_IS_CONNECTED (current_wdata->request)) |
1 | 218 { |
616 | 219 if ((tempstr = current_wdata->request->hostname) == NULL) |
220 tempstr = empty; | |
221 gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (hostedit)->entry), tempstr); | |
222 | |
223 if ((tempstr = current_wdata->request->username) == NULL) | |
224 tempstr = empty; | |
225 gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (useredit)->entry), tempstr); | |
226 | |
227 if ((tempstr = current_wdata->request->password) == NULL) | |
228 tempstr = empty; | |
229 gtk_entry_set_text (GTK_ENTRY (passedit), tempstr); | |
230 | |
231 port = gftp_protocol_default_port (current_wdata->request); | |
232 if (current_wdata->request->port != 0 && | |
233 port != current_wdata->request->port) | |
234 { | |
235 tempstr = g_strdup_printf ("%d", current_wdata->request->port); | |
236 gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (portedit)->entry), tempstr); | |
237 g_free (tempstr); | |
238 } | |
239 else | |
240 gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (portedit)->entry), ""); | |
241 | |
783 | 242 for (i=0, j=0; gftp_protocols[i].init != NULL; i++) |
616 | 243 { |
783 | 244 if (!gftp_protocols[i].shown) |
245 continue; | |
246 | |
616 | 247 if (current_wdata->request->init == gftp_protocols[i].init) |
248 { | |
249 gtk_option_menu_set_history (GTK_OPTION_MENU (optionmenu), i); | |
250 break; | |
251 } | |
783 | 252 j++; |
616 | 253 } |
1 | 254 |
616 | 255 gtk_tooltips_set_tip (GTK_TOOLTIPS(openurl_tooltip), openurl_btn, |
256 _("Disconnect from the remote server"), NULL); | |
518 | 257 } |
604 | 258 else |
259 gtk_tooltips_set_tip (GTK_TOOLTIPS(openurl_tooltip), openurl_btn, | |
260 _("Connect to the site specified in the host entry. If the host entry is blank, then a dialog is presented that will allow you to enter a URL."), NULL); | |
1 | 261 } |
262 | |
263 update_window (&window1); | |
264 update_window (&window2); | |
265 | |
788 | 266 tempwid = gtk_item_factory_get_widget (factory, "/Tools/Compare Windows"); |
1 | 267 gtk_widget_set_sensitive (tempwid, GFTP_IS_CONNECTED (window1.request) |
268 && GFTP_IS_CONNECTED (window2.request)); | |
269 } | |
270 | |
271 | |
48 | 272 static void |
273 set_menu_sensitive (gftp_window_data * wdata, char *path, int sensitive) | |
274 { | |
275 GtkWidget * tempwid; | |
276 char * pos; | |
277 | |
278 tempwid = NULL; | |
279 | |
280 if (factory != NULL) | |
281 tempwid = gtk_item_factory_get_widget (factory, path); | |
282 if (tempwid) | |
283 gtk_widget_set_sensitive (tempwid, sensitive); | |
284 | |
586 | 285 if (wdata != NULL) |
286 { | |
287 if ((pos = strchr (path + 1, '/')) == NULL) | |
288 pos = path; | |
289 | |
290 if (wdata->ifactory) | |
291 tempwid = gtk_item_factory_get_widget (wdata->ifactory, pos); | |
292 if (tempwid) | |
293 gtk_widget_set_sensitive (tempwid, sensitive); | |
294 } | |
48 | 295 } |
296 | |
297 | |
1 | 298 void |
299 update_window (gftp_window_data * wdata) | |
300 { | |
291 | 301 char *dir, *tempstr, *temp1str, *fspec, *utf8_directory; |
1 | 302 int connected, start; |
303 | |
304 connected = GFTP_IS_CONNECTED (wdata->request); | |
305 if (connected) | |
306 { | |
307 fspec = wdata->show_selected ? "Selected" : strcmp (wdata->filespec, "*") == 0 ? _("All Files") : wdata->filespec; | |
308 | |
129 | 309 if ((temp1str = wdata->request->hostname) == NULL || |
66 | 310 wdata->request->protonum == GFTP_LOCAL_NUM) |
1 | 311 temp1str = ""; |
312 tempstr = g_strconcat (temp1str, *temp1str == '\0' ? "[" : " [", | |
129 | 313 gftp_protocols[wdata->request->protonum].name, |
1 | 314 wdata->request->cached ? _("] (Cached) [") : "] [", |
315 fspec, "]", current_wdata == wdata ? "*" : "", NULL); | |
316 gtk_label_set (GTK_LABEL (wdata->hoststxt), tempstr); | |
317 g_free (tempstr); | |
318 | |
291 | 319 utf8_directory = NULL; |
129 | 320 if ((dir = wdata->request->directory) == NULL) |
1 | 321 temp1str = ""; |
322 else | |
291 | 323 { |
324 utf8_directory = gftp_string_to_utf8 (wdata->request, | |
325 wdata->request->directory); | |
326 if (utf8_directory != NULL) | |
327 temp1str = utf8_directory; | |
328 else | |
329 temp1str = dir; | |
330 } | |
1 | 331 |
332 gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (wdata->combo)->entry),temp1str); | |
291 | 333 |
334 if (utf8_directory != NULL) | |
335 g_free (utf8_directory); | |
1 | 336 } |
337 else if (wdata->hoststxt != NULL) | |
338 { | |
339 tempstr = g_strconcat (_("Not connected"), | |
340 current_wdata == wdata ? "*" : "", NULL); | |
341 gtk_label_set (GTK_LABEL (wdata->hoststxt), tempstr); | |
342 g_free (tempstr); | |
343 gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (wdata->combo)->entry), ""); | |
344 } | |
345 | |
346 if (wdata == &window1) | |
347 start = local_start; | |
348 else | |
349 start = remote_start; | |
350 | |
351 set_menu_sensitive (wdata, menus[start + 3].path, connected && | |
352 strcmp (wdata->request->url_prefix, "file") != 0); | |
353 set_menu_sensitive (wdata, menus[start + 5].path, connected); | |
354 set_menu_sensitive (wdata, menus[start + 6].path, connected); | |
355 set_menu_sensitive (wdata, menus[start + 7].path, connected); | |
356 set_menu_sensitive (wdata, menus[start + 8].path, connected); | |
357 set_menu_sensitive (wdata, menus[start + 9].path, connected); | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
358 set_menu_sensitive (wdata, menus[start + 11].path, connected); |
1 | 359 set_menu_sensitive (wdata, menus[start + 12].path, connected && |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
360 wdata->request->site != NULL); |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
361 set_menu_sensitive (wdata, menus[start + 13].path, connected && |
1 | 362 wdata->request->chdir!= NULL); |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
363 set_menu_sensitive (wdata, menus[start + 14].path, connected && |
1 | 364 wdata->request->chmod != NULL); |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
365 set_menu_sensitive (wdata, menus[start + 15].path, connected && |
1 | 366 wdata->request->mkdir != NULL); |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
367 set_menu_sensitive (wdata, menus[start + 16].path, connected && |
1 | 368 wdata->request->rename != NULL); |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
369 set_menu_sensitive (wdata, menus[start + 17].path, connected && |
1 | 370 wdata->request->rmdir != NULL && |
371 wdata->request->rmfile != NULL); | |
372 set_menu_sensitive (wdata, menus[start + 18].path, connected && | |
373 wdata->request->get_file != NULL); | |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
374 set_menu_sensitive (wdata, menus[start + 19].path, connected && |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
375 wdata->request->get_file != NULL); |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
376 set_menu_sensitive (wdata, menus[start + 20].path, connected); |
586 | 377 |
378 connected = GFTP_IS_CONNECTED (window1.request) && GFTP_IS_CONNECTED (window2.request); | |
379 | |
380 start = trans_start; | |
381 set_menu_sensitive (NULL, menus[start + 2].path, connected); | |
382 set_menu_sensitive (NULL, menus[start + 3].path, connected); | |
383 set_menu_sensitive (NULL, menus[start + 5].path, connected); | |
384 set_menu_sensitive (NULL, menus[start + 6].path, connected); | |
385 | |
386 set_menu_sensitive (NULL, menus[start + 7].path, connected); | |
387 set_menu_sensitive (NULL, menus[start + 8].path, connected); | |
388 | |
389 set_menu_sensitive (NULL, menus[start + 10].path, connected); | |
390 set_menu_sensitive (NULL, menus[start + 11].path, connected); | |
587 | 391 |
392 gtk_widget_set_sensitive (download_left_arrow, connected); | |
393 gtk_widget_set_sensitive (upload_right_arrow, connected); | |
1 | 394 } |
395 | |
396 | |
397 GtkWidget * | |
398 toolbar_pixmap (GtkWidget * widget, char *filename) | |
399 { | |
400 gftp_graphic * graphic; | |
401 GtkWidget *pix; | |
402 | |
403 if (filename == NULL || *filename == '\0') | |
404 return (NULL); | |
405 | |
406 graphic = open_xpm (widget, filename); | |
407 | |
408 if (graphic == NULL) | |
409 return (NULL); | |
410 | |
411 if ((pix = gtk_pixmap_new (graphic->pixmap, graphic->bitmap)) == NULL) | |
412 return (NULL); | |
413 | |
414 gtk_widget_show (pix); | |
415 return (pix); | |
416 } | |
417 | |
418 | |
419 gftp_graphic * | |
420 open_xpm (GtkWidget * widget, char *filename) | |
421 { | |
422 gftp_graphic * graphic; | |
423 GtkStyle *style; | |
424 char *exfile; | |
425 | |
426 if ((graphic = g_hash_table_lookup (graphic_hash_table, filename)) != NULL) | |
427 return (graphic); | |
428 | |
429 style = gtk_widget_get_style (widget); | |
430 | |
431 if ((exfile = get_xpm_path (filename, 0)) == NULL) | |
432 return (NULL); | |
433 | |
434 graphic = g_malloc0 (sizeof (*graphic)); | |
435 graphic->pixmap = gdk_pixmap_create_from_xpm (widget->window, | |
436 &graphic->bitmap, &style->bg[GTK_STATE_NORMAL], exfile); | |
437 g_free (exfile); | |
438 | |
439 if (graphic->pixmap == NULL) | |
440 { | |
441 g_free (graphic); | |
442 ftp_log (gftp_logging_error, NULL, _("Error opening file %s: %s\n"), | |
443 exfile, g_strerror (errno)); | |
444 return (NULL); | |
445 } | |
446 | |
129 | 447 graphic->filename = g_strdup (filename); |
1 | 448 g_hash_table_insert (graphic_hash_table, graphic->filename, graphic); |
449 | |
450 return (graphic); | |
451 } | |
452 | |
453 | |
454 void | |
455 gftp_free_pixmap (char *filename) | |
456 { | |
457 gftp_graphic * graphic; | |
458 | |
459 if ((graphic = g_hash_table_lookup (graphic_hash_table, filename)) == NULL) | |
460 return; | |
461 | |
45 | 462 #if GTK_MAJOR_VERSION == 1 |
1 | 463 gdk_pixmap_unref (graphic->pixmap); |
464 gdk_bitmap_unref (graphic->bitmap); | |
465 #else | |
41 | 466 g_object_unref (graphic->pixmap); |
467 g_object_unref (graphic->bitmap); | |
1 | 468 #endif |
469 | |
470 g_hash_table_remove (graphic_hash_table, filename); | |
471 g_free (graphic->filename); | |
472 g_free (graphic); | |
473 } | |
474 | |
475 | |
476 void | |
477 gftp_get_pixmap (GtkWidget * widget, char *filename, GdkPixmap ** pix, | |
478 GdkBitmap ** bitmap) | |
479 { | |
480 gftp_graphic * graphic; | |
481 | |
482 if (filename == NULL || *filename == '\0') | |
483 { | |
484 *pix = NULL; | |
485 *bitmap = NULL; | |
486 return; | |
487 } | |
488 | |
489 if ((graphic = g_hash_table_lookup (graphic_hash_table, filename)) == NULL) | |
490 graphic = open_xpm (widget, filename); | |
491 | |
492 if (graphic == NULL) | |
493 { | |
494 *pix = NULL; | |
495 *bitmap = NULL; | |
496 return; | |
497 } | |
498 | |
499 *pix = graphic->pixmap; | |
500 *bitmap = graphic->bitmap; | |
501 } | |
502 | |
503 | |
504 int | |
767 | 505 check_status (char *name, gftp_window_data *wdata, |
506 unsigned int check_other_stop, unsigned int only_one, | |
507 unsigned int at_least_one, unsigned int func) | |
1 | 508 { |
509 gftp_window_data * owdata; | |
510 | |
511 owdata = wdata == &window1 ? &window2 : &window1; | |
512 | |
513 if (wdata->request->stopable) | |
514 { | |
677 | 515 ftp_log (gftp_logging_error, NULL, |
1 | 516 _("%s: Please hit the stop button first to do anything else\n"), |
517 name); | |
518 return (0); | |
519 } | |
520 | |
521 if (check_other_stop && owdata->request->stopable) | |
522 { | |
677 | 523 ftp_log (gftp_logging_error, NULL, |
1 | 524 _("%s: Please hit the stop button first to do anything else\n"), |
525 name); | |
526 return (0); | |
527 } | |
528 | |
529 if (!GFTP_IS_CONNECTED (wdata->request)) | |
530 { | |
677 | 531 ftp_log (gftp_logging_error, NULL, |
1 | 532 _("%s: Not connected to a remote site\n"), name); |
533 return (0); | |
534 } | |
535 | |
536 if (!func) | |
537 { | |
677 | 538 ftp_log (gftp_logging_error, NULL, |
1 | 539 _("%s: This feature is not available using this protocol\n"), |
540 name); | |
541 return (0); | |
542 } | |
543 | |
544 if (only_one && !IS_ONE_SELECTED (wdata)) | |
545 { | |
677 | 546 ftp_log (gftp_logging_error, NULL, |
1 | 547 _("%s: You must only have one item selected\n"), name); |
548 return (0); | |
549 } | |
550 | |
551 if (at_least_one && !only_one && IS_NONE_SELECTED (wdata)) | |
552 { | |
677 | 553 ftp_log (gftp_logging_error, NULL, |
1 | 554 _("%s: You must have at least one item selected\n"), name); |
555 return (0); | |
556 } | |
557 return (1); | |
558 } | |
559 | |
19 | 560 |
7 | 561 static gchar * |
168 | 562 gftp_item_factory_translate (const char *path, gpointer func_data) |
7 | 563 { |
564 const gchar *strip_prefix = func_data; | |
565 const char *result; | |
566 | |
567 if (strip_prefix) | |
568 { | |
569 char *tmp_path = g_strconcat (strip_prefix, path, NULL); | |
570 result = gettext (tmp_path); | |
571 if (result == tmp_path) | |
168 | 572 result = path; |
7 | 573 g_free (tmp_path); |
574 } | |
575 else | |
576 result = gettext (path); | |
577 | |
578 return (char *)result; | |
579 } | |
580 | |
19 | 581 |
7 | 582 GtkItemFactory * |
19 | 583 item_factory_new (GtkType container_type, const char *path, |
584 GtkAccelGroup *accel_group, const char *strip_prefix) | |
7 | 585 { |
586 GtkItemFactory *result = gtk_item_factory_new (container_type, path, accel_group); | |
201 | 587 gchar *strip_prefix_dup = g_strdup (strip_prefix); |
7 | 588 |
589 gtk_item_factory_set_translate_func (result, gftp_item_factory_translate, | |
590 strip_prefix_dup, NULL); | |
591 | |
592 if (strip_prefix_dup) | |
593 gtk_object_set_data_full (GTK_OBJECT (result), "gftp-strip-prefix", | |
594 strip_prefix_dup, (GDestroyNotify)g_free); | |
595 | |
596 return result; | |
597 } | |
1 | 598 |
19 | 599 |
1 | 600 void |
767 | 601 create_item_factory (GtkItemFactory * ifactory, gint n_entries, |
602 GtkItemFactoryEntry * entries, gpointer callback_data) | |
1 | 603 { |
518 | 604 const char *strip_prefix; |
605 size_t strip_prefix_len; | |
767 | 606 int i; |
7 | 607 |
518 | 608 strip_prefix = gtk_object_get_data (GTK_OBJECT (ifactory), "gftp-strip-prefix"); |
7 | 609 if (strip_prefix) |
610 strip_prefix_len = strlen (strip_prefix); | |
518 | 611 else |
612 strip_prefix_len = 0; | |
1 | 613 |
614 for (i = 0; i < n_entries; i++) | |
615 { | |
7 | 616 GtkItemFactoryEntry dummy_item = entries[i]; |
617 if (strip_prefix && strncmp (entries[i].path, strip_prefix, strip_prefix_len) == 0) | |
618 dummy_item.path += strip_prefix_len; | |
619 | |
1 | 620 gtk_item_factory_create_item (ifactory, &dummy_item, callback_data, 1); |
621 } | |
622 } | |
623 | |
624 void | |
625 add_history (GtkWidget * widget, GList ** history, unsigned int *histlen, | |
626 const char *str) | |
627 { | |
628 GList *node, *delnode; | |
629 char *tempstr; | |
630 int i; | |
631 | |
632 if (str == NULL || *str == '\0') | |
633 return; | |
634 | |
635 for (node = *history; node != NULL; node = node->next) | |
636 { | |
637 if (strcmp ((char *) node->data, str) == 0) | |
638 break; | |
639 } | |
640 | |
641 if (node == NULL) | |
642 { | |
643 if (*histlen >= MAX_HIST_LEN) | |
644 { | |
645 node = *history; | |
646 for (i = 1; i < MAX_HIST_LEN; i++) | |
647 node = node->next; | |
648 node->prev->next = NULL; | |
649 node->prev = NULL; | |
650 delnode = node; | |
651 while (delnode != NULL) | |
652 { | |
653 if (delnode->data) | |
654 g_free (delnode->data); | |
655 delnode = delnode->next; | |
656 } | |
657 g_list_free (node); | |
658 } | |
129 | 659 tempstr = g_strdup (str); |
1 | 660 *history = g_list_prepend (*history, tempstr); |
661 ++*histlen; | |
662 } | |
663 else if (node->prev != NULL) | |
664 { | |
665 node->prev->next = node->next; | |
666 if (node->next != NULL) | |
667 node->next->prev = node->prev; | |
668 node->prev = NULL; | |
669 node->next = *history; | |
670 if (node->next != NULL) | |
671 node->next->prev = node; | |
672 *history = node; | |
673 } | |
674 gtk_combo_set_popdown_strings (GTK_COMBO (widget), *history); | |
675 } | |
676 | |
677 | |
678 int | |
679 check_reconnect (gftp_window_data *wdata) | |
680 { | |
169 | 681 return (wdata->request->cached && wdata->request->datafd < 0 && |
66 | 682 !wdata->request->always_connected && |
767 | 683 !ftp_connect (wdata, wdata->request) ? -1 : 0); |
1 | 684 } |
685 | |
686 | |
687 void | |
688 add_file_listbox (gftp_window_data * wdata, gftp_file * fle) | |
689 { | |
499 | 690 char *add_data[7] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; |
691 char *tempstr, *str, *pos, *attribs; | |
129 | 692 gftp_config_list_vars * tmplistvar; |
499 | 693 gftp_file_extensions * tempext; |
326 | 694 intptr_t show_hidden_files; |
1 | 695 GdkBitmap * bitmap; |
696 GList * templist; | |
697 GdkPixmap * pix; | |
499 | 698 int clist_num; |
1 | 699 size_t stlen; |
700 | |
129 | 701 gftp_lookup_request_option (wdata->request, "show_hidden_files", |
702 &show_hidden_files); | |
703 | |
1 | 704 if (wdata->show_selected) |
705 { | |
706 fle->shown = fle->was_sel; | |
707 if (!fle->shown) | |
708 return; | |
709 } | |
710 else if ((!show_hidden_files && *fle->file == '.' && | |
711 strcmp (fle->file, "..") != 0) || | |
712 !gftp_match_filespec (fle->file, wdata->filespec)) | |
713 { | |
714 fle->shown = 0; | |
715 fle->was_sel = 0; | |
716 return; | |
717 } | |
718 else | |
719 fle->shown = 1; | |
720 | |
721 clist_num = gtk_clist_append (GTK_CLIST (wdata->listbox), add_data); | |
722 | |
723 if (fle->was_sel) | |
724 { | |
725 fle->was_sel = 0; | |
726 gtk_clist_select_row (GTK_CLIST (wdata->listbox), clist_num, 0); | |
727 } | |
728 | |
729 pix = NULL; | |
730 bitmap = NULL; | |
731 if (strcmp (fle->file, "..") == 0) | |
732 gftp_get_pixmap (wdata->listbox, "dotdot.xpm", &pix, &bitmap); | |
499 | 733 else if (S_ISLNK (fle->st_mode) && S_ISDIR (fle->st_mode)) |
1 | 734 gftp_get_pixmap (wdata->listbox, "linkdir.xpm", &pix, &bitmap); |
499 | 735 else if (S_ISLNK (fle->st_mode)) |
1 | 736 gftp_get_pixmap (wdata->listbox, "linkfile.xpm", &pix, &bitmap); |
500 | 737 else if (S_ISDIR (fle->st_mode)) |
1 | 738 gftp_get_pixmap (wdata->listbox, "dir.xpm", &pix, &bitmap); |
499 | 739 else if ((fle->st_mode & S_IXUSR) || |
740 (fle->st_mode & S_IXGRP) || | |
741 (fle->st_mode & S_IXOTH)) | |
1 | 742 gftp_get_pixmap (wdata->listbox, "exe.xpm", &pix, &bitmap); |
743 else | |
744 { | |
745 stlen = strlen (fle->file); | |
129 | 746 gftp_lookup_global_option ("ext", &tmplistvar); |
747 templist = tmplistvar->list; | |
1 | 748 while (templist != NULL) |
749 { | |
750 tempext = templist->data; | |
751 if (stlen >= tempext->stlen && | |
752 strcmp (&fle->file[stlen - tempext->stlen], tempext->ext) == 0) | |
753 { | |
754 gftp_get_pixmap (wdata->listbox, tempext->filename, &pix, | |
755 &bitmap); | |
756 break; | |
757 } | |
758 templist = templist->next; | |
759 } | |
760 } | |
761 | |
762 if (pix == NULL && bitmap == NULL) | |
763 gftp_get_pixmap (wdata->listbox, "doc.xpm", &pix, &bitmap); | |
764 | |
765 gtk_clist_set_pixmap (GTK_CLIST (wdata->listbox), clist_num, 0, pix, bitmap); | |
766 | |
184 | 767 if (fle->utf8_file) |
768 gtk_clist_set_text (GTK_CLIST (wdata->listbox), clist_num, 1, | |
769 fle->utf8_file); | |
770 else if (fle->file) | |
1 | 771 gtk_clist_set_text (GTK_CLIST (wdata->listbox), clist_num, 1, fle->file); |
772 | |
499 | 773 if (GFTP_IS_SPECIAL_DEVICE (fle->st_mode)) |
48 | 774 tempstr = g_strdup_printf ("%d, %d", major (fle->size), |
775 minor (fle->size)); | |
1 | 776 else |
777 tempstr = insert_commas (fle->size, NULL, 0); | |
778 | |
779 gtk_clist_set_text (GTK_CLIST (wdata->listbox), clist_num, 2, tempstr); | |
780 g_free (tempstr); | |
781 | |
782 if (fle->user) | |
783 gtk_clist_set_text (GTK_CLIST (wdata->listbox), clist_num, 3, fle->user); | |
784 if (fle->group) | |
785 gtk_clist_set_text (GTK_CLIST (wdata->listbox), clist_num, 4, fle->group); | |
786 if ((str = ctime (&fle->datetime))) | |
787 { | |
788 if ((pos = strchr (str, '\n')) != NULL) | |
789 *pos = '\0'; | |
790 gtk_clist_set_text (GTK_CLIST (wdata->listbox), clist_num, 5, str); | |
791 } | |
499 | 792 |
793 attribs = gftp_convert_attributes_from_mode_t (fle->st_mode); | |
794 gtk_clist_set_text (GTK_CLIST (wdata->listbox), clist_num, 6, attribs); | |
795 g_free (attribs); | |
1 | 796 |
797 } | |
798 | |
799 | |
425 | 800 void |
801 destroy_dialog (gftp_dialog_data * ddata) | |
802 { | |
803 if (ddata->dialog != NULL) | |
804 { | |
805 gtk_widget_destroy (ddata->dialog); | |
806 ddata->dialog = NULL; | |
807 } | |
808 } | |
809 | |
810 | |
45 | 811 #if GTK_MAJOR_VERSION == 1 |
21 | 812 static void |
813 ok_dialog_response (GtkWidget * widget, gftp_dialog_data * ddata) | |
814 { | |
815 if (ddata->edit == NULL) | |
198 | 816 { |
817 gtk_widget_destroy (ddata->dialog); | |
818 ddata->dialog = NULL; | |
819 ddata->checkbox = NULL; | |
820 } | |
21 | 821 |
822 if (ddata->yesfunc != NULL) | |
823 ddata->yesfunc (ddata->yespointer, ddata); | |
824 | |
425 | 825 if (ddata->edit != NULL && |
826 ddata->dialog != NULL) | |
21 | 827 gtk_widget_destroy (ddata->dialog); |
828 | |
829 g_free (ddata); | |
830 } | |
831 | |
832 | |
833 static void | |
834 cancel_dialog_response (GtkWidget * widget, gftp_dialog_data * ddata) | |
835 { | |
836 if (ddata->edit == NULL) | |
198 | 837 { |
838 gtk_widget_destroy (ddata->dialog); | |
839 ddata->dialog = NULL; | |
840 ddata->checkbox = NULL; | |
841 } | |
21 | 842 |
843 if (ddata->nofunc != NULL) | |
844 ddata->nofunc (ddata->nopointer, ddata); | |
845 | |
425 | 846 if (ddata->edit != NULL && |
847 ddata->dialog != NULL) | |
21 | 848 gtk_widget_destroy (ddata->dialog); |
849 | |
850 g_free (ddata); | |
851 } | |
852 #else | |
19 | 853 static void |
854 dialog_response (GtkWidget * widget, gint response, gftp_dialog_data * ddata) | |
855 { | |
856 if (ddata->edit == NULL) | |
198 | 857 { |
858 gtk_widget_destroy (ddata->dialog); | |
859 ddata->dialog = NULL; | |
860 ddata->checkbox = NULL; | |
861 } | |
19 | 862 |
863 switch (response) | |
864 { | |
865 case GTK_RESPONSE_YES: | |
866 if (ddata->yesfunc != NULL) | |
867 ddata->yesfunc (ddata->yespointer, ddata); | |
868 break; | |
869 default: | |
870 if (ddata->nofunc != NULL) | |
871 ddata->nofunc (ddata->nopointer, ddata); | |
872 break; | |
873 } | |
874 | |
425 | 875 if (ddata->edit != NULL && |
876 ddata->dialog != NULL) | |
72 | 877 gtk_widget_destroy (ddata->dialog); |
19 | 878 |
879 g_free (ddata); | |
880 } | |
881 #endif | |
882 | |
883 | |
72 | 884 static gint |
885 dialog_keypress (GtkWidget * widget, GdkEventKey * event, gpointer data) | |
886 { | |
887 if (event->type != GDK_KEY_PRESS) | |
888 return (FALSE); | |
889 | |
890 if (event->keyval == GDK_KP_Enter || event->keyval == GDK_Return) | |
891 { | |
892 #if GTK_MAJOR_VERSION == 1 | |
893 ok_dialog_response (widget, data); | |
894 #else | |
895 dialog_response (widget, GTK_RESPONSE_YES, data); | |
896 #endif | |
897 return (TRUE); | |
898 } | |
899 else if (event->keyval == GDK_Escape) | |
900 { | |
901 #if GTK_MAJOR_VERSION == 1 | |
902 cancel_dialog_response (widget, data); | |
903 #else | |
904 dialog_response (widget, GTK_RESPONSE_NO, data); | |
905 #endif | |
906 return (TRUE); | |
907 } | |
908 | |
909 return (FALSE); | |
910 } | |
911 | |
912 | |
1 | 913 void |
19 | 914 MakeEditDialog (char *diagtxt, char *infotxt, char *deftext, int passwd_item, |
915 char *checktext, | |
916 gftp_dialog_button okbutton, void (*okfunc) (), void *okptr, | |
917 void (*cancelfunc) (), void *cancelptr) | |
1 | 918 { |
19 | 919 GtkWidget * tempwid, * dialog; |
920 gftp_dialog_data * ddata; | |
921 const gchar * yes_text; | |
922 | |
659 | 923 ddata = g_malloc0 (sizeof (*ddata)); |
19 | 924 ddata->yesfunc = okfunc; |
925 ddata->yespointer = okptr; | |
926 ddata->nofunc = cancelfunc; | |
927 ddata->nopointer = cancelptr; | |
1 | 928 |
45 | 929 #if GTK_MAJOR_VERSION == 1 |
19 | 930 dialog = gtk_dialog_new (); |
931 gtk_window_set_title (GTK_WINDOW (dialog), diagtxt); | |
932 gtk_grab_add (dialog); | |
1 | 933 gtk_container_border_width (GTK_CONTAINER |
19 | 934 (GTK_DIALOG (dialog)->action_area), 5); |
935 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 15); | |
936 gtk_box_set_homogeneous (GTK_BOX (GTK_DIALOG (dialog)->action_area), TRUE); | |
937 #else | |
938 switch (okbutton) | |
939 { | |
341 | 940 case gftp_dialog_button_ok: |
941 yes_text = GTK_STOCK_OK; | |
942 break; | |
19 | 943 case gftp_dialog_button_create: |
944 yes_text = GTK_STOCK_ADD; | |
945 break; | |
946 case gftp_dialog_button_change: | |
947 yes_text = _("Change"); | |
948 break; | |
949 case gftp_dialog_button_connect: | |
950 yes_text = _("Connect"); | |
951 break; | |
952 case gftp_dialog_button_rename: | |
953 yes_text = _("Rename"); | |
954 break; | |
955 default: | |
956 yes_text = GTK_STOCK_MISSING_IMAGE; | |
957 break; | |
958 } | |
1 | 959 |
19 | 960 dialog = gtk_dialog_new_with_buttons (_(diagtxt), NULL, 0, |
961 yes_text, | |
962 GTK_RESPONSE_YES, | |
963 GTK_STOCK_CANCEL, | |
964 GTK_RESPONSE_NO, | |
965 NULL); | |
966 #endif | |
967 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), 10); | |
968 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 5); | |
969 gtk_window_set_wmclass (GTK_WINDOW(dialog), "edit", "gFTP"); | |
970 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE); | |
971 gtk_widget_realize (dialog); | |
1 | 972 |
19 | 973 if (gftp_icon != NULL) |
974 { | |
975 gdk_window_set_icon (dialog->window, NULL, gftp_icon->pixmap, | |
976 gftp_icon->bitmap); | |
168 | 977 gdk_window_set_icon_name (dialog->window, gftp_version); |
19 | 978 } |
979 | |
980 ddata->dialog = dialog; | |
981 | |
1 | 982 tempwid = gtk_label_new (infotxt); |
19 | 983 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), tempwid, TRUE, |
1 | 984 TRUE, 0); |
985 gtk_widget_show (tempwid); | |
986 | |
19 | 987 ddata->edit = gtk_entry_new (); |
72 | 988 gtk_signal_connect (GTK_OBJECT (ddata->edit), "key_press_event", |
989 GTK_SIGNAL_FUNC (dialog_keypress), (gpointer) ddata); | |
990 | |
19 | 991 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), ddata->edit, TRUE, |
1 | 992 TRUE, 0); |
19 | 993 gtk_widget_grab_focus (ddata->edit); |
994 gtk_entry_set_visibility (GTK_ENTRY (ddata->edit), passwd_item); | |
1 | 995 |
996 if (deftext != NULL) | |
997 { | |
19 | 998 gtk_entry_set_text (GTK_ENTRY (ddata->edit), deftext); |
999 gtk_entry_select_region (GTK_ENTRY (ddata->edit), 0, strlen (deftext)); | |
1 | 1000 } |
19 | 1001 gtk_widget_show (ddata->edit); |
1 | 1002 |
19 | 1003 if (checktext != NULL) |
1 | 1004 { |
19 | 1005 ddata->checkbox = gtk_check_button_new_with_label (checktext); |
1006 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), | |
1007 ddata->checkbox, TRUE, TRUE, 0); | |
1008 gtk_widget_show (ddata->checkbox); | |
1 | 1009 } |
1010 | |
45 | 1011 #if GTK_MAJOR_VERSION == 1 |
21 | 1012 switch (okbutton) |
1013 { | |
341 | 1014 case gftp_dialog_button_ok: |
401 | 1015 yes_text = _("OK"); |
341 | 1016 break; |
21 | 1017 case gftp_dialog_button_create: |
1018 yes_text = _("Add"); | |
1019 break; | |
1020 case gftp_dialog_button_change: | |
1021 yes_text = _("Change"); | |
1022 break; | |
1023 case gftp_dialog_button_connect: | |
1024 yes_text = _("Connect"); | |
1025 break; | |
1026 case gftp_dialog_button_rename: | |
1027 yes_text = _("Rename"); | |
1028 break; | |
1029 default: | |
1030 yes_text = ""; | |
1031 break; | |
1032 } | |
1033 | |
1034 tempwid = gtk_button_new_with_label (yes_text); | |
1 | 1035 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); |
19 | 1036 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid, |
1 | 1037 TRUE, TRUE, 0); |
21 | 1038 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", |
1039 GTK_SIGNAL_FUNC (ok_dialog_response), | |
1040 ddata); | |
1 | 1041 gtk_widget_grab_default (tempwid); |
1042 gtk_widget_show (tempwid); | |
1043 | |
21 | 1044 tempwid = gtk_button_new_with_label (_("Cancel")); |
1 | 1045 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); |
19 | 1046 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid, |
1 | 1047 TRUE, TRUE, 0); |
21 | 1048 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", |
1049 GTK_SIGNAL_FUNC (cancel_dialog_response), | |
1050 ddata); | |
1 | 1051 gtk_widget_show (tempwid); |
19 | 1052 #else |
1053 g_signal_connect (GTK_OBJECT (dialog), "response", | |
1054 G_CALLBACK (dialog_response), ddata); | |
1055 #endif | |
1 | 1056 |
19 | 1057 gtk_widget_show (dialog); |
1 | 1058 } |
1059 | |
1060 | |
1061 void | |
19 | 1062 MakeYesNoDialog (char *diagtxt, char *infotxt, |
1063 void (*yesfunc) (), gpointer yespointer, | |
1064 void (*nofunc) (), gpointer nopointer) | |
1 | 1065 { |
19 | 1066 GtkWidget * text, * dialog; |
1067 gftp_dialog_data * ddata; | |
45 | 1068 #if GTK_MAJOR_VERSION == 1 |
21 | 1069 GtkWidget * tempwid; |
19 | 1070 #endif |
1 | 1071 |
659 | 1072 ddata = g_malloc0 (sizeof (*ddata)); |
21 | 1073 ddata->yesfunc = yesfunc; |
1074 ddata->yespointer = yespointer; | |
1075 ddata->nofunc = nofunc; | |
1076 ddata->nopointer = nopointer; | |
1077 | |
45 | 1078 #if GTK_MAJOR_VERSION == 1 |
1 | 1079 dialog = gtk_dialog_new (); |
1080 gtk_grab_add (dialog); | |
1081 gtk_window_set_title (GTK_WINDOW (dialog), diagtxt); | |
1082 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), | |
1083 5); | |
1084 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 15); | |
1085 gtk_box_set_homogeneous (GTK_BOX (GTK_DIALOG (dialog)->action_area), TRUE); | |
19 | 1086 #else |
1087 dialog = gtk_dialog_new_with_buttons (_(diagtxt), NULL, 0, | |
1088 GTK_STOCK_YES, | |
1089 GTK_RESPONSE_YES, | |
1090 GTK_STOCK_NO, | |
1091 GTK_RESPONSE_NO, | |
1092 NULL); | |
1093 #endif | |
1094 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), 10); | |
1095 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 5); | |
1 | 1096 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE); |
19 | 1097 gtk_window_set_wmclass (GTK_WINDOW(dialog), "yndiag", "gFTP"); |
1098 gtk_widget_realize (dialog); | |
1099 | |
1100 if (gftp_icon != NULL) | |
1101 { | |
1102 gdk_window_set_icon (dialog->window, NULL, gftp_icon->pixmap, | |
1103 gftp_icon->bitmap); | |
168 | 1104 gdk_window_set_icon_name (dialog->window, gftp_version); |
19 | 1105 } |
1 | 1106 |
21 | 1107 ddata->dialog = dialog; |
1108 | |
1 | 1109 text = gtk_label_new (infotxt); |
1110 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), text, TRUE, TRUE, 0); | |
1111 gtk_widget_show (text); | |
1112 | |
45 | 1113 #if GTK_MAJOR_VERSION == 1 |
19 | 1114 tempwid = gtk_button_new_with_label (_(" Yes ")); |
1115 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); | |
1116 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid, | |
1117 FALSE, FALSE, 0); | |
21 | 1118 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", |
72 | 1119 GTK_SIGNAL_FUNC (ok_dialog_response), ddata); |
1120 | |
19 | 1121 gtk_widget_grab_default (tempwid); |
1122 gtk_widget_show (tempwid); | |
1 | 1123 |
19 | 1124 tempwid = gtk_button_new_with_label (_(" No ")); |
1125 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); | |
1126 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid, | |
1127 FALSE, FALSE, 0); | |
21 | 1128 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", |
72 | 1129 GTK_SIGNAL_FUNC (cancel_dialog_response), ddata); |
19 | 1130 gtk_widget_show (tempwid); |
1131 | |
1132 #else | |
1133 g_signal_connect (GTK_OBJECT (dialog), "response", | |
1134 G_CALLBACK (dialog_response), ddata); | |
1135 #endif | |
1 | 1136 |
1137 gtk_widget_show (dialog); | |
1138 } | |
1139 | |
1140 | |
48 | 1141 static gint |
1142 delete_event (GtkWidget * widget, GdkEvent * event, gpointer data) | |
1143 { | |
1144 return (TRUE); | |
1145 } | |
1146 | |
1147 | |
1148 static void | |
1149 trans_stop_button (GtkWidget * widget, gpointer data) | |
1150 { | |
1151 gftp_transfer * transfer; | |
1152 | |
1153 transfer = data; | |
1154 pthread_kill (((gftp_window_data *) transfer->fromwdata)->tid, SIGINT); | |
1155 } | |
1156 | |
1157 | |
1 | 1158 void |
1159 update_directory_download_progress (gftp_transfer * transfer) | |
1160 { | |
1161 static GtkWidget * dialog = NULL, * textwid, * stopwid; | |
1162 char tempstr[255]; | |
1163 GtkWidget * vbox; | |
1164 | |
1165 if (transfer->numfiles < 0 || transfer->numdirs < 0) | |
1166 { | |
1167 if (dialog != NULL) | |
1168 gtk_widget_destroy (dialog); | |
1169 dialog = NULL; | |
1170 return; | |
1171 } | |
1172 | |
1173 if (dialog == NULL) | |
1174 { | |
303 | 1175 dialog = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
424 | 1176 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); |
303 | 1177 #if GTK_MAJOR_VERSION > 1 |
1178 gtk_window_set_decorated (GTK_WINDOW (dialog), 0); | |
1179 #endif | |
1 | 1180 gtk_grab_add (dialog); |
1181 gtk_signal_connect (GTK_OBJECT (dialog), "delete_event", | |
1182 GTK_SIGNAL_FUNC (delete_event), NULL); | |
1183 gtk_window_set_title (GTK_WINDOW (dialog), | |
1184 _("Getting directory listings")); | |
1185 gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE); | |
1186 gtk_window_set_wmclass (GTK_WINDOW(dialog), "dirlist", "gFTP"); | |
1187 | |
1188 vbox = gtk_vbox_new (FALSE, 5); | |
1189 gtk_container_border_width (GTK_CONTAINER (vbox), 10); | |
1190 gtk_container_add (GTK_CONTAINER (dialog), vbox); | |
1191 gtk_widget_show (vbox); | |
1192 | |
1193 textwid = gtk_label_new (NULL); | |
1194 gtk_box_pack_start (GTK_BOX (vbox), textwid, TRUE, TRUE, 0); | |
1195 gtk_widget_show (textwid); | |
1196 | |
1197 statuswid = gtk_progress_bar_new (); | |
1198 gtk_progress_set_activity_mode (GTK_PROGRESS (statuswid), 1); | |
1199 gtk_progress_bar_set_activity_step (GTK_PROGRESS_BAR (statuswid), 3); | |
1200 gtk_progress_bar_set_activity_blocks (GTK_PROGRESS_BAR (statuswid), 5); | |
1201 gtk_box_pack_start (GTK_BOX (vbox), statuswid, TRUE, TRUE, 0); | |
1202 gtk_widget_show (statuswid); | |
1203 | |
1204 stopwid = gtk_button_new_with_label (_(" Stop ")); | |
1205 gtk_signal_connect (GTK_OBJECT (stopwid), "clicked", | |
1206 GTK_SIGNAL_FUNC (trans_stop_button), transfer); | |
1207 gtk_box_pack_start (GTK_BOX (vbox), stopwid, TRUE, TRUE, 0); | |
1208 gtk_widget_show (stopwid); | |
1209 | |
1210 gtk_widget_show (dialog); | |
1211 } | |
1212 | |
1213 g_snprintf (tempstr, sizeof (tempstr), | |
1214 _("Received %ld directories\nand %ld files"), | |
1215 transfer->numdirs, transfer->numfiles); | |
1216 gtk_label_set_text (GTK_LABEL (textwid), tempstr); | |
1217 } | |
1218 | |
1219 | |
1220 int | |
1221 progress_timeout (gpointer data) | |
1222 { | |
1223 gftp_transfer * tdata; | |
1224 double val; | |
1225 | |
1226 tdata = data; | |
1227 | |
1228 update_directory_download_progress (tdata); | |
1229 | |
1230 val = gtk_progress_get_value (GTK_PROGRESS (statuswid)); | |
1231 if (val >= 1.0) | |
517 | 1232 val = 0.0; |
1 | 1233 else |
1234 val += 0.10; | |
1235 gtk_progress_bar_update (GTK_PROGRESS_BAR (statuswid), val); | |
1236 | |
1237 return (1); | |
1238 } | |
1239 | |
1240 | |
1241 void | |
1242 display_cached_logs (void) | |
1243 { | |
1244 gftp_log * templog; | |
1245 GList * templist; | |
1246 | |
1247 pthread_mutex_lock (&log_mutex); | |
129 | 1248 templist = gftp_file_transfer_logs; |
1 | 1249 while (templist != NULL) |
1250 { | |
1251 templog = (gftp_log *) templist->data; | |
186 | 1252 ftp_log (templog->type, NULL, "%s", templog->msg); |
1 | 1253 g_free (templog->msg); |
1254 g_free (templog); | |
1255 templist->data = NULL; | |
1256 templist = templist->next; | |
1257 } | |
129 | 1258 g_list_free (gftp_file_transfer_logs); |
1259 gftp_file_transfer_logs = NULL; | |
1 | 1260 pthread_mutex_unlock (&log_mutex); |
1261 } | |
1262 | |
42 | 1263 |
201 | 1264 char * |
1265 get_xpm_path (char *filename, int quit_on_err) | |
1266 { | |
483 | 1267 char *tempstr, *exfile, *share_dir; |
201 | 1268 |
1269 tempstr = g_strconcat (BASE_CONF_DIR, "/", filename, NULL); | |
555 | 1270 exfile = gftp_expand_path (NULL, tempstr); |
201 | 1271 g_free (tempstr); |
1272 if (access (exfile, F_OK) != 0) | |
1273 { | |
1274 g_free (exfile); | |
483 | 1275 share_dir = gftp_get_share_dir (); |
1276 | |
1277 tempstr = g_strconcat (share_dir, "/", filename, NULL); | |
555 | 1278 exfile = gftp_expand_path (NULL, tempstr); |
201 | 1279 g_free (tempstr); |
1280 if (access (exfile, F_OK) != 0) | |
1281 { | |
1282 g_free (exfile); | |
1283 exfile = g_strconcat ("/usr/share/icons/", filename, NULL); | |
1284 if (access (exfile, F_OK) != 0) | |
1285 { | |
1286 g_free (exfile); | |
1287 if (!quit_on_err) | |
1288 return (NULL); | |
1289 | |
1290 printf (_("gFTP Error: Cannot find file %s in %s or %s\n"), | |
483 | 1291 filename, share_dir, BASE_CONF_DIR); |
767 | 1292 exit (EXIT_FAILURE); |
201 | 1293 } |
1294 } | |
1295 } | |
1296 return (exfile); | |
1297 } | |
1298 |