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