Statistics
| Revision:

root / src / prefs_ui.c @ 3043

History | View | Annotate | Download (13.4 kB)

1 527 hiro
/*
2 527 hiro
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 1053 hiro
 * Copyright (C) 1999-2006 Hiroyuki Yamamoto
4 527 hiro
 *
5 527 hiro
 * This program is free software; you can redistribute it and/or modify
6 527 hiro
 * it under the terms of the GNU General Public License as published by
7 527 hiro
 * the Free Software Foundation; either version 2 of the License, or
8 527 hiro
 * (at your option) any later version.
9 527 hiro
 *
10 527 hiro
 * This program is distributed in the hope that it will be useful,
11 527 hiro
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 527 hiro
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 527 hiro
 * GNU General Public License for more details.
14 527 hiro
 *
15 527 hiro
 * You should have received a copy of the GNU General Public License
16 527 hiro
 * along with this program; if not, write to the Free Software
17 527 hiro
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 527 hiro
 */
19 527 hiro
20 527 hiro
#ifdef HAVE_CONFIG_H
21 527 hiro
#  include "config.h"
22 527 hiro
#endif
23 527 hiro
24 527 hiro
#include <glib.h>
25 527 hiro
#include <glib/gi18n.h>
26 527 hiro
#include <gtk/gtk.h>
27 527 hiro
#include <stdio.h>
28 527 hiro
#include <stdlib.h>
29 527 hiro
#include <string.h>
30 527 hiro
#include <unistd.h>
31 527 hiro
#include <errno.h>
32 527 hiro
33 527 hiro
#include "prefs.h"
34 527 hiro
#include "prefs_ui.h"
35 1053 hiro
#include "menu.h"
36 527 hiro
#include "codeconv.h"
37 527 hiro
#include "utils.h"
38 527 hiro
#include "gtkutils.h"
39 527 hiro
40 527 hiro
typedef enum
41 527 hiro
{
42 527 hiro
        DUMMY_PARAM
43 527 hiro
} DummyEnum;
44 527 hiro
45 527 hiro
void prefs_dialog_create(PrefsDialog *dialog)
46 527 hiro
{
47 527 hiro
        GtkWidget *window;
48 527 hiro
        GtkWidget *vbox;
49 527 hiro
        GtkWidget *notebook;
50 527 hiro
51 527 hiro
        GtkWidget *confirm_area;
52 527 hiro
        GtkWidget *ok_btn;
53 527 hiro
        GtkWidget *cancel_btn;
54 527 hiro
        GtkWidget *apply_btn;
55 527 hiro
56 527 hiro
        g_return_if_fail(dialog != NULL);
57 527 hiro
58 527 hiro
        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
59 765 hiro
        gtk_container_set_border_width (GTK_CONTAINER (window), 6);
60 527 hiro
        gtk_window_set_position (GTK_WINDOW(window), GTK_WIN_POS_CENTER);
61 527 hiro
        gtk_window_set_modal (GTK_WINDOW (window), TRUE);
62 527 hiro
        gtk_window_set_policy (GTK_WINDOW(window), FALSE, TRUE, FALSE);
63 527 hiro
64 527 hiro
        vbox = gtk_vbox_new (FALSE, 6);
65 527 hiro
        gtk_widget_show(vbox);
66 527 hiro
        gtk_container_add (GTK_CONTAINER (window), vbox);
67 527 hiro
68 527 hiro
        notebook = gtk_notebook_new ();
69 527 hiro
        gtk_widget_show(notebook);
70 527 hiro
        gtk_box_pack_start (GTK_BOX (vbox), notebook, TRUE, TRUE, 0);
71 527 hiro
        gtk_container_set_border_width (GTK_CONTAINER (notebook), 2);
72 527 hiro
        /* GTK_WIDGET_UNSET_FLAGS (notebook, GTK_CAN_FOCUS); */
73 527 hiro
        gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
74 527 hiro
75 527 hiro
        gtkut_stock_button_set_create(&confirm_area,
76 527 hiro
                                      &ok_btn, GTK_STOCK_OK,
77 527 hiro
                                      &cancel_btn, GTK_STOCK_CANCEL,
78 527 hiro
                                      &apply_btn, GTK_STOCK_APPLY);
79 527 hiro
        gtk_widget_show(confirm_area);
80 527 hiro
        gtk_box_pack_end (GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
81 527 hiro
        gtk_widget_grab_default(ok_btn);
82 527 hiro
83 527 hiro
        dialog->window       = window;
84 527 hiro
        dialog->notebook     = notebook;
85 527 hiro
        dialog->confirm_area = confirm_area;
86 527 hiro
        dialog->ok_btn       = ok_btn;
87 527 hiro
        dialog->cancel_btn   = cancel_btn;
88 527 hiro
        dialog->apply_btn    = apply_btn;
89 527 hiro
}
90 527 hiro
91 527 hiro
void prefs_dialog_destroy(PrefsDialog *dialog)
92 527 hiro
{
93 527 hiro
        gtk_widget_destroy(dialog->window);
94 527 hiro
        dialog->window     = NULL;
95 527 hiro
        dialog->notebook   = NULL;
96 527 hiro
        dialog->ok_btn     = NULL;
97 527 hiro
        dialog->cancel_btn = NULL;
98 527 hiro
        dialog->apply_btn  = NULL;
99 527 hiro
}
100 527 hiro
101 527 hiro
void prefs_button_toggled(GtkToggleButton *toggle_btn, GtkWidget *widget)
102 527 hiro
{
103 527 hiro
        gboolean is_active;
104 527 hiro
105 527 hiro
        is_active = gtk_toggle_button_get_active(toggle_btn);
106 527 hiro
        gtk_widget_set_sensitive(widget, is_active);
107 527 hiro
}
108 527 hiro
109 1124 hiro
void prefs_button_toggled_rev(GtkToggleButton *toggle_btn, GtkWidget *widget)
110 1124 hiro
{
111 1124 hiro
        gboolean is_active;
112 1124 hiro
113 1124 hiro
        is_active = gtk_toggle_button_get_active(toggle_btn);
114 1124 hiro
        gtk_widget_set_sensitive(widget, !is_active);
115 1124 hiro
}
116 1124 hiro
117 533 hiro
void prefs_register_ui(PrefParam *param, PrefsUIData *ui_data)
118 533 hiro
{
119 533 hiro
        GHashTable *param_table;
120 533 hiro
        PrefParam *param_;
121 533 hiro
        gint i;
122 533 hiro
123 533 hiro
        param_table = prefs_param_table_get(param);
124 533 hiro
125 533 hiro
        for (i = 0; ui_data[i].name != NULL; i++) {
126 533 hiro
                param_ = g_hash_table_lookup(param_table, ui_data[i].name);
127 533 hiro
                if (param_) {
128 533 hiro
                        param_->ui_data = &ui_data[i];
129 533 hiro
                }
130 533 hiro
        }
131 533 hiro
132 533 hiro
        prefs_param_table_destroy(param_table);
133 533 hiro
}
134 533 hiro
135 527 hiro
void prefs_set_dialog(PrefParam *param)
136 527 hiro
{
137 533 hiro
        PrefsUIData *ui_data;
138 527 hiro
        gint i;
139 527 hiro
140 527 hiro
        for (i = 0; param[i].name != NULL; i++) {
141 533 hiro
                ui_data = (PrefsUIData *)param[i].ui_data;
142 533 hiro
                if (ui_data && ui_data->widget_set_func)
143 533 hiro
                        ui_data->widget_set_func(&param[i]);
144 527 hiro
        }
145 527 hiro
}
146 527 hiro
147 527 hiro
void prefs_set_data_from_dialog(PrefParam *param)
148 527 hiro
{
149 533 hiro
        PrefsUIData *ui_data;
150 527 hiro
        gint i;
151 527 hiro
152 527 hiro
        for (i = 0; param[i].name != NULL; i++) {
153 533 hiro
                ui_data = (PrefsUIData *)param[i].ui_data;
154 533 hiro
                if (ui_data && ui_data->data_set_func)
155 533 hiro
                        ui_data->data_set_func(&param[i]);
156 527 hiro
        }
157 527 hiro
}
158 527 hiro
159 527 hiro
void prefs_set_dialog_to_default(PrefParam *param)
160 527 hiro
{
161 527 hiro
        gint           i;
162 533 hiro
        PrefsUIData *ui_data;
163 527 hiro
        PrefParam  tmpparam;
164 527 hiro
        gchar          *str_data = NULL;
165 527 hiro
        gint           int_data;
166 527 hiro
        gushort    ushort_data;
167 527 hiro
        gboolean   bool_data;
168 527 hiro
        DummyEnum  enum_data;
169 527 hiro
170 527 hiro
        for (i = 0; param[i].name != NULL; i++) {
171 533 hiro
                ui_data = (PrefsUIData *)param[i].ui_data;
172 533 hiro
                if (!ui_data || !ui_data->widget_set_func) continue;
173 527 hiro
174 527 hiro
                tmpparam = param[i];
175 527 hiro
176 527 hiro
                switch (tmpparam.type) {
177 527 hiro
                case P_STRING:
178 527 hiro
                        if (tmpparam.defval) {
179 527 hiro
                                if (!g_ascii_strncasecmp
180 527 hiro
                                        (tmpparam.defval, "ENV_", 4)) {
181 527 hiro
                                        str_data = g_strdup
182 527 hiro
                                                (g_getenv(param[i].defval + 4));
183 527 hiro
                                        tmpparam.data = &str_data;
184 527 hiro
                                        break;
185 527 hiro
                                } else if (tmpparam.defval[0] == '~') {
186 527 hiro
                                        str_data =
187 624 hiro
#ifdef G_OS_WIN32
188 624 hiro
                                                g_strconcat(get_rc_dir(),
189 624 hiro
#else
190 527 hiro
                                                g_strconcat(get_home_dir(),
191 624 hiro
#endif
192 527 hiro
                                                            param[i].defval + 1,
193 527 hiro
                                                            NULL);
194 527 hiro
                                        tmpparam.data = &str_data;
195 527 hiro
                                        break;
196 527 hiro
                                }
197 527 hiro
                        }
198 527 hiro
                        tmpparam.data = &tmpparam.defval;
199 527 hiro
                        break;
200 527 hiro
                case P_INT:
201 527 hiro
                        if (tmpparam.defval)
202 527 hiro
                                int_data = atoi(tmpparam.defval);
203 527 hiro
                        else
204 527 hiro
                                int_data = 0;
205 527 hiro
                        tmpparam.data = &int_data;
206 527 hiro
                        break;
207 527 hiro
                case P_USHORT:
208 527 hiro
                        if (tmpparam.defval)
209 527 hiro
                                ushort_data = atoi(tmpparam.defval);
210 527 hiro
                        else
211 527 hiro
                                ushort_data = 0;
212 527 hiro
                        tmpparam.data = &ushort_data;
213 527 hiro
                        break;
214 527 hiro
                case P_BOOL:
215 527 hiro
                        if (tmpparam.defval) {
216 527 hiro
                                if (!g_ascii_strcasecmp(tmpparam.defval, "TRUE"))
217 527 hiro
                                        bool_data = TRUE;
218 527 hiro
                                else
219 527 hiro
                                        bool_data = atoi(tmpparam.defval)
220 527 hiro
                                                ? TRUE : FALSE;
221 527 hiro
                        } else
222 527 hiro
                                bool_data = FALSE;
223 527 hiro
                        tmpparam.data = &bool_data;
224 527 hiro
                        break;
225 527 hiro
                case P_ENUM:
226 527 hiro
                        if (tmpparam.defval)
227 527 hiro
                                enum_data = (DummyEnum)atoi(tmpparam.defval);
228 527 hiro
                        else
229 527 hiro
                                enum_data = 0;
230 527 hiro
                        tmpparam.data = &enum_data;
231 527 hiro
                        break;
232 527 hiro
                case P_OTHER:
233 527 hiro
                        break;
234 527 hiro
                }
235 533 hiro
                ui_data->widget_set_func(&tmpparam);
236 527 hiro
                g_free(str_data);
237 527 hiro
                str_data = NULL;
238 527 hiro
        }
239 527 hiro
}
240 527 hiro
241 527 hiro
void prefs_set_data_from_entry(PrefParam *pparam)
242 527 hiro
{
243 533 hiro
        PrefsUIData *ui_data;
244 527 hiro
        gchar **str;
245 527 hiro
        const gchar *entry_str;
246 527 hiro
247 533 hiro
        ui_data = (PrefsUIData *)pparam->ui_data;
248 533 hiro
        g_return_if_fail(ui_data != NULL);
249 533 hiro
        g_return_if_fail(*ui_data->widget != NULL);
250 527 hiro
251 533 hiro
        entry_str = gtk_entry_get_text(GTK_ENTRY(*ui_data->widget));
252 527 hiro
253 527 hiro
        switch (pparam->type) {
254 527 hiro
        case P_STRING:
255 527 hiro
                str = (gchar **)pparam->data;
256 527 hiro
                g_free(*str);
257 527 hiro
                *str = entry_str[0] ? g_strdup(entry_str) : NULL;
258 527 hiro
                break;
259 527 hiro
        case P_USHORT:
260 527 hiro
                *((gushort *)pparam->data) = atoi(entry_str);
261 527 hiro
                break;
262 527 hiro
        case P_INT:
263 527 hiro
                *((gint *)pparam->data) = atoi(entry_str);
264 527 hiro
                break;
265 527 hiro
        default:
266 527 hiro
                g_warning("Invalid PrefType for GtkEntry widget: %d\n",
267 527 hiro
                          pparam->type);
268 527 hiro
        }
269 527 hiro
}
270 527 hiro
271 527 hiro
void prefs_set_entry(PrefParam *pparam)
272 527 hiro
{
273 533 hiro
        PrefsUIData *ui_data;
274 527 hiro
        gchar **str;
275 527 hiro
276 533 hiro
        ui_data = (PrefsUIData *)pparam->ui_data;
277 533 hiro
        g_return_if_fail(ui_data != NULL);
278 533 hiro
        g_return_if_fail(*ui_data->widget != NULL);
279 527 hiro
280 527 hiro
        switch (pparam->type) {
281 527 hiro
        case P_STRING:
282 527 hiro
                str = (gchar **)pparam->data;
283 533 hiro
                gtk_entry_set_text(GTK_ENTRY(*ui_data->widget),
284 527 hiro
                                   *str ? *str : "");
285 527 hiro
                break;
286 527 hiro
        case P_INT:
287 533 hiro
                gtk_entry_set_text(GTK_ENTRY(*ui_data->widget),
288 527 hiro
                                   itos(*((gint *)pparam->data)));
289 527 hiro
                break;
290 527 hiro
        case P_USHORT:
291 533 hiro
                gtk_entry_set_text(GTK_ENTRY(*ui_data->widget),
292 527 hiro
                                   itos(*((gushort *)pparam->data)));
293 527 hiro
                break;
294 527 hiro
        default:
295 527 hiro
                g_warning("Invalid PrefType for GtkEntry widget: %d\n",
296 527 hiro
                          pparam->type);
297 527 hiro
        }
298 527 hiro
}
299 527 hiro
300 527 hiro
void prefs_set_data_from_text(PrefParam *pparam)
301 527 hiro
{
302 533 hiro
        PrefsUIData *ui_data;
303 527 hiro
        gchar **str;
304 527 hiro
        gchar *text = NULL, *tp = NULL;
305 527 hiro
        gchar *tmp, *tmpp;
306 527 hiro
307 533 hiro
        ui_data = (PrefsUIData *)pparam->ui_data;
308 533 hiro
        g_return_if_fail(ui_data != NULL);
309 533 hiro
        g_return_if_fail(*ui_data->widget != NULL);
310 533 hiro
        g_return_if_fail(GTK_IS_EDITABLE(*ui_data->widget) ||
311 533 hiro
                         GTK_IS_TEXT_VIEW(*ui_data->widget));
312 527 hiro
313 527 hiro
        switch (pparam->type) {
314 527 hiro
        case P_STRING:
315 527 hiro
                str = (gchar **)pparam->data;
316 527 hiro
                g_free(*str);
317 533 hiro
                if (GTK_IS_EDITABLE(*ui_data->widget)) {
318 527 hiro
                        tp = text = gtk_editable_get_chars
319 533 hiro
                                (GTK_EDITABLE(*ui_data->widget), 0, -1);
320 533 hiro
                } else if (GTK_IS_TEXT_VIEW(*ui_data->widget)) {
321 533 hiro
                        GtkTextView *textview = GTK_TEXT_VIEW(*ui_data->widget);
322 527 hiro
                        GtkTextBuffer *buffer;
323 527 hiro
                        GtkTextIter start, end;
324 527 hiro
325 527 hiro
                        buffer = gtk_text_view_get_buffer(textview);
326 527 hiro
                        gtk_text_buffer_get_start_iter(buffer, &start);
327 527 hiro
                        gtk_text_buffer_get_iter_at_offset(buffer, &end, -1);
328 527 hiro
                        tp = text = gtk_text_buffer_get_text
329 527 hiro
                                (buffer, &start, &end, FALSE);
330 527 hiro
                }
331 527 hiro
332 527 hiro
                g_return_if_fail(tp != NULL && text != NULL);
333 527 hiro
334 527 hiro
                if (text[0] == '\0') {
335 527 hiro
                        *str = NULL;
336 527 hiro
                        g_free(text);
337 527 hiro
                        break;
338 527 hiro
                }
339 527 hiro
340 2875 hiro
                tmpp = tmp = g_malloc(strlen(text) * 2 + 1);
341 527 hiro
                while (*tp) {
342 527 hiro
                        if (*tp == '\n') {
343 527 hiro
                                *tmpp++ = '\\';
344 527 hiro
                                *tmpp++ = 'n';
345 527 hiro
                                tp++;
346 527 hiro
                        } else
347 527 hiro
                                *tmpp++ = *tp++;
348 527 hiro
                }
349 527 hiro
                *tmpp = '\0';
350 2875 hiro
                *str = tmp;
351 527 hiro
                g_free(text);
352 527 hiro
                break;
353 527 hiro
        default:
354 527 hiro
                g_warning("Invalid PrefType for GtkTextView widget: %d\n",
355 527 hiro
                          pparam->type);
356 527 hiro
        }
357 527 hiro
}
358 527 hiro
359 527 hiro
void prefs_set_text(PrefParam *pparam)
360 527 hiro
{
361 533 hiro
        PrefsUIData *ui_data;
362 527 hiro
        gchar *buf, *sp, *bufp;
363 527 hiro
        gchar **str;
364 527 hiro
        GtkTextView *text;
365 527 hiro
        GtkTextBuffer *buffer;
366 527 hiro
        GtkTextIter iter;
367 527 hiro
368 533 hiro
        ui_data = (PrefsUIData *)pparam->ui_data;
369 533 hiro
        g_return_if_fail(ui_data != NULL);
370 533 hiro
        g_return_if_fail(*ui_data->widget != NULL);
371 527 hiro
372 527 hiro
        switch (pparam->type) {
373 527 hiro
        case P_STRING:
374 527 hiro
                str = (gchar **)pparam->data;
375 527 hiro
                if (*str) {
376 2875 hiro
                        bufp = buf = g_malloc(strlen(*str) + 1);
377 2875 hiro
                        sp = *str;
378 2875 hiro
                        while (*sp) {
379 2875 hiro
                                if (*sp == '\\' && *(sp + 1) == 'n') {
380 2875 hiro
                                        *bufp++ = '\n';
381 2875 hiro
                                        sp += 2;
382 2875 hiro
                                } else
383 2875 hiro
                                        *bufp++ = *sp++;
384 527 hiro
                        }
385 2875 hiro
                        *bufp = '\0';
386 527 hiro
                } else
387 2875 hiro
                        buf = g_strdup("");
388 527 hiro
389 533 hiro
                text = GTK_TEXT_VIEW(*ui_data->widget);
390 527 hiro
                buffer = gtk_text_view_get_buffer(text);
391 527 hiro
                gtk_text_buffer_set_text(buffer, "", 0);
392 527 hiro
                gtk_text_buffer_get_start_iter(buffer, &iter);
393 527 hiro
                gtk_text_buffer_insert(buffer, &iter, buf, -1);
394 2875 hiro
                g_free(buf);
395 527 hiro
                break;
396 527 hiro
        default:
397 527 hiro
                g_warning("Invalid PrefType for GtkTextView widget: %d\n",
398 527 hiro
                          pparam->type);
399 527 hiro
        }
400 527 hiro
}
401 527 hiro
402 527 hiro
void prefs_set_data_from_toggle(PrefParam *pparam)
403 527 hiro
{
404 533 hiro
        PrefsUIData *ui_data;
405 533 hiro
406 533 hiro
        ui_data = (PrefsUIData *)pparam->ui_data;
407 527 hiro
        g_return_if_fail(pparam->type == P_BOOL);
408 533 hiro
        g_return_if_fail(ui_data != NULL);
409 533 hiro
        g_return_if_fail(*ui_data->widget != NULL);
410 527 hiro
411 527 hiro
        *((gboolean *)pparam->data) =
412 533 hiro
                gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(*ui_data->widget));
413 527 hiro
}
414 527 hiro
415 527 hiro
void prefs_set_toggle(PrefParam *pparam)
416 527 hiro
{
417 533 hiro
        PrefsUIData *ui_data;
418 533 hiro
419 533 hiro
        ui_data = (PrefsUIData *)pparam->ui_data;
420 527 hiro
        g_return_if_fail(pparam->type == P_BOOL);
421 533 hiro
        g_return_if_fail(ui_data != NULL);
422 533 hiro
        g_return_if_fail(*ui_data->widget != NULL);
423 527 hiro
424 533 hiro
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(*ui_data->widget),
425 527 hiro
                                     *((gboolean *)pparam->data));
426 527 hiro
}
427 527 hiro
428 527 hiro
void prefs_set_data_from_spinbtn(PrefParam *pparam)
429 527 hiro
{
430 533 hiro
        PrefsUIData *ui_data;
431 527 hiro
432 533 hiro
        ui_data = (PrefsUIData *)pparam->ui_data;
433 533 hiro
        g_return_if_fail(ui_data != NULL);
434 533 hiro
        g_return_if_fail(*ui_data->widget != NULL);
435 533 hiro
436 527 hiro
        switch (pparam->type) {
437 527 hiro
        case P_INT:
438 527 hiro
                *((gint *)pparam->data) =
439 527 hiro
                        gtk_spin_button_get_value_as_int
440 533 hiro
                        (GTK_SPIN_BUTTON(*ui_data->widget));
441 527 hiro
                break;
442 527 hiro
        case P_USHORT:
443 527 hiro
                *((gushort *)pparam->data) =
444 527 hiro
                        (gushort)gtk_spin_button_get_value_as_int
445 533 hiro
                        (GTK_SPIN_BUTTON(*ui_data->widget));
446 527 hiro
                break;
447 527 hiro
        default:
448 527 hiro
                g_warning("Invalid PrefType for GtkSpinButton widget: %d\n",
449 527 hiro
                          pparam->type);
450 527 hiro
        }
451 527 hiro
}
452 527 hiro
453 527 hiro
void prefs_set_spinbtn(PrefParam *pparam)
454 527 hiro
{
455 533 hiro
        PrefsUIData *ui_data;
456 527 hiro
457 533 hiro
        ui_data = (PrefsUIData *)pparam->ui_data;
458 533 hiro
        g_return_if_fail(ui_data != NULL);
459 533 hiro
        g_return_if_fail(*ui_data->widget != NULL);
460 533 hiro
461 527 hiro
        switch (pparam->type) {
462 527 hiro
        case P_INT:
463 533 hiro
                gtk_spin_button_set_value(GTK_SPIN_BUTTON(*ui_data->widget),
464 527 hiro
                                          (gfloat)*((gint *)pparam->data));
465 527 hiro
                break;
466 527 hiro
        case P_USHORT:
467 533 hiro
                gtk_spin_button_set_value(GTK_SPIN_BUTTON(*ui_data->widget),
468 527 hiro
                                          (gfloat)*((gushort *)pparam->data));
469 527 hiro
                break;
470 527 hiro
        default:
471 527 hiro
                g_warning("Invalid PrefType for GtkSpinButton widget: %d\n",
472 527 hiro
                          pparam->type);
473 527 hiro
        }
474 527 hiro
}
475 527 hiro
476 527 hiro
void prefs_set_data_from_fontbtn(PrefParam *pparam)
477 527 hiro
{
478 533 hiro
        PrefsUIData *ui_data;
479 527 hiro
        gchar **str;
480 527 hiro
        const gchar *font_str;
481 527 hiro
482 533 hiro
        ui_data = (PrefsUIData *)pparam->ui_data;
483 533 hiro
        g_return_if_fail(ui_data != NULL);
484 533 hiro
        g_return_if_fail(*ui_data->widget != NULL);
485 527 hiro
486 527 hiro
        font_str = gtk_font_button_get_font_name
487 533 hiro
                (GTK_FONT_BUTTON(*ui_data->widget));
488 527 hiro
489 527 hiro
        switch (pparam->type) {
490 527 hiro
        case P_STRING:
491 527 hiro
                str = (gchar **)pparam->data;
492 527 hiro
                g_free(*str);
493 527 hiro
                *str = font_str[0] ? g_strdup(font_str) : NULL;
494 527 hiro
                break;
495 527 hiro
        default:
496 527 hiro
                g_warning("Invalid PrefType for GtkFontButton widget: %d\n",
497 527 hiro
                          pparam->type);
498 527 hiro
        }
499 527 hiro
}
500 527 hiro
501 527 hiro
void prefs_set_fontbtn(PrefParam *pparam)
502 527 hiro
{
503 533 hiro
        PrefsUIData *ui_data;
504 527 hiro
        gchar **str;
505 527 hiro
506 533 hiro
        ui_data = (PrefsUIData *)pparam->ui_data;
507 533 hiro
        g_return_if_fail(ui_data != NULL);
508 533 hiro
        g_return_if_fail(*ui_data->widget != NULL);
509 527 hiro
510 527 hiro
        switch (pparam->type) {
511 527 hiro
        case P_STRING:
512 527 hiro
                str = (gchar **)pparam->data;
513 533 hiro
                gtk_font_button_set_font_name(GTK_FONT_BUTTON(*ui_data->widget),
514 527 hiro
                                              *str ? *str : "");
515 527 hiro
                break;
516 527 hiro
        default:
517 527 hiro
                g_warning("Invalid PrefType for GtkFontButton widget: %d\n",
518 527 hiro
                          pparam->type);
519 527 hiro
        }
520 527 hiro
}
521 1053 hiro
522 1053 hiro
void prefs_set_data_from_optmenu(PrefParam *pparam)
523 1053 hiro
{
524 1053 hiro
        PrefsUIData *ui_data;
525 1053 hiro
        GtkWidget *menu;
526 1053 hiro
        GtkWidget *menuitem;
527 1053 hiro
528 1053 hiro
        ui_data = (PrefsUIData *)pparam->ui_data;
529 1053 hiro
        g_return_if_fail(ui_data != NULL);
530 1053 hiro
        g_return_if_fail(*ui_data->widget != NULL);
531 1053 hiro
532 1053 hiro
        menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(*ui_data->widget));
533 1053 hiro
        menuitem = gtk_menu_get_active(GTK_MENU(menu));
534 1053 hiro
        *((DummyEnum *)pparam->data) = GPOINTER_TO_INT
535 1053 hiro
                (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
536 1053 hiro
}
537 1053 hiro
538 1053 hiro
void prefs_set_optmenu(PrefParam *pparam)
539 1053 hiro
{
540 1053 hiro
        PrefsUIData *ui_data;
541 1053 hiro
        DummyEnum val = *((DummyEnum *)pparam->data);
542 1053 hiro
        GtkOptionMenu *optmenu;
543 1053 hiro
        gint index;
544 1053 hiro
545 1053 hiro
        ui_data = (PrefsUIData *)pparam->ui_data;
546 1053 hiro
        g_return_if_fail(ui_data != NULL);
547 1053 hiro
        g_return_if_fail(*ui_data->widget != NULL);
548 1053 hiro
549 1053 hiro
        optmenu = GTK_OPTION_MENU(*ui_data->widget);
550 1053 hiro
        g_return_if_fail(optmenu != NULL);
551 1053 hiro
552 1053 hiro
        index = menu_find_option_menu_index(optmenu, GINT_TO_POINTER(val),
553 1053 hiro
                                            NULL);
554 1053 hiro
        if (index >= 0)
555 1053 hiro
                gtk_option_menu_set_history(optmenu, index);
556 1053 hiro
        else {
557 1053 hiro
                gtk_option_menu_set_history(optmenu, 0);
558 1053 hiro
                prefs_set_data_from_optmenu(pparam);
559 1053 hiro
        }
560 1053 hiro
}