X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=driver%2Fdemo-Gtk.c;h=32440ba8013598a5c41327153d588b6df0d8f6fc;hb=3f9592851ce4ed76a9979bfdd6ec7dc5c457e183;hp=26c69db6791e52d827c1d40065c7ea31076d177a;hpb=a94197e76a5dea5cb60542840809d6c20d0abbf3;p=xscreensaver diff --git a/driver/demo-Gtk.c b/driver/demo-Gtk.c index 26c69db6..32440ba8 100644 --- a/driver/demo-Gtk.c +++ b/driver/demo-Gtk.c @@ -22,6 +22,10 @@ # include #endif +#ifdef ENABLE_NLS +# include +#endif /* ENABLE_NLS */ + #ifndef VMS # include /* for getpwuid() */ #else /* VMS */ @@ -504,13 +508,13 @@ about_menu_cb (GtkMenuItem *menuitem, gpointer user_data) char *vers = strdup (screensaver_id + 4); char *s; char copy[1024]; - char *desc = "For updates, check http://www.jwz.org/xscreensaver/"; + char *desc = _("For updates, check http://www.jwz.org/xscreensaver/"); s = strchr (vers, ','); *s = 0; s += 2; - sprintf(copy, "Copyright \251 1991-2002 %s", s); + sprintf(copy, _("Copyright \251 1991-2002 %s"), s); sprintf (msg, "%s\n\n%s", copy, desc); @@ -580,7 +584,7 @@ about_menu_cb (GtkMenuItem *menuitem, gpointer user_data) gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), hb, TRUE, TRUE, 0); - ok = gtk_button_new_with_label ("OK"); + ok = gtk_button_new_with_label (_("OK")); gtk_container_add (GTK_CONTAINER (hb), ok); gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); @@ -617,8 +621,8 @@ doc_menu_cb (GtkMenuItem *menuitem, gpointer user_data) if (!p->help_url || !*p->help_url) { warning_dialog (s->toplevel_widget, - "Error:\n\n" - "No Help URL has been specified.\n", False, 100); + _("Error:\n\n" + "No Help URL has been specified.\n"), False, 100); return; } @@ -703,13 +707,13 @@ await_xscreensaver (state *s) Bool root_p = (geteuid () == 0); strcpy (buf, - "Error:\n\n" - "The xscreensaver daemon did not start up properly.\n" - "\n"); + _("Error:\n\n" + "The xscreensaver daemon did not start up properly.\n" + "\n")); if (root_p) strcat (buf, - "You are running as root. This usually means that xscreensaver\n" + _("You are running as root. This usually means that xscreensaver\n" "was unable to contact your X server because access control is\n" "turned on. Try running this command:\n" "\n" @@ -723,9 +727,9 @@ await_xscreensaver (state *s) "manual and FAQ for more information.\n" "\n" "You shouldn't run X as root. Instead, you should log in as a\n" - "normal user, and `su' as necessary."); + "normal user, and `su' as necessary.")); else - strcat (buf, "Please check your $PATH and permissions."); + strcat (buf, _("Please check your $PATH and permissions.")); warning_dialog (s->toplevel_widget, buf, False, 1); } @@ -760,12 +764,12 @@ demo_write_init_file (state *s, saver_preferences *p) const char *f = init_file_name(); if (!f || !*f) warning_dialog (s->toplevel_widget, - "Error:\n\nCouldn't determine init file name!\n", + _("Error:\n\nCouldn't determine init file name!\n"), False, 100); else { char *b = (char *) malloc (strlen(f) + 1024); - sprintf (b, "Error:\n\nCouldn't write %s\n", f); + sprintf (b, _("Error:\n\nCouldn't write %s\n"), f); warning_dialog (s->toplevel_widget, b, False, 100); free (b); } @@ -824,7 +828,7 @@ manual_cb (GtkButton *button, gpointer user_data) else { warning_dialog (GTK_WIDGET (button), - "Error:\n\nno `manualCommand' resource set.", + _("Error:\n\nno `manualCommand' resource set."), False, 100); } @@ -994,8 +998,8 @@ hack_time_text (state *s, const char *line, Time *store, Bool sec_p) { char b[255]; sprintf (b, - "Error:\n\n" - "Unparsable time format: \"%s\"\n", + _("Error:\n\n" + "Unparsable time format: \"%s\"\n"), line); warning_dialog (s->toplevel_widget, b, False, 100); } @@ -1311,7 +1315,7 @@ flush_popup_changes_and_save (state *s) { gdk_beep (); /* unparsable */ visual = ""; - gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (vis)->entry), "Any"); + gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (vis)->entry), _("Any")); } changed = flush_changes (s, list_elt, -1, command, visual); @@ -1521,7 +1525,7 @@ store_image_directory (GtkWidget *button, gpointer user_data) if (!directory_p (path)) { char b[255]; - sprintf (b, "Error:\n\n" "Directory does not exist: \"%s\"\n", path); + sprintf (b, _("Error:\n\n" "Directory does not exist: \"%s\"\n"), path); warning_dialog (GTK_WIDGET (top), b, False, 100); return; } @@ -1874,8 +1878,18 @@ populate_prefs_page (state *s) saver_preferences *p = &s->prefs; char str[100]; + /* The file supports timeouts of less than a minute, but the GUI does + not, so throttle the values to be at least one minute (since "0" is + a bad rounding choice...) + */ +# define THROTTLE(NAME) if (p->NAME != 0 && p->NAME < 60000) p->NAME = 60000 + THROTTLE (timeout); + THROTTLE (cycle); + THROTTLE (passwd_timeout); +# undef THROTTLE + # define FMT_MINUTES(NAME,N) \ - sprintf (str, "%d", ((N) + 59) / (60 * 1000)); \ + sprintf (str, "%d", (((N / 1000) + 59) / 60)); \ gtk_entry_set_text (GTK_ENTRY (name_to_widget (s, (NAME))), str) # define FMT_SECONDS(NAME,N) \ @@ -2012,6 +2026,10 @@ populate_popup_window (state *s) screenhack *hack = (hack_number >= 0 ? p->screenhacks[hack_number] : 0); char *doc_string = 0; + /* #### not in Gtk 1.2 + gtk_label_set_selectable (doc); + */ + # ifdef HAVE_XML if (s->cdata) { @@ -2032,12 +2050,12 @@ populate_popup_window (state *s) ? s->cdata->description : 0); # else /* !HAVE_XML */ - doc_string = "Descriptions not available: no XML support compiled in."; + doc_string = _("Descriptions not available: no XML support compiled in."); # endif /* !HAVE_XML */ gtk_label_set_text (doc, (doc_string - ? doc_string - : "No description available.")); + ? _(doc_string) + : _("No description available."))); } @@ -2286,13 +2304,13 @@ populate_demo_window (state *s, int list_elt) if (p->mode == BLANK_ONLY) { hack = 0; - pretty_name = strdup ("Blank Screen"); + pretty_name = strdup (_("Blank Screen")); schedule_preview (s, 0); } else if (p->mode == DONT_BLANK) { hack = 0; - pretty_name = strdup ("Screen Saver Disabled"); + pretty_name = strdup (_("Screen Saver Disabled")); schedule_preview (s, 0); } else @@ -2315,7 +2333,7 @@ populate_demo_window (state *s, int list_elt) } if (!pretty_name) - pretty_name = strdup ("Preview"); + pretty_name = strdup (_("Preview")); gtk_frame_set_label (frame1, pretty_name); gtk_frame_set_label (frame2, pretty_name); @@ -2334,7 +2352,7 @@ populate_demo_window (state *s, int list_elt) (hack ? (hack->visual && *hack->visual ? hack->visual - : "Any") + : _("Any")) : "")); sensitize_demo_widgets (s, (hack ? True : False)); @@ -2452,8 +2470,8 @@ maybe_reload_init_file (state *s) if (!f || !*f) return 0; b = (char *) malloc (strlen(f) + 1024); sprintf (b, - "Warning:\n\n" - "file \"%s\" has changed, reloading.\n", + _("Warning:\n\n" + "file \"%s\" has changed, reloading.\n"), f); warning_dialog (s->toplevel_widget, b, False, 100); free (b); @@ -2519,7 +2537,7 @@ clear_preview_window (state *s) if (s->running_preview_error_p) { - const char * const lines[] = { "No Preview", "Available" }; + const char * const lines[] = { N_("No Preview"), N_("Available") }; int lh = p->style->font->ascent + p->style->font->descent; int y, i; gint w, h; @@ -2528,11 +2546,11 @@ clear_preview_window (state *s) y += p->style->font->ascent; for (i = 0; i < countof(lines); i++) { - int sw = gdk_string_width (p->style->font, lines[i]); + int sw = gdk_string_width (p->style->font, _(lines[i])); int x = (w - sw) / 2; gdk_draw_string (window, p->style->font, p->style->fg_gc[GTK_STATE_NORMAL], - x, y, lines[i]); + x, y, _(lines[i])); y += lh; } } @@ -2796,7 +2814,7 @@ launch_preview_subproc (state *s) { saver_preferences *p = &s->prefs; Window id; - char *new_cmd; + char *new_cmd = 0; pid_t forked; const char *cmd = s->desired_preview_cmd; @@ -2808,7 +2826,7 @@ launch_preview_subproc (state *s) if (s->preview_suppressed_p) { kill_preview_subproc (s); - return; + goto DONE; } new_cmd = malloc (strlen (cmd) + 40); @@ -2831,7 +2849,7 @@ launch_preview_subproc (state *s) { s->running_preview_error_p = True; clear_preview_window (s); - return; + goto DONE; } switch ((int) (forked = fork ())) @@ -2842,7 +2860,8 @@ launch_preview_subproc (state *s) sprintf (buf, "%s: couldn't fork", blurb()); perror (buf); s->running_preview_error_p = True; - return; + goto DONE; + break; } case 0: { @@ -2876,6 +2895,10 @@ launch_preview_subproc (state *s) } schedule_preview_check (s); + + DONE: + if (new_cmd) free (new_cmd); + new_cmd = 0; } @@ -2902,6 +2925,11 @@ hack_environment (state *s) if (s->debug_p) fprintf (stderr, "%s: %s\n", blurb(), ndpy); + /* don't free(ndpy) -- some implementations of putenv (BSD 4.4, glibc + 2.0) copy the argument, but some (libc4,5, glibc 2.1.2) do not. + So we must leak it (and/or the previous setting). Yay. + */ + if (def_path && *def_path) { const char *opath = getenv("PATH"); @@ -2913,6 +2941,7 @@ hack_environment (state *s) if (putenv (npath)) abort (); + /* do not free(npath) -- see above */ if (s->debug_p) fprintf (stderr, "%s: added \"%s\" to $PATH\n", blurb(), def_path); @@ -3139,7 +3168,7 @@ static void the_network_is_not_the_computer (state *s) { Display *dpy = GDK_DISPLAY(); - char *rversion, *ruser, *rhost; + char *rversion = 0, *ruser = 0, *rhost = 0; char *luser, *lhost; char *msg = 0; struct passwd *p = getpwuid (getuid ()); @@ -3178,9 +3207,9 @@ the_network_is_not_the_computer (state *s) if (!rversion || !*rversion) { sprintf (msg, - "Warning:\n\n" - "The XScreenSaver daemon doesn't seem to be running\n" - "on display \"%s\". Launch it now?", + _("Warning:\n\n" + "The XScreenSaver daemon doesn't seem to be running\n" + "on display \"%s\". Launch it now?"), d); } else if (p && ruser && *ruser && !!strcmp (ruser, p->pw_name)) @@ -3188,7 +3217,7 @@ the_network_is_not_the_computer (state *s) /* Warn that the two processes are running as different users. */ sprintf(msg, - "Warning:\n\n" + _("Warning:\n\n" "%s is running as user \"%s\" on host \"%s\".\n" "But the xscreensaver managing display \"%s\"\n" "is running as user \"%s\" on host \"%s\".\n" @@ -3200,7 +3229,7 @@ the_network_is_not_the_computer (state *s) "You should either re-run %s as \"%s\", or re-run\n" "xscreensaver as \"%s\".\n" "\n" - "Restart the xscreensaver daemon now?\n", + "Restart the xscreensaver daemon now?\n"), blurb(), luser, lhost, d, (ruser ? ruser : "???"), (rhost ? rhost : "???"), @@ -3213,7 +3242,7 @@ the_network_is_not_the_computer (state *s) /* Warn that the two processes are running on different hosts. */ sprintf (msg, - "Warning:\n\n" + _("Warning:\n\n" "%s is running as user \"%s\" on host \"%s\".\n" "But the xscreensaver managing display \"%s\"\n" "is running as user \"%s\" on host \"%s\".\n" @@ -3222,7 +3251,7 @@ the_network_is_not_the_computer (state *s) "if they don't see the same ~%s/.xscreensaver file) then\n" "%s won't work right.\n" "\n" - "Restart the daemon on \"%s\" as \"%s\" now?\n", + "Restart the daemon on \"%s\" as \"%s\" now?\n"), blurb(), luser, lhost, d, (ruser ? ruser : "???"), (rhost ? rhost : "???"), @@ -3235,13 +3264,13 @@ the_network_is_not_the_computer (state *s) /* Warn that the version numbers don't match. */ sprintf (msg, - "Warning:\n\n" + _("Warning:\n\n" "This is %s version %s.\n" "But the xscreensaver managing display \"%s\"\n" "is version %s. This could cause problems.\n" - "\n" - "Restart the xscreensaver daemon now?\n", - blurb(), s->short_version, + "\n" + "Restart the xscreensaver daemon now?\n"), + progname, s->short_version, d, rversion); } @@ -3250,6 +3279,9 @@ the_network_is_not_the_computer (state *s) if (*msg) warning_dialog (s->toplevel_widget, msg, True, 1); + if (rversion) free (rversion); + if (ruser) free (ruser); + if (rhost) free (rhost); free (msg); } @@ -3262,13 +3294,9 @@ demo_ehandler (Display *dpy, XErrorEvent *error) { state *s = global_state_kludge; /* I hate C so much... */ fprintf (stderr, "\nX error in %s:\n", blurb()); - if (XmuPrintDefaultErrorMessage (dpy, error, stderr)) - { - kill_preview_subproc (s); - exit (-1); - } - else - fprintf (stderr, " (nonfatal.)\n"); + XmuPrintDefaultErrorMessage (dpy, error, stderr); + kill_preview_subproc (s); + exit (-1); return 0; } @@ -3321,8 +3349,7 @@ const char *usage = "[--display dpy] [--prefs]" # ifdef HAVE_CRAPPLET " [--crapplet]" # endif - " [--debug]"; - + "\n\t\t [--debug] [--sync] [--no-xshm]"; static void map_popup_window_cb (GtkWidget *w, gpointer user_data) @@ -3394,6 +3421,19 @@ main (int argc, char **argv) Bool crapplet_p = False; char *str; +#ifdef ENABLE_NLS + bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); + textdomain (GETTEXT_PACKAGE); + +# ifdef HAVE_GTK2 + bindtextdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); +# else /* ! HAVE_GTK2 */ + if (!setlocale (LC_ALL, "")) + fprintf (stderr, "%s: locale not supported by C library\n", real_progname); +# endif /* ! HAVE_GTK2 */ + +#endif /* ENABLE_NLS */ + str = strrchr (real_progname, '/'); if (str) real_progname = str+1; @@ -3424,7 +3464,10 @@ main (int argc, char **argv) } #ifdef DEFAULT_ICONDIR /* from -D on compile line */ - add_pixmap_directory (DEFAULT_ICONDIR); + { + const char *dir = DEFAULT_ICONDIR; + if (*dir) add_pixmap_directory (dir); + } #endif /* This is gross, but Gtk understands --display and not -display... @@ -3589,7 +3632,7 @@ main (int argc, char **argv) ; else { - fprintf (stderr, "%s: unknown option: %s\n", real_progname, argv[i]); + fprintf (stderr, _("%s: unknown option: %s\n"), real_progname, argv[i]); fprintf (stderr, "%s: %s\n", real_progname, usage); exit (1); }