4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2000, Thomas Leonard, <tal197@ecs.soton.ac.uk>.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 * Place, Suite 330, Boston, MA 02111-1307 USA
34 #include "gui_support.h"
36 /* Static prototypes */
37 static GtkWidget
*create_options();
38 static void update_options();
39 static void set_options();
40 static void save_options();
41 static char *parse_lang(guchar
*line
);
43 static OptionsSection options
=
52 static guchar
*o_default_lang
= NULL
;
55 /****************************************************************
56 * EXTERNAL INTERFACE *
57 ****************************************************************/
60 /* Set things up for internationalisation */
63 o_default_lang
= g_strdup("");
69 lang_path
= choices_find_path_load("Locale", "ROX-Filer");
71 parse_file(lang_path
, parse_lang
);
74 setenv("LANG", o_default_lang
, 1);
75 setlocale(LC_ALL
, "");
76 bindtextdomain("ROX-Filer",
77 make_path(getenv("APP_DIR"), "po")->str
);
78 textdomain("ROX-Filer");
81 options_sections
= g_slist_prepend(options_sections
, &options
);
85 /****************************************************************
86 * INTERNAL FUNCTIONS *
87 ****************************************************************/
93 static GtkWidget
*w_lang_entry
= NULL
;
96 /* Build up some option widgets to go in the options dialog, but don't
99 static GtkWidget
*create_options()
102 GtkWidget
*vbox
, *hbox
, *label
;
104 vbox
= gtk_vbox_new(FALSE
, 0);
105 gtk_container_set_border_width(GTK_CONTAINER(vbox
), 4);
107 hbox
= gtk_hbox_new(TRUE
, 0);
108 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, TRUE
, 0);
110 label
= gtk_label_new("Language to use");
111 gtk_box_pack_start(GTK_BOX(hbox
), label
, FALSE
, TRUE
, 0);
113 w_lang_entry
= gtk_entry_new();
114 gtk_box_pack_start(GTK_BOX(hbox
), w_lang_entry
, TRUE
, TRUE
, 0);
118 label
= gtk_label_new("Not compiled with gettext support");
123 /* Reflect current state by changing the widgets in the options box */
124 static void update_options()
127 gtk_entry_set_text(GTK_ENTRY(w_lang_entry
), o_default_lang
);
131 /* Set current values by reading the states of the widgets in the options box */
132 static void set_options()
135 g_free(o_default_lang
);
137 o_default_lang
= gtk_editable_get_chars(GTK_EDITABLE(w_lang_entry
),
142 static void save_options()
146 lang_path
= choices_find_path_save("Locale", "ROX-Filer", TRUE
);
153 file
= fopen(lang_path
, "wb");
156 delayed_error(PROJECT
, g_strerror(errno
));
160 count
= strlen(o_default_lang
);
161 if (fwrite(o_default_lang
, 1, count
, file
) < count
)
163 delayed_error(PROJECT
, g_strerror(errno
));
166 else if (fclose(file
))
167 delayed_error(PROJECT
, g_strerror(errno
));
171 static char *parse_lang(guchar
*line
)
173 o_default_lang
= g_strdup(line
);
178 /* These two stolen from dia :-) */
179 GtkItemFactoryEntry
*translate_entries(GtkItemFactoryEntry
*entries
, gint n
)
182 GtkItemFactoryEntry
*ret
;
184 ret
= g_malloc(sizeof(GtkItemFactoryEntry
) * n
);
185 for (i
= 0; i
< n
; i
++)
187 /* Translation. Note the explicit use of gettext(). */
188 ret
[i
].path
= g_strdup(gettext(entries
[i
].path
));
189 /* accelerator and item_type are not duped, only referenced */
190 ret
[i
].accelerator
= entries
[i
].accelerator
;
191 ret
[i
].callback
= entries
[i
].callback
;
192 ret
[i
].callback_action
= entries
[i
].callback_action
;
193 ret
[i
].item_type
= entries
[i
].item_type
;
198 void free_translated_entries(GtkItemFactoryEntry
*entries
, gint n
)
203 g_free(entries
[i
].path
);